depcomp revision 65d490d0
1e4da13eeSmacallan#! /bin/sh 2e4da13eeSmacallan# depcomp - compile a program generating dependencies as side-effects 3e4da13eeSmacallan 465d490d0Smrgscriptversion=2012-07-12.20; # UTC 5e4da13eeSmacallan 665d490d0Smrg# Copyright (C) 1999-2012 Free Software Foundation, Inc. 7e4da13eeSmacallan 8e4da13eeSmacallan# This program is free software; you can redistribute it and/or modify 9e4da13eeSmacallan# it under the terms of the GNU General Public License as published by 10e4da13eeSmacallan# the Free Software Foundation; either version 2, or (at your option) 11e4da13eeSmacallan# any later version. 12e4da13eeSmacallan 13e4da13eeSmacallan# This program is distributed in the hope that it will be useful, 14e4da13eeSmacallan# but WITHOUT ANY WARRANTY; without even the implied warranty of 15e4da13eeSmacallan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16e4da13eeSmacallan# GNU General Public License for more details. 17e4da13eeSmacallan 18e4da13eeSmacallan# You should have received a copy of the GNU General Public License 1965d490d0Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20e4da13eeSmacallan 21e4da13eeSmacallan# As a special exception to the GNU General Public License, if you 22e4da13eeSmacallan# distribute this file as part of a program that contains a 23e4da13eeSmacallan# configuration script generated by Autoconf, you may include it under 24e4da13eeSmacallan# the same distribution terms that you use for the rest of that program. 25e4da13eeSmacallan 26e4da13eeSmacallan# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27e4da13eeSmacallan 28e4da13eeSmacallancase $1 in 29e4da13eeSmacallan '') 3065d490d0Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31e4da13eeSmacallan exit 1; 32e4da13eeSmacallan ;; 33e4da13eeSmacallan -h | --h*) 34e4da13eeSmacallan cat <<\EOF 35e4da13eeSmacallanUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36e4da13eeSmacallan 37e4da13eeSmacallanRun PROGRAMS ARGS to compile a file, generating dependencies 38e4da13eeSmacallanas side-effects. 39e4da13eeSmacallan 40e4da13eeSmacallanEnvironment variables: 41e4da13eeSmacallan depmode Dependency tracking mode. 4265d490d0Smrg source Source file read by 'PROGRAMS ARGS'. 4365d490d0Smrg object Object file output by 'PROGRAMS ARGS'. 44e4da13eeSmacallan DEPDIR directory where to store dependencies. 45e4da13eeSmacallan depfile Dependency file to output. 4665d490d0Smrg tmpdepfile Temporary file to use when outputting dependencies. 47e4da13eeSmacallan libtool Whether libtool is used (yes/no). 48e4da13eeSmacallan 49e4da13eeSmacallanReport bugs to <bug-automake@gnu.org>. 50e4da13eeSmacallanEOF 51e4da13eeSmacallan exit $? 52e4da13eeSmacallan ;; 53e4da13eeSmacallan -v | --v*) 54e4da13eeSmacallan echo "depcomp $scriptversion" 55e4da13eeSmacallan exit $? 56e4da13eeSmacallan ;; 57e4da13eeSmacallanesac 58e4da13eeSmacallan 5965d490d0Smrg# A tabulation character. 6065d490d0Smrgtab=' ' 6165d490d0Smrg# A newline character. 6265d490d0Smrgnl=' 6365d490d0Smrg' 6465d490d0Smrg 65e4da13eeSmacallanif test -z "$depmode" || test -z "$source" || test -z "$object"; then 66e4da13eeSmacallan echo "depcomp: Variables source, object and depmode must be set" 1>&2 67e4da13eeSmacallan exit 1 68e4da13eeSmacallanfi 69e4da13eeSmacallan 70e4da13eeSmacallan# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 71e4da13eeSmacallandepfile=${depfile-`echo "$object" | 72e4da13eeSmacallan sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 73e4da13eeSmacallantmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 74e4da13eeSmacallan 75e4da13eeSmacallanrm -f "$tmpdepfile" 76e4da13eeSmacallan 7765d490d0Smrg# Avoid interferences from the environment. 7865d490d0Smrggccflag= dashmflag= 7965d490d0Smrg 80e4da13eeSmacallan# Some modes work just like other modes, but use different flags. We 81e4da13eeSmacallan# parameterize here, but still list the modes in the big case below, 82e4da13eeSmacallan# to make depend.m4 easier to write. Note that we *cannot* use a case 83e4da13eeSmacallan# here, because this file can only contain one case statement. 84e4da13eeSmacallanif test "$depmode" = hp; then 85e4da13eeSmacallan # HP compiler uses -M and no extra arg. 86e4da13eeSmacallan gccflag=-M 87e4da13eeSmacallan depmode=gcc 88e4da13eeSmacallanfi 89e4da13eeSmacallan 90e4da13eeSmacallanif test "$depmode" = dashXmstdout; then 91e4da13eeSmacallan # This is just like dashmstdout with a different argument. 92e4da13eeSmacallan dashmflag=-xM 93e4da13eeSmacallan depmode=dashmstdout 94e4da13eeSmacallanfi 95e4da13eeSmacallan 9665d490d0Smrgcygpath_u="cygpath -u -f -" 9765d490d0Smrgif test "$depmode" = msvcmsys; then 9865d490d0Smrg # This is just like msvisualcpp but w/o cygpath translation. 9965d490d0Smrg # Just convert the backslash-escaped backslashes to single forward 10065d490d0Smrg # slashes to satisfy depend.m4 10165d490d0Smrg cygpath_u='sed s,\\\\,/,g' 10265d490d0Smrg depmode=msvisualcpp 10365d490d0Smrgfi 10465d490d0Smrg 10565d490d0Smrgif test "$depmode" = msvc7msys; then 10665d490d0Smrg # This is just like msvc7 but w/o cygpath translation. 10765d490d0Smrg # Just convert the backslash-escaped backslashes to single forward 10865d490d0Smrg # slashes to satisfy depend.m4 10965d490d0Smrg cygpath_u='sed s,\\\\,/,g' 11065d490d0Smrg depmode=msvc7 11165d490d0Smrgfi 11265d490d0Smrg 11365d490d0Smrgif test "$depmode" = xlc; then 11465d490d0Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 11565d490d0Smrg gccflag=-qmakedep=gcc,-MF 11665d490d0Smrg depmode=gcc 11765d490d0Smrgfi 11865d490d0Smrg 119e4da13eeSmacallancase "$depmode" in 120e4da13eeSmacallangcc3) 121e4da13eeSmacallan## gcc 3 implements dependency tracking that does exactly what 122e4da13eeSmacallan## we want. Yay! Note: for some reason libtool 1.4 doesn't like 123e4da13eeSmacallan## it if -MD -MP comes after the -MF stuff. Hmm. 124e4da13eeSmacallan## Unfortunately, FreeBSD c89 acceptance of flags depends upon 125e4da13eeSmacallan## the command line argument order; so add the flags where they 126e4da13eeSmacallan## appear in depend2.am. Note that the slowdown incurred here 127e4da13eeSmacallan## affects only configure: in makefiles, %FASTDEP% shortcuts this. 128e4da13eeSmacallan for arg 129e4da13eeSmacallan do 130e4da13eeSmacallan case $arg in 131e4da13eeSmacallan -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 132e4da13eeSmacallan *) set fnord "$@" "$arg" ;; 133e4da13eeSmacallan esac 134e4da13eeSmacallan shift # fnord 135e4da13eeSmacallan shift # $arg 136e4da13eeSmacallan done 137e4da13eeSmacallan "$@" 138e4da13eeSmacallan stat=$? 139e4da13eeSmacallan if test $stat -eq 0; then : 140e4da13eeSmacallan else 141e4da13eeSmacallan rm -f "$tmpdepfile" 142e4da13eeSmacallan exit $stat 143e4da13eeSmacallan fi 144e4da13eeSmacallan mv "$tmpdepfile" "$depfile" 145e4da13eeSmacallan ;; 146e4da13eeSmacallan 147e4da13eeSmacallangcc) 14865d490d0Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 14965d490d0Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 15065d490d0Smrg## (see the conditional assignment to $gccflag above). 151e4da13eeSmacallan## There are various ways to get dependency output from gcc. Here's 152e4da13eeSmacallan## why we pick this rather obscure method: 153e4da13eeSmacallan## - Don't want to use -MD because we'd like the dependencies to end 154e4da13eeSmacallan## up in a subdir. Having to rename by hand is ugly. 155e4da13eeSmacallan## (We might end up doing this anyway to support other compilers.) 156e4da13eeSmacallan## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 15765d490d0Smrg## -MM, not -M (despite what the docs say). Also, it might not be 15865d490d0Smrg## supported by the other compilers which use the 'gcc' depmode. 159e4da13eeSmacallan## - Using -M directly means running the compiler twice (even worse 160e4da13eeSmacallan## than renaming). 161e4da13eeSmacallan if test -z "$gccflag"; then 162e4da13eeSmacallan gccflag=-MD, 163e4da13eeSmacallan fi 164e4da13eeSmacallan "$@" -Wp,"$gccflag$tmpdepfile" 165e4da13eeSmacallan stat=$? 166e4da13eeSmacallan if test $stat -eq 0; then : 167e4da13eeSmacallan else 168e4da13eeSmacallan rm -f "$tmpdepfile" 169e4da13eeSmacallan exit $stat 170e4da13eeSmacallan fi 171e4da13eeSmacallan rm -f "$depfile" 172e4da13eeSmacallan echo "$object : \\" > "$depfile" 173e4da13eeSmacallan alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 174e4da13eeSmacallan## The second -e expression handles DOS-style file names with drive letters. 175e4da13eeSmacallan sed -e 's/^[^:]*: / /' \ 176e4da13eeSmacallan -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 17765d490d0Smrg## This next piece of magic avoids the "deleted header file" problem. 178e4da13eeSmacallan## The problem is that when a header file which appears in a .P file 179e4da13eeSmacallan## is deleted, the dependency causes make to die (because there is 180e4da13eeSmacallan## typically no way to rebuild the header). We avoid this by adding 181e4da13eeSmacallan## dummy dependencies for each header file. Too bad gcc doesn't do 182e4da13eeSmacallan## this for us directly. 18365d490d0Smrg tr ' ' "$nl" < "$tmpdepfile" | 18465d490d0Smrg## Some versions of gcc put a space before the ':'. On the theory 185e4da13eeSmacallan## that the space means something, we add a space to the output as 18665d490d0Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 18765d490d0Smrg## to the object. Take care to not repeat it in the output. 188e4da13eeSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 189e4da13eeSmacallan## correctly. Breaking it into two sed invocations is a workaround. 19065d490d0Smrg sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 19165d490d0Smrg | sed -e 's/$/ :/' >> "$depfile" 192e4da13eeSmacallan rm -f "$tmpdepfile" 193e4da13eeSmacallan ;; 194e4da13eeSmacallan 195e4da13eeSmacallanhp) 196e4da13eeSmacallan # This case exists only to let depend.m4 do its work. It works by 197e4da13eeSmacallan # looking at the text of this script. This case will never be run, 198e4da13eeSmacallan # since it is checked for above. 199e4da13eeSmacallan exit 1 200e4da13eeSmacallan ;; 201e4da13eeSmacallan 202e4da13eeSmacallansgi) 203e4da13eeSmacallan if test "$libtool" = yes; then 204e4da13eeSmacallan "$@" "-Wp,-MDupdate,$tmpdepfile" 205e4da13eeSmacallan else 206e4da13eeSmacallan "$@" -MDupdate "$tmpdepfile" 207e4da13eeSmacallan fi 208e4da13eeSmacallan stat=$? 209e4da13eeSmacallan if test $stat -eq 0; then : 210e4da13eeSmacallan else 211e4da13eeSmacallan rm -f "$tmpdepfile" 212e4da13eeSmacallan exit $stat 213e4da13eeSmacallan fi 214e4da13eeSmacallan rm -f "$depfile" 215e4da13eeSmacallan 216e4da13eeSmacallan if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 217e4da13eeSmacallan echo "$object : \\" > "$depfile" 218e4da13eeSmacallan 219e4da13eeSmacallan # Clip off the initial element (the dependent). Don't try to be 220e4da13eeSmacallan # clever and replace this with sed code, as IRIX sed won't handle 221e4da13eeSmacallan # lines with more than a fixed number of characters (4096 in 222e4da13eeSmacallan # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 22365d490d0Smrg # the IRIX cc adds comments like '#:fec' to the end of the 224e4da13eeSmacallan # dependency line. 22565d490d0Smrg tr ' ' "$nl" < "$tmpdepfile" \ 226e4da13eeSmacallan | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ 22765d490d0Smrg tr "$nl" ' ' >> "$depfile" 22865d490d0Smrg echo >> "$depfile" 229e4da13eeSmacallan 230e4da13eeSmacallan # The second pass generates a dummy entry for each header file. 23165d490d0Smrg tr ' ' "$nl" < "$tmpdepfile" \ 232e4da13eeSmacallan | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 23365d490d0Smrg >> "$depfile" 234e4da13eeSmacallan else 235e4da13eeSmacallan # The sourcefile does not contain any dependencies, so just 236e4da13eeSmacallan # store a dummy comment line, to avoid errors with the Makefile 237e4da13eeSmacallan # "include basename.Plo" scheme. 238e4da13eeSmacallan echo "#dummy" > "$depfile" 239e4da13eeSmacallan fi 240e4da13eeSmacallan rm -f "$tmpdepfile" 241e4da13eeSmacallan ;; 242e4da13eeSmacallan 24365d490d0Smrgxlc) 24465d490d0Smrg # This case exists only to let depend.m4 do its work. It works by 24565d490d0Smrg # looking at the text of this script. This case will never be run, 24665d490d0Smrg # since it is checked for above. 24765d490d0Smrg exit 1 24865d490d0Smrg ;; 24965d490d0Smrg 250e4da13eeSmacallanaix) 251e4da13eeSmacallan # The C for AIX Compiler uses -M and outputs the dependencies 252e4da13eeSmacallan # in a .u file. In older versions, this file always lives in the 25365d490d0Smrg # current directory. Also, the AIX compiler puts '$object:' at the 254e4da13eeSmacallan # start of each line; $object doesn't have directory information. 255e4da13eeSmacallan # Version 6 uses the directory in both cases. 256e4da13eeSmacallan dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 257e4da13eeSmacallan test "x$dir" = "x$object" && dir= 258e4da13eeSmacallan base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 259e4da13eeSmacallan if test "$libtool" = yes; then 260e4da13eeSmacallan tmpdepfile1=$dir$base.u 261e4da13eeSmacallan tmpdepfile2=$base.u 262e4da13eeSmacallan tmpdepfile3=$dir.libs/$base.u 263e4da13eeSmacallan "$@" -Wc,-M 264e4da13eeSmacallan else 265e4da13eeSmacallan tmpdepfile1=$dir$base.u 266e4da13eeSmacallan tmpdepfile2=$dir$base.u 267e4da13eeSmacallan tmpdepfile3=$dir$base.u 268e4da13eeSmacallan "$@" -M 269e4da13eeSmacallan fi 270e4da13eeSmacallan stat=$? 271e4da13eeSmacallan 272e4da13eeSmacallan if test $stat -eq 0; then : 273e4da13eeSmacallan else 274e4da13eeSmacallan rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 275e4da13eeSmacallan exit $stat 276e4da13eeSmacallan fi 277e4da13eeSmacallan 278e4da13eeSmacallan for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 279e4da13eeSmacallan do 280e4da13eeSmacallan test -f "$tmpdepfile" && break 281e4da13eeSmacallan done 282e4da13eeSmacallan if test -f "$tmpdepfile"; then 28365d490d0Smrg # Each line is of the form 'foo.o: dependent.h'. 284e4da13eeSmacallan # Do two passes, one to just change these to 28565d490d0Smrg # '$object: dependent.h' and one to simply 'dependent.h:'. 286e4da13eeSmacallan sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 28765d490d0Smrg sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 288e4da13eeSmacallan else 289e4da13eeSmacallan # The sourcefile does not contain any dependencies, so just 290e4da13eeSmacallan # store a dummy comment line, to avoid errors with the Makefile 291e4da13eeSmacallan # "include basename.Plo" scheme. 292e4da13eeSmacallan echo "#dummy" > "$depfile" 293e4da13eeSmacallan fi 294e4da13eeSmacallan rm -f "$tmpdepfile" 295e4da13eeSmacallan ;; 296e4da13eeSmacallan 297e4da13eeSmacallanicc) 29865d490d0Smrg # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'. 29965d490d0Smrg # However on 30065d490d0Smrg # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c 301e4da13eeSmacallan # ICC 7.0 will fill foo.d with something like 302e4da13eeSmacallan # foo.o: sub/foo.c 303e4da13eeSmacallan # foo.o: sub/foo.h 30465d490d0Smrg # which is wrong. We want 305e4da13eeSmacallan # sub/foo.o: sub/foo.c 306e4da13eeSmacallan # sub/foo.o: sub/foo.h 307e4da13eeSmacallan # sub/foo.c: 308e4da13eeSmacallan # sub/foo.h: 309e4da13eeSmacallan # ICC 7.1 will output 310e4da13eeSmacallan # foo.o: sub/foo.c sub/foo.h 31165d490d0Smrg # and will wrap long lines using '\': 312e4da13eeSmacallan # foo.o: sub/foo.c ... \ 313e4da13eeSmacallan # sub/foo.h ... \ 314e4da13eeSmacallan # ... 31565d490d0Smrg # tcc 0.9.26 (FIXME still under development at the moment of writing) 31665d490d0Smrg # will emit a similar output, but also prepend the continuation lines 31765d490d0Smrg # with horizontal tabulation characters. 318e4da13eeSmacallan "$@" -MD -MF "$tmpdepfile" 319e4da13eeSmacallan stat=$? 320e4da13eeSmacallan if test $stat -eq 0; then : 321e4da13eeSmacallan else 322e4da13eeSmacallan rm -f "$tmpdepfile" 323e4da13eeSmacallan exit $stat 324e4da13eeSmacallan fi 325e4da13eeSmacallan rm -f "$depfile" 32665d490d0Smrg # Each line is of the form 'foo.o: dependent.h', 32765d490d0Smrg # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'. 32865d490d0Smrg # Do two passes, one to just change these to 32965d490d0Smrg # '$object: dependent.h' and one to simply 'dependent.h:'. 33065d490d0Smrg sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \ 33165d490d0Smrg < "$tmpdepfile" > "$depfile" 33265d490d0Smrg sed ' 33365d490d0Smrg s/[ '"$tab"'][ '"$tab"']*/ /g 33465d490d0Smrg s/^ *// 33565d490d0Smrg s/ *\\*$// 33665d490d0Smrg s/^[^:]*: *// 33765d490d0Smrg /^$/d 33865d490d0Smrg /:$/d 33965d490d0Smrg s/$/ :/ 34065d490d0Smrg ' < "$tmpdepfile" >> "$depfile" 34165d490d0Smrg rm -f "$tmpdepfile" 34265d490d0Smrg ;; 34365d490d0Smrg 34465d490d0Smrg## The order of this option in the case statement is important, since the 34565d490d0Smrg## shell code in configure will try each of these formats in the order 34665d490d0Smrg## listed in this file. A plain '-MD' option would be understood by many 34765d490d0Smrg## compilers, so we must ensure this comes after the gcc and icc options. 34865d490d0Smrgpgcc) 34965d490d0Smrg # Portland's C compiler understands '-MD'. 35065d490d0Smrg # Will always output deps to 'file.d' where file is the root name of the 35165d490d0Smrg # source file under compilation, even if file resides in a subdirectory. 35265d490d0Smrg # The object file name does not affect the name of the '.d' file. 35365d490d0Smrg # pgcc 10.2 will output 35465d490d0Smrg # foo.o: sub/foo.c sub/foo.h 35565d490d0Smrg # and will wrap long lines using '\' : 35665d490d0Smrg # foo.o: sub/foo.c ... \ 35765d490d0Smrg # sub/foo.h ... \ 35865d490d0Smrg # ... 35965d490d0Smrg dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 36065d490d0Smrg test "x$dir" = "x$object" && dir= 36165d490d0Smrg # Use the source, not the object, to determine the base name, since 36265d490d0Smrg # that's sadly what pgcc will do too. 36365d490d0Smrg base=`echo "$source" | sed -e 's|^.*/||' -e 's/\.[-_a-zA-Z0-9]*$//'` 36465d490d0Smrg tmpdepfile="$base.d" 36565d490d0Smrg 36665d490d0Smrg # For projects that build the same source file twice into different object 36765d490d0Smrg # files, the pgcc approach of using the *source* file root name can cause 36865d490d0Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 36965d490d0Smrg # the same $tmpdepfile. 37065d490d0Smrg lockdir="$base.d-lock" 37165d490d0Smrg trap "echo '$0: caught signal, cleaning up...' >&2; rm -rf $lockdir" 1 2 13 15 37265d490d0Smrg numtries=100 37365d490d0Smrg i=$numtries 37465d490d0Smrg while test $i -gt 0 ; do 37565d490d0Smrg # mkdir is a portable test-and-set. 37665d490d0Smrg if mkdir $lockdir 2>/dev/null; then 37765d490d0Smrg # This process acquired the lock. 37865d490d0Smrg "$@" -MD 37965d490d0Smrg stat=$? 38065d490d0Smrg # Release the lock. 38165d490d0Smrg rm -rf $lockdir 38265d490d0Smrg break 38365d490d0Smrg else 38465d490d0Smrg ## the lock is being held by a different process, 38565d490d0Smrg ## wait until the winning process is done or we timeout 38665d490d0Smrg while test -d $lockdir && test $i -gt 0; do 38765d490d0Smrg sleep 1 38865d490d0Smrg i=`expr $i - 1` 38965d490d0Smrg done 39065d490d0Smrg fi 39165d490d0Smrg i=`expr $i - 1` 39265d490d0Smrg done 39365d490d0Smrg trap - 1 2 13 15 39465d490d0Smrg if test $i -le 0; then 39565d490d0Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 39665d490d0Smrg echo "$0: check lockdir '$lockdir'" >&2 39765d490d0Smrg exit 1 39865d490d0Smrg fi 39965d490d0Smrg 40065d490d0Smrg if test $stat -ne 0; then 40165d490d0Smrg rm -f "$tmpdepfile" 40265d490d0Smrg exit $stat 40365d490d0Smrg fi 40465d490d0Smrg rm -f "$depfile" 405e4da13eeSmacallan # Each line is of the form `foo.o: dependent.h', 406e4da13eeSmacallan # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 407e4da13eeSmacallan # Do two passes, one to just change these to 408e4da13eeSmacallan # `$object: dependent.h' and one to simply `dependent.h:'. 409e4da13eeSmacallan sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 410e4da13eeSmacallan # Some versions of the HPUX 10.20 sed can't process this invocation 411e4da13eeSmacallan # correctly. Breaking it into two sed invocations is a workaround. 412e4da13eeSmacallan sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" | 413e4da13eeSmacallan sed -e 's/$/ :/' >> "$depfile" 414e4da13eeSmacallan rm -f "$tmpdepfile" 415e4da13eeSmacallan ;; 416e4da13eeSmacallan 417e4da13eeSmacallanhp2) 418e4da13eeSmacallan # The "hp" stanza above does not work with aCC (C++) and HP's ia64 419e4da13eeSmacallan # compilers, which have integrated preprocessors. The correct option 420e4da13eeSmacallan # to use with these is +Maked; it writes dependencies to a file named 421e4da13eeSmacallan # 'foo.d', which lands next to the object file, wherever that 422e4da13eeSmacallan # happens to be. 423e4da13eeSmacallan # Much of this is similar to the tru64 case; see comments there. 424e4da13eeSmacallan dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 425e4da13eeSmacallan test "x$dir" = "x$object" && dir= 426e4da13eeSmacallan base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 427e4da13eeSmacallan if test "$libtool" = yes; then 428e4da13eeSmacallan tmpdepfile1=$dir$base.d 429e4da13eeSmacallan tmpdepfile2=$dir.libs/$base.d 430e4da13eeSmacallan "$@" -Wc,+Maked 431e4da13eeSmacallan else 432e4da13eeSmacallan tmpdepfile1=$dir$base.d 433e4da13eeSmacallan tmpdepfile2=$dir$base.d 434e4da13eeSmacallan "$@" +Maked 435e4da13eeSmacallan fi 436e4da13eeSmacallan stat=$? 437e4da13eeSmacallan if test $stat -eq 0; then : 438e4da13eeSmacallan else 439e4da13eeSmacallan rm -f "$tmpdepfile1" "$tmpdepfile2" 440e4da13eeSmacallan exit $stat 441e4da13eeSmacallan fi 442e4da13eeSmacallan 443e4da13eeSmacallan for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 444e4da13eeSmacallan do 445e4da13eeSmacallan test -f "$tmpdepfile" && break 446e4da13eeSmacallan done 447e4da13eeSmacallan if test -f "$tmpdepfile"; then 448e4da13eeSmacallan sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile" 44965d490d0Smrg # Add 'dependent.h:' lines. 45065d490d0Smrg sed -ne '2,${ 45165d490d0Smrg s/^ *// 45265d490d0Smrg s/ \\*$// 45365d490d0Smrg s/$/:/ 45465d490d0Smrg p 45565d490d0Smrg }' "$tmpdepfile" >> "$depfile" 456e4da13eeSmacallan else 457e4da13eeSmacallan echo "#dummy" > "$depfile" 458e4da13eeSmacallan fi 459e4da13eeSmacallan rm -f "$tmpdepfile" "$tmpdepfile2" 460e4da13eeSmacallan ;; 461e4da13eeSmacallan 462e4da13eeSmacallantru64) 463e4da13eeSmacallan # The Tru64 compiler uses -MD to generate dependencies as a side 46465d490d0Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 465e4da13eeSmacallan # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 46665d490d0Smrg # dependencies in 'foo.d' instead, so we check for that too. 467e4da13eeSmacallan # Subdirectories are respected. 468e4da13eeSmacallan dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 469e4da13eeSmacallan test "x$dir" = "x$object" && dir= 470e4da13eeSmacallan base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 471e4da13eeSmacallan 472e4da13eeSmacallan if test "$libtool" = yes; then 473e4da13eeSmacallan # With Tru64 cc, shared objects can also be used to make a 474e4da13eeSmacallan # static library. This mechanism is used in libtool 1.4 series to 475e4da13eeSmacallan # handle both shared and static libraries in a single compilation. 476e4da13eeSmacallan # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. 477e4da13eeSmacallan # 478e4da13eeSmacallan # With libtool 1.5 this exception was removed, and libtool now 479e4da13eeSmacallan # generates 2 separate objects for the 2 libraries. These two 480e4da13eeSmacallan # compilations output dependencies in $dir.libs/$base.o.d and 481e4da13eeSmacallan # in $dir$base.o.d. We have to check for both files, because 482e4da13eeSmacallan # one of the two compilations can be disabled. We should prefer 483e4da13eeSmacallan # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 484e4da13eeSmacallan # automatically cleaned when .libs/ is deleted, while ignoring 485e4da13eeSmacallan # the former would cause a distcleancheck panic. 486e4da13eeSmacallan tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 487e4da13eeSmacallan tmpdepfile2=$dir$base.o.d # libtool 1.5 488e4da13eeSmacallan tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 489e4da13eeSmacallan tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 490e4da13eeSmacallan "$@" -Wc,-MD 491e4da13eeSmacallan else 492e4da13eeSmacallan tmpdepfile1=$dir$base.o.d 493e4da13eeSmacallan tmpdepfile2=$dir$base.d 494e4da13eeSmacallan tmpdepfile3=$dir$base.d 495e4da13eeSmacallan tmpdepfile4=$dir$base.d 496e4da13eeSmacallan "$@" -MD 497e4da13eeSmacallan fi 498e4da13eeSmacallan 499e4da13eeSmacallan stat=$? 500e4da13eeSmacallan if test $stat -eq 0; then : 501e4da13eeSmacallan else 502e4da13eeSmacallan rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 503e4da13eeSmacallan exit $stat 504e4da13eeSmacallan fi 505e4da13eeSmacallan 506e4da13eeSmacallan for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 507e4da13eeSmacallan do 508e4da13eeSmacallan test -f "$tmpdepfile" && break 509e4da13eeSmacallan done 510e4da13eeSmacallan if test -f "$tmpdepfile"; then 511e4da13eeSmacallan sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 51265d490d0Smrg sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 513e4da13eeSmacallan else 514e4da13eeSmacallan echo "#dummy" > "$depfile" 515e4da13eeSmacallan fi 516e4da13eeSmacallan rm -f "$tmpdepfile" 517e4da13eeSmacallan ;; 518e4da13eeSmacallan 51965d490d0Smrgmsvc7) 52065d490d0Smrg if test "$libtool" = yes; then 52165d490d0Smrg showIncludes=-Wc,-showIncludes 52265d490d0Smrg else 52365d490d0Smrg showIncludes=-showIncludes 52465d490d0Smrg fi 52565d490d0Smrg "$@" $showIncludes > "$tmpdepfile" 52665d490d0Smrg stat=$? 52765d490d0Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52865d490d0Smrg if test "$stat" = 0; then : 52965d490d0Smrg else 53065d490d0Smrg rm -f "$tmpdepfile" 53165d490d0Smrg exit $stat 53265d490d0Smrg fi 53365d490d0Smrg rm -f "$depfile" 53465d490d0Smrg echo "$object : \\" > "$depfile" 53565d490d0Smrg # The first sed program below extracts the file names and escapes 53665d490d0Smrg # backslashes for cygpath. The second sed program outputs the file 53765d490d0Smrg # name when reading, but also accumulates all include files in the 53865d490d0Smrg # hold buffer in order to output them again at the end. This only 53965d490d0Smrg # works with sed implementations that can handle large buffers. 54065d490d0Smrg sed < "$tmpdepfile" -n ' 54165d490d0Smrg/^Note: including file: *\(.*\)/ { 54265d490d0Smrg s//\1/ 54365d490d0Smrg s/\\/\\\\/g 54465d490d0Smrg p 54565d490d0Smrg}' | $cygpath_u | sort -u | sed -n ' 54665d490d0Smrgs/ /\\ /g 54765d490d0Smrgs/\(.*\)/'"$tab"'\1 \\/p 54865d490d0Smrgs/.\(.*\) \\/\1:/ 54965d490d0SmrgH 55065d490d0Smrg$ { 55165d490d0Smrg s/.*/'"$tab"'/ 55265d490d0Smrg G 55365d490d0Smrg p 55465d490d0Smrg}' >> "$depfile" 55565d490d0Smrg rm -f "$tmpdepfile" 55665d490d0Smrg ;; 55765d490d0Smrg 55865d490d0Smrgmsvc7msys) 55965d490d0Smrg # This case exists only to let depend.m4 do its work. It works by 56065d490d0Smrg # looking at the text of this script. This case will never be run, 56165d490d0Smrg # since it is checked for above. 56265d490d0Smrg exit 1 56365d490d0Smrg ;; 56465d490d0Smrg 565e4da13eeSmacallan#nosideeffect) 566e4da13eeSmacallan # This comment above is used by automake to tell side-effect 567e4da13eeSmacallan # dependency tracking mechanisms from slower ones. 568e4da13eeSmacallan 569e4da13eeSmacallandashmstdout) 570e4da13eeSmacallan # Important note: in order to support this mode, a compiler *must* 571e4da13eeSmacallan # always write the preprocessed file to stdout, regardless of -o. 572e4da13eeSmacallan "$@" || exit $? 573e4da13eeSmacallan 574e4da13eeSmacallan # Remove the call to Libtool. 575e4da13eeSmacallan if test "$libtool" = yes; then 57665d490d0Smrg while test "X$1" != 'X--mode=compile'; do 577e4da13eeSmacallan shift 578e4da13eeSmacallan done 579e4da13eeSmacallan shift 580e4da13eeSmacallan fi 581e4da13eeSmacallan 58265d490d0Smrg # Remove '-o $object'. 583e4da13eeSmacallan IFS=" " 584e4da13eeSmacallan for arg 585e4da13eeSmacallan do 586e4da13eeSmacallan case $arg in 587e4da13eeSmacallan -o) 588e4da13eeSmacallan shift 589e4da13eeSmacallan ;; 590e4da13eeSmacallan $object) 591e4da13eeSmacallan shift 592e4da13eeSmacallan ;; 593e4da13eeSmacallan *) 594e4da13eeSmacallan set fnord "$@" "$arg" 595e4da13eeSmacallan shift # fnord 596e4da13eeSmacallan shift # $arg 597e4da13eeSmacallan ;; 598e4da13eeSmacallan esac 599e4da13eeSmacallan done 600e4da13eeSmacallan 601e4da13eeSmacallan test -z "$dashmflag" && dashmflag=-M 60265d490d0Smrg # Require at least two characters before searching for ':' 603e4da13eeSmacallan # in the target name. This is to cope with DOS-style filenames: 60465d490d0Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 605e4da13eeSmacallan "$@" $dashmflag | 60665d490d0Smrg sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile" 607e4da13eeSmacallan rm -f "$depfile" 608e4da13eeSmacallan cat < "$tmpdepfile" > "$depfile" 60965d490d0Smrg tr ' ' "$nl" < "$tmpdepfile" | \ 610e4da13eeSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 611e4da13eeSmacallan## correctly. Breaking it into two sed invocations is a workaround. 612e4da13eeSmacallan sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 613e4da13eeSmacallan rm -f "$tmpdepfile" 614e4da13eeSmacallan ;; 615e4da13eeSmacallan 616e4da13eeSmacallandashXmstdout) 617e4da13eeSmacallan # This case only exists to satisfy depend.m4. It is never actually 618e4da13eeSmacallan # run, as this mode is specially recognized in the preamble. 619e4da13eeSmacallan exit 1 620e4da13eeSmacallan ;; 621e4da13eeSmacallan 622e4da13eeSmacallanmakedepend) 623e4da13eeSmacallan "$@" || exit $? 624e4da13eeSmacallan # Remove any Libtool call 625e4da13eeSmacallan if test "$libtool" = yes; then 62665d490d0Smrg while test "X$1" != 'X--mode=compile'; do 627e4da13eeSmacallan shift 628e4da13eeSmacallan done 629e4da13eeSmacallan shift 630e4da13eeSmacallan fi 631e4da13eeSmacallan # X makedepend 632e4da13eeSmacallan shift 63365d490d0Smrg cleared=no eat=no 63465d490d0Smrg for arg 63565d490d0Smrg do 636e4da13eeSmacallan case $cleared in 637e4da13eeSmacallan no) 638e4da13eeSmacallan set ""; shift 639e4da13eeSmacallan cleared=yes ;; 640e4da13eeSmacallan esac 64165d490d0Smrg if test $eat = yes; then 64265d490d0Smrg eat=no 64365d490d0Smrg continue 64465d490d0Smrg fi 645e4da13eeSmacallan case "$arg" in 646e4da13eeSmacallan -D*|-I*) 647e4da13eeSmacallan set fnord "$@" "$arg"; shift ;; 648e4da13eeSmacallan # Strip any option that makedepend may not understand. Remove 649e4da13eeSmacallan # the object too, otherwise makedepend will parse it as a source file. 65065d490d0Smrg -arch) 65165d490d0Smrg eat=yes ;; 652e4da13eeSmacallan -*|$object) 653e4da13eeSmacallan ;; 654e4da13eeSmacallan *) 655e4da13eeSmacallan set fnord "$@" "$arg"; shift ;; 656e4da13eeSmacallan esac 657e4da13eeSmacallan done 65865d490d0Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 659e4da13eeSmacallan touch "$tmpdepfile" 660e4da13eeSmacallan ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 661e4da13eeSmacallan rm -f "$depfile" 66265d490d0Smrg # makedepend may prepend the VPATH from the source file name to the object. 66365d490d0Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66465d490d0Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66565d490d0Smrg sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \ 666e4da13eeSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 667e4da13eeSmacallan## correctly. Breaking it into two sed invocations is a workaround. 668e4da13eeSmacallan sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 669e4da13eeSmacallan rm -f "$tmpdepfile" "$tmpdepfile".bak 670e4da13eeSmacallan ;; 671e4da13eeSmacallan 672e4da13eeSmacallancpp) 673e4da13eeSmacallan # Important note: in order to support this mode, a compiler *must* 674e4da13eeSmacallan # always write the preprocessed file to stdout. 675e4da13eeSmacallan "$@" || exit $? 676e4da13eeSmacallan 677e4da13eeSmacallan # Remove the call to Libtool. 678e4da13eeSmacallan if test "$libtool" = yes; then 67965d490d0Smrg while test "X$1" != 'X--mode=compile'; do 680e4da13eeSmacallan shift 681e4da13eeSmacallan done 682e4da13eeSmacallan shift 683e4da13eeSmacallan fi 684e4da13eeSmacallan 68565d490d0Smrg # Remove '-o $object'. 686e4da13eeSmacallan IFS=" " 687e4da13eeSmacallan for arg 688e4da13eeSmacallan do 689e4da13eeSmacallan case $arg in 690e4da13eeSmacallan -o) 691e4da13eeSmacallan shift 692e4da13eeSmacallan ;; 693e4da13eeSmacallan $object) 694e4da13eeSmacallan shift 695e4da13eeSmacallan ;; 696e4da13eeSmacallan *) 697e4da13eeSmacallan set fnord "$@" "$arg" 698e4da13eeSmacallan shift # fnord 699e4da13eeSmacallan shift # $arg 700e4da13eeSmacallan ;; 701e4da13eeSmacallan esac 702e4da13eeSmacallan done 703e4da13eeSmacallan 704e4da13eeSmacallan "$@" -E | 705e4da13eeSmacallan sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 706e4da13eeSmacallan -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | 707e4da13eeSmacallan sed '$ s: \\$::' > "$tmpdepfile" 708e4da13eeSmacallan rm -f "$depfile" 709e4da13eeSmacallan echo "$object : \\" > "$depfile" 710e4da13eeSmacallan cat < "$tmpdepfile" >> "$depfile" 711e4da13eeSmacallan sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 712e4da13eeSmacallan rm -f "$tmpdepfile" 713e4da13eeSmacallan ;; 714e4da13eeSmacallan 715e4da13eeSmacallanmsvisualcpp) 716e4da13eeSmacallan # Important note: in order to support this mode, a compiler *must* 71765d490d0Smrg # always write the preprocessed file to stdout. 718e4da13eeSmacallan "$@" || exit $? 71965d490d0Smrg 72065d490d0Smrg # Remove the call to Libtool. 72165d490d0Smrg if test "$libtool" = yes; then 72265d490d0Smrg while test "X$1" != 'X--mode=compile'; do 72365d490d0Smrg shift 72465d490d0Smrg done 72565d490d0Smrg shift 72665d490d0Smrg fi 72765d490d0Smrg 728e4da13eeSmacallan IFS=" " 729e4da13eeSmacallan for arg 730e4da13eeSmacallan do 731e4da13eeSmacallan case "$arg" in 73265d490d0Smrg -o) 73365d490d0Smrg shift 73465d490d0Smrg ;; 73565d490d0Smrg $object) 73665d490d0Smrg shift 73765d490d0Smrg ;; 738e4da13eeSmacallan "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 739e4da13eeSmacallan set fnord "$@" 740e4da13eeSmacallan shift 741e4da13eeSmacallan shift 742e4da13eeSmacallan ;; 743e4da13eeSmacallan *) 744e4da13eeSmacallan set fnord "$@" "$arg" 745e4da13eeSmacallan shift 746e4da13eeSmacallan shift 747e4da13eeSmacallan ;; 748e4da13eeSmacallan esac 749e4da13eeSmacallan done 75065d490d0Smrg "$@" -E 2>/dev/null | 75165d490d0Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 752e4da13eeSmacallan rm -f "$depfile" 753e4da13eeSmacallan echo "$object : \\" > "$depfile" 75465d490d0Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75565d490d0Smrg echo "$tab" >> "$depfile" 75665d490d0Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 757e4da13eeSmacallan rm -f "$tmpdepfile" 758e4da13eeSmacallan ;; 759e4da13eeSmacallan 76065d490d0Smrgmsvcmsys) 76165d490d0Smrg # This case exists only to let depend.m4 do its work. It works by 76265d490d0Smrg # looking at the text of this script. This case will never be run, 76365d490d0Smrg # since it is checked for above. 76465d490d0Smrg exit 1 76565d490d0Smrg ;; 76665d490d0Smrg 767e4da13eeSmacallannone) 768e4da13eeSmacallan exec "$@" 769e4da13eeSmacallan ;; 770e4da13eeSmacallan 771e4da13eeSmacallan*) 772e4da13eeSmacallan echo "Unknown depmode $depmode" 1>&2 773e4da13eeSmacallan exit 1 774e4da13eeSmacallan ;; 775e4da13eeSmacallanesac 776e4da13eeSmacallan 777e4da13eeSmacallanexit 0 778e4da13eeSmacallan 779e4da13eeSmacallan# Local Variables: 780e4da13eeSmacallan# mode: shell-script 781e4da13eeSmacallan# sh-indentation: 2 782e4da13eeSmacallan# eval: (add-hook 'write-file-hooks 'time-stamp) 783e4da13eeSmacallan# time-stamp-start: "scriptversion=" 784e4da13eeSmacallan# time-stamp-format: "%:y-%02m-%02d.%02H" 78565d490d0Smrg# time-stamp-time-zone: "UTC" 78665d490d0Smrg# time-stamp-end: "; # UTC" 787e4da13eeSmacallan# End: 788