117a48c7cSmrg#! /bin/sh 217a48c7cSmrg# depcomp - compile a program generating dependencies as side-effects 317a48c7cSmrg 436e956c5Smrgscriptversion=2013-05-30.07; # UTC 517a48c7cSmrg 636e956c5Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc. 717a48c7cSmrg 817a48c7cSmrg# This program is free software; you can redistribute it and/or modify 917a48c7cSmrg# it under the terms of the GNU General Public License as published by 1017a48c7cSmrg# the Free Software Foundation; either version 2, or (at your option) 1117a48c7cSmrg# any later version. 1217a48c7cSmrg 1317a48c7cSmrg# This program is distributed in the hope that it will be useful, 1417a48c7cSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1517a48c7cSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1617a48c7cSmrg# GNU General Public License for more details. 1717a48c7cSmrg 1817a48c7cSmrg# You should have received a copy of the GNU General Public License 19fbed5abfSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 2017a48c7cSmrg 2117a48c7cSmrg# As a special exception to the GNU General Public License, if you 2217a48c7cSmrg# distribute this file as part of a program that contains a 2317a48c7cSmrg# configuration script generated by Autoconf, you may include it under 2417a48c7cSmrg# the same distribution terms that you use for the rest of that program. 2517a48c7cSmrg 2617a48c7cSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2717a48c7cSmrg 2817a48c7cSmrgcase $1 in 2917a48c7cSmrg '') 3036e956c5Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3136e956c5Smrg exit 1; 3236e956c5Smrg ;; 3317a48c7cSmrg -h | --h*) 3417a48c7cSmrg cat <<\EOF 3517a48c7cSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3617a48c7cSmrg 3717a48c7cSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3817a48c7cSmrgas side-effects. 3917a48c7cSmrg 4017a48c7cSmrgEnvironment variables: 4117a48c7cSmrg depmode Dependency tracking mode. 4236e956c5Smrg source Source file read by 'PROGRAMS ARGS'. 4336e956c5Smrg object Object file output by 'PROGRAMS ARGS'. 4417a48c7cSmrg DEPDIR directory where to store dependencies. 4517a48c7cSmrg depfile Dependency file to output. 460dd80ee0Smrg tmpdepfile Temporary file to use when outputting dependencies. 4717a48c7cSmrg libtool Whether libtool is used (yes/no). 4817a48c7cSmrg 4917a48c7cSmrgReport bugs to <bug-automake@gnu.org>. 5017a48c7cSmrgEOF 5117a48c7cSmrg exit $? 5217a48c7cSmrg ;; 5317a48c7cSmrg -v | --v*) 5417a48c7cSmrg echo "depcomp $scriptversion" 5517a48c7cSmrg exit $? 5617a48c7cSmrg ;; 5717a48c7cSmrgesac 5817a48c7cSmrg 5936e956c5Smrg# Get the directory component of the given path, and save it in the 6036e956c5Smrg# global variables '$dir'. Note that this directory component will 6136e956c5Smrg# be either empty or ending with a '/' character. This is deliberate. 6236e956c5Smrgset_dir_from () 6336e956c5Smrg{ 6436e956c5Smrg case $1 in 6536e956c5Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6636e956c5Smrg *) dir=;; 6736e956c5Smrg esac 6836e956c5Smrg} 6936e956c5Smrg 7036e956c5Smrg# Get the suffix-stripped basename of the given path, and save it the 7136e956c5Smrg# global variable '$base'. 7236e956c5Smrgset_base_from () 7336e956c5Smrg{ 7436e956c5Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7536e956c5Smrg} 7636e956c5Smrg 7736e956c5Smrg# If no dependency file was actually created by the compiler invocation, 7836e956c5Smrg# we still have to create a dummy depfile, to avoid errors with the 7936e956c5Smrg# Makefile "include basename.Plo" scheme. 8036e956c5Smrgmake_dummy_depfile () 8136e956c5Smrg{ 8236e956c5Smrg echo "#dummy" > "$depfile" 8336e956c5Smrg} 8436e956c5Smrg 8536e956c5Smrg# Factor out some common post-processing of the generated depfile. 8636e956c5Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8736e956c5Smrgaix_post_process_depfile () 8836e956c5Smrg{ 8936e956c5Smrg # If the compiler actually managed to produce a dependency file, 9036e956c5Smrg # post-process it. 9136e956c5Smrg if test -f "$tmpdepfile"; then 9236e956c5Smrg # Each line is of the form 'foo.o: dependency.h'. 9336e956c5Smrg # Do two passes, one to just change these to 9436e956c5Smrg # $object: dependency.h 9536e956c5Smrg # and one to simply output 9636e956c5Smrg # dependency.h: 9736e956c5Smrg # which is needed to avoid the deleted-header problem. 9836e956c5Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9936e956c5Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10036e956c5Smrg } > "$depfile" 10136e956c5Smrg rm -f "$tmpdepfile" 10236e956c5Smrg else 10336e956c5Smrg make_dummy_depfile 10436e956c5Smrg fi 10536e956c5Smrg} 10636e956c5Smrg 10736e956c5Smrg# A tabulation character. 10836e956c5Smrgtab=' ' 10936e956c5Smrg# A newline character. 11036e956c5Smrgnl=' 11136e956c5Smrg' 11236e956c5Smrg# Character ranges might be problematic outside the C locale. 11336e956c5Smrg# These definitions help. 11436e956c5Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11536e956c5Smrglower=abcdefghijklmnopqrstuvwxyz 11636e956c5Smrgdigits=0123456789 11736e956c5Smrgalpha=${upper}${lower} 11836e956c5Smrg 11917a48c7cSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12017a48c7cSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12117a48c7cSmrg exit 1 12217a48c7cSmrgfi 12317a48c7cSmrg 12417a48c7cSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12517a48c7cSmrgdepfile=${depfile-`echo "$object" | 12617a48c7cSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12717a48c7cSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12817a48c7cSmrg 12917a48c7cSmrgrm -f "$tmpdepfile" 13017a48c7cSmrg 13136e956c5Smrg# Avoid interferences from the environment. 13236e956c5Smrggccflag= dashmflag= 13336e956c5Smrg 13417a48c7cSmrg# Some modes work just like other modes, but use different flags. We 13517a48c7cSmrg# parameterize here, but still list the modes in the big case below, 13617a48c7cSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13717a48c7cSmrg# here, because this file can only contain one case statement. 13817a48c7cSmrgif test "$depmode" = hp; then 13917a48c7cSmrg # HP compiler uses -M and no extra arg. 14017a48c7cSmrg gccflag=-M 14117a48c7cSmrg depmode=gcc 14217a48c7cSmrgfi 14317a48c7cSmrg 14417a48c7cSmrgif test "$depmode" = dashXmstdout; then 14536e956c5Smrg # This is just like dashmstdout with a different argument. 14636e956c5Smrg dashmflag=-xM 14736e956c5Smrg depmode=dashmstdout 14817a48c7cSmrgfi 14917a48c7cSmrg 150fbed5abfSmrgcygpath_u="cygpath -u -f -" 151fbed5abfSmrgif test "$depmode" = msvcmsys; then 15236e956c5Smrg # This is just like msvisualcpp but w/o cygpath translation. 15336e956c5Smrg # Just convert the backslash-escaped backslashes to single forward 15436e956c5Smrg # slashes to satisfy depend.m4 15536e956c5Smrg cygpath_u='sed s,\\\\,/,g' 15636e956c5Smrg depmode=msvisualcpp 157fbed5abfSmrgfi 158fbed5abfSmrg 1590dd80ee0Smrgif test "$depmode" = msvc7msys; then 16036e956c5Smrg # This is just like msvc7 but w/o cygpath translation. 16136e956c5Smrg # Just convert the backslash-escaped backslashes to single forward 16236e956c5Smrg # slashes to satisfy depend.m4 16336e956c5Smrg cygpath_u='sed s,\\\\,/,g' 16436e956c5Smrg depmode=msvc7 16536e956c5Smrgfi 16636e956c5Smrg 16736e956c5Smrgif test "$depmode" = xlc; then 16836e956c5Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16936e956c5Smrg gccflag=-qmakedep=gcc,-MF 17036e956c5Smrg depmode=gcc 1710dd80ee0Smrgfi 1720dd80ee0Smrg 17317a48c7cSmrgcase "$depmode" in 17417a48c7cSmrggcc3) 17517a48c7cSmrg## gcc 3 implements dependency tracking that does exactly what 17617a48c7cSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17717a48c7cSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 1788e0ed500Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1798e0ed500Smrg## the command line argument order; so add the flags where they 1808e0ed500Smrg## appear in depend2.am. Note that the slowdown incurred here 1818e0ed500Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1828e0ed500Smrg for arg 1838e0ed500Smrg do 1848e0ed500Smrg case $arg in 1858e0ed500Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1868e0ed500Smrg *) set fnord "$@" "$arg" ;; 1878e0ed500Smrg esac 1888e0ed500Smrg shift # fnord 1898e0ed500Smrg shift # $arg 1908e0ed500Smrg done 1918e0ed500Smrg "$@" 19217a48c7cSmrg stat=$? 19336e956c5Smrg if test $stat -ne 0; then 19417a48c7cSmrg rm -f "$tmpdepfile" 19517a48c7cSmrg exit $stat 19617a48c7cSmrg fi 19717a48c7cSmrg mv "$tmpdepfile" "$depfile" 19817a48c7cSmrg ;; 19917a48c7cSmrg 20017a48c7cSmrggcc) 20136e956c5Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20236e956c5Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20336e956c5Smrg## (see the conditional assignment to $gccflag above). 20417a48c7cSmrg## There are various ways to get dependency output from gcc. Here's 20517a48c7cSmrg## why we pick this rather obscure method: 20617a48c7cSmrg## - Don't want to use -MD because we'd like the dependencies to end 20717a48c7cSmrg## up in a subdir. Having to rename by hand is ugly. 20817a48c7cSmrg## (We might end up doing this anyway to support other compilers.) 20917a48c7cSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21036e956c5Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21136e956c5Smrg## supported by the other compilers which use the 'gcc' depmode. 21217a48c7cSmrg## - Using -M directly means running the compiler twice (even worse 21317a48c7cSmrg## than renaming). 21417a48c7cSmrg if test -z "$gccflag"; then 21517a48c7cSmrg gccflag=-MD, 21617a48c7cSmrg fi 21717a48c7cSmrg "$@" -Wp,"$gccflag$tmpdepfile" 21817a48c7cSmrg stat=$? 21936e956c5Smrg if test $stat -ne 0; then 22017a48c7cSmrg rm -f "$tmpdepfile" 22117a48c7cSmrg exit $stat 22217a48c7cSmrg fi 22317a48c7cSmrg rm -f "$depfile" 22417a48c7cSmrg echo "$object : \\" > "$depfile" 22536e956c5Smrg # The second -e expression handles DOS-style file names with drive 22636e956c5Smrg # letters. 22717a48c7cSmrg sed -e 's/^[^:]*: / /' \ 22817a48c7cSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22936e956c5Smrg## This next piece of magic avoids the "deleted header file" problem. 23017a48c7cSmrg## The problem is that when a header file which appears in a .P file 23117a48c7cSmrg## is deleted, the dependency causes make to die (because there is 23217a48c7cSmrg## typically no way to rebuild the header). We avoid this by adding 23317a48c7cSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 23417a48c7cSmrg## this for us directly. 23536e956c5Smrg## Some versions of gcc put a space before the ':'. On the theory 23617a48c7cSmrg## that the space means something, we add a space to the output as 2370dd80ee0Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 2380dd80ee0Smrg## to the object. Take care to not repeat it in the output. 23917a48c7cSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 24017a48c7cSmrg## correctly. Breaking it into two sed invocations is a workaround. 24136e956c5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24236e956c5Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24336e956c5Smrg | sed -e 's/$/ :/' >> "$depfile" 24417a48c7cSmrg rm -f "$tmpdepfile" 24517a48c7cSmrg ;; 24617a48c7cSmrg 24717a48c7cSmrghp) 24817a48c7cSmrg # This case exists only to let depend.m4 do its work. It works by 24917a48c7cSmrg # looking at the text of this script. This case will never be run, 25017a48c7cSmrg # since it is checked for above. 25117a48c7cSmrg exit 1 25217a48c7cSmrg ;; 25317a48c7cSmrg 25417a48c7cSmrgsgi) 25517a48c7cSmrg if test "$libtool" = yes; then 25617a48c7cSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25717a48c7cSmrg else 25817a48c7cSmrg "$@" -MDupdate "$tmpdepfile" 25917a48c7cSmrg fi 26017a48c7cSmrg stat=$? 26136e956c5Smrg if test $stat -ne 0; then 26217a48c7cSmrg rm -f "$tmpdepfile" 26317a48c7cSmrg exit $stat 26417a48c7cSmrg fi 26517a48c7cSmrg rm -f "$depfile" 26617a48c7cSmrg 26717a48c7cSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26817a48c7cSmrg echo "$object : \\" > "$depfile" 26917a48c7cSmrg # Clip off the initial element (the dependent). Don't try to be 27017a48c7cSmrg # clever and replace this with sed code, as IRIX sed won't handle 27117a48c7cSmrg # lines with more than a fixed number of characters (4096 in 27217a48c7cSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27336e956c5Smrg # the IRIX cc adds comments like '#:fec' to the end of the 27417a48c7cSmrg # dependency line. 27536e956c5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27636e956c5Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27736e956c5Smrg | tr "$nl" ' ' >> "$depfile" 278fbed5abfSmrg echo >> "$depfile" 27917a48c7cSmrg # The second pass generates a dummy entry for each header file. 28036e956c5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28136e956c5Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28236e956c5Smrg >> "$depfile" 28317a48c7cSmrg else 28436e956c5Smrg make_dummy_depfile 28517a48c7cSmrg fi 28617a48c7cSmrg rm -f "$tmpdepfile" 28717a48c7cSmrg ;; 28817a48c7cSmrg 28936e956c5Smrgxlc) 29036e956c5Smrg # This case exists only to let depend.m4 do its work. It works by 29136e956c5Smrg # looking at the text of this script. This case will never be run, 29236e956c5Smrg # since it is checked for above. 29336e956c5Smrg exit 1 29436e956c5Smrg ;; 29536e956c5Smrg 29617a48c7cSmrgaix) 29717a48c7cSmrg # The C for AIX Compiler uses -M and outputs the dependencies 29817a48c7cSmrg # in a .u file. In older versions, this file always lives in the 29936e956c5Smrg # current directory. Also, the AIX compiler puts '$object:' at the 30017a48c7cSmrg # start of each line; $object doesn't have directory information. 30117a48c7cSmrg # Version 6 uses the directory in both cases. 30236e956c5Smrg set_dir_from "$object" 30336e956c5Smrg set_base_from "$object" 30417a48c7cSmrg if test "$libtool" = yes; then 305fbed5abfSmrg tmpdepfile1=$dir$base.u 306fbed5abfSmrg tmpdepfile2=$base.u 307fbed5abfSmrg tmpdepfile3=$dir.libs/$base.u 30817a48c7cSmrg "$@" -Wc,-M 30917a48c7cSmrg else 310fbed5abfSmrg tmpdepfile1=$dir$base.u 311fbed5abfSmrg tmpdepfile2=$dir$base.u 312fbed5abfSmrg tmpdepfile3=$dir$base.u 31317a48c7cSmrg "$@" -M 31417a48c7cSmrg fi 31517a48c7cSmrg stat=$? 31636e956c5Smrg if test $stat -ne 0; then 317fbed5abfSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31817a48c7cSmrg exit $stat 31917a48c7cSmrg fi 32017a48c7cSmrg 321fbed5abfSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322fbed5abfSmrg do 323fbed5abfSmrg test -f "$tmpdepfile" && break 324fbed5abfSmrg done 32536e956c5Smrg aix_post_process_depfile 32636e956c5Smrg ;; 32736e956c5Smrg 32836e956c5Smrgtcc) 32936e956c5Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33036e956c5Smrg # FIXME: That version still under development at the moment of writing. 33136e956c5Smrg # Make that this statement remains true also for stable, released 33236e956c5Smrg # versions. 33336e956c5Smrg # It will wrap lines (doesn't matter whether long or short) with a 33436e956c5Smrg # trailing '\', as in: 33536e956c5Smrg # 33636e956c5Smrg # foo.o : \ 33736e956c5Smrg # foo.c \ 33836e956c5Smrg # foo.h \ 33936e956c5Smrg # 34036e956c5Smrg # It will put a trailing '\' even on the last line, and will use leading 34136e956c5Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34236e956c5Smrg # "Emit spaces for -MD"). 34336e956c5Smrg "$@" -MD -MF "$tmpdepfile" 34436e956c5Smrg stat=$? 34536e956c5Smrg if test $stat -ne 0; then 34636e956c5Smrg rm -f "$tmpdepfile" 34736e956c5Smrg exit $stat 34817a48c7cSmrg fi 34936e956c5Smrg rm -f "$depfile" 35036e956c5Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35136e956c5Smrg # We have to change lines of the first kind to '$object: \'. 35236e956c5Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35336e956c5Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35436e956c5Smrg # dummy dependency, to avoid the deleted-header problem. 35536e956c5Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35617a48c7cSmrg rm -f "$tmpdepfile" 35717a48c7cSmrg ;; 35817a48c7cSmrg 35936e956c5Smrg## The order of this option in the case statement is important, since the 36036e956c5Smrg## shell code in configure will try each of these formats in the order 36136e956c5Smrg## listed in this file. A plain '-MD' option would be understood by many 36236e956c5Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36336e956c5Smrgpgcc) 36436e956c5Smrg # Portland's C compiler understands '-MD'. 36536e956c5Smrg # Will always output deps to 'file.d' where file is the root name of the 36636e956c5Smrg # source file under compilation, even if file resides in a subdirectory. 36736e956c5Smrg # The object file name does not affect the name of the '.d' file. 36836e956c5Smrg # pgcc 10.2 will output 36917a48c7cSmrg # foo.o: sub/foo.c sub/foo.h 37036e956c5Smrg # and will wrap long lines using '\' : 37117a48c7cSmrg # foo.o: sub/foo.c ... \ 37217a48c7cSmrg # sub/foo.h ... \ 37317a48c7cSmrg # ... 37436e956c5Smrg set_dir_from "$object" 37536e956c5Smrg # Use the source, not the object, to determine the base name, since 37636e956c5Smrg # that's sadly what pgcc will do too. 37736e956c5Smrg set_base_from "$source" 37836e956c5Smrg tmpdepfile=$base.d 37936e956c5Smrg 38036e956c5Smrg # For projects that build the same source file twice into different object 38136e956c5Smrg # files, the pgcc approach of using the *source* file root name can cause 38236e956c5Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38336e956c5Smrg # the same $tmpdepfile. 38436e956c5Smrg lockdir=$base.d-lock 38536e956c5Smrg trap " 38636e956c5Smrg echo '$0: caught signal, cleaning up...' >&2 38736e956c5Smrg rmdir '$lockdir' 38836e956c5Smrg exit 1 38936e956c5Smrg " 1 2 13 15 39036e956c5Smrg numtries=100 39136e956c5Smrg i=$numtries 39236e956c5Smrg while test $i -gt 0; do 39336e956c5Smrg # mkdir is a portable test-and-set. 39436e956c5Smrg if mkdir "$lockdir" 2>/dev/null; then 39536e956c5Smrg # This process acquired the lock. 39636e956c5Smrg "$@" -MD 39736e956c5Smrg stat=$? 39836e956c5Smrg # Release the lock. 39936e956c5Smrg rmdir "$lockdir" 40036e956c5Smrg break 40136e956c5Smrg else 40236e956c5Smrg # If the lock is being held by a different process, wait 40336e956c5Smrg # until the winning process is done or we timeout. 40436e956c5Smrg while test -d "$lockdir" && test $i -gt 0; do 40536e956c5Smrg sleep 1 40636e956c5Smrg i=`expr $i - 1` 40736e956c5Smrg done 40836e956c5Smrg fi 40936e956c5Smrg i=`expr $i - 1` 41036e956c5Smrg done 41136e956c5Smrg trap - 1 2 13 15 41236e956c5Smrg if test $i -le 0; then 41336e956c5Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41436e956c5Smrg echo "$0: check lockdir '$lockdir'" >&2 41536e956c5Smrg exit 1 41636e956c5Smrg fi 41717a48c7cSmrg 41836e956c5Smrg if test $stat -ne 0; then 41917a48c7cSmrg rm -f "$tmpdepfile" 42017a48c7cSmrg exit $stat 42117a48c7cSmrg fi 42217a48c7cSmrg rm -f "$depfile" 42317a48c7cSmrg # Each line is of the form `foo.o: dependent.h', 42417a48c7cSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42517a48c7cSmrg # Do two passes, one to just change these to 42617a48c7cSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 42717a48c7cSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42817a48c7cSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 42917a48c7cSmrg # correctly. Breaking it into two sed invocations is a workaround. 43036e956c5Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43136e956c5Smrg | sed -e 's/$/ :/' >> "$depfile" 43217a48c7cSmrg rm -f "$tmpdepfile" 43317a48c7cSmrg ;; 43417a48c7cSmrg 4358e0ed500Smrghp2) 4368e0ed500Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4378e0ed500Smrg # compilers, which have integrated preprocessors. The correct option 4388e0ed500Smrg # to use with these is +Maked; it writes dependencies to a file named 4398e0ed500Smrg # 'foo.d', which lands next to the object file, wherever that 4408e0ed500Smrg # happens to be. 4418e0ed500Smrg # Much of this is similar to the tru64 case; see comments there. 44236e956c5Smrg set_dir_from "$object" 44336e956c5Smrg set_base_from "$object" 4448e0ed500Smrg if test "$libtool" = yes; then 4458e0ed500Smrg tmpdepfile1=$dir$base.d 4468e0ed500Smrg tmpdepfile2=$dir.libs/$base.d 4478e0ed500Smrg "$@" -Wc,+Maked 4488e0ed500Smrg else 4498e0ed500Smrg tmpdepfile1=$dir$base.d 4508e0ed500Smrg tmpdepfile2=$dir$base.d 4518e0ed500Smrg "$@" +Maked 4528e0ed500Smrg fi 4538e0ed500Smrg stat=$? 45436e956c5Smrg if test $stat -ne 0; then 4558e0ed500Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4568e0ed500Smrg exit $stat 4578e0ed500Smrg fi 4588e0ed500Smrg 4598e0ed500Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4608e0ed500Smrg do 4618e0ed500Smrg test -f "$tmpdepfile" && break 4628e0ed500Smrg done 4638e0ed500Smrg if test -f "$tmpdepfile"; then 46436e956c5Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46536e956c5Smrg # Add 'dependent.h:' lines. 466fbed5abfSmrg sed -ne '2,${ 46736e956c5Smrg s/^ *// 46836e956c5Smrg s/ \\*$// 46936e956c5Smrg s/$/:/ 47036e956c5Smrg p 47136e956c5Smrg }' "$tmpdepfile" >> "$depfile" 4728e0ed500Smrg else 47336e956c5Smrg make_dummy_depfile 4748e0ed500Smrg fi 4758e0ed500Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4768e0ed500Smrg ;; 4778e0ed500Smrg 47817a48c7cSmrgtru64) 47936e956c5Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48036e956c5Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48136e956c5Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48236e956c5Smrg # dependencies in 'foo.d' instead, so we check for that too. 48336e956c5Smrg # Subdirectories are respected. 48436e956c5Smrg set_dir_from "$object" 48536e956c5Smrg set_base_from "$object" 48636e956c5Smrg 48736e956c5Smrg if test "$libtool" = yes; then 48836e956c5Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48936e956c5Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49036e956c5Smrg # in $dir$base.o.d. We have to check for both files, because 49136e956c5Smrg # one of the two compilations can be disabled. We should prefer 49236e956c5Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49336e956c5Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49436e956c5Smrg # the former would cause a distcleancheck panic. 49536e956c5Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49636e956c5Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49736e956c5Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49836e956c5Smrg "$@" -Wc,-MD 49936e956c5Smrg else 50036e956c5Smrg tmpdepfile1=$dir$base.d 50136e956c5Smrg tmpdepfile2=$dir$base.d 50236e956c5Smrg tmpdepfile3=$dir$base.d 50336e956c5Smrg "$@" -MD 50436e956c5Smrg fi 50536e956c5Smrg 50636e956c5Smrg stat=$? 50736e956c5Smrg if test $stat -ne 0; then 50836e956c5Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50936e956c5Smrg exit $stat 51036e956c5Smrg fi 51136e956c5Smrg 51236e956c5Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51336e956c5Smrg do 51436e956c5Smrg test -f "$tmpdepfile" && break 51536e956c5Smrg done 51636e956c5Smrg # Same post-processing that is required for AIX mode. 51736e956c5Smrg aix_post_process_depfile 51836e956c5Smrg ;; 51917a48c7cSmrg 5200dd80ee0Smrgmsvc7) 5210dd80ee0Smrg if test "$libtool" = yes; then 5220dd80ee0Smrg showIncludes=-Wc,-showIncludes 5230dd80ee0Smrg else 5240dd80ee0Smrg showIncludes=-showIncludes 5250dd80ee0Smrg fi 5260dd80ee0Smrg "$@" $showIncludes > "$tmpdepfile" 5270dd80ee0Smrg stat=$? 5280dd80ee0Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52936e956c5Smrg if test $stat -ne 0; then 5300dd80ee0Smrg rm -f "$tmpdepfile" 5310dd80ee0Smrg exit $stat 5320dd80ee0Smrg fi 5330dd80ee0Smrg rm -f "$depfile" 5340dd80ee0Smrg echo "$object : \\" > "$depfile" 5350dd80ee0Smrg # The first sed program below extracts the file names and escapes 5360dd80ee0Smrg # backslashes for cygpath. The second sed program outputs the file 5370dd80ee0Smrg # name when reading, but also accumulates all include files in the 5380dd80ee0Smrg # hold buffer in order to output them again at the end. This only 5390dd80ee0Smrg # works with sed implementations that can handle large buffers. 5400dd80ee0Smrg sed < "$tmpdepfile" -n ' 5410dd80ee0Smrg/^Note: including file: *\(.*\)/ { 5420dd80ee0Smrg s//\1/ 5430dd80ee0Smrg s/\\/\\\\/g 5440dd80ee0Smrg p 5450dd80ee0Smrg}' | $cygpath_u | sort -u | sed -n ' 5460dd80ee0Smrgs/ /\\ /g 54736e956c5Smrgs/\(.*\)/'"$tab"'\1 \\/p 5480dd80ee0Smrgs/.\(.*\) \\/\1:/ 5490dd80ee0SmrgH 5500dd80ee0Smrg$ { 55136e956c5Smrg s/.*/'"$tab"'/ 5520dd80ee0Smrg G 5530dd80ee0Smrg p 5540dd80ee0Smrg}' >> "$depfile" 55536e956c5Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5560dd80ee0Smrg rm -f "$tmpdepfile" 5570dd80ee0Smrg ;; 5580dd80ee0Smrg 5590dd80ee0Smrgmsvc7msys) 5600dd80ee0Smrg # This case exists only to let depend.m4 do its work. It works by 5610dd80ee0Smrg # looking at the text of this script. This case will never be run, 5620dd80ee0Smrg # since it is checked for above. 5630dd80ee0Smrg exit 1 5640dd80ee0Smrg ;; 5650dd80ee0Smrg 56617a48c7cSmrg#nosideeffect) 56717a48c7cSmrg # This comment above is used by automake to tell side-effect 56817a48c7cSmrg # dependency tracking mechanisms from slower ones. 56917a48c7cSmrg 57017a48c7cSmrgdashmstdout) 57117a48c7cSmrg # Important note: in order to support this mode, a compiler *must* 57217a48c7cSmrg # always write the preprocessed file to stdout, regardless of -o. 57317a48c7cSmrg "$@" || exit $? 57417a48c7cSmrg 57517a48c7cSmrg # Remove the call to Libtool. 57617a48c7cSmrg if test "$libtool" = yes; then 577fbed5abfSmrg while test "X$1" != 'X--mode=compile'; do 57817a48c7cSmrg shift 57917a48c7cSmrg done 58017a48c7cSmrg shift 58117a48c7cSmrg fi 58217a48c7cSmrg 58336e956c5Smrg # Remove '-o $object'. 58417a48c7cSmrg IFS=" " 58517a48c7cSmrg for arg 58617a48c7cSmrg do 58717a48c7cSmrg case $arg in 58817a48c7cSmrg -o) 58917a48c7cSmrg shift 59017a48c7cSmrg ;; 59117a48c7cSmrg $object) 59217a48c7cSmrg shift 59317a48c7cSmrg ;; 59417a48c7cSmrg *) 59517a48c7cSmrg set fnord "$@" "$arg" 59617a48c7cSmrg shift # fnord 59717a48c7cSmrg shift # $arg 59817a48c7cSmrg ;; 59917a48c7cSmrg esac 60017a48c7cSmrg done 60117a48c7cSmrg 60217a48c7cSmrg test -z "$dashmflag" && dashmflag=-M 60336e956c5Smrg # Require at least two characters before searching for ':' 60417a48c7cSmrg # in the target name. This is to cope with DOS-style filenames: 60536e956c5Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60617a48c7cSmrg "$@" $dashmflag | 60736e956c5Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60817a48c7cSmrg rm -f "$depfile" 60917a48c7cSmrg cat < "$tmpdepfile" > "$depfile" 61036e956c5Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61136e956c5Smrg # correctly. Breaking it into two sed invocations is a workaround. 61236e956c5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61336e956c5Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61436e956c5Smrg | sed -e 's/$/ :/' >> "$depfile" 61517a48c7cSmrg rm -f "$tmpdepfile" 61617a48c7cSmrg ;; 61717a48c7cSmrg 61817a48c7cSmrgdashXmstdout) 61917a48c7cSmrg # This case only exists to satisfy depend.m4. It is never actually 62017a48c7cSmrg # run, as this mode is specially recognized in the preamble. 62117a48c7cSmrg exit 1 62217a48c7cSmrg ;; 62317a48c7cSmrg 62417a48c7cSmrgmakedepend) 62517a48c7cSmrg "$@" || exit $? 62617a48c7cSmrg # Remove any Libtool call 62717a48c7cSmrg if test "$libtool" = yes; then 628fbed5abfSmrg while test "X$1" != 'X--mode=compile'; do 62917a48c7cSmrg shift 63017a48c7cSmrg done 63117a48c7cSmrg shift 63217a48c7cSmrg fi 63317a48c7cSmrg # X makedepend 63417a48c7cSmrg shift 635fbed5abfSmrg cleared=no eat=no 636fbed5abfSmrg for arg 637fbed5abfSmrg do 63817a48c7cSmrg case $cleared in 63917a48c7cSmrg no) 64017a48c7cSmrg set ""; shift 64117a48c7cSmrg cleared=yes ;; 64217a48c7cSmrg esac 643fbed5abfSmrg if test $eat = yes; then 644fbed5abfSmrg eat=no 645fbed5abfSmrg continue 646fbed5abfSmrg fi 64717a48c7cSmrg case "$arg" in 64817a48c7cSmrg -D*|-I*) 64917a48c7cSmrg set fnord "$@" "$arg"; shift ;; 65017a48c7cSmrg # Strip any option that makedepend may not understand. Remove 65117a48c7cSmrg # the object too, otherwise makedepend will parse it as a source file. 652fbed5abfSmrg -arch) 653fbed5abfSmrg eat=yes ;; 65417a48c7cSmrg -*|$object) 65517a48c7cSmrg ;; 65617a48c7cSmrg *) 65717a48c7cSmrg set fnord "$@" "$arg"; shift ;; 65817a48c7cSmrg esac 65917a48c7cSmrg done 660fbed5abfSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66117a48c7cSmrg touch "$tmpdepfile" 66217a48c7cSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66317a48c7cSmrg rm -f "$depfile" 6640dd80ee0Smrg # makedepend may prepend the VPATH from the source file name to the object. 6650dd80ee0Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 6660dd80ee0Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66736e956c5Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66836e956c5Smrg # correctly. Breaking it into two sed invocations is a workaround. 66936e956c5Smrg sed '1,2d' "$tmpdepfile" \ 67036e956c5Smrg | tr ' ' "$nl" \ 67136e956c5Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67236e956c5Smrg | sed -e 's/$/ :/' >> "$depfile" 67317a48c7cSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67417a48c7cSmrg ;; 67517a48c7cSmrg 67617a48c7cSmrgcpp) 67717a48c7cSmrg # Important note: in order to support this mode, a compiler *must* 67817a48c7cSmrg # always write the preprocessed file to stdout. 67917a48c7cSmrg "$@" || exit $? 68017a48c7cSmrg 68117a48c7cSmrg # Remove the call to Libtool. 68217a48c7cSmrg if test "$libtool" = yes; then 683fbed5abfSmrg while test "X$1" != 'X--mode=compile'; do 68417a48c7cSmrg shift 68517a48c7cSmrg done 68617a48c7cSmrg shift 68717a48c7cSmrg fi 68817a48c7cSmrg 68936e956c5Smrg # Remove '-o $object'. 69017a48c7cSmrg IFS=" " 69117a48c7cSmrg for arg 69217a48c7cSmrg do 69317a48c7cSmrg case $arg in 69417a48c7cSmrg -o) 69517a48c7cSmrg shift 69617a48c7cSmrg ;; 69717a48c7cSmrg $object) 69817a48c7cSmrg shift 69917a48c7cSmrg ;; 70017a48c7cSmrg *) 70117a48c7cSmrg set fnord "$@" "$arg" 70217a48c7cSmrg shift # fnord 70317a48c7cSmrg shift # $arg 70417a48c7cSmrg ;; 70517a48c7cSmrg esac 70617a48c7cSmrg done 70717a48c7cSmrg 70836e956c5Smrg "$@" -E \ 70936e956c5Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71036e956c5Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71136e956c5Smrg | sed '$ s: \\$::' > "$tmpdepfile" 71217a48c7cSmrg rm -f "$depfile" 71317a48c7cSmrg echo "$object : \\" > "$depfile" 71417a48c7cSmrg cat < "$tmpdepfile" >> "$depfile" 71517a48c7cSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71617a48c7cSmrg rm -f "$tmpdepfile" 71717a48c7cSmrg ;; 71817a48c7cSmrg 71917a48c7cSmrgmsvisualcpp) 72017a48c7cSmrg # Important note: in order to support this mode, a compiler *must* 721fbed5abfSmrg # always write the preprocessed file to stdout. 72217a48c7cSmrg "$@" || exit $? 723fbed5abfSmrg 724fbed5abfSmrg # Remove the call to Libtool. 725fbed5abfSmrg if test "$libtool" = yes; then 726fbed5abfSmrg while test "X$1" != 'X--mode=compile'; do 727fbed5abfSmrg shift 728fbed5abfSmrg done 729fbed5abfSmrg shift 730fbed5abfSmrg fi 731fbed5abfSmrg 73217a48c7cSmrg IFS=" " 73317a48c7cSmrg for arg 73417a48c7cSmrg do 73517a48c7cSmrg case "$arg" in 736fbed5abfSmrg -o) 737fbed5abfSmrg shift 738fbed5abfSmrg ;; 739fbed5abfSmrg $object) 740fbed5abfSmrg shift 741fbed5abfSmrg ;; 74217a48c7cSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74336e956c5Smrg set fnord "$@" 74436e956c5Smrg shift 74536e956c5Smrg shift 74636e956c5Smrg ;; 74717a48c7cSmrg *) 74836e956c5Smrg set fnord "$@" "$arg" 74936e956c5Smrg shift 75036e956c5Smrg shift 75136e956c5Smrg ;; 75217a48c7cSmrg esac 75317a48c7cSmrg done 754fbed5abfSmrg "$@" -E 2>/dev/null | 755fbed5abfSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75617a48c7cSmrg rm -f "$depfile" 75717a48c7cSmrg echo "$object : \\" > "$depfile" 75836e956c5Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75936e956c5Smrg echo "$tab" >> "$depfile" 760fbed5abfSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76117a48c7cSmrg rm -f "$tmpdepfile" 76217a48c7cSmrg ;; 76317a48c7cSmrg 764fbed5abfSmrgmsvcmsys) 765fbed5abfSmrg # This case exists only to let depend.m4 do its work. It works by 766fbed5abfSmrg # looking at the text of this script. This case will never be run, 767fbed5abfSmrg # since it is checked for above. 768fbed5abfSmrg exit 1 769fbed5abfSmrg ;; 770fbed5abfSmrg 77117a48c7cSmrgnone) 77217a48c7cSmrg exec "$@" 77317a48c7cSmrg ;; 77417a48c7cSmrg 77517a48c7cSmrg*) 77617a48c7cSmrg echo "Unknown depmode $depmode" 1>&2 77717a48c7cSmrg exit 1 77817a48c7cSmrg ;; 77917a48c7cSmrgesac 78017a48c7cSmrg 78117a48c7cSmrgexit 0 78217a48c7cSmrg 78317a48c7cSmrg# Local Variables: 78417a48c7cSmrg# mode: shell-script 78517a48c7cSmrg# sh-indentation: 2 78617a48c7cSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 78717a48c7cSmrg# time-stamp-start: "scriptversion=" 78817a48c7cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789fbed5abfSmrg# time-stamp-time-zone: "UTC" 790fbed5abfSmrg# time-stamp-end: "; # UTC" 79117a48c7cSmrg# End: 792