depcomp revision a67f45c3
176910425Smrg#! /bin/sh 276910425Smrg# depcomp - compile a program generating dependencies as side-effects 376910425Smrg 4a67f45c3Smrgscriptversion=2018-03-07.03; # UTC 576910425Smrg 6a67f45c3Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 776910425Smrg 876910425Smrg# This program is free software; you can redistribute it and/or modify 976910425Smrg# it under the terms of the GNU General Public License as published by 1076910425Smrg# the Free Software Foundation; either version 2, or (at your option) 1176910425Smrg# any later version. 1276910425Smrg 1376910425Smrg# This program is distributed in the hope that it will be useful, 1476910425Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1576910425Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1676910425Smrg# GNU General Public License for more details. 1776910425Smrg 1876910425Smrg# You should have received a copy of the GNU General Public License 19a67f45c3Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2076910425Smrg 2176910425Smrg# As a special exception to the GNU General Public License, if you 2276910425Smrg# distribute this file as part of a program that contains a 2376910425Smrg# configuration script generated by Autoconf, you may include it under 2476910425Smrg# the same distribution terms that you use for the rest of that program. 2576910425Smrg 2676910425Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2776910425Smrg 2876910425Smrgcase $1 in 2976910425Smrg '') 309ff100acSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 319ff100acSmrg exit 1; 329ff100acSmrg ;; 3376910425Smrg -h | --h*) 3476910425Smrg cat <<\EOF 3576910425SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3676910425Smrg 3776910425SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3876910425Smrgas side-effects. 3976910425Smrg 4076910425SmrgEnvironment variables: 4176910425Smrg depmode Dependency tracking mode. 429ff100acSmrg source Source file read by 'PROGRAMS ARGS'. 439ff100acSmrg object Object file output by 'PROGRAMS ARGS'. 4476910425Smrg DEPDIR directory where to store dependencies. 4576910425Smrg depfile Dependency file to output. 469ff100acSmrg tmpdepfile Temporary file to use when outputting dependencies. 4776910425Smrg libtool Whether libtool is used (yes/no). 4876910425Smrg 4976910425SmrgReport bugs to <bug-automake@gnu.org>. 5076910425SmrgEOF 5176910425Smrg exit $? 5276910425Smrg ;; 5376910425Smrg -v | --v*) 5476910425Smrg echo "depcomp $scriptversion" 5576910425Smrg exit $? 5676910425Smrg ;; 5776910425Smrgesac 5876910425Smrg 599ff100acSmrg# Get the directory component of the given path, and save it in the 609ff100acSmrg# global variables '$dir'. Note that this directory component will 619ff100acSmrg# be either empty or ending with a '/' character. This is deliberate. 629ff100acSmrgset_dir_from () 639ff100acSmrg{ 649ff100acSmrg case $1 in 659ff100acSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 669ff100acSmrg *) dir=;; 679ff100acSmrg esac 689ff100acSmrg} 699ff100acSmrg 709ff100acSmrg# Get the suffix-stripped basename of the given path, and save it the 719ff100acSmrg# global variable '$base'. 729ff100acSmrgset_base_from () 739ff100acSmrg{ 749ff100acSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 759ff100acSmrg} 769ff100acSmrg 779ff100acSmrg# If no dependency file was actually created by the compiler invocation, 789ff100acSmrg# we still have to create a dummy depfile, to avoid errors with the 799ff100acSmrg# Makefile "include basename.Plo" scheme. 809ff100acSmrgmake_dummy_depfile () 819ff100acSmrg{ 829ff100acSmrg echo "#dummy" > "$depfile" 839ff100acSmrg} 849ff100acSmrg 859ff100acSmrg# Factor out some common post-processing of the generated depfile. 869ff100acSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 879ff100acSmrgaix_post_process_depfile () 889ff100acSmrg{ 899ff100acSmrg # If the compiler actually managed to produce a dependency file, 909ff100acSmrg # post-process it. 919ff100acSmrg if test -f "$tmpdepfile"; then 929ff100acSmrg # Each line is of the form 'foo.o: dependency.h'. 939ff100acSmrg # Do two passes, one to just change these to 949ff100acSmrg # $object: dependency.h 959ff100acSmrg # and one to simply output 969ff100acSmrg # dependency.h: 979ff100acSmrg # which is needed to avoid the deleted-header problem. 989ff100acSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 999ff100acSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1009ff100acSmrg } > "$depfile" 1019ff100acSmrg rm -f "$tmpdepfile" 1029ff100acSmrg else 1039ff100acSmrg make_dummy_depfile 1049ff100acSmrg fi 1059ff100acSmrg} 1069ff100acSmrg 1079ff100acSmrg# A tabulation character. 1089ff100acSmrgtab=' ' 1099ff100acSmrg# A newline character. 1109ff100acSmrgnl=' 1119ff100acSmrg' 1129ff100acSmrg# Character ranges might be problematic outside the C locale. 1139ff100acSmrg# These definitions help. 1149ff100acSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1159ff100acSmrglower=abcdefghijklmnopqrstuvwxyz 1169ff100acSmrgdigits=0123456789 1179ff100acSmrgalpha=${upper}${lower} 1189ff100acSmrg 11976910425Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12076910425Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12176910425Smrg exit 1 12276910425Smrgfi 12376910425Smrg 12476910425Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12576910425Smrgdepfile=${depfile-`echo "$object" | 12676910425Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12776910425Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12876910425Smrg 12976910425Smrgrm -f "$tmpdepfile" 13076910425Smrg 1319ff100acSmrg# Avoid interferences from the environment. 1329ff100acSmrggccflag= dashmflag= 1339ff100acSmrg 13476910425Smrg# Some modes work just like other modes, but use different flags. We 13576910425Smrg# parameterize here, but still list the modes in the big case below, 13676910425Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13776910425Smrg# here, because this file can only contain one case statement. 13876910425Smrgif test "$depmode" = hp; then 13976910425Smrg # HP compiler uses -M and no extra arg. 14076910425Smrg gccflag=-M 14176910425Smrg depmode=gcc 14276910425Smrgfi 14376910425Smrg 14476910425Smrgif test "$depmode" = dashXmstdout; then 1459ff100acSmrg # This is just like dashmstdout with a different argument. 1469ff100acSmrg dashmflag=-xM 1479ff100acSmrg depmode=dashmstdout 14876910425Smrgfi 14976910425Smrg 150db17cd6dSmrgcygpath_u="cygpath -u -f -" 151db17cd6dSmrgif test "$depmode" = msvcmsys; then 1529ff100acSmrg # This is just like msvisualcpp but w/o cygpath translation. 1539ff100acSmrg # Just convert the backslash-escaped backslashes to single forward 1549ff100acSmrg # slashes to satisfy depend.m4 1559ff100acSmrg cygpath_u='sed s,\\\\,/,g' 1569ff100acSmrg depmode=msvisualcpp 1579ff100acSmrgfi 1589ff100acSmrg 1599ff100acSmrgif test "$depmode" = msvc7msys; then 1609ff100acSmrg # This is just like msvc7 but w/o cygpath translation. 1619ff100acSmrg # Just convert the backslash-escaped backslashes to single forward 1629ff100acSmrg # slashes to satisfy depend.m4 1639ff100acSmrg cygpath_u='sed s,\\\\,/,g' 1649ff100acSmrg depmode=msvc7 1659ff100acSmrgfi 1669ff100acSmrg 1679ff100acSmrgif test "$depmode" = xlc; then 1689ff100acSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1699ff100acSmrg gccflag=-qmakedep=gcc,-MF 1709ff100acSmrg depmode=gcc 171db17cd6dSmrgfi 172db17cd6dSmrg 17376910425Smrgcase "$depmode" in 17476910425Smrggcc3) 17576910425Smrg## gcc 3 implements dependency tracking that does exactly what 17676910425Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17776910425Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178db17cd6dSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179db17cd6dSmrg## the command line argument order; so add the flags where they 180db17cd6dSmrg## appear in depend2.am. Note that the slowdown incurred here 181db17cd6dSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182db17cd6dSmrg for arg 183db17cd6dSmrg do 184db17cd6dSmrg case $arg in 185db17cd6dSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186db17cd6dSmrg *) set fnord "$@" "$arg" ;; 187db17cd6dSmrg esac 188db17cd6dSmrg shift # fnord 189db17cd6dSmrg shift # $arg 190db17cd6dSmrg done 191db17cd6dSmrg "$@" 19276910425Smrg stat=$? 1939ff100acSmrg if test $stat -ne 0; then 19476910425Smrg rm -f "$tmpdepfile" 19576910425Smrg exit $stat 19676910425Smrg fi 19776910425Smrg mv "$tmpdepfile" "$depfile" 19876910425Smrg ;; 19976910425Smrg 20076910425Smrggcc) 2019ff100acSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2029ff100acSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2039ff100acSmrg## (see the conditional assignment to $gccflag above). 20476910425Smrg## There are various ways to get dependency output from gcc. Here's 20576910425Smrg## why we pick this rather obscure method: 20676910425Smrg## - Don't want to use -MD because we'd like the dependencies to end 20776910425Smrg## up in a subdir. Having to rename by hand is ugly. 20876910425Smrg## (We might end up doing this anyway to support other compilers.) 20976910425Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2109ff100acSmrg## -MM, not -M (despite what the docs say). Also, it might not be 2119ff100acSmrg## supported by the other compilers which use the 'gcc' depmode. 21276910425Smrg## - Using -M directly means running the compiler twice (even worse 21376910425Smrg## than renaming). 21476910425Smrg if test -z "$gccflag"; then 21576910425Smrg gccflag=-MD, 21676910425Smrg fi 21776910425Smrg "$@" -Wp,"$gccflag$tmpdepfile" 21876910425Smrg stat=$? 2199ff100acSmrg if test $stat -ne 0; then 22076910425Smrg rm -f "$tmpdepfile" 22176910425Smrg exit $stat 22276910425Smrg fi 22376910425Smrg rm -f "$depfile" 22476910425Smrg echo "$object : \\" > "$depfile" 2259ff100acSmrg # The second -e expression handles DOS-style file names with drive 2269ff100acSmrg # letters. 22776910425Smrg sed -e 's/^[^:]*: / /' \ 22876910425Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2299ff100acSmrg## This next piece of magic avoids the "deleted header file" problem. 23076910425Smrg## The problem is that when a header file which appears in a .P file 23176910425Smrg## is deleted, the dependency causes make to die (because there is 23276910425Smrg## typically no way to rebuild the header). We avoid this by adding 23376910425Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 23476910425Smrg## this for us directly. 2359ff100acSmrg## Some versions of gcc put a space before the ':'. On the theory 23676910425Smrg## that the space means something, we add a space to the output as 2379ff100acSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 2389ff100acSmrg## to the object. Take care to not repeat it in the output. 23976910425Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 24076910425Smrg## correctly. Breaking it into two sed invocations is a workaround. 2419ff100acSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2429ff100acSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2439ff100acSmrg | sed -e 's/$/ :/' >> "$depfile" 24476910425Smrg rm -f "$tmpdepfile" 24576910425Smrg ;; 24676910425Smrg 24776910425Smrghp) 24876910425Smrg # This case exists only to let depend.m4 do its work. It works by 24976910425Smrg # looking at the text of this script. This case will never be run, 25076910425Smrg # since it is checked for above. 25176910425Smrg exit 1 25276910425Smrg ;; 25376910425Smrg 25476910425Smrgsgi) 25576910425Smrg if test "$libtool" = yes; then 25676910425Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25776910425Smrg else 25876910425Smrg "$@" -MDupdate "$tmpdepfile" 25976910425Smrg fi 26076910425Smrg stat=$? 2619ff100acSmrg if test $stat -ne 0; then 26276910425Smrg rm -f "$tmpdepfile" 26376910425Smrg exit $stat 26476910425Smrg fi 26576910425Smrg rm -f "$depfile" 26676910425Smrg 26776910425Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26876910425Smrg echo "$object : \\" > "$depfile" 26976910425Smrg # Clip off the initial element (the dependent). Don't try to be 27076910425Smrg # clever and replace this with sed code, as IRIX sed won't handle 27176910425Smrg # lines with more than a fixed number of characters (4096 in 27276910425Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2739ff100acSmrg # the IRIX cc adds comments like '#:fec' to the end of the 27476910425Smrg # dependency line. 2759ff100acSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2769ff100acSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2779ff100acSmrg | tr "$nl" ' ' >> "$depfile" 278db17cd6dSmrg echo >> "$depfile" 27976910425Smrg # The second pass generates a dummy entry for each header file. 2809ff100acSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2819ff100acSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2829ff100acSmrg >> "$depfile" 28376910425Smrg else 2849ff100acSmrg make_dummy_depfile 28576910425Smrg fi 28676910425Smrg rm -f "$tmpdepfile" 28776910425Smrg ;; 28876910425Smrg 2899ff100acSmrgxlc) 2909ff100acSmrg # This case exists only to let depend.m4 do its work. It works by 2919ff100acSmrg # looking at the text of this script. This case will never be run, 2929ff100acSmrg # since it is checked for above. 2939ff100acSmrg exit 1 2949ff100acSmrg ;; 2959ff100acSmrg 29676910425Smrgaix) 29776910425Smrg # The C for AIX Compiler uses -M and outputs the dependencies 29876910425Smrg # in a .u file. In older versions, this file always lives in the 2999ff100acSmrg # current directory. Also, the AIX compiler puts '$object:' at the 30076910425Smrg # start of each line; $object doesn't have directory information. 30176910425Smrg # Version 6 uses the directory in both cases. 3029ff100acSmrg set_dir_from "$object" 3039ff100acSmrg set_base_from "$object" 30476910425Smrg if test "$libtool" = yes; then 305db17cd6dSmrg tmpdepfile1=$dir$base.u 306db17cd6dSmrg tmpdepfile2=$base.u 307db17cd6dSmrg tmpdepfile3=$dir.libs/$base.u 30876910425Smrg "$@" -Wc,-M 30976910425Smrg else 310db17cd6dSmrg tmpdepfile1=$dir$base.u 311db17cd6dSmrg tmpdepfile2=$dir$base.u 312db17cd6dSmrg tmpdepfile3=$dir$base.u 31376910425Smrg "$@" -M 31476910425Smrg fi 31576910425Smrg stat=$? 3169ff100acSmrg if test $stat -ne 0; then 317db17cd6dSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31876910425Smrg exit $stat 31976910425Smrg fi 32076910425Smrg 321db17cd6dSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322db17cd6dSmrg do 323db17cd6dSmrg test -f "$tmpdepfile" && break 324db17cd6dSmrg done 3259ff100acSmrg aix_post_process_depfile 3269ff100acSmrg ;; 3279ff100acSmrg 3289ff100acSmrgtcc) 3299ff100acSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3309ff100acSmrg # FIXME: That version still under development at the moment of writing. 3319ff100acSmrg # Make that this statement remains true also for stable, released 3329ff100acSmrg # versions. 3339ff100acSmrg # It will wrap lines (doesn't matter whether long or short) with a 3349ff100acSmrg # trailing '\', as in: 3359ff100acSmrg # 3369ff100acSmrg # foo.o : \ 3379ff100acSmrg # foo.c \ 3389ff100acSmrg # foo.h \ 3399ff100acSmrg # 3409ff100acSmrg # It will put a trailing '\' even on the last line, and will use leading 3419ff100acSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 3429ff100acSmrg # "Emit spaces for -MD"). 3439ff100acSmrg "$@" -MD -MF "$tmpdepfile" 3449ff100acSmrg stat=$? 3459ff100acSmrg if test $stat -ne 0; then 3469ff100acSmrg rm -f "$tmpdepfile" 3479ff100acSmrg exit $stat 34876910425Smrg fi 3499ff100acSmrg rm -f "$depfile" 3509ff100acSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3519ff100acSmrg # We have to change lines of the first kind to '$object: \'. 3529ff100acSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3539ff100acSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 3549ff100acSmrg # dummy dependency, to avoid the deleted-header problem. 3559ff100acSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35676910425Smrg rm -f "$tmpdepfile" 35776910425Smrg ;; 35876910425Smrg 3599ff100acSmrg## The order of this option in the case statement is important, since the 3609ff100acSmrg## shell code in configure will try each of these formats in the order 3619ff100acSmrg## listed in this file. A plain '-MD' option would be understood by many 3629ff100acSmrg## compilers, so we must ensure this comes after the gcc and icc options. 3639ff100acSmrgpgcc) 3649ff100acSmrg # Portland's C compiler understands '-MD'. 3659ff100acSmrg # Will always output deps to 'file.d' where file is the root name of the 3669ff100acSmrg # source file under compilation, even if file resides in a subdirectory. 3679ff100acSmrg # The object file name does not affect the name of the '.d' file. 3689ff100acSmrg # pgcc 10.2 will output 36976910425Smrg # foo.o: sub/foo.c sub/foo.h 3709ff100acSmrg # and will wrap long lines using '\' : 37176910425Smrg # foo.o: sub/foo.c ... \ 37276910425Smrg # sub/foo.h ... \ 37376910425Smrg # ... 3749ff100acSmrg set_dir_from "$object" 3759ff100acSmrg # Use the source, not the object, to determine the base name, since 3769ff100acSmrg # that's sadly what pgcc will do too. 3779ff100acSmrg set_base_from "$source" 3789ff100acSmrg tmpdepfile=$base.d 3799ff100acSmrg 3809ff100acSmrg # For projects that build the same source file twice into different object 3819ff100acSmrg # files, the pgcc approach of using the *source* file root name can cause 3829ff100acSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3839ff100acSmrg # the same $tmpdepfile. 3849ff100acSmrg lockdir=$base.d-lock 3859ff100acSmrg trap " 3869ff100acSmrg echo '$0: caught signal, cleaning up...' >&2 3879ff100acSmrg rmdir '$lockdir' 3889ff100acSmrg exit 1 3899ff100acSmrg " 1 2 13 15 3909ff100acSmrg numtries=100 3919ff100acSmrg i=$numtries 3929ff100acSmrg while test $i -gt 0; do 3939ff100acSmrg # mkdir is a portable test-and-set. 3949ff100acSmrg if mkdir "$lockdir" 2>/dev/null; then 3959ff100acSmrg # This process acquired the lock. 3969ff100acSmrg "$@" -MD 3979ff100acSmrg stat=$? 3989ff100acSmrg # Release the lock. 3999ff100acSmrg rmdir "$lockdir" 4009ff100acSmrg break 4019ff100acSmrg else 4029ff100acSmrg # If the lock is being held by a different process, wait 4039ff100acSmrg # until the winning process is done or we timeout. 4049ff100acSmrg while test -d "$lockdir" && test $i -gt 0; do 4059ff100acSmrg sleep 1 4069ff100acSmrg i=`expr $i - 1` 4079ff100acSmrg done 4089ff100acSmrg fi 4099ff100acSmrg i=`expr $i - 1` 4109ff100acSmrg done 4119ff100acSmrg trap - 1 2 13 15 4129ff100acSmrg if test $i -le 0; then 4139ff100acSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4149ff100acSmrg echo "$0: check lockdir '$lockdir'" >&2 4159ff100acSmrg exit 1 4169ff100acSmrg fi 41776910425Smrg 4189ff100acSmrg if test $stat -ne 0; then 41976910425Smrg rm -f "$tmpdepfile" 42076910425Smrg exit $stat 42176910425Smrg fi 42276910425Smrg rm -f "$depfile" 42376910425Smrg # Each line is of the form `foo.o: dependent.h', 42476910425Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42576910425Smrg # Do two passes, one to just change these to 42676910425Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 42776910425Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42876910425Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 42976910425Smrg # correctly. Breaking it into two sed invocations is a workaround. 4309ff100acSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4319ff100acSmrg | sed -e 's/$/ :/' >> "$depfile" 43276910425Smrg rm -f "$tmpdepfile" 43376910425Smrg ;; 43476910425Smrg 435db17cd6dSmrghp2) 436db17cd6dSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437db17cd6dSmrg # compilers, which have integrated preprocessors. The correct option 438db17cd6dSmrg # to use with these is +Maked; it writes dependencies to a file named 439db17cd6dSmrg # 'foo.d', which lands next to the object file, wherever that 440db17cd6dSmrg # happens to be. 441db17cd6dSmrg # Much of this is similar to the tru64 case; see comments there. 4429ff100acSmrg set_dir_from "$object" 4439ff100acSmrg set_base_from "$object" 444db17cd6dSmrg if test "$libtool" = yes; then 445db17cd6dSmrg tmpdepfile1=$dir$base.d 446db17cd6dSmrg tmpdepfile2=$dir.libs/$base.d 447db17cd6dSmrg "$@" -Wc,+Maked 448db17cd6dSmrg else 449db17cd6dSmrg tmpdepfile1=$dir$base.d 450db17cd6dSmrg tmpdepfile2=$dir$base.d 451db17cd6dSmrg "$@" +Maked 452db17cd6dSmrg fi 453db17cd6dSmrg stat=$? 4549ff100acSmrg if test $stat -ne 0; then 455db17cd6dSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456db17cd6dSmrg exit $stat 457db17cd6dSmrg fi 458db17cd6dSmrg 459db17cd6dSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460db17cd6dSmrg do 461db17cd6dSmrg test -f "$tmpdepfile" && break 462db17cd6dSmrg done 463db17cd6dSmrg if test -f "$tmpdepfile"; then 4649ff100acSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4659ff100acSmrg # Add 'dependent.h:' lines. 466db17cd6dSmrg sed -ne '2,${ 4679ff100acSmrg s/^ *// 4689ff100acSmrg s/ \\*$// 4699ff100acSmrg s/$/:/ 4709ff100acSmrg p 4719ff100acSmrg }' "$tmpdepfile" >> "$depfile" 472db17cd6dSmrg else 4739ff100acSmrg make_dummy_depfile 474db17cd6dSmrg fi 475db17cd6dSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 476db17cd6dSmrg ;; 477db17cd6dSmrg 47876910425Smrgtru64) 4799ff100acSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 4809ff100acSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4819ff100acSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4829ff100acSmrg # dependencies in 'foo.d' instead, so we check for that too. 4839ff100acSmrg # Subdirectories are respected. 4849ff100acSmrg set_dir_from "$object" 4859ff100acSmrg set_base_from "$object" 4869ff100acSmrg 4879ff100acSmrg if test "$libtool" = yes; then 4889ff100acSmrg # Libtool generates 2 separate objects for the 2 libraries. These 4899ff100acSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 4909ff100acSmrg # in $dir$base.o.d. We have to check for both files, because 4919ff100acSmrg # one of the two compilations can be disabled. We should prefer 4929ff100acSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4939ff100acSmrg # automatically cleaned when .libs/ is deleted, while ignoring 4949ff100acSmrg # the former would cause a distcleancheck panic. 4959ff100acSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4969ff100acSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4979ff100acSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4989ff100acSmrg "$@" -Wc,-MD 4999ff100acSmrg else 5009ff100acSmrg tmpdepfile1=$dir$base.d 5019ff100acSmrg tmpdepfile2=$dir$base.d 5029ff100acSmrg tmpdepfile3=$dir$base.d 5039ff100acSmrg "$@" -MD 5049ff100acSmrg fi 5059ff100acSmrg 5069ff100acSmrg stat=$? 5079ff100acSmrg if test $stat -ne 0; then 5089ff100acSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5099ff100acSmrg exit $stat 5109ff100acSmrg fi 5119ff100acSmrg 5129ff100acSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5139ff100acSmrg do 5149ff100acSmrg test -f "$tmpdepfile" && break 5159ff100acSmrg done 5169ff100acSmrg # Same post-processing that is required for AIX mode. 5179ff100acSmrg aix_post_process_depfile 5189ff100acSmrg ;; 5199ff100acSmrg 5209ff100acSmrgmsvc7) 5219ff100acSmrg if test "$libtool" = yes; then 5229ff100acSmrg showIncludes=-Wc,-showIncludes 5239ff100acSmrg else 5249ff100acSmrg showIncludes=-showIncludes 5259ff100acSmrg fi 5269ff100acSmrg "$@" $showIncludes > "$tmpdepfile" 5279ff100acSmrg stat=$? 5289ff100acSmrg grep -v '^Note: including file: ' "$tmpdepfile" 5299ff100acSmrg if test $stat -ne 0; then 5309ff100acSmrg rm -f "$tmpdepfile" 5319ff100acSmrg exit $stat 5329ff100acSmrg fi 5339ff100acSmrg rm -f "$depfile" 5349ff100acSmrg echo "$object : \\" > "$depfile" 5359ff100acSmrg # The first sed program below extracts the file names and escapes 5369ff100acSmrg # backslashes for cygpath. The second sed program outputs the file 5379ff100acSmrg # name when reading, but also accumulates all include files in the 5389ff100acSmrg # hold buffer in order to output them again at the end. This only 5399ff100acSmrg # works with sed implementations that can handle large buffers. 5409ff100acSmrg sed < "$tmpdepfile" -n ' 5419ff100acSmrg/^Note: including file: *\(.*\)/ { 5429ff100acSmrg s//\1/ 5439ff100acSmrg s/\\/\\\\/g 5449ff100acSmrg p 5459ff100acSmrg}' | $cygpath_u | sort -u | sed -n ' 5469ff100acSmrgs/ /\\ /g 5479ff100acSmrgs/\(.*\)/'"$tab"'\1 \\/p 5489ff100acSmrgs/.\(.*\) \\/\1:/ 5499ff100acSmrgH 5509ff100acSmrg$ { 5519ff100acSmrg s/.*/'"$tab"'/ 5529ff100acSmrg G 5539ff100acSmrg p 5549ff100acSmrg}' >> "$depfile" 5559ff100acSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5569ff100acSmrg rm -f "$tmpdepfile" 5579ff100acSmrg ;; 5589ff100acSmrg 5599ff100acSmrgmsvc7msys) 5609ff100acSmrg # This case exists only to let depend.m4 do its work. It works by 5619ff100acSmrg # looking at the text of this script. This case will never be run, 5629ff100acSmrg # since it is checked for above. 5639ff100acSmrg exit 1 5649ff100acSmrg ;; 56576910425Smrg 56676910425Smrg#nosideeffect) 56776910425Smrg # This comment above is used by automake to tell side-effect 56876910425Smrg # dependency tracking mechanisms from slower ones. 56976910425Smrg 57076910425Smrgdashmstdout) 57176910425Smrg # Important note: in order to support this mode, a compiler *must* 57276910425Smrg # always write the preprocessed file to stdout, regardless of -o. 57376910425Smrg "$@" || exit $? 57476910425Smrg 57576910425Smrg # Remove the call to Libtool. 57676910425Smrg if test "$libtool" = yes; then 577db17cd6dSmrg while test "X$1" != 'X--mode=compile'; do 57876910425Smrg shift 57976910425Smrg done 58076910425Smrg shift 58176910425Smrg fi 58276910425Smrg 5839ff100acSmrg # Remove '-o $object'. 58476910425Smrg IFS=" " 58576910425Smrg for arg 58676910425Smrg do 58776910425Smrg case $arg in 58876910425Smrg -o) 58976910425Smrg shift 59076910425Smrg ;; 59176910425Smrg $object) 59276910425Smrg shift 59376910425Smrg ;; 59476910425Smrg *) 59576910425Smrg set fnord "$@" "$arg" 59676910425Smrg shift # fnord 59776910425Smrg shift # $arg 59876910425Smrg ;; 59976910425Smrg esac 60076910425Smrg done 60176910425Smrg 60276910425Smrg test -z "$dashmflag" && dashmflag=-M 6039ff100acSmrg # Require at least two characters before searching for ':' 60476910425Smrg # in the target name. This is to cope with DOS-style filenames: 6059ff100acSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60676910425Smrg "$@" $dashmflag | 6079ff100acSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60876910425Smrg rm -f "$depfile" 60976910425Smrg cat < "$tmpdepfile" > "$depfile" 6109ff100acSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6119ff100acSmrg # correctly. Breaking it into two sed invocations is a workaround. 6129ff100acSmrg tr ' ' "$nl" < "$tmpdepfile" \ 6139ff100acSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6149ff100acSmrg | sed -e 's/$/ :/' >> "$depfile" 61576910425Smrg rm -f "$tmpdepfile" 61676910425Smrg ;; 61776910425Smrg 61876910425SmrgdashXmstdout) 61976910425Smrg # This case only exists to satisfy depend.m4. It is never actually 62076910425Smrg # run, as this mode is specially recognized in the preamble. 62176910425Smrg exit 1 62276910425Smrg ;; 62376910425Smrg 62476910425Smrgmakedepend) 62576910425Smrg "$@" || exit $? 62676910425Smrg # Remove any Libtool call 62776910425Smrg if test "$libtool" = yes; then 628db17cd6dSmrg while test "X$1" != 'X--mode=compile'; do 62976910425Smrg shift 63076910425Smrg done 63176910425Smrg shift 63276910425Smrg fi 63376910425Smrg # X makedepend 63476910425Smrg shift 635db17cd6dSmrg cleared=no eat=no 636db17cd6dSmrg for arg 637db17cd6dSmrg do 63876910425Smrg case $cleared in 63976910425Smrg no) 64076910425Smrg set ""; shift 64176910425Smrg cleared=yes ;; 64276910425Smrg esac 643db17cd6dSmrg if test $eat = yes; then 644db17cd6dSmrg eat=no 645db17cd6dSmrg continue 646db17cd6dSmrg fi 64776910425Smrg case "$arg" in 64876910425Smrg -D*|-I*) 64976910425Smrg set fnord "$@" "$arg"; shift ;; 65076910425Smrg # Strip any option that makedepend may not understand. Remove 65176910425Smrg # the object too, otherwise makedepend will parse it as a source file. 652db17cd6dSmrg -arch) 653db17cd6dSmrg eat=yes ;; 65476910425Smrg -*|$object) 65576910425Smrg ;; 65676910425Smrg *) 65776910425Smrg set fnord "$@" "$arg"; shift ;; 65876910425Smrg esac 65976910425Smrg done 660db17cd6dSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66176910425Smrg touch "$tmpdepfile" 66276910425Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66376910425Smrg rm -f "$depfile" 6649ff100acSmrg # makedepend may prepend the VPATH from the source file name to the object. 6659ff100acSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 6669ff100acSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6679ff100acSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6689ff100acSmrg # correctly. Breaking it into two sed invocations is a workaround. 6699ff100acSmrg sed '1,2d' "$tmpdepfile" \ 6709ff100acSmrg | tr ' ' "$nl" \ 6719ff100acSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6729ff100acSmrg | sed -e 's/$/ :/' >> "$depfile" 67376910425Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67476910425Smrg ;; 67576910425Smrg 67676910425Smrgcpp) 67776910425Smrg # Important note: in order to support this mode, a compiler *must* 67876910425Smrg # always write the preprocessed file to stdout. 67976910425Smrg "$@" || exit $? 68076910425Smrg 68176910425Smrg # Remove the call to Libtool. 68276910425Smrg if test "$libtool" = yes; then 683db17cd6dSmrg while test "X$1" != 'X--mode=compile'; do 68476910425Smrg shift 68576910425Smrg done 68676910425Smrg shift 68776910425Smrg fi 68876910425Smrg 6899ff100acSmrg # Remove '-o $object'. 69076910425Smrg IFS=" " 69176910425Smrg for arg 69276910425Smrg do 69376910425Smrg case $arg in 69476910425Smrg -o) 69576910425Smrg shift 69676910425Smrg ;; 69776910425Smrg $object) 69876910425Smrg shift 69976910425Smrg ;; 70076910425Smrg *) 70176910425Smrg set fnord "$@" "$arg" 70276910425Smrg shift # fnord 70376910425Smrg shift # $arg 70476910425Smrg ;; 70576910425Smrg esac 70676910425Smrg done 70776910425Smrg 7089ff100acSmrg "$@" -E \ 7099ff100acSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7109ff100acSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7119ff100acSmrg | sed '$ s: \\$::' > "$tmpdepfile" 71276910425Smrg rm -f "$depfile" 71376910425Smrg echo "$object : \\" > "$depfile" 71476910425Smrg cat < "$tmpdepfile" >> "$depfile" 71576910425Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71676910425Smrg rm -f "$tmpdepfile" 71776910425Smrg ;; 71876910425Smrg 71976910425Smrgmsvisualcpp) 72076910425Smrg # Important note: in order to support this mode, a compiler *must* 721db17cd6dSmrg # always write the preprocessed file to stdout. 72276910425Smrg "$@" || exit $? 723db17cd6dSmrg 724db17cd6dSmrg # Remove the call to Libtool. 725db17cd6dSmrg if test "$libtool" = yes; then 726db17cd6dSmrg while test "X$1" != 'X--mode=compile'; do 727db17cd6dSmrg shift 728db17cd6dSmrg done 729db17cd6dSmrg shift 730db17cd6dSmrg fi 731db17cd6dSmrg 73276910425Smrg IFS=" " 73376910425Smrg for arg 73476910425Smrg do 73576910425Smrg case "$arg" in 736db17cd6dSmrg -o) 737db17cd6dSmrg shift 738db17cd6dSmrg ;; 739db17cd6dSmrg $object) 740db17cd6dSmrg shift 741db17cd6dSmrg ;; 74276910425Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7439ff100acSmrg set fnord "$@" 7449ff100acSmrg shift 7459ff100acSmrg shift 7469ff100acSmrg ;; 74776910425Smrg *) 7489ff100acSmrg set fnord "$@" "$arg" 7499ff100acSmrg shift 7509ff100acSmrg shift 7519ff100acSmrg ;; 75276910425Smrg esac 75376910425Smrg done 754db17cd6dSmrg "$@" -E 2>/dev/null | 755db17cd6dSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75676910425Smrg rm -f "$depfile" 75776910425Smrg echo "$object : \\" > "$depfile" 7589ff100acSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7599ff100acSmrg echo "$tab" >> "$depfile" 760db17cd6dSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76176910425Smrg rm -f "$tmpdepfile" 76276910425Smrg ;; 76376910425Smrg 764db17cd6dSmrgmsvcmsys) 765db17cd6dSmrg # This case exists only to let depend.m4 do its work. It works by 766db17cd6dSmrg # looking at the text of this script. This case will never be run, 767db17cd6dSmrg # since it is checked for above. 768db17cd6dSmrg exit 1 769db17cd6dSmrg ;; 770db17cd6dSmrg 77176910425Smrgnone) 77276910425Smrg exec "$@" 77376910425Smrg ;; 77476910425Smrg 77576910425Smrg*) 77676910425Smrg echo "Unknown depmode $depmode" 1>&2 77776910425Smrg exit 1 77876910425Smrg ;; 77976910425Smrgesac 78076910425Smrg 78176910425Smrgexit 0 78276910425Smrg 78376910425Smrg# Local Variables: 78476910425Smrg# mode: shell-script 78576910425Smrg# sh-indentation: 2 786a67f45c3Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 78776910425Smrg# time-stamp-start: "scriptversion=" 78876910425Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789a67f45c3Smrg# time-stamp-time-zone: "UTC0" 790db17cd6dSmrg# time-stamp-end: "; # UTC" 79176910425Smrg# End: 792