depcomp revision 89c04b6c
11f0ac6a5Smrg#! /bin/sh 21f0ac6a5Smrg# depcomp - compile a program generating dependencies as side-effects 31f0ac6a5Smrg 489c04b6cSmrgscriptversion=2012-10-18.11; # UTC 51f0ac6a5Smrg 689c04b6cSmrg# Copyright (C) 1999-2013 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 19e5410a46Smrg# along with this program. If not, see <http://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>. 501f0ac6a5SmrgEOF 511f0ac6a5Smrg exit $? 521f0ac6a5Smrg ;; 531f0ac6a5Smrg -v | --v*) 541f0ac6a5Smrg echo "depcomp $scriptversion" 551f0ac6a5Smrg exit $? 561f0ac6a5Smrg ;; 571f0ac6a5Smrgesac 581f0ac6a5Smrg 5989c04b6cSmrg# Get the directory component of the given path, and save it in the 6089c04b6cSmrg# global variables '$dir'. Note that this directory component will 6189c04b6cSmrg# be either empty or ending with a '/' character. This is deliberate. 6289c04b6cSmrgset_dir_from () 6389c04b6cSmrg{ 6489c04b6cSmrg case $1 in 6589c04b6cSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6689c04b6cSmrg *) dir=;; 6789c04b6cSmrg esac 6889c04b6cSmrg} 6989c04b6cSmrg 7089c04b6cSmrg# Get the suffix-stripped basename of the given path, and save it the 7189c04b6cSmrg# global variable '$base'. 7289c04b6cSmrgset_base_from () 7389c04b6cSmrg{ 7489c04b6cSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7589c04b6cSmrg} 7689c04b6cSmrg 7789c04b6cSmrg# If no dependency file was actually created by the compiler invocation, 7889c04b6cSmrg# we still have to create a dummy depfile, to avoid errors with the 7989c04b6cSmrg# Makefile "include basename.Plo" scheme. 8089c04b6cSmrgmake_dummy_depfile () 8189c04b6cSmrg{ 8289c04b6cSmrg echo "#dummy" > "$depfile" 8389c04b6cSmrg} 8489c04b6cSmrg 8589c04b6cSmrg# Factor out some common post-processing of the generated depfile. 8689c04b6cSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8789c04b6cSmrgaix_post_process_depfile () 8889c04b6cSmrg{ 8989c04b6cSmrg # If the compiler actually managed to produce a dependency file, 9089c04b6cSmrg # post-process it. 9189c04b6cSmrg if test -f "$tmpdepfile"; then 9289c04b6cSmrg # Each line is of the form 'foo.o: dependency.h'. 9389c04b6cSmrg # Do two passes, one to just change these to 9489c04b6cSmrg # $object: dependency.h 9589c04b6cSmrg # and one to simply output 9689c04b6cSmrg # dependency.h: 9789c04b6cSmrg # which is needed to avoid the deleted-header problem. 9889c04b6cSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9989c04b6cSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10089c04b6cSmrg } > "$depfile" 10189c04b6cSmrg rm -f "$tmpdepfile" 10289c04b6cSmrg else 10389c04b6cSmrg make_dummy_depfile 10489c04b6cSmrg fi 10589c04b6cSmrg} 10689c04b6cSmrg 10789c04b6cSmrg# A tabulation character. 10889c04b6cSmrgtab=' ' 10989c04b6cSmrg# A newline character. 11089c04b6cSmrgnl=' 11189c04b6cSmrg' 11289c04b6cSmrg# Character ranges might be problematic outside the C locale. 11389c04b6cSmrg# These definitions help. 11489c04b6cSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11589c04b6cSmrglower=abcdefghijklmnopqrstuvwxyz 11689c04b6cSmrgdigits=0123456789 11789c04b6cSmrgalpha=${upper}${lower} 11889c04b6cSmrg 1191f0ac6a5Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1201f0ac6a5Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1211f0ac6a5Smrg exit 1 1221f0ac6a5Smrgfi 1231f0ac6a5Smrg 1241f0ac6a5Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1251f0ac6a5Smrgdepfile=${depfile-`echo "$object" | 1261f0ac6a5Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1271f0ac6a5Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1281f0ac6a5Smrg 1291f0ac6a5Smrgrm -f "$tmpdepfile" 1301f0ac6a5Smrg 13189c04b6cSmrg# Avoid interferences from the environment. 13289c04b6cSmrggccflag= dashmflag= 13389c04b6cSmrg 1341f0ac6a5Smrg# Some modes work just like other modes, but use different flags. We 1351f0ac6a5Smrg# parameterize here, but still list the modes in the big case below, 1361f0ac6a5Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1371f0ac6a5Smrg# here, because this file can only contain one case statement. 1381f0ac6a5Smrgif test "$depmode" = hp; then 1391f0ac6a5Smrg # HP compiler uses -M and no extra arg. 1401f0ac6a5Smrg gccflag=-M 1411f0ac6a5Smrg depmode=gcc 1421f0ac6a5Smrgfi 1431f0ac6a5Smrg 1441f0ac6a5Smrgif test "$depmode" = dashXmstdout; then 14589c04b6cSmrg # This is just like dashmstdout with a different argument. 14689c04b6cSmrg dashmflag=-xM 14789c04b6cSmrg depmode=dashmstdout 1481f0ac6a5Smrgfi 1491f0ac6a5Smrg 150e5410a46Smrgcygpath_u="cygpath -u -f -" 151e5410a46Smrgif test "$depmode" = msvcmsys; then 15289c04b6cSmrg # This is just like msvisualcpp but w/o cygpath translation. 15389c04b6cSmrg # Just convert the backslash-escaped backslashes to single forward 15489c04b6cSmrg # slashes to satisfy depend.m4 15589c04b6cSmrg cygpath_u='sed s,\\\\,/,g' 15689c04b6cSmrg depmode=msvisualcpp 15789c04b6cSmrgfi 15889c04b6cSmrg 15989c04b6cSmrgif test "$depmode" = msvc7msys; then 16089c04b6cSmrg # This is just like msvc7 but w/o cygpath translation. 16189c04b6cSmrg # Just convert the backslash-escaped backslashes to single forward 16289c04b6cSmrg # slashes to satisfy depend.m4 16389c04b6cSmrg cygpath_u='sed s,\\\\,/,g' 16489c04b6cSmrg depmode=msvc7 16589c04b6cSmrgfi 16689c04b6cSmrg 16789c04b6cSmrgif test "$depmode" = xlc; then 16889c04b6cSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16989c04b6cSmrg gccflag=-qmakedep=gcc,-MF 17089c04b6cSmrg depmode=gcc 171e5410a46Smrgfi 172e5410a46Smrg 1731f0ac6a5Smrgcase "$depmode" in 1741f0ac6a5Smrggcc3) 1751f0ac6a5Smrg## gcc 3 implements dependency tracking that does exactly what 1761f0ac6a5Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1771f0ac6a5Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1781f0ac6a5Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1791f0ac6a5Smrg## the command line argument order; so add the flags where they 1801f0ac6a5Smrg## appear in depend2.am. Note that the slowdown incurred here 1811f0ac6a5Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1821f0ac6a5Smrg for arg 1831f0ac6a5Smrg do 1841f0ac6a5Smrg case $arg in 1851f0ac6a5Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1861f0ac6a5Smrg *) set fnord "$@" "$arg" ;; 1871f0ac6a5Smrg esac 1881f0ac6a5Smrg shift # fnord 1891f0ac6a5Smrg shift # $arg 1901f0ac6a5Smrg done 1911f0ac6a5Smrg "$@" 1921f0ac6a5Smrg stat=$? 19389c04b6cSmrg if test $stat -ne 0; then 1941f0ac6a5Smrg rm -f "$tmpdepfile" 1951f0ac6a5Smrg exit $stat 1961f0ac6a5Smrg fi 1971f0ac6a5Smrg mv "$tmpdepfile" "$depfile" 1981f0ac6a5Smrg ;; 1991f0ac6a5Smrg 2001f0ac6a5Smrggcc) 20189c04b6cSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20289c04b6cSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20389c04b6cSmrg## (see the conditional assignment to $gccflag above). 2041f0ac6a5Smrg## There are various ways to get dependency output from gcc. Here's 2051f0ac6a5Smrg## why we pick this rather obscure method: 2061f0ac6a5Smrg## - Don't want to use -MD because we'd like the dependencies to end 2071f0ac6a5Smrg## up in a subdir. Having to rename by hand is ugly. 2081f0ac6a5Smrg## (We might end up doing this anyway to support other compilers.) 2091f0ac6a5Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21089c04b6cSmrg## -MM, not -M (despite what the docs say). Also, it might not be 21189c04b6cSmrg## supported by the other compilers which use the 'gcc' depmode. 2121f0ac6a5Smrg## - Using -M directly means running the compiler twice (even worse 2131f0ac6a5Smrg## than renaming). 2141f0ac6a5Smrg if test -z "$gccflag"; then 2151f0ac6a5Smrg gccflag=-MD, 2161f0ac6a5Smrg fi 2171f0ac6a5Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2181f0ac6a5Smrg stat=$? 21989c04b6cSmrg if test $stat -ne 0; then 2201f0ac6a5Smrg rm -f "$tmpdepfile" 2211f0ac6a5Smrg exit $stat 2221f0ac6a5Smrg fi 2231f0ac6a5Smrg rm -f "$depfile" 2241f0ac6a5Smrg echo "$object : \\" > "$depfile" 22589c04b6cSmrg # The second -e expression handles DOS-style file names with drive 22689c04b6cSmrg # letters. 2271f0ac6a5Smrg sed -e 's/^[^:]*: / /' \ 2281f0ac6a5Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22989c04b6cSmrg## This next piece of magic avoids the "deleted header file" problem. 2301f0ac6a5Smrg## The problem is that when a header file which appears in a .P file 2311f0ac6a5Smrg## is deleted, the dependency causes make to die (because there is 2321f0ac6a5Smrg## typically no way to rebuild the header). We avoid this by adding 2331f0ac6a5Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2341f0ac6a5Smrg## this for us directly. 23589c04b6cSmrg## Some versions of gcc put a space before the ':'. On the theory 2361f0ac6a5Smrg## that the space means something, we add a space to the output as 23789c04b6cSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 23889c04b6cSmrg## to the object. Take care to not repeat it in the output. 2391f0ac6a5Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2401f0ac6a5Smrg## correctly. Breaking it into two sed invocations is a workaround. 24189c04b6cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 24289c04b6cSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24389c04b6cSmrg | sed -e 's/$/ :/' >> "$depfile" 2441f0ac6a5Smrg rm -f "$tmpdepfile" 2451f0ac6a5Smrg ;; 2461f0ac6a5Smrg 2471f0ac6a5Smrghp) 2481f0ac6a5Smrg # This case exists only to let depend.m4 do its work. It works by 2491f0ac6a5Smrg # looking at the text of this script. This case will never be run, 2501f0ac6a5Smrg # since it is checked for above. 2511f0ac6a5Smrg exit 1 2521f0ac6a5Smrg ;; 2531f0ac6a5Smrg 2541f0ac6a5Smrgsgi) 2551f0ac6a5Smrg if test "$libtool" = yes; then 2561f0ac6a5Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2571f0ac6a5Smrg else 2581f0ac6a5Smrg "$@" -MDupdate "$tmpdepfile" 2591f0ac6a5Smrg fi 2601f0ac6a5Smrg stat=$? 26189c04b6cSmrg if test $stat -ne 0; then 2621f0ac6a5Smrg rm -f "$tmpdepfile" 2631f0ac6a5Smrg exit $stat 2641f0ac6a5Smrg fi 2651f0ac6a5Smrg rm -f "$depfile" 2661f0ac6a5Smrg 2671f0ac6a5Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2681f0ac6a5Smrg echo "$object : \\" > "$depfile" 2691f0ac6a5Smrg # Clip off the initial element (the dependent). Don't try to be 2701f0ac6a5Smrg # clever and replace this with sed code, as IRIX sed won't handle 2711f0ac6a5Smrg # lines with more than a fixed number of characters (4096 in 2721f0ac6a5Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27389c04b6cSmrg # the IRIX cc adds comments like '#:fec' to the end of the 2741f0ac6a5Smrg # dependency line. 27589c04b6cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 27689c04b6cSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27789c04b6cSmrg | tr "$nl" ' ' >> "$depfile" 278e5410a46Smrg echo >> "$depfile" 2791f0ac6a5Smrg # The second pass generates a dummy entry for each header file. 28089c04b6cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 28189c04b6cSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28289c04b6cSmrg >> "$depfile" 2831f0ac6a5Smrg else 28489c04b6cSmrg make_dummy_depfile 2851f0ac6a5Smrg fi 2861f0ac6a5Smrg rm -f "$tmpdepfile" 2871f0ac6a5Smrg ;; 2881f0ac6a5Smrg 28989c04b6cSmrgxlc) 29089c04b6cSmrg # This case exists only to let depend.m4 do its work. It works by 29189c04b6cSmrg # looking at the text of this script. This case will never be run, 29289c04b6cSmrg # since it is checked for above. 29389c04b6cSmrg exit 1 29489c04b6cSmrg ;; 29589c04b6cSmrg 2961f0ac6a5Smrgaix) 2971f0ac6a5Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2981f0ac6a5Smrg # in a .u file. In older versions, this file always lives in the 29989c04b6cSmrg # current directory. Also, the AIX compiler puts '$object:' at the 3001f0ac6a5Smrg # start of each line; $object doesn't have directory information. 3011f0ac6a5Smrg # Version 6 uses the directory in both cases. 30289c04b6cSmrg set_dir_from "$object" 30389c04b6cSmrg set_base_from "$object" 3041f0ac6a5Smrg if test "$libtool" = yes; then 305e5410a46Smrg tmpdepfile1=$dir$base.u 306e5410a46Smrg tmpdepfile2=$base.u 307e5410a46Smrg tmpdepfile3=$dir.libs/$base.u 3081f0ac6a5Smrg "$@" -Wc,-M 3091f0ac6a5Smrg else 310e5410a46Smrg tmpdepfile1=$dir$base.u 311e5410a46Smrg tmpdepfile2=$dir$base.u 312e5410a46Smrg tmpdepfile3=$dir$base.u 3131f0ac6a5Smrg "$@" -M 3141f0ac6a5Smrg fi 3151f0ac6a5Smrg stat=$? 31689c04b6cSmrg if test $stat -ne 0; then 317e5410a46Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3181f0ac6a5Smrg exit $stat 3191f0ac6a5Smrg fi 3201f0ac6a5Smrg 321e5410a46Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322e5410a46Smrg do 323e5410a46Smrg test -f "$tmpdepfile" && break 324e5410a46Smrg done 32589c04b6cSmrg aix_post_process_depfile 32689c04b6cSmrg ;; 32789c04b6cSmrg 32889c04b6cSmrgtcc) 32989c04b6cSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33089c04b6cSmrg # FIXME: That version still under development at the moment of writing. 33189c04b6cSmrg # Make that this statement remains true also for stable, released 33289c04b6cSmrg # versions. 33389c04b6cSmrg # It will wrap lines (doesn't matter whether long or short) with a 33489c04b6cSmrg # trailing '\', as in: 33589c04b6cSmrg # 33689c04b6cSmrg # foo.o : \ 33789c04b6cSmrg # foo.c \ 33889c04b6cSmrg # foo.h \ 33989c04b6cSmrg # 34089c04b6cSmrg # It will put a trailing '\' even on the last line, and will use leading 34189c04b6cSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 34289c04b6cSmrg # "Emit spaces for -MD"). 34389c04b6cSmrg "$@" -MD -MF "$tmpdepfile" 34489c04b6cSmrg stat=$? 34589c04b6cSmrg if test $stat -ne 0; then 34689c04b6cSmrg rm -f "$tmpdepfile" 34789c04b6cSmrg exit $stat 3481f0ac6a5Smrg fi 34989c04b6cSmrg rm -f "$depfile" 35089c04b6cSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35189c04b6cSmrg # We have to change lines of the first kind to '$object: \'. 35289c04b6cSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35389c04b6cSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 35489c04b6cSmrg # dummy dependency, to avoid the deleted-header problem. 35589c04b6cSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3561f0ac6a5Smrg rm -f "$tmpdepfile" 3571f0ac6a5Smrg ;; 3581f0ac6a5Smrg 35989c04b6cSmrg## The order of this option in the case statement is important, since the 36089c04b6cSmrg## shell code in configure will try each of these formats in the order 36189c04b6cSmrg## listed in this file. A plain '-MD' option would be understood by many 36289c04b6cSmrg## compilers, so we must ensure this comes after the gcc and icc options. 36389c04b6cSmrgpgcc) 36489c04b6cSmrg # Portland's C compiler understands '-MD'. 36589c04b6cSmrg # Will always output deps to 'file.d' where file is the root name of the 36689c04b6cSmrg # source file under compilation, even if file resides in a subdirectory. 36789c04b6cSmrg # The object file name does not affect the name of the '.d' file. 36889c04b6cSmrg # pgcc 10.2 will output 3691f0ac6a5Smrg # foo.o: sub/foo.c sub/foo.h 37089c04b6cSmrg # and will wrap long lines using '\' : 3711f0ac6a5Smrg # foo.o: sub/foo.c ... \ 3721f0ac6a5Smrg # sub/foo.h ... \ 3731f0ac6a5Smrg # ... 37489c04b6cSmrg set_dir_from "$object" 37589c04b6cSmrg # Use the source, not the object, to determine the base name, since 37689c04b6cSmrg # that's sadly what pgcc will do too. 37789c04b6cSmrg set_base_from "$source" 37889c04b6cSmrg tmpdepfile=$base.d 37989c04b6cSmrg 38089c04b6cSmrg # For projects that build the same source file twice into different object 38189c04b6cSmrg # files, the pgcc approach of using the *source* file root name can cause 38289c04b6cSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38389c04b6cSmrg # the same $tmpdepfile. 38489c04b6cSmrg lockdir=$base.d-lock 38589c04b6cSmrg trap " 38689c04b6cSmrg echo '$0: caught signal, cleaning up...' >&2 38789c04b6cSmrg rmdir '$lockdir' 38889c04b6cSmrg exit 1 38989c04b6cSmrg " 1 2 13 15 39089c04b6cSmrg numtries=100 39189c04b6cSmrg i=$numtries 39289c04b6cSmrg while test $i -gt 0; do 39389c04b6cSmrg # mkdir is a portable test-and-set. 39489c04b6cSmrg if mkdir "$lockdir" 2>/dev/null; then 39589c04b6cSmrg # This process acquired the lock. 39689c04b6cSmrg "$@" -MD 39789c04b6cSmrg stat=$? 39889c04b6cSmrg # Release the lock. 39989c04b6cSmrg rmdir "$lockdir" 40089c04b6cSmrg break 40189c04b6cSmrg else 40289c04b6cSmrg # If the lock is being held by a different process, wait 40389c04b6cSmrg # until the winning process is done or we timeout. 40489c04b6cSmrg while test -d "$lockdir" && test $i -gt 0; do 40589c04b6cSmrg sleep 1 40689c04b6cSmrg i=`expr $i - 1` 40789c04b6cSmrg done 40889c04b6cSmrg fi 40989c04b6cSmrg i=`expr $i - 1` 41089c04b6cSmrg done 41189c04b6cSmrg trap - 1 2 13 15 41289c04b6cSmrg if test $i -le 0; then 41389c04b6cSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41489c04b6cSmrg echo "$0: check lockdir '$lockdir'" >&2 41589c04b6cSmrg exit 1 41689c04b6cSmrg fi 4171f0ac6a5Smrg 41889c04b6cSmrg if test $stat -ne 0; then 4191f0ac6a5Smrg rm -f "$tmpdepfile" 4201f0ac6a5Smrg exit $stat 4211f0ac6a5Smrg fi 4221f0ac6a5Smrg rm -f "$depfile" 4231f0ac6a5Smrg # Each line is of the form `foo.o: dependent.h', 4241f0ac6a5Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4251f0ac6a5Smrg # Do two passes, one to just change these to 4261f0ac6a5Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4271f0ac6a5Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4281f0ac6a5Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4291f0ac6a5Smrg # correctly. Breaking it into two sed invocations is a workaround. 43089c04b6cSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43189c04b6cSmrg | sed -e 's/$/ :/' >> "$depfile" 4321f0ac6a5Smrg rm -f "$tmpdepfile" 4331f0ac6a5Smrg ;; 4341f0ac6a5Smrg 4351f0ac6a5Smrghp2) 4361f0ac6a5Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4371f0ac6a5Smrg # compilers, which have integrated preprocessors. The correct option 4381f0ac6a5Smrg # to use with these is +Maked; it writes dependencies to a file named 4391f0ac6a5Smrg # 'foo.d', which lands next to the object file, wherever that 4401f0ac6a5Smrg # happens to be. 4411f0ac6a5Smrg # Much of this is similar to the tru64 case; see comments there. 44289c04b6cSmrg set_dir_from "$object" 44389c04b6cSmrg set_base_from "$object" 4441f0ac6a5Smrg if test "$libtool" = yes; then 4451f0ac6a5Smrg tmpdepfile1=$dir$base.d 4461f0ac6a5Smrg tmpdepfile2=$dir.libs/$base.d 4471f0ac6a5Smrg "$@" -Wc,+Maked 4481f0ac6a5Smrg else 4491f0ac6a5Smrg tmpdepfile1=$dir$base.d 4501f0ac6a5Smrg tmpdepfile2=$dir$base.d 4511f0ac6a5Smrg "$@" +Maked 4521f0ac6a5Smrg fi 4531f0ac6a5Smrg stat=$? 45489c04b6cSmrg if test $stat -ne 0; then 4551f0ac6a5Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4561f0ac6a5Smrg exit $stat 4571f0ac6a5Smrg fi 4581f0ac6a5Smrg 4591f0ac6a5Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4601f0ac6a5Smrg do 4611f0ac6a5Smrg test -f "$tmpdepfile" && break 4621f0ac6a5Smrg done 4631f0ac6a5Smrg if test -f "$tmpdepfile"; then 46489c04b6cSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46589c04b6cSmrg # Add 'dependent.h:' lines. 466e5410a46Smrg sed -ne '2,${ 46789c04b6cSmrg s/^ *// 46889c04b6cSmrg s/ \\*$// 46989c04b6cSmrg s/$/:/ 47089c04b6cSmrg p 47189c04b6cSmrg }' "$tmpdepfile" >> "$depfile" 4721f0ac6a5Smrg else 47389c04b6cSmrg make_dummy_depfile 4741f0ac6a5Smrg fi 4751f0ac6a5Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4761f0ac6a5Smrg ;; 4771f0ac6a5Smrg 4781f0ac6a5Smrgtru64) 47989c04b6cSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 48089c04b6cSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48189c04b6cSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48289c04b6cSmrg # dependencies in 'foo.d' instead, so we check for that too. 48389c04b6cSmrg # Subdirectories are respected. 48489c04b6cSmrg set_dir_from "$object" 48589c04b6cSmrg set_base_from "$object" 48689c04b6cSmrg 48789c04b6cSmrg if test "$libtool" = yes; then 48889c04b6cSmrg # Libtool generates 2 separate objects for the 2 libraries. These 48989c04b6cSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 49089c04b6cSmrg # in $dir$base.o.d. We have to check for both files, because 49189c04b6cSmrg # one of the two compilations can be disabled. We should prefer 49289c04b6cSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49389c04b6cSmrg # automatically cleaned when .libs/ is deleted, while ignoring 49489c04b6cSmrg # the former would cause a distcleancheck panic. 49589c04b6cSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49689c04b6cSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49789c04b6cSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49889c04b6cSmrg "$@" -Wc,-MD 49989c04b6cSmrg else 50089c04b6cSmrg tmpdepfile1=$dir$base.d 50189c04b6cSmrg tmpdepfile2=$dir$base.d 50289c04b6cSmrg tmpdepfile3=$dir$base.d 50389c04b6cSmrg "$@" -MD 50489c04b6cSmrg fi 50589c04b6cSmrg 50689c04b6cSmrg stat=$? 50789c04b6cSmrg if test $stat -ne 0; then 50889c04b6cSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50989c04b6cSmrg exit $stat 51089c04b6cSmrg fi 51189c04b6cSmrg 51289c04b6cSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51389c04b6cSmrg do 51489c04b6cSmrg test -f "$tmpdepfile" && break 51589c04b6cSmrg done 51689c04b6cSmrg # Same post-processing that is required for AIX mode. 51789c04b6cSmrg aix_post_process_depfile 51889c04b6cSmrg ;; 51989c04b6cSmrg 52089c04b6cSmrgmsvc7) 52189c04b6cSmrg if test "$libtool" = yes; then 52289c04b6cSmrg showIncludes=-Wc,-showIncludes 52389c04b6cSmrg else 52489c04b6cSmrg showIncludes=-showIncludes 52589c04b6cSmrg fi 52689c04b6cSmrg "$@" $showIncludes > "$tmpdepfile" 52789c04b6cSmrg stat=$? 52889c04b6cSmrg grep -v '^Note: including file: ' "$tmpdepfile" 52989c04b6cSmrg if test $stat -ne 0; then 53089c04b6cSmrg rm -f "$tmpdepfile" 53189c04b6cSmrg exit $stat 53289c04b6cSmrg fi 53389c04b6cSmrg rm -f "$depfile" 53489c04b6cSmrg echo "$object : \\" > "$depfile" 53589c04b6cSmrg # The first sed program below extracts the file names and escapes 53689c04b6cSmrg # backslashes for cygpath. The second sed program outputs the file 53789c04b6cSmrg # name when reading, but also accumulates all include files in the 53889c04b6cSmrg # hold buffer in order to output them again at the end. This only 53989c04b6cSmrg # works with sed implementations that can handle large buffers. 54089c04b6cSmrg sed < "$tmpdepfile" -n ' 54189c04b6cSmrg/^Note: including file: *\(.*\)/ { 54289c04b6cSmrg s//\1/ 54389c04b6cSmrg s/\\/\\\\/g 54489c04b6cSmrg p 54589c04b6cSmrg}' | $cygpath_u | sort -u | sed -n ' 54689c04b6cSmrgs/ /\\ /g 54789c04b6cSmrgs/\(.*\)/'"$tab"'\1 \\/p 54889c04b6cSmrgs/.\(.*\) \\/\1:/ 54989c04b6cSmrgH 55089c04b6cSmrg$ { 55189c04b6cSmrg s/.*/'"$tab"'/ 55289c04b6cSmrg G 55389c04b6cSmrg p 55489c04b6cSmrg}' >> "$depfile" 55589c04b6cSmrg rm -f "$tmpdepfile" 55689c04b6cSmrg ;; 55789c04b6cSmrg 55889c04b6cSmrgmsvc7msys) 55989c04b6cSmrg # This case exists only to let depend.m4 do its work. It works by 56089c04b6cSmrg # looking at the text of this script. This case will never be run, 56189c04b6cSmrg # since it is checked for above. 56289c04b6cSmrg exit 1 56389c04b6cSmrg ;; 5641f0ac6a5Smrg 5651f0ac6a5Smrg#nosideeffect) 5661f0ac6a5Smrg # This comment above is used by automake to tell side-effect 5671f0ac6a5Smrg # dependency tracking mechanisms from slower ones. 5681f0ac6a5Smrg 5691f0ac6a5Smrgdashmstdout) 5701f0ac6a5Smrg # Important note: in order to support this mode, a compiler *must* 5711f0ac6a5Smrg # always write the preprocessed file to stdout, regardless of -o. 5721f0ac6a5Smrg "$@" || exit $? 5731f0ac6a5Smrg 5741f0ac6a5Smrg # Remove the call to Libtool. 5751f0ac6a5Smrg if test "$libtool" = yes; then 576e5410a46Smrg while test "X$1" != 'X--mode=compile'; do 5771f0ac6a5Smrg shift 5781f0ac6a5Smrg done 5791f0ac6a5Smrg shift 5801f0ac6a5Smrg fi 5811f0ac6a5Smrg 58289c04b6cSmrg # Remove '-o $object'. 5831f0ac6a5Smrg IFS=" " 5841f0ac6a5Smrg for arg 5851f0ac6a5Smrg do 5861f0ac6a5Smrg case $arg in 5871f0ac6a5Smrg -o) 5881f0ac6a5Smrg shift 5891f0ac6a5Smrg ;; 5901f0ac6a5Smrg $object) 5911f0ac6a5Smrg shift 5921f0ac6a5Smrg ;; 5931f0ac6a5Smrg *) 5941f0ac6a5Smrg set fnord "$@" "$arg" 5951f0ac6a5Smrg shift # fnord 5961f0ac6a5Smrg shift # $arg 5971f0ac6a5Smrg ;; 5981f0ac6a5Smrg esac 5991f0ac6a5Smrg done 6001f0ac6a5Smrg 6011f0ac6a5Smrg test -z "$dashmflag" && dashmflag=-M 60289c04b6cSmrg # Require at least two characters before searching for ':' 6031f0ac6a5Smrg # in the target name. This is to cope with DOS-style filenames: 60489c04b6cSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6051f0ac6a5Smrg "$@" $dashmflag | 60689c04b6cSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6071f0ac6a5Smrg rm -f "$depfile" 6081f0ac6a5Smrg cat < "$tmpdepfile" > "$depfile" 60989c04b6cSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61089c04b6cSmrg # correctly. Breaking it into two sed invocations is a workaround. 61189c04b6cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 61289c04b6cSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61389c04b6cSmrg | sed -e 's/$/ :/' >> "$depfile" 6141f0ac6a5Smrg rm -f "$tmpdepfile" 6151f0ac6a5Smrg ;; 6161f0ac6a5Smrg 6171f0ac6a5SmrgdashXmstdout) 6181f0ac6a5Smrg # This case only exists to satisfy depend.m4. It is never actually 6191f0ac6a5Smrg # run, as this mode is specially recognized in the preamble. 6201f0ac6a5Smrg exit 1 6211f0ac6a5Smrg ;; 6221f0ac6a5Smrg 6231f0ac6a5Smrgmakedepend) 6241f0ac6a5Smrg "$@" || exit $? 6251f0ac6a5Smrg # Remove any Libtool call 6261f0ac6a5Smrg if test "$libtool" = yes; then 627e5410a46Smrg while test "X$1" != 'X--mode=compile'; do 6281f0ac6a5Smrg shift 6291f0ac6a5Smrg done 6301f0ac6a5Smrg shift 6311f0ac6a5Smrg fi 6321f0ac6a5Smrg # X makedepend 6331f0ac6a5Smrg shift 634e5410a46Smrg cleared=no eat=no 635e5410a46Smrg for arg 636e5410a46Smrg do 6371f0ac6a5Smrg case $cleared in 6381f0ac6a5Smrg no) 6391f0ac6a5Smrg set ""; shift 6401f0ac6a5Smrg cleared=yes ;; 6411f0ac6a5Smrg esac 642e5410a46Smrg if test $eat = yes; then 643e5410a46Smrg eat=no 644e5410a46Smrg continue 645e5410a46Smrg fi 6461f0ac6a5Smrg case "$arg" in 6471f0ac6a5Smrg -D*|-I*) 6481f0ac6a5Smrg set fnord "$@" "$arg"; shift ;; 6491f0ac6a5Smrg # Strip any option that makedepend may not understand. Remove 6501f0ac6a5Smrg # the object too, otherwise makedepend will parse it as a source file. 651e5410a46Smrg -arch) 652e5410a46Smrg eat=yes ;; 6531f0ac6a5Smrg -*|$object) 6541f0ac6a5Smrg ;; 6551f0ac6a5Smrg *) 6561f0ac6a5Smrg set fnord "$@" "$arg"; shift ;; 6571f0ac6a5Smrg esac 6581f0ac6a5Smrg done 659e5410a46Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6601f0ac6a5Smrg touch "$tmpdepfile" 6611f0ac6a5Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6621f0ac6a5Smrg rm -f "$depfile" 66389c04b6cSmrg # makedepend may prepend the VPATH from the source file name to the object. 66489c04b6cSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 66589c04b6cSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66689c04b6cSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66789c04b6cSmrg # correctly. Breaking it into two sed invocations is a workaround. 66889c04b6cSmrg sed '1,2d' "$tmpdepfile" \ 66989c04b6cSmrg | tr ' ' "$nl" \ 67089c04b6cSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67189c04b6cSmrg | sed -e 's/$/ :/' >> "$depfile" 6721f0ac6a5Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6731f0ac6a5Smrg ;; 6741f0ac6a5Smrg 6751f0ac6a5Smrgcpp) 6761f0ac6a5Smrg # Important note: in order to support this mode, a compiler *must* 6771f0ac6a5Smrg # always write the preprocessed file to stdout. 6781f0ac6a5Smrg "$@" || exit $? 6791f0ac6a5Smrg 6801f0ac6a5Smrg # Remove the call to Libtool. 6811f0ac6a5Smrg if test "$libtool" = yes; then 682e5410a46Smrg while test "X$1" != 'X--mode=compile'; do 6831f0ac6a5Smrg shift 6841f0ac6a5Smrg done 6851f0ac6a5Smrg shift 6861f0ac6a5Smrg fi 6871f0ac6a5Smrg 68889c04b6cSmrg # Remove '-o $object'. 6891f0ac6a5Smrg IFS=" " 6901f0ac6a5Smrg for arg 6911f0ac6a5Smrg do 6921f0ac6a5Smrg case $arg in 6931f0ac6a5Smrg -o) 6941f0ac6a5Smrg shift 6951f0ac6a5Smrg ;; 6961f0ac6a5Smrg $object) 6971f0ac6a5Smrg shift 6981f0ac6a5Smrg ;; 6991f0ac6a5Smrg *) 7001f0ac6a5Smrg set fnord "$@" "$arg" 7011f0ac6a5Smrg shift # fnord 7021f0ac6a5Smrg shift # $arg 7031f0ac6a5Smrg ;; 7041f0ac6a5Smrg esac 7051f0ac6a5Smrg done 7061f0ac6a5Smrg 70789c04b6cSmrg "$@" -E \ 70889c04b6cSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 70989c04b6cSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71089c04b6cSmrg | sed '$ s: \\$::' > "$tmpdepfile" 7111f0ac6a5Smrg rm -f "$depfile" 7121f0ac6a5Smrg echo "$object : \\" > "$depfile" 7131f0ac6a5Smrg cat < "$tmpdepfile" >> "$depfile" 7141f0ac6a5Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7151f0ac6a5Smrg rm -f "$tmpdepfile" 7161f0ac6a5Smrg ;; 7171f0ac6a5Smrg 7181f0ac6a5Smrgmsvisualcpp) 7191f0ac6a5Smrg # Important note: in order to support this mode, a compiler *must* 720e5410a46Smrg # always write the preprocessed file to stdout. 7211f0ac6a5Smrg "$@" || exit $? 722e5410a46Smrg 723e5410a46Smrg # Remove the call to Libtool. 724e5410a46Smrg if test "$libtool" = yes; then 725e5410a46Smrg while test "X$1" != 'X--mode=compile'; do 726e5410a46Smrg shift 727e5410a46Smrg done 728e5410a46Smrg shift 729e5410a46Smrg fi 730e5410a46Smrg 7311f0ac6a5Smrg IFS=" " 7321f0ac6a5Smrg for arg 7331f0ac6a5Smrg do 7341f0ac6a5Smrg case "$arg" in 735e5410a46Smrg -o) 736e5410a46Smrg shift 737e5410a46Smrg ;; 738e5410a46Smrg $object) 739e5410a46Smrg shift 740e5410a46Smrg ;; 7411f0ac6a5Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74289c04b6cSmrg set fnord "$@" 74389c04b6cSmrg shift 74489c04b6cSmrg shift 74589c04b6cSmrg ;; 7461f0ac6a5Smrg *) 74789c04b6cSmrg set fnord "$@" "$arg" 74889c04b6cSmrg shift 74989c04b6cSmrg shift 75089c04b6cSmrg ;; 7511f0ac6a5Smrg esac 7521f0ac6a5Smrg done 753e5410a46Smrg "$@" -E 2>/dev/null | 754e5410a46Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7551f0ac6a5Smrg rm -f "$depfile" 7561f0ac6a5Smrg echo "$object : \\" > "$depfile" 75789c04b6cSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75889c04b6cSmrg echo "$tab" >> "$depfile" 759e5410a46Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7601f0ac6a5Smrg rm -f "$tmpdepfile" 7611f0ac6a5Smrg ;; 7621f0ac6a5Smrg 763e5410a46Smrgmsvcmsys) 764e5410a46Smrg # This case exists only to let depend.m4 do its work. It works by 765e5410a46Smrg # looking at the text of this script. This case will never be run, 766e5410a46Smrg # since it is checked for above. 767e5410a46Smrg exit 1 768e5410a46Smrg ;; 769e5410a46Smrg 7701f0ac6a5Smrgnone) 7711f0ac6a5Smrg exec "$@" 7721f0ac6a5Smrg ;; 7731f0ac6a5Smrg 7741f0ac6a5Smrg*) 7751f0ac6a5Smrg echo "Unknown depmode $depmode" 1>&2 7761f0ac6a5Smrg exit 1 7771f0ac6a5Smrg ;; 7781f0ac6a5Smrgesac 7791f0ac6a5Smrg 7801f0ac6a5Smrgexit 0 7811f0ac6a5Smrg 7821f0ac6a5Smrg# Local Variables: 7831f0ac6a5Smrg# mode: shell-script 7841f0ac6a5Smrg# sh-indentation: 2 7851f0ac6a5Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 7861f0ac6a5Smrg# time-stamp-start: "scriptversion=" 7871f0ac6a5Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 788e5410a46Smrg# time-stamp-time-zone: "UTC" 789e5410a46Smrg# time-stamp-end: "; # UTC" 7901f0ac6a5Smrg# End: 791