19aa228fdSmrg#! /bin/sh 29aa228fdSmrg# depcomp - compile a program generating dependencies as side-effects 39aa228fdSmrg 446374b8dSmrgscriptversion=2024-06-19.01; # UTC 59aa228fdSmrg 646374b8dSmrg# Copyright (C) 1999-2024 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>. 5046374b8dSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 5146374b8dSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 529aa228fdSmrgEOF 539aa228fdSmrg exit $? 549aa228fdSmrg ;; 559aa228fdSmrg -v | --v*) 5646374b8dSmrg echo "depcomp (GNU Automake) $scriptversion" 579aa228fdSmrg exit $? 589aa228fdSmrg ;; 599aa228fdSmrgesac 609aa228fdSmrg 610c7e83b2Smrg# Get the directory component of the given path, and save it in the 620c7e83b2Smrg# global variables '$dir'. Note that this directory component will 630c7e83b2Smrg# be either empty or ending with a '/' character. This is deliberate. 640c7e83b2Smrgset_dir_from () 650c7e83b2Smrg{ 660c7e83b2Smrg case $1 in 670c7e83b2Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 680c7e83b2Smrg *) dir=;; 690c7e83b2Smrg esac 700c7e83b2Smrg} 710c7e83b2Smrg 720c7e83b2Smrg# Get the suffix-stripped basename of the given path, and save it the 730c7e83b2Smrg# global variable '$base'. 740c7e83b2Smrgset_base_from () 750c7e83b2Smrg{ 760c7e83b2Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 770c7e83b2Smrg} 780c7e83b2Smrg 790c7e83b2Smrg# If no dependency file was actually created by the compiler invocation, 800c7e83b2Smrg# we still have to create a dummy depfile, to avoid errors with the 810c7e83b2Smrg# Makefile "include basename.Plo" scheme. 820c7e83b2Smrgmake_dummy_depfile () 830c7e83b2Smrg{ 840c7e83b2Smrg echo "#dummy" > "$depfile" 850c7e83b2Smrg} 860c7e83b2Smrg 870c7e83b2Smrg# Factor out some common post-processing of the generated depfile. 880c7e83b2Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 890c7e83b2Smrgaix_post_process_depfile () 900c7e83b2Smrg{ 910c7e83b2Smrg # If the compiler actually managed to produce a dependency file, 920c7e83b2Smrg # post-process it. 930c7e83b2Smrg if test -f "$tmpdepfile"; then 940c7e83b2Smrg # Each line is of the form 'foo.o: dependency.h'. 950c7e83b2Smrg # Do two passes, one to just change these to 960c7e83b2Smrg # $object: dependency.h 970c7e83b2Smrg # and one to simply output 980c7e83b2Smrg # dependency.h: 990c7e83b2Smrg # which is needed to avoid the deleted-header problem. 1000c7e83b2Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 1010c7e83b2Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1020c7e83b2Smrg } > "$depfile" 1030c7e83b2Smrg rm -f "$tmpdepfile" 1040c7e83b2Smrg else 1050c7e83b2Smrg make_dummy_depfile 1060c7e83b2Smrg fi 1070c7e83b2Smrg} 1080c7e83b2Smrg 1090c7e83b2Smrg# A tabulation character. 1100c7e83b2Smrgtab=' ' 1110c7e83b2Smrg# A newline character. 1120c7e83b2Smrgnl=' 1130c7e83b2Smrg' 1140c7e83b2Smrg# Character ranges might be problematic outside the C locale. 1150c7e83b2Smrg# These definitions help. 1160c7e83b2Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1170c7e83b2Smrglower=abcdefghijklmnopqrstuvwxyz 1180c7e83b2Smrgalpha=${upper}${lower} 1190c7e83b2Smrg 1209aa228fdSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1219aa228fdSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1229aa228fdSmrg exit 1 1239aa228fdSmrgfi 1249aa228fdSmrg 1259aa228fdSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1269aa228fdSmrgdepfile=${depfile-`echo "$object" | 1279aa228fdSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1289aa228fdSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1299aa228fdSmrg 1309aa228fdSmrgrm -f "$tmpdepfile" 1319aa228fdSmrg 13246374b8dSmrg# Avoid interference from the environment. 1330c7e83b2Smrggccflag= dashmflag= 1340c7e83b2Smrg 1359aa228fdSmrg# Some modes work just like other modes, but use different flags. We 1369aa228fdSmrg# parameterize here, but still list the modes in the big case below, 1379aa228fdSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1389aa228fdSmrg# here, because this file can only contain one case statement. 1399aa228fdSmrgif test "$depmode" = hp; then 1409aa228fdSmrg # HP compiler uses -M and no extra arg. 1419aa228fdSmrg gccflag=-M 1429aa228fdSmrg depmode=gcc 1439aa228fdSmrgfi 1449aa228fdSmrg 1459aa228fdSmrgif test "$depmode" = dashXmstdout; then 1460c7e83b2Smrg # This is just like dashmstdout with a different argument. 1470c7e83b2Smrg dashmflag=-xM 1480c7e83b2Smrg depmode=dashmstdout 1499aa228fdSmrgfi 1509aa228fdSmrg 1518f65982aSmrgcygpath_u="cygpath -u -f -" 1528f65982aSmrgif test "$depmode" = msvcmsys; then 1530c7e83b2Smrg # This is just like msvisualcpp but w/o cygpath translation. 1540c7e83b2Smrg # Just convert the backslash-escaped backslashes to single forward 1550c7e83b2Smrg # slashes to satisfy depend.m4 1560c7e83b2Smrg cygpath_u='sed s,\\\\,/,g' 1570c7e83b2Smrg depmode=msvisualcpp 1588f65982aSmrgfi 1598f65982aSmrg 16080b026c6Smrgif test "$depmode" = msvc7msys; then 1610c7e83b2Smrg # This is just like msvc7 but w/o cygpath translation. 1620c7e83b2Smrg # Just convert the backslash-escaped backslashes to single forward 1630c7e83b2Smrg # slashes to satisfy depend.m4 1640c7e83b2Smrg cygpath_u='sed s,\\\\,/,g' 1650c7e83b2Smrg depmode=msvc7 1660c7e83b2Smrgfi 1670c7e83b2Smrg 1680c7e83b2Smrgif test "$depmode" = xlc; then 1690c7e83b2Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1700c7e83b2Smrg gccflag=-qmakedep=gcc,-MF 1710c7e83b2Smrg depmode=gcc 17280b026c6Smrgfi 17380b026c6Smrg 1749aa228fdSmrgcase "$depmode" in 1759aa228fdSmrggcc3) 1769aa228fdSmrg## gcc 3 implements dependency tracking that does exactly what 1779aa228fdSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1789aa228fdSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 1799aa228fdSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1809aa228fdSmrg## the command line argument order; so add the flags where they 1819aa228fdSmrg## appear in depend2.am. Note that the slowdown incurred here 1829aa228fdSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1839aa228fdSmrg for arg 1849aa228fdSmrg do 1859aa228fdSmrg case $arg in 1869aa228fdSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1879aa228fdSmrg *) set fnord "$@" "$arg" ;; 1889aa228fdSmrg esac 1899aa228fdSmrg shift # fnord 1909aa228fdSmrg shift # $arg 1919aa228fdSmrg done 1929aa228fdSmrg "$@" 1939aa228fdSmrg stat=$? 1940c7e83b2Smrg if test $stat -ne 0; then 1959aa228fdSmrg rm -f "$tmpdepfile" 1969aa228fdSmrg exit $stat 1979aa228fdSmrg fi 1989aa228fdSmrg mv "$tmpdepfile" "$depfile" 1999aa228fdSmrg ;; 2009aa228fdSmrg 2019aa228fdSmrggcc) 20246374b8dSmrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 20346374b8dSmrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 2040c7e83b2Smrg## (see the conditional assignment to $gccflag above). 2059aa228fdSmrg## There are various ways to get dependency output from gcc. Here's 2069aa228fdSmrg## why we pick this rather obscure method: 2079aa228fdSmrg## - Don't want to use -MD because we'd like the dependencies to end 2089aa228fdSmrg## up in a subdir. Having to rename by hand is ugly. 2099aa228fdSmrg## (We might end up doing this anyway to support other compilers.) 2109aa228fdSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2110c7e83b2Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2120c7e83b2Smrg## supported by the other compilers which use the 'gcc' depmode. 2139aa228fdSmrg## - Using -M directly means running the compiler twice (even worse 2149aa228fdSmrg## than renaming). 2159aa228fdSmrg if test -z "$gccflag"; then 2169aa228fdSmrg gccflag=-MD, 2179aa228fdSmrg fi 2189aa228fdSmrg "$@" -Wp,"$gccflag$tmpdepfile" 2199aa228fdSmrg stat=$? 2200c7e83b2Smrg if test $stat -ne 0; then 2219aa228fdSmrg rm -f "$tmpdepfile" 2229aa228fdSmrg exit $stat 2239aa228fdSmrg fi 2249aa228fdSmrg rm -f "$depfile" 2259aa228fdSmrg echo "$object : \\" > "$depfile" 2260c7e83b2Smrg # The second -e expression handles DOS-style file names with drive 2270c7e83b2Smrg # letters. 2289aa228fdSmrg sed -e 's/^[^:]*: / /' \ 2299aa228fdSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2300c7e83b2Smrg## This next piece of magic avoids the "deleted header file" problem. 2319aa228fdSmrg## The problem is that when a header file which appears in a .P file 2329aa228fdSmrg## is deleted, the dependency causes make to die (because there is 2339aa228fdSmrg## typically no way to rebuild the header). We avoid this by adding 2349aa228fdSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 2359aa228fdSmrg## this for us directly. 2360c7e83b2Smrg## Some versions of gcc put a space before the ':'. On the theory 2379aa228fdSmrg## that the space means something, we add a space to the output as 23880b026c6Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23980b026c6Smrg## to the object. Take care to not repeat it in the output. 2409aa228fdSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 2419aa228fdSmrg## correctly. Breaking it into two sed invocations is a workaround. 2420c7e83b2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2430c7e83b2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2440c7e83b2Smrg | sed -e 's/$/ :/' >> "$depfile" 2459aa228fdSmrg rm -f "$tmpdepfile" 2469aa228fdSmrg ;; 2479aa228fdSmrg 2489aa228fdSmrghp) 2499aa228fdSmrg # This case exists only to let depend.m4 do its work. It works by 2509aa228fdSmrg # looking at the text of this script. This case will never be run, 2519aa228fdSmrg # since it is checked for above. 2529aa228fdSmrg exit 1 2539aa228fdSmrg ;; 2549aa228fdSmrg 2559aa228fdSmrgsgi) 2569aa228fdSmrg if test "$libtool" = yes; then 2579aa228fdSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2589aa228fdSmrg else 2599aa228fdSmrg "$@" -MDupdate "$tmpdepfile" 2609aa228fdSmrg fi 2619aa228fdSmrg stat=$? 2620c7e83b2Smrg if test $stat -ne 0; then 2639aa228fdSmrg rm -f "$tmpdepfile" 2649aa228fdSmrg exit $stat 2659aa228fdSmrg fi 2669aa228fdSmrg rm -f "$depfile" 2679aa228fdSmrg 2689aa228fdSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2699aa228fdSmrg echo "$object : \\" > "$depfile" 2709aa228fdSmrg # Clip off the initial element (the dependent). Don't try to be 2719aa228fdSmrg # clever and replace this with sed code, as IRIX sed won't handle 2729aa228fdSmrg # lines with more than a fixed number of characters (4096 in 2739aa228fdSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2740c7e83b2Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2759aa228fdSmrg # dependency line. 2760c7e83b2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2770c7e83b2Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2780c7e83b2Smrg | tr "$nl" ' ' >> "$depfile" 2798f65982aSmrg echo >> "$depfile" 2809aa228fdSmrg # The second pass generates a dummy entry for each header file. 2810c7e83b2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2820c7e83b2Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2830c7e83b2Smrg >> "$depfile" 2849aa228fdSmrg else 2850c7e83b2Smrg make_dummy_depfile 2869aa228fdSmrg fi 2879aa228fdSmrg rm -f "$tmpdepfile" 2889aa228fdSmrg ;; 2899aa228fdSmrg 2900c7e83b2Smrgxlc) 2910c7e83b2Smrg # This case exists only to let depend.m4 do its work. It works by 2920c7e83b2Smrg # looking at the text of this script. This case will never be run, 2930c7e83b2Smrg # since it is checked for above. 2940c7e83b2Smrg exit 1 2950c7e83b2Smrg ;; 2960c7e83b2Smrg 2979aa228fdSmrgaix) 2989aa228fdSmrg # The C for AIX Compiler uses -M and outputs the dependencies 2999aa228fdSmrg # in a .u file. In older versions, this file always lives in the 3000c7e83b2Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3019aa228fdSmrg # start of each line; $object doesn't have directory information. 3029aa228fdSmrg # Version 6 uses the directory in both cases. 3030c7e83b2Smrg set_dir_from "$object" 3040c7e83b2Smrg set_base_from "$object" 3059aa228fdSmrg if test "$libtool" = yes; then 3068f65982aSmrg tmpdepfile1=$dir$base.u 3078f65982aSmrg tmpdepfile2=$base.u 3088f65982aSmrg tmpdepfile3=$dir.libs/$base.u 3099aa228fdSmrg "$@" -Wc,-M 3109aa228fdSmrg else 3118f65982aSmrg tmpdepfile1=$dir$base.u 3128f65982aSmrg tmpdepfile2=$dir$base.u 3138f65982aSmrg tmpdepfile3=$dir$base.u 3149aa228fdSmrg "$@" -M 3159aa228fdSmrg fi 3169aa228fdSmrg stat=$? 3170c7e83b2Smrg if test $stat -ne 0; then 3188f65982aSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3199aa228fdSmrg exit $stat 3209aa228fdSmrg fi 3219aa228fdSmrg 3228f65982aSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3238f65982aSmrg do 3248f65982aSmrg test -f "$tmpdepfile" && break 3258f65982aSmrg done 3260c7e83b2Smrg aix_post_process_depfile 3270c7e83b2Smrg ;; 3280c7e83b2Smrg 3290c7e83b2Smrgtcc) 3300c7e83b2Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3310c7e83b2Smrg # FIXME: That version still under development at the moment of writing. 3320c7e83b2Smrg # Make that this statement remains true also for stable, released 3330c7e83b2Smrg # versions. 3340c7e83b2Smrg # It will wrap lines (doesn't matter whether long or short) with a 3350c7e83b2Smrg # trailing '\', as in: 3360c7e83b2Smrg # 3370c7e83b2Smrg # foo.o : \ 3380c7e83b2Smrg # foo.c \ 3390c7e83b2Smrg # foo.h \ 3400c7e83b2Smrg # 3410c7e83b2Smrg # It will put a trailing '\' even on the last line, and will use leading 3420c7e83b2Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3430c7e83b2Smrg # "Emit spaces for -MD"). 3440c7e83b2Smrg "$@" -MD -MF "$tmpdepfile" 3450c7e83b2Smrg stat=$? 3460c7e83b2Smrg if test $stat -ne 0; then 3470c7e83b2Smrg rm -f "$tmpdepfile" 3480c7e83b2Smrg exit $stat 3499aa228fdSmrg fi 3500c7e83b2Smrg rm -f "$depfile" 3510c7e83b2Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3520c7e83b2Smrg # We have to change lines of the first kind to '$object: \'. 3530c7e83b2Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3540c7e83b2Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3550c7e83b2Smrg # dummy dependency, to avoid the deleted-header problem. 3560c7e83b2Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3579aa228fdSmrg rm -f "$tmpdepfile" 3589aa228fdSmrg ;; 3599aa228fdSmrg 3600c7e83b2Smrg## The order of this option in the case statement is important, since the 3610c7e83b2Smrg## shell code in configure will try each of these formats in the order 3620c7e83b2Smrg## listed in this file. A plain '-MD' option would be understood by many 3630c7e83b2Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3640c7e83b2Smrgpgcc) 3650c7e83b2Smrg # Portland's C compiler understands '-MD'. 3660c7e83b2Smrg # Will always output deps to 'file.d' where file is the root name of the 3670c7e83b2Smrg # source file under compilation, even if file resides in a subdirectory. 3680c7e83b2Smrg # The object file name does not affect the name of the '.d' file. 3690c7e83b2Smrg # pgcc 10.2 will output 3709aa228fdSmrg # foo.o: sub/foo.c sub/foo.h 3710c7e83b2Smrg # and will wrap long lines using '\' : 3729aa228fdSmrg # foo.o: sub/foo.c ... \ 3739aa228fdSmrg # sub/foo.h ... \ 3749aa228fdSmrg # ... 3750c7e83b2Smrg set_dir_from "$object" 3760c7e83b2Smrg # Use the source, not the object, to determine the base name, since 3770c7e83b2Smrg # that's sadly what pgcc will do too. 3780c7e83b2Smrg set_base_from "$source" 3790c7e83b2Smrg tmpdepfile=$base.d 3800c7e83b2Smrg 3810c7e83b2Smrg # For projects that build the same source file twice into different object 3820c7e83b2Smrg # files, the pgcc approach of using the *source* file root name can cause 3830c7e83b2Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3840c7e83b2Smrg # the same $tmpdepfile. 3850c7e83b2Smrg lockdir=$base.d-lock 3860c7e83b2Smrg trap " 3870c7e83b2Smrg echo '$0: caught signal, cleaning up...' >&2 3880c7e83b2Smrg rmdir '$lockdir' 3890c7e83b2Smrg exit 1 3900c7e83b2Smrg " 1 2 13 15 3910c7e83b2Smrg numtries=100 3920c7e83b2Smrg i=$numtries 3930c7e83b2Smrg while test $i -gt 0; do 3940c7e83b2Smrg # mkdir is a portable test-and-set. 3950c7e83b2Smrg if mkdir "$lockdir" 2>/dev/null; then 3960c7e83b2Smrg # This process acquired the lock. 3970c7e83b2Smrg "$@" -MD 3980c7e83b2Smrg stat=$? 3990c7e83b2Smrg # Release the lock. 4000c7e83b2Smrg rmdir "$lockdir" 4010c7e83b2Smrg break 4020c7e83b2Smrg else 4030c7e83b2Smrg # If the lock is being held by a different process, wait 4040c7e83b2Smrg # until the winning process is done or we timeout. 4050c7e83b2Smrg while test -d "$lockdir" && test $i -gt 0; do 4060c7e83b2Smrg sleep 1 4070c7e83b2Smrg i=`expr $i - 1` 4080c7e83b2Smrg done 4090c7e83b2Smrg fi 4100c7e83b2Smrg i=`expr $i - 1` 4110c7e83b2Smrg done 4120c7e83b2Smrg trap - 1 2 13 15 4130c7e83b2Smrg if test $i -le 0; then 4140c7e83b2Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4150c7e83b2Smrg echo "$0: check lockdir '$lockdir'" >&2 4160c7e83b2Smrg exit 1 4170c7e83b2Smrg fi 4189aa228fdSmrg 4190c7e83b2Smrg if test $stat -ne 0; then 4209aa228fdSmrg rm -f "$tmpdepfile" 4219aa228fdSmrg exit $stat 4229aa228fdSmrg fi 4239aa228fdSmrg rm -f "$depfile" 4249aa228fdSmrg # Each line is of the form `foo.o: dependent.h', 4259aa228fdSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4269aa228fdSmrg # Do two passes, one to just change these to 4279aa228fdSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 4289aa228fdSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4299aa228fdSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 4309aa228fdSmrg # correctly. Breaking it into two sed invocations is a workaround. 4310c7e83b2Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4320c7e83b2Smrg | sed -e 's/$/ :/' >> "$depfile" 4339aa228fdSmrg rm -f "$tmpdepfile" 4349aa228fdSmrg ;; 4359aa228fdSmrg 4369aa228fdSmrghp2) 4379aa228fdSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4389aa228fdSmrg # compilers, which have integrated preprocessors. The correct option 4399aa228fdSmrg # to use with these is +Maked; it writes dependencies to a file named 4409aa228fdSmrg # 'foo.d', which lands next to the object file, wherever that 4419aa228fdSmrg # happens to be. 4429aa228fdSmrg # Much of this is similar to the tru64 case; see comments there. 4430c7e83b2Smrg set_dir_from "$object" 4440c7e83b2Smrg set_base_from "$object" 4459aa228fdSmrg if test "$libtool" = yes; then 4469aa228fdSmrg tmpdepfile1=$dir$base.d 4479aa228fdSmrg tmpdepfile2=$dir.libs/$base.d 4489aa228fdSmrg "$@" -Wc,+Maked 4499aa228fdSmrg else 4509aa228fdSmrg tmpdepfile1=$dir$base.d 4519aa228fdSmrg tmpdepfile2=$dir$base.d 4529aa228fdSmrg "$@" +Maked 4539aa228fdSmrg fi 4549aa228fdSmrg stat=$? 4550c7e83b2Smrg if test $stat -ne 0; then 4569aa228fdSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4579aa228fdSmrg exit $stat 4589aa228fdSmrg fi 4599aa228fdSmrg 4609aa228fdSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4619aa228fdSmrg do 4629aa228fdSmrg test -f "$tmpdepfile" && break 4639aa228fdSmrg done 4649aa228fdSmrg if test -f "$tmpdepfile"; then 4650c7e83b2Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4660c7e83b2Smrg # Add 'dependent.h:' lines. 4678f65982aSmrg sed -ne '2,${ 4680c7e83b2Smrg s/^ *// 4690c7e83b2Smrg s/ \\*$// 4700c7e83b2Smrg s/$/:/ 4710c7e83b2Smrg p 4720c7e83b2Smrg }' "$tmpdepfile" >> "$depfile" 4739aa228fdSmrg else 4740c7e83b2Smrg make_dummy_depfile 4759aa228fdSmrg fi 4769aa228fdSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 4779aa228fdSmrg ;; 4789aa228fdSmrg 4799aa228fdSmrgtru64) 4800c7e83b2Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4810c7e83b2Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4820c7e83b2Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4830c7e83b2Smrg # dependencies in 'foo.d' instead, so we check for that too. 4840c7e83b2Smrg # Subdirectories are respected. 4850c7e83b2Smrg set_dir_from "$object" 4860c7e83b2Smrg set_base_from "$object" 4870c7e83b2Smrg 4880c7e83b2Smrg if test "$libtool" = yes; then 4890c7e83b2Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4900c7e83b2Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4910c7e83b2Smrg # in $dir$base.o.d. We have to check for both files, because 4920c7e83b2Smrg # one of the two compilations can be disabled. We should prefer 4930c7e83b2Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4940c7e83b2Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4950c7e83b2Smrg # the former would cause a distcleancheck panic. 4960c7e83b2Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4970c7e83b2Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4980c7e83b2Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4990c7e83b2Smrg "$@" -Wc,-MD 5000c7e83b2Smrg else 5010c7e83b2Smrg tmpdepfile1=$dir$base.d 5020c7e83b2Smrg tmpdepfile2=$dir$base.d 5030c7e83b2Smrg tmpdepfile3=$dir$base.d 5040c7e83b2Smrg "$@" -MD 5050c7e83b2Smrg fi 5060c7e83b2Smrg 5070c7e83b2Smrg stat=$? 5080c7e83b2Smrg if test $stat -ne 0; then 5090c7e83b2Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5100c7e83b2Smrg exit $stat 5110c7e83b2Smrg fi 5120c7e83b2Smrg 5130c7e83b2Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5140c7e83b2Smrg do 5150c7e83b2Smrg test -f "$tmpdepfile" && break 5160c7e83b2Smrg done 5170c7e83b2Smrg # Same post-processing that is required for AIX mode. 5180c7e83b2Smrg aix_post_process_depfile 5190c7e83b2Smrg ;; 5209aa228fdSmrg 52180b026c6Smrgmsvc7) 52280b026c6Smrg if test "$libtool" = yes; then 52380b026c6Smrg showIncludes=-Wc,-showIncludes 52480b026c6Smrg else 52580b026c6Smrg showIncludes=-showIncludes 52680b026c6Smrg fi 52780b026c6Smrg "$@" $showIncludes > "$tmpdepfile" 52880b026c6Smrg stat=$? 52980b026c6Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5300c7e83b2Smrg if test $stat -ne 0; then 53180b026c6Smrg rm -f "$tmpdepfile" 53280b026c6Smrg exit $stat 53380b026c6Smrg fi 53480b026c6Smrg rm -f "$depfile" 53580b026c6Smrg echo "$object : \\" > "$depfile" 53680b026c6Smrg # The first sed program below extracts the file names and escapes 53780b026c6Smrg # backslashes for cygpath. The second sed program outputs the file 53880b026c6Smrg # name when reading, but also accumulates all include files in the 53980b026c6Smrg # hold buffer in order to output them again at the end. This only 54080b026c6Smrg # works with sed implementations that can handle large buffers. 54180b026c6Smrg sed < "$tmpdepfile" -n ' 54280b026c6Smrg/^Note: including file: *\(.*\)/ { 54380b026c6Smrg s//\1/ 54480b026c6Smrg s/\\/\\\\/g 54580b026c6Smrg p 54680b026c6Smrg}' | $cygpath_u | sort -u | sed -n ' 54780b026c6Smrgs/ /\\ /g 5480c7e83b2Smrgs/\(.*\)/'"$tab"'\1 \\/p 54980b026c6Smrgs/.\(.*\) \\/\1:/ 55080b026c6SmrgH 55180b026c6Smrg$ { 5520c7e83b2Smrg s/.*/'"$tab"'/ 55380b026c6Smrg G 55480b026c6Smrg p 55580b026c6Smrg}' >> "$depfile" 5560c7e83b2Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55780b026c6Smrg rm -f "$tmpdepfile" 55880b026c6Smrg ;; 55980b026c6Smrg 56080b026c6Smrgmsvc7msys) 56180b026c6Smrg # This case exists only to let depend.m4 do its work. It works by 56280b026c6Smrg # looking at the text of this script. This case will never be run, 56380b026c6Smrg # since it is checked for above. 56480b026c6Smrg exit 1 56580b026c6Smrg ;; 56680b026c6Smrg 5679aa228fdSmrg#nosideeffect) 5689aa228fdSmrg # This comment above is used by automake to tell side-effect 5699aa228fdSmrg # dependency tracking mechanisms from slower ones. 5709aa228fdSmrg 5719aa228fdSmrgdashmstdout) 5729aa228fdSmrg # Important note: in order to support this mode, a compiler *must* 5739aa228fdSmrg # always write the preprocessed file to stdout, regardless of -o. 5749aa228fdSmrg "$@" || exit $? 5759aa228fdSmrg 5769aa228fdSmrg # Remove the call to Libtool. 5779aa228fdSmrg if test "$libtool" = yes; then 5788f65982aSmrg while test "X$1" != 'X--mode=compile'; do 5799aa228fdSmrg shift 5809aa228fdSmrg done 5819aa228fdSmrg shift 5829aa228fdSmrg fi 5839aa228fdSmrg 5840c7e83b2Smrg # Remove '-o $object'. 5859aa228fdSmrg IFS=" " 5869aa228fdSmrg for arg 5879aa228fdSmrg do 5889aa228fdSmrg case $arg in 5899aa228fdSmrg -o) 5909aa228fdSmrg shift 5919aa228fdSmrg ;; 5929aa228fdSmrg $object) 5939aa228fdSmrg shift 5949aa228fdSmrg ;; 5959aa228fdSmrg *) 5969aa228fdSmrg set fnord "$@" "$arg" 5979aa228fdSmrg shift # fnord 5989aa228fdSmrg shift # $arg 5999aa228fdSmrg ;; 6009aa228fdSmrg esac 6019aa228fdSmrg done 6029aa228fdSmrg 6039aa228fdSmrg test -z "$dashmflag" && dashmflag=-M 6040c7e83b2Smrg # Require at least two characters before searching for ':' 6059aa228fdSmrg # in the target name. This is to cope with DOS-style filenames: 6060c7e83b2Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6079aa228fdSmrg "$@" $dashmflag | 6080c7e83b2Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6099aa228fdSmrg rm -f "$depfile" 6109aa228fdSmrg cat < "$tmpdepfile" > "$depfile" 6110c7e83b2Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6120c7e83b2Smrg # correctly. Breaking it into two sed invocations is a workaround. 6130c7e83b2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6140c7e83b2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6150c7e83b2Smrg | sed -e 's/$/ :/' >> "$depfile" 6169aa228fdSmrg rm -f "$tmpdepfile" 6179aa228fdSmrg ;; 6189aa228fdSmrg 6199aa228fdSmrgdashXmstdout) 6209aa228fdSmrg # This case only exists to satisfy depend.m4. It is never actually 6219aa228fdSmrg # run, as this mode is specially recognized in the preamble. 6229aa228fdSmrg exit 1 6239aa228fdSmrg ;; 6249aa228fdSmrg 6259aa228fdSmrgmakedepend) 6269aa228fdSmrg "$@" || exit $? 6279aa228fdSmrg # Remove any Libtool call 6289aa228fdSmrg if test "$libtool" = yes; then 6298f65982aSmrg while test "X$1" != 'X--mode=compile'; do 6309aa228fdSmrg shift 6319aa228fdSmrg done 6329aa228fdSmrg shift 6339aa228fdSmrg fi 6349aa228fdSmrg # X makedepend 6359aa228fdSmrg shift 6368f65982aSmrg cleared=no eat=no 6378f65982aSmrg for arg 6388f65982aSmrg do 6399aa228fdSmrg case $cleared in 6409aa228fdSmrg no) 6419aa228fdSmrg set ""; shift 6429aa228fdSmrg cleared=yes ;; 6439aa228fdSmrg esac 6448f65982aSmrg if test $eat = yes; then 6458f65982aSmrg eat=no 6468f65982aSmrg continue 6478f65982aSmrg fi 6489aa228fdSmrg case "$arg" in 6499aa228fdSmrg -D*|-I*) 6509aa228fdSmrg set fnord "$@" "$arg"; shift ;; 6519aa228fdSmrg # Strip any option that makedepend may not understand. Remove 6529aa228fdSmrg # the object too, otherwise makedepend will parse it as a source file. 6538f65982aSmrg -arch) 6548f65982aSmrg eat=yes ;; 6559aa228fdSmrg -*|$object) 6569aa228fdSmrg ;; 6579aa228fdSmrg *) 6589aa228fdSmrg set fnord "$@" "$arg"; shift ;; 6599aa228fdSmrg esac 6609aa228fdSmrg done 6618f65982aSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6629aa228fdSmrg touch "$tmpdepfile" 6639aa228fdSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6649aa228fdSmrg rm -f "$depfile" 66580b026c6Smrg # makedepend may prepend the VPATH from the source file name to the object. 66680b026c6Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66780b026c6Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6680c7e83b2Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6690c7e83b2Smrg # correctly. Breaking it into two sed invocations is a workaround. 6700c7e83b2Smrg sed '1,2d' "$tmpdepfile" \ 6710c7e83b2Smrg | tr ' ' "$nl" \ 6720c7e83b2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6730c7e83b2Smrg | sed -e 's/$/ :/' >> "$depfile" 6749aa228fdSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6759aa228fdSmrg ;; 6769aa228fdSmrg 6779aa228fdSmrgcpp) 6789aa228fdSmrg # Important note: in order to support this mode, a compiler *must* 6799aa228fdSmrg # always write the preprocessed file to stdout. 6809aa228fdSmrg "$@" || exit $? 6819aa228fdSmrg 6829aa228fdSmrg # Remove the call to Libtool. 6839aa228fdSmrg if test "$libtool" = yes; then 6848f65982aSmrg while test "X$1" != 'X--mode=compile'; do 6859aa228fdSmrg shift 6869aa228fdSmrg done 6879aa228fdSmrg shift 6889aa228fdSmrg fi 6899aa228fdSmrg 6900c7e83b2Smrg # Remove '-o $object'. 6919aa228fdSmrg IFS=" " 6929aa228fdSmrg for arg 6939aa228fdSmrg do 6949aa228fdSmrg case $arg in 6959aa228fdSmrg -o) 6969aa228fdSmrg shift 6979aa228fdSmrg ;; 6989aa228fdSmrg $object) 6999aa228fdSmrg shift 7009aa228fdSmrg ;; 7019aa228fdSmrg *) 7029aa228fdSmrg set fnord "$@" "$arg" 7039aa228fdSmrg shift # fnord 7049aa228fdSmrg shift # $arg 7059aa228fdSmrg ;; 7069aa228fdSmrg esac 7079aa228fdSmrg done 7089aa228fdSmrg 7090c7e83b2Smrg "$@" -E \ 7100c7e83b2Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7110c7e83b2Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7120c7e83b2Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7139aa228fdSmrg rm -f "$depfile" 7149aa228fdSmrg echo "$object : \\" > "$depfile" 7159aa228fdSmrg cat < "$tmpdepfile" >> "$depfile" 7169aa228fdSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7179aa228fdSmrg rm -f "$tmpdepfile" 7189aa228fdSmrg ;; 7199aa228fdSmrg 7209aa228fdSmrgmsvisualcpp) 7219aa228fdSmrg # Important note: in order to support this mode, a compiler *must* 7228f65982aSmrg # always write the preprocessed file to stdout. 7239aa228fdSmrg "$@" || exit $? 7248f65982aSmrg 7258f65982aSmrg # Remove the call to Libtool. 7268f65982aSmrg if test "$libtool" = yes; then 7278f65982aSmrg while test "X$1" != 'X--mode=compile'; do 7288f65982aSmrg shift 7298f65982aSmrg done 7308f65982aSmrg shift 7318f65982aSmrg fi 7328f65982aSmrg 7339aa228fdSmrg IFS=" " 7349aa228fdSmrg for arg 7359aa228fdSmrg do 7369aa228fdSmrg case "$arg" in 7378f65982aSmrg -o) 7388f65982aSmrg shift 7398f65982aSmrg ;; 7408f65982aSmrg $object) 7418f65982aSmrg shift 7428f65982aSmrg ;; 7439aa228fdSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7440c7e83b2Smrg set fnord "$@" 7450c7e83b2Smrg shift 7460c7e83b2Smrg shift 7470c7e83b2Smrg ;; 7489aa228fdSmrg *) 7490c7e83b2Smrg set fnord "$@" "$arg" 7500c7e83b2Smrg shift 7510c7e83b2Smrg shift 7520c7e83b2Smrg ;; 7539aa228fdSmrg esac 7549aa228fdSmrg done 7558f65982aSmrg "$@" -E 2>/dev/null | 7568f65982aSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7579aa228fdSmrg rm -f "$depfile" 7589aa228fdSmrg echo "$object : \\" > "$depfile" 7590c7e83b2Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7600c7e83b2Smrg echo "$tab" >> "$depfile" 7618f65982aSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7629aa228fdSmrg rm -f "$tmpdepfile" 7639aa228fdSmrg ;; 7649aa228fdSmrg 7658f65982aSmrgmsvcmsys) 7668f65982aSmrg # This case exists only to let depend.m4 do its work. It works by 7678f65982aSmrg # looking at the text of this script. This case will never be run, 7688f65982aSmrg # since it is checked for above. 7698f65982aSmrg exit 1 7708f65982aSmrg ;; 7718f65982aSmrg 7729aa228fdSmrgnone) 7739aa228fdSmrg exec "$@" 7749aa228fdSmrg ;; 7759aa228fdSmrg 7769aa228fdSmrg*) 7779aa228fdSmrg echo "Unknown depmode $depmode" 1>&2 7789aa228fdSmrg exit 1 7799aa228fdSmrg ;; 7809aa228fdSmrgesac 7819aa228fdSmrg 7829aa228fdSmrgexit 0 7839aa228fdSmrg 7849aa228fdSmrg# Local Variables: 7859aa228fdSmrg# mode: shell-script 7869aa228fdSmrg# sh-indentation: 2 787e39ce84cSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7889aa228fdSmrg# time-stamp-start: "scriptversion=" 7899aa228fdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 790e39ce84cSmrg# time-stamp-time-zone: "UTC0" 7918f65982aSmrg# time-stamp-end: "; # UTC" 7929aa228fdSmrg# End: 793