depcomp revision 46374b8d
17117f1b4Smrg#! /bin/sh 27117f1b4Smrg# depcomp - compile a program generating dependencies as side-effects 37117f1b4Smrg 47117f1b4Smrgscriptversion=2024-06-19.01; # UTC 57117f1b4Smrg 67117f1b4Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 77117f1b4Smrg 87117f1b4Smrg# This program is free software; you can redistribute it and/or modify 97117f1b4Smrg# it under the terms of the GNU General Public License as published by 107117f1b4Smrg# the Free Software Foundation; either version 2, or (at your option) 117117f1b4Smrg# any later version. 127117f1b4Smrg 137117f1b4Smrg# This program is distributed in the hope that it will be useful, 147117f1b4Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 157117f1b4Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 167117f1b4Smrg# GNU General Public License for more details. 177117f1b4Smrg 187117f1b4Smrg# You should have received a copy of the GNU General Public License 197117f1b4Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 207117f1b4Smrg 217117f1b4Smrg# As a special exception to the GNU General Public License, if you 227117f1b4Smrg# distribute this file as part of a program that contains a 237117f1b4Smrg# configuration script generated by Autoconf, you may include it under 247117f1b4Smrg# the same distribution terms that you use for the rest of that program. 257117f1b4Smrg 267117f1b4Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 277117f1b4Smrg 287117f1b4Smrgcase $1 in 297117f1b4Smrg '') 307117f1b4Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 317117f1b4Smrg exit 1; 327117f1b4Smrg ;; 337117f1b4Smrg -h | --h*) 347117f1b4Smrg cat <<\EOF 357117f1b4SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 367117f1b4Smrg 377117f1b4SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 387117f1b4Smrgas side-effects. 397117f1b4Smrg 407117f1b4SmrgEnvironment variables: 417117f1b4Smrg depmode Dependency tracking mode. 427117f1b4Smrg source Source file read by 'PROGRAMS ARGS'. 437117f1b4Smrg object Object file output by 'PROGRAMS ARGS'. 447117f1b4Smrg DEPDIR directory where to store dependencies. 457117f1b4Smrg depfile Dependency file to output. 467117f1b4Smrg tmpdepfile Temporary file to use when outputting dependencies. 477117f1b4Smrg libtool Whether libtool is used (yes/no). 487117f1b4Smrg 497117f1b4SmrgReport bugs to <bug-automake@gnu.org>. 507117f1b4SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 517117f1b4SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 527117f1b4SmrgEOF 537117f1b4Smrg exit $? 547117f1b4Smrg ;; 557117f1b4Smrg -v | --v*) 567117f1b4Smrg echo "depcomp (GNU Automake) $scriptversion" 577117f1b4Smrg exit $? 587117f1b4Smrg ;; 597117f1b4Smrgesac 607117f1b4Smrg 617117f1b4Smrg# Get the directory component of the given path, and save it in the 627117f1b4Smrg# global variables '$dir'. Note that this directory component will 637117f1b4Smrg# be either empty or ending with a '/' character. This is deliberate. 647117f1b4Smrgset_dir_from () 657117f1b4Smrg{ 667117f1b4Smrg case $1 in 677117f1b4Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 687117f1b4Smrg *) dir=;; 697117f1b4Smrg esac 707117f1b4Smrg} 717117f1b4Smrg 727117f1b4Smrg# Get the suffix-stripped basename of the given path, and save it the 737117f1b4Smrg# global variable '$base'. 747117f1b4Smrgset_base_from () 757117f1b4Smrg{ 767117f1b4Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 777117f1b4Smrg} 787117f1b4Smrg 797117f1b4Smrg# If no dependency file was actually created by the compiler invocation, 807117f1b4Smrg# we still have to create a dummy depfile, to avoid errors with the 817117f1b4Smrg# Makefile "include basename.Plo" scheme. 827117f1b4Smrgmake_dummy_depfile () 837117f1b4Smrg{ 847117f1b4Smrg echo "#dummy" > "$depfile" 857117f1b4Smrg} 867117f1b4Smrg 877117f1b4Smrg# Factor out some common post-processing of the generated depfile. 887117f1b4Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 897117f1b4Smrgaix_post_process_depfile () 907117f1b4Smrg{ 917117f1b4Smrg # If the compiler actually managed to produce a dependency file, 927117f1b4Smrg # post-process it. 937117f1b4Smrg if test -f "$tmpdepfile"; then 947117f1b4Smrg # Each line is of the form 'foo.o: dependency.h'. 957117f1b4Smrg # Do two passes, one to just change these to 967117f1b4Smrg # $object: dependency.h 977117f1b4Smrg # and one to simply output 987117f1b4Smrg # dependency.h: 997117f1b4Smrg # which is needed to avoid the deleted-header problem. 1007117f1b4Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 1017117f1b4Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1027117f1b4Smrg } > "$depfile" 1037117f1b4Smrg rm -f "$tmpdepfile" 1047117f1b4Smrg else 1057117f1b4Smrg make_dummy_depfile 1067117f1b4Smrg fi 1077117f1b4Smrg} 1087117f1b4Smrg 1097117f1b4Smrg# A tabulation character. 1107117f1b4Smrgtab=' ' 1117117f1b4Smrg# A newline character. 1127117f1b4Smrgnl=' 1137117f1b4Smrg' 1147117f1b4Smrg# Character ranges might be problematic outside the C locale. 1157117f1b4Smrg# These definitions help. 1167117f1b4Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1177117f1b4Smrglower=abcdefghijklmnopqrstuvwxyz 1187117f1b4Smrgalpha=${upper}${lower} 1197117f1b4Smrg 1207117f1b4Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1217117f1b4Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1227117f1b4Smrg exit 1 1237117f1b4Smrgfi 1247117f1b4Smrg 1257117f1b4Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1267117f1b4Smrgdepfile=${depfile-`echo "$object" | 1277117f1b4Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1287117f1b4Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1297117f1b4Smrg 1307117f1b4Smrgrm -f "$tmpdepfile" 1317117f1b4Smrg 1327117f1b4Smrg# Avoid interference from the environment. 1337117f1b4Smrggccflag= dashmflag= 1347117f1b4Smrg 1357117f1b4Smrg# Some modes work just like other modes, but use different flags. We 1367117f1b4Smrg# parameterize here, but still list the modes in the big case below, 1377117f1b4Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1387117f1b4Smrg# here, because this file can only contain one case statement. 1397117f1b4Smrgif test "$depmode" = hp; then 1407117f1b4Smrg # HP compiler uses -M and no extra arg. 1417117f1b4Smrg gccflag=-M 1427117f1b4Smrg depmode=gcc 1437117f1b4Smrgfi 1447117f1b4Smrg 1457117f1b4Smrgif test "$depmode" = dashXmstdout; then 1467117f1b4Smrg # This is just like dashmstdout with a different argument. 1477117f1b4Smrg dashmflag=-xM 1487117f1b4Smrg depmode=dashmstdout 1497117f1b4Smrgfi 1507117f1b4Smrg 1517117f1b4Smrgcygpath_u="cygpath -u -f -" 1527117f1b4Smrgif test "$depmode" = msvcmsys; then 1537117f1b4Smrg # This is just like msvisualcpp but w/o cygpath translation. 1547117f1b4Smrg # Just convert the backslash-escaped backslashes to single forward 1557117f1b4Smrg # slashes to satisfy depend.m4 1567117f1b4Smrg cygpath_u='sed s,\\\\,/,g' 1577117f1b4Smrg depmode=msvisualcpp 1587117f1b4Smrgfi 1597117f1b4Smrg 1607117f1b4Smrgif test "$depmode" = msvc7msys; then 1617117f1b4Smrg # This is just like msvc7 but w/o cygpath translation. 1627117f1b4Smrg # Just convert the backslash-escaped backslashes to single forward 1637117f1b4Smrg # slashes to satisfy depend.m4 1647117f1b4Smrg cygpath_u='sed s,\\\\,/,g' 1657117f1b4Smrg depmode=msvc7 1667117f1b4Smrgfi 1677117f1b4Smrg 1687117f1b4Smrgif test "$depmode" = xlc; then 1697117f1b4Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1707117f1b4Smrg gccflag=-qmakedep=gcc,-MF 1717117f1b4Smrg depmode=gcc 1727117f1b4Smrgfi 1737117f1b4Smrg 1747117f1b4Smrgcase "$depmode" in 1757117f1b4Smrggcc3) 1767117f1b4Smrg## gcc 3 implements dependency tracking that does exactly what 1777117f1b4Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1787117f1b4Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1797117f1b4Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1807117f1b4Smrg## the command line argument order; so add the flags where they 1817117f1b4Smrg## appear in depend2.am. Note that the slowdown incurred here 1827117f1b4Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1837117f1b4Smrg for arg 1847117f1b4Smrg do 1857117f1b4Smrg case $arg in 1867117f1b4Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1877117f1b4Smrg *) set fnord "$@" "$arg" ;; 1887117f1b4Smrg esac 1897117f1b4Smrg shift # fnord 1907117f1b4Smrg shift # $arg 1917117f1b4Smrg done 1927117f1b4Smrg "$@" 1937117f1b4Smrg stat=$? 1947117f1b4Smrg if test $stat -ne 0; then 1957117f1b4Smrg rm -f "$tmpdepfile" 1967117f1b4Smrg exit $stat 1977117f1b4Smrg fi 1987117f1b4Smrg mv "$tmpdepfile" "$depfile" 1997117f1b4Smrg ;; 2007117f1b4Smrg 2017117f1b4Smrggcc) 2027117f1b4Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 2037117f1b4Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 2047117f1b4Smrg## (see the conditional assignment to $gccflag above). 2057117f1b4Smrg## There are various ways to get dependency output from gcc. Here's 2067117f1b4Smrg## why we pick this rather obscure method: 2077117f1b4Smrg## - Don't want to use -MD because we'd like the dependencies to end 2087117f1b4Smrg## up in a subdir. Having to rename by hand is ugly. 2097117f1b4Smrg## (We might end up doing this anyway to support other compilers.) 2107117f1b4Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2117117f1b4Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2127117f1b4Smrg## supported by the other compilers which use the 'gcc' depmode. 2137117f1b4Smrg## - Using -M directly means running the compiler twice (even worse 2147117f1b4Smrg## than renaming). 2157117f1b4Smrg if test -z "$gccflag"; then 2167117f1b4Smrg gccflag=-MD, 2177117f1b4Smrg fi 2187117f1b4Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2197117f1b4Smrg stat=$? 2207117f1b4Smrg if test $stat -ne 0; then 2217117f1b4Smrg rm -f "$tmpdepfile" 2227117f1b4Smrg exit $stat 2237117f1b4Smrg fi 2247117f1b4Smrg rm -f "$depfile" 2257117f1b4Smrg echo "$object : \\" > "$depfile" 2267117f1b4Smrg # The second -e expression handles DOS-style file names with drive 2277117f1b4Smrg # letters. 2287117f1b4Smrg sed -e 's/^[^:]*: / /' \ 2297117f1b4Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2307117f1b4Smrg## This next piece of magic avoids the "deleted header file" problem. 2317117f1b4Smrg## The problem is that when a header file which appears in a .P file 2327117f1b4Smrg## is deleted, the dependency causes make to die (because there is 2337117f1b4Smrg## typically no way to rebuild the header). We avoid this by adding 2347117f1b4Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2357117f1b4Smrg## this for us directly. 2367117f1b4Smrg## Some versions of gcc put a space before the ':'. On the theory 2377117f1b4Smrg## that the space means something, we add a space to the output as 2387117f1b4Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 2397117f1b4Smrg## to the object. Take care to not repeat it in the output. 2407117f1b4Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2417117f1b4Smrg## correctly. Breaking it into two sed invocations is a workaround. 2427117f1b4Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2437117f1b4Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2447117f1b4Smrg | sed -e 's/$/ :/' >> "$depfile" 2457117f1b4Smrg rm -f "$tmpdepfile" 2467117f1b4Smrg ;; 2477117f1b4Smrg 2487117f1b4Smrghp) 2497117f1b4Smrg # This case exists only to let depend.m4 do its work. It works by 2507117f1b4Smrg # looking at the text of this script. This case will never be run, 2517117f1b4Smrg # since it is checked for above. 2527117f1b4Smrg exit 1 2537117f1b4Smrg ;; 2547117f1b4Smrg 2557117f1b4Smrgsgi) 2567117f1b4Smrg if test "$libtool" = yes; then 2577117f1b4Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2587117f1b4Smrg else 2597117f1b4Smrg "$@" -MDupdate "$tmpdepfile" 2607117f1b4Smrg fi 2617117f1b4Smrg stat=$? 2627117f1b4Smrg if test $stat -ne 0; then 2637117f1b4Smrg rm -f "$tmpdepfile" 2647117f1b4Smrg exit $stat 2657117f1b4Smrg fi 2667117f1b4Smrg rm -f "$depfile" 2677117f1b4Smrg 2687117f1b4Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2697117f1b4Smrg echo "$object : \\" > "$depfile" 2707117f1b4Smrg # Clip off the initial element (the dependent). Don't try to be 2717117f1b4Smrg # clever and replace this with sed code, as IRIX sed won't handle 2727117f1b4Smrg # lines with more than a fixed number of characters (4096 in 2737117f1b4Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2747117f1b4Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2757117f1b4Smrg # dependency line. 2767117f1b4Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2777117f1b4Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2787117f1b4Smrg | tr "$nl" ' ' >> "$depfile" 2797117f1b4Smrg echo >> "$depfile" 2807117f1b4Smrg # The second pass generates a dummy entry for each header file. 2817117f1b4Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2827117f1b4Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2837117f1b4Smrg >> "$depfile" 2847117f1b4Smrg else 2857117f1b4Smrg make_dummy_depfile 2867117f1b4Smrg fi 2877117f1b4Smrg rm -f "$tmpdepfile" 2887117f1b4Smrg ;; 2897117f1b4Smrg 2907117f1b4Smrgxlc) 2917117f1b4Smrg # This case exists only to let depend.m4 do its work. It works by 2927117f1b4Smrg # looking at the text of this script. This case will never be run, 2937117f1b4Smrg # since it is checked for above. 2947117f1b4Smrg exit 1 2957117f1b4Smrg ;; 2967117f1b4Smrg 2977117f1b4Smrgaix) 2987117f1b4Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2997117f1b4Smrg # in a .u file. In older versions, this file always lives in the 3007117f1b4Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3017117f1b4Smrg # start of each line; $object doesn't have directory information. 3027117f1b4Smrg # Version 6 uses the directory in both cases. 3037117f1b4Smrg set_dir_from "$object" 3047117f1b4Smrg set_base_from "$object" 3057117f1b4Smrg if test "$libtool" = yes; then 3067117f1b4Smrg tmpdepfile1=$dir$base.u 3077117f1b4Smrg tmpdepfile2=$base.u 3087117f1b4Smrg tmpdepfile3=$dir.libs/$base.u 3097117f1b4Smrg "$@" -Wc,-M 3107117f1b4Smrg else 3117117f1b4Smrg tmpdepfile1=$dir$base.u 3127117f1b4Smrg tmpdepfile2=$dir$base.u 3137117f1b4Smrg tmpdepfile3=$dir$base.u 3147117f1b4Smrg "$@" -M 3157117f1b4Smrg fi 3167117f1b4Smrg stat=$? 3177117f1b4Smrg if test $stat -ne 0; then 3187117f1b4Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3197117f1b4Smrg exit $stat 3207117f1b4Smrg fi 3217117f1b4Smrg 3227117f1b4Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3237117f1b4Smrg do 3247117f1b4Smrg test -f "$tmpdepfile" && break 3257117f1b4Smrg done 3267117f1b4Smrg aix_post_process_depfile 3277117f1b4Smrg ;; 3287117f1b4Smrg 3297117f1b4Smrgtcc) 3307117f1b4Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3317117f1b4Smrg # FIXME: That version still under development at the moment of writing. 3327117f1b4Smrg # Make that this statement remains true also for stable, released 3337117f1b4Smrg # versions. 3347117f1b4Smrg # It will wrap lines (doesn't matter whether long or short) with a 3357117f1b4Smrg # trailing '\', as in: 3367117f1b4Smrg # 3377117f1b4Smrg # foo.o : \ 3387117f1b4Smrg # foo.c \ 3397117f1b4Smrg # foo.h \ 3407117f1b4Smrg # 3417117f1b4Smrg # It will put a trailing '\' even on the last line, and will use leading 3427117f1b4Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3437117f1b4Smrg # "Emit spaces for -MD"). 3447117f1b4Smrg "$@" -MD -MF "$tmpdepfile" 3457117f1b4Smrg stat=$? 3467117f1b4Smrg if test $stat -ne 0; then 3477117f1b4Smrg rm -f "$tmpdepfile" 3487117f1b4Smrg exit $stat 3497117f1b4Smrg fi 3507117f1b4Smrg rm -f "$depfile" 3517117f1b4Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3527117f1b4Smrg # We have to change lines of the first kind to '$object: \'. 3537117f1b4Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3547117f1b4Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3557117f1b4Smrg # dummy dependency, to avoid the deleted-header problem. 3567117f1b4Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3577117f1b4Smrg rm -f "$tmpdepfile" 3587117f1b4Smrg ;; 3597117f1b4Smrg 3607117f1b4Smrg## The order of this option in the case statement is important, since the 3617117f1b4Smrg## shell code in configure will try each of these formats in the order 3627117f1b4Smrg## listed in this file. A plain '-MD' option would be understood by many 3637117f1b4Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3647117f1b4Smrgpgcc) 3657117f1b4Smrg # Portland's C compiler understands '-MD'. 3667117f1b4Smrg # Will always output deps to 'file.d' where file is the root name of the 3677117f1b4Smrg # source file under compilation, even if file resides in a subdirectory. 3687117f1b4Smrg # The object file name does not affect the name of the '.d' file. 3697117f1b4Smrg # pgcc 10.2 will output 3707117f1b4Smrg # foo.o: sub/foo.c sub/foo.h 3717117f1b4Smrg # and will wrap long lines using '\' : 3727117f1b4Smrg # foo.o: sub/foo.c ... \ 3737117f1b4Smrg # sub/foo.h ... \ 3747117f1b4Smrg # ... 3757117f1b4Smrg set_dir_from "$object" 3767117f1b4Smrg # Use the source, not the object, to determine the base name, since 3777117f1b4Smrg # that's sadly what pgcc will do too. 3787117f1b4Smrg set_base_from "$source" 3797117f1b4Smrg tmpdepfile=$base.d 3807117f1b4Smrg 3817117f1b4Smrg # For projects that build the same source file twice into different object 3827117f1b4Smrg # files, the pgcc approach of using the *source* file root name can cause 3837117f1b4Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3847117f1b4Smrg # the same $tmpdepfile. 3857117f1b4Smrg lockdir=$base.d-lock 3867117f1b4Smrg trap " 3877117f1b4Smrg echo '$0: caught signal, cleaning up...' >&2 3887117f1b4Smrg rmdir '$lockdir' 3897117f1b4Smrg exit 1 3907117f1b4Smrg " 1 2 13 15 3917117f1b4Smrg numtries=100 3927117f1b4Smrg i=$numtries 3937117f1b4Smrg while test $i -gt 0; do 3947117f1b4Smrg # mkdir is a portable test-and-set. 3957117f1b4Smrg if mkdir "$lockdir" 2>/dev/null; then 3967117f1b4Smrg # This process acquired the lock. 3977117f1b4Smrg "$@" -MD 3987117f1b4Smrg stat=$? 3997117f1b4Smrg # Release the lock. 4007117f1b4Smrg rmdir "$lockdir" 4017117f1b4Smrg break 4027117f1b4Smrg else 4037117f1b4Smrg # If the lock is being held by a different process, wait 4047117f1b4Smrg # until the winning process is done or we timeout. 4057117f1b4Smrg while test -d "$lockdir" && test $i -gt 0; do 4067117f1b4Smrg sleep 1 4077117f1b4Smrg i=`expr $i - 1` 4087117f1b4Smrg done 4097117f1b4Smrg fi 4107117f1b4Smrg i=`expr $i - 1` 4117117f1b4Smrg done 4127117f1b4Smrg trap - 1 2 13 15 4137117f1b4Smrg if test $i -le 0; then 4147117f1b4Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4157117f1b4Smrg echo "$0: check lockdir '$lockdir'" >&2 4167117f1b4Smrg exit 1 4177117f1b4Smrg fi 4187117f1b4Smrg 4197117f1b4Smrg if test $stat -ne 0; then 4207117f1b4Smrg rm -f "$tmpdepfile" 4217117f1b4Smrg exit $stat 4227117f1b4Smrg fi 4237117f1b4Smrg rm -f "$depfile" 4247117f1b4Smrg # Each line is of the form `foo.o: dependent.h', 4257117f1b4Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4267117f1b4Smrg # Do two passes, one to just change these to 4277117f1b4Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4287117f1b4Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4297117f1b4Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4307117f1b4Smrg # correctly. Breaking it into two sed invocations is a workaround. 4317117f1b4Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4327117f1b4Smrg | sed -e 's/$/ :/' >> "$depfile" 4337117f1b4Smrg rm -f "$tmpdepfile" 4347117f1b4Smrg ;; 4357117f1b4Smrg 4367117f1b4Smrghp2) 4377117f1b4Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4387117f1b4Smrg # compilers, which have integrated preprocessors. The correct option 4397117f1b4Smrg # to use with these is +Maked; it writes dependencies to a file named 4407117f1b4Smrg # 'foo.d', which lands next to the object file, wherever that 4417117f1b4Smrg # happens to be. 4427117f1b4Smrg # Much of this is similar to the tru64 case; see comments there. 4437117f1b4Smrg set_dir_from "$object" 4447117f1b4Smrg set_base_from "$object" 4457117f1b4Smrg if test "$libtool" = yes; then 4467117f1b4Smrg tmpdepfile1=$dir$base.d 4477117f1b4Smrg tmpdepfile2=$dir.libs/$base.d 4487117f1b4Smrg "$@" -Wc,+Maked 4497117f1b4Smrg else 4507117f1b4Smrg tmpdepfile1=$dir$base.d 4517117f1b4Smrg tmpdepfile2=$dir$base.d 4527117f1b4Smrg "$@" +Maked 4537117f1b4Smrg fi 4547117f1b4Smrg stat=$? 4557117f1b4Smrg if test $stat -ne 0; then 4567117f1b4Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4577117f1b4Smrg exit $stat 4587117f1b4Smrg fi 4597117f1b4Smrg 4607117f1b4Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4617117f1b4Smrg do 4627117f1b4Smrg test -f "$tmpdepfile" && break 4637117f1b4Smrg done 4647117f1b4Smrg if test -f "$tmpdepfile"; then 4657117f1b4Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4667117f1b4Smrg # Add 'dependent.h:' lines. 4677117f1b4Smrg sed -ne '2,${ 4687117f1b4Smrg s/^ *// 4697117f1b4Smrg s/ \\*$// 4707117f1b4Smrg s/$/:/ 4717117f1b4Smrg p 4727117f1b4Smrg }' "$tmpdepfile" >> "$depfile" 4737117f1b4Smrg else 4747117f1b4Smrg make_dummy_depfile 4757117f1b4Smrg fi 4767117f1b4Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4777117f1b4Smrg ;; 4787117f1b4Smrg 4797117f1b4Smrgtru64) 4807117f1b4Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4817117f1b4Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4827117f1b4Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4837117f1b4Smrg # dependencies in 'foo.d' instead, so we check for that too. 4847117f1b4Smrg # Subdirectories are respected. 4857117f1b4Smrg set_dir_from "$object" 4867117f1b4Smrg set_base_from "$object" 4877117f1b4Smrg 4887117f1b4Smrg if test "$libtool" = yes; then 4897117f1b4Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4907117f1b4Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4917117f1b4Smrg # in $dir$base.o.d. We have to check for both files, because 4927117f1b4Smrg # one of the two compilations can be disabled. We should prefer 4937117f1b4Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4947117f1b4Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4957117f1b4Smrg # the former would cause a distcleancheck panic. 4967117f1b4Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4977117f1b4Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4987117f1b4Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4997117f1b4Smrg "$@" -Wc,-MD 5007117f1b4Smrg else 5017117f1b4Smrg tmpdepfile1=$dir$base.d 5027117f1b4Smrg tmpdepfile2=$dir$base.d 5037117f1b4Smrg tmpdepfile3=$dir$base.d 5047117f1b4Smrg "$@" -MD 5057117f1b4Smrg fi 5067117f1b4Smrg 5077117f1b4Smrg stat=$? 5087117f1b4Smrg if test $stat -ne 0; then 5097117f1b4Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5107117f1b4Smrg exit $stat 5117117f1b4Smrg fi 5127117f1b4Smrg 5137117f1b4Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5147117f1b4Smrg do 5157117f1b4Smrg test -f "$tmpdepfile" && break 5167117f1b4Smrg done 5177117f1b4Smrg # Same post-processing that is required for AIX mode. 5187117f1b4Smrg aix_post_process_depfile 5197117f1b4Smrg ;; 5207117f1b4Smrg 5217117f1b4Smrgmsvc7) 5227117f1b4Smrg if test "$libtool" = yes; then 5237117f1b4Smrg showIncludes=-Wc,-showIncludes 5247117f1b4Smrg else 5257117f1b4Smrg showIncludes=-showIncludes 5267117f1b4Smrg fi 5277117f1b4Smrg "$@" $showIncludes > "$tmpdepfile" 5287117f1b4Smrg stat=$? 5297117f1b4Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5307117f1b4Smrg if test $stat -ne 0; then 5317117f1b4Smrg rm -f "$tmpdepfile" 5327117f1b4Smrg exit $stat 5337117f1b4Smrg fi 5347117f1b4Smrg rm -f "$depfile" 5357117f1b4Smrg echo "$object : \\" > "$depfile" 5367117f1b4Smrg # The first sed program below extracts the file names and escapes 5377117f1b4Smrg # backslashes for cygpath. The second sed program outputs the file 5387117f1b4Smrg # name when reading, but also accumulates all include files in the 5397117f1b4Smrg # hold buffer in order to output them again at the end. This only 5407117f1b4Smrg # works with sed implementations that can handle large buffers. 5417117f1b4Smrg sed < "$tmpdepfile" -n ' 5427117f1b4Smrg/^Note: including file: *\(.*\)/ { 5437117f1b4Smrg s//\1/ 5447117f1b4Smrg s/\\/\\\\/g 5457117f1b4Smrg p 5467117f1b4Smrg}' | $cygpath_u | sort -u | sed -n ' 5477117f1b4Smrgs/ /\\ /g 5487117f1b4Smrgs/\(.*\)/'"$tab"'\1 \\/p 5497117f1b4Smrgs/.\(.*\) \\/\1:/ 5507117f1b4SmrgH 5517117f1b4Smrg$ { 5527117f1b4Smrg s/.*/'"$tab"'/ 5537117f1b4Smrg G 5547117f1b4Smrg p 5557117f1b4Smrg}' >> "$depfile" 5567117f1b4Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5577117f1b4Smrg rm -f "$tmpdepfile" 5587117f1b4Smrg ;; 5597117f1b4Smrg 5607117f1b4Smrgmsvc7msys) 5617117f1b4Smrg # This case exists only to let depend.m4 do its work. It works by 5627117f1b4Smrg # looking at the text of this script. This case will never be run, 5637117f1b4Smrg # since it is checked for above. 5647117f1b4Smrg exit 1 565 ;; 566 567#nosideeffect) 568 # This comment above is used by automake to tell side-effect 569 # dependency tracking mechanisms from slower ones. 570 571dashmstdout) 572 # Important note: in order to support this mode, a compiler *must* 573 # always write the preprocessed file to stdout, regardless of -o. 574 "$@" || exit $? 575 576 # Remove the call to Libtool. 577 if test "$libtool" = yes; then 578 while test "X$1" != 'X--mode=compile'; do 579 shift 580 done 581 shift 582 fi 583 584 # Remove '-o $object'. 585 IFS=" " 586 for arg 587 do 588 case $arg in 589 -o) 590 shift 591 ;; 592 $object) 593 shift 594 ;; 595 *) 596 set fnord "$@" "$arg" 597 shift # fnord 598 shift # $arg 599 ;; 600 esac 601 done 602 603 test -z "$dashmflag" && dashmflag=-M 604 # Require at least two characters before searching for ':' 605 # in the target name. This is to cope with DOS-style filenames: 606 # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 607 "$@" $dashmflag | 608 sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 609 rm -f "$depfile" 610 cat < "$tmpdepfile" > "$depfile" 611 # Some versions of the HPUX 10.20 sed can't process this sed invocation 612 # correctly. Breaking it into two sed invocations is a workaround. 613 tr ' ' "$nl" < "$tmpdepfile" \ 614 | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 615 | sed -e 's/$/ :/' >> "$depfile" 616 rm -f "$tmpdepfile" 617 ;; 618 619dashXmstdout) 620 # This case only exists to satisfy depend.m4. It is never actually 621 # run, as this mode is specially recognized in the preamble. 622 exit 1 623 ;; 624 625makedepend) 626 "$@" || exit $? 627 # Remove any Libtool call 628 if test "$libtool" = yes; then 629 while test "X$1" != 'X--mode=compile'; do 630 shift 631 done 632 shift 633 fi 634 # X makedepend 635 shift 636 cleared=no eat=no 637 for arg 638 do 639 case $cleared in 640 no) 641 set ""; shift 642 cleared=yes ;; 643 esac 644 if test $eat = yes; then 645 eat=no 646 continue 647 fi 648 case "$arg" in 649 -D*|-I*) 650 set fnord "$@" "$arg"; shift ;; 651 # Strip any option that makedepend may not understand. Remove 652 # the object too, otherwise makedepend will parse it as a source file. 653 -arch) 654 eat=yes ;; 655 -*|$object) 656 ;; 657 *) 658 set fnord "$@" "$arg"; shift ;; 659 esac 660 done 661 obj_suffix=`echo "$object" | sed 's/^.*\././'` 662 touch "$tmpdepfile" 663 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 664 rm -f "$depfile" 665 # makedepend may prepend the VPATH from the source file name to the object. 666 # No need to regex-escape $object, excess matching of '.' is harmless. 667 sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 668 # Some versions of the HPUX 10.20 sed can't process the last invocation 669 # correctly. Breaking it into two sed invocations is a workaround. 670 sed '1,2d' "$tmpdepfile" \ 671 | tr ' ' "$nl" \ 672 | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 673 | sed -e 's/$/ :/' >> "$depfile" 674 rm -f "$tmpdepfile" "$tmpdepfile".bak 675 ;; 676 677cpp) 678 # Important note: in order to support this mode, a compiler *must* 679 # always write the preprocessed file to stdout. 680 "$@" || exit $? 681 682 # Remove the call to Libtool. 683 if test "$libtool" = yes; then 684 while test "X$1" != 'X--mode=compile'; do 685 shift 686 done 687 shift 688 fi 689 690 # Remove '-o $object'. 691 IFS=" " 692 for arg 693 do 694 case $arg in 695 -o) 696 shift 697 ;; 698 $object) 699 shift 700 ;; 701 *) 702 set fnord "$@" "$arg" 703 shift # fnord 704 shift # $arg 705 ;; 706 esac 707 done 708 709 "$@" -E \ 710 | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 712 | sed '$ s: \\$::' > "$tmpdepfile" 713 rm -f "$depfile" 714 echo "$object : \\" > "$depfile" 715 cat < "$tmpdepfile" >> "$depfile" 716 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 717 rm -f "$tmpdepfile" 718 ;; 719 720msvisualcpp) 721 # Important note: in order to support this mode, a compiler *must* 722 # always write the preprocessed file to stdout. 723 "$@" || exit $? 724 725 # Remove the call to Libtool. 726 if test "$libtool" = yes; then 727 while test "X$1" != 'X--mode=compile'; do 728 shift 729 done 730 shift 731 fi 732 733 IFS=" " 734 for arg 735 do 736 case "$arg" in 737 -o) 738 shift 739 ;; 740 $object) 741 shift 742 ;; 743 "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 744 set fnord "$@" 745 shift 746 shift 747 ;; 748 *) 749 set fnord "$@" "$arg" 750 shift 751 shift 752 ;; 753 esac 754 done 755 "$@" -E 2>/dev/null | 756 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 757 rm -f "$depfile" 758 echo "$object : \\" > "$depfile" 759 sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 760 echo "$tab" >> "$depfile" 761 sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 762 rm -f "$tmpdepfile" 763 ;; 764 765msvcmsys) 766 # This case exists only to let depend.m4 do its work. It works by 767 # looking at the text of this script. This case will never be run, 768 # since it is checked for above. 769 exit 1 770 ;; 771 772none) 773 exec "$@" 774 ;; 775 776*) 777 echo "Unknown depmode $depmode" 1>&2 778 exit 1 779 ;; 780esac 781 782exit 0 783 784# Local Variables: 785# mode: shell-script 786# sh-indentation: 2 787# eval: (add-hook 'before-save-hook 'time-stamp) 788# time-stamp-start: "scriptversion=" 789# time-stamp-format: "%:y-%02m-%02d.%02H" 790# time-stamp-time-zone: "UTC0" 791# time-stamp-end: "; # UTC" 792# End: 793