depcomp revision 2a75d1c4
1f7ec340bSmacallan#! /bin/sh 2f7ec340bSmacallan# depcomp - compile a program generating dependencies as side-effects 3f7ec340bSmacallan 42a75d1c4Smrgscriptversion=2012-07-12.20; # UTC 5f7ec340bSmacallan 62a75d1c4Smrg# Copyright (C) 1999-2012 Free Software Foundation, Inc. 7f7ec340bSmacallan 8f7ec340bSmacallan# This program is free software; you can redistribute it and/or modify 9f7ec340bSmacallan# it under the terms of the GNU General Public License as published by 10f7ec340bSmacallan# the Free Software Foundation; either version 2, or (at your option) 11f7ec340bSmacallan# any later version. 12f7ec340bSmacallan 13f7ec340bSmacallan# This program is distributed in the hope that it will be useful, 14f7ec340bSmacallan# but WITHOUT ANY WARRANTY; without even the implied warranty of 15f7ec340bSmacallan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16f7ec340bSmacallan# GNU General Public License for more details. 17f7ec340bSmacallan 18f7ec340bSmacallan# You should have received a copy of the GNU General Public License 192a75d1c4Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20f7ec340bSmacallan 21f7ec340bSmacallan# As a special exception to the GNU General Public License, if you 22f7ec340bSmacallan# distribute this file as part of a program that contains a 23f7ec340bSmacallan# configuration script generated by Autoconf, you may include it under 24f7ec340bSmacallan# the same distribution terms that you use for the rest of that program. 25f7ec340bSmacallan 26f7ec340bSmacallan# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27f7ec340bSmacallan 28f7ec340bSmacallancase $1 in 29f7ec340bSmacallan '') 302a75d1c4Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31f7ec340bSmacallan exit 1; 32f7ec340bSmacallan ;; 33f7ec340bSmacallan -h | --h*) 34f7ec340bSmacallan cat <<\EOF 35f7ec340bSmacallanUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36f7ec340bSmacallan 37f7ec340bSmacallanRun PROGRAMS ARGS to compile a file, generating dependencies 38f7ec340bSmacallanas side-effects. 39f7ec340bSmacallan 40f7ec340bSmacallanEnvironment variables: 41f7ec340bSmacallan depmode Dependency tracking mode. 422a75d1c4Smrg source Source file read by 'PROGRAMS ARGS'. 432a75d1c4Smrg object Object file output by 'PROGRAMS ARGS'. 44f7ec340bSmacallan DEPDIR directory where to store dependencies. 45f7ec340bSmacallan depfile Dependency file to output. 462a75d1c4Smrg tmpdepfile Temporary file to use when outputting dependencies. 47f7ec340bSmacallan libtool Whether libtool is used (yes/no). 48f7ec340bSmacallan 49f7ec340bSmacallanReport bugs to <bug-automake@gnu.org>. 50f7ec340bSmacallanEOF 51f7ec340bSmacallan exit $? 52f7ec340bSmacallan ;; 53f7ec340bSmacallan -v | --v*) 54f7ec340bSmacallan echo "depcomp $scriptversion" 55f7ec340bSmacallan exit $? 56f7ec340bSmacallan ;; 57f7ec340bSmacallanesac 58f7ec340bSmacallan 592a75d1c4Smrg# A tabulation character. 602a75d1c4Smrgtab=' ' 612a75d1c4Smrg# A newline character. 622a75d1c4Smrgnl=' 632a75d1c4Smrg' 642a75d1c4Smrg 65f7ec340bSmacallanif test -z "$depmode" || test -z "$source" || test -z "$object"; then 66f7ec340bSmacallan echo "depcomp: Variables source, object and depmode must be set" 1>&2 67f7ec340bSmacallan exit 1 68f7ec340bSmacallanfi 69f7ec340bSmacallan 70f7ec340bSmacallan# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 71f7ec340bSmacallandepfile=${depfile-`echo "$object" | 72f7ec340bSmacallan sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 73f7ec340bSmacallantmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 74f7ec340bSmacallan 75f7ec340bSmacallanrm -f "$tmpdepfile" 76f7ec340bSmacallan 772a75d1c4Smrg# Avoid interferences from the environment. 782a75d1c4Smrggccflag= dashmflag= 792a75d1c4Smrg 80f7ec340bSmacallan# Some modes work just like other modes, but use different flags. We 81f7ec340bSmacallan# parameterize here, but still list the modes in the big case below, 82f7ec340bSmacallan# to make depend.m4 easier to write. Note that we *cannot* use a case 83f7ec340bSmacallan# here, because this file can only contain one case statement. 84f7ec340bSmacallanif test "$depmode" = hp; then 85f7ec340bSmacallan # HP compiler uses -M and no extra arg. 86f7ec340bSmacallan gccflag=-M 87f7ec340bSmacallan depmode=gcc 88f7ec340bSmacallanfi 89f7ec340bSmacallan 90f7ec340bSmacallanif test "$depmode" = dashXmstdout; then 91f7ec340bSmacallan # This is just like dashmstdout with a different argument. 92f7ec340bSmacallan dashmflag=-xM 93f7ec340bSmacallan depmode=dashmstdout 94f7ec340bSmacallanfi 95f7ec340bSmacallan 962a75d1c4Smrgcygpath_u="cygpath -u -f -" 972a75d1c4Smrgif test "$depmode" = msvcmsys; then 982a75d1c4Smrg # This is just like msvisualcpp but w/o cygpath translation. 992a75d1c4Smrg # Just convert the backslash-escaped backslashes to single forward 1002a75d1c4Smrg # slashes to satisfy depend.m4 1012a75d1c4Smrg cygpath_u='sed s,\\\\,/,g' 1022a75d1c4Smrg depmode=msvisualcpp 1032a75d1c4Smrgfi 1042a75d1c4Smrg 1052a75d1c4Smrgif test "$depmode" = msvc7msys; then 1062a75d1c4Smrg # This is just like msvc7 but w/o cygpath translation. 1072a75d1c4Smrg # Just convert the backslash-escaped backslashes to single forward 1082a75d1c4Smrg # slashes to satisfy depend.m4 1092a75d1c4Smrg cygpath_u='sed s,\\\\,/,g' 1102a75d1c4Smrg depmode=msvc7 1112a75d1c4Smrgfi 1122a75d1c4Smrg 1132a75d1c4Smrgif test "$depmode" = xlc; then 1142a75d1c4Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1152a75d1c4Smrg gccflag=-qmakedep=gcc,-MF 1162a75d1c4Smrg depmode=gcc 1172a75d1c4Smrgfi 1182a75d1c4Smrg 119f7ec340bSmacallancase "$depmode" in 120f7ec340bSmacallangcc3) 121f7ec340bSmacallan## gcc 3 implements dependency tracking that does exactly what 122f7ec340bSmacallan## we want. Yay! Note: for some reason libtool 1.4 doesn't like 123f7ec340bSmacallan## it if -MD -MP comes after the -MF stuff. Hmm. 1247ce7e03cSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1257ce7e03cSmrg## the command line argument order; so add the flags where they 1267ce7e03cSmrg## appear in depend2.am. Note that the slowdown incurred here 1277ce7e03cSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1287ce7e03cSmrg for arg 1297ce7e03cSmrg do 1307ce7e03cSmrg case $arg in 1317ce7e03cSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1327ce7e03cSmrg *) set fnord "$@" "$arg" ;; 1337ce7e03cSmrg esac 1347ce7e03cSmrg shift # fnord 1357ce7e03cSmrg shift # $arg 1367ce7e03cSmrg done 1377ce7e03cSmrg "$@" 138f7ec340bSmacallan stat=$? 139f7ec340bSmacallan if test $stat -eq 0; then : 140f7ec340bSmacallan else 141f7ec340bSmacallan rm -f "$tmpdepfile" 142f7ec340bSmacallan exit $stat 143f7ec340bSmacallan fi 144f7ec340bSmacallan mv "$tmpdepfile" "$depfile" 145f7ec340bSmacallan ;; 146f7ec340bSmacallan 147f7ec340bSmacallangcc) 1482a75d1c4Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 1492a75d1c4Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 1502a75d1c4Smrg## (see the conditional assignment to $gccflag above). 151f7ec340bSmacallan## There are various ways to get dependency output from gcc. Here's 152f7ec340bSmacallan## why we pick this rather obscure method: 153f7ec340bSmacallan## - Don't want to use -MD because we'd like the dependencies to end 154f7ec340bSmacallan## up in a subdir. Having to rename by hand is ugly. 155f7ec340bSmacallan## (We might end up doing this anyway to support other compilers.) 156f7ec340bSmacallan## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 1572a75d1c4Smrg## -MM, not -M (despite what the docs say). Also, it might not be 1582a75d1c4Smrg## supported by the other compilers which use the 'gcc' depmode. 159f7ec340bSmacallan## - Using -M directly means running the compiler twice (even worse 160f7ec340bSmacallan## than renaming). 161f7ec340bSmacallan if test -z "$gccflag"; then 162f7ec340bSmacallan gccflag=-MD, 163f7ec340bSmacallan fi 164f7ec340bSmacallan "$@" -Wp,"$gccflag$tmpdepfile" 165f7ec340bSmacallan stat=$? 166f7ec340bSmacallan if test $stat -eq 0; then : 167f7ec340bSmacallan else 168f7ec340bSmacallan rm -f "$tmpdepfile" 169f7ec340bSmacallan exit $stat 170f7ec340bSmacallan fi 171f7ec340bSmacallan rm -f "$depfile" 172f7ec340bSmacallan echo "$object : \\" > "$depfile" 173f7ec340bSmacallan alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 174f7ec340bSmacallan## The second -e expression handles DOS-style file names with drive letters. 175f7ec340bSmacallan sed -e 's/^[^:]*: / /' \ 176f7ec340bSmacallan -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 1772a75d1c4Smrg## This next piece of magic avoids the "deleted header file" problem. 178f7ec340bSmacallan## The problem is that when a header file which appears in a .P file 179f7ec340bSmacallan## is deleted, the dependency causes make to die (because there is 180f7ec340bSmacallan## typically no way to rebuild the header). We avoid this by adding 181f7ec340bSmacallan## dummy dependencies for each header file. Too bad gcc doesn't do 182f7ec340bSmacallan## this for us directly. 1832a75d1c4Smrg tr ' ' "$nl" < "$tmpdepfile" | 1842a75d1c4Smrg## Some versions of gcc put a space before the ':'. On the theory 185f7ec340bSmacallan## that the space means something, we add a space to the output as 1862a75d1c4Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 1872a75d1c4Smrg## to the object. Take care to not repeat it in the output. 188f7ec340bSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 189f7ec340bSmacallan## correctly. Breaking it into two sed invocations is a workaround. 1902a75d1c4Smrg sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 1912a75d1c4Smrg | sed -e 's/$/ :/' >> "$depfile" 192f7ec340bSmacallan rm -f "$tmpdepfile" 193f7ec340bSmacallan ;; 194f7ec340bSmacallan 195f7ec340bSmacallanhp) 196f7ec340bSmacallan # This case exists only to let depend.m4 do its work. It works by 197f7ec340bSmacallan # looking at the text of this script. This case will never be run, 198f7ec340bSmacallan # since it is checked for above. 199f7ec340bSmacallan exit 1 200f7ec340bSmacallan ;; 201f7ec340bSmacallan 202f7ec340bSmacallansgi) 203f7ec340bSmacallan if test "$libtool" = yes; then 204f7ec340bSmacallan "$@" "-Wp,-MDupdate,$tmpdepfile" 205f7ec340bSmacallan else 206f7ec340bSmacallan "$@" -MDupdate "$tmpdepfile" 207f7ec340bSmacallan fi 208f7ec340bSmacallan stat=$? 209f7ec340bSmacallan if test $stat -eq 0; then : 210f7ec340bSmacallan else 211f7ec340bSmacallan rm -f "$tmpdepfile" 212f7ec340bSmacallan exit $stat 213f7ec340bSmacallan fi 214f7ec340bSmacallan rm -f "$depfile" 215f7ec340bSmacallan 216f7ec340bSmacallan if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 217f7ec340bSmacallan echo "$object : \\" > "$depfile" 218f7ec340bSmacallan 219f7ec340bSmacallan # Clip off the initial element (the dependent). Don't try to be 220f7ec340bSmacallan # clever and replace this with sed code, as IRIX sed won't handle 221f7ec340bSmacallan # lines with more than a fixed number of characters (4096 in 222f7ec340bSmacallan # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2232a75d1c4Smrg # the IRIX cc adds comments like '#:fec' to the end of the 224f7ec340bSmacallan # dependency line. 2252a75d1c4Smrg tr ' ' "$nl" < "$tmpdepfile" \ 226f7ec340bSmacallan | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ 2272a75d1c4Smrg tr "$nl" ' ' >> "$depfile" 2282a75d1c4Smrg echo >> "$depfile" 229f7ec340bSmacallan 230f7ec340bSmacallan # The second pass generates a dummy entry for each header file. 2312a75d1c4Smrg tr ' ' "$nl" < "$tmpdepfile" \ 232f7ec340bSmacallan | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2332a75d1c4Smrg >> "$depfile" 234f7ec340bSmacallan else 235f7ec340bSmacallan # The sourcefile does not contain any dependencies, so just 236f7ec340bSmacallan # store a dummy comment line, to avoid errors with the Makefile 237f7ec340bSmacallan # "include basename.Plo" scheme. 238f7ec340bSmacallan echo "#dummy" > "$depfile" 239f7ec340bSmacallan fi 240f7ec340bSmacallan rm -f "$tmpdepfile" 241f7ec340bSmacallan ;; 242f7ec340bSmacallan 2432a75d1c4Smrgxlc) 2442a75d1c4Smrg # This case exists only to let depend.m4 do its work. It works by 2452a75d1c4Smrg # looking at the text of this script. This case will never be run, 2462a75d1c4Smrg # since it is checked for above. 2472a75d1c4Smrg exit 1 2482a75d1c4Smrg ;; 2492a75d1c4Smrg 250f7ec340bSmacallanaix) 251f7ec340bSmacallan # The C for AIX Compiler uses -M and outputs the dependencies 252f7ec340bSmacallan # in a .u file. In older versions, this file always lives in the 2532a75d1c4Smrg # current directory. Also, the AIX compiler puts '$object:' at the 254f7ec340bSmacallan # start of each line; $object doesn't have directory information. 255f7ec340bSmacallan # Version 6 uses the directory in both cases. 2567ce7e03cSmrg dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 2577ce7e03cSmrg test "x$dir" = "x$object" && dir= 2587ce7e03cSmrg base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 259f7ec340bSmacallan if test "$libtool" = yes; then 2607ce7e03cSmrg tmpdepfile1=$dir$base.u 2617ce7e03cSmrg tmpdepfile2=$base.u 2627ce7e03cSmrg tmpdepfile3=$dir.libs/$base.u 263f7ec340bSmacallan "$@" -Wc,-M 264f7ec340bSmacallan else 2657ce7e03cSmrg tmpdepfile1=$dir$base.u 2667ce7e03cSmrg tmpdepfile2=$dir$base.u 2677ce7e03cSmrg tmpdepfile3=$dir$base.u 268f7ec340bSmacallan "$@" -M 269f7ec340bSmacallan fi 270f7ec340bSmacallan stat=$? 271f7ec340bSmacallan 272f7ec340bSmacallan if test $stat -eq 0; then : 273f7ec340bSmacallan else 2747ce7e03cSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 275f7ec340bSmacallan exit $stat 276f7ec340bSmacallan fi 277f7ec340bSmacallan 2787ce7e03cSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 2797ce7e03cSmrg do 2807ce7e03cSmrg test -f "$tmpdepfile" && break 2817ce7e03cSmrg done 282f7ec340bSmacallan if test -f "$tmpdepfile"; then 2832a75d1c4Smrg # Each line is of the form 'foo.o: dependent.h'. 284f7ec340bSmacallan # Do two passes, one to just change these to 2852a75d1c4Smrg # '$object: dependent.h' and one to simply 'dependent.h:'. 2867ce7e03cSmrg sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 2872a75d1c4Smrg sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 288f7ec340bSmacallan else 289f7ec340bSmacallan # The sourcefile does not contain any dependencies, so just 290f7ec340bSmacallan # store a dummy comment line, to avoid errors with the Makefile 291f7ec340bSmacallan # "include basename.Plo" scheme. 292f7ec340bSmacallan echo "#dummy" > "$depfile" 293f7ec340bSmacallan fi 294f7ec340bSmacallan rm -f "$tmpdepfile" 295f7ec340bSmacallan ;; 296f7ec340bSmacallan 297f7ec340bSmacallanicc) 2982a75d1c4Smrg # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'. 2992a75d1c4Smrg # However on 3002a75d1c4Smrg # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c 301f7ec340bSmacallan # ICC 7.0 will fill foo.d with something like 302f7ec340bSmacallan # foo.o: sub/foo.c 303f7ec340bSmacallan # foo.o: sub/foo.h 3042a75d1c4Smrg # which is wrong. We want 305f7ec340bSmacallan # sub/foo.o: sub/foo.c 306f7ec340bSmacallan # sub/foo.o: sub/foo.h 307f7ec340bSmacallan # sub/foo.c: 308f7ec340bSmacallan # sub/foo.h: 309f7ec340bSmacallan # ICC 7.1 will output 310f7ec340bSmacallan # foo.o: sub/foo.c sub/foo.h 3112a75d1c4Smrg # and will wrap long lines using '\': 312f7ec340bSmacallan # foo.o: sub/foo.c ... \ 313f7ec340bSmacallan # sub/foo.h ... \ 314f7ec340bSmacallan # ... 3152a75d1c4Smrg # tcc 0.9.26 (FIXME still under development at the moment of writing) 3162a75d1c4Smrg # will emit a similar output, but also prepend the continuation lines 3172a75d1c4Smrg # with horizontal tabulation characters. 318f7ec340bSmacallan "$@" -MD -MF "$tmpdepfile" 319f7ec340bSmacallan stat=$? 320f7ec340bSmacallan if test $stat -eq 0; then : 321f7ec340bSmacallan else 322f7ec340bSmacallan rm -f "$tmpdepfile" 323f7ec340bSmacallan exit $stat 324f7ec340bSmacallan fi 325f7ec340bSmacallan rm -f "$depfile" 3262a75d1c4Smrg # Each line is of the form 'foo.o: dependent.h', 3272a75d1c4Smrg # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'. 3282a75d1c4Smrg # Do two passes, one to just change these to 3292a75d1c4Smrg # '$object: dependent.h' and one to simply 'dependent.h:'. 3302a75d1c4Smrg sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \ 3312a75d1c4Smrg < "$tmpdepfile" > "$depfile" 3322a75d1c4Smrg sed ' 3332a75d1c4Smrg s/[ '"$tab"'][ '"$tab"']*/ /g 3342a75d1c4Smrg s/^ *// 3352a75d1c4Smrg s/ *\\*$// 3362a75d1c4Smrg s/^[^:]*: *// 3372a75d1c4Smrg /^$/d 3382a75d1c4Smrg /:$/d 3392a75d1c4Smrg s/$/ :/ 3402a75d1c4Smrg ' < "$tmpdepfile" >> "$depfile" 3412a75d1c4Smrg rm -f "$tmpdepfile" 3422a75d1c4Smrg ;; 3432a75d1c4Smrg 3442a75d1c4Smrg## The order of this option in the case statement is important, since the 3452a75d1c4Smrg## shell code in configure will try each of these formats in the order 3462a75d1c4Smrg## listed in this file. A plain '-MD' option would be understood by many 3472a75d1c4Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3482a75d1c4Smrgpgcc) 3492a75d1c4Smrg # Portland's C compiler understands '-MD'. 3502a75d1c4Smrg # Will always output deps to 'file.d' where file is the root name of the 3512a75d1c4Smrg # source file under compilation, even if file resides in a subdirectory. 3522a75d1c4Smrg # The object file name does not affect the name of the '.d' file. 3532a75d1c4Smrg # pgcc 10.2 will output 3542a75d1c4Smrg # foo.o: sub/foo.c sub/foo.h 3552a75d1c4Smrg # and will wrap long lines using '\' : 3562a75d1c4Smrg # foo.o: sub/foo.c ... \ 3572a75d1c4Smrg # sub/foo.h ... \ 3582a75d1c4Smrg # ... 3592a75d1c4Smrg dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 3602a75d1c4Smrg test "x$dir" = "x$object" && dir= 3612a75d1c4Smrg # Use the source, not the object, to determine the base name, since 3622a75d1c4Smrg # that's sadly what pgcc will do too. 3632a75d1c4Smrg base=`echo "$source" | sed -e 's|^.*/||' -e 's/\.[-_a-zA-Z0-9]*$//'` 3642a75d1c4Smrg tmpdepfile="$base.d" 3652a75d1c4Smrg 3662a75d1c4Smrg # For projects that build the same source file twice into different object 3672a75d1c4Smrg # files, the pgcc approach of using the *source* file root name can cause 3682a75d1c4Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3692a75d1c4Smrg # the same $tmpdepfile. 3702a75d1c4Smrg lockdir="$base.d-lock" 3712a75d1c4Smrg trap "echo '$0: caught signal, cleaning up...' >&2; rm -rf $lockdir" 1 2 13 15 3722a75d1c4Smrg numtries=100 3732a75d1c4Smrg i=$numtries 3742a75d1c4Smrg while test $i -gt 0 ; do 3752a75d1c4Smrg # mkdir is a portable test-and-set. 3762a75d1c4Smrg if mkdir $lockdir 2>/dev/null; then 3772a75d1c4Smrg # This process acquired the lock. 3782a75d1c4Smrg "$@" -MD 3792a75d1c4Smrg stat=$? 3802a75d1c4Smrg # Release the lock. 3812a75d1c4Smrg rm -rf $lockdir 3822a75d1c4Smrg break 3832a75d1c4Smrg else 3842a75d1c4Smrg ## the lock is being held by a different process, 3852a75d1c4Smrg ## wait until the winning process is done or we timeout 3862a75d1c4Smrg while test -d $lockdir && test $i -gt 0; do 3872a75d1c4Smrg sleep 1 3882a75d1c4Smrg i=`expr $i - 1` 3892a75d1c4Smrg done 3902a75d1c4Smrg fi 3912a75d1c4Smrg i=`expr $i - 1` 3922a75d1c4Smrg done 3932a75d1c4Smrg trap - 1 2 13 15 3942a75d1c4Smrg if test $i -le 0; then 3952a75d1c4Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 3962a75d1c4Smrg echo "$0: check lockdir '$lockdir'" >&2 3972a75d1c4Smrg exit 1 3982a75d1c4Smrg fi 3992a75d1c4Smrg 4002a75d1c4Smrg if test $stat -ne 0; then 4012a75d1c4Smrg rm -f "$tmpdepfile" 4022a75d1c4Smrg exit $stat 4032a75d1c4Smrg fi 4042a75d1c4Smrg rm -f "$depfile" 405f7ec340bSmacallan # Each line is of the form `foo.o: dependent.h', 406f7ec340bSmacallan # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 407f7ec340bSmacallan # Do two passes, one to just change these to 408f7ec340bSmacallan # `$object: dependent.h' and one to simply `dependent.h:'. 409f7ec340bSmacallan sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 410f7ec340bSmacallan # Some versions of the HPUX 10.20 sed can't process this invocation 411f7ec340bSmacallan # correctly. Breaking it into two sed invocations is a workaround. 412f7ec340bSmacallan sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" | 413f7ec340bSmacallan sed -e 's/$/ :/' >> "$depfile" 414f7ec340bSmacallan rm -f "$tmpdepfile" 415f7ec340bSmacallan ;; 416f7ec340bSmacallan 4177ce7e03cSmrghp2) 4187ce7e03cSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4197ce7e03cSmrg # compilers, which have integrated preprocessors. The correct option 4207ce7e03cSmrg # to use with these is +Maked; it writes dependencies to a file named 4217ce7e03cSmrg # 'foo.d', which lands next to the object file, wherever that 4227ce7e03cSmrg # happens to be. 4237ce7e03cSmrg # Much of this is similar to the tru64 case; see comments there. 4247ce7e03cSmrg dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 4257ce7e03cSmrg test "x$dir" = "x$object" && dir= 4267ce7e03cSmrg base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 4277ce7e03cSmrg if test "$libtool" = yes; then 4287ce7e03cSmrg tmpdepfile1=$dir$base.d 4297ce7e03cSmrg tmpdepfile2=$dir.libs/$base.d 4307ce7e03cSmrg "$@" -Wc,+Maked 4317ce7e03cSmrg else 4327ce7e03cSmrg tmpdepfile1=$dir$base.d 4337ce7e03cSmrg tmpdepfile2=$dir$base.d 4347ce7e03cSmrg "$@" +Maked 4357ce7e03cSmrg fi 4367ce7e03cSmrg stat=$? 4377ce7e03cSmrg if test $stat -eq 0; then : 4387ce7e03cSmrg else 4397ce7e03cSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4407ce7e03cSmrg exit $stat 4417ce7e03cSmrg fi 4427ce7e03cSmrg 4437ce7e03cSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4447ce7e03cSmrg do 4457ce7e03cSmrg test -f "$tmpdepfile" && break 4467ce7e03cSmrg done 4477ce7e03cSmrg if test -f "$tmpdepfile"; then 4487ce7e03cSmrg sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile" 4492a75d1c4Smrg # Add 'dependent.h:' lines. 4502a75d1c4Smrg sed -ne '2,${ 4512a75d1c4Smrg s/^ *// 4522a75d1c4Smrg s/ \\*$// 4532a75d1c4Smrg s/$/:/ 4542a75d1c4Smrg p 4552a75d1c4Smrg }' "$tmpdepfile" >> "$depfile" 4567ce7e03cSmrg else 4577ce7e03cSmrg echo "#dummy" > "$depfile" 4587ce7e03cSmrg fi 4597ce7e03cSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 4607ce7e03cSmrg ;; 4617ce7e03cSmrg 462f7ec340bSmacallantru64) 463f7ec340bSmacallan # The Tru64 compiler uses -MD to generate dependencies as a side 4642a75d1c4Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 465f7ec340bSmacallan # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4662a75d1c4Smrg # dependencies in 'foo.d' instead, so we check for that too. 467f7ec340bSmacallan # Subdirectories are respected. 468f7ec340bSmacallan dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 469f7ec340bSmacallan test "x$dir" = "x$object" && dir= 470f7ec340bSmacallan base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 471f7ec340bSmacallan 472f7ec340bSmacallan if test "$libtool" = yes; then 473f7ec340bSmacallan # With Tru64 cc, shared objects can also be used to make a 4747ce7e03cSmrg # static library. This mechanism is used in libtool 1.4 series to 475f7ec340bSmacallan # handle both shared and static libraries in a single compilation. 476f7ec340bSmacallan # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. 477f7ec340bSmacallan # 478f7ec340bSmacallan # With libtool 1.5 this exception was removed, and libtool now 479f7ec340bSmacallan # generates 2 separate objects for the 2 libraries. These two 4807ce7e03cSmrg # compilations output dependencies in $dir.libs/$base.o.d and 481f7ec340bSmacallan # in $dir$base.o.d. We have to check for both files, because 482f7ec340bSmacallan # one of the two compilations can be disabled. We should prefer 483f7ec340bSmacallan # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 484f7ec340bSmacallan # automatically cleaned when .libs/ is deleted, while ignoring 485f7ec340bSmacallan # the former would cause a distcleancheck panic. 486f7ec340bSmacallan tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 487f7ec340bSmacallan tmpdepfile2=$dir$base.o.d # libtool 1.5 488f7ec340bSmacallan tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 489f7ec340bSmacallan tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 490f7ec340bSmacallan "$@" -Wc,-MD 491f7ec340bSmacallan else 492f7ec340bSmacallan tmpdepfile1=$dir$base.o.d 493f7ec340bSmacallan tmpdepfile2=$dir$base.d 494f7ec340bSmacallan tmpdepfile3=$dir$base.d 495f7ec340bSmacallan tmpdepfile4=$dir$base.d 496f7ec340bSmacallan "$@" -MD 497f7ec340bSmacallan fi 498f7ec340bSmacallan 499f7ec340bSmacallan stat=$? 500f7ec340bSmacallan if test $stat -eq 0; then : 501f7ec340bSmacallan else 502f7ec340bSmacallan rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 503f7ec340bSmacallan exit $stat 504f7ec340bSmacallan fi 505f7ec340bSmacallan 506f7ec340bSmacallan for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 507f7ec340bSmacallan do 508f7ec340bSmacallan test -f "$tmpdepfile" && break 509f7ec340bSmacallan done 510f7ec340bSmacallan if test -f "$tmpdepfile"; then 511f7ec340bSmacallan sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 5122a75d1c4Smrg sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 513f7ec340bSmacallan else 514f7ec340bSmacallan echo "#dummy" > "$depfile" 515f7ec340bSmacallan fi 516f7ec340bSmacallan rm -f "$tmpdepfile" 517f7ec340bSmacallan ;; 518f7ec340bSmacallan 5192a75d1c4Smrgmsvc7) 5202a75d1c4Smrg if test "$libtool" = yes; then 5212a75d1c4Smrg showIncludes=-Wc,-showIncludes 5222a75d1c4Smrg else 5232a75d1c4Smrg showIncludes=-showIncludes 5242a75d1c4Smrg fi 5252a75d1c4Smrg "$@" $showIncludes > "$tmpdepfile" 5262a75d1c4Smrg stat=$? 5272a75d1c4Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5282a75d1c4Smrg if test "$stat" = 0; then : 5292a75d1c4Smrg else 5302a75d1c4Smrg rm -f "$tmpdepfile" 5312a75d1c4Smrg exit $stat 5322a75d1c4Smrg fi 5332a75d1c4Smrg rm -f "$depfile" 5342a75d1c4Smrg echo "$object : \\" > "$depfile" 5352a75d1c4Smrg # The first sed program below extracts the file names and escapes 5362a75d1c4Smrg # backslashes for cygpath. The second sed program outputs the file 5372a75d1c4Smrg # name when reading, but also accumulates all include files in the 5382a75d1c4Smrg # hold buffer in order to output them again at the end. This only 5392a75d1c4Smrg # works with sed implementations that can handle large buffers. 5402a75d1c4Smrg sed < "$tmpdepfile" -n ' 5412a75d1c4Smrg/^Note: including file: *\(.*\)/ { 5422a75d1c4Smrg s//\1/ 5432a75d1c4Smrg s/\\/\\\\/g 5442a75d1c4Smrg p 5452a75d1c4Smrg}' | $cygpath_u | sort -u | sed -n ' 5462a75d1c4Smrgs/ /\\ /g 5472a75d1c4Smrgs/\(.*\)/'"$tab"'\1 \\/p 5482a75d1c4Smrgs/.\(.*\) \\/\1:/ 5492a75d1c4SmrgH 5502a75d1c4Smrg$ { 5512a75d1c4Smrg s/.*/'"$tab"'/ 5522a75d1c4Smrg G 5532a75d1c4Smrg p 5542a75d1c4Smrg}' >> "$depfile" 5552a75d1c4Smrg rm -f "$tmpdepfile" 5562a75d1c4Smrg ;; 5572a75d1c4Smrg 5582a75d1c4Smrgmsvc7msys) 5592a75d1c4Smrg # This case exists only to let depend.m4 do its work. It works by 5602a75d1c4Smrg # looking at the text of this script. This case will never be run, 5612a75d1c4Smrg # since it is checked for above. 5622a75d1c4Smrg exit 1 5632a75d1c4Smrg ;; 5642a75d1c4Smrg 565f7ec340bSmacallan#nosideeffect) 566f7ec340bSmacallan # This comment above is used by automake to tell side-effect 567f7ec340bSmacallan # dependency tracking mechanisms from slower ones. 568f7ec340bSmacallan 569f7ec340bSmacallandashmstdout) 570f7ec340bSmacallan # Important note: in order to support this mode, a compiler *must* 571f7ec340bSmacallan # always write the preprocessed file to stdout, regardless of -o. 572f7ec340bSmacallan "$@" || exit $? 573f7ec340bSmacallan 574f7ec340bSmacallan # Remove the call to Libtool. 575f7ec340bSmacallan if test "$libtool" = yes; then 5762a75d1c4Smrg while test "X$1" != 'X--mode=compile'; do 577f7ec340bSmacallan shift 578f7ec340bSmacallan done 579f7ec340bSmacallan shift 580f7ec340bSmacallan fi 581f7ec340bSmacallan 5822a75d1c4Smrg # Remove '-o $object'. 583f7ec340bSmacallan IFS=" " 584f7ec340bSmacallan for arg 585f7ec340bSmacallan do 586f7ec340bSmacallan case $arg in 587f7ec340bSmacallan -o) 588f7ec340bSmacallan shift 589f7ec340bSmacallan ;; 590f7ec340bSmacallan $object) 591f7ec340bSmacallan shift 592f7ec340bSmacallan ;; 593f7ec340bSmacallan *) 594f7ec340bSmacallan set fnord "$@" "$arg" 595f7ec340bSmacallan shift # fnord 596f7ec340bSmacallan shift # $arg 597f7ec340bSmacallan ;; 598f7ec340bSmacallan esac 599f7ec340bSmacallan done 600f7ec340bSmacallan 601f7ec340bSmacallan test -z "$dashmflag" && dashmflag=-M 6022a75d1c4Smrg # Require at least two characters before searching for ':' 603f7ec340bSmacallan # in the target name. This is to cope with DOS-style filenames: 6042a75d1c4Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 605f7ec340bSmacallan "$@" $dashmflag | 6062a75d1c4Smrg sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile" 607f7ec340bSmacallan rm -f "$depfile" 608f7ec340bSmacallan cat < "$tmpdepfile" > "$depfile" 6092a75d1c4Smrg tr ' ' "$nl" < "$tmpdepfile" | \ 610f7ec340bSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 611f7ec340bSmacallan## correctly. Breaking it into two sed invocations is a workaround. 612f7ec340bSmacallan sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 613f7ec340bSmacallan rm -f "$tmpdepfile" 614f7ec340bSmacallan ;; 615f7ec340bSmacallan 616f7ec340bSmacallandashXmstdout) 617f7ec340bSmacallan # This case only exists to satisfy depend.m4. It is never actually 618f7ec340bSmacallan # run, as this mode is specially recognized in the preamble. 619f7ec340bSmacallan exit 1 620f7ec340bSmacallan ;; 621f7ec340bSmacallan 622f7ec340bSmacallanmakedepend) 623f7ec340bSmacallan "$@" || exit $? 624f7ec340bSmacallan # Remove any Libtool call 625f7ec340bSmacallan if test "$libtool" = yes; then 6262a75d1c4Smrg while test "X$1" != 'X--mode=compile'; do 627f7ec340bSmacallan shift 628f7ec340bSmacallan done 629f7ec340bSmacallan shift 630f7ec340bSmacallan fi 631f7ec340bSmacallan # X makedepend 632f7ec340bSmacallan shift 6332a75d1c4Smrg cleared=no eat=no 6342a75d1c4Smrg for arg 6352a75d1c4Smrg do 636f7ec340bSmacallan case $cleared in 637f7ec340bSmacallan no) 638f7ec340bSmacallan set ""; shift 639f7ec340bSmacallan cleared=yes ;; 640f7ec340bSmacallan esac 6412a75d1c4Smrg if test $eat = yes; then 6422a75d1c4Smrg eat=no 6432a75d1c4Smrg continue 6442a75d1c4Smrg fi 645f7ec340bSmacallan case "$arg" in 646f7ec340bSmacallan -D*|-I*) 647f7ec340bSmacallan set fnord "$@" "$arg"; shift ;; 648f7ec340bSmacallan # Strip any option that makedepend may not understand. Remove 649f7ec340bSmacallan # the object too, otherwise makedepend will parse it as a source file. 6502a75d1c4Smrg -arch) 6512a75d1c4Smrg eat=yes ;; 652f7ec340bSmacallan -*|$object) 653f7ec340bSmacallan ;; 654f7ec340bSmacallan *) 655f7ec340bSmacallan set fnord "$@" "$arg"; shift ;; 656f7ec340bSmacallan esac 657f7ec340bSmacallan done 6582a75d1c4Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 659f7ec340bSmacallan touch "$tmpdepfile" 660f7ec340bSmacallan ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 661f7ec340bSmacallan rm -f "$depfile" 6622a75d1c4Smrg # makedepend may prepend the VPATH from the source file name to the object. 6632a75d1c4Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 6642a75d1c4Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6652a75d1c4Smrg sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \ 666f7ec340bSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 667f7ec340bSmacallan## correctly. Breaking it into two sed invocations is a workaround. 668f7ec340bSmacallan sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 669f7ec340bSmacallan rm -f "$tmpdepfile" "$tmpdepfile".bak 670f7ec340bSmacallan ;; 671f7ec340bSmacallan 672f7ec340bSmacallancpp) 673f7ec340bSmacallan # Important note: in order to support this mode, a compiler *must* 674f7ec340bSmacallan # always write the preprocessed file to stdout. 675f7ec340bSmacallan "$@" || exit $? 676f7ec340bSmacallan 677f7ec340bSmacallan # Remove the call to Libtool. 678f7ec340bSmacallan if test "$libtool" = yes; then 6792a75d1c4Smrg while test "X$1" != 'X--mode=compile'; do 680f7ec340bSmacallan shift 681f7ec340bSmacallan done 682f7ec340bSmacallan shift 683f7ec340bSmacallan fi 684f7ec340bSmacallan 6852a75d1c4Smrg # Remove '-o $object'. 686f7ec340bSmacallan IFS=" " 687f7ec340bSmacallan for arg 688f7ec340bSmacallan do 689f7ec340bSmacallan case $arg in 690f7ec340bSmacallan -o) 691f7ec340bSmacallan shift 692f7ec340bSmacallan ;; 693f7ec340bSmacallan $object) 694f7ec340bSmacallan shift 695f7ec340bSmacallan ;; 696f7ec340bSmacallan *) 697f7ec340bSmacallan set fnord "$@" "$arg" 698f7ec340bSmacallan shift # fnord 699f7ec340bSmacallan shift # $arg 700f7ec340bSmacallan ;; 701f7ec340bSmacallan esac 702f7ec340bSmacallan done 703f7ec340bSmacallan 704f7ec340bSmacallan "$@" -E | 705f7ec340bSmacallan sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 706f7ec340bSmacallan -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | 707f7ec340bSmacallan sed '$ s: \\$::' > "$tmpdepfile" 708f7ec340bSmacallan rm -f "$depfile" 709f7ec340bSmacallan echo "$object : \\" > "$depfile" 710f7ec340bSmacallan cat < "$tmpdepfile" >> "$depfile" 711f7ec340bSmacallan sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 712f7ec340bSmacallan rm -f "$tmpdepfile" 713f7ec340bSmacallan ;; 714f7ec340bSmacallan 715f7ec340bSmacallanmsvisualcpp) 716f7ec340bSmacallan # Important note: in order to support this mode, a compiler *must* 7172a75d1c4Smrg # always write the preprocessed file to stdout. 718f7ec340bSmacallan "$@" || exit $? 7192a75d1c4Smrg 7202a75d1c4Smrg # Remove the call to Libtool. 7212a75d1c4Smrg if test "$libtool" = yes; then 7222a75d1c4Smrg while test "X$1" != 'X--mode=compile'; do 7232a75d1c4Smrg shift 7242a75d1c4Smrg done 7252a75d1c4Smrg shift 7262a75d1c4Smrg fi 7272a75d1c4Smrg 728f7ec340bSmacallan IFS=" " 729f7ec340bSmacallan for arg 730f7ec340bSmacallan do 731f7ec340bSmacallan case "$arg" in 7322a75d1c4Smrg -o) 7332a75d1c4Smrg shift 7342a75d1c4Smrg ;; 7352a75d1c4Smrg $object) 7362a75d1c4Smrg shift 7372a75d1c4Smrg ;; 738f7ec340bSmacallan "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 739f7ec340bSmacallan set fnord "$@" 740f7ec340bSmacallan shift 741f7ec340bSmacallan shift 742f7ec340bSmacallan ;; 743f7ec340bSmacallan *) 744f7ec340bSmacallan set fnord "$@" "$arg" 745f7ec340bSmacallan shift 746f7ec340bSmacallan shift 747f7ec340bSmacallan ;; 748f7ec340bSmacallan esac 749f7ec340bSmacallan done 7502a75d1c4Smrg "$@" -E 2>/dev/null | 7512a75d1c4Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 752f7ec340bSmacallan rm -f "$depfile" 753f7ec340bSmacallan echo "$object : \\" > "$depfile" 7542a75d1c4Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7552a75d1c4Smrg echo "$tab" >> "$depfile" 7562a75d1c4Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 757f7ec340bSmacallan rm -f "$tmpdepfile" 758f7ec340bSmacallan ;; 759f7ec340bSmacallan 7602a75d1c4Smrgmsvcmsys) 7612a75d1c4Smrg # This case exists only to let depend.m4 do its work. It works by 7622a75d1c4Smrg # looking at the text of this script. This case will never be run, 7632a75d1c4Smrg # since it is checked for above. 7642a75d1c4Smrg exit 1 7652a75d1c4Smrg ;; 7662a75d1c4Smrg 767f7ec340bSmacallannone) 768f7ec340bSmacallan exec "$@" 769f7ec340bSmacallan ;; 770f7ec340bSmacallan 771f7ec340bSmacallan*) 772f7ec340bSmacallan echo "Unknown depmode $depmode" 1>&2 773f7ec340bSmacallan exit 1 774f7ec340bSmacallan ;; 775f7ec340bSmacallanesac 776f7ec340bSmacallan 777f7ec340bSmacallanexit 0 778f7ec340bSmacallan 779f7ec340bSmacallan# Local Variables: 780f7ec340bSmacallan# mode: shell-script 781f7ec340bSmacallan# sh-indentation: 2 782f7ec340bSmacallan# eval: (add-hook 'write-file-hooks 'time-stamp) 783f7ec340bSmacallan# time-stamp-start: "scriptversion=" 784f7ec340bSmacallan# time-stamp-format: "%:y-%02m-%02d.%02H" 7852a75d1c4Smrg# time-stamp-time-zone: "UTC" 7862a75d1c4Smrg# time-stamp-end: "; # UTC" 787f7ec340bSmacallan# End: 788