1b8f75c19Smrg#! /bin/sh
2b8f75c19Smrg# depcomp - compile a program generating dependencies as side-effects
37e4fd55aSmrg
48e4923e5Smrgscriptversion=2013-05-30.07; # UTC
57e4fd55aSmrg
68832ea4aSmrg# Copyright (C) 1999-2014 Free Software Foundation, Inc.
7b8f75c19Smrg
8b8f75c19Smrg# This program is free software; you can redistribute it and/or modify
9b8f75c19Smrg# it under the terms of the GNU General Public License as published by
10b8f75c19Smrg# the Free Software Foundation; either version 2, or (at your option)
11b8f75c19Smrg# any later version.
12b8f75c19Smrg
13b8f75c19Smrg# This program is distributed in the hope that it will be useful,
14b8f75c19Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15b8f75c19Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16b8f75c19Smrg# GNU General Public License for more details.
17b8f75c19Smrg
18b8f75c19Smrg# You should have received a copy of the GNU General Public License
197e4fd55aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20b8f75c19Smrg
21b8f75c19Smrg# As a special exception to the GNU General Public License, if you
22b8f75c19Smrg# distribute this file as part of a program that contains a
23b8f75c19Smrg# configuration script generated by Autoconf, you may include it under
24b8f75c19Smrg# the same distribution terms that you use for the rest of that program.
25b8f75c19Smrg
26b8f75c19Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27b8f75c19Smrg
287e4fd55aSmrgcase $1 in
297e4fd55aSmrg  '')
308e4923e5Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
318e4923e5Smrg    exit 1;
328e4923e5Smrg    ;;
337e4fd55aSmrg  -h | --h*)
347e4fd55aSmrg    cat <<\EOF
357e4fd55aSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
367e4fd55aSmrg
377e4fd55aSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
387e4fd55aSmrgas side-effects.
397e4fd55aSmrg
407e4fd55aSmrgEnvironment variables:
417e4fd55aSmrg  depmode     Dependency tracking mode.
428e4923e5Smrg  source      Source file read by 'PROGRAMS ARGS'.
438e4923e5Smrg  object      Object file output by 'PROGRAMS ARGS'.
447e4fd55aSmrg  DEPDIR      directory where to store dependencies.
457e4fd55aSmrg  depfile     Dependency file to output.
468e4923e5Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
477e4fd55aSmrg  libtool     Whether libtool is used (yes/no).
487e4fd55aSmrg
497e4fd55aSmrgReport bugs to <bug-automake@gnu.org>.
507e4fd55aSmrgEOF
517e4fd55aSmrg    exit $?
527e4fd55aSmrg    ;;
537e4fd55aSmrg  -v | --v*)
547e4fd55aSmrg    echo "depcomp $scriptversion"
557e4fd55aSmrg    exit $?
567e4fd55aSmrg    ;;
577e4fd55aSmrgesac
587e4fd55aSmrg
598e4923e5Smrg# Get the directory component of the given path, and save it in the
608e4923e5Smrg# global variables '$dir'.  Note that this directory component will
618e4923e5Smrg# be either empty or ending with a '/' character.  This is deliberate.
628e4923e5Smrgset_dir_from ()
638e4923e5Smrg{
648e4923e5Smrg  case $1 in
658e4923e5Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
668e4923e5Smrg      *) dir=;;
678e4923e5Smrg  esac
688e4923e5Smrg}
698e4923e5Smrg
708e4923e5Smrg# Get the suffix-stripped basename of the given path, and save it the
718e4923e5Smrg# global variable '$base'.
728e4923e5Smrgset_base_from ()
738e4923e5Smrg{
748e4923e5Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
758e4923e5Smrg}
768e4923e5Smrg
778e4923e5Smrg# If no dependency file was actually created by the compiler invocation,
788e4923e5Smrg# we still have to create a dummy depfile, to avoid errors with the
798e4923e5Smrg# Makefile "include basename.Plo" scheme.
808e4923e5Smrgmake_dummy_depfile ()
818e4923e5Smrg{
828e4923e5Smrg  echo "#dummy" > "$depfile"
838e4923e5Smrg}
848e4923e5Smrg
858e4923e5Smrg# Factor out some common post-processing of the generated depfile.
868e4923e5Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
878e4923e5Smrgaix_post_process_depfile ()
888e4923e5Smrg{
898e4923e5Smrg  # If the compiler actually managed to produce a dependency file,
908e4923e5Smrg  # post-process it.
918e4923e5Smrg  if test -f "$tmpdepfile"; then
928e4923e5Smrg    # Each line is of the form 'foo.o: dependency.h'.
938e4923e5Smrg    # Do two passes, one to just change these to
948e4923e5Smrg    #   $object: dependency.h
958e4923e5Smrg    # and one to simply output
968e4923e5Smrg    #   dependency.h:
978e4923e5Smrg    # which is needed to avoid the deleted-header problem.
988e4923e5Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
998e4923e5Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1008e4923e5Smrg    } > "$depfile"
1018e4923e5Smrg    rm -f "$tmpdepfile"
1028e4923e5Smrg  else
1038e4923e5Smrg    make_dummy_depfile
1048e4923e5Smrg  fi
1058e4923e5Smrg}
1068e4923e5Smrg
1078e4923e5Smrg# A tabulation character.
1088e4923e5Smrgtab='	'
1098e4923e5Smrg# A newline character.
1108e4923e5Smrgnl='
1118e4923e5Smrg'
1128e4923e5Smrg# Character ranges might be problematic outside the C locale.
1138e4923e5Smrg# These definitions help.
1148e4923e5Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1158e4923e5Smrglower=abcdefghijklmnopqrstuvwxyz
1168e4923e5Smrgdigits=0123456789
1178e4923e5Smrgalpha=${upper}${lower}
1188e4923e5Smrg
119b8f75c19Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120b8f75c19Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121b8f75c19Smrg  exit 1
122b8f75c19Smrgfi
123b8f75c19Smrg
1247e4fd55aSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1257e4fd55aSmrgdepfile=${depfile-`echo "$object" |
1267e4fd55aSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127b8f75c19Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128b8f75c19Smrg
129b8f75c19Smrgrm -f "$tmpdepfile"
130b8f75c19Smrg
1318e4923e5Smrg# Avoid interferences from the environment.
1328e4923e5Smrggccflag= dashmflag=
1338e4923e5Smrg
134b8f75c19Smrg# Some modes work just like other modes, but use different flags.  We
135b8f75c19Smrg# parameterize here, but still list the modes in the big case below,
136b8f75c19Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137b8f75c19Smrg# here, because this file can only contain one case statement.
138b8f75c19Smrgif test "$depmode" = hp; then
139b8f75c19Smrg  # HP compiler uses -M and no extra arg.
140b8f75c19Smrg  gccflag=-M
141b8f75c19Smrg  depmode=gcc
142b8f75c19Smrgfi
143b8f75c19Smrg
144b8f75c19Smrgif test "$depmode" = dashXmstdout; then
1458e4923e5Smrg  # This is just like dashmstdout with a different argument.
1468e4923e5Smrg  dashmflag=-xM
1478e4923e5Smrg  depmode=dashmstdout
148b8f75c19Smrgfi
149b8f75c19Smrg
1507e4fd55aSmrgcygpath_u="cygpath -u -f -"
1517e4fd55aSmrgif test "$depmode" = msvcmsys; then
1528e4923e5Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1538e4923e5Smrg  # Just convert the backslash-escaped backslashes to single forward
1548e4923e5Smrg  # slashes to satisfy depend.m4
1558e4923e5Smrg  cygpath_u='sed s,\\\\,/,g'
1568e4923e5Smrg  depmode=msvisualcpp
1578e4923e5Smrgfi
1588e4923e5Smrg
1598e4923e5Smrgif test "$depmode" = msvc7msys; then
1608e4923e5Smrg  # This is just like msvc7 but w/o cygpath translation.
1618e4923e5Smrg  # Just convert the backslash-escaped backslashes to single forward
1628e4923e5Smrg  # slashes to satisfy depend.m4
1638e4923e5Smrg  cygpath_u='sed s,\\\\,/,g'
1648e4923e5Smrg  depmode=msvc7
1658e4923e5Smrgfi
1668e4923e5Smrg
1678e4923e5Smrgif test "$depmode" = xlc; then
1688e4923e5Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1698e4923e5Smrg  gccflag=-qmakedep=gcc,-MF
1708e4923e5Smrg  depmode=gcc
1717e4fd55aSmrgfi
1727e4fd55aSmrg
173b8f75c19Smrgcase "$depmode" in
174b8f75c19Smrggcc3)
175b8f75c19Smrg## gcc 3 implements dependency tracking that does exactly what
176b8f75c19Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177b8f75c19Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1787e4fd55aSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1797e4fd55aSmrg## the command line argument order; so add the flags where they
1807e4fd55aSmrg## appear in depend2.am.  Note that the slowdown incurred here
1817e4fd55aSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1827e4fd55aSmrg  for arg
1837e4fd55aSmrg  do
1847e4fd55aSmrg    case $arg in
1857e4fd55aSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1867e4fd55aSmrg    *)  set fnord "$@" "$arg" ;;
1877e4fd55aSmrg    esac
1887e4fd55aSmrg    shift # fnord
1897e4fd55aSmrg    shift # $arg
1907e4fd55aSmrg  done
1917e4fd55aSmrg  "$@"
192b8f75c19Smrg  stat=$?
1938e4923e5Smrg  if test $stat -ne 0; then
194b8f75c19Smrg    rm -f "$tmpdepfile"
195b8f75c19Smrg    exit $stat
196b8f75c19Smrg  fi
197b8f75c19Smrg  mv "$tmpdepfile" "$depfile"
198b8f75c19Smrg  ;;
199b8f75c19Smrg
200b8f75c19Smrggcc)
2018e4923e5Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2028e4923e5Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2038e4923e5Smrg## (see the conditional assignment to $gccflag above).
204b8f75c19Smrg## There are various ways to get dependency output from gcc.  Here's
205b8f75c19Smrg## why we pick this rather obscure method:
206b8f75c19Smrg## - Don't want to use -MD because we'd like the dependencies to end
207b8f75c19Smrg##   up in a subdir.  Having to rename by hand is ugly.
208b8f75c19Smrg##   (We might end up doing this anyway to support other compilers.)
209b8f75c19Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2108e4923e5Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2118e4923e5Smrg##   supported by the other compilers which use the 'gcc' depmode.
212b8f75c19Smrg## - Using -M directly means running the compiler twice (even worse
213b8f75c19Smrg##   than renaming).
214b8f75c19Smrg  if test -z "$gccflag"; then
215b8f75c19Smrg    gccflag=-MD,
216b8f75c19Smrg  fi
217b8f75c19Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218b8f75c19Smrg  stat=$?
2198e4923e5Smrg  if test $stat -ne 0; then
220b8f75c19Smrg    rm -f "$tmpdepfile"
221b8f75c19Smrg    exit $stat
222b8f75c19Smrg  fi
223b8f75c19Smrg  rm -f "$depfile"
224b8f75c19Smrg  echo "$object : \\" > "$depfile"
2258e4923e5Smrg  # The second -e expression handles DOS-style file names with drive
2268e4923e5Smrg  # letters.
227b8f75c19Smrg  sed -e 's/^[^:]*: / /' \
228b8f75c19Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2298e4923e5Smrg## This next piece of magic avoids the "deleted header file" problem.
230b8f75c19Smrg## The problem is that when a header file which appears in a .P file
231b8f75c19Smrg## is deleted, the dependency causes make to die (because there is
232b8f75c19Smrg## typically no way to rebuild the header).  We avoid this by adding
233b8f75c19Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234b8f75c19Smrg## this for us directly.
2358e4923e5Smrg## Some versions of gcc put a space before the ':'.  On the theory
236b8f75c19Smrg## that the space means something, we add a space to the output as
2378e4923e5Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2388e4923e5Smrg## to the object.  Take care to not repeat it in the output.
239b8f75c19Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240b8f75c19Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2418e4923e5Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2428e4923e5Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2438e4923e5Smrg    | sed -e 's/$/ :/' >> "$depfile"
244b8f75c19Smrg  rm -f "$tmpdepfile"
245b8f75c19Smrg  ;;
246b8f75c19Smrg
247b8f75c19Smrghp)
248b8f75c19Smrg  # This case exists only to let depend.m4 do its work.  It works by
249b8f75c19Smrg  # looking at the text of this script.  This case will never be run,
250b8f75c19Smrg  # since it is checked for above.
251b8f75c19Smrg  exit 1
252b8f75c19Smrg  ;;
253b8f75c19Smrg
254b8f75c19Smrgsgi)
255b8f75c19Smrg  if test "$libtool" = yes; then
256b8f75c19Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257b8f75c19Smrg  else
258b8f75c19Smrg    "$@" -MDupdate "$tmpdepfile"
259b8f75c19Smrg  fi
260b8f75c19Smrg  stat=$?
2618e4923e5Smrg  if test $stat -ne 0; then
262b8f75c19Smrg    rm -f "$tmpdepfile"
263b8f75c19Smrg    exit $stat
264b8f75c19Smrg  fi
265b8f75c19Smrg  rm -f "$depfile"
266b8f75c19Smrg
267b8f75c19Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268b8f75c19Smrg    echo "$object : \\" > "$depfile"
269b8f75c19Smrg    # Clip off the initial element (the dependent).  Don't try to be
270b8f75c19Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271b8f75c19Smrg    # lines with more than a fixed number of characters (4096 in
272b8f75c19Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2738e4923e5Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274b8f75c19Smrg    # dependency line.
2758e4923e5Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2768e4923e5Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2778e4923e5Smrg      | tr "$nl" ' ' >> "$depfile"
2787e4fd55aSmrg    echo >> "$depfile"
279b8f75c19Smrg    # The second pass generates a dummy entry for each header file.
2808e4923e5Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2818e4923e5Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2828e4923e5Smrg      >> "$depfile"
283b8f75c19Smrg  else
2848e4923e5Smrg    make_dummy_depfile
285b8f75c19Smrg  fi
286b8f75c19Smrg  rm -f "$tmpdepfile"
287b8f75c19Smrg  ;;
288b8f75c19Smrg
2898e4923e5Smrgxlc)
2908e4923e5Smrg  # This case exists only to let depend.m4 do its work.  It works by
2918e4923e5Smrg  # looking at the text of this script.  This case will never be run,
2928e4923e5Smrg  # since it is checked for above.
2938e4923e5Smrg  exit 1
2948e4923e5Smrg  ;;
2958e4923e5Smrg
296b8f75c19Smrgaix)
297b8f75c19Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298b8f75c19Smrg  # in a .u file.  In older versions, this file always lives in the
2998e4923e5Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300b8f75c19Smrg  # start of each line; $object doesn't have directory information.
301b8f75c19Smrg  # Version 6 uses the directory in both cases.
3028e4923e5Smrg  set_dir_from "$object"
3038e4923e5Smrg  set_base_from "$object"
304b8f75c19Smrg  if test "$libtool" = yes; then
3057e4fd55aSmrg    tmpdepfile1=$dir$base.u
3067e4fd55aSmrg    tmpdepfile2=$base.u
3077e4fd55aSmrg    tmpdepfile3=$dir.libs/$base.u
308b8f75c19Smrg    "$@" -Wc,-M
309b8f75c19Smrg  else
3107e4fd55aSmrg    tmpdepfile1=$dir$base.u
3117e4fd55aSmrg    tmpdepfile2=$dir$base.u
3127e4fd55aSmrg    tmpdepfile3=$dir$base.u
313b8f75c19Smrg    "$@" -M
314b8f75c19Smrg  fi
315b8f75c19Smrg  stat=$?
3168e4923e5Smrg  if test $stat -ne 0; then
3177e4fd55aSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318b8f75c19Smrg    exit $stat
319b8f75c19Smrg  fi
320b8f75c19Smrg
3217e4fd55aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3227e4fd55aSmrg  do
3237e4fd55aSmrg    test -f "$tmpdepfile" && break
3247e4fd55aSmrg  done
3258e4923e5Smrg  aix_post_process_depfile
3268e4923e5Smrg  ;;
3278e4923e5Smrg
3288e4923e5Smrgtcc)
3298e4923e5Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3308e4923e5Smrg  # FIXME: That version still under development at the moment of writing.
3318e4923e5Smrg  #        Make that this statement remains true also for stable, released
3328e4923e5Smrg  #        versions.
3338e4923e5Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3348e4923e5Smrg  # trailing '\', as in:
3358e4923e5Smrg  #
3368e4923e5Smrg  #   foo.o : \
3378e4923e5Smrg  #    foo.c \
3388e4923e5Smrg  #    foo.h \
3398e4923e5Smrg  #
3408e4923e5Smrg  # It will put a trailing '\' even on the last line, and will use leading
3418e4923e5Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3428e4923e5Smrg  # "Emit spaces for -MD").
3438e4923e5Smrg  "$@" -MD -MF "$tmpdepfile"
3448e4923e5Smrg  stat=$?
3458e4923e5Smrg  if test $stat -ne 0; then
3468e4923e5Smrg    rm -f "$tmpdepfile"
3478e4923e5Smrg    exit $stat
348b8f75c19Smrg  fi
3498e4923e5Smrg  rm -f "$depfile"
3508e4923e5Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3518e4923e5Smrg  # We have to change lines of the first kind to '$object: \'.
3528e4923e5Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3538e4923e5Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3548e4923e5Smrg  # dummy dependency, to avoid the deleted-header problem.
3558e4923e5Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356b8f75c19Smrg  rm -f "$tmpdepfile"
357b8f75c19Smrg  ;;
358b8f75c19Smrg
3598e4923e5Smrg## The order of this option in the case statement is important, since the
3608e4923e5Smrg## shell code in configure will try each of these formats in the order
3618e4923e5Smrg## listed in this file.  A plain '-MD' option would be understood by many
3628e4923e5Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3638e4923e5Smrgpgcc)
3648e4923e5Smrg  # Portland's C compiler understands '-MD'.
3658e4923e5Smrg  # Will always output deps to 'file.d' where file is the root name of the
3668e4923e5Smrg  # source file under compilation, even if file resides in a subdirectory.
3678e4923e5Smrg  # The object file name does not affect the name of the '.d' file.
3688e4923e5Smrg  # pgcc 10.2 will output
369b8f75c19Smrg  #    foo.o: sub/foo.c sub/foo.h
3708e4923e5Smrg  # and will wrap long lines using '\' :
371b8f75c19Smrg  #    foo.o: sub/foo.c ... \
372b8f75c19Smrg  #     sub/foo.h ... \
373b8f75c19Smrg  #     ...
3748e4923e5Smrg  set_dir_from "$object"
3758e4923e5Smrg  # Use the source, not the object, to determine the base name, since
3768e4923e5Smrg  # that's sadly what pgcc will do too.
3778e4923e5Smrg  set_base_from "$source"
3788e4923e5Smrg  tmpdepfile=$base.d
3798e4923e5Smrg
3808e4923e5Smrg  # For projects that build the same source file twice into different object
3818e4923e5Smrg  # files, the pgcc approach of using the *source* file root name can cause
3828e4923e5Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3838e4923e5Smrg  # the same $tmpdepfile.
3848e4923e5Smrg  lockdir=$base.d-lock
3858e4923e5Smrg  trap "
3868e4923e5Smrg    echo '$0: caught signal, cleaning up...' >&2
3878e4923e5Smrg    rmdir '$lockdir'
3888e4923e5Smrg    exit 1
3898e4923e5Smrg  " 1 2 13 15
3908e4923e5Smrg  numtries=100
3918e4923e5Smrg  i=$numtries
3928e4923e5Smrg  while test $i -gt 0; do
3938e4923e5Smrg    # mkdir is a portable test-and-set.
3948e4923e5Smrg    if mkdir "$lockdir" 2>/dev/null; then
3958e4923e5Smrg      # This process acquired the lock.
3968e4923e5Smrg      "$@" -MD
3978e4923e5Smrg      stat=$?
3988e4923e5Smrg      # Release the lock.
3998e4923e5Smrg      rmdir "$lockdir"
4008e4923e5Smrg      break
4018e4923e5Smrg    else
4028e4923e5Smrg      # If the lock is being held by a different process, wait
4038e4923e5Smrg      # until the winning process is done or we timeout.
4048e4923e5Smrg      while test -d "$lockdir" && test $i -gt 0; do
4058e4923e5Smrg        sleep 1
4068e4923e5Smrg        i=`expr $i - 1`
4078e4923e5Smrg      done
4088e4923e5Smrg    fi
4098e4923e5Smrg    i=`expr $i - 1`
4108e4923e5Smrg  done
4118e4923e5Smrg  trap - 1 2 13 15
4128e4923e5Smrg  if test $i -le 0; then
4138e4923e5Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4148e4923e5Smrg    echo "$0: check lockdir '$lockdir'" >&2
4158e4923e5Smrg    exit 1
4168e4923e5Smrg  fi
417b8f75c19Smrg
4188e4923e5Smrg  if test $stat -ne 0; then
419b8f75c19Smrg    rm -f "$tmpdepfile"
420b8f75c19Smrg    exit $stat
421b8f75c19Smrg  fi
422b8f75c19Smrg  rm -f "$depfile"
423b8f75c19Smrg  # Each line is of the form `foo.o: dependent.h',
424b8f75c19Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425b8f75c19Smrg  # Do two passes, one to just change these to
426b8f75c19Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427b8f75c19Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428b8f75c19Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429b8f75c19Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4308e4923e5Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4318e4923e5Smrg    | sed -e 's/$/ :/' >> "$depfile"
432b8f75c19Smrg  rm -f "$tmpdepfile"
433b8f75c19Smrg  ;;
434b8f75c19Smrg
4357e4fd55aSmrghp2)
4367e4fd55aSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4377e4fd55aSmrg  # compilers, which have integrated preprocessors.  The correct option
4387e4fd55aSmrg  # to use with these is +Maked; it writes dependencies to a file named
4397e4fd55aSmrg  # 'foo.d', which lands next to the object file, wherever that
4407e4fd55aSmrg  # happens to be.
4417e4fd55aSmrg  # Much of this is similar to the tru64 case; see comments there.
4428e4923e5Smrg  set_dir_from  "$object"
4438e4923e5Smrg  set_base_from "$object"
4447e4fd55aSmrg  if test "$libtool" = yes; then
4457e4fd55aSmrg    tmpdepfile1=$dir$base.d
4467e4fd55aSmrg    tmpdepfile2=$dir.libs/$base.d
4477e4fd55aSmrg    "$@" -Wc,+Maked
4487e4fd55aSmrg  else
4497e4fd55aSmrg    tmpdepfile1=$dir$base.d
4507e4fd55aSmrg    tmpdepfile2=$dir$base.d
4517e4fd55aSmrg    "$@" +Maked
4527e4fd55aSmrg  fi
4537e4fd55aSmrg  stat=$?
4548e4923e5Smrg  if test $stat -ne 0; then
4557e4fd55aSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4567e4fd55aSmrg     exit $stat
4577e4fd55aSmrg  fi
4587e4fd55aSmrg
4597e4fd55aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4607e4fd55aSmrg  do
4617e4fd55aSmrg    test -f "$tmpdepfile" && break
4627e4fd55aSmrg  done
4637e4fd55aSmrg  if test -f "$tmpdepfile"; then
4648e4923e5Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4658e4923e5Smrg    # Add 'dependent.h:' lines.
4667e4fd55aSmrg    sed -ne '2,${
4678e4923e5Smrg               s/^ *//
4688e4923e5Smrg               s/ \\*$//
4698e4923e5Smrg               s/$/:/
4708e4923e5Smrg               p
4718e4923e5Smrg             }' "$tmpdepfile" >> "$depfile"
4727e4fd55aSmrg  else
4738e4923e5Smrg    make_dummy_depfile
4747e4fd55aSmrg  fi
4757e4fd55aSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4767e4fd55aSmrg  ;;
4777e4fd55aSmrg
478b8f75c19Smrgtru64)
4798e4923e5Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4808e4923e5Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4818e4923e5Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4828e4923e5Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4838e4923e5Smrg  # Subdirectories are respected.
4848e4923e5Smrg  set_dir_from  "$object"
4858e4923e5Smrg  set_base_from "$object"
4868e4923e5Smrg
4878e4923e5Smrg  if test "$libtool" = yes; then
4888e4923e5Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4898e4923e5Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4908e4923e5Smrg    # in $dir$base.o.d.  We have to check for both files, because
4918e4923e5Smrg    # one of the two compilations can be disabled.  We should prefer
4928e4923e5Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4938e4923e5Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4948e4923e5Smrg    # the former would cause a distcleancheck panic.
4958e4923e5Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4968e4923e5Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4978e4923e5Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4988e4923e5Smrg    "$@" -Wc,-MD
4998e4923e5Smrg  else
5008e4923e5Smrg    tmpdepfile1=$dir$base.d
5018e4923e5Smrg    tmpdepfile2=$dir$base.d
5028e4923e5Smrg    tmpdepfile3=$dir$base.d
5038e4923e5Smrg    "$@" -MD
5048e4923e5Smrg  fi
5058e4923e5Smrg
5068e4923e5Smrg  stat=$?
5078e4923e5Smrg  if test $stat -ne 0; then
5088e4923e5Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5098e4923e5Smrg    exit $stat
5108e4923e5Smrg  fi
5118e4923e5Smrg
5128e4923e5Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5138e4923e5Smrg  do
5148e4923e5Smrg    test -f "$tmpdepfile" && break
5158e4923e5Smrg  done
5168e4923e5Smrg  # Same post-processing that is required for AIX mode.
5178e4923e5Smrg  aix_post_process_depfile
5188e4923e5Smrg  ;;
5198e4923e5Smrg
5208e4923e5Smrgmsvc7)
5218e4923e5Smrg  if test "$libtool" = yes; then
5228e4923e5Smrg    showIncludes=-Wc,-showIncludes
5238e4923e5Smrg  else
5248e4923e5Smrg    showIncludes=-showIncludes
5258e4923e5Smrg  fi
5268e4923e5Smrg  "$@" $showIncludes > "$tmpdepfile"
5278e4923e5Smrg  stat=$?
5288e4923e5Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5298e4923e5Smrg  if test $stat -ne 0; then
5308e4923e5Smrg    rm -f "$tmpdepfile"
5318e4923e5Smrg    exit $stat
5328e4923e5Smrg  fi
5338e4923e5Smrg  rm -f "$depfile"
5348e4923e5Smrg  echo "$object : \\" > "$depfile"
5358e4923e5Smrg  # The first sed program below extracts the file names and escapes
5368e4923e5Smrg  # backslashes for cygpath.  The second sed program outputs the file
5378e4923e5Smrg  # name when reading, but also accumulates all include files in the
5388e4923e5Smrg  # hold buffer in order to output them again at the end.  This only
5398e4923e5Smrg  # works with sed implementations that can handle large buffers.
5408e4923e5Smrg  sed < "$tmpdepfile" -n '
5418e4923e5Smrg/^Note: including file:  *\(.*\)/ {
5428e4923e5Smrg  s//\1/
5438e4923e5Smrg  s/\\/\\\\/g
5448e4923e5Smrg  p
5458e4923e5Smrg}' | $cygpath_u | sort -u | sed -n '
5468e4923e5Smrgs/ /\\ /g
5478e4923e5Smrgs/\(.*\)/'"$tab"'\1 \\/p
5488e4923e5Smrgs/.\(.*\) \\/\1:/
5498e4923e5SmrgH
5508e4923e5Smrg$ {
5518e4923e5Smrg  s/.*/'"$tab"'/
5528e4923e5Smrg  G
5538e4923e5Smrg  p
5548e4923e5Smrg}' >> "$depfile"
5558e4923e5Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5568e4923e5Smrg  rm -f "$tmpdepfile"
5578e4923e5Smrg  ;;
5588e4923e5Smrg
5598e4923e5Smrgmsvc7msys)
5608e4923e5Smrg  # This case exists only to let depend.m4 do its work.  It works by
5618e4923e5Smrg  # looking at the text of this script.  This case will never be run,
5628e4923e5Smrg  # since it is checked for above.
5638e4923e5Smrg  exit 1
5648e4923e5Smrg  ;;
565b8f75c19Smrg
566b8f75c19Smrg#nosideeffect)
567b8f75c19Smrg  # This comment above is used by automake to tell side-effect
568b8f75c19Smrg  # dependency tracking mechanisms from slower ones.
569b8f75c19Smrg
570b8f75c19Smrgdashmstdout)
571b8f75c19Smrg  # Important note: in order to support this mode, a compiler *must*
572b8f75c19Smrg  # always write the preprocessed file to stdout, regardless of -o.
573b8f75c19Smrg  "$@" || exit $?
574b8f75c19Smrg
575b8f75c19Smrg  # Remove the call to Libtool.
576b8f75c19Smrg  if test "$libtool" = yes; then
5777e4fd55aSmrg    while test "X$1" != 'X--mode=compile'; do
578b8f75c19Smrg      shift
579b8f75c19Smrg    done
580b8f75c19Smrg    shift
581b8f75c19Smrg  fi
582b8f75c19Smrg
5838e4923e5Smrg  # Remove '-o $object'.
584b8f75c19Smrg  IFS=" "
585b8f75c19Smrg  for arg
586b8f75c19Smrg  do
587b8f75c19Smrg    case $arg in
588b8f75c19Smrg    -o)
589b8f75c19Smrg      shift
590b8f75c19Smrg      ;;
591b8f75c19Smrg    $object)
592b8f75c19Smrg      shift
593b8f75c19Smrg      ;;
594b8f75c19Smrg    *)
595b8f75c19Smrg      set fnord "$@" "$arg"
596b8f75c19Smrg      shift # fnord
597b8f75c19Smrg      shift # $arg
598b8f75c19Smrg      ;;
599b8f75c19Smrg    esac
600b8f75c19Smrg  done
601b8f75c19Smrg
602b8f75c19Smrg  test -z "$dashmflag" && dashmflag=-M
6038e4923e5Smrg  # Require at least two characters before searching for ':'
604b8f75c19Smrg  # in the target name.  This is to cope with DOS-style filenames:
6058e4923e5Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606b8f75c19Smrg  "$@" $dashmflag |
6078e4923e5Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608b8f75c19Smrg  rm -f "$depfile"
609b8f75c19Smrg  cat < "$tmpdepfile" > "$depfile"
6108e4923e5Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6118e4923e5Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6128e4923e5Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6138e4923e5Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6148e4923e5Smrg    | sed -e 's/$/ :/' >> "$depfile"
615b8f75c19Smrg  rm -f "$tmpdepfile"
616b8f75c19Smrg  ;;
617b8f75c19Smrg
618b8f75c19SmrgdashXmstdout)
619b8f75c19Smrg  # This case only exists to satisfy depend.m4.  It is never actually
620b8f75c19Smrg  # run, as this mode is specially recognized in the preamble.
621b8f75c19Smrg  exit 1
622b8f75c19Smrg  ;;
623b8f75c19Smrg
624b8f75c19Smrgmakedepend)
625b8f75c19Smrg  "$@" || exit $?
626b8f75c19Smrg  # Remove any Libtool call
627b8f75c19Smrg  if test "$libtool" = yes; then
6287e4fd55aSmrg    while test "X$1" != 'X--mode=compile'; do
629b8f75c19Smrg      shift
630b8f75c19Smrg    done
631b8f75c19Smrg    shift
632b8f75c19Smrg  fi
633b8f75c19Smrg  # X makedepend
634b8f75c19Smrg  shift
6357e4fd55aSmrg  cleared=no eat=no
6367e4fd55aSmrg  for arg
6377e4fd55aSmrg  do
638b8f75c19Smrg    case $cleared in
639b8f75c19Smrg    no)
640b8f75c19Smrg      set ""; shift
641b8f75c19Smrg      cleared=yes ;;
642b8f75c19Smrg    esac
6437e4fd55aSmrg    if test $eat = yes; then
6447e4fd55aSmrg      eat=no
6457e4fd55aSmrg      continue
6467e4fd55aSmrg    fi
647b8f75c19Smrg    case "$arg" in
648b8f75c19Smrg    -D*|-I*)
649b8f75c19Smrg      set fnord "$@" "$arg"; shift ;;
650b8f75c19Smrg    # Strip any option that makedepend may not understand.  Remove
651b8f75c19Smrg    # the object too, otherwise makedepend will parse it as a source file.
6527e4fd55aSmrg    -arch)
6537e4fd55aSmrg      eat=yes ;;
654b8f75c19Smrg    -*|$object)
655b8f75c19Smrg      ;;
656b8f75c19Smrg    *)
657b8f75c19Smrg      set fnord "$@" "$arg"; shift ;;
658b8f75c19Smrg    esac
659b8f75c19Smrg  done
6607e4fd55aSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661b8f75c19Smrg  touch "$tmpdepfile"
662b8f75c19Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663b8f75c19Smrg  rm -f "$depfile"
6648e4923e5Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6658e4923e5Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6668e4923e5Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6678e4923e5Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6688e4923e5Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6698e4923e5Smrg  sed '1,2d' "$tmpdepfile" \
6708e4923e5Smrg    | tr ' ' "$nl" \
6718e4923e5Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6728e4923e5Smrg    | sed -e 's/$/ :/' >> "$depfile"
673b8f75c19Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674b8f75c19Smrg  ;;
675b8f75c19Smrg
676b8f75c19Smrgcpp)
677b8f75c19Smrg  # Important note: in order to support this mode, a compiler *must*
678b8f75c19Smrg  # always write the preprocessed file to stdout.
679b8f75c19Smrg  "$@" || exit $?
680b8f75c19Smrg
681b8f75c19Smrg  # Remove the call to Libtool.
682b8f75c19Smrg  if test "$libtool" = yes; then
6837e4fd55aSmrg    while test "X$1" != 'X--mode=compile'; do
684b8f75c19Smrg      shift
685b8f75c19Smrg    done
686b8f75c19Smrg    shift
687b8f75c19Smrg  fi
688b8f75c19Smrg
6898e4923e5Smrg  # Remove '-o $object'.
690b8f75c19Smrg  IFS=" "
691b8f75c19Smrg  for arg
692b8f75c19Smrg  do
693b8f75c19Smrg    case $arg in
694b8f75c19Smrg    -o)
695b8f75c19Smrg      shift
696b8f75c19Smrg      ;;
697b8f75c19Smrg    $object)
698b8f75c19Smrg      shift
699b8f75c19Smrg      ;;
700b8f75c19Smrg    *)
701b8f75c19Smrg      set fnord "$@" "$arg"
702b8f75c19Smrg      shift # fnord
703b8f75c19Smrg      shift # $arg
704b8f75c19Smrg      ;;
705b8f75c19Smrg    esac
706b8f75c19Smrg  done
707b8f75c19Smrg
7088e4923e5Smrg  "$@" -E \
7098e4923e5Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7108e4923e5Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7118e4923e5Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712b8f75c19Smrg  rm -f "$depfile"
713b8f75c19Smrg  echo "$object : \\" > "$depfile"
714b8f75c19Smrg  cat < "$tmpdepfile" >> "$depfile"
715b8f75c19Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716b8f75c19Smrg  rm -f "$tmpdepfile"
717b8f75c19Smrg  ;;
718b8f75c19Smrg
719b8f75c19Smrgmsvisualcpp)
720b8f75c19Smrg  # Important note: in order to support this mode, a compiler *must*
7217e4fd55aSmrg  # always write the preprocessed file to stdout.
722b8f75c19Smrg  "$@" || exit $?
7237e4fd55aSmrg
7247e4fd55aSmrg  # Remove the call to Libtool.
7257e4fd55aSmrg  if test "$libtool" = yes; then
7267e4fd55aSmrg    while test "X$1" != 'X--mode=compile'; do
7277e4fd55aSmrg      shift
7287e4fd55aSmrg    done
7297e4fd55aSmrg    shift
7307e4fd55aSmrg  fi
7317e4fd55aSmrg
732b8f75c19Smrg  IFS=" "
733b8f75c19Smrg  for arg
734b8f75c19Smrg  do
735b8f75c19Smrg    case "$arg" in
7367e4fd55aSmrg    -o)
7377e4fd55aSmrg      shift
7387e4fd55aSmrg      ;;
7397e4fd55aSmrg    $object)
7407e4fd55aSmrg      shift
7417e4fd55aSmrg      ;;
742b8f75c19Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7438e4923e5Smrg        set fnord "$@"
7448e4923e5Smrg        shift
7458e4923e5Smrg        shift
7468e4923e5Smrg        ;;
747b8f75c19Smrg    *)
7488e4923e5Smrg        set fnord "$@" "$arg"
7498e4923e5Smrg        shift
7508e4923e5Smrg        shift
7518e4923e5Smrg        ;;
752b8f75c19Smrg    esac
753b8f75c19Smrg  done
7547e4fd55aSmrg  "$@" -E 2>/dev/null |
7557e4fd55aSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756b8f75c19Smrg  rm -f "$depfile"
757b8f75c19Smrg  echo "$object : \\" > "$depfile"
7588e4923e5Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7598e4923e5Smrg  echo "$tab" >> "$depfile"
7607e4fd55aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761b8f75c19Smrg  rm -f "$tmpdepfile"
762b8f75c19Smrg  ;;
763b8f75c19Smrg
7647e4fd55aSmrgmsvcmsys)
7657e4fd55aSmrg  # This case exists only to let depend.m4 do its work.  It works by
7667e4fd55aSmrg  # looking at the text of this script.  This case will never be run,
7677e4fd55aSmrg  # since it is checked for above.
7687e4fd55aSmrg  exit 1
7697e4fd55aSmrg  ;;
7707e4fd55aSmrg
771b8f75c19Smrgnone)
772b8f75c19Smrg  exec "$@"
773b8f75c19Smrg  ;;
774b8f75c19Smrg
775b8f75c19Smrg*)
776b8f75c19Smrg  echo "Unknown depmode $depmode" 1>&2
777b8f75c19Smrg  exit 1
778b8f75c19Smrg  ;;
779b8f75c19Smrgesac
780b8f75c19Smrg
781b8f75c19Smrgexit 0
7827e4fd55aSmrg
7837e4fd55aSmrg# Local Variables:
7847e4fd55aSmrg# mode: shell-script
7857e4fd55aSmrg# sh-indentation: 2
7867e4fd55aSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
7877e4fd55aSmrg# time-stamp-start: "scriptversion="
7887e4fd55aSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7897e4fd55aSmrg# time-stamp-time-zone: "UTC"
7907e4fd55aSmrg# time-stamp-end: "; # UTC"
7917e4fd55aSmrg# End:
792