123dfcd74Spooka#! /bin/sh 223dfcd74Spooka# depcomp - compile a program generating dependencies as side-effects 323dfcd74Spooka 423dfcd74Spookascriptversion=2013-05-30.07; # UTC 523dfcd74Spooka 623dfcd74Spooka# Copyright (C) 1999-2013 Free Software Foundation, Inc. 723dfcd74Spooka 823dfcd74Spooka# This program is free software; you can redistribute it and/or modify 923dfcd74Spooka# it under the terms of the GNU General Public License as published by 1023dfcd74Spooka# the Free Software Foundation; either version 2, or (at your option) 1123dfcd74Spooka# any later version. 1223dfcd74Spooka 1323dfcd74Spooka# This program is distributed in the hope that it will be useful, 1423dfcd74Spooka# but WITHOUT ANY WARRANTY; without even the implied warranty of 1523dfcd74Spooka# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1623dfcd74Spooka# GNU General Public License for more details. 1723dfcd74Spooka 1823dfcd74Spooka# You should have received a copy of the GNU General Public License 1923dfcd74Spooka# along with this program. If not, see <http://www.gnu.org/licenses/>. 2023dfcd74Spooka 2123dfcd74Spooka# As a special exception to the GNU General Public License, if you 2223dfcd74Spooka# distribute this file as part of a program that contains a 2323dfcd74Spooka# configuration script generated by Autoconf, you may include it under 2423dfcd74Spooka# the same distribution terms that you use for the rest of that program. 2523dfcd74Spooka 2623dfcd74Spooka# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2723dfcd74Spooka 2823dfcd74Spookacase $1 in 2923dfcd74Spooka '') 3023dfcd74Spooka echo "$0: No command. Try '$0 --help' for more information." 1>&2 3123dfcd74Spooka exit 1; 3223dfcd74Spooka ;; 3323dfcd74Spooka -h | --h*) 3423dfcd74Spooka cat <<\EOF 3523dfcd74SpookaUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3623dfcd74Spooka 3723dfcd74SpookaRun PROGRAMS ARGS to compile a file, generating dependencies 3823dfcd74Spookaas side-effects. 3923dfcd74Spooka 4023dfcd74SpookaEnvironment variables: 4123dfcd74Spooka depmode Dependency tracking mode. 4223dfcd74Spooka source Source file read by 'PROGRAMS ARGS'. 4323dfcd74Spooka object Object file output by 'PROGRAMS ARGS'. 4423dfcd74Spooka DEPDIR directory where to store dependencies. 4523dfcd74Spooka depfile Dependency file to output. 4623dfcd74Spooka tmpdepfile Temporary file to use when outputting dependencies. 4723dfcd74Spooka libtool Whether libtool is used (yes/no). 4823dfcd74Spooka 4923dfcd74SpookaReport bugs to <bug-automake@gnu.org>. 5023dfcd74SpookaEOF 5123dfcd74Spooka exit $? 5223dfcd74Spooka ;; 5323dfcd74Spooka -v | --v*) 5423dfcd74Spooka echo "depcomp $scriptversion" 5523dfcd74Spooka exit $? 5623dfcd74Spooka ;; 5723dfcd74Spookaesac 5823dfcd74Spooka 5923dfcd74Spooka# Get the directory component of the given path, and save it in the 6023dfcd74Spooka# global variables '$dir'. Note that this directory component will 6123dfcd74Spooka# be either empty or ending with a '/' character. This is deliberate. 6223dfcd74Spookaset_dir_from () 6323dfcd74Spooka{ 6423dfcd74Spooka case $1 in 6523dfcd74Spooka */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6623dfcd74Spooka *) dir=;; 6723dfcd74Spooka esac 6823dfcd74Spooka} 6923dfcd74Spooka 7023dfcd74Spooka# Get the suffix-stripped basename of the given path, and save it the 7123dfcd74Spooka# global variable '$base'. 7223dfcd74Spookaset_base_from () 7323dfcd74Spooka{ 7423dfcd74Spooka base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7523dfcd74Spooka} 7623dfcd74Spooka 7723dfcd74Spooka# If no dependency file was actually created by the compiler invocation, 7823dfcd74Spooka# we still have to create a dummy depfile, to avoid errors with the 7923dfcd74Spooka# Makefile "include basename.Plo" scheme. 8023dfcd74Spookamake_dummy_depfile () 8123dfcd74Spooka{ 8223dfcd74Spooka echo "#dummy" > "$depfile" 8323dfcd74Spooka} 8423dfcd74Spooka 8523dfcd74Spooka# Factor out some common post-processing of the generated depfile. 8623dfcd74Spooka# Requires the auxiliary global variable '$tmpdepfile' to be set. 8723dfcd74Spookaaix_post_process_depfile () 8823dfcd74Spooka{ 8923dfcd74Spooka # If the compiler actually managed to produce a dependency file, 9023dfcd74Spooka # post-process it. 9123dfcd74Spooka if test -f "$tmpdepfile"; then 9223dfcd74Spooka # Each line is of the form 'foo.o: dependency.h'. 9323dfcd74Spooka # Do two passes, one to just change these to 9423dfcd74Spooka # $object: dependency.h 9523dfcd74Spooka # and one to simply output 9623dfcd74Spooka # dependency.h: 9723dfcd74Spooka # which is needed to avoid the deleted-header problem. 9823dfcd74Spooka { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9923dfcd74Spooka sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10023dfcd74Spooka } > "$depfile" 10123dfcd74Spooka rm -f "$tmpdepfile" 10223dfcd74Spooka else 10323dfcd74Spooka make_dummy_depfile 10423dfcd74Spooka fi 10523dfcd74Spooka} 10623dfcd74Spooka 10723dfcd74Spooka# A tabulation character. 10823dfcd74Spookatab=' ' 10923dfcd74Spooka# A newline character. 11023dfcd74Spookanl=' 11123dfcd74Spooka' 11223dfcd74Spooka# Character ranges might be problematic outside the C locale. 11323dfcd74Spooka# These definitions help. 11423dfcd74Spookaupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11523dfcd74Spookalower=abcdefghijklmnopqrstuvwxyz 11623dfcd74Spookadigits=0123456789 11723dfcd74Spookaalpha=${upper}${lower} 11823dfcd74Spooka 11923dfcd74Spookaif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12023dfcd74Spooka echo "depcomp: Variables source, object and depmode must be set" 1>&2 12123dfcd74Spooka exit 1 12223dfcd74Spookafi 12323dfcd74Spooka 12423dfcd74Spooka# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12523dfcd74Spookadepfile=${depfile-`echo "$object" | 12623dfcd74Spooka sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12723dfcd74Spookatmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12823dfcd74Spooka 12923dfcd74Spookarm -f "$tmpdepfile" 13023dfcd74Spooka 13123dfcd74Spooka# Avoid interferences from the environment. 13223dfcd74Spookagccflag= dashmflag= 13323dfcd74Spooka 13423dfcd74Spooka# Some modes work just like other modes, but use different flags. We 13523dfcd74Spooka# parameterize here, but still list the modes in the big case below, 13623dfcd74Spooka# to make depend.m4 easier to write. Note that we *cannot* use a case 13723dfcd74Spooka# here, because this file can only contain one case statement. 13823dfcd74Spookaif test "$depmode" = hp; then 13923dfcd74Spooka # HP compiler uses -M and no extra arg. 14023dfcd74Spooka gccflag=-M 14123dfcd74Spooka depmode=gcc 14223dfcd74Spookafi 14323dfcd74Spooka 14423dfcd74Spookaif test "$depmode" = dashXmstdout; then 14523dfcd74Spooka # This is just like dashmstdout with a different argument. 14623dfcd74Spooka dashmflag=-xM 14723dfcd74Spooka depmode=dashmstdout 14823dfcd74Spookafi 14923dfcd74Spooka 15023dfcd74Spookacygpath_u="cygpath -u -f -" 15123dfcd74Spookaif test "$depmode" = msvcmsys; then 15223dfcd74Spooka # This is just like msvisualcpp but w/o cygpath translation. 15323dfcd74Spooka # Just convert the backslash-escaped backslashes to single forward 15423dfcd74Spooka # slashes to satisfy depend.m4 15523dfcd74Spooka cygpath_u='sed s,\\\\,/,g' 15623dfcd74Spooka depmode=msvisualcpp 15723dfcd74Spookafi 15823dfcd74Spooka 15923dfcd74Spookaif test "$depmode" = msvc7msys; then 16023dfcd74Spooka # This is just like msvc7 but w/o cygpath translation. 16123dfcd74Spooka # Just convert the backslash-escaped backslashes to single forward 16223dfcd74Spooka # slashes to satisfy depend.m4 16323dfcd74Spooka cygpath_u='sed s,\\\\,/,g' 16423dfcd74Spooka depmode=msvc7 16523dfcd74Spookafi 16623dfcd74Spooka 16723dfcd74Spookaif test "$depmode" = xlc; then 16823dfcd74Spooka # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16923dfcd74Spooka gccflag=-qmakedep=gcc,-MF 17023dfcd74Spooka depmode=gcc 17123dfcd74Spookafi 17223dfcd74Spooka 17323dfcd74Spookacase "$depmode" in 17423dfcd74Spookagcc3) 17523dfcd74Spooka## gcc 3 implements dependency tracking that does exactly what 17623dfcd74Spooka## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17723dfcd74Spooka## it if -MD -MP comes after the -MF stuff. Hmm. 17823dfcd74Spooka## Unfortunately, FreeBSD c89 acceptance of flags depends upon 17923dfcd74Spooka## the command line argument order; so add the flags where they 18023dfcd74Spooka## appear in depend2.am. Note that the slowdown incurred here 18123dfcd74Spooka## affects only configure: in makefiles, %FASTDEP% shortcuts this. 18223dfcd74Spooka for arg 18323dfcd74Spooka do 18423dfcd74Spooka case $arg in 18523dfcd74Spooka -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 18623dfcd74Spooka *) set fnord "$@" "$arg" ;; 18723dfcd74Spooka esac 18823dfcd74Spooka shift # fnord 18923dfcd74Spooka shift # $arg 19023dfcd74Spooka done 19123dfcd74Spooka "$@" 19223dfcd74Spooka stat=$? 19323dfcd74Spooka if test $stat -ne 0; then 19423dfcd74Spooka rm -f "$tmpdepfile" 19523dfcd74Spooka exit $stat 19623dfcd74Spooka fi 19723dfcd74Spooka mv "$tmpdepfile" "$depfile" 19823dfcd74Spooka ;; 19923dfcd74Spooka 20023dfcd74Spookagcc) 201*11688febSandvar## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 20223dfcd74Spooka## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20323dfcd74Spooka## (see the conditional assignment to $gccflag above). 20423dfcd74Spooka## There are various ways to get dependency output from gcc. Here's 20523dfcd74Spooka## why we pick this rather obscure method: 20623dfcd74Spooka## - Don't want to use -MD because we'd like the dependencies to end 20723dfcd74Spooka## up in a subdir. Having to rename by hand is ugly. 20823dfcd74Spooka## (We might end up doing this anyway to support other compilers.) 20923dfcd74Spooka## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21023dfcd74Spooka## -MM, not -M (despite what the docs say). Also, it might not be 21123dfcd74Spooka## supported by the other compilers which use the 'gcc' depmode. 21223dfcd74Spooka## - Using -M directly means running the compiler twice (even worse 21323dfcd74Spooka## than renaming). 21423dfcd74Spooka if test -z "$gccflag"; then 21523dfcd74Spooka gccflag=-MD, 21623dfcd74Spooka fi 21723dfcd74Spooka "$@" -Wp,"$gccflag$tmpdepfile" 21823dfcd74Spooka stat=$? 21923dfcd74Spooka if test $stat -ne 0; then 22023dfcd74Spooka rm -f "$tmpdepfile" 22123dfcd74Spooka exit $stat 22223dfcd74Spooka fi 22323dfcd74Spooka rm -f "$depfile" 22423dfcd74Spooka echo "$object : \\" > "$depfile" 22523dfcd74Spooka # The second -e expression handles DOS-style file names with drive 22623dfcd74Spooka # letters. 22723dfcd74Spooka sed -e 's/^[^:]*: / /' \ 22823dfcd74Spooka -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22923dfcd74Spooka## This next piece of magic avoids the "deleted header file" problem. 23023dfcd74Spooka## The problem is that when a header file which appears in a .P file 23123dfcd74Spooka## is deleted, the dependency causes make to die (because there is 23223dfcd74Spooka## typically no way to rebuild the header). We avoid this by adding 23323dfcd74Spooka## dummy dependencies for each header file. Too bad gcc doesn't do 23423dfcd74Spooka## this for us directly. 23523dfcd74Spooka## Some versions of gcc put a space before the ':'. On the theory 23623dfcd74Spooka## that the space means something, we add a space to the output as 23723dfcd74Spooka## well. hp depmode also adds that space, but also prefixes the VPATH 23823dfcd74Spooka## to the object. Take care to not repeat it in the output. 23923dfcd74Spooka## Some versions of the HPUX 10.20 sed can't process this invocation 24023dfcd74Spooka## correctly. Breaking it into two sed invocations is a workaround. 24123dfcd74Spooka tr ' ' "$nl" < "$tmpdepfile" \ 24223dfcd74Spooka | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24323dfcd74Spooka | sed -e 's/$/ :/' >> "$depfile" 24423dfcd74Spooka rm -f "$tmpdepfile" 24523dfcd74Spooka ;; 24623dfcd74Spooka 24723dfcd74Spookahp) 24823dfcd74Spooka # This case exists only to let depend.m4 do its work. It works by 24923dfcd74Spooka # looking at the text of this script. This case will never be run, 25023dfcd74Spooka # since it is checked for above. 25123dfcd74Spooka exit 1 25223dfcd74Spooka ;; 25323dfcd74Spooka 25423dfcd74Spookasgi) 25523dfcd74Spooka if test "$libtool" = yes; then 25623dfcd74Spooka "$@" "-Wp,-MDupdate,$tmpdepfile" 25723dfcd74Spooka else 25823dfcd74Spooka "$@" -MDupdate "$tmpdepfile" 25923dfcd74Spooka fi 26023dfcd74Spooka stat=$? 26123dfcd74Spooka if test $stat -ne 0; then 26223dfcd74Spooka rm -f "$tmpdepfile" 26323dfcd74Spooka exit $stat 26423dfcd74Spooka fi 26523dfcd74Spooka rm -f "$depfile" 26623dfcd74Spooka 26723dfcd74Spooka if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26823dfcd74Spooka echo "$object : \\" > "$depfile" 26923dfcd74Spooka # Clip off the initial element (the dependent). Don't try to be 27023dfcd74Spooka # clever and replace this with sed code, as IRIX sed won't handle 27123dfcd74Spooka # lines with more than a fixed number of characters (4096 in 27223dfcd74Spooka # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27323dfcd74Spooka # the IRIX cc adds comments like '#:fec' to the end of the 27423dfcd74Spooka # dependency line. 27523dfcd74Spooka tr ' ' "$nl" < "$tmpdepfile" \ 27623dfcd74Spooka | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27723dfcd74Spooka | tr "$nl" ' ' >> "$depfile" 27823dfcd74Spooka echo >> "$depfile" 27923dfcd74Spooka # The second pass generates a dummy entry for each header file. 28023dfcd74Spooka tr ' ' "$nl" < "$tmpdepfile" \ 28123dfcd74Spooka | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28223dfcd74Spooka >> "$depfile" 28323dfcd74Spooka else 28423dfcd74Spooka make_dummy_depfile 28523dfcd74Spooka fi 28623dfcd74Spooka rm -f "$tmpdepfile" 28723dfcd74Spooka ;; 28823dfcd74Spooka 28923dfcd74Spookaxlc) 29023dfcd74Spooka # This case exists only to let depend.m4 do its work. It works by 29123dfcd74Spooka # looking at the text of this script. This case will never be run, 29223dfcd74Spooka # since it is checked for above. 29323dfcd74Spooka exit 1 29423dfcd74Spooka ;; 29523dfcd74Spooka 29623dfcd74Spookaaix) 29723dfcd74Spooka # The C for AIX Compiler uses -M and outputs the dependencies 29823dfcd74Spooka # in a .u file. In older versions, this file always lives in the 29923dfcd74Spooka # current directory. Also, the AIX compiler puts '$object:' at the 30023dfcd74Spooka # start of each line; $object doesn't have directory information. 30123dfcd74Spooka # Version 6 uses the directory in both cases. 30223dfcd74Spooka set_dir_from "$object" 30323dfcd74Spooka set_base_from "$object" 30423dfcd74Spooka if test "$libtool" = yes; then 30523dfcd74Spooka tmpdepfile1=$dir$base.u 30623dfcd74Spooka tmpdepfile2=$base.u 30723dfcd74Spooka tmpdepfile3=$dir.libs/$base.u 30823dfcd74Spooka "$@" -Wc,-M 30923dfcd74Spooka else 31023dfcd74Spooka tmpdepfile1=$dir$base.u 31123dfcd74Spooka tmpdepfile2=$dir$base.u 31223dfcd74Spooka tmpdepfile3=$dir$base.u 31323dfcd74Spooka "$@" -M 31423dfcd74Spooka fi 31523dfcd74Spooka stat=$? 31623dfcd74Spooka if test $stat -ne 0; then 31723dfcd74Spooka rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31823dfcd74Spooka exit $stat 31923dfcd74Spooka fi 32023dfcd74Spooka 32123dfcd74Spooka for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32223dfcd74Spooka do 32323dfcd74Spooka test -f "$tmpdepfile" && break 32423dfcd74Spooka done 32523dfcd74Spooka aix_post_process_depfile 32623dfcd74Spooka ;; 32723dfcd74Spooka 32823dfcd74Spookatcc) 32923dfcd74Spooka # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33023dfcd74Spooka # FIXME: That version still under development at the moment of writing. 33123dfcd74Spooka # Make that this statement remains true also for stable, released 33223dfcd74Spooka # versions. 33323dfcd74Spooka # It will wrap lines (doesn't matter whether long or short) with a 33423dfcd74Spooka # trailing '\', as in: 33523dfcd74Spooka # 33623dfcd74Spooka # foo.o : \ 33723dfcd74Spooka # foo.c \ 33823dfcd74Spooka # foo.h \ 33923dfcd74Spooka # 34023dfcd74Spooka # It will put a trailing '\' even on the last line, and will use leading 34123dfcd74Spooka # spaces rather than leading tabs (at least since its commit 0394caf7 34223dfcd74Spooka # "Emit spaces for -MD"). 34323dfcd74Spooka "$@" -MD -MF "$tmpdepfile" 34423dfcd74Spooka stat=$? 34523dfcd74Spooka if test $stat -ne 0; then 34623dfcd74Spooka rm -f "$tmpdepfile" 34723dfcd74Spooka exit $stat 34823dfcd74Spooka fi 34923dfcd74Spooka rm -f "$depfile" 35023dfcd74Spooka # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35123dfcd74Spooka # We have to change lines of the first kind to '$object: \'. 35223dfcd74Spooka sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35323dfcd74Spooka # And for each line of the second kind, we have to emit a 'dep.h:' 35423dfcd74Spooka # dummy dependency, to avoid the deleted-header problem. 35523dfcd74Spooka sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35623dfcd74Spooka rm -f "$tmpdepfile" 35723dfcd74Spooka ;; 35823dfcd74Spooka 35923dfcd74Spooka## The order of this option in the case statement is important, since the 36023dfcd74Spooka## shell code in configure will try each of these formats in the order 36123dfcd74Spooka## listed in this file. A plain '-MD' option would be understood by many 36223dfcd74Spooka## compilers, so we must ensure this comes after the gcc and icc options. 36323dfcd74Spookapgcc) 36423dfcd74Spooka # Portland's C compiler understands '-MD'. 36523dfcd74Spooka # Will always output deps to 'file.d' where file is the root name of the 36623dfcd74Spooka # source file under compilation, even if file resides in a subdirectory. 36723dfcd74Spooka # The object file name does not affect the name of the '.d' file. 36823dfcd74Spooka # pgcc 10.2 will output 36923dfcd74Spooka # foo.o: sub/foo.c sub/foo.h 37023dfcd74Spooka # and will wrap long lines using '\' : 37123dfcd74Spooka # foo.o: sub/foo.c ... \ 37223dfcd74Spooka # sub/foo.h ... \ 37323dfcd74Spooka # ... 37423dfcd74Spooka set_dir_from "$object" 37523dfcd74Spooka # Use the source, not the object, to determine the base name, since 37623dfcd74Spooka # that's sadly what pgcc will do too. 37723dfcd74Spooka set_base_from "$source" 37823dfcd74Spooka tmpdepfile=$base.d 37923dfcd74Spooka 38023dfcd74Spooka # For projects that build the same source file twice into different object 38123dfcd74Spooka # files, the pgcc approach of using the *source* file root name can cause 38223dfcd74Spooka # problems in parallel builds. Use a locking strategy to avoid stomping on 38323dfcd74Spooka # the same $tmpdepfile. 38423dfcd74Spooka lockdir=$base.d-lock 38523dfcd74Spooka trap " 38623dfcd74Spooka echo '$0: caught signal, cleaning up...' >&2 38723dfcd74Spooka rmdir '$lockdir' 38823dfcd74Spooka exit 1 38923dfcd74Spooka " 1 2 13 15 39023dfcd74Spooka numtries=100 39123dfcd74Spooka i=$numtries 39223dfcd74Spooka while test $i -gt 0; do 39323dfcd74Spooka # mkdir is a portable test-and-set. 39423dfcd74Spooka if mkdir "$lockdir" 2>/dev/null; then 39523dfcd74Spooka # This process acquired the lock. 39623dfcd74Spooka "$@" -MD 39723dfcd74Spooka stat=$? 39823dfcd74Spooka # Release the lock. 39923dfcd74Spooka rmdir "$lockdir" 40023dfcd74Spooka break 40123dfcd74Spooka else 40223dfcd74Spooka # If the lock is being held by a different process, wait 40323dfcd74Spooka # until the winning process is done or we timeout. 40423dfcd74Spooka while test -d "$lockdir" && test $i -gt 0; do 40523dfcd74Spooka sleep 1 40623dfcd74Spooka i=`expr $i - 1` 40723dfcd74Spooka done 40823dfcd74Spooka fi 40923dfcd74Spooka i=`expr $i - 1` 41023dfcd74Spooka done 41123dfcd74Spooka trap - 1 2 13 15 41223dfcd74Spooka if test $i -le 0; then 41323dfcd74Spooka echo "$0: failed to acquire lock after $numtries attempts" >&2 41423dfcd74Spooka echo "$0: check lockdir '$lockdir'" >&2 41523dfcd74Spooka exit 1 41623dfcd74Spooka fi 41723dfcd74Spooka 41823dfcd74Spooka if test $stat -ne 0; then 41923dfcd74Spooka rm -f "$tmpdepfile" 42023dfcd74Spooka exit $stat 42123dfcd74Spooka fi 42223dfcd74Spooka rm -f "$depfile" 42323dfcd74Spooka # Each line is of the form `foo.o: dependent.h', 42423dfcd74Spooka # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42523dfcd74Spooka # Do two passes, one to just change these to 42623dfcd74Spooka # `$object: dependent.h' and one to simply `dependent.h:'. 42723dfcd74Spooka sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42823dfcd74Spooka # Some versions of the HPUX 10.20 sed can't process this invocation 42923dfcd74Spooka # correctly. Breaking it into two sed invocations is a workaround. 43023dfcd74Spooka sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43123dfcd74Spooka | sed -e 's/$/ :/' >> "$depfile" 43223dfcd74Spooka rm -f "$tmpdepfile" 43323dfcd74Spooka ;; 43423dfcd74Spooka 43523dfcd74Spookahp2) 43623dfcd74Spooka # The "hp" stanza above does not work with aCC (C++) and HP's ia64 43723dfcd74Spooka # compilers, which have integrated preprocessors. The correct option 43823dfcd74Spooka # to use with these is +Maked; it writes dependencies to a file named 43923dfcd74Spooka # 'foo.d', which lands next to the object file, wherever that 44023dfcd74Spooka # happens to be. 44123dfcd74Spooka # Much of this is similar to the tru64 case; see comments there. 44223dfcd74Spooka set_dir_from "$object" 44323dfcd74Spooka set_base_from "$object" 44423dfcd74Spooka if test "$libtool" = yes; then 44523dfcd74Spooka tmpdepfile1=$dir$base.d 44623dfcd74Spooka tmpdepfile2=$dir.libs/$base.d 44723dfcd74Spooka "$@" -Wc,+Maked 44823dfcd74Spooka else 44923dfcd74Spooka tmpdepfile1=$dir$base.d 45023dfcd74Spooka tmpdepfile2=$dir$base.d 45123dfcd74Spooka "$@" +Maked 45223dfcd74Spooka fi 45323dfcd74Spooka stat=$? 45423dfcd74Spooka if test $stat -ne 0; then 45523dfcd74Spooka rm -f "$tmpdepfile1" "$tmpdepfile2" 45623dfcd74Spooka exit $stat 45723dfcd74Spooka fi 45823dfcd74Spooka 45923dfcd74Spooka for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 46023dfcd74Spooka do 46123dfcd74Spooka test -f "$tmpdepfile" && break 46223dfcd74Spooka done 46323dfcd74Spooka if test -f "$tmpdepfile"; then 46423dfcd74Spooka sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46523dfcd74Spooka # Add 'dependent.h:' lines. 46623dfcd74Spooka sed -ne '2,${ 46723dfcd74Spooka s/^ *// 46823dfcd74Spooka s/ \\*$// 46923dfcd74Spooka s/$/:/ 47023dfcd74Spooka p 47123dfcd74Spooka }' "$tmpdepfile" >> "$depfile" 47223dfcd74Spooka else 47323dfcd74Spooka make_dummy_depfile 47423dfcd74Spooka fi 47523dfcd74Spooka rm -f "$tmpdepfile" "$tmpdepfile2" 47623dfcd74Spooka ;; 47723dfcd74Spooka 47823dfcd74Spookatru64) 47923dfcd74Spooka # The Tru64 compiler uses -MD to generate dependencies as a side 48023dfcd74Spooka # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48123dfcd74Spooka # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48223dfcd74Spooka # dependencies in 'foo.d' instead, so we check for that too. 48323dfcd74Spooka # Subdirectories are respected. 48423dfcd74Spooka set_dir_from "$object" 48523dfcd74Spooka set_base_from "$object" 48623dfcd74Spooka 48723dfcd74Spooka if test "$libtool" = yes; then 48823dfcd74Spooka # Libtool generates 2 separate objects for the 2 libraries. These 48923dfcd74Spooka # two compilations output dependencies in $dir.libs/$base.o.d and 49023dfcd74Spooka # in $dir$base.o.d. We have to check for both files, because 49123dfcd74Spooka # one of the two compilations can be disabled. We should prefer 49223dfcd74Spooka # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49323dfcd74Spooka # automatically cleaned when .libs/ is deleted, while ignoring 49423dfcd74Spooka # the former would cause a distcleancheck panic. 49523dfcd74Spooka tmpdepfile1=$dir$base.o.d # libtool 1.5 49623dfcd74Spooka tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49723dfcd74Spooka tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49823dfcd74Spooka "$@" -Wc,-MD 49923dfcd74Spooka else 50023dfcd74Spooka tmpdepfile1=$dir$base.d 50123dfcd74Spooka tmpdepfile2=$dir$base.d 50223dfcd74Spooka tmpdepfile3=$dir$base.d 50323dfcd74Spooka "$@" -MD 50423dfcd74Spooka fi 50523dfcd74Spooka 50623dfcd74Spooka stat=$? 50723dfcd74Spooka if test $stat -ne 0; then 50823dfcd74Spooka rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50923dfcd74Spooka exit $stat 51023dfcd74Spooka fi 51123dfcd74Spooka 51223dfcd74Spooka for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51323dfcd74Spooka do 51423dfcd74Spooka test -f "$tmpdepfile" && break 51523dfcd74Spooka done 51623dfcd74Spooka # Same post-processing that is required for AIX mode. 51723dfcd74Spooka aix_post_process_depfile 51823dfcd74Spooka ;; 51923dfcd74Spooka 52023dfcd74Spookamsvc7) 52123dfcd74Spooka if test "$libtool" = yes; then 52223dfcd74Spooka showIncludes=-Wc,-showIncludes 52323dfcd74Spooka else 52423dfcd74Spooka showIncludes=-showIncludes 52523dfcd74Spooka fi 52623dfcd74Spooka "$@" $showIncludes > "$tmpdepfile" 52723dfcd74Spooka stat=$? 52823dfcd74Spooka grep -v '^Note: including file: ' "$tmpdepfile" 52923dfcd74Spooka if test $stat -ne 0; then 53023dfcd74Spooka rm -f "$tmpdepfile" 53123dfcd74Spooka exit $stat 53223dfcd74Spooka fi 53323dfcd74Spooka rm -f "$depfile" 53423dfcd74Spooka echo "$object : \\" > "$depfile" 53523dfcd74Spooka # The first sed program below extracts the file names and escapes 53623dfcd74Spooka # backslashes for cygpath. The second sed program outputs the file 53723dfcd74Spooka # name when reading, but also accumulates all include files in the 53823dfcd74Spooka # hold buffer in order to output them again at the end. This only 53923dfcd74Spooka # works with sed implementations that can handle large buffers. 54023dfcd74Spooka sed < "$tmpdepfile" -n ' 54123dfcd74Spooka/^Note: including file: *\(.*\)/ { 54223dfcd74Spooka s//\1/ 54323dfcd74Spooka s/\\/\\\\/g 54423dfcd74Spooka p 54523dfcd74Spooka}' | $cygpath_u | sort -u | sed -n ' 54623dfcd74Spookas/ /\\ /g 54723dfcd74Spookas/\(.*\)/'"$tab"'\1 \\/p 54823dfcd74Spookas/.\(.*\) \\/\1:/ 54923dfcd74SpookaH 55023dfcd74Spooka$ { 55123dfcd74Spooka s/.*/'"$tab"'/ 55223dfcd74Spooka G 55323dfcd74Spooka p 55423dfcd74Spooka}' >> "$depfile" 55523dfcd74Spooka echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55623dfcd74Spooka rm -f "$tmpdepfile" 55723dfcd74Spooka ;; 55823dfcd74Spooka 55923dfcd74Spookamsvc7msys) 56023dfcd74Spooka # This case exists only to let depend.m4 do its work. It works by 56123dfcd74Spooka # looking at the text of this script. This case will never be run, 56223dfcd74Spooka # since it is checked for above. 56323dfcd74Spooka exit 1 56423dfcd74Spooka ;; 56523dfcd74Spooka 56623dfcd74Spooka#nosideeffect) 56723dfcd74Spooka # This comment above is used by automake to tell side-effect 56823dfcd74Spooka # dependency tracking mechanisms from slower ones. 56923dfcd74Spooka 57023dfcd74Spookadashmstdout) 57123dfcd74Spooka # Important note: in order to support this mode, a compiler *must* 57223dfcd74Spooka # always write the preprocessed file to stdout, regardless of -o. 57323dfcd74Spooka "$@" || exit $? 57423dfcd74Spooka 57523dfcd74Spooka # Remove the call to Libtool. 57623dfcd74Spooka if test "$libtool" = yes; then 57723dfcd74Spooka while test "X$1" != 'X--mode=compile'; do 57823dfcd74Spooka shift 57923dfcd74Spooka done 58023dfcd74Spooka shift 58123dfcd74Spooka fi 58223dfcd74Spooka 58323dfcd74Spooka # Remove '-o $object'. 58423dfcd74Spooka IFS=" " 58523dfcd74Spooka for arg 58623dfcd74Spooka do 58723dfcd74Spooka case $arg in 58823dfcd74Spooka -o) 58923dfcd74Spooka shift 59023dfcd74Spooka ;; 59123dfcd74Spooka $object) 59223dfcd74Spooka shift 59323dfcd74Spooka ;; 59423dfcd74Spooka *) 59523dfcd74Spooka set fnord "$@" "$arg" 59623dfcd74Spooka shift # fnord 59723dfcd74Spooka shift # $arg 59823dfcd74Spooka ;; 59923dfcd74Spooka esac 60023dfcd74Spooka done 60123dfcd74Spooka 60223dfcd74Spooka test -z "$dashmflag" && dashmflag=-M 60323dfcd74Spooka # Require at least two characters before searching for ':' 60423dfcd74Spooka # in the target name. This is to cope with DOS-style filenames: 60523dfcd74Spooka # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60623dfcd74Spooka "$@" $dashmflag | 60723dfcd74Spooka sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60823dfcd74Spooka rm -f "$depfile" 60923dfcd74Spooka cat < "$tmpdepfile" > "$depfile" 61023dfcd74Spooka # Some versions of the HPUX 10.20 sed can't process this sed invocation 61123dfcd74Spooka # correctly. Breaking it into two sed invocations is a workaround. 61223dfcd74Spooka tr ' ' "$nl" < "$tmpdepfile" \ 61323dfcd74Spooka | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61423dfcd74Spooka | sed -e 's/$/ :/' >> "$depfile" 61523dfcd74Spooka rm -f "$tmpdepfile" 61623dfcd74Spooka ;; 61723dfcd74Spooka 61823dfcd74SpookadashXmstdout) 61923dfcd74Spooka # This case only exists to satisfy depend.m4. It is never actually 62023dfcd74Spooka # run, as this mode is specially recognized in the preamble. 62123dfcd74Spooka exit 1 62223dfcd74Spooka ;; 62323dfcd74Spooka 62423dfcd74Spookamakedepend) 62523dfcd74Spooka "$@" || exit $? 62623dfcd74Spooka # Remove any Libtool call 62723dfcd74Spooka if test "$libtool" = yes; then 62823dfcd74Spooka while test "X$1" != 'X--mode=compile'; do 62923dfcd74Spooka shift 63023dfcd74Spooka done 63123dfcd74Spooka shift 63223dfcd74Spooka fi 63323dfcd74Spooka # X makedepend 63423dfcd74Spooka shift 63523dfcd74Spooka cleared=no eat=no 63623dfcd74Spooka for arg 63723dfcd74Spooka do 63823dfcd74Spooka case $cleared in 63923dfcd74Spooka no) 64023dfcd74Spooka set ""; shift 64123dfcd74Spooka cleared=yes ;; 64223dfcd74Spooka esac 64323dfcd74Spooka if test $eat = yes; then 64423dfcd74Spooka eat=no 64523dfcd74Spooka continue 64623dfcd74Spooka fi 64723dfcd74Spooka case "$arg" in 64823dfcd74Spooka -D*|-I*) 64923dfcd74Spooka set fnord "$@" "$arg"; shift ;; 65023dfcd74Spooka # Strip any option that makedepend may not understand. Remove 65123dfcd74Spooka # the object too, otherwise makedepend will parse it as a source file. 65223dfcd74Spooka -arch) 65323dfcd74Spooka eat=yes ;; 65423dfcd74Spooka -*|$object) 65523dfcd74Spooka ;; 65623dfcd74Spooka *) 65723dfcd74Spooka set fnord "$@" "$arg"; shift ;; 65823dfcd74Spooka esac 65923dfcd74Spooka done 66023dfcd74Spooka obj_suffix=`echo "$object" | sed 's/^.*\././'` 66123dfcd74Spooka touch "$tmpdepfile" 66223dfcd74Spooka ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66323dfcd74Spooka rm -f "$depfile" 66423dfcd74Spooka # makedepend may prepend the VPATH from the source file name to the object. 66523dfcd74Spooka # No need to regex-escape $object, excess matching of '.' is harmless. 66623dfcd74Spooka sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66723dfcd74Spooka # Some versions of the HPUX 10.20 sed can't process the last invocation 66823dfcd74Spooka # correctly. Breaking it into two sed invocations is a workaround. 66923dfcd74Spooka sed '1,2d' "$tmpdepfile" \ 67023dfcd74Spooka | tr ' ' "$nl" \ 67123dfcd74Spooka | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67223dfcd74Spooka | sed -e 's/$/ :/' >> "$depfile" 67323dfcd74Spooka rm -f "$tmpdepfile" "$tmpdepfile".bak 67423dfcd74Spooka ;; 67523dfcd74Spooka 67623dfcd74Spookacpp) 67723dfcd74Spooka # Important note: in order to support this mode, a compiler *must* 67823dfcd74Spooka # always write the preprocessed file to stdout. 67923dfcd74Spooka "$@" || exit $? 68023dfcd74Spooka 68123dfcd74Spooka # Remove the call to Libtool. 68223dfcd74Spooka if test "$libtool" = yes; then 68323dfcd74Spooka while test "X$1" != 'X--mode=compile'; do 68423dfcd74Spooka shift 68523dfcd74Spooka done 68623dfcd74Spooka shift 68723dfcd74Spooka fi 68823dfcd74Spooka 68923dfcd74Spooka # Remove '-o $object'. 69023dfcd74Spooka IFS=" " 69123dfcd74Spooka for arg 69223dfcd74Spooka do 69323dfcd74Spooka case $arg in 69423dfcd74Spooka -o) 69523dfcd74Spooka shift 69623dfcd74Spooka ;; 69723dfcd74Spooka $object) 69823dfcd74Spooka shift 69923dfcd74Spooka ;; 70023dfcd74Spooka *) 70123dfcd74Spooka set fnord "$@" "$arg" 70223dfcd74Spooka shift # fnord 70323dfcd74Spooka shift # $arg 70423dfcd74Spooka ;; 70523dfcd74Spooka esac 70623dfcd74Spooka done 70723dfcd74Spooka 70823dfcd74Spooka "$@" -E \ 70923dfcd74Spooka | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71023dfcd74Spooka -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71123dfcd74Spooka | sed '$ s: \\$::' > "$tmpdepfile" 71223dfcd74Spooka rm -f "$depfile" 71323dfcd74Spooka echo "$object : \\" > "$depfile" 71423dfcd74Spooka cat < "$tmpdepfile" >> "$depfile" 71523dfcd74Spooka sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71623dfcd74Spooka rm -f "$tmpdepfile" 71723dfcd74Spooka ;; 71823dfcd74Spooka 71923dfcd74Spookamsvisualcpp) 72023dfcd74Spooka # Important note: in order to support this mode, a compiler *must* 72123dfcd74Spooka # always write the preprocessed file to stdout. 72223dfcd74Spooka "$@" || exit $? 72323dfcd74Spooka 72423dfcd74Spooka # Remove the call to Libtool. 72523dfcd74Spooka if test "$libtool" = yes; then 72623dfcd74Spooka while test "X$1" != 'X--mode=compile'; do 72723dfcd74Spooka shift 72823dfcd74Spooka done 72923dfcd74Spooka shift 73023dfcd74Spooka fi 73123dfcd74Spooka 73223dfcd74Spooka IFS=" " 73323dfcd74Spooka for arg 73423dfcd74Spooka do 73523dfcd74Spooka case "$arg" in 73623dfcd74Spooka -o) 73723dfcd74Spooka shift 73823dfcd74Spooka ;; 73923dfcd74Spooka $object) 74023dfcd74Spooka shift 74123dfcd74Spooka ;; 74223dfcd74Spooka "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74323dfcd74Spooka set fnord "$@" 74423dfcd74Spooka shift 74523dfcd74Spooka shift 74623dfcd74Spooka ;; 74723dfcd74Spooka *) 74823dfcd74Spooka set fnord "$@" "$arg" 74923dfcd74Spooka shift 75023dfcd74Spooka shift 75123dfcd74Spooka ;; 75223dfcd74Spooka esac 75323dfcd74Spooka done 75423dfcd74Spooka "$@" -E 2>/dev/null | 75523dfcd74Spooka sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75623dfcd74Spooka rm -f "$depfile" 75723dfcd74Spooka echo "$object : \\" > "$depfile" 75823dfcd74Spooka sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75923dfcd74Spooka echo "$tab" >> "$depfile" 76023dfcd74Spooka sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76123dfcd74Spooka rm -f "$tmpdepfile" 76223dfcd74Spooka ;; 76323dfcd74Spooka 76423dfcd74Spookamsvcmsys) 76523dfcd74Spooka # This case exists only to let depend.m4 do its work. It works by 76623dfcd74Spooka # looking at the text of this script. This case will never be run, 76723dfcd74Spooka # since it is checked for above. 76823dfcd74Spooka exit 1 76923dfcd74Spooka ;; 77023dfcd74Spooka 77123dfcd74Spookanone) 77223dfcd74Spooka exec "$@" 77323dfcd74Spooka ;; 77423dfcd74Spooka 77523dfcd74Spooka*) 77623dfcd74Spooka echo "Unknown depmode $depmode" 1>&2 77723dfcd74Spooka exit 1 77823dfcd74Spooka ;; 77923dfcd74Spookaesac 78023dfcd74Spooka 78123dfcd74Spookaexit 0 78223dfcd74Spooka 78323dfcd74Spooka# Local Variables: 78423dfcd74Spooka# mode: shell-script 78523dfcd74Spooka# sh-indentation: 2 78623dfcd74Spooka# eval: (add-hook 'write-file-hooks 'time-stamp) 78723dfcd74Spooka# time-stamp-start: "scriptversion=" 78823dfcd74Spooka# time-stamp-format: "%:y-%02m-%02d.%02H" 78923dfcd74Spooka# time-stamp-time-zone: "UTC" 79023dfcd74Spooka# time-stamp-end: "; # UTC" 79123dfcd74Spooka# End: 792