depcomp revision 889a2364
121c2f794Smrg#! /bin/sh 221c2f794Smrg# depcomp - compile a program generating dependencies as side-effects 321c2f794Smrg 4889a2364Smrgscriptversion=2018-03-07.03; # UTC 521c2f794Smrg 6889a2364Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 721c2f794Smrg 821c2f794Smrg# This program is free software; you can redistribute it and/or modify 921c2f794Smrg# it under the terms of the GNU General Public License as published by 1021c2f794Smrg# the Free Software Foundation; either version 2, or (at your option) 1121c2f794Smrg# any later version. 1221c2f794Smrg 1321c2f794Smrg# This program is distributed in the hope that it will be useful, 1421c2f794Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1521c2f794Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1621c2f794Smrg# GNU General Public License for more details. 1721c2f794Smrg 1821c2f794Smrg# You should have received a copy of the GNU General Public License 19889a2364Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2021c2f794Smrg 2121c2f794Smrg# As a special exception to the GNU General Public License, if you 2221c2f794Smrg# distribute this file as part of a program that contains a 2321c2f794Smrg# configuration script generated by Autoconf, you may include it under 2421c2f794Smrg# the same distribution terms that you use for the rest of that program. 2521c2f794Smrg 2621c2f794Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2721c2f794Smrg 2821c2f794Smrgcase $1 in 2921c2f794Smrg '') 301b2353dbSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 311b2353dbSmrg exit 1; 321b2353dbSmrg ;; 3321c2f794Smrg -h | --h*) 3421c2f794Smrg cat <<\EOF 3521c2f794SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3621c2f794Smrg 3721c2f794SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3821c2f794Smrgas side-effects. 3921c2f794Smrg 4021c2f794SmrgEnvironment variables: 4121c2f794Smrg depmode Dependency tracking mode. 421b2353dbSmrg source Source file read by 'PROGRAMS ARGS'. 431b2353dbSmrg object Object file output by 'PROGRAMS ARGS'. 4421c2f794Smrg DEPDIR directory where to store dependencies. 4521c2f794Smrg depfile Dependency file to output. 4682e12b1bSmrg tmpdepfile Temporary file to use when outputting dependencies. 4721c2f794Smrg libtool Whether libtool is used (yes/no). 4821c2f794Smrg 4921c2f794SmrgReport bugs to <bug-automake@gnu.org>. 5021c2f794SmrgEOF 5121c2f794Smrg exit $? 5221c2f794Smrg ;; 5321c2f794Smrg -v | --v*) 5421c2f794Smrg echo "depcomp $scriptversion" 5521c2f794Smrg exit $? 5621c2f794Smrg ;; 5721c2f794Smrgesac 5821c2f794Smrg 591b2353dbSmrg# Get the directory component of the given path, and save it in the 601b2353dbSmrg# global variables '$dir'. Note that this directory component will 611b2353dbSmrg# be either empty or ending with a '/' character. This is deliberate. 621b2353dbSmrgset_dir_from () 631b2353dbSmrg{ 641b2353dbSmrg case $1 in 651b2353dbSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 661b2353dbSmrg *) dir=;; 671b2353dbSmrg esac 681b2353dbSmrg} 691b2353dbSmrg 701b2353dbSmrg# Get the suffix-stripped basename of the given path, and save it the 711b2353dbSmrg# global variable '$base'. 721b2353dbSmrgset_base_from () 731b2353dbSmrg{ 741b2353dbSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 751b2353dbSmrg} 761b2353dbSmrg 771b2353dbSmrg# If no dependency file was actually created by the compiler invocation, 781b2353dbSmrg# we still have to create a dummy depfile, to avoid errors with the 791b2353dbSmrg# Makefile "include basename.Plo" scheme. 801b2353dbSmrgmake_dummy_depfile () 811b2353dbSmrg{ 821b2353dbSmrg echo "#dummy" > "$depfile" 831b2353dbSmrg} 841b2353dbSmrg 851b2353dbSmrg# Factor out some common post-processing of the generated depfile. 861b2353dbSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 871b2353dbSmrgaix_post_process_depfile () 881b2353dbSmrg{ 891b2353dbSmrg # If the compiler actually managed to produce a dependency file, 901b2353dbSmrg # post-process it. 911b2353dbSmrg if test -f "$tmpdepfile"; then 921b2353dbSmrg # Each line is of the form 'foo.o: dependency.h'. 931b2353dbSmrg # Do two passes, one to just change these to 941b2353dbSmrg # $object: dependency.h 951b2353dbSmrg # and one to simply output 961b2353dbSmrg # dependency.h: 971b2353dbSmrg # which is needed to avoid the deleted-header problem. 981b2353dbSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 991b2353dbSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1001b2353dbSmrg } > "$depfile" 1011b2353dbSmrg rm -f "$tmpdepfile" 1021b2353dbSmrg else 1031b2353dbSmrg make_dummy_depfile 1041b2353dbSmrg fi 1051b2353dbSmrg} 1061b2353dbSmrg 1071b2353dbSmrg# A tabulation character. 1081b2353dbSmrgtab=' ' 1091b2353dbSmrg# A newline character. 1101b2353dbSmrgnl=' 1111b2353dbSmrg' 1121b2353dbSmrg# Character ranges might be problematic outside the C locale. 1131b2353dbSmrg# These definitions help. 1141b2353dbSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1151b2353dbSmrglower=abcdefghijklmnopqrstuvwxyz 1161b2353dbSmrgdigits=0123456789 1171b2353dbSmrgalpha=${upper}${lower} 1181b2353dbSmrg 11921c2f794Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12021c2f794Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12121c2f794Smrg exit 1 12221c2f794Smrgfi 12321c2f794Smrg 12421c2f794Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12521c2f794Smrgdepfile=${depfile-`echo "$object" | 12621c2f794Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12721c2f794Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12821c2f794Smrg 12921c2f794Smrgrm -f "$tmpdepfile" 13021c2f794Smrg 1311b2353dbSmrg# Avoid interferences from the environment. 1321b2353dbSmrggccflag= dashmflag= 1331b2353dbSmrg 13421c2f794Smrg# Some modes work just like other modes, but use different flags. We 13521c2f794Smrg# parameterize here, but still list the modes in the big case below, 13621c2f794Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13721c2f794Smrg# here, because this file can only contain one case statement. 13821c2f794Smrgif test "$depmode" = hp; then 13921c2f794Smrg # HP compiler uses -M and no extra arg. 14021c2f794Smrg gccflag=-M 14121c2f794Smrg depmode=gcc 14221c2f794Smrgfi 14321c2f794Smrg 14421c2f794Smrgif test "$depmode" = dashXmstdout; then 1451b2353dbSmrg # This is just like dashmstdout with a different argument. 1461b2353dbSmrg dashmflag=-xM 1471b2353dbSmrg depmode=dashmstdout 14821c2f794Smrgfi 14921c2f794Smrg 15012391620Smrgcygpath_u="cygpath -u -f -" 15112391620Smrgif test "$depmode" = msvcmsys; then 1521b2353dbSmrg # This is just like msvisualcpp but w/o cygpath translation. 1531b2353dbSmrg # Just convert the backslash-escaped backslashes to single forward 1541b2353dbSmrg # slashes to satisfy depend.m4 1551b2353dbSmrg cygpath_u='sed s,\\\\,/,g' 1561b2353dbSmrg depmode=msvisualcpp 15712391620Smrgfi 15812391620Smrg 15982e12b1bSmrgif test "$depmode" = msvc7msys; then 1601b2353dbSmrg # This is just like msvc7 but w/o cygpath translation. 1611b2353dbSmrg # Just convert the backslash-escaped backslashes to single forward 1621b2353dbSmrg # slashes to satisfy depend.m4 1631b2353dbSmrg cygpath_u='sed s,\\\\,/,g' 1641b2353dbSmrg depmode=msvc7 1651b2353dbSmrgfi 1661b2353dbSmrg 1671b2353dbSmrgif test "$depmode" = xlc; then 1681b2353dbSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1691b2353dbSmrg gccflag=-qmakedep=gcc,-MF 1701b2353dbSmrg depmode=gcc 17182e12b1bSmrgfi 17282e12b1bSmrg 17321c2f794Smrgcase "$depmode" in 17421c2f794Smrggcc3) 17521c2f794Smrg## gcc 3 implements dependency tracking that does exactly what 17621c2f794Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17721c2f794Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 17821c2f794Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 17921c2f794Smrg## the command line argument order; so add the flags where they 18021c2f794Smrg## appear in depend2.am. Note that the slowdown incurred here 18121c2f794Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 18221c2f794Smrg for arg 18321c2f794Smrg do 18421c2f794Smrg case $arg in 18521c2f794Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 18621c2f794Smrg *) set fnord "$@" "$arg" ;; 18721c2f794Smrg esac 18821c2f794Smrg shift # fnord 18921c2f794Smrg shift # $arg 19021c2f794Smrg done 19121c2f794Smrg "$@" 19221c2f794Smrg stat=$? 1931b2353dbSmrg if test $stat -ne 0; then 19421c2f794Smrg rm -f "$tmpdepfile" 19521c2f794Smrg exit $stat 19621c2f794Smrg fi 19721c2f794Smrg mv "$tmpdepfile" "$depfile" 19821c2f794Smrg ;; 19921c2f794Smrg 20021c2f794Smrggcc) 2011b2353dbSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2021b2353dbSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2031b2353dbSmrg## (see the conditional assignment to $gccflag above). 20421c2f794Smrg## There are various ways to get dependency output from gcc. Here's 20521c2f794Smrg## why we pick this rather obscure method: 20621c2f794Smrg## - Don't want to use -MD because we'd like the dependencies to end 20721c2f794Smrg## up in a subdir. Having to rename by hand is ugly. 20821c2f794Smrg## (We might end up doing this anyway to support other compilers.) 20921c2f794Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2101b2353dbSmrg## -MM, not -M (despite what the docs say). Also, it might not be 2111b2353dbSmrg## supported by the other compilers which use the 'gcc' depmode. 21221c2f794Smrg## - Using -M directly means running the compiler twice (even worse 21321c2f794Smrg## than renaming). 21421c2f794Smrg if test -z "$gccflag"; then 21521c2f794Smrg gccflag=-MD, 21621c2f794Smrg fi 21721c2f794Smrg "$@" -Wp,"$gccflag$tmpdepfile" 21821c2f794Smrg stat=$? 2191b2353dbSmrg if test $stat -ne 0; then 22021c2f794Smrg rm -f "$tmpdepfile" 22121c2f794Smrg exit $stat 22221c2f794Smrg fi 22321c2f794Smrg rm -f "$depfile" 22421c2f794Smrg echo "$object : \\" > "$depfile" 2251b2353dbSmrg # The second -e expression handles DOS-style file names with drive 2261b2353dbSmrg # letters. 22721c2f794Smrg sed -e 's/^[^:]*: / /' \ 22821c2f794Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2291b2353dbSmrg## This next piece of magic avoids the "deleted header file" problem. 23021c2f794Smrg## The problem is that when a header file which appears in a .P file 23121c2f794Smrg## is deleted, the dependency causes make to die (because there is 23221c2f794Smrg## typically no way to rebuild the header). We avoid this by adding 23321c2f794Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 23421c2f794Smrg## this for us directly. 2351b2353dbSmrg## Some versions of gcc put a space before the ':'. On the theory 23621c2f794Smrg## that the space means something, we add a space to the output as 23782e12b1bSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 23882e12b1bSmrg## to the object. Take care to not repeat it in the output. 23921c2f794Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 24021c2f794Smrg## correctly. Breaking it into two sed invocations is a workaround. 2411b2353dbSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2421b2353dbSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2431b2353dbSmrg | sed -e 's/$/ :/' >> "$depfile" 24421c2f794Smrg rm -f "$tmpdepfile" 24521c2f794Smrg ;; 24621c2f794Smrg 24721c2f794Smrghp) 24821c2f794Smrg # This case exists only to let depend.m4 do its work. It works by 24921c2f794Smrg # looking at the text of this script. This case will never be run, 25021c2f794Smrg # since it is checked for above. 25121c2f794Smrg exit 1 25221c2f794Smrg ;; 25321c2f794Smrg 25421c2f794Smrgsgi) 25521c2f794Smrg if test "$libtool" = yes; then 25621c2f794Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25721c2f794Smrg else 25821c2f794Smrg "$@" -MDupdate "$tmpdepfile" 25921c2f794Smrg fi 26021c2f794Smrg stat=$? 2611b2353dbSmrg if test $stat -ne 0; then 26221c2f794Smrg rm -f "$tmpdepfile" 26321c2f794Smrg exit $stat 26421c2f794Smrg fi 26521c2f794Smrg rm -f "$depfile" 26621c2f794Smrg 26721c2f794Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26821c2f794Smrg echo "$object : \\" > "$depfile" 26921c2f794Smrg # Clip off the initial element (the dependent). Don't try to be 27021c2f794Smrg # clever and replace this with sed code, as IRIX sed won't handle 27121c2f794Smrg # lines with more than a fixed number of characters (4096 in 27221c2f794Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2731b2353dbSmrg # the IRIX cc adds comments like '#:fec' to the end of the 27421c2f794Smrg # dependency line. 2751b2353dbSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2761b2353dbSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2771b2353dbSmrg | tr "$nl" ' ' >> "$depfile" 27812391620Smrg echo >> "$depfile" 27921c2f794Smrg # The second pass generates a dummy entry for each header file. 2801b2353dbSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2811b2353dbSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2821b2353dbSmrg >> "$depfile" 28321c2f794Smrg else 2841b2353dbSmrg make_dummy_depfile 28521c2f794Smrg fi 28621c2f794Smrg rm -f "$tmpdepfile" 28721c2f794Smrg ;; 28821c2f794Smrg 2891b2353dbSmrgxlc) 2901b2353dbSmrg # This case exists only to let depend.m4 do its work. It works by 2911b2353dbSmrg # looking at the text of this script. This case will never be run, 2921b2353dbSmrg # since it is checked for above. 2931b2353dbSmrg exit 1 2941b2353dbSmrg ;; 2951b2353dbSmrg 29621c2f794Smrgaix) 29721c2f794Smrg # The C for AIX Compiler uses -M and outputs the dependencies 29821c2f794Smrg # in a .u file. In older versions, this file always lives in the 2991b2353dbSmrg # current directory. Also, the AIX compiler puts '$object:' at the 30021c2f794Smrg # start of each line; $object doesn't have directory information. 30121c2f794Smrg # Version 6 uses the directory in both cases. 3021b2353dbSmrg set_dir_from "$object" 3031b2353dbSmrg set_base_from "$object" 30421c2f794Smrg if test "$libtool" = yes; then 30512391620Smrg tmpdepfile1=$dir$base.u 30612391620Smrg tmpdepfile2=$base.u 30712391620Smrg tmpdepfile3=$dir.libs/$base.u 30821c2f794Smrg "$@" -Wc,-M 30921c2f794Smrg else 31012391620Smrg tmpdepfile1=$dir$base.u 31112391620Smrg tmpdepfile2=$dir$base.u 31212391620Smrg tmpdepfile3=$dir$base.u 31321c2f794Smrg "$@" -M 31421c2f794Smrg fi 31521c2f794Smrg stat=$? 3161b2353dbSmrg if test $stat -ne 0; then 31712391620Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31821c2f794Smrg exit $stat 31921c2f794Smrg fi 32021c2f794Smrg 32112391620Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32212391620Smrg do 32312391620Smrg test -f "$tmpdepfile" && break 32412391620Smrg done 3251b2353dbSmrg aix_post_process_depfile 3261b2353dbSmrg ;; 3271b2353dbSmrg 3281b2353dbSmrgtcc) 3291b2353dbSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3301b2353dbSmrg # FIXME: That version still under development at the moment of writing. 3311b2353dbSmrg # Make that this statement remains true also for stable, released 3321b2353dbSmrg # versions. 3331b2353dbSmrg # It will wrap lines (doesn't matter whether long or short) with a 3341b2353dbSmrg # trailing '\', as in: 3351b2353dbSmrg # 3361b2353dbSmrg # foo.o : \ 3371b2353dbSmrg # foo.c \ 3381b2353dbSmrg # foo.h \ 3391b2353dbSmrg # 3401b2353dbSmrg # It will put a trailing '\' even on the last line, and will use leading 3411b2353dbSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 3421b2353dbSmrg # "Emit spaces for -MD"). 3431b2353dbSmrg "$@" -MD -MF "$tmpdepfile" 3441b2353dbSmrg stat=$? 3451b2353dbSmrg if test $stat -ne 0; then 3461b2353dbSmrg rm -f "$tmpdepfile" 3471b2353dbSmrg exit $stat 34821c2f794Smrg fi 3491b2353dbSmrg rm -f "$depfile" 3501b2353dbSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3511b2353dbSmrg # We have to change lines of the first kind to '$object: \'. 3521b2353dbSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3531b2353dbSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 3541b2353dbSmrg # dummy dependency, to avoid the deleted-header problem. 3551b2353dbSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35621c2f794Smrg rm -f "$tmpdepfile" 35721c2f794Smrg ;; 35821c2f794Smrg 3591b2353dbSmrg## The order of this option in the case statement is important, since the 3601b2353dbSmrg## shell code in configure will try each of these formats in the order 3611b2353dbSmrg## listed in this file. A plain '-MD' option would be understood by many 3621b2353dbSmrg## compilers, so we must ensure this comes after the gcc and icc options. 3631b2353dbSmrgpgcc) 3641b2353dbSmrg # Portland's C compiler understands '-MD'. 3651b2353dbSmrg # Will always output deps to 'file.d' where file is the root name of the 3661b2353dbSmrg # source file under compilation, even if file resides in a subdirectory. 3671b2353dbSmrg # The object file name does not affect the name of the '.d' file. 3681b2353dbSmrg # pgcc 10.2 will output 36921c2f794Smrg # foo.o: sub/foo.c sub/foo.h 3701b2353dbSmrg # and will wrap long lines using '\' : 37121c2f794Smrg # foo.o: sub/foo.c ... \ 37221c2f794Smrg # sub/foo.h ... \ 37321c2f794Smrg # ... 3741b2353dbSmrg set_dir_from "$object" 3751b2353dbSmrg # Use the source, not the object, to determine the base name, since 3761b2353dbSmrg # that's sadly what pgcc will do too. 3771b2353dbSmrg set_base_from "$source" 3781b2353dbSmrg tmpdepfile=$base.d 3791b2353dbSmrg 3801b2353dbSmrg # For projects that build the same source file twice into different object 3811b2353dbSmrg # files, the pgcc approach of using the *source* file root name can cause 3821b2353dbSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3831b2353dbSmrg # the same $tmpdepfile. 3841b2353dbSmrg lockdir=$base.d-lock 3851b2353dbSmrg trap " 3861b2353dbSmrg echo '$0: caught signal, cleaning up...' >&2 3871b2353dbSmrg rmdir '$lockdir' 3881b2353dbSmrg exit 1 3891b2353dbSmrg " 1 2 13 15 3901b2353dbSmrg numtries=100 3911b2353dbSmrg i=$numtries 3921b2353dbSmrg while test $i -gt 0; do 3931b2353dbSmrg # mkdir is a portable test-and-set. 3941b2353dbSmrg if mkdir "$lockdir" 2>/dev/null; then 3951b2353dbSmrg # This process acquired the lock. 3961b2353dbSmrg "$@" -MD 3971b2353dbSmrg stat=$? 3981b2353dbSmrg # Release the lock. 3991b2353dbSmrg rmdir "$lockdir" 4001b2353dbSmrg break 4011b2353dbSmrg else 4021b2353dbSmrg # If the lock is being held by a different process, wait 4031b2353dbSmrg # until the winning process is done or we timeout. 4041b2353dbSmrg while test -d "$lockdir" && test $i -gt 0; do 4051b2353dbSmrg sleep 1 4061b2353dbSmrg i=`expr $i - 1` 4071b2353dbSmrg done 4081b2353dbSmrg fi 4091b2353dbSmrg i=`expr $i - 1` 4101b2353dbSmrg done 4111b2353dbSmrg trap - 1 2 13 15 4121b2353dbSmrg if test $i -le 0; then 4131b2353dbSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4141b2353dbSmrg echo "$0: check lockdir '$lockdir'" >&2 4151b2353dbSmrg exit 1 4161b2353dbSmrg fi 41721c2f794Smrg 4181b2353dbSmrg if test $stat -ne 0; then 41921c2f794Smrg rm -f "$tmpdepfile" 42021c2f794Smrg exit $stat 42121c2f794Smrg fi 42221c2f794Smrg rm -f "$depfile" 42321c2f794Smrg # Each line is of the form `foo.o: dependent.h', 42421c2f794Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42521c2f794Smrg # Do two passes, one to just change these to 42621c2f794Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 42721c2f794Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42821c2f794Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 42921c2f794Smrg # correctly. Breaking it into two sed invocations is a workaround. 4301b2353dbSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4311b2353dbSmrg | sed -e 's/$/ :/' >> "$depfile" 43221c2f794Smrg rm -f "$tmpdepfile" 43321c2f794Smrg ;; 43421c2f794Smrg 43521c2f794Smrghp2) 43621c2f794Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 43721c2f794Smrg # compilers, which have integrated preprocessors. The correct option 43821c2f794Smrg # to use with these is +Maked; it writes dependencies to a file named 43921c2f794Smrg # 'foo.d', which lands next to the object file, wherever that 44021c2f794Smrg # happens to be. 44121c2f794Smrg # Much of this is similar to the tru64 case; see comments there. 4421b2353dbSmrg set_dir_from "$object" 4431b2353dbSmrg set_base_from "$object" 44421c2f794Smrg if test "$libtool" = yes; then 44521c2f794Smrg tmpdepfile1=$dir$base.d 44621c2f794Smrg tmpdepfile2=$dir.libs/$base.d 44721c2f794Smrg "$@" -Wc,+Maked 44821c2f794Smrg else 44921c2f794Smrg tmpdepfile1=$dir$base.d 45021c2f794Smrg tmpdepfile2=$dir$base.d 45121c2f794Smrg "$@" +Maked 45221c2f794Smrg fi 45321c2f794Smrg stat=$? 4541b2353dbSmrg if test $stat -ne 0; then 45521c2f794Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 45621c2f794Smrg exit $stat 45721c2f794Smrg fi 45821c2f794Smrg 45921c2f794Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 46021c2f794Smrg do 46121c2f794Smrg test -f "$tmpdepfile" && break 46221c2f794Smrg done 46321c2f794Smrg if test -f "$tmpdepfile"; then 4641b2353dbSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4651b2353dbSmrg # Add 'dependent.h:' lines. 46612391620Smrg sed -ne '2,${ 4671b2353dbSmrg s/^ *// 4681b2353dbSmrg s/ \\*$// 4691b2353dbSmrg s/$/:/ 4701b2353dbSmrg p 4711b2353dbSmrg }' "$tmpdepfile" >> "$depfile" 47221c2f794Smrg else 4731b2353dbSmrg make_dummy_depfile 47421c2f794Smrg fi 47521c2f794Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 47621c2f794Smrg ;; 47721c2f794Smrg 47821c2f794Smrgtru64) 4791b2353dbSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 4801b2353dbSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4811b2353dbSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4821b2353dbSmrg # dependencies in 'foo.d' instead, so we check for that too. 4831b2353dbSmrg # Subdirectories are respected. 4841b2353dbSmrg set_dir_from "$object" 4851b2353dbSmrg set_base_from "$object" 4861b2353dbSmrg 4871b2353dbSmrg if test "$libtool" = yes; then 4881b2353dbSmrg # Libtool generates 2 separate objects for the 2 libraries. These 4891b2353dbSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 4901b2353dbSmrg # in $dir$base.o.d. We have to check for both files, because 4911b2353dbSmrg # one of the two compilations can be disabled. We should prefer 4921b2353dbSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4931b2353dbSmrg # automatically cleaned when .libs/ is deleted, while ignoring 4941b2353dbSmrg # the former would cause a distcleancheck panic. 4951b2353dbSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4961b2353dbSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4971b2353dbSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4981b2353dbSmrg "$@" -Wc,-MD 4991b2353dbSmrg else 5001b2353dbSmrg tmpdepfile1=$dir$base.d 5011b2353dbSmrg tmpdepfile2=$dir$base.d 5021b2353dbSmrg tmpdepfile3=$dir$base.d 5031b2353dbSmrg "$@" -MD 5041b2353dbSmrg fi 5051b2353dbSmrg 5061b2353dbSmrg stat=$? 5071b2353dbSmrg if test $stat -ne 0; then 5081b2353dbSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5091b2353dbSmrg exit $stat 5101b2353dbSmrg fi 5111b2353dbSmrg 5121b2353dbSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5131b2353dbSmrg do 5141b2353dbSmrg test -f "$tmpdepfile" && break 5151b2353dbSmrg done 5161b2353dbSmrg # Same post-processing that is required for AIX mode. 5171b2353dbSmrg aix_post_process_depfile 5181b2353dbSmrg ;; 51921c2f794Smrg 52082e12b1bSmrgmsvc7) 52182e12b1bSmrg if test "$libtool" = yes; then 52282e12b1bSmrg showIncludes=-Wc,-showIncludes 52382e12b1bSmrg else 52482e12b1bSmrg showIncludes=-showIncludes 52582e12b1bSmrg fi 52682e12b1bSmrg "$@" $showIncludes > "$tmpdepfile" 52782e12b1bSmrg stat=$? 52882e12b1bSmrg grep -v '^Note: including file: ' "$tmpdepfile" 5291b2353dbSmrg if test $stat -ne 0; then 53082e12b1bSmrg rm -f "$tmpdepfile" 53182e12b1bSmrg exit $stat 53282e12b1bSmrg fi 53382e12b1bSmrg rm -f "$depfile" 53482e12b1bSmrg echo "$object : \\" > "$depfile" 53582e12b1bSmrg # The first sed program below extracts the file names and escapes 53682e12b1bSmrg # backslashes for cygpath. The second sed program outputs the file 53782e12b1bSmrg # name when reading, but also accumulates all include files in the 53882e12b1bSmrg # hold buffer in order to output them again at the end. This only 53982e12b1bSmrg # works with sed implementations that can handle large buffers. 54082e12b1bSmrg sed < "$tmpdepfile" -n ' 54182e12b1bSmrg/^Note: including file: *\(.*\)/ { 54282e12b1bSmrg s//\1/ 54382e12b1bSmrg s/\\/\\\\/g 54482e12b1bSmrg p 54582e12b1bSmrg}' | $cygpath_u | sort -u | sed -n ' 54682e12b1bSmrgs/ /\\ /g 5471b2353dbSmrgs/\(.*\)/'"$tab"'\1 \\/p 54882e12b1bSmrgs/.\(.*\) \\/\1:/ 54982e12b1bSmrgH 55082e12b1bSmrg$ { 5511b2353dbSmrg s/.*/'"$tab"'/ 55282e12b1bSmrg G 55382e12b1bSmrg p 55482e12b1bSmrg}' >> "$depfile" 5551b2353dbSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55682e12b1bSmrg rm -f "$tmpdepfile" 55782e12b1bSmrg ;; 55882e12b1bSmrg 55982e12b1bSmrgmsvc7msys) 56082e12b1bSmrg # This case exists only to let depend.m4 do its work. It works by 56182e12b1bSmrg # looking at the text of this script. This case will never be run, 56282e12b1bSmrg # since it is checked for above. 56382e12b1bSmrg exit 1 56482e12b1bSmrg ;; 56582e12b1bSmrg 56621c2f794Smrg#nosideeffect) 56721c2f794Smrg # This comment above is used by automake to tell side-effect 56821c2f794Smrg # dependency tracking mechanisms from slower ones. 56921c2f794Smrg 57021c2f794Smrgdashmstdout) 57121c2f794Smrg # Important note: in order to support this mode, a compiler *must* 57221c2f794Smrg # always write the preprocessed file to stdout, regardless of -o. 57321c2f794Smrg "$@" || exit $? 57421c2f794Smrg 57521c2f794Smrg # Remove the call to Libtool. 57621c2f794Smrg if test "$libtool" = yes; then 57712391620Smrg while test "X$1" != 'X--mode=compile'; do 57821c2f794Smrg shift 57921c2f794Smrg done 58021c2f794Smrg shift 58121c2f794Smrg fi 58221c2f794Smrg 5831b2353dbSmrg # Remove '-o $object'. 58421c2f794Smrg IFS=" " 58521c2f794Smrg for arg 58621c2f794Smrg do 58721c2f794Smrg case $arg in 58821c2f794Smrg -o) 58921c2f794Smrg shift 59021c2f794Smrg ;; 59121c2f794Smrg $object) 59221c2f794Smrg shift 59321c2f794Smrg ;; 59421c2f794Smrg *) 59521c2f794Smrg set fnord "$@" "$arg" 59621c2f794Smrg shift # fnord 59721c2f794Smrg shift # $arg 59821c2f794Smrg ;; 59921c2f794Smrg esac 60021c2f794Smrg done 60121c2f794Smrg 60221c2f794Smrg test -z "$dashmflag" && dashmflag=-M 6031b2353dbSmrg # Require at least two characters before searching for ':' 60421c2f794Smrg # in the target name. This is to cope with DOS-style filenames: 6051b2353dbSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60621c2f794Smrg "$@" $dashmflag | 6071b2353dbSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60821c2f794Smrg rm -f "$depfile" 60921c2f794Smrg cat < "$tmpdepfile" > "$depfile" 6101b2353dbSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6111b2353dbSmrg # correctly. Breaking it into two sed invocations is a workaround. 6121b2353dbSmrg tr ' ' "$nl" < "$tmpdepfile" \ 6131b2353dbSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6141b2353dbSmrg | sed -e 's/$/ :/' >> "$depfile" 61521c2f794Smrg rm -f "$tmpdepfile" 61621c2f794Smrg ;; 61721c2f794Smrg 61821c2f794SmrgdashXmstdout) 61921c2f794Smrg # This case only exists to satisfy depend.m4. It is never actually 62021c2f794Smrg # run, as this mode is specially recognized in the preamble. 62121c2f794Smrg exit 1 62221c2f794Smrg ;; 62321c2f794Smrg 62421c2f794Smrgmakedepend) 62521c2f794Smrg "$@" || exit $? 62621c2f794Smrg # Remove any Libtool call 62721c2f794Smrg if test "$libtool" = yes; then 62812391620Smrg while test "X$1" != 'X--mode=compile'; do 62921c2f794Smrg shift 63021c2f794Smrg done 63121c2f794Smrg shift 63221c2f794Smrg fi 63321c2f794Smrg # X makedepend 63421c2f794Smrg shift 63512391620Smrg cleared=no eat=no 63612391620Smrg for arg 63712391620Smrg do 63821c2f794Smrg case $cleared in 63921c2f794Smrg no) 64021c2f794Smrg set ""; shift 64121c2f794Smrg cleared=yes ;; 64221c2f794Smrg esac 64312391620Smrg if test $eat = yes; then 64412391620Smrg eat=no 64512391620Smrg continue 64612391620Smrg fi 64721c2f794Smrg case "$arg" in 64821c2f794Smrg -D*|-I*) 64921c2f794Smrg set fnord "$@" "$arg"; shift ;; 65021c2f794Smrg # Strip any option that makedepend may not understand. Remove 65121c2f794Smrg # the object too, otherwise makedepend will parse it as a source file. 65212391620Smrg -arch) 65312391620Smrg eat=yes ;; 65421c2f794Smrg -*|$object) 65521c2f794Smrg ;; 65621c2f794Smrg *) 65721c2f794Smrg set fnord "$@" "$arg"; shift ;; 65821c2f794Smrg esac 65921c2f794Smrg done 66012391620Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66121c2f794Smrg touch "$tmpdepfile" 66221c2f794Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66321c2f794Smrg rm -f "$depfile" 66482e12b1bSmrg # makedepend may prepend the VPATH from the source file name to the object. 66582e12b1bSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 66682e12b1bSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6671b2353dbSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6681b2353dbSmrg # correctly. Breaking it into two sed invocations is a workaround. 6691b2353dbSmrg sed '1,2d' "$tmpdepfile" \ 6701b2353dbSmrg | tr ' ' "$nl" \ 6711b2353dbSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6721b2353dbSmrg | sed -e 's/$/ :/' >> "$depfile" 67321c2f794Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67421c2f794Smrg ;; 67521c2f794Smrg 67621c2f794Smrgcpp) 67721c2f794Smrg # Important note: in order to support this mode, a compiler *must* 67821c2f794Smrg # always write the preprocessed file to stdout. 67921c2f794Smrg "$@" || exit $? 68021c2f794Smrg 68121c2f794Smrg # Remove the call to Libtool. 68221c2f794Smrg if test "$libtool" = yes; then 68312391620Smrg while test "X$1" != 'X--mode=compile'; do 68421c2f794Smrg shift 68521c2f794Smrg done 68621c2f794Smrg shift 68721c2f794Smrg fi 68821c2f794Smrg 6891b2353dbSmrg # Remove '-o $object'. 69021c2f794Smrg IFS=" " 69121c2f794Smrg for arg 69221c2f794Smrg do 69321c2f794Smrg case $arg in 69421c2f794Smrg -o) 69521c2f794Smrg shift 69621c2f794Smrg ;; 69721c2f794Smrg $object) 69821c2f794Smrg shift 69921c2f794Smrg ;; 70021c2f794Smrg *) 70121c2f794Smrg set fnord "$@" "$arg" 70221c2f794Smrg shift # fnord 70321c2f794Smrg shift # $arg 70421c2f794Smrg ;; 70521c2f794Smrg esac 70621c2f794Smrg done 70721c2f794Smrg 7081b2353dbSmrg "$@" -E \ 7091b2353dbSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7101b2353dbSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7111b2353dbSmrg | sed '$ s: \\$::' > "$tmpdepfile" 71221c2f794Smrg rm -f "$depfile" 71321c2f794Smrg echo "$object : \\" > "$depfile" 71421c2f794Smrg cat < "$tmpdepfile" >> "$depfile" 71521c2f794Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71621c2f794Smrg rm -f "$tmpdepfile" 71721c2f794Smrg ;; 71821c2f794Smrg 71921c2f794Smrgmsvisualcpp) 72021c2f794Smrg # Important note: in order to support this mode, a compiler *must* 72112391620Smrg # always write the preprocessed file to stdout. 72221c2f794Smrg "$@" || exit $? 72312391620Smrg 72412391620Smrg # Remove the call to Libtool. 72512391620Smrg if test "$libtool" = yes; then 72612391620Smrg while test "X$1" != 'X--mode=compile'; do 72712391620Smrg shift 72812391620Smrg done 72912391620Smrg shift 73012391620Smrg fi 73112391620Smrg 73221c2f794Smrg IFS=" " 73321c2f794Smrg for arg 73421c2f794Smrg do 73521c2f794Smrg case "$arg" in 73612391620Smrg -o) 73712391620Smrg shift 73812391620Smrg ;; 73912391620Smrg $object) 74012391620Smrg shift 74112391620Smrg ;; 74221c2f794Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7431b2353dbSmrg set fnord "$@" 7441b2353dbSmrg shift 7451b2353dbSmrg shift 7461b2353dbSmrg ;; 74721c2f794Smrg *) 7481b2353dbSmrg set fnord "$@" "$arg" 7491b2353dbSmrg shift 7501b2353dbSmrg shift 7511b2353dbSmrg ;; 75221c2f794Smrg esac 75321c2f794Smrg done 75412391620Smrg "$@" -E 2>/dev/null | 75512391620Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75621c2f794Smrg rm -f "$depfile" 75721c2f794Smrg echo "$object : \\" > "$depfile" 7581b2353dbSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7591b2353dbSmrg echo "$tab" >> "$depfile" 76012391620Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76121c2f794Smrg rm -f "$tmpdepfile" 76221c2f794Smrg ;; 76321c2f794Smrg 76412391620Smrgmsvcmsys) 76512391620Smrg # This case exists only to let depend.m4 do its work. It works by 76612391620Smrg # looking at the text of this script. This case will never be run, 76712391620Smrg # since it is checked for above. 76812391620Smrg exit 1 76912391620Smrg ;; 77012391620Smrg 77121c2f794Smrgnone) 77221c2f794Smrg exec "$@" 77321c2f794Smrg ;; 77421c2f794Smrg 77521c2f794Smrg*) 77621c2f794Smrg echo "Unknown depmode $depmode" 1>&2 77721c2f794Smrg exit 1 77821c2f794Smrg ;; 77921c2f794Smrgesac 78021c2f794Smrg 78121c2f794Smrgexit 0 78221c2f794Smrg 78321c2f794Smrg# Local Variables: 78421c2f794Smrg# mode: shell-script 78521c2f794Smrg# sh-indentation: 2 786889a2364Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 78721c2f794Smrg# time-stamp-start: "scriptversion=" 78821c2f794Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789889a2364Smrg# time-stamp-time-zone: "UTC0" 79012391620Smrg# time-stamp-end: "; # UTC" 79121c2f794Smrg# End: 792