depcomp revision e39ce84c
19aa228fdSmrg#! /bin/sh 29aa228fdSmrg# depcomp - compile a program generating dependencies as side-effects 39aa228fdSmrg 4e39ce84cSmrgscriptversion=2018-03-07.03; # UTC 59aa228fdSmrg 6e39ce84cSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 79aa228fdSmrg 89aa228fdSmrg# This program is free software; you can redistribute it and/or modify 99aa228fdSmrg# it under the terms of the GNU General Public License as published by 109aa228fdSmrg# the Free Software Foundation; either version 2, or (at your option) 119aa228fdSmrg# any later version. 129aa228fdSmrg 139aa228fdSmrg# This program is distributed in the hope that it will be useful, 149aa228fdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 159aa228fdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 169aa228fdSmrg# GNU General Public License for more details. 179aa228fdSmrg 189aa228fdSmrg# You should have received a copy of the GNU General Public License 19e39ce84cSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 209aa228fdSmrg 219aa228fdSmrg# As a special exception to the GNU General Public License, if you 229aa228fdSmrg# distribute this file as part of a program that contains a 239aa228fdSmrg# configuration script generated by Autoconf, you may include it under 249aa228fdSmrg# the same distribution terms that you use for the rest of that program. 259aa228fdSmrg 269aa228fdSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 279aa228fdSmrg 289aa228fdSmrgcase $1 in 299aa228fdSmrg '') 300c7e83b2Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 310c7e83b2Smrg exit 1; 320c7e83b2Smrg ;; 339aa228fdSmrg -h | --h*) 349aa228fdSmrg cat <<\EOF 359aa228fdSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 369aa228fdSmrg 379aa228fdSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 389aa228fdSmrgas side-effects. 399aa228fdSmrg 409aa228fdSmrgEnvironment variables: 419aa228fdSmrg depmode Dependency tracking mode. 420c7e83b2Smrg source Source file read by 'PROGRAMS ARGS'. 430c7e83b2Smrg object Object file output by 'PROGRAMS ARGS'. 449aa228fdSmrg DEPDIR directory where to store dependencies. 459aa228fdSmrg depfile Dependency file to output. 4680b026c6Smrg tmpdepfile Temporary file to use when outputting dependencies. 479aa228fdSmrg libtool Whether libtool is used (yes/no). 489aa228fdSmrg 499aa228fdSmrgReport bugs to <bug-automake@gnu.org>. 509aa228fdSmrgEOF 519aa228fdSmrg exit $? 529aa228fdSmrg ;; 539aa228fdSmrg -v | --v*) 549aa228fdSmrg echo "depcomp $scriptversion" 559aa228fdSmrg exit $? 569aa228fdSmrg ;; 579aa228fdSmrgesac 589aa228fdSmrg 590c7e83b2Smrg# Get the directory component of the given path, and save it in the 600c7e83b2Smrg# global variables '$dir'. Note that this directory component will 610c7e83b2Smrg# be either empty or ending with a '/' character. This is deliberate. 620c7e83b2Smrgset_dir_from () 630c7e83b2Smrg{ 640c7e83b2Smrg case $1 in 650c7e83b2Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 660c7e83b2Smrg *) dir=;; 670c7e83b2Smrg esac 680c7e83b2Smrg} 690c7e83b2Smrg 700c7e83b2Smrg# Get the suffix-stripped basename of the given path, and save it the 710c7e83b2Smrg# global variable '$base'. 720c7e83b2Smrgset_base_from () 730c7e83b2Smrg{ 740c7e83b2Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 750c7e83b2Smrg} 760c7e83b2Smrg 770c7e83b2Smrg# If no dependency file was actually created by the compiler invocation, 780c7e83b2Smrg# we still have to create a dummy depfile, to avoid errors with the 790c7e83b2Smrg# Makefile "include basename.Plo" scheme. 800c7e83b2Smrgmake_dummy_depfile () 810c7e83b2Smrg{ 820c7e83b2Smrg echo "#dummy" > "$depfile" 830c7e83b2Smrg} 840c7e83b2Smrg 850c7e83b2Smrg# Factor out some common post-processing of the generated depfile. 860c7e83b2Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 870c7e83b2Smrgaix_post_process_depfile () 880c7e83b2Smrg{ 890c7e83b2Smrg # If the compiler actually managed to produce a dependency file, 900c7e83b2Smrg # post-process it. 910c7e83b2Smrg if test -f "$tmpdepfile"; then 920c7e83b2Smrg # Each line is of the form 'foo.o: dependency.h'. 930c7e83b2Smrg # Do two passes, one to just change these to 940c7e83b2Smrg # $object: dependency.h 950c7e83b2Smrg # and one to simply output 960c7e83b2Smrg # dependency.h: 970c7e83b2Smrg # which is needed to avoid the deleted-header problem. 980c7e83b2Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 990c7e83b2Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1000c7e83b2Smrg } > "$depfile" 1010c7e83b2Smrg rm -f "$tmpdepfile" 1020c7e83b2Smrg else 1030c7e83b2Smrg make_dummy_depfile 1040c7e83b2Smrg fi 1050c7e83b2Smrg} 1060c7e83b2Smrg 1070c7e83b2Smrg# A tabulation character. 1080c7e83b2Smrgtab=' ' 1090c7e83b2Smrg# A newline character. 1100c7e83b2Smrgnl=' 1110c7e83b2Smrg' 1120c7e83b2Smrg# Character ranges might be problematic outside the C locale. 1130c7e83b2Smrg# These definitions help. 1140c7e83b2Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1150c7e83b2Smrglower=abcdefghijklmnopqrstuvwxyz 1160c7e83b2Smrgdigits=0123456789 1170c7e83b2Smrgalpha=${upper}${lower} 1180c7e83b2Smrg 1199aa228fdSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1209aa228fdSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1219aa228fdSmrg exit 1 1229aa228fdSmrgfi 1239aa228fdSmrg 1249aa228fdSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1259aa228fdSmrgdepfile=${depfile-`echo "$object" | 1269aa228fdSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1279aa228fdSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1289aa228fdSmrg 1299aa228fdSmrgrm -f "$tmpdepfile" 1309aa228fdSmrg 1310c7e83b2Smrg# Avoid interferences from the environment. 1320c7e83b2Smrggccflag= dashmflag= 1330c7e83b2Smrg 1349aa228fdSmrg# Some modes work just like other modes, but use different flags. We 1359aa228fdSmrg# parameterize here, but still list the modes in the big case below, 1369aa228fdSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1379aa228fdSmrg# here, because this file can only contain one case statement. 1389aa228fdSmrgif test "$depmode" = hp; then 1399aa228fdSmrg # HP compiler uses -M and no extra arg. 1409aa228fdSmrg gccflag=-M 1419aa228fdSmrg depmode=gcc 1429aa228fdSmrgfi 1439aa228fdSmrg 1449aa228fdSmrgif test "$depmode" = dashXmstdout; then 1450c7e83b2Smrg # This is just like dashmstdout with a different argument. 1460c7e83b2Smrg dashmflag=-xM 1470c7e83b2Smrg depmode=dashmstdout 1489aa228fdSmrgfi 1499aa228fdSmrg 1508f65982aSmrgcygpath_u="cygpath -u -f -" 1518f65982aSmrgif test "$depmode" = msvcmsys; then 1520c7e83b2Smrg # This is just like msvisualcpp but w/o cygpath translation. 1530c7e83b2Smrg # Just convert the backslash-escaped backslashes to single forward 1540c7e83b2Smrg # slashes to satisfy depend.m4 1550c7e83b2Smrg cygpath_u='sed s,\\\\,/,g' 1560c7e83b2Smrg depmode=msvisualcpp 1578f65982aSmrgfi 1588f65982aSmrg 15980b026c6Smrgif test "$depmode" = msvc7msys; then 1600c7e83b2Smrg # This is just like msvc7 but w/o cygpath translation. 1610c7e83b2Smrg # Just convert the backslash-escaped backslashes to single forward 1620c7e83b2Smrg # slashes to satisfy depend.m4 1630c7e83b2Smrg cygpath_u='sed s,\\\\,/,g' 1640c7e83b2Smrg depmode=msvc7 1650c7e83b2Smrgfi 1660c7e83b2Smrg 1670c7e83b2Smrgif test "$depmode" = xlc; then 1680c7e83b2Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1690c7e83b2Smrg gccflag=-qmakedep=gcc,-MF 1700c7e83b2Smrg depmode=gcc 17180b026c6Smrgfi 17280b026c6Smrg 1739aa228fdSmrgcase "$depmode" in 1749aa228fdSmrggcc3) 1759aa228fdSmrg## gcc 3 implements dependency tracking that does exactly what 1769aa228fdSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1779aa228fdSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 1789aa228fdSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1799aa228fdSmrg## the command line argument order; so add the flags where they 1809aa228fdSmrg## appear in depend2.am. Note that the slowdown incurred here 1819aa228fdSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1829aa228fdSmrg for arg 1839aa228fdSmrg do 1849aa228fdSmrg case $arg in 1859aa228fdSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1869aa228fdSmrg *) set fnord "$@" "$arg" ;; 1879aa228fdSmrg esac 1889aa228fdSmrg shift # fnord 1899aa228fdSmrg shift # $arg 1909aa228fdSmrg done 1919aa228fdSmrg "$@" 1929aa228fdSmrg stat=$? 1930c7e83b2Smrg if test $stat -ne 0; then 1949aa228fdSmrg rm -f "$tmpdepfile" 1959aa228fdSmrg exit $stat 1969aa228fdSmrg fi 1979aa228fdSmrg mv "$tmpdepfile" "$depfile" 1989aa228fdSmrg ;; 1999aa228fdSmrg 2009aa228fdSmrggcc) 2010c7e83b2Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2020c7e83b2Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2030c7e83b2Smrg## (see the conditional assignment to $gccflag above). 2049aa228fdSmrg## There are various ways to get dependency output from gcc. Here's 2059aa228fdSmrg## why we pick this rather obscure method: 2069aa228fdSmrg## - Don't want to use -MD because we'd like the dependencies to end 2079aa228fdSmrg## up in a subdir. Having to rename by hand is ugly. 2089aa228fdSmrg## (We might end up doing this anyway to support other compilers.) 2099aa228fdSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2100c7e83b2Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2110c7e83b2Smrg## supported by the other compilers which use the 'gcc' depmode. 2129aa228fdSmrg## - Using -M directly means running the compiler twice (even worse 2139aa228fdSmrg## than renaming). 2149aa228fdSmrg if test -z "$gccflag"; then 2159aa228fdSmrg gccflag=-MD, 2169aa228fdSmrg fi 2179aa228fdSmrg "$@" -Wp,"$gccflag$tmpdepfile" 2189aa228fdSmrg stat=$? 2190c7e83b2Smrg if test $stat -ne 0; then 2209aa228fdSmrg rm -f "$tmpdepfile" 2219aa228fdSmrg exit $stat 2229aa228fdSmrg fi 2239aa228fdSmrg rm -f "$depfile" 2249aa228fdSmrg echo "$object : \\" > "$depfile" 2250c7e83b2Smrg # The second -e expression handles DOS-style file names with drive 2260c7e83b2Smrg # letters. 2279aa228fdSmrg sed -e 's/^[^:]*: / /' \ 2289aa228fdSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2290c7e83b2Smrg## This next piece of magic avoids the "deleted header file" problem. 2309aa228fdSmrg## The problem is that when a header file which appears in a .P file 2319aa228fdSmrg## is deleted, the dependency causes make to die (because there is 2329aa228fdSmrg## typically no way to rebuild the header). We avoid this by adding 2339aa228fdSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 2349aa228fdSmrg## this for us directly. 2350c7e83b2Smrg## Some versions of gcc put a space before the ':'. On the theory 2369aa228fdSmrg## that the space means something, we add a space to the output as 23780b026c6Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23880b026c6Smrg## to the object. Take care to not repeat it in the output. 2399aa228fdSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 2409aa228fdSmrg## correctly. Breaking it into two sed invocations is a workaround. 2410c7e83b2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2420c7e83b2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2430c7e83b2Smrg | sed -e 's/$/ :/' >> "$depfile" 2449aa228fdSmrg rm -f "$tmpdepfile" 2459aa228fdSmrg ;; 2469aa228fdSmrg 2479aa228fdSmrghp) 2489aa228fdSmrg # This case exists only to let depend.m4 do its work. It works by 2499aa228fdSmrg # looking at the text of this script. This case will never be run, 2509aa228fdSmrg # since it is checked for above. 2519aa228fdSmrg exit 1 2529aa228fdSmrg ;; 2539aa228fdSmrg 2549aa228fdSmrgsgi) 2559aa228fdSmrg if test "$libtool" = yes; then 2569aa228fdSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2579aa228fdSmrg else 2589aa228fdSmrg "$@" -MDupdate "$tmpdepfile" 2599aa228fdSmrg fi 2609aa228fdSmrg stat=$? 2610c7e83b2Smrg if test $stat -ne 0; then 2629aa228fdSmrg rm -f "$tmpdepfile" 2639aa228fdSmrg exit $stat 2649aa228fdSmrg fi 2659aa228fdSmrg rm -f "$depfile" 2669aa228fdSmrg 2679aa228fdSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2689aa228fdSmrg echo "$object : \\" > "$depfile" 2699aa228fdSmrg # Clip off the initial element (the dependent). Don't try to be 2709aa228fdSmrg # clever and replace this with sed code, as IRIX sed won't handle 2719aa228fdSmrg # lines with more than a fixed number of characters (4096 in 2729aa228fdSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2730c7e83b2Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2749aa228fdSmrg # dependency line. 2750c7e83b2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2760c7e83b2Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2770c7e83b2Smrg | tr "$nl" ' ' >> "$depfile" 2788f65982aSmrg echo >> "$depfile" 2799aa228fdSmrg # The second pass generates a dummy entry for each header file. 2800c7e83b2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2810c7e83b2Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2820c7e83b2Smrg >> "$depfile" 2839aa228fdSmrg else 2840c7e83b2Smrg make_dummy_depfile 2859aa228fdSmrg fi 2869aa228fdSmrg rm -f "$tmpdepfile" 2879aa228fdSmrg ;; 2889aa228fdSmrg 2890c7e83b2Smrgxlc) 2900c7e83b2Smrg # This case exists only to let depend.m4 do its work. It works by 2910c7e83b2Smrg # looking at the text of this script. This case will never be run, 2920c7e83b2Smrg # since it is checked for above. 2930c7e83b2Smrg exit 1 2940c7e83b2Smrg ;; 2950c7e83b2Smrg 2969aa228fdSmrgaix) 2979aa228fdSmrg # The C for AIX Compiler uses -M and outputs the dependencies 2989aa228fdSmrg # in a .u file. In older versions, this file always lives in the 2990c7e83b2Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3009aa228fdSmrg # start of each line; $object doesn't have directory information. 3019aa228fdSmrg # Version 6 uses the directory in both cases. 3020c7e83b2Smrg set_dir_from "$object" 3030c7e83b2Smrg set_base_from "$object" 3049aa228fdSmrg if test "$libtool" = yes; then 3058f65982aSmrg tmpdepfile1=$dir$base.u 3068f65982aSmrg tmpdepfile2=$base.u 3078f65982aSmrg tmpdepfile3=$dir.libs/$base.u 3089aa228fdSmrg "$@" -Wc,-M 3099aa228fdSmrg else 3108f65982aSmrg tmpdepfile1=$dir$base.u 3118f65982aSmrg tmpdepfile2=$dir$base.u 3128f65982aSmrg tmpdepfile3=$dir$base.u 3139aa228fdSmrg "$@" -M 3149aa228fdSmrg fi 3159aa228fdSmrg stat=$? 3160c7e83b2Smrg if test $stat -ne 0; then 3178f65982aSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3189aa228fdSmrg exit $stat 3199aa228fdSmrg fi 3209aa228fdSmrg 3218f65982aSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3228f65982aSmrg do 3238f65982aSmrg test -f "$tmpdepfile" && break 3248f65982aSmrg done 3250c7e83b2Smrg aix_post_process_depfile 3260c7e83b2Smrg ;; 3270c7e83b2Smrg 3280c7e83b2Smrgtcc) 3290c7e83b2Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3300c7e83b2Smrg # FIXME: That version still under development at the moment of writing. 3310c7e83b2Smrg # Make that this statement remains true also for stable, released 3320c7e83b2Smrg # versions. 3330c7e83b2Smrg # It will wrap lines (doesn't matter whether long or short) with a 3340c7e83b2Smrg # trailing '\', as in: 3350c7e83b2Smrg # 3360c7e83b2Smrg # foo.o : \ 3370c7e83b2Smrg # foo.c \ 3380c7e83b2Smrg # foo.h \ 3390c7e83b2Smrg # 3400c7e83b2Smrg # It will put a trailing '\' even on the last line, and will use leading 3410c7e83b2Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3420c7e83b2Smrg # "Emit spaces for -MD"). 3430c7e83b2Smrg "$@" -MD -MF "$tmpdepfile" 3440c7e83b2Smrg stat=$? 3450c7e83b2Smrg if test $stat -ne 0; then 3460c7e83b2Smrg rm -f "$tmpdepfile" 3470c7e83b2Smrg exit $stat 3489aa228fdSmrg fi 3490c7e83b2Smrg rm -f "$depfile" 3500c7e83b2Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3510c7e83b2Smrg # We have to change lines of the first kind to '$object: \'. 3520c7e83b2Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3530c7e83b2Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3540c7e83b2Smrg # dummy dependency, to avoid the deleted-header problem. 3550c7e83b2Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3569aa228fdSmrg rm -f "$tmpdepfile" 3579aa228fdSmrg ;; 3589aa228fdSmrg 3590c7e83b2Smrg## The order of this option in the case statement is important, since the 3600c7e83b2Smrg## shell code in configure will try each of these formats in the order 3610c7e83b2Smrg## listed in this file. A plain '-MD' option would be understood by many 3620c7e83b2Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3630c7e83b2Smrgpgcc) 3640c7e83b2Smrg # Portland's C compiler understands '-MD'. 3650c7e83b2Smrg # Will always output deps to 'file.d' where file is the root name of the 3660c7e83b2Smrg # source file under compilation, even if file resides in a subdirectory. 3670c7e83b2Smrg # The object file name does not affect the name of the '.d' file. 3680c7e83b2Smrg # pgcc 10.2 will output 3699aa228fdSmrg # foo.o: sub/foo.c sub/foo.h 3700c7e83b2Smrg # and will wrap long lines using '\' : 3719aa228fdSmrg # foo.o: sub/foo.c ... \ 3729aa228fdSmrg # sub/foo.h ... \ 3739aa228fdSmrg # ... 3740c7e83b2Smrg set_dir_from "$object" 3750c7e83b2Smrg # Use the source, not the object, to determine the base name, since 3760c7e83b2Smrg # that's sadly what pgcc will do too. 3770c7e83b2Smrg set_base_from "$source" 3780c7e83b2Smrg tmpdepfile=$base.d 3790c7e83b2Smrg 3800c7e83b2Smrg # For projects that build the same source file twice into different object 3810c7e83b2Smrg # files, the pgcc approach of using the *source* file root name can cause 3820c7e83b2Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3830c7e83b2Smrg # the same $tmpdepfile. 3840c7e83b2Smrg lockdir=$base.d-lock 3850c7e83b2Smrg trap " 3860c7e83b2Smrg echo '$0: caught signal, cleaning up...' >&2 3870c7e83b2Smrg rmdir '$lockdir' 3880c7e83b2Smrg exit 1 3890c7e83b2Smrg " 1 2 13 15 3900c7e83b2Smrg numtries=100 3910c7e83b2Smrg i=$numtries 3920c7e83b2Smrg while test $i -gt 0; do 3930c7e83b2Smrg # mkdir is a portable test-and-set. 3940c7e83b2Smrg if mkdir "$lockdir" 2>/dev/null; then 3950c7e83b2Smrg # This process acquired the lock. 3960c7e83b2Smrg "$@" -MD 3970c7e83b2Smrg stat=$? 3980c7e83b2Smrg # Release the lock. 3990c7e83b2Smrg rmdir "$lockdir" 4000c7e83b2Smrg break 4010c7e83b2Smrg else 4020c7e83b2Smrg # If the lock is being held by a different process, wait 4030c7e83b2Smrg # until the winning process is done or we timeout. 4040c7e83b2Smrg while test -d "$lockdir" && test $i -gt 0; do 4050c7e83b2Smrg sleep 1 4060c7e83b2Smrg i=`expr $i - 1` 4070c7e83b2Smrg done 4080c7e83b2Smrg fi 4090c7e83b2Smrg i=`expr $i - 1` 4100c7e83b2Smrg done 4110c7e83b2Smrg trap - 1 2 13 15 4120c7e83b2Smrg if test $i -le 0; then 4130c7e83b2Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4140c7e83b2Smrg echo "$0: check lockdir '$lockdir'" >&2 4150c7e83b2Smrg exit 1 4160c7e83b2Smrg fi 4179aa228fdSmrg 4180c7e83b2Smrg if test $stat -ne 0; then 4199aa228fdSmrg rm -f "$tmpdepfile" 4209aa228fdSmrg exit $stat 4219aa228fdSmrg fi 4229aa228fdSmrg rm -f "$depfile" 4239aa228fdSmrg # Each line is of the form `foo.o: dependent.h', 4249aa228fdSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4259aa228fdSmrg # Do two passes, one to just change these to 4269aa228fdSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 4279aa228fdSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4289aa228fdSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 4299aa228fdSmrg # correctly. Breaking it into two sed invocations is a workaround. 4300c7e83b2Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4310c7e83b2Smrg | sed -e 's/$/ :/' >> "$depfile" 4329aa228fdSmrg rm -f "$tmpdepfile" 4339aa228fdSmrg ;; 4349aa228fdSmrg 4359aa228fdSmrghp2) 4369aa228fdSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4379aa228fdSmrg # compilers, which have integrated preprocessors. The correct option 4389aa228fdSmrg # to use with these is +Maked; it writes dependencies to a file named 4399aa228fdSmrg # 'foo.d', which lands next to the object file, wherever that 4409aa228fdSmrg # happens to be. 4419aa228fdSmrg # Much of this is similar to the tru64 case; see comments there. 4420c7e83b2Smrg set_dir_from "$object" 4430c7e83b2Smrg set_base_from "$object" 4449aa228fdSmrg if test "$libtool" = yes; then 4459aa228fdSmrg tmpdepfile1=$dir$base.d 4469aa228fdSmrg tmpdepfile2=$dir.libs/$base.d 4479aa228fdSmrg "$@" -Wc,+Maked 4489aa228fdSmrg else 4499aa228fdSmrg tmpdepfile1=$dir$base.d 4509aa228fdSmrg tmpdepfile2=$dir$base.d 4519aa228fdSmrg "$@" +Maked 4529aa228fdSmrg fi 4539aa228fdSmrg stat=$? 4540c7e83b2Smrg if test $stat -ne 0; then 4559aa228fdSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4569aa228fdSmrg exit $stat 4579aa228fdSmrg fi 4589aa228fdSmrg 4599aa228fdSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4609aa228fdSmrg do 4619aa228fdSmrg test -f "$tmpdepfile" && break 4629aa228fdSmrg done 4639aa228fdSmrg if test -f "$tmpdepfile"; then 4640c7e83b2Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4650c7e83b2Smrg # Add 'dependent.h:' lines. 4668f65982aSmrg sed -ne '2,${ 4670c7e83b2Smrg s/^ *// 4680c7e83b2Smrg s/ \\*$// 4690c7e83b2Smrg s/$/:/ 4700c7e83b2Smrg p 4710c7e83b2Smrg }' "$tmpdepfile" >> "$depfile" 4729aa228fdSmrg else 4730c7e83b2Smrg make_dummy_depfile 4749aa228fdSmrg fi 4759aa228fdSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 4769aa228fdSmrg ;; 4779aa228fdSmrg 4789aa228fdSmrgtru64) 4790c7e83b2Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4800c7e83b2Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4810c7e83b2Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4820c7e83b2Smrg # dependencies in 'foo.d' instead, so we check for that too. 4830c7e83b2Smrg # Subdirectories are respected. 4840c7e83b2Smrg set_dir_from "$object" 4850c7e83b2Smrg set_base_from "$object" 4860c7e83b2Smrg 4870c7e83b2Smrg if test "$libtool" = yes; then 4880c7e83b2Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4890c7e83b2Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4900c7e83b2Smrg # in $dir$base.o.d. We have to check for both files, because 4910c7e83b2Smrg # one of the two compilations can be disabled. We should prefer 4920c7e83b2Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4930c7e83b2Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4940c7e83b2Smrg # the former would cause a distcleancheck panic. 4950c7e83b2Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4960c7e83b2Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4970c7e83b2Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4980c7e83b2Smrg "$@" -Wc,-MD 4990c7e83b2Smrg else 5000c7e83b2Smrg tmpdepfile1=$dir$base.d 5010c7e83b2Smrg tmpdepfile2=$dir$base.d 5020c7e83b2Smrg tmpdepfile3=$dir$base.d 5030c7e83b2Smrg "$@" -MD 5040c7e83b2Smrg fi 5050c7e83b2Smrg 5060c7e83b2Smrg stat=$? 5070c7e83b2Smrg if test $stat -ne 0; then 5080c7e83b2Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5090c7e83b2Smrg exit $stat 5100c7e83b2Smrg fi 5110c7e83b2Smrg 5120c7e83b2Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5130c7e83b2Smrg do 5140c7e83b2Smrg test -f "$tmpdepfile" && break 5150c7e83b2Smrg done 5160c7e83b2Smrg # Same post-processing that is required for AIX mode. 5170c7e83b2Smrg aix_post_process_depfile 5180c7e83b2Smrg ;; 5199aa228fdSmrg 52080b026c6Smrgmsvc7) 52180b026c6Smrg if test "$libtool" = yes; then 52280b026c6Smrg showIncludes=-Wc,-showIncludes 52380b026c6Smrg else 52480b026c6Smrg showIncludes=-showIncludes 52580b026c6Smrg fi 52680b026c6Smrg "$@" $showIncludes > "$tmpdepfile" 52780b026c6Smrg stat=$? 52880b026c6Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5290c7e83b2Smrg if test $stat -ne 0; then 53080b026c6Smrg rm -f "$tmpdepfile" 53180b026c6Smrg exit $stat 53280b026c6Smrg fi 53380b026c6Smrg rm -f "$depfile" 53480b026c6Smrg echo "$object : \\" > "$depfile" 53580b026c6Smrg # The first sed program below extracts the file names and escapes 53680b026c6Smrg # backslashes for cygpath. The second sed program outputs the file 53780b026c6Smrg # name when reading, but also accumulates all include files in the 53880b026c6Smrg # hold buffer in order to output them again at the end. This only 53980b026c6Smrg # works with sed implementations that can handle large buffers. 54080b026c6Smrg sed < "$tmpdepfile" -n ' 54180b026c6Smrg/^Note: including file: *\(.*\)/ { 54280b026c6Smrg s//\1/ 54380b026c6Smrg s/\\/\\\\/g 54480b026c6Smrg p 54580b026c6Smrg}' | $cygpath_u | sort -u | sed -n ' 54680b026c6Smrgs/ /\\ /g 5470c7e83b2Smrgs/\(.*\)/'"$tab"'\1 \\/p 54880b026c6Smrgs/.\(.*\) \\/\1:/ 54980b026c6SmrgH 55080b026c6Smrg$ { 5510c7e83b2Smrg s/.*/'"$tab"'/ 55280b026c6Smrg G 55380b026c6Smrg p 55480b026c6Smrg}' >> "$depfile" 5550c7e83b2Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55680b026c6Smrg rm -f "$tmpdepfile" 55780b026c6Smrg ;; 55880b026c6Smrg 55980b026c6Smrgmsvc7msys) 56080b026c6Smrg # This case exists only to let depend.m4 do its work. It works by 56180b026c6Smrg # looking at the text of this script. This case will never be run, 56280b026c6Smrg # since it is checked for above. 56380b026c6Smrg exit 1 56480b026c6Smrg ;; 56580b026c6Smrg 5669aa228fdSmrg#nosideeffect) 5679aa228fdSmrg # This comment above is used by automake to tell side-effect 5689aa228fdSmrg # dependency tracking mechanisms from slower ones. 5699aa228fdSmrg 5709aa228fdSmrgdashmstdout) 5719aa228fdSmrg # Important note: in order to support this mode, a compiler *must* 5729aa228fdSmrg # always write the preprocessed file to stdout, regardless of -o. 5739aa228fdSmrg "$@" || exit $? 5749aa228fdSmrg 5759aa228fdSmrg # Remove the call to Libtool. 5769aa228fdSmrg if test "$libtool" = yes; then 5778f65982aSmrg while test "X$1" != 'X--mode=compile'; do 5789aa228fdSmrg shift 5799aa228fdSmrg done 5809aa228fdSmrg shift 5819aa228fdSmrg fi 5829aa228fdSmrg 5830c7e83b2Smrg # Remove '-o $object'. 5849aa228fdSmrg IFS=" " 5859aa228fdSmrg for arg 5869aa228fdSmrg do 5879aa228fdSmrg case $arg in 5889aa228fdSmrg -o) 5899aa228fdSmrg shift 5909aa228fdSmrg ;; 5919aa228fdSmrg $object) 5929aa228fdSmrg shift 5939aa228fdSmrg ;; 5949aa228fdSmrg *) 5959aa228fdSmrg set fnord "$@" "$arg" 5969aa228fdSmrg shift # fnord 5979aa228fdSmrg shift # $arg 5989aa228fdSmrg ;; 5999aa228fdSmrg esac 6009aa228fdSmrg done 6019aa228fdSmrg 6029aa228fdSmrg test -z "$dashmflag" && dashmflag=-M 6030c7e83b2Smrg # Require at least two characters before searching for ':' 6049aa228fdSmrg # in the target name. This is to cope with DOS-style filenames: 6050c7e83b2Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6069aa228fdSmrg "$@" $dashmflag | 6070c7e83b2Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6089aa228fdSmrg rm -f "$depfile" 6099aa228fdSmrg cat < "$tmpdepfile" > "$depfile" 6100c7e83b2Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6110c7e83b2Smrg # correctly. Breaking it into two sed invocations is a workaround. 6120c7e83b2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6130c7e83b2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6140c7e83b2Smrg | sed -e 's/$/ :/' >> "$depfile" 6159aa228fdSmrg rm -f "$tmpdepfile" 6169aa228fdSmrg ;; 6179aa228fdSmrg 6189aa228fdSmrgdashXmstdout) 6199aa228fdSmrg # This case only exists to satisfy depend.m4. It is never actually 6209aa228fdSmrg # run, as this mode is specially recognized in the preamble. 6219aa228fdSmrg exit 1 6229aa228fdSmrg ;; 6239aa228fdSmrg 6249aa228fdSmrgmakedepend) 6259aa228fdSmrg "$@" || exit $? 6269aa228fdSmrg # Remove any Libtool call 6279aa228fdSmrg if test "$libtool" = yes; then 6288f65982aSmrg while test "X$1" != 'X--mode=compile'; do 6299aa228fdSmrg shift 6309aa228fdSmrg done 6319aa228fdSmrg shift 6329aa228fdSmrg fi 6339aa228fdSmrg # X makedepend 6349aa228fdSmrg shift 6358f65982aSmrg cleared=no eat=no 6368f65982aSmrg for arg 6378f65982aSmrg do 6389aa228fdSmrg case $cleared in 6399aa228fdSmrg no) 6409aa228fdSmrg set ""; shift 6419aa228fdSmrg cleared=yes ;; 6429aa228fdSmrg esac 6438f65982aSmrg if test $eat = yes; then 6448f65982aSmrg eat=no 6458f65982aSmrg continue 6468f65982aSmrg fi 6479aa228fdSmrg case "$arg" in 6489aa228fdSmrg -D*|-I*) 6499aa228fdSmrg set fnord "$@" "$arg"; shift ;; 6509aa228fdSmrg # Strip any option that makedepend may not understand. Remove 6519aa228fdSmrg # the object too, otherwise makedepend will parse it as a source file. 6528f65982aSmrg -arch) 6538f65982aSmrg eat=yes ;; 6549aa228fdSmrg -*|$object) 6559aa228fdSmrg ;; 6569aa228fdSmrg *) 6579aa228fdSmrg set fnord "$@" "$arg"; shift ;; 6589aa228fdSmrg esac 6599aa228fdSmrg done 6608f65982aSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6619aa228fdSmrg touch "$tmpdepfile" 6629aa228fdSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6639aa228fdSmrg rm -f "$depfile" 66480b026c6Smrg # makedepend may prepend the VPATH from the source file name to the object. 66580b026c6Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66680b026c6Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6670c7e83b2Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6680c7e83b2Smrg # correctly. Breaking it into two sed invocations is a workaround. 6690c7e83b2Smrg sed '1,2d' "$tmpdepfile" \ 6700c7e83b2Smrg | tr ' ' "$nl" \ 6710c7e83b2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6720c7e83b2Smrg | sed -e 's/$/ :/' >> "$depfile" 6739aa228fdSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6749aa228fdSmrg ;; 6759aa228fdSmrg 6769aa228fdSmrgcpp) 6779aa228fdSmrg # Important note: in order to support this mode, a compiler *must* 6789aa228fdSmrg # always write the preprocessed file to stdout. 6799aa228fdSmrg "$@" || exit $? 6809aa228fdSmrg 6819aa228fdSmrg # Remove the call to Libtool. 6829aa228fdSmrg if test "$libtool" = yes; then 6838f65982aSmrg while test "X$1" != 'X--mode=compile'; do 6849aa228fdSmrg shift 6859aa228fdSmrg done 6869aa228fdSmrg shift 6879aa228fdSmrg fi 6889aa228fdSmrg 6890c7e83b2Smrg # Remove '-o $object'. 6909aa228fdSmrg IFS=" " 6919aa228fdSmrg for arg 6929aa228fdSmrg do 6939aa228fdSmrg case $arg in 6949aa228fdSmrg -o) 6959aa228fdSmrg shift 6969aa228fdSmrg ;; 6979aa228fdSmrg $object) 6989aa228fdSmrg shift 6999aa228fdSmrg ;; 7009aa228fdSmrg *) 7019aa228fdSmrg set fnord "$@" "$arg" 7029aa228fdSmrg shift # fnord 7039aa228fdSmrg shift # $arg 7049aa228fdSmrg ;; 7059aa228fdSmrg esac 7069aa228fdSmrg done 7079aa228fdSmrg 7080c7e83b2Smrg "$@" -E \ 7090c7e83b2Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7100c7e83b2Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7110c7e83b2Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7129aa228fdSmrg rm -f "$depfile" 7139aa228fdSmrg echo "$object : \\" > "$depfile" 7149aa228fdSmrg cat < "$tmpdepfile" >> "$depfile" 7159aa228fdSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7169aa228fdSmrg rm -f "$tmpdepfile" 7179aa228fdSmrg ;; 7189aa228fdSmrg 7199aa228fdSmrgmsvisualcpp) 7209aa228fdSmrg # Important note: in order to support this mode, a compiler *must* 7218f65982aSmrg # always write the preprocessed file to stdout. 7229aa228fdSmrg "$@" || exit $? 7238f65982aSmrg 7248f65982aSmrg # Remove the call to Libtool. 7258f65982aSmrg if test "$libtool" = yes; then 7268f65982aSmrg while test "X$1" != 'X--mode=compile'; do 7278f65982aSmrg shift 7288f65982aSmrg done 7298f65982aSmrg shift 7308f65982aSmrg fi 7318f65982aSmrg 7329aa228fdSmrg IFS=" " 7339aa228fdSmrg for arg 7349aa228fdSmrg do 7359aa228fdSmrg case "$arg" in 7368f65982aSmrg -o) 7378f65982aSmrg shift 7388f65982aSmrg ;; 7398f65982aSmrg $object) 7408f65982aSmrg shift 7418f65982aSmrg ;; 7429aa228fdSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7430c7e83b2Smrg set fnord "$@" 7440c7e83b2Smrg shift 7450c7e83b2Smrg shift 7460c7e83b2Smrg ;; 7479aa228fdSmrg *) 7480c7e83b2Smrg set fnord "$@" "$arg" 7490c7e83b2Smrg shift 7500c7e83b2Smrg shift 7510c7e83b2Smrg ;; 7529aa228fdSmrg esac 7539aa228fdSmrg done 7548f65982aSmrg "$@" -E 2>/dev/null | 7558f65982aSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7569aa228fdSmrg rm -f "$depfile" 7579aa228fdSmrg echo "$object : \\" > "$depfile" 7580c7e83b2Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7590c7e83b2Smrg echo "$tab" >> "$depfile" 7608f65982aSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7619aa228fdSmrg rm -f "$tmpdepfile" 7629aa228fdSmrg ;; 7639aa228fdSmrg 7648f65982aSmrgmsvcmsys) 7658f65982aSmrg # This case exists only to let depend.m4 do its work. It works by 7668f65982aSmrg # looking at the text of this script. This case will never be run, 7678f65982aSmrg # since it is checked for above. 7688f65982aSmrg exit 1 7698f65982aSmrg ;; 7708f65982aSmrg 7719aa228fdSmrgnone) 7729aa228fdSmrg exec "$@" 7739aa228fdSmrg ;; 7749aa228fdSmrg 7759aa228fdSmrg*) 7769aa228fdSmrg echo "Unknown depmode $depmode" 1>&2 7779aa228fdSmrg exit 1 7789aa228fdSmrg ;; 7799aa228fdSmrgesac 7809aa228fdSmrg 7819aa228fdSmrgexit 0 7829aa228fdSmrg 7839aa228fdSmrg# Local Variables: 7849aa228fdSmrg# mode: shell-script 7859aa228fdSmrg# sh-indentation: 2 786e39ce84cSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7879aa228fdSmrg# time-stamp-start: "scriptversion=" 7889aa228fdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789e39ce84cSmrg# time-stamp-time-zone: "UTC0" 7908f65982aSmrg# time-stamp-end: "; # UTC" 7919aa228fdSmrg# End: 792