depcomp revision 0a6b08f8
1126a8a12Smrg#! /bin/sh
2126a8a12Smrg# depcomp - compile a program generating dependencies as side-effects
3126a8a12Smrg
40a6b08f8Smrgscriptversion=2013-05-30.07; # UTC
5126a8a12Smrg
60a6b08f8Smrg# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7126a8a12Smrg
8126a8a12Smrg# This program is free software; you can redistribute it and/or modify
9126a8a12Smrg# it under the terms of the GNU General Public License as published by
10126a8a12Smrg# the Free Software Foundation; either version 2, or (at your option)
11126a8a12Smrg# any later version.
12126a8a12Smrg
13126a8a12Smrg# This program is distributed in the hope that it will be useful,
14126a8a12Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15126a8a12Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16126a8a12Smrg# GNU General Public License for more details.
17126a8a12Smrg
18126a8a12Smrg# You should have received a copy of the GNU General Public License
19d656433aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20126a8a12Smrg
21126a8a12Smrg# As a special exception to the GNU General Public License, if you
22126a8a12Smrg# distribute this file as part of a program that contains a
23126a8a12Smrg# configuration script generated by Autoconf, you may include it under
24126a8a12Smrg# the same distribution terms that you use for the rest of that program.
25126a8a12Smrg
26126a8a12Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27126a8a12Smrg
28126a8a12Smrgcase $1 in
29126a8a12Smrg  '')
300a6b08f8Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
310a6b08f8Smrg    exit 1;
320a6b08f8Smrg    ;;
33126a8a12Smrg  -h | --h*)
34126a8a12Smrg    cat <<\EOF
35126a8a12SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36126a8a12Smrg
37126a8a12SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38126a8a12Smrgas side-effects.
39126a8a12Smrg
40126a8a12SmrgEnvironment variables:
41126a8a12Smrg  depmode     Dependency tracking mode.
420a6b08f8Smrg  source      Source file read by 'PROGRAMS ARGS'.
430a6b08f8Smrg  object      Object file output by 'PROGRAMS ARGS'.
44126a8a12Smrg  DEPDIR      directory where to store dependencies.
45126a8a12Smrg  depfile     Dependency file to output.
460a6b08f8Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47126a8a12Smrg  libtool     Whether libtool is used (yes/no).
48126a8a12Smrg
49126a8a12SmrgReport bugs to <bug-automake@gnu.org>.
50126a8a12SmrgEOF
51126a8a12Smrg    exit $?
52126a8a12Smrg    ;;
53126a8a12Smrg  -v | --v*)
54126a8a12Smrg    echo "depcomp $scriptversion"
55126a8a12Smrg    exit $?
56126a8a12Smrg    ;;
57126a8a12Smrgesac
58126a8a12Smrg
590a6b08f8Smrg# Get the directory component of the given path, and save it in the
600a6b08f8Smrg# global variables '$dir'.  Note that this directory component will
610a6b08f8Smrg# be either empty or ending with a '/' character.  This is deliberate.
620a6b08f8Smrgset_dir_from ()
630a6b08f8Smrg{
640a6b08f8Smrg  case $1 in
650a6b08f8Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
660a6b08f8Smrg      *) dir=;;
670a6b08f8Smrg  esac
680a6b08f8Smrg}
690a6b08f8Smrg
700a6b08f8Smrg# Get the suffix-stripped basename of the given path, and save it the
710a6b08f8Smrg# global variable '$base'.
720a6b08f8Smrgset_base_from ()
730a6b08f8Smrg{
740a6b08f8Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
750a6b08f8Smrg}
760a6b08f8Smrg
770a6b08f8Smrg# If no dependency file was actually created by the compiler invocation,
780a6b08f8Smrg# we still have to create a dummy depfile, to avoid errors with the
790a6b08f8Smrg# Makefile "include basename.Plo" scheme.
800a6b08f8Smrgmake_dummy_depfile ()
810a6b08f8Smrg{
820a6b08f8Smrg  echo "#dummy" > "$depfile"
830a6b08f8Smrg}
840a6b08f8Smrg
850a6b08f8Smrg# Factor out some common post-processing of the generated depfile.
860a6b08f8Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
870a6b08f8Smrgaix_post_process_depfile ()
880a6b08f8Smrg{
890a6b08f8Smrg  # If the compiler actually managed to produce a dependency file,
900a6b08f8Smrg  # post-process it.
910a6b08f8Smrg  if test -f "$tmpdepfile"; then
920a6b08f8Smrg    # Each line is of the form 'foo.o: dependency.h'.
930a6b08f8Smrg    # Do two passes, one to just change these to
940a6b08f8Smrg    #   $object: dependency.h
950a6b08f8Smrg    # and one to simply output
960a6b08f8Smrg    #   dependency.h:
970a6b08f8Smrg    # which is needed to avoid the deleted-header problem.
980a6b08f8Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
990a6b08f8Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1000a6b08f8Smrg    } > "$depfile"
1010a6b08f8Smrg    rm -f "$tmpdepfile"
1020a6b08f8Smrg  else
1030a6b08f8Smrg    make_dummy_depfile
1040a6b08f8Smrg  fi
1050a6b08f8Smrg}
1060a6b08f8Smrg
1070a6b08f8Smrg# A tabulation character.
1080a6b08f8Smrgtab='	'
1090a6b08f8Smrg# A newline character.
1100a6b08f8Smrgnl='
1110a6b08f8Smrg'
1120a6b08f8Smrg# Character ranges might be problematic outside the C locale.
1130a6b08f8Smrg# These definitions help.
1140a6b08f8Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1150a6b08f8Smrglower=abcdefghijklmnopqrstuvwxyz
1160a6b08f8Smrgdigits=0123456789
1170a6b08f8Smrgalpha=${upper}${lower}
1180a6b08f8Smrg
119126a8a12Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120126a8a12Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121126a8a12Smrg  exit 1
122126a8a12Smrgfi
123126a8a12Smrg
124126a8a12Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125126a8a12Smrgdepfile=${depfile-`echo "$object" |
126126a8a12Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127126a8a12Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128126a8a12Smrg
129126a8a12Smrgrm -f "$tmpdepfile"
130126a8a12Smrg
1310a6b08f8Smrg# Avoid interferences from the environment.
1320a6b08f8Smrggccflag= dashmflag=
1330a6b08f8Smrg
134126a8a12Smrg# Some modes work just like other modes, but use different flags.  We
135126a8a12Smrg# parameterize here, but still list the modes in the big case below,
136126a8a12Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137126a8a12Smrg# here, because this file can only contain one case statement.
138126a8a12Smrgif test "$depmode" = hp; then
139126a8a12Smrg  # HP compiler uses -M and no extra arg.
140126a8a12Smrg  gccflag=-M
141126a8a12Smrg  depmode=gcc
142126a8a12Smrgfi
143126a8a12Smrg
144126a8a12Smrgif test "$depmode" = dashXmstdout; then
1450a6b08f8Smrg  # This is just like dashmstdout with a different argument.
1460a6b08f8Smrg  dashmflag=-xM
1470a6b08f8Smrg  depmode=dashmstdout
148126a8a12Smrgfi
149126a8a12Smrg
150d656433aSmrgcygpath_u="cygpath -u -f -"
151d656433aSmrgif test "$depmode" = msvcmsys; then
1520a6b08f8Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1530a6b08f8Smrg  # Just convert the backslash-escaped backslashes to single forward
1540a6b08f8Smrg  # slashes to satisfy depend.m4
1550a6b08f8Smrg  cygpath_u='sed s,\\\\,/,g'
1560a6b08f8Smrg  depmode=msvisualcpp
1570a6b08f8Smrgfi
1580a6b08f8Smrg
1590a6b08f8Smrgif test "$depmode" = msvc7msys; then
1600a6b08f8Smrg  # This is just like msvc7 but w/o cygpath translation.
1610a6b08f8Smrg  # Just convert the backslash-escaped backslashes to single forward
1620a6b08f8Smrg  # slashes to satisfy depend.m4
1630a6b08f8Smrg  cygpath_u='sed s,\\\\,/,g'
1640a6b08f8Smrg  depmode=msvc7
1650a6b08f8Smrgfi
1660a6b08f8Smrg
1670a6b08f8Smrgif test "$depmode" = xlc; then
1680a6b08f8Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1690a6b08f8Smrg  gccflag=-qmakedep=gcc,-MF
1700a6b08f8Smrg  depmode=gcc
171d656433aSmrgfi
172d656433aSmrg
173126a8a12Smrgcase "$depmode" in
174126a8a12Smrggcc3)
175126a8a12Smrg## gcc 3 implements dependency tracking that does exactly what
176126a8a12Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177126a8a12Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178126a8a12Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179126a8a12Smrg## the command line argument order; so add the flags where they
180126a8a12Smrg## appear in depend2.am.  Note that the slowdown incurred here
181126a8a12Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182126a8a12Smrg  for arg
183126a8a12Smrg  do
184126a8a12Smrg    case $arg in
185126a8a12Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186126a8a12Smrg    *)  set fnord "$@" "$arg" ;;
187126a8a12Smrg    esac
188126a8a12Smrg    shift # fnord
189126a8a12Smrg    shift # $arg
190126a8a12Smrg  done
191126a8a12Smrg  "$@"
192126a8a12Smrg  stat=$?
1930a6b08f8Smrg  if test $stat -ne 0; then
194126a8a12Smrg    rm -f "$tmpdepfile"
195126a8a12Smrg    exit $stat
196126a8a12Smrg  fi
197126a8a12Smrg  mv "$tmpdepfile" "$depfile"
198126a8a12Smrg  ;;
199126a8a12Smrg
200126a8a12Smrggcc)
2010a6b08f8Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2020a6b08f8Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2030a6b08f8Smrg## (see the conditional assignment to $gccflag above).
204126a8a12Smrg## There are various ways to get dependency output from gcc.  Here's
205126a8a12Smrg## why we pick this rather obscure method:
206126a8a12Smrg## - Don't want to use -MD because we'd like the dependencies to end
207126a8a12Smrg##   up in a subdir.  Having to rename by hand is ugly.
208126a8a12Smrg##   (We might end up doing this anyway to support other compilers.)
209126a8a12Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2100a6b08f8Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2110a6b08f8Smrg##   supported by the other compilers which use the 'gcc' depmode.
212126a8a12Smrg## - Using -M directly means running the compiler twice (even worse
213126a8a12Smrg##   than renaming).
214126a8a12Smrg  if test -z "$gccflag"; then
215126a8a12Smrg    gccflag=-MD,
216126a8a12Smrg  fi
217126a8a12Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218126a8a12Smrg  stat=$?
2190a6b08f8Smrg  if test $stat -ne 0; then
220126a8a12Smrg    rm -f "$tmpdepfile"
221126a8a12Smrg    exit $stat
222126a8a12Smrg  fi
223126a8a12Smrg  rm -f "$depfile"
224126a8a12Smrg  echo "$object : \\" > "$depfile"
2250a6b08f8Smrg  # The second -e expression handles DOS-style file names with drive
2260a6b08f8Smrg  # letters.
227126a8a12Smrg  sed -e 's/^[^:]*: / /' \
228126a8a12Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2290a6b08f8Smrg## This next piece of magic avoids the "deleted header file" problem.
230126a8a12Smrg## The problem is that when a header file which appears in a .P file
231126a8a12Smrg## is deleted, the dependency causes make to die (because there is
232126a8a12Smrg## typically no way to rebuild the header).  We avoid this by adding
233126a8a12Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234126a8a12Smrg## this for us directly.
2350a6b08f8Smrg## Some versions of gcc put a space before the ':'.  On the theory
236126a8a12Smrg## that the space means something, we add a space to the output as
2370a6b08f8Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2380a6b08f8Smrg## to the object.  Take care to not repeat it in the output.
239126a8a12Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240126a8a12Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2410a6b08f8Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2420a6b08f8Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2430a6b08f8Smrg    | sed -e 's/$/ :/' >> "$depfile"
244126a8a12Smrg  rm -f "$tmpdepfile"
245126a8a12Smrg  ;;
246126a8a12Smrg
247126a8a12Smrghp)
248126a8a12Smrg  # This case exists only to let depend.m4 do its work.  It works by
249126a8a12Smrg  # looking at the text of this script.  This case will never be run,
250126a8a12Smrg  # since it is checked for above.
251126a8a12Smrg  exit 1
252126a8a12Smrg  ;;
253126a8a12Smrg
254126a8a12Smrgsgi)
255126a8a12Smrg  if test "$libtool" = yes; then
256126a8a12Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257126a8a12Smrg  else
258126a8a12Smrg    "$@" -MDupdate "$tmpdepfile"
259126a8a12Smrg  fi
260126a8a12Smrg  stat=$?
2610a6b08f8Smrg  if test $stat -ne 0; then
262126a8a12Smrg    rm -f "$tmpdepfile"
263126a8a12Smrg    exit $stat
264126a8a12Smrg  fi
265126a8a12Smrg  rm -f "$depfile"
266126a8a12Smrg
267126a8a12Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268126a8a12Smrg    echo "$object : \\" > "$depfile"
269126a8a12Smrg    # Clip off the initial element (the dependent).  Don't try to be
270126a8a12Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271126a8a12Smrg    # lines with more than a fixed number of characters (4096 in
272126a8a12Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2730a6b08f8Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274126a8a12Smrg    # dependency line.
2750a6b08f8Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2760a6b08f8Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2770a6b08f8Smrg      | tr "$nl" ' ' >> "$depfile"
278d656433aSmrg    echo >> "$depfile"
279126a8a12Smrg    # The second pass generates a dummy entry for each header file.
2800a6b08f8Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2810a6b08f8Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2820a6b08f8Smrg      >> "$depfile"
283126a8a12Smrg  else
2840a6b08f8Smrg    make_dummy_depfile
285126a8a12Smrg  fi
286126a8a12Smrg  rm -f "$tmpdepfile"
287126a8a12Smrg  ;;
288126a8a12Smrg
2890a6b08f8Smrgxlc)
2900a6b08f8Smrg  # This case exists only to let depend.m4 do its work.  It works by
2910a6b08f8Smrg  # looking at the text of this script.  This case will never be run,
2920a6b08f8Smrg  # since it is checked for above.
2930a6b08f8Smrg  exit 1
2940a6b08f8Smrg  ;;
2950a6b08f8Smrg
296126a8a12Smrgaix)
297126a8a12Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298126a8a12Smrg  # in a .u file.  In older versions, this file always lives in the
2990a6b08f8Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300126a8a12Smrg  # start of each line; $object doesn't have directory information.
301126a8a12Smrg  # Version 6 uses the directory in both cases.
3020a6b08f8Smrg  set_dir_from "$object"
3030a6b08f8Smrg  set_base_from "$object"
304126a8a12Smrg  if test "$libtool" = yes; then
305d656433aSmrg    tmpdepfile1=$dir$base.u
306d656433aSmrg    tmpdepfile2=$base.u
307d656433aSmrg    tmpdepfile3=$dir.libs/$base.u
308126a8a12Smrg    "$@" -Wc,-M
309126a8a12Smrg  else
310d656433aSmrg    tmpdepfile1=$dir$base.u
311d656433aSmrg    tmpdepfile2=$dir$base.u
312d656433aSmrg    tmpdepfile3=$dir$base.u
313126a8a12Smrg    "$@" -M
314126a8a12Smrg  fi
315126a8a12Smrg  stat=$?
3160a6b08f8Smrg  if test $stat -ne 0; then
317d656433aSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318126a8a12Smrg    exit $stat
319126a8a12Smrg  fi
320126a8a12Smrg
321d656433aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322d656433aSmrg  do
323d656433aSmrg    test -f "$tmpdepfile" && break
324d656433aSmrg  done
3250a6b08f8Smrg  aix_post_process_depfile
3260a6b08f8Smrg  ;;
3270a6b08f8Smrg
3280a6b08f8Smrgtcc)
3290a6b08f8Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3300a6b08f8Smrg  # FIXME: That version still under development at the moment of writing.
3310a6b08f8Smrg  #        Make that this statement remains true also for stable, released
3320a6b08f8Smrg  #        versions.
3330a6b08f8Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3340a6b08f8Smrg  # trailing '\', as in:
3350a6b08f8Smrg  #
3360a6b08f8Smrg  #   foo.o : \
3370a6b08f8Smrg  #    foo.c \
3380a6b08f8Smrg  #    foo.h \
3390a6b08f8Smrg  #
3400a6b08f8Smrg  # It will put a trailing '\' even on the last line, and will use leading
3410a6b08f8Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3420a6b08f8Smrg  # "Emit spaces for -MD").
3430a6b08f8Smrg  "$@" -MD -MF "$tmpdepfile"
3440a6b08f8Smrg  stat=$?
3450a6b08f8Smrg  if test $stat -ne 0; then
3460a6b08f8Smrg    rm -f "$tmpdepfile"
3470a6b08f8Smrg    exit $stat
348126a8a12Smrg  fi
3490a6b08f8Smrg  rm -f "$depfile"
3500a6b08f8Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3510a6b08f8Smrg  # We have to change lines of the first kind to '$object: \'.
3520a6b08f8Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3530a6b08f8Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3540a6b08f8Smrg  # dummy dependency, to avoid the deleted-header problem.
3550a6b08f8Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356126a8a12Smrg  rm -f "$tmpdepfile"
357126a8a12Smrg  ;;
358126a8a12Smrg
3590a6b08f8Smrg## The order of this option in the case statement is important, since the
3600a6b08f8Smrg## shell code in configure will try each of these formats in the order
3610a6b08f8Smrg## listed in this file.  A plain '-MD' option would be understood by many
3620a6b08f8Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3630a6b08f8Smrgpgcc)
3640a6b08f8Smrg  # Portland's C compiler understands '-MD'.
3650a6b08f8Smrg  # Will always output deps to 'file.d' where file is the root name of the
3660a6b08f8Smrg  # source file under compilation, even if file resides in a subdirectory.
3670a6b08f8Smrg  # The object file name does not affect the name of the '.d' file.
3680a6b08f8Smrg  # pgcc 10.2 will output
369126a8a12Smrg  #    foo.o: sub/foo.c sub/foo.h
3700a6b08f8Smrg  # and will wrap long lines using '\' :
371126a8a12Smrg  #    foo.o: sub/foo.c ... \
372126a8a12Smrg  #     sub/foo.h ... \
373126a8a12Smrg  #     ...
3740a6b08f8Smrg  set_dir_from "$object"
3750a6b08f8Smrg  # Use the source, not the object, to determine the base name, since
3760a6b08f8Smrg  # that's sadly what pgcc will do too.
3770a6b08f8Smrg  set_base_from "$source"
3780a6b08f8Smrg  tmpdepfile=$base.d
3790a6b08f8Smrg
3800a6b08f8Smrg  # For projects that build the same source file twice into different object
3810a6b08f8Smrg  # files, the pgcc approach of using the *source* file root name can cause
3820a6b08f8Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3830a6b08f8Smrg  # the same $tmpdepfile.
3840a6b08f8Smrg  lockdir=$base.d-lock
3850a6b08f8Smrg  trap "
3860a6b08f8Smrg    echo '$0: caught signal, cleaning up...' >&2
3870a6b08f8Smrg    rmdir '$lockdir'
3880a6b08f8Smrg    exit 1
3890a6b08f8Smrg  " 1 2 13 15
3900a6b08f8Smrg  numtries=100
3910a6b08f8Smrg  i=$numtries
3920a6b08f8Smrg  while test $i -gt 0; do
3930a6b08f8Smrg    # mkdir is a portable test-and-set.
3940a6b08f8Smrg    if mkdir "$lockdir" 2>/dev/null; then
3950a6b08f8Smrg      # This process acquired the lock.
3960a6b08f8Smrg      "$@" -MD
3970a6b08f8Smrg      stat=$?
3980a6b08f8Smrg      # Release the lock.
3990a6b08f8Smrg      rmdir "$lockdir"
4000a6b08f8Smrg      break
4010a6b08f8Smrg    else
4020a6b08f8Smrg      # If the lock is being held by a different process, wait
4030a6b08f8Smrg      # until the winning process is done or we timeout.
4040a6b08f8Smrg      while test -d "$lockdir" && test $i -gt 0; do
4050a6b08f8Smrg        sleep 1
4060a6b08f8Smrg        i=`expr $i - 1`
4070a6b08f8Smrg      done
4080a6b08f8Smrg    fi
4090a6b08f8Smrg    i=`expr $i - 1`
4100a6b08f8Smrg  done
4110a6b08f8Smrg  trap - 1 2 13 15
4120a6b08f8Smrg  if test $i -le 0; then
4130a6b08f8Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4140a6b08f8Smrg    echo "$0: check lockdir '$lockdir'" >&2
4150a6b08f8Smrg    exit 1
4160a6b08f8Smrg  fi
417126a8a12Smrg
4180a6b08f8Smrg  if test $stat -ne 0; then
419126a8a12Smrg    rm -f "$tmpdepfile"
420126a8a12Smrg    exit $stat
421126a8a12Smrg  fi
422126a8a12Smrg  rm -f "$depfile"
423126a8a12Smrg  # Each line is of the form `foo.o: dependent.h',
424126a8a12Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425126a8a12Smrg  # Do two passes, one to just change these to
426126a8a12Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427126a8a12Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428126a8a12Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429126a8a12Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4300a6b08f8Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4310a6b08f8Smrg    | sed -e 's/$/ :/' >> "$depfile"
432126a8a12Smrg  rm -f "$tmpdepfile"
433126a8a12Smrg  ;;
434126a8a12Smrg
435126a8a12Smrghp2)
436126a8a12Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437126a8a12Smrg  # compilers, which have integrated preprocessors.  The correct option
438126a8a12Smrg  # to use with these is +Maked; it writes dependencies to a file named
439126a8a12Smrg  # 'foo.d', which lands next to the object file, wherever that
440126a8a12Smrg  # happens to be.
441126a8a12Smrg  # Much of this is similar to the tru64 case; see comments there.
4420a6b08f8Smrg  set_dir_from  "$object"
4430a6b08f8Smrg  set_base_from "$object"
444126a8a12Smrg  if test "$libtool" = yes; then
445126a8a12Smrg    tmpdepfile1=$dir$base.d
446126a8a12Smrg    tmpdepfile2=$dir.libs/$base.d
447126a8a12Smrg    "$@" -Wc,+Maked
448126a8a12Smrg  else
449126a8a12Smrg    tmpdepfile1=$dir$base.d
450126a8a12Smrg    tmpdepfile2=$dir$base.d
451126a8a12Smrg    "$@" +Maked
452126a8a12Smrg  fi
453126a8a12Smrg  stat=$?
4540a6b08f8Smrg  if test $stat -ne 0; then
455126a8a12Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456126a8a12Smrg     exit $stat
457126a8a12Smrg  fi
458126a8a12Smrg
459126a8a12Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460126a8a12Smrg  do
461126a8a12Smrg    test -f "$tmpdepfile" && break
462126a8a12Smrg  done
463126a8a12Smrg  if test -f "$tmpdepfile"; then
4640a6b08f8Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4650a6b08f8Smrg    # Add 'dependent.h:' lines.
466d656433aSmrg    sed -ne '2,${
4670a6b08f8Smrg               s/^ *//
4680a6b08f8Smrg               s/ \\*$//
4690a6b08f8Smrg               s/$/:/
4700a6b08f8Smrg               p
4710a6b08f8Smrg             }' "$tmpdepfile" >> "$depfile"
472126a8a12Smrg  else
4730a6b08f8Smrg    make_dummy_depfile
474126a8a12Smrg  fi
475126a8a12Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476126a8a12Smrg  ;;
477126a8a12Smrg
478126a8a12Smrgtru64)
4790a6b08f8Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4800a6b08f8Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4810a6b08f8Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4820a6b08f8Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4830a6b08f8Smrg  # Subdirectories are respected.
4840a6b08f8Smrg  set_dir_from  "$object"
4850a6b08f8Smrg  set_base_from "$object"
4860a6b08f8Smrg
4870a6b08f8Smrg  if test "$libtool" = yes; then
4880a6b08f8Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4890a6b08f8Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4900a6b08f8Smrg    # in $dir$base.o.d.  We have to check for both files, because
4910a6b08f8Smrg    # one of the two compilations can be disabled.  We should prefer
4920a6b08f8Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4930a6b08f8Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4940a6b08f8Smrg    # the former would cause a distcleancheck panic.
4950a6b08f8Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4960a6b08f8Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4970a6b08f8Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4980a6b08f8Smrg    "$@" -Wc,-MD
4990a6b08f8Smrg  else
5000a6b08f8Smrg    tmpdepfile1=$dir$base.d
5010a6b08f8Smrg    tmpdepfile2=$dir$base.d
5020a6b08f8Smrg    tmpdepfile3=$dir$base.d
5030a6b08f8Smrg    "$@" -MD
5040a6b08f8Smrg  fi
5050a6b08f8Smrg
5060a6b08f8Smrg  stat=$?
5070a6b08f8Smrg  if test $stat -ne 0; then
5080a6b08f8Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5090a6b08f8Smrg    exit $stat
5100a6b08f8Smrg  fi
5110a6b08f8Smrg
5120a6b08f8Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5130a6b08f8Smrg  do
5140a6b08f8Smrg    test -f "$tmpdepfile" && break
5150a6b08f8Smrg  done
5160a6b08f8Smrg  # Same post-processing that is required for AIX mode.
5170a6b08f8Smrg  aix_post_process_depfile
5180a6b08f8Smrg  ;;
5190a6b08f8Smrg
5200a6b08f8Smrgmsvc7)
5210a6b08f8Smrg  if test "$libtool" = yes; then
5220a6b08f8Smrg    showIncludes=-Wc,-showIncludes
5230a6b08f8Smrg  else
5240a6b08f8Smrg    showIncludes=-showIncludes
5250a6b08f8Smrg  fi
5260a6b08f8Smrg  "$@" $showIncludes > "$tmpdepfile"
5270a6b08f8Smrg  stat=$?
5280a6b08f8Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5290a6b08f8Smrg  if test $stat -ne 0; then
5300a6b08f8Smrg    rm -f "$tmpdepfile"
5310a6b08f8Smrg    exit $stat
5320a6b08f8Smrg  fi
5330a6b08f8Smrg  rm -f "$depfile"
5340a6b08f8Smrg  echo "$object : \\" > "$depfile"
5350a6b08f8Smrg  # The first sed program below extracts the file names and escapes
5360a6b08f8Smrg  # backslashes for cygpath.  The second sed program outputs the file
5370a6b08f8Smrg  # name when reading, but also accumulates all include files in the
5380a6b08f8Smrg  # hold buffer in order to output them again at the end.  This only
5390a6b08f8Smrg  # works with sed implementations that can handle large buffers.
5400a6b08f8Smrg  sed < "$tmpdepfile" -n '
5410a6b08f8Smrg/^Note: including file:  *\(.*\)/ {
5420a6b08f8Smrg  s//\1/
5430a6b08f8Smrg  s/\\/\\\\/g
5440a6b08f8Smrg  p
5450a6b08f8Smrg}' | $cygpath_u | sort -u | sed -n '
5460a6b08f8Smrgs/ /\\ /g
5470a6b08f8Smrgs/\(.*\)/'"$tab"'\1 \\/p
5480a6b08f8Smrgs/.\(.*\) \\/\1:/
5490a6b08f8SmrgH
5500a6b08f8Smrg$ {
5510a6b08f8Smrg  s/.*/'"$tab"'/
5520a6b08f8Smrg  G
5530a6b08f8Smrg  p
5540a6b08f8Smrg}' >> "$depfile"
5550a6b08f8Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5560a6b08f8Smrg  rm -f "$tmpdepfile"
5570a6b08f8Smrg  ;;
5580a6b08f8Smrg
5590a6b08f8Smrgmsvc7msys)
5600a6b08f8Smrg  # This case exists only to let depend.m4 do its work.  It works by
5610a6b08f8Smrg  # looking at the text of this script.  This case will never be run,
5620a6b08f8Smrg  # since it is checked for above.
5630a6b08f8Smrg  exit 1
5640a6b08f8Smrg  ;;
565126a8a12Smrg
566126a8a12Smrg#nosideeffect)
567126a8a12Smrg  # This comment above is used by automake to tell side-effect
568126a8a12Smrg  # dependency tracking mechanisms from slower ones.
569126a8a12Smrg
570126a8a12Smrgdashmstdout)
571126a8a12Smrg  # Important note: in order to support this mode, a compiler *must*
572126a8a12Smrg  # always write the preprocessed file to stdout, regardless of -o.
573126a8a12Smrg  "$@" || exit $?
574126a8a12Smrg
575126a8a12Smrg  # Remove the call to Libtool.
576126a8a12Smrg  if test "$libtool" = yes; then
577d656433aSmrg    while test "X$1" != 'X--mode=compile'; do
578126a8a12Smrg      shift
579126a8a12Smrg    done
580126a8a12Smrg    shift
581126a8a12Smrg  fi
582126a8a12Smrg
5830a6b08f8Smrg  # Remove '-o $object'.
584126a8a12Smrg  IFS=" "
585126a8a12Smrg  for arg
586126a8a12Smrg  do
587126a8a12Smrg    case $arg in
588126a8a12Smrg    -o)
589126a8a12Smrg      shift
590126a8a12Smrg      ;;
591126a8a12Smrg    $object)
592126a8a12Smrg      shift
593126a8a12Smrg      ;;
594126a8a12Smrg    *)
595126a8a12Smrg      set fnord "$@" "$arg"
596126a8a12Smrg      shift # fnord
597126a8a12Smrg      shift # $arg
598126a8a12Smrg      ;;
599126a8a12Smrg    esac
600126a8a12Smrg  done
601126a8a12Smrg
602126a8a12Smrg  test -z "$dashmflag" && dashmflag=-M
6030a6b08f8Smrg  # Require at least two characters before searching for ':'
604126a8a12Smrg  # in the target name.  This is to cope with DOS-style filenames:
6050a6b08f8Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606126a8a12Smrg  "$@" $dashmflag |
6070a6b08f8Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608126a8a12Smrg  rm -f "$depfile"
609126a8a12Smrg  cat < "$tmpdepfile" > "$depfile"
6100a6b08f8Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6110a6b08f8Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6120a6b08f8Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6130a6b08f8Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6140a6b08f8Smrg    | sed -e 's/$/ :/' >> "$depfile"
615126a8a12Smrg  rm -f "$tmpdepfile"
616126a8a12Smrg  ;;
617126a8a12Smrg
618126a8a12SmrgdashXmstdout)
619126a8a12Smrg  # This case only exists to satisfy depend.m4.  It is never actually
620126a8a12Smrg  # run, as this mode is specially recognized in the preamble.
621126a8a12Smrg  exit 1
622126a8a12Smrg  ;;
623126a8a12Smrg
624126a8a12Smrgmakedepend)
625126a8a12Smrg  "$@" || exit $?
626126a8a12Smrg  # Remove any Libtool call
627126a8a12Smrg  if test "$libtool" = yes; then
628d656433aSmrg    while test "X$1" != 'X--mode=compile'; do
629126a8a12Smrg      shift
630126a8a12Smrg    done
631126a8a12Smrg    shift
632126a8a12Smrg  fi
633126a8a12Smrg  # X makedepend
634126a8a12Smrg  shift
635d656433aSmrg  cleared=no eat=no
636d656433aSmrg  for arg
637d656433aSmrg  do
638126a8a12Smrg    case $cleared in
639126a8a12Smrg    no)
640126a8a12Smrg      set ""; shift
641126a8a12Smrg      cleared=yes ;;
642126a8a12Smrg    esac
643d656433aSmrg    if test $eat = yes; then
644d656433aSmrg      eat=no
645d656433aSmrg      continue
646d656433aSmrg    fi
647126a8a12Smrg    case "$arg" in
648126a8a12Smrg    -D*|-I*)
649126a8a12Smrg      set fnord "$@" "$arg"; shift ;;
650126a8a12Smrg    # Strip any option that makedepend may not understand.  Remove
651126a8a12Smrg    # the object too, otherwise makedepend will parse it as a source file.
652d656433aSmrg    -arch)
653d656433aSmrg      eat=yes ;;
654126a8a12Smrg    -*|$object)
655126a8a12Smrg      ;;
656126a8a12Smrg    *)
657126a8a12Smrg      set fnord "$@" "$arg"; shift ;;
658126a8a12Smrg    esac
659126a8a12Smrg  done
660d656433aSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661126a8a12Smrg  touch "$tmpdepfile"
662126a8a12Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663126a8a12Smrg  rm -f "$depfile"
6640a6b08f8Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6650a6b08f8Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6660a6b08f8Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6670a6b08f8Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6680a6b08f8Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6690a6b08f8Smrg  sed '1,2d' "$tmpdepfile" \
6700a6b08f8Smrg    | tr ' ' "$nl" \
6710a6b08f8Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6720a6b08f8Smrg    | sed -e 's/$/ :/' >> "$depfile"
673126a8a12Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674126a8a12Smrg  ;;
675126a8a12Smrg
676126a8a12Smrgcpp)
677126a8a12Smrg  # Important note: in order to support this mode, a compiler *must*
678126a8a12Smrg  # always write the preprocessed file to stdout.
679126a8a12Smrg  "$@" || exit $?
680126a8a12Smrg
681126a8a12Smrg  # Remove the call to Libtool.
682126a8a12Smrg  if test "$libtool" = yes; then
683d656433aSmrg    while test "X$1" != 'X--mode=compile'; do
684126a8a12Smrg      shift
685126a8a12Smrg    done
686126a8a12Smrg    shift
687126a8a12Smrg  fi
688126a8a12Smrg
6890a6b08f8Smrg  # Remove '-o $object'.
690126a8a12Smrg  IFS=" "
691126a8a12Smrg  for arg
692126a8a12Smrg  do
693126a8a12Smrg    case $arg in
694126a8a12Smrg    -o)
695126a8a12Smrg      shift
696126a8a12Smrg      ;;
697126a8a12Smrg    $object)
698126a8a12Smrg      shift
699126a8a12Smrg      ;;
700126a8a12Smrg    *)
701126a8a12Smrg      set fnord "$@" "$arg"
702126a8a12Smrg      shift # fnord
703126a8a12Smrg      shift # $arg
704126a8a12Smrg      ;;
705126a8a12Smrg    esac
706126a8a12Smrg  done
707126a8a12Smrg
7080a6b08f8Smrg  "$@" -E \
7090a6b08f8Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7100a6b08f8Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7110a6b08f8Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712126a8a12Smrg  rm -f "$depfile"
713126a8a12Smrg  echo "$object : \\" > "$depfile"
714126a8a12Smrg  cat < "$tmpdepfile" >> "$depfile"
715126a8a12Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716126a8a12Smrg  rm -f "$tmpdepfile"
717126a8a12Smrg  ;;
718126a8a12Smrg
719126a8a12Smrgmsvisualcpp)
720126a8a12Smrg  # Important note: in order to support this mode, a compiler *must*
721d656433aSmrg  # always write the preprocessed file to stdout.
722126a8a12Smrg  "$@" || exit $?
723d656433aSmrg
724d656433aSmrg  # Remove the call to Libtool.
725d656433aSmrg  if test "$libtool" = yes; then
726d656433aSmrg    while test "X$1" != 'X--mode=compile'; do
727d656433aSmrg      shift
728d656433aSmrg    done
729d656433aSmrg    shift
730d656433aSmrg  fi
731d656433aSmrg
732126a8a12Smrg  IFS=" "
733126a8a12Smrg  for arg
734126a8a12Smrg  do
735126a8a12Smrg    case "$arg" in
736d656433aSmrg    -o)
737d656433aSmrg      shift
738d656433aSmrg      ;;
739d656433aSmrg    $object)
740d656433aSmrg      shift
741d656433aSmrg      ;;
742126a8a12Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7430a6b08f8Smrg        set fnord "$@"
7440a6b08f8Smrg        shift
7450a6b08f8Smrg        shift
7460a6b08f8Smrg        ;;
747126a8a12Smrg    *)
7480a6b08f8Smrg        set fnord "$@" "$arg"
7490a6b08f8Smrg        shift
7500a6b08f8Smrg        shift
7510a6b08f8Smrg        ;;
752126a8a12Smrg    esac
753126a8a12Smrg  done
754d656433aSmrg  "$@" -E 2>/dev/null |
755d656433aSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756126a8a12Smrg  rm -f "$depfile"
757126a8a12Smrg  echo "$object : \\" > "$depfile"
7580a6b08f8Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7590a6b08f8Smrg  echo "$tab" >> "$depfile"
760d656433aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761126a8a12Smrg  rm -f "$tmpdepfile"
762126a8a12Smrg  ;;
763126a8a12Smrg
764d656433aSmrgmsvcmsys)
765d656433aSmrg  # This case exists only to let depend.m4 do its work.  It works by
766d656433aSmrg  # looking at the text of this script.  This case will never be run,
767d656433aSmrg  # since it is checked for above.
768d656433aSmrg  exit 1
769d656433aSmrg  ;;
770d656433aSmrg
771126a8a12Smrgnone)
772126a8a12Smrg  exec "$@"
773126a8a12Smrg  ;;
774126a8a12Smrg
775126a8a12Smrg*)
776126a8a12Smrg  echo "Unknown depmode $depmode" 1>&2
777126a8a12Smrg  exit 1
778126a8a12Smrg  ;;
779126a8a12Smrgesac
780126a8a12Smrg
781126a8a12Smrgexit 0
782126a8a12Smrg
783126a8a12Smrg# Local Variables:
784126a8a12Smrg# mode: shell-script
785126a8a12Smrg# sh-indentation: 2
786126a8a12Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
787126a8a12Smrg# time-stamp-start: "scriptversion="
788126a8a12Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789d656433aSmrg# time-stamp-time-zone: "UTC"
790d656433aSmrg# time-stamp-end: "; # UTC"
791126a8a12Smrg# End:
792