11f0ac6a5Smrg#! /bin/sh 21f0ac6a5Smrg# depcomp - compile a program generating dependencies as side-effects 31f0ac6a5Smrg 46ee7d557Smrgscriptversion=2024-06-19.01; # UTC 51f0ac6a5Smrg 66ee7d557Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 71f0ac6a5Smrg 81f0ac6a5Smrg# This program is free software; you can redistribute it and/or modify 91f0ac6a5Smrg# it under the terms of the GNU General Public License as published by 101f0ac6a5Smrg# the Free Software Foundation; either version 2, or (at your option) 111f0ac6a5Smrg# any later version. 121f0ac6a5Smrg 131f0ac6a5Smrg# This program is distributed in the hope that it will be useful, 141f0ac6a5Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 151f0ac6a5Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 161f0ac6a5Smrg# GNU General Public License for more details. 171f0ac6a5Smrg 181f0ac6a5Smrg# You should have received a copy of the GNU General Public License 19d21ab8bcSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 201f0ac6a5Smrg 211f0ac6a5Smrg# As a special exception to the GNU General Public License, if you 221f0ac6a5Smrg# distribute this file as part of a program that contains a 231f0ac6a5Smrg# configuration script generated by Autoconf, you may include it under 241f0ac6a5Smrg# the same distribution terms that you use for the rest of that program. 251f0ac6a5Smrg 261f0ac6a5Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 271f0ac6a5Smrg 281f0ac6a5Smrgcase $1 in 291f0ac6a5Smrg '') 3089c04b6cSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3189c04b6cSmrg exit 1; 3289c04b6cSmrg ;; 331f0ac6a5Smrg -h | --h*) 341f0ac6a5Smrg cat <<\EOF 351f0ac6a5SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 361f0ac6a5Smrg 371f0ac6a5SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 381f0ac6a5Smrgas side-effects. 391f0ac6a5Smrg 401f0ac6a5SmrgEnvironment variables: 411f0ac6a5Smrg depmode Dependency tracking mode. 4289c04b6cSmrg source Source file read by 'PROGRAMS ARGS'. 4389c04b6cSmrg object Object file output by 'PROGRAMS ARGS'. 441f0ac6a5Smrg DEPDIR directory where to store dependencies. 451f0ac6a5Smrg depfile Dependency file to output. 4689c04b6cSmrg tmpdepfile Temporary file to use when outputting dependencies. 471f0ac6a5Smrg libtool Whether libtool is used (yes/no). 481f0ac6a5Smrg 491f0ac6a5SmrgReport bugs to <bug-automake@gnu.org>. 506ee7d557SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 516ee7d557SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 521f0ac6a5SmrgEOF 531f0ac6a5Smrg exit $? 541f0ac6a5Smrg ;; 551f0ac6a5Smrg -v | --v*) 566ee7d557Smrg echo "depcomp (GNU Automake) $scriptversion" 571f0ac6a5Smrg exit $? 581f0ac6a5Smrg ;; 591f0ac6a5Smrgesac 601f0ac6a5Smrg 6189c04b6cSmrg# Get the directory component of the given path, and save it in the 6289c04b6cSmrg# global variables '$dir'. Note that this directory component will 6389c04b6cSmrg# be either empty or ending with a '/' character. This is deliberate. 6489c04b6cSmrgset_dir_from () 6589c04b6cSmrg{ 6689c04b6cSmrg case $1 in 6789c04b6cSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6889c04b6cSmrg *) dir=;; 6989c04b6cSmrg esac 7089c04b6cSmrg} 7189c04b6cSmrg 7289c04b6cSmrg# Get the suffix-stripped basename of the given path, and save it the 7389c04b6cSmrg# global variable '$base'. 7489c04b6cSmrgset_base_from () 7589c04b6cSmrg{ 7689c04b6cSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7789c04b6cSmrg} 7889c04b6cSmrg 7989c04b6cSmrg# If no dependency file was actually created by the compiler invocation, 8089c04b6cSmrg# we still have to create a dummy depfile, to avoid errors with the 8189c04b6cSmrg# Makefile "include basename.Plo" scheme. 8289c04b6cSmrgmake_dummy_depfile () 8389c04b6cSmrg{ 8489c04b6cSmrg echo "#dummy" > "$depfile" 8589c04b6cSmrg} 8689c04b6cSmrg 8789c04b6cSmrg# Factor out some common post-processing of the generated depfile. 8889c04b6cSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8989c04b6cSmrgaix_post_process_depfile () 9089c04b6cSmrg{ 9189c04b6cSmrg # If the compiler actually managed to produce a dependency file, 9289c04b6cSmrg # post-process it. 9389c04b6cSmrg if test -f "$tmpdepfile"; then 9489c04b6cSmrg # Each line is of the form 'foo.o: dependency.h'. 9589c04b6cSmrg # Do two passes, one to just change these to 9689c04b6cSmrg # $object: dependency.h 9789c04b6cSmrg # and one to simply output 9889c04b6cSmrg # dependency.h: 9989c04b6cSmrg # which is needed to avoid the deleted-header problem. 10089c04b6cSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 10189c04b6cSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10289c04b6cSmrg } > "$depfile" 10389c04b6cSmrg rm -f "$tmpdepfile" 10489c04b6cSmrg else 10589c04b6cSmrg make_dummy_depfile 10689c04b6cSmrg fi 10789c04b6cSmrg} 10889c04b6cSmrg 10989c04b6cSmrg# A tabulation character. 11089c04b6cSmrgtab=' ' 11189c04b6cSmrg# A newline character. 11289c04b6cSmrgnl=' 11389c04b6cSmrg' 11489c04b6cSmrg# Character ranges might be problematic outside the C locale. 11589c04b6cSmrg# These definitions help. 11689c04b6cSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11789c04b6cSmrglower=abcdefghijklmnopqrstuvwxyz 11889c04b6cSmrgalpha=${upper}${lower} 11989c04b6cSmrg 1201f0ac6a5Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1211f0ac6a5Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1221f0ac6a5Smrg exit 1 1231f0ac6a5Smrgfi 1241f0ac6a5Smrg 1251f0ac6a5Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1261f0ac6a5Smrgdepfile=${depfile-`echo "$object" | 1271f0ac6a5Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1281f0ac6a5Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1291f0ac6a5Smrg 1301f0ac6a5Smrgrm -f "$tmpdepfile" 1311f0ac6a5Smrg 1326ee7d557Smrg# Avoid interference from the environment. 13389c04b6cSmrggccflag= dashmflag= 13489c04b6cSmrg 1351f0ac6a5Smrg# Some modes work just like other modes, but use different flags. We 1361f0ac6a5Smrg# parameterize here, but still list the modes in the big case below, 1371f0ac6a5Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1381f0ac6a5Smrg# here, because this file can only contain one case statement. 1391f0ac6a5Smrgif test "$depmode" = hp; then 1401f0ac6a5Smrg # HP compiler uses -M and no extra arg. 1411f0ac6a5Smrg gccflag=-M 1421f0ac6a5Smrg depmode=gcc 1431f0ac6a5Smrgfi 1441f0ac6a5Smrg 1451f0ac6a5Smrgif test "$depmode" = dashXmstdout; then 14689c04b6cSmrg # This is just like dashmstdout with a different argument. 14789c04b6cSmrg dashmflag=-xM 14889c04b6cSmrg depmode=dashmstdout 1491f0ac6a5Smrgfi 1501f0ac6a5Smrg 151e5410a46Smrgcygpath_u="cygpath -u -f -" 152e5410a46Smrgif test "$depmode" = msvcmsys; then 15389c04b6cSmrg # This is just like msvisualcpp but w/o cygpath translation. 15489c04b6cSmrg # Just convert the backslash-escaped backslashes to single forward 15589c04b6cSmrg # slashes to satisfy depend.m4 15689c04b6cSmrg cygpath_u='sed s,\\\\,/,g' 15789c04b6cSmrg depmode=msvisualcpp 15889c04b6cSmrgfi 15989c04b6cSmrg 16089c04b6cSmrgif test "$depmode" = msvc7msys; then 16189c04b6cSmrg # This is just like msvc7 but w/o cygpath translation. 16289c04b6cSmrg # Just convert the backslash-escaped backslashes to single forward 16389c04b6cSmrg # slashes to satisfy depend.m4 16489c04b6cSmrg cygpath_u='sed s,\\\\,/,g' 16589c04b6cSmrg depmode=msvc7 16689c04b6cSmrgfi 16789c04b6cSmrg 16889c04b6cSmrgif test "$depmode" = xlc; then 16989c04b6cSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 17089c04b6cSmrg gccflag=-qmakedep=gcc,-MF 17189c04b6cSmrg depmode=gcc 172e5410a46Smrgfi 173e5410a46Smrg 1741f0ac6a5Smrgcase "$depmode" in 1751f0ac6a5Smrggcc3) 1761f0ac6a5Smrg## gcc 3 implements dependency tracking that does exactly what 1771f0ac6a5Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1781f0ac6a5Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1791f0ac6a5Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1801f0ac6a5Smrg## the command line argument order; so add the flags where they 1811f0ac6a5Smrg## appear in depend2.am. Note that the slowdown incurred here 1821f0ac6a5Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1831f0ac6a5Smrg for arg 1841f0ac6a5Smrg do 1851f0ac6a5Smrg case $arg in 1861f0ac6a5Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1871f0ac6a5Smrg *) set fnord "$@" "$arg" ;; 1881f0ac6a5Smrg esac 1891f0ac6a5Smrg shift # fnord 1901f0ac6a5Smrg shift # $arg 1911f0ac6a5Smrg done 1921f0ac6a5Smrg "$@" 1931f0ac6a5Smrg stat=$? 19489c04b6cSmrg if test $stat -ne 0; then 1951f0ac6a5Smrg rm -f "$tmpdepfile" 1961f0ac6a5Smrg exit $stat 1971f0ac6a5Smrg fi 1981f0ac6a5Smrg mv "$tmpdepfile" "$depfile" 1991f0ac6a5Smrg ;; 2001f0ac6a5Smrg 2011f0ac6a5Smrggcc) 2026ee7d557Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 2036ee7d557Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 20489c04b6cSmrg## (see the conditional assignment to $gccflag above). 2051f0ac6a5Smrg## There are various ways to get dependency output from gcc. Here's 2061f0ac6a5Smrg## why we pick this rather obscure method: 2071f0ac6a5Smrg## - Don't want to use -MD because we'd like the dependencies to end 2081f0ac6a5Smrg## up in a subdir. Having to rename by hand is ugly. 2091f0ac6a5Smrg## (We might end up doing this anyway to support other compilers.) 2101f0ac6a5Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21189c04b6cSmrg## -MM, not -M (despite what the docs say). Also, it might not be 21289c04b6cSmrg## supported by the other compilers which use the 'gcc' depmode. 2131f0ac6a5Smrg## - Using -M directly means running the compiler twice (even worse 2141f0ac6a5Smrg## than renaming). 2151f0ac6a5Smrg if test -z "$gccflag"; then 2161f0ac6a5Smrg gccflag=-MD, 2171f0ac6a5Smrg fi 2181f0ac6a5Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2191f0ac6a5Smrg stat=$? 22089c04b6cSmrg if test $stat -ne 0; then 2211f0ac6a5Smrg rm -f "$tmpdepfile" 2221f0ac6a5Smrg exit $stat 2231f0ac6a5Smrg fi 2241f0ac6a5Smrg rm -f "$depfile" 2251f0ac6a5Smrg echo "$object : \\" > "$depfile" 22689c04b6cSmrg # The second -e expression handles DOS-style file names with drive 22789c04b6cSmrg # letters. 2281f0ac6a5Smrg sed -e 's/^[^:]*: / /' \ 2291f0ac6a5Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 23089c04b6cSmrg## This next piece of magic avoids the "deleted header file" problem. 2311f0ac6a5Smrg## The problem is that when a header file which appears in a .P file 2321f0ac6a5Smrg## is deleted, the dependency causes make to die (because there is 2331f0ac6a5Smrg## typically no way to rebuild the header). We avoid this by adding 2341f0ac6a5Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2351f0ac6a5Smrg## this for us directly. 23689c04b6cSmrg## Some versions of gcc put a space before the ':'. On the theory 2371f0ac6a5Smrg## that the space means something, we add a space to the output as 23889c04b6cSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 23989c04b6cSmrg## to the object. Take care to not repeat it in the output. 2401f0ac6a5Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2411f0ac6a5Smrg## correctly. Breaking it into two sed invocations is a workaround. 24289c04b6cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 24389c04b6cSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24489c04b6cSmrg | sed -e 's/$/ :/' >> "$depfile" 2451f0ac6a5Smrg rm -f "$tmpdepfile" 2461f0ac6a5Smrg ;; 2471f0ac6a5Smrg 2481f0ac6a5Smrghp) 2491f0ac6a5Smrg # This case exists only to let depend.m4 do its work. It works by 2501f0ac6a5Smrg # looking at the text of this script. This case will never be run, 2511f0ac6a5Smrg # since it is checked for above. 2521f0ac6a5Smrg exit 1 2531f0ac6a5Smrg ;; 2541f0ac6a5Smrg 2551f0ac6a5Smrgsgi) 2561f0ac6a5Smrg if test "$libtool" = yes; then 2571f0ac6a5Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2581f0ac6a5Smrg else 2591f0ac6a5Smrg "$@" -MDupdate "$tmpdepfile" 2601f0ac6a5Smrg fi 2611f0ac6a5Smrg stat=$? 26289c04b6cSmrg if test $stat -ne 0; then 2631f0ac6a5Smrg rm -f "$tmpdepfile" 2641f0ac6a5Smrg exit $stat 2651f0ac6a5Smrg fi 2661f0ac6a5Smrg rm -f "$depfile" 2671f0ac6a5Smrg 2681f0ac6a5Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2691f0ac6a5Smrg echo "$object : \\" > "$depfile" 2701f0ac6a5Smrg # Clip off the initial element (the dependent). Don't try to be 2711f0ac6a5Smrg # clever and replace this with sed code, as IRIX sed won't handle 2721f0ac6a5Smrg # lines with more than a fixed number of characters (4096 in 2731f0ac6a5Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27489c04b6cSmrg # the IRIX cc adds comments like '#:fec' to the end of the 2751f0ac6a5Smrg # dependency line. 27689c04b6cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 27789c04b6cSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27889c04b6cSmrg | tr "$nl" ' ' >> "$depfile" 279e5410a46Smrg echo >> "$depfile" 2801f0ac6a5Smrg # The second pass generates a dummy entry for each header file. 28189c04b6cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 28289c04b6cSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28389c04b6cSmrg >> "$depfile" 2841f0ac6a5Smrg else 28589c04b6cSmrg make_dummy_depfile 2861f0ac6a5Smrg fi 2871f0ac6a5Smrg rm -f "$tmpdepfile" 2881f0ac6a5Smrg ;; 2891f0ac6a5Smrg 29089c04b6cSmrgxlc) 29189c04b6cSmrg # This case exists only to let depend.m4 do its work. It works by 29289c04b6cSmrg # looking at the text of this script. This case will never be run, 29389c04b6cSmrg # since it is checked for above. 29489c04b6cSmrg exit 1 29589c04b6cSmrg ;; 29689c04b6cSmrg 2971f0ac6a5Smrgaix) 2981f0ac6a5Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2991f0ac6a5Smrg # in a .u file. In older versions, this file always lives in the 30089c04b6cSmrg # current directory. Also, the AIX compiler puts '$object:' at the 3011f0ac6a5Smrg # start of each line; $object doesn't have directory information. 3021f0ac6a5Smrg # Version 6 uses the directory in both cases. 30389c04b6cSmrg set_dir_from "$object" 30489c04b6cSmrg set_base_from "$object" 3051f0ac6a5Smrg if test "$libtool" = yes; then 306e5410a46Smrg tmpdepfile1=$dir$base.u 307e5410a46Smrg tmpdepfile2=$base.u 308e5410a46Smrg tmpdepfile3=$dir.libs/$base.u 3091f0ac6a5Smrg "$@" -Wc,-M 3101f0ac6a5Smrg else 311e5410a46Smrg tmpdepfile1=$dir$base.u 312e5410a46Smrg tmpdepfile2=$dir$base.u 313e5410a46Smrg tmpdepfile3=$dir$base.u 3141f0ac6a5Smrg "$@" -M 3151f0ac6a5Smrg fi 3161f0ac6a5Smrg stat=$? 31789c04b6cSmrg if test $stat -ne 0; then 318e5410a46Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3191f0ac6a5Smrg exit $stat 3201f0ac6a5Smrg fi 3211f0ac6a5Smrg 322e5410a46Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 323e5410a46Smrg do 324e5410a46Smrg test -f "$tmpdepfile" && break 325e5410a46Smrg done 32689c04b6cSmrg aix_post_process_depfile 32789c04b6cSmrg ;; 32889c04b6cSmrg 32989c04b6cSmrgtcc) 33089c04b6cSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33189c04b6cSmrg # FIXME: That version still under development at the moment of writing. 33289c04b6cSmrg # Make that this statement remains true also for stable, released 33389c04b6cSmrg # versions. 33489c04b6cSmrg # It will wrap lines (doesn't matter whether long or short) with a 33589c04b6cSmrg # trailing '\', as in: 33689c04b6cSmrg # 33789c04b6cSmrg # foo.o : \ 33889c04b6cSmrg # foo.c \ 33989c04b6cSmrg # foo.h \ 34089c04b6cSmrg # 34189c04b6cSmrg # It will put a trailing '\' even on the last line, and will use leading 34289c04b6cSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 34389c04b6cSmrg # "Emit spaces for -MD"). 34489c04b6cSmrg "$@" -MD -MF "$tmpdepfile" 34589c04b6cSmrg stat=$? 34689c04b6cSmrg if test $stat -ne 0; then 34789c04b6cSmrg rm -f "$tmpdepfile" 34889c04b6cSmrg exit $stat 3491f0ac6a5Smrg fi 35089c04b6cSmrg rm -f "$depfile" 35189c04b6cSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35289c04b6cSmrg # We have to change lines of the first kind to '$object: \'. 35389c04b6cSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35489c04b6cSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 35589c04b6cSmrg # dummy dependency, to avoid the deleted-header problem. 35689c04b6cSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3571f0ac6a5Smrg rm -f "$tmpdepfile" 3581f0ac6a5Smrg ;; 3591f0ac6a5Smrg 36089c04b6cSmrg## The order of this option in the case statement is important, since the 36189c04b6cSmrg## shell code in configure will try each of these formats in the order 36289c04b6cSmrg## listed in this file. A plain '-MD' option would be understood by many 36389c04b6cSmrg## compilers, so we must ensure this comes after the gcc and icc options. 36489c04b6cSmrgpgcc) 36589c04b6cSmrg # Portland's C compiler understands '-MD'. 36689c04b6cSmrg # Will always output deps to 'file.d' where file is the root name of the 36789c04b6cSmrg # source file under compilation, even if file resides in a subdirectory. 36889c04b6cSmrg # The object file name does not affect the name of the '.d' file. 36989c04b6cSmrg # pgcc 10.2 will output 3701f0ac6a5Smrg # foo.o: sub/foo.c sub/foo.h 37189c04b6cSmrg # and will wrap long lines using '\' : 3721f0ac6a5Smrg # foo.o: sub/foo.c ... \ 3731f0ac6a5Smrg # sub/foo.h ... \ 3741f0ac6a5Smrg # ... 37589c04b6cSmrg set_dir_from "$object" 37689c04b6cSmrg # Use the source, not the object, to determine the base name, since 37789c04b6cSmrg # that's sadly what pgcc will do too. 37889c04b6cSmrg set_base_from "$source" 37989c04b6cSmrg tmpdepfile=$base.d 38089c04b6cSmrg 38189c04b6cSmrg # For projects that build the same source file twice into different object 38289c04b6cSmrg # files, the pgcc approach of using the *source* file root name can cause 38389c04b6cSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38489c04b6cSmrg # the same $tmpdepfile. 38589c04b6cSmrg lockdir=$base.d-lock 38689c04b6cSmrg trap " 38789c04b6cSmrg echo '$0: caught signal, cleaning up...' >&2 38889c04b6cSmrg rmdir '$lockdir' 38989c04b6cSmrg exit 1 39089c04b6cSmrg " 1 2 13 15 39189c04b6cSmrg numtries=100 39289c04b6cSmrg i=$numtries 39389c04b6cSmrg while test $i -gt 0; do 39489c04b6cSmrg # mkdir is a portable test-and-set. 39589c04b6cSmrg if mkdir "$lockdir" 2>/dev/null; then 39689c04b6cSmrg # This process acquired the lock. 39789c04b6cSmrg "$@" -MD 39889c04b6cSmrg stat=$? 39989c04b6cSmrg # Release the lock. 40089c04b6cSmrg rmdir "$lockdir" 40189c04b6cSmrg break 40289c04b6cSmrg else 40389c04b6cSmrg # If the lock is being held by a different process, wait 40489c04b6cSmrg # until the winning process is done or we timeout. 40589c04b6cSmrg while test -d "$lockdir" && test $i -gt 0; do 40689c04b6cSmrg sleep 1 40789c04b6cSmrg i=`expr $i - 1` 40889c04b6cSmrg done 40989c04b6cSmrg fi 41089c04b6cSmrg i=`expr $i - 1` 41189c04b6cSmrg done 41289c04b6cSmrg trap - 1 2 13 15 41389c04b6cSmrg if test $i -le 0; then 41489c04b6cSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41589c04b6cSmrg echo "$0: check lockdir '$lockdir'" >&2 41689c04b6cSmrg exit 1 41789c04b6cSmrg fi 4181f0ac6a5Smrg 41989c04b6cSmrg if test $stat -ne 0; then 4201f0ac6a5Smrg rm -f "$tmpdepfile" 4211f0ac6a5Smrg exit $stat 4221f0ac6a5Smrg fi 4231f0ac6a5Smrg rm -f "$depfile" 4241f0ac6a5Smrg # Each line is of the form `foo.o: dependent.h', 4251f0ac6a5Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4261f0ac6a5Smrg # Do two passes, one to just change these to 4271f0ac6a5Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4281f0ac6a5Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4291f0ac6a5Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4301f0ac6a5Smrg # correctly. Breaking it into two sed invocations is a workaround. 43189c04b6cSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43289c04b6cSmrg | sed -e 's/$/ :/' >> "$depfile" 4331f0ac6a5Smrg rm -f "$tmpdepfile" 4341f0ac6a5Smrg ;; 4351f0ac6a5Smrg 4361f0ac6a5Smrghp2) 4371f0ac6a5Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4381f0ac6a5Smrg # compilers, which have integrated preprocessors. The correct option 4391f0ac6a5Smrg # to use with these is +Maked; it writes dependencies to a file named 4401f0ac6a5Smrg # 'foo.d', which lands next to the object file, wherever that 4411f0ac6a5Smrg # happens to be. 4421f0ac6a5Smrg # Much of this is similar to the tru64 case; see comments there. 44389c04b6cSmrg set_dir_from "$object" 44489c04b6cSmrg set_base_from "$object" 4451f0ac6a5Smrg if test "$libtool" = yes; then 4461f0ac6a5Smrg tmpdepfile1=$dir$base.d 4471f0ac6a5Smrg tmpdepfile2=$dir.libs/$base.d 4481f0ac6a5Smrg "$@" -Wc,+Maked 4491f0ac6a5Smrg else 4501f0ac6a5Smrg tmpdepfile1=$dir$base.d 4511f0ac6a5Smrg tmpdepfile2=$dir$base.d 4521f0ac6a5Smrg "$@" +Maked 4531f0ac6a5Smrg fi 4541f0ac6a5Smrg stat=$? 45589c04b6cSmrg if test $stat -ne 0; then 4561f0ac6a5Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4571f0ac6a5Smrg exit $stat 4581f0ac6a5Smrg fi 4591f0ac6a5Smrg 4601f0ac6a5Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4611f0ac6a5Smrg do 4621f0ac6a5Smrg test -f "$tmpdepfile" && break 4631f0ac6a5Smrg done 4641f0ac6a5Smrg if test -f "$tmpdepfile"; then 46589c04b6cSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46689c04b6cSmrg # Add 'dependent.h:' lines. 467e5410a46Smrg sed -ne '2,${ 46889c04b6cSmrg s/^ *// 46989c04b6cSmrg s/ \\*$// 47089c04b6cSmrg s/$/:/ 47189c04b6cSmrg p 47289c04b6cSmrg }' "$tmpdepfile" >> "$depfile" 4731f0ac6a5Smrg else 47489c04b6cSmrg make_dummy_depfile 4751f0ac6a5Smrg fi 4761f0ac6a5Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4771f0ac6a5Smrg ;; 4781f0ac6a5Smrg 4791f0ac6a5Smrgtru64) 48089c04b6cSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 48189c04b6cSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48289c04b6cSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48389c04b6cSmrg # dependencies in 'foo.d' instead, so we check for that too. 48489c04b6cSmrg # Subdirectories are respected. 48589c04b6cSmrg set_dir_from "$object" 48689c04b6cSmrg set_base_from "$object" 48789c04b6cSmrg 48889c04b6cSmrg if test "$libtool" = yes; then 48989c04b6cSmrg # Libtool generates 2 separate objects for the 2 libraries. These 49089c04b6cSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 49189c04b6cSmrg # in $dir$base.o.d. We have to check for both files, because 49289c04b6cSmrg # one of the two compilations can be disabled. We should prefer 49389c04b6cSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49489c04b6cSmrg # automatically cleaned when .libs/ is deleted, while ignoring 49589c04b6cSmrg # the former would cause a distcleancheck panic. 49689c04b6cSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49789c04b6cSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49889c04b6cSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49989c04b6cSmrg "$@" -Wc,-MD 50089c04b6cSmrg else 50189c04b6cSmrg tmpdepfile1=$dir$base.d 50289c04b6cSmrg tmpdepfile2=$dir$base.d 50389c04b6cSmrg tmpdepfile3=$dir$base.d 50489c04b6cSmrg "$@" -MD 50589c04b6cSmrg fi 50689c04b6cSmrg 50789c04b6cSmrg stat=$? 50889c04b6cSmrg if test $stat -ne 0; then 50989c04b6cSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51089c04b6cSmrg exit $stat 51189c04b6cSmrg fi 51289c04b6cSmrg 51389c04b6cSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51489c04b6cSmrg do 51589c04b6cSmrg test -f "$tmpdepfile" && break 51689c04b6cSmrg done 51789c04b6cSmrg # Same post-processing that is required for AIX mode. 51889c04b6cSmrg aix_post_process_depfile 51989c04b6cSmrg ;; 52089c04b6cSmrg 52189c04b6cSmrgmsvc7) 52289c04b6cSmrg if test "$libtool" = yes; then 52389c04b6cSmrg showIncludes=-Wc,-showIncludes 52489c04b6cSmrg else 52589c04b6cSmrg showIncludes=-showIncludes 52689c04b6cSmrg fi 52789c04b6cSmrg "$@" $showIncludes > "$tmpdepfile" 52889c04b6cSmrg stat=$? 52989c04b6cSmrg grep -v '^Note: including file: ' "$tmpdepfile" 53089c04b6cSmrg if test $stat -ne 0; then 53189c04b6cSmrg rm -f "$tmpdepfile" 53289c04b6cSmrg exit $stat 53389c04b6cSmrg fi 53489c04b6cSmrg rm -f "$depfile" 53589c04b6cSmrg echo "$object : \\" > "$depfile" 53689c04b6cSmrg # The first sed program below extracts the file names and escapes 53789c04b6cSmrg # backslashes for cygpath. The second sed program outputs the file 53889c04b6cSmrg # name when reading, but also accumulates all include files in the 53989c04b6cSmrg # hold buffer in order to output them again at the end. This only 54089c04b6cSmrg # works with sed implementations that can handle large buffers. 54189c04b6cSmrg sed < "$tmpdepfile" -n ' 54289c04b6cSmrg/^Note: including file: *\(.*\)/ { 54389c04b6cSmrg s//\1/ 54489c04b6cSmrg s/\\/\\\\/g 54589c04b6cSmrg p 54689c04b6cSmrg}' | $cygpath_u | sort -u | sed -n ' 54789c04b6cSmrgs/ /\\ /g 54889c04b6cSmrgs/\(.*\)/'"$tab"'\1 \\/p 54989c04b6cSmrgs/.\(.*\) \\/\1:/ 55089c04b6cSmrgH 55189c04b6cSmrg$ { 55289c04b6cSmrg s/.*/'"$tab"'/ 55389c04b6cSmrg G 55489c04b6cSmrg p 55589c04b6cSmrg}' >> "$depfile" 556b9867631Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55789c04b6cSmrg rm -f "$tmpdepfile" 55889c04b6cSmrg ;; 55989c04b6cSmrg 56089c04b6cSmrgmsvc7msys) 56189c04b6cSmrg # This case exists only to let depend.m4 do its work. It works by 56289c04b6cSmrg # looking at the text of this script. This case will never be run, 56389c04b6cSmrg # since it is checked for above. 56489c04b6cSmrg exit 1 56589c04b6cSmrg ;; 5661f0ac6a5Smrg 5671f0ac6a5Smrg#nosideeffect) 5681f0ac6a5Smrg # This comment above is used by automake to tell side-effect 5691f0ac6a5Smrg # dependency tracking mechanisms from slower ones. 5701f0ac6a5Smrg 5711f0ac6a5Smrgdashmstdout) 5721f0ac6a5Smrg # Important note: in order to support this mode, a compiler *must* 5731f0ac6a5Smrg # always write the preprocessed file to stdout, regardless of -o. 5741f0ac6a5Smrg "$@" || exit $? 5751f0ac6a5Smrg 5761f0ac6a5Smrg # Remove the call to Libtool. 5771f0ac6a5Smrg if test "$libtool" = yes; then 578e5410a46Smrg while test "X$1" != 'X--mode=compile'; do 5791f0ac6a5Smrg shift 5801f0ac6a5Smrg done 5811f0ac6a5Smrg shift 5821f0ac6a5Smrg fi 5831f0ac6a5Smrg 58489c04b6cSmrg # Remove '-o $object'. 5851f0ac6a5Smrg IFS=" " 5861f0ac6a5Smrg for arg 5871f0ac6a5Smrg do 5881f0ac6a5Smrg case $arg in 5891f0ac6a5Smrg -o) 5901f0ac6a5Smrg shift 5911f0ac6a5Smrg ;; 5921f0ac6a5Smrg $object) 5931f0ac6a5Smrg shift 5941f0ac6a5Smrg ;; 5951f0ac6a5Smrg *) 5961f0ac6a5Smrg set fnord "$@" "$arg" 5971f0ac6a5Smrg shift # fnord 5981f0ac6a5Smrg shift # $arg 5991f0ac6a5Smrg ;; 6001f0ac6a5Smrg esac 6011f0ac6a5Smrg done 6021f0ac6a5Smrg 6031f0ac6a5Smrg test -z "$dashmflag" && dashmflag=-M 60489c04b6cSmrg # Require at least two characters before searching for ':' 6051f0ac6a5Smrg # in the target name. This is to cope with DOS-style filenames: 60689c04b6cSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6071f0ac6a5Smrg "$@" $dashmflag | 60889c04b6cSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6091f0ac6a5Smrg rm -f "$depfile" 6101f0ac6a5Smrg cat < "$tmpdepfile" > "$depfile" 61189c04b6cSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61289c04b6cSmrg # correctly. Breaking it into two sed invocations is a workaround. 61389c04b6cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 61489c04b6cSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61589c04b6cSmrg | sed -e 's/$/ :/' >> "$depfile" 6161f0ac6a5Smrg rm -f "$tmpdepfile" 6171f0ac6a5Smrg ;; 6181f0ac6a5Smrg 6191f0ac6a5SmrgdashXmstdout) 6201f0ac6a5Smrg # This case only exists to satisfy depend.m4. It is never actually 6211f0ac6a5Smrg # run, as this mode is specially recognized in the preamble. 6221f0ac6a5Smrg exit 1 6231f0ac6a5Smrg ;; 6241f0ac6a5Smrg 6251f0ac6a5Smrgmakedepend) 6261f0ac6a5Smrg "$@" || exit $? 6271f0ac6a5Smrg # Remove any Libtool call 6281f0ac6a5Smrg if test "$libtool" = yes; then 629e5410a46Smrg while test "X$1" != 'X--mode=compile'; do 6301f0ac6a5Smrg shift 6311f0ac6a5Smrg done 6321f0ac6a5Smrg shift 6331f0ac6a5Smrg fi 6341f0ac6a5Smrg # X makedepend 6351f0ac6a5Smrg shift 636e5410a46Smrg cleared=no eat=no 637e5410a46Smrg for arg 638e5410a46Smrg do 6391f0ac6a5Smrg case $cleared in 6401f0ac6a5Smrg no) 6411f0ac6a5Smrg set ""; shift 6421f0ac6a5Smrg cleared=yes ;; 6431f0ac6a5Smrg esac 644e5410a46Smrg if test $eat = yes; then 645e5410a46Smrg eat=no 646e5410a46Smrg continue 647e5410a46Smrg fi 6481f0ac6a5Smrg case "$arg" in 6491f0ac6a5Smrg -D*|-I*) 6501f0ac6a5Smrg set fnord "$@" "$arg"; shift ;; 6511f0ac6a5Smrg # Strip any option that makedepend may not understand. Remove 6521f0ac6a5Smrg # the object too, otherwise makedepend will parse it as a source file. 653e5410a46Smrg -arch) 654e5410a46Smrg eat=yes ;; 6551f0ac6a5Smrg -*|$object) 6561f0ac6a5Smrg ;; 6571f0ac6a5Smrg *) 6581f0ac6a5Smrg set fnord "$@" "$arg"; shift ;; 6591f0ac6a5Smrg esac 6601f0ac6a5Smrg done 661e5410a46Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6621f0ac6a5Smrg touch "$tmpdepfile" 6631f0ac6a5Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6641f0ac6a5Smrg rm -f "$depfile" 66589c04b6cSmrg # makedepend may prepend the VPATH from the source file name to the object. 66689c04b6cSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 66789c04b6cSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66889c04b6cSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66989c04b6cSmrg # correctly. Breaking it into two sed invocations is a workaround. 67089c04b6cSmrg sed '1,2d' "$tmpdepfile" \ 67189c04b6cSmrg | tr ' ' "$nl" \ 67289c04b6cSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67389c04b6cSmrg | sed -e 's/$/ :/' >> "$depfile" 6741f0ac6a5Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6751f0ac6a5Smrg ;; 6761f0ac6a5Smrg 6771f0ac6a5Smrgcpp) 6781f0ac6a5Smrg # Important note: in order to support this mode, a compiler *must* 6791f0ac6a5Smrg # always write the preprocessed file to stdout. 6801f0ac6a5Smrg "$@" || exit $? 6811f0ac6a5Smrg 6821f0ac6a5Smrg # Remove the call to Libtool. 6831f0ac6a5Smrg if test "$libtool" = yes; then 684e5410a46Smrg while test "X$1" != 'X--mode=compile'; do 6851f0ac6a5Smrg shift 6861f0ac6a5Smrg done 6871f0ac6a5Smrg shift 6881f0ac6a5Smrg fi 6891f0ac6a5Smrg 69089c04b6cSmrg # Remove '-o $object'. 6911f0ac6a5Smrg IFS=" " 6921f0ac6a5Smrg for arg 6931f0ac6a5Smrg do 6941f0ac6a5Smrg case $arg in 6951f0ac6a5Smrg -o) 6961f0ac6a5Smrg shift 6971f0ac6a5Smrg ;; 6981f0ac6a5Smrg $object) 6991f0ac6a5Smrg shift 7001f0ac6a5Smrg ;; 7011f0ac6a5Smrg *) 7021f0ac6a5Smrg set fnord "$@" "$arg" 7031f0ac6a5Smrg shift # fnord 7041f0ac6a5Smrg shift # $arg 7051f0ac6a5Smrg ;; 7061f0ac6a5Smrg esac 7071f0ac6a5Smrg done 7081f0ac6a5Smrg 70989c04b6cSmrg "$@" -E \ 71089c04b6cSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71189c04b6cSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71289c04b6cSmrg | sed '$ s: \\$::' > "$tmpdepfile" 7131f0ac6a5Smrg rm -f "$depfile" 7141f0ac6a5Smrg echo "$object : \\" > "$depfile" 7151f0ac6a5Smrg cat < "$tmpdepfile" >> "$depfile" 7161f0ac6a5Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7171f0ac6a5Smrg rm -f "$tmpdepfile" 7181f0ac6a5Smrg ;; 7191f0ac6a5Smrg 7201f0ac6a5Smrgmsvisualcpp) 7211f0ac6a5Smrg # Important note: in order to support this mode, a compiler *must* 722e5410a46Smrg # always write the preprocessed file to stdout. 7231f0ac6a5Smrg "$@" || exit $? 724e5410a46Smrg 725e5410a46Smrg # Remove the call to Libtool. 726e5410a46Smrg if test "$libtool" = yes; then 727e5410a46Smrg while test "X$1" != 'X--mode=compile'; do 728e5410a46Smrg shift 729e5410a46Smrg done 730e5410a46Smrg shift 731e5410a46Smrg fi 732e5410a46Smrg 7331f0ac6a5Smrg IFS=" " 7341f0ac6a5Smrg for arg 7351f0ac6a5Smrg do 7361f0ac6a5Smrg case "$arg" in 737e5410a46Smrg -o) 738e5410a46Smrg shift 739e5410a46Smrg ;; 740e5410a46Smrg $object) 741e5410a46Smrg shift 742e5410a46Smrg ;; 7431f0ac6a5Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74489c04b6cSmrg set fnord "$@" 74589c04b6cSmrg shift 74689c04b6cSmrg shift 74789c04b6cSmrg ;; 7481f0ac6a5Smrg *) 74989c04b6cSmrg set fnord "$@" "$arg" 75089c04b6cSmrg shift 75189c04b6cSmrg shift 75289c04b6cSmrg ;; 7531f0ac6a5Smrg esac 7541f0ac6a5Smrg done 755e5410a46Smrg "$@" -E 2>/dev/null | 756e5410a46Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7571f0ac6a5Smrg rm -f "$depfile" 7581f0ac6a5Smrg echo "$object : \\" > "$depfile" 75989c04b6cSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 76089c04b6cSmrg echo "$tab" >> "$depfile" 761e5410a46Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7621f0ac6a5Smrg rm -f "$tmpdepfile" 7631f0ac6a5Smrg ;; 7641f0ac6a5Smrg 765e5410a46Smrgmsvcmsys) 766e5410a46Smrg # This case exists only to let depend.m4 do its work. It works by 767e5410a46Smrg # looking at the text of this script. This case will never be run, 768e5410a46Smrg # since it is checked for above. 769e5410a46Smrg exit 1 770e5410a46Smrg ;; 771e5410a46Smrg 7721f0ac6a5Smrgnone) 7731f0ac6a5Smrg exec "$@" 7741f0ac6a5Smrg ;; 7751f0ac6a5Smrg 7761f0ac6a5Smrg*) 7771f0ac6a5Smrg echo "Unknown depmode $depmode" 1>&2 7781f0ac6a5Smrg exit 1 7791f0ac6a5Smrg ;; 7801f0ac6a5Smrgesac 7811f0ac6a5Smrg 7821f0ac6a5Smrgexit 0 7831f0ac6a5Smrg 7841f0ac6a5Smrg# Local Variables: 7851f0ac6a5Smrg# mode: shell-script 7861f0ac6a5Smrg# sh-indentation: 2 787d21ab8bcSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7881f0ac6a5Smrg# time-stamp-start: "scriptversion=" 7891f0ac6a5Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 790d21ab8bcSmrg# time-stamp-time-zone: "UTC0" 791e5410a46Smrg# time-stamp-end: "; # UTC" 7921f0ac6a5Smrg# End: 793