depcomp revision a5a2a776
11abf7346Smrg#! /bin/sh 21abf7346Smrg# depcomp - compile a program generating dependencies as side-effects 31abf7346Smrg 4a5a2a776Smrgscriptversion=2018-03-07.03; # UTC 51abf7346Smrg 6a5a2a776Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 71abf7346Smrg 81abf7346Smrg# This program is free software; you can redistribute it and/or modify 91abf7346Smrg# it under the terms of the GNU General Public License as published by 101abf7346Smrg# the Free Software Foundation; either version 2, or (at your option) 111abf7346Smrg# any later version. 121abf7346Smrg 131abf7346Smrg# This program is distributed in the hope that it will be useful, 141abf7346Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 151abf7346Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 161abf7346Smrg# GNU General Public License for more details. 171abf7346Smrg 181abf7346Smrg# You should have received a copy of the GNU General Public License 19a5a2a776Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 201abf7346Smrg 211abf7346Smrg# As a special exception to the GNU General Public License, if you 221abf7346Smrg# distribute this file as part of a program that contains a 231abf7346Smrg# configuration script generated by Autoconf, you may include it under 241abf7346Smrg# the same distribution terms that you use for the rest of that program. 251abf7346Smrg 261abf7346Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 271abf7346Smrg 281abf7346Smrgcase $1 in 291abf7346Smrg '') 306d36ef34Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 316d36ef34Smrg exit 1; 326d36ef34Smrg ;; 331abf7346Smrg -h | --h*) 341abf7346Smrg cat <<\EOF 351abf7346SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 361abf7346Smrg 371abf7346SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 381abf7346Smrgas side-effects. 391abf7346Smrg 401abf7346SmrgEnvironment variables: 411abf7346Smrg depmode Dependency tracking mode. 426d36ef34Smrg source Source file read by 'PROGRAMS ARGS'. 436d36ef34Smrg object Object file output by 'PROGRAMS ARGS'. 441abf7346Smrg DEPDIR directory where to store dependencies. 451abf7346Smrg depfile Dependency file to output. 466d36ef34Smrg tmpdepfile Temporary file to use when outputting dependencies. 471abf7346Smrg libtool Whether libtool is used (yes/no). 481abf7346Smrg 491abf7346SmrgReport bugs to <bug-automake@gnu.org>. 501abf7346SmrgEOF 511abf7346Smrg exit $? 521abf7346Smrg ;; 531abf7346Smrg -v | --v*) 541abf7346Smrg echo "depcomp $scriptversion" 551abf7346Smrg exit $? 561abf7346Smrg ;; 571abf7346Smrgesac 581abf7346Smrg 596d36ef34Smrg# Get the directory component of the given path, and save it in the 606d36ef34Smrg# global variables '$dir'. Note that this directory component will 616d36ef34Smrg# be either empty or ending with a '/' character. This is deliberate. 626d36ef34Smrgset_dir_from () 636d36ef34Smrg{ 646d36ef34Smrg case $1 in 656d36ef34Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 666d36ef34Smrg *) dir=;; 676d36ef34Smrg esac 686d36ef34Smrg} 696d36ef34Smrg 706d36ef34Smrg# Get the suffix-stripped basename of the given path, and save it the 716d36ef34Smrg# global variable '$base'. 726d36ef34Smrgset_base_from () 736d36ef34Smrg{ 746d36ef34Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 756d36ef34Smrg} 766d36ef34Smrg 776d36ef34Smrg# If no dependency file was actually created by the compiler invocation, 786d36ef34Smrg# we still have to create a dummy depfile, to avoid errors with the 796d36ef34Smrg# Makefile "include basename.Plo" scheme. 806d36ef34Smrgmake_dummy_depfile () 816d36ef34Smrg{ 826d36ef34Smrg echo "#dummy" > "$depfile" 836d36ef34Smrg} 846d36ef34Smrg 856d36ef34Smrg# Factor out some common post-processing of the generated depfile. 866d36ef34Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 876d36ef34Smrgaix_post_process_depfile () 886d36ef34Smrg{ 896d36ef34Smrg # If the compiler actually managed to produce a dependency file, 906d36ef34Smrg # post-process it. 916d36ef34Smrg if test -f "$tmpdepfile"; then 926d36ef34Smrg # Each line is of the form 'foo.o: dependency.h'. 936d36ef34Smrg # Do two passes, one to just change these to 946d36ef34Smrg # $object: dependency.h 956d36ef34Smrg # and one to simply output 966d36ef34Smrg # dependency.h: 976d36ef34Smrg # which is needed to avoid the deleted-header problem. 986d36ef34Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 996d36ef34Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1006d36ef34Smrg } > "$depfile" 1016d36ef34Smrg rm -f "$tmpdepfile" 1026d36ef34Smrg else 1036d36ef34Smrg make_dummy_depfile 1046d36ef34Smrg fi 1056d36ef34Smrg} 1066d36ef34Smrg 1076d36ef34Smrg# A tabulation character. 1086d36ef34Smrgtab=' ' 1096d36ef34Smrg# A newline character. 1106d36ef34Smrgnl=' 1116d36ef34Smrg' 1126d36ef34Smrg# Character ranges might be problematic outside the C locale. 1136d36ef34Smrg# These definitions help. 1146d36ef34Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1156d36ef34Smrglower=abcdefghijklmnopqrstuvwxyz 1166d36ef34Smrgdigits=0123456789 1176d36ef34Smrgalpha=${upper}${lower} 1186d36ef34Smrg 1191abf7346Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1201abf7346Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1211abf7346Smrg exit 1 1221abf7346Smrgfi 1231abf7346Smrg 1241abf7346Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1251abf7346Smrgdepfile=${depfile-`echo "$object" | 1261abf7346Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1271abf7346Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1281abf7346Smrg 1291abf7346Smrgrm -f "$tmpdepfile" 1301abf7346Smrg 1316d36ef34Smrg# Avoid interferences from the environment. 1326d36ef34Smrggccflag= dashmflag= 1336d36ef34Smrg 1341abf7346Smrg# Some modes work just like other modes, but use different flags. We 1351abf7346Smrg# parameterize here, but still list the modes in the big case below, 1361abf7346Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1371abf7346Smrg# here, because this file can only contain one case statement. 1381abf7346Smrgif test "$depmode" = hp; then 1391abf7346Smrg # HP compiler uses -M and no extra arg. 1401abf7346Smrg gccflag=-M 1411abf7346Smrg depmode=gcc 1421abf7346Smrgfi 1431abf7346Smrg 1441abf7346Smrgif test "$depmode" = dashXmstdout; then 1456d36ef34Smrg # This is just like dashmstdout with a different argument. 1466d36ef34Smrg dashmflag=-xM 1476d36ef34Smrg depmode=dashmstdout 1481abf7346Smrgfi 1491abf7346Smrg 1508b6d6341Smrgcygpath_u="cygpath -u -f -" 1518b6d6341Smrgif test "$depmode" = msvcmsys; then 1526d36ef34Smrg # This is just like msvisualcpp but w/o cygpath translation. 1536d36ef34Smrg # Just convert the backslash-escaped backslashes to single forward 1546d36ef34Smrg # slashes to satisfy depend.m4 1556d36ef34Smrg cygpath_u='sed s,\\\\,/,g' 1566d36ef34Smrg depmode=msvisualcpp 1576d36ef34Smrgfi 1586d36ef34Smrg 1596d36ef34Smrgif test "$depmode" = msvc7msys; then 1606d36ef34Smrg # This is just like msvc7 but w/o cygpath translation. 1616d36ef34Smrg # Just convert the backslash-escaped backslashes to single forward 1626d36ef34Smrg # slashes to satisfy depend.m4 1636d36ef34Smrg cygpath_u='sed s,\\\\,/,g' 1646d36ef34Smrg depmode=msvc7 1656d36ef34Smrgfi 1666d36ef34Smrg 1676d36ef34Smrgif test "$depmode" = xlc; then 1686d36ef34Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1696d36ef34Smrg gccflag=-qmakedep=gcc,-MF 1706d36ef34Smrg depmode=gcc 1718b6d6341Smrgfi 1728b6d6341Smrg 1731abf7346Smrgcase "$depmode" in 1741abf7346Smrggcc3) 1751abf7346Smrg## gcc 3 implements dependency tracking that does exactly what 1761abf7346Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1771abf7346Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1781abf7346Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1791abf7346Smrg## the command line argument order; so add the flags where they 1801abf7346Smrg## appear in depend2.am. Note that the slowdown incurred here 1811abf7346Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1821abf7346Smrg for arg 1831abf7346Smrg do 1841abf7346Smrg case $arg in 1851abf7346Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1861abf7346Smrg *) set fnord "$@" "$arg" ;; 1871abf7346Smrg esac 1881abf7346Smrg shift # fnord 1891abf7346Smrg shift # $arg 1901abf7346Smrg done 1911abf7346Smrg "$@" 1921abf7346Smrg stat=$? 1936d36ef34Smrg if test $stat -ne 0; then 1941abf7346Smrg rm -f "$tmpdepfile" 1951abf7346Smrg exit $stat 1961abf7346Smrg fi 1971abf7346Smrg mv "$tmpdepfile" "$depfile" 1981abf7346Smrg ;; 1991abf7346Smrg 2001abf7346Smrggcc) 2016d36ef34Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2026d36ef34Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2036d36ef34Smrg## (see the conditional assignment to $gccflag above). 2041abf7346Smrg## There are various ways to get dependency output from gcc. Here's 2051abf7346Smrg## why we pick this rather obscure method: 2061abf7346Smrg## - Don't want to use -MD because we'd like the dependencies to end 2071abf7346Smrg## up in a subdir. Having to rename by hand is ugly. 2081abf7346Smrg## (We might end up doing this anyway to support other compilers.) 2091abf7346Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2106d36ef34Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2116d36ef34Smrg## supported by the other compilers which use the 'gcc' depmode. 2121abf7346Smrg## - Using -M directly means running the compiler twice (even worse 2131abf7346Smrg## than renaming). 2141abf7346Smrg if test -z "$gccflag"; then 2151abf7346Smrg gccflag=-MD, 2161abf7346Smrg fi 2171abf7346Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2181abf7346Smrg stat=$? 2196d36ef34Smrg if test $stat -ne 0; then 2201abf7346Smrg rm -f "$tmpdepfile" 2211abf7346Smrg exit $stat 2221abf7346Smrg fi 2231abf7346Smrg rm -f "$depfile" 2241abf7346Smrg echo "$object : \\" > "$depfile" 2256d36ef34Smrg # The second -e expression handles DOS-style file names with drive 2266d36ef34Smrg # letters. 2271abf7346Smrg sed -e 's/^[^:]*: / /' \ 2281abf7346Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2296d36ef34Smrg## This next piece of magic avoids the "deleted header file" problem. 2301abf7346Smrg## The problem is that when a header file which appears in a .P file 2311abf7346Smrg## is deleted, the dependency causes make to die (because there is 2321abf7346Smrg## typically no way to rebuild the header). We avoid this by adding 2331abf7346Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2341abf7346Smrg## this for us directly. 2356d36ef34Smrg## Some versions of gcc put a space before the ':'. On the theory 2361abf7346Smrg## that the space means something, we add a space to the output as 2376d36ef34Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 2386d36ef34Smrg## to the object. Take care to not repeat it in the output. 2391abf7346Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2401abf7346Smrg## correctly. Breaking it into two sed invocations is a workaround. 2416d36ef34Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2426d36ef34Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2436d36ef34Smrg | sed -e 's/$/ :/' >> "$depfile" 2441abf7346Smrg rm -f "$tmpdepfile" 2451abf7346Smrg ;; 2461abf7346Smrg 2471abf7346Smrghp) 2481abf7346Smrg # This case exists only to let depend.m4 do its work. It works by 2491abf7346Smrg # looking at the text of this script. This case will never be run, 2501abf7346Smrg # since it is checked for above. 2511abf7346Smrg exit 1 2521abf7346Smrg ;; 2531abf7346Smrg 2541abf7346Smrgsgi) 2551abf7346Smrg if test "$libtool" = yes; then 2561abf7346Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2571abf7346Smrg else 2581abf7346Smrg "$@" -MDupdate "$tmpdepfile" 2591abf7346Smrg fi 2601abf7346Smrg stat=$? 2616d36ef34Smrg if test $stat -ne 0; then 2621abf7346Smrg rm -f "$tmpdepfile" 2631abf7346Smrg exit $stat 2641abf7346Smrg fi 2651abf7346Smrg rm -f "$depfile" 2661abf7346Smrg 2671abf7346Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2681abf7346Smrg echo "$object : \\" > "$depfile" 2691abf7346Smrg # Clip off the initial element (the dependent). Don't try to be 2701abf7346Smrg # clever and replace this with sed code, as IRIX sed won't handle 2711abf7346Smrg # lines with more than a fixed number of characters (4096 in 2721abf7346Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2736d36ef34Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2741abf7346Smrg # dependency line. 2756d36ef34Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2766d36ef34Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2776d36ef34Smrg | tr "$nl" ' ' >> "$depfile" 2788b6d6341Smrg echo >> "$depfile" 2791abf7346Smrg # The second pass generates a dummy entry for each header file. 2806d36ef34Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2816d36ef34Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2826d36ef34Smrg >> "$depfile" 2831abf7346Smrg else 2846d36ef34Smrg make_dummy_depfile 2851abf7346Smrg fi 2861abf7346Smrg rm -f "$tmpdepfile" 2871abf7346Smrg ;; 2881abf7346Smrg 2896d36ef34Smrgxlc) 2906d36ef34Smrg # This case exists only to let depend.m4 do its work. It works by 2916d36ef34Smrg # looking at the text of this script. This case will never be run, 2926d36ef34Smrg # since it is checked for above. 2936d36ef34Smrg exit 1 2946d36ef34Smrg ;; 2956d36ef34Smrg 2961abf7346Smrgaix) 2971abf7346Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2981abf7346Smrg # in a .u file. In older versions, this file always lives in the 2996d36ef34Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3001abf7346Smrg # start of each line; $object doesn't have directory information. 3011abf7346Smrg # Version 6 uses the directory in both cases. 3026d36ef34Smrg set_dir_from "$object" 3036d36ef34Smrg set_base_from "$object" 3041abf7346Smrg if test "$libtool" = yes; then 3058b6d6341Smrg tmpdepfile1=$dir$base.u 3068b6d6341Smrg tmpdepfile2=$base.u 3078b6d6341Smrg tmpdepfile3=$dir.libs/$base.u 3081abf7346Smrg "$@" -Wc,-M 3091abf7346Smrg else 3108b6d6341Smrg tmpdepfile1=$dir$base.u 3118b6d6341Smrg tmpdepfile2=$dir$base.u 3128b6d6341Smrg tmpdepfile3=$dir$base.u 3131abf7346Smrg "$@" -M 3141abf7346Smrg fi 3151abf7346Smrg stat=$? 3166d36ef34Smrg if test $stat -ne 0; then 3178b6d6341Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3181abf7346Smrg exit $stat 3191abf7346Smrg fi 3201abf7346Smrg 3218b6d6341Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3228b6d6341Smrg do 3238b6d6341Smrg test -f "$tmpdepfile" && break 3248b6d6341Smrg done 3256d36ef34Smrg aix_post_process_depfile 3266d36ef34Smrg ;; 3276d36ef34Smrg 3286d36ef34Smrgtcc) 3296d36ef34Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3306d36ef34Smrg # FIXME: That version still under development at the moment of writing. 3316d36ef34Smrg # Make that this statement remains true also for stable, released 3326d36ef34Smrg # versions. 3336d36ef34Smrg # It will wrap lines (doesn't matter whether long or short) with a 3346d36ef34Smrg # trailing '\', as in: 3356d36ef34Smrg # 3366d36ef34Smrg # foo.o : \ 3376d36ef34Smrg # foo.c \ 3386d36ef34Smrg # foo.h \ 3396d36ef34Smrg # 3406d36ef34Smrg # It will put a trailing '\' even on the last line, and will use leading 3416d36ef34Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3426d36ef34Smrg # "Emit spaces for -MD"). 3436d36ef34Smrg "$@" -MD -MF "$tmpdepfile" 3446d36ef34Smrg stat=$? 3456d36ef34Smrg if test $stat -ne 0; then 3466d36ef34Smrg rm -f "$tmpdepfile" 3476d36ef34Smrg exit $stat 3481abf7346Smrg fi 3496d36ef34Smrg rm -f "$depfile" 3506d36ef34Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3516d36ef34Smrg # We have to change lines of the first kind to '$object: \'. 3526d36ef34Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3536d36ef34Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3546d36ef34Smrg # dummy dependency, to avoid the deleted-header problem. 3556d36ef34Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3561abf7346Smrg rm -f "$tmpdepfile" 3571abf7346Smrg ;; 3581abf7346Smrg 3596d36ef34Smrg## The order of this option in the case statement is important, since the 3606d36ef34Smrg## shell code in configure will try each of these formats in the order 3616d36ef34Smrg## listed in this file. A plain '-MD' option would be understood by many 3626d36ef34Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3636d36ef34Smrgpgcc) 3646d36ef34Smrg # Portland's C compiler understands '-MD'. 3656d36ef34Smrg # Will always output deps to 'file.d' where file is the root name of the 3666d36ef34Smrg # source file under compilation, even if file resides in a subdirectory. 3676d36ef34Smrg # The object file name does not affect the name of the '.d' file. 3686d36ef34Smrg # pgcc 10.2 will output 3691abf7346Smrg # foo.o: sub/foo.c sub/foo.h 3706d36ef34Smrg # and will wrap long lines using '\' : 3711abf7346Smrg # foo.o: sub/foo.c ... \ 3721abf7346Smrg # sub/foo.h ... \ 3731abf7346Smrg # ... 3746d36ef34Smrg set_dir_from "$object" 3756d36ef34Smrg # Use the source, not the object, to determine the base name, since 3766d36ef34Smrg # that's sadly what pgcc will do too. 3776d36ef34Smrg set_base_from "$source" 3786d36ef34Smrg tmpdepfile=$base.d 3796d36ef34Smrg 3806d36ef34Smrg # For projects that build the same source file twice into different object 3816d36ef34Smrg # files, the pgcc approach of using the *source* file root name can cause 3826d36ef34Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3836d36ef34Smrg # the same $tmpdepfile. 3846d36ef34Smrg lockdir=$base.d-lock 3856d36ef34Smrg trap " 3866d36ef34Smrg echo '$0: caught signal, cleaning up...' >&2 3876d36ef34Smrg rmdir '$lockdir' 3886d36ef34Smrg exit 1 3896d36ef34Smrg " 1 2 13 15 3906d36ef34Smrg numtries=100 3916d36ef34Smrg i=$numtries 3926d36ef34Smrg while test $i -gt 0; do 3936d36ef34Smrg # mkdir is a portable test-and-set. 3946d36ef34Smrg if mkdir "$lockdir" 2>/dev/null; then 3956d36ef34Smrg # This process acquired the lock. 3966d36ef34Smrg "$@" -MD 3976d36ef34Smrg stat=$? 3986d36ef34Smrg # Release the lock. 3996d36ef34Smrg rmdir "$lockdir" 4006d36ef34Smrg break 4016d36ef34Smrg else 4026d36ef34Smrg # If the lock is being held by a different process, wait 4036d36ef34Smrg # until the winning process is done or we timeout. 4046d36ef34Smrg while test -d "$lockdir" && test $i -gt 0; do 4056d36ef34Smrg sleep 1 4066d36ef34Smrg i=`expr $i - 1` 4076d36ef34Smrg done 4086d36ef34Smrg fi 4096d36ef34Smrg i=`expr $i - 1` 4106d36ef34Smrg done 4116d36ef34Smrg trap - 1 2 13 15 4126d36ef34Smrg if test $i -le 0; then 4136d36ef34Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4146d36ef34Smrg echo "$0: check lockdir '$lockdir'" >&2 4156d36ef34Smrg exit 1 4166d36ef34Smrg fi 4171abf7346Smrg 4186d36ef34Smrg if test $stat -ne 0; then 4191abf7346Smrg rm -f "$tmpdepfile" 4201abf7346Smrg exit $stat 4211abf7346Smrg fi 4221abf7346Smrg rm -f "$depfile" 4231abf7346Smrg # Each line is of the form `foo.o: dependent.h', 4241abf7346Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4251abf7346Smrg # Do two passes, one to just change these to 4261abf7346Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4271abf7346Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4281abf7346Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4291abf7346Smrg # correctly. Breaking it into two sed invocations is a workaround. 4306d36ef34Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4316d36ef34Smrg | sed -e 's/$/ :/' >> "$depfile" 4321abf7346Smrg rm -f "$tmpdepfile" 4331abf7346Smrg ;; 4341abf7346Smrg 4351abf7346Smrghp2) 4361abf7346Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4371abf7346Smrg # compilers, which have integrated preprocessors. The correct option 4381abf7346Smrg # to use with these is +Maked; it writes dependencies to a file named 4391abf7346Smrg # 'foo.d', which lands next to the object file, wherever that 4401abf7346Smrg # happens to be. 4411abf7346Smrg # Much of this is similar to the tru64 case; see comments there. 4426d36ef34Smrg set_dir_from "$object" 4436d36ef34Smrg set_base_from "$object" 4441abf7346Smrg if test "$libtool" = yes; then 4451abf7346Smrg tmpdepfile1=$dir$base.d 4461abf7346Smrg tmpdepfile2=$dir.libs/$base.d 4471abf7346Smrg "$@" -Wc,+Maked 4481abf7346Smrg else 4491abf7346Smrg tmpdepfile1=$dir$base.d 4501abf7346Smrg tmpdepfile2=$dir$base.d 4511abf7346Smrg "$@" +Maked 4521abf7346Smrg fi 4531abf7346Smrg stat=$? 4546d36ef34Smrg if test $stat -ne 0; then 4551abf7346Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4561abf7346Smrg exit $stat 4571abf7346Smrg fi 4581abf7346Smrg 4591abf7346Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4601abf7346Smrg do 4611abf7346Smrg test -f "$tmpdepfile" && break 4621abf7346Smrg done 4631abf7346Smrg if test -f "$tmpdepfile"; then 4646d36ef34Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4656d36ef34Smrg # Add 'dependent.h:' lines. 4668b6d6341Smrg sed -ne '2,${ 4676d36ef34Smrg s/^ *// 4686d36ef34Smrg s/ \\*$// 4696d36ef34Smrg s/$/:/ 4706d36ef34Smrg p 4716d36ef34Smrg }' "$tmpdepfile" >> "$depfile" 4721abf7346Smrg else 4736d36ef34Smrg make_dummy_depfile 4741abf7346Smrg fi 4751abf7346Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4761abf7346Smrg ;; 4771abf7346Smrg 4781abf7346Smrgtru64) 4796d36ef34Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4806d36ef34Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4816d36ef34Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4826d36ef34Smrg # dependencies in 'foo.d' instead, so we check for that too. 4836d36ef34Smrg # Subdirectories are respected. 4846d36ef34Smrg set_dir_from "$object" 4856d36ef34Smrg set_base_from "$object" 4866d36ef34Smrg 4876d36ef34Smrg if test "$libtool" = yes; then 4886d36ef34Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4896d36ef34Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4906d36ef34Smrg # in $dir$base.o.d. We have to check for both files, because 4916d36ef34Smrg # one of the two compilations can be disabled. We should prefer 4926d36ef34Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4936d36ef34Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4946d36ef34Smrg # the former would cause a distcleancheck panic. 4956d36ef34Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4966d36ef34Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4976d36ef34Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4986d36ef34Smrg "$@" -Wc,-MD 4996d36ef34Smrg else 5006d36ef34Smrg tmpdepfile1=$dir$base.d 5016d36ef34Smrg tmpdepfile2=$dir$base.d 5026d36ef34Smrg tmpdepfile3=$dir$base.d 5036d36ef34Smrg "$@" -MD 5046d36ef34Smrg fi 5056d36ef34Smrg 5066d36ef34Smrg stat=$? 5076d36ef34Smrg if test $stat -ne 0; then 5086d36ef34Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5096d36ef34Smrg exit $stat 5106d36ef34Smrg fi 5116d36ef34Smrg 5126d36ef34Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5136d36ef34Smrg do 5146d36ef34Smrg test -f "$tmpdepfile" && break 5156d36ef34Smrg done 5166d36ef34Smrg # Same post-processing that is required for AIX mode. 5176d36ef34Smrg aix_post_process_depfile 5186d36ef34Smrg ;; 5196d36ef34Smrg 5206d36ef34Smrgmsvc7) 5216d36ef34Smrg if test "$libtool" = yes; then 5226d36ef34Smrg showIncludes=-Wc,-showIncludes 5236d36ef34Smrg else 5246d36ef34Smrg showIncludes=-showIncludes 5256d36ef34Smrg fi 5266d36ef34Smrg "$@" $showIncludes > "$tmpdepfile" 5276d36ef34Smrg stat=$? 5286d36ef34Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5296d36ef34Smrg if test $stat -ne 0; then 5306d36ef34Smrg rm -f "$tmpdepfile" 5316d36ef34Smrg exit $stat 5326d36ef34Smrg fi 5336d36ef34Smrg rm -f "$depfile" 5346d36ef34Smrg echo "$object : \\" > "$depfile" 5356d36ef34Smrg # The first sed program below extracts the file names and escapes 5366d36ef34Smrg # backslashes for cygpath. The second sed program outputs the file 5376d36ef34Smrg # name when reading, but also accumulates all include files in the 5386d36ef34Smrg # hold buffer in order to output them again at the end. This only 5396d36ef34Smrg # works with sed implementations that can handle large buffers. 5406d36ef34Smrg sed < "$tmpdepfile" -n ' 5416d36ef34Smrg/^Note: including file: *\(.*\)/ { 5426d36ef34Smrg s//\1/ 5436d36ef34Smrg s/\\/\\\\/g 5446d36ef34Smrg p 5456d36ef34Smrg}' | $cygpath_u | sort -u | sed -n ' 5466d36ef34Smrgs/ /\\ /g 5476d36ef34Smrgs/\(.*\)/'"$tab"'\1 \\/p 5486d36ef34Smrgs/.\(.*\) \\/\1:/ 5496d36ef34SmrgH 5506d36ef34Smrg$ { 5516d36ef34Smrg s/.*/'"$tab"'/ 5526d36ef34Smrg G 5536d36ef34Smrg p 5546d36ef34Smrg}' >> "$depfile" 5556d36ef34Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5566d36ef34Smrg rm -f "$tmpdepfile" 5576d36ef34Smrg ;; 5586d36ef34Smrg 5596d36ef34Smrgmsvc7msys) 5606d36ef34Smrg # This case exists only to let depend.m4 do its work. It works by 5616d36ef34Smrg # looking at the text of this script. This case will never be run, 5626d36ef34Smrg # since it is checked for above. 5636d36ef34Smrg exit 1 5646d36ef34Smrg ;; 5651abf7346Smrg 5661abf7346Smrg#nosideeffect) 5671abf7346Smrg # This comment above is used by automake to tell side-effect 5681abf7346Smrg # dependency tracking mechanisms from slower ones. 5691abf7346Smrg 5701abf7346Smrgdashmstdout) 5711abf7346Smrg # Important note: in order to support this mode, a compiler *must* 5721abf7346Smrg # always write the preprocessed file to stdout, regardless of -o. 5731abf7346Smrg "$@" || exit $? 5741abf7346Smrg 5751abf7346Smrg # Remove the call to Libtool. 5761abf7346Smrg if test "$libtool" = yes; then 5778b6d6341Smrg while test "X$1" != 'X--mode=compile'; do 5781abf7346Smrg shift 5791abf7346Smrg done 5801abf7346Smrg shift 5811abf7346Smrg fi 5821abf7346Smrg 5836d36ef34Smrg # Remove '-o $object'. 5841abf7346Smrg IFS=" " 5851abf7346Smrg for arg 5861abf7346Smrg do 5871abf7346Smrg case $arg in 5881abf7346Smrg -o) 5891abf7346Smrg shift 5901abf7346Smrg ;; 5911abf7346Smrg $object) 5921abf7346Smrg shift 5931abf7346Smrg ;; 5941abf7346Smrg *) 5951abf7346Smrg set fnord "$@" "$arg" 5961abf7346Smrg shift # fnord 5971abf7346Smrg shift # $arg 5981abf7346Smrg ;; 5991abf7346Smrg esac 6001abf7346Smrg done 6011abf7346Smrg 6021abf7346Smrg test -z "$dashmflag" && dashmflag=-M 6036d36ef34Smrg # Require at least two characters before searching for ':' 6041abf7346Smrg # in the target name. This is to cope with DOS-style filenames: 6056d36ef34Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6061abf7346Smrg "$@" $dashmflag | 6076d36ef34Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6081abf7346Smrg rm -f "$depfile" 6091abf7346Smrg cat < "$tmpdepfile" > "$depfile" 6106d36ef34Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6116d36ef34Smrg # correctly. Breaking it into two sed invocations is a workaround. 6126d36ef34Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6136d36ef34Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6146d36ef34Smrg | sed -e 's/$/ :/' >> "$depfile" 6151abf7346Smrg rm -f "$tmpdepfile" 6161abf7346Smrg ;; 6171abf7346Smrg 6181abf7346SmrgdashXmstdout) 6191abf7346Smrg # This case only exists to satisfy depend.m4. It is never actually 6201abf7346Smrg # run, as this mode is specially recognized in the preamble. 6211abf7346Smrg exit 1 6221abf7346Smrg ;; 6231abf7346Smrg 6241abf7346Smrgmakedepend) 6251abf7346Smrg "$@" || exit $? 6261abf7346Smrg # Remove any Libtool call 6271abf7346Smrg if test "$libtool" = yes; then 6288b6d6341Smrg while test "X$1" != 'X--mode=compile'; do 6291abf7346Smrg shift 6301abf7346Smrg done 6311abf7346Smrg shift 6321abf7346Smrg fi 6331abf7346Smrg # X makedepend 6341abf7346Smrg shift 6358b6d6341Smrg cleared=no eat=no 6368b6d6341Smrg for arg 6378b6d6341Smrg do 6381abf7346Smrg case $cleared in 6391abf7346Smrg no) 6401abf7346Smrg set ""; shift 6411abf7346Smrg cleared=yes ;; 6421abf7346Smrg esac 6438b6d6341Smrg if test $eat = yes; then 6448b6d6341Smrg eat=no 6458b6d6341Smrg continue 6468b6d6341Smrg fi 6471abf7346Smrg case "$arg" in 6481abf7346Smrg -D*|-I*) 6491abf7346Smrg set fnord "$@" "$arg"; shift ;; 6501abf7346Smrg # Strip any option that makedepend may not understand. Remove 6511abf7346Smrg # the object too, otherwise makedepend will parse it as a source file. 6528b6d6341Smrg -arch) 6538b6d6341Smrg eat=yes ;; 6541abf7346Smrg -*|$object) 6551abf7346Smrg ;; 6561abf7346Smrg *) 6571abf7346Smrg set fnord "$@" "$arg"; shift ;; 6581abf7346Smrg esac 6591abf7346Smrg done 6608b6d6341Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6611abf7346Smrg touch "$tmpdepfile" 6621abf7346Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6631abf7346Smrg rm -f "$depfile" 6646d36ef34Smrg # makedepend may prepend the VPATH from the source file name to the object. 6656d36ef34Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 6666d36ef34Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6676d36ef34Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6686d36ef34Smrg # correctly. Breaking it into two sed invocations is a workaround. 6696d36ef34Smrg sed '1,2d' "$tmpdepfile" \ 6706d36ef34Smrg | tr ' ' "$nl" \ 6716d36ef34Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6726d36ef34Smrg | sed -e 's/$/ :/' >> "$depfile" 6731abf7346Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6741abf7346Smrg ;; 6751abf7346Smrg 6761abf7346Smrgcpp) 6771abf7346Smrg # Important note: in order to support this mode, a compiler *must* 6781abf7346Smrg # always write the preprocessed file to stdout. 6791abf7346Smrg "$@" || exit $? 6801abf7346Smrg 6811abf7346Smrg # Remove the call to Libtool. 6821abf7346Smrg if test "$libtool" = yes; then 6838b6d6341Smrg while test "X$1" != 'X--mode=compile'; do 6841abf7346Smrg shift 6851abf7346Smrg done 6861abf7346Smrg shift 6871abf7346Smrg fi 6881abf7346Smrg 6896d36ef34Smrg # Remove '-o $object'. 6901abf7346Smrg IFS=" " 6911abf7346Smrg for arg 6921abf7346Smrg do 6931abf7346Smrg case $arg in 6941abf7346Smrg -o) 6951abf7346Smrg shift 6961abf7346Smrg ;; 6971abf7346Smrg $object) 6981abf7346Smrg shift 6991abf7346Smrg ;; 7001abf7346Smrg *) 7011abf7346Smrg set fnord "$@" "$arg" 7021abf7346Smrg shift # fnord 7031abf7346Smrg shift # $arg 7041abf7346Smrg ;; 7051abf7346Smrg esac 7061abf7346Smrg done 7071abf7346Smrg 7086d36ef34Smrg "$@" -E \ 7096d36ef34Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7106d36ef34Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7116d36ef34Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7121abf7346Smrg rm -f "$depfile" 7131abf7346Smrg echo "$object : \\" > "$depfile" 7141abf7346Smrg cat < "$tmpdepfile" >> "$depfile" 7151abf7346Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7161abf7346Smrg rm -f "$tmpdepfile" 7171abf7346Smrg ;; 7181abf7346Smrg 7191abf7346Smrgmsvisualcpp) 7201abf7346Smrg # Important note: in order to support this mode, a compiler *must* 7218b6d6341Smrg # always write the preprocessed file to stdout. 7221abf7346Smrg "$@" || exit $? 7238b6d6341Smrg 7248b6d6341Smrg # Remove the call to Libtool. 7258b6d6341Smrg if test "$libtool" = yes; then 7268b6d6341Smrg while test "X$1" != 'X--mode=compile'; do 7278b6d6341Smrg shift 7288b6d6341Smrg done 7298b6d6341Smrg shift 7308b6d6341Smrg fi 7318b6d6341Smrg 7321abf7346Smrg IFS=" " 7331abf7346Smrg for arg 7341abf7346Smrg do 7351abf7346Smrg case "$arg" in 7368b6d6341Smrg -o) 7378b6d6341Smrg shift 7388b6d6341Smrg ;; 7398b6d6341Smrg $object) 7408b6d6341Smrg shift 7418b6d6341Smrg ;; 7421abf7346Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7436d36ef34Smrg set fnord "$@" 7446d36ef34Smrg shift 7456d36ef34Smrg shift 7466d36ef34Smrg ;; 7471abf7346Smrg *) 7486d36ef34Smrg set fnord "$@" "$arg" 7496d36ef34Smrg shift 7506d36ef34Smrg shift 7516d36ef34Smrg ;; 7521abf7346Smrg esac 7531abf7346Smrg done 7548b6d6341Smrg "$@" -E 2>/dev/null | 7558b6d6341Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7561abf7346Smrg rm -f "$depfile" 7571abf7346Smrg echo "$object : \\" > "$depfile" 7586d36ef34Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7596d36ef34Smrg echo "$tab" >> "$depfile" 7608b6d6341Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7611abf7346Smrg rm -f "$tmpdepfile" 7621abf7346Smrg ;; 7631abf7346Smrg 7648b6d6341Smrgmsvcmsys) 7658b6d6341Smrg # This case exists only to let depend.m4 do its work. It works by 7668b6d6341Smrg # looking at the text of this script. This case will never be run, 7678b6d6341Smrg # since it is checked for above. 7688b6d6341Smrg exit 1 7698b6d6341Smrg ;; 7708b6d6341Smrg 7711abf7346Smrgnone) 7721abf7346Smrg exec "$@" 7731abf7346Smrg ;; 7741abf7346Smrg 7751abf7346Smrg*) 7761abf7346Smrg echo "Unknown depmode $depmode" 1>&2 7771abf7346Smrg exit 1 7781abf7346Smrg ;; 7791abf7346Smrgesac 7801abf7346Smrg 7811abf7346Smrgexit 0 7821abf7346Smrg 7831abf7346Smrg# Local Variables: 7841abf7346Smrg# mode: shell-script 7851abf7346Smrg# sh-indentation: 2 786a5a2a776Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 7871abf7346Smrg# time-stamp-start: "scriptversion=" 7881abf7346Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789a5a2a776Smrg# time-stamp-time-zone: "UTC0" 7908b6d6341Smrg# time-stamp-end: "; # UTC" 7911abf7346Smrg# End: 792