13da084b3Smrg#! /bin/sh
23da084b3Smrg# depcomp - compile a program generating dependencies as side-effects
33da084b3Smrg
42a53b785Smrgscriptversion=2018-03-07.03; # UTC
53da084b3Smrg
62a53b785Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
73da084b3Smrg
83da084b3Smrg# This program is free software; you can redistribute it and/or modify
93da084b3Smrg# it under the terms of the GNU General Public License as published by
103da084b3Smrg# the Free Software Foundation; either version 2, or (at your option)
113da084b3Smrg# any later version.
123da084b3Smrg
133da084b3Smrg# This program is distributed in the hope that it will be useful,
143da084b3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
153da084b3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
163da084b3Smrg# GNU General Public License for more details.
173da084b3Smrg
183da084b3Smrg# You should have received a copy of the GNU General Public License
192a53b785Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
203da084b3Smrg
213da084b3Smrg# As a special exception to the GNU General Public License, if you
223da084b3Smrg# distribute this file as part of a program that contains a
233da084b3Smrg# configuration script generated by Autoconf, you may include it under
243da084b3Smrg# the same distribution terms that you use for the rest of that program.
253da084b3Smrg
263da084b3Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
273da084b3Smrg
283da084b3Smrgcase $1 in
293da084b3Smrg  '')
30e1c0d025Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31e1c0d025Smrg    exit 1;
32e1c0d025Smrg    ;;
333da084b3Smrg  -h | --h*)
343da084b3Smrg    cat <<\EOF
353da084b3SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
363da084b3Smrg
373da084b3SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
383da084b3Smrgas side-effects.
393da084b3Smrg
403da084b3SmrgEnvironment variables:
413da084b3Smrg  depmode     Dependency tracking mode.
42e1c0d025Smrg  source      Source file read by 'PROGRAMS ARGS'.
43e1c0d025Smrg  object      Object file output by 'PROGRAMS ARGS'.
443da084b3Smrg  DEPDIR      directory where to store dependencies.
453da084b3Smrg  depfile     Dependency file to output.
4648c85eb7Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
473da084b3Smrg  libtool     Whether libtool is used (yes/no).
483da084b3Smrg
493da084b3SmrgReport bugs to <bug-automake@gnu.org>.
503da084b3SmrgEOF
513da084b3Smrg    exit $?
523da084b3Smrg    ;;
533da084b3Smrg  -v | --v*)
543da084b3Smrg    echo "depcomp $scriptversion"
553da084b3Smrg    exit $?
563da084b3Smrg    ;;
573da084b3Smrgesac
583da084b3Smrg
59e1c0d025Smrg# Get the directory component of the given path, and save it in the
60e1c0d025Smrg# global variables '$dir'.  Note that this directory component will
61e1c0d025Smrg# be either empty or ending with a '/' character.  This is deliberate.
62e1c0d025Smrgset_dir_from ()
63e1c0d025Smrg{
64e1c0d025Smrg  case $1 in
65e1c0d025Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66e1c0d025Smrg      *) dir=;;
67e1c0d025Smrg  esac
68e1c0d025Smrg}
69e1c0d025Smrg
70e1c0d025Smrg# Get the suffix-stripped basename of the given path, and save it the
71e1c0d025Smrg# global variable '$base'.
72e1c0d025Smrgset_base_from ()
73e1c0d025Smrg{
74e1c0d025Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75e1c0d025Smrg}
76e1c0d025Smrg
77e1c0d025Smrg# If no dependency file was actually created by the compiler invocation,
78e1c0d025Smrg# we still have to create a dummy depfile, to avoid errors with the
79e1c0d025Smrg# Makefile "include basename.Plo" scheme.
80e1c0d025Smrgmake_dummy_depfile ()
81e1c0d025Smrg{
82e1c0d025Smrg  echo "#dummy" > "$depfile"
83e1c0d025Smrg}
84e1c0d025Smrg
85e1c0d025Smrg# Factor out some common post-processing of the generated depfile.
86e1c0d025Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87e1c0d025Smrgaix_post_process_depfile ()
88e1c0d025Smrg{
89e1c0d025Smrg  # If the compiler actually managed to produce a dependency file,
90e1c0d025Smrg  # post-process it.
91e1c0d025Smrg  if test -f "$tmpdepfile"; then
92e1c0d025Smrg    # Each line is of the form 'foo.o: dependency.h'.
93e1c0d025Smrg    # Do two passes, one to just change these to
94e1c0d025Smrg    #   $object: dependency.h
95e1c0d025Smrg    # and one to simply output
96e1c0d025Smrg    #   dependency.h:
97e1c0d025Smrg    # which is needed to avoid the deleted-header problem.
98e1c0d025Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99e1c0d025Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100e1c0d025Smrg    } > "$depfile"
101e1c0d025Smrg    rm -f "$tmpdepfile"
102e1c0d025Smrg  else
103e1c0d025Smrg    make_dummy_depfile
104e1c0d025Smrg  fi
105e1c0d025Smrg}
106e1c0d025Smrg
107e1c0d025Smrg# A tabulation character.
108e1c0d025Smrgtab='	'
109e1c0d025Smrg# A newline character.
110e1c0d025Smrgnl='
111e1c0d025Smrg'
112e1c0d025Smrg# Character ranges might be problematic outside the C locale.
113e1c0d025Smrg# These definitions help.
114e1c0d025Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115e1c0d025Smrglower=abcdefghijklmnopqrstuvwxyz
116e1c0d025Smrgdigits=0123456789
117e1c0d025Smrgalpha=${upper}${lower}
118e1c0d025Smrg
1193da084b3Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1203da084b3Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1213da084b3Smrg  exit 1
1223da084b3Smrgfi
1233da084b3Smrg
1243da084b3Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1253da084b3Smrgdepfile=${depfile-`echo "$object" |
1263da084b3Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1273da084b3Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1283da084b3Smrg
1293da084b3Smrgrm -f "$tmpdepfile"
1303da084b3Smrg
131e1c0d025Smrg# Avoid interferences from the environment.
132e1c0d025Smrggccflag= dashmflag=
133e1c0d025Smrg
1343da084b3Smrg# Some modes work just like other modes, but use different flags.  We
1353da084b3Smrg# parameterize here, but still list the modes in the big case below,
1363da084b3Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1373da084b3Smrg# here, because this file can only contain one case statement.
1383da084b3Smrgif test "$depmode" = hp; then
1393da084b3Smrg  # HP compiler uses -M and no extra arg.
1403da084b3Smrg  gccflag=-M
1413da084b3Smrg  depmode=gcc
1423da084b3Smrgfi
1433da084b3Smrg
1443da084b3Smrgif test "$depmode" = dashXmstdout; then
145e1c0d025Smrg  # This is just like dashmstdout with a different argument.
146e1c0d025Smrg  dashmflag=-xM
147e1c0d025Smrg  depmode=dashmstdout
1483da084b3Smrgfi
1493da084b3Smrg
15055acc8fcSmrgcygpath_u="cygpath -u -f -"
15155acc8fcSmrgif test "$depmode" = msvcmsys; then
152e1c0d025Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153e1c0d025Smrg  # Just convert the backslash-escaped backslashes to single forward
154e1c0d025Smrg  # slashes to satisfy depend.m4
155e1c0d025Smrg  cygpath_u='sed s,\\\\,/,g'
156e1c0d025Smrg  depmode=msvisualcpp
15755acc8fcSmrgfi
15855acc8fcSmrg
15948c85eb7Smrgif test "$depmode" = msvc7msys; then
160e1c0d025Smrg  # This is just like msvc7 but w/o cygpath translation.
161e1c0d025Smrg  # Just convert the backslash-escaped backslashes to single forward
162e1c0d025Smrg  # slashes to satisfy depend.m4
163e1c0d025Smrg  cygpath_u='sed s,\\\\,/,g'
164e1c0d025Smrg  depmode=msvc7
165e1c0d025Smrgfi
166e1c0d025Smrg
167e1c0d025Smrgif test "$depmode" = xlc; then
168e1c0d025Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169e1c0d025Smrg  gccflag=-qmakedep=gcc,-MF
170e1c0d025Smrg  depmode=gcc
17148c85eb7Smrgfi
17248c85eb7Smrg
1733da084b3Smrgcase "$depmode" in
1743da084b3Smrggcc3)
1753da084b3Smrg## gcc 3 implements dependency tracking that does exactly what
1763da084b3Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1773da084b3Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178d63fdb69Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179d63fdb69Smrg## the command line argument order; so add the flags where they
180d63fdb69Smrg## appear in depend2.am.  Note that the slowdown incurred here
181d63fdb69Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182d63fdb69Smrg  for arg
183d63fdb69Smrg  do
184d63fdb69Smrg    case $arg in
185d63fdb69Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186d63fdb69Smrg    *)  set fnord "$@" "$arg" ;;
187d63fdb69Smrg    esac
188d63fdb69Smrg    shift # fnord
189d63fdb69Smrg    shift # $arg
190d63fdb69Smrg  done
191d63fdb69Smrg  "$@"
1923da084b3Smrg  stat=$?
193e1c0d025Smrg  if test $stat -ne 0; then
1943da084b3Smrg    rm -f "$tmpdepfile"
1953da084b3Smrg    exit $stat
1963da084b3Smrg  fi
1973da084b3Smrg  mv "$tmpdepfile" "$depfile"
1983da084b3Smrg  ;;
1993da084b3Smrg
2003da084b3Smrggcc)
201e1c0d025Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202e1c0d025Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203e1c0d025Smrg## (see the conditional assignment to $gccflag above).
2043da084b3Smrg## There are various ways to get dependency output from gcc.  Here's
2053da084b3Smrg## why we pick this rather obscure method:
2063da084b3Smrg## - Don't want to use -MD because we'd like the dependencies to end
2073da084b3Smrg##   up in a subdir.  Having to rename by hand is ugly.
2083da084b3Smrg##   (We might end up doing this anyway to support other compilers.)
2093da084b3Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210e1c0d025Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211e1c0d025Smrg##   supported by the other compilers which use the 'gcc' depmode.
2123da084b3Smrg## - Using -M directly means running the compiler twice (even worse
2133da084b3Smrg##   than renaming).
2143da084b3Smrg  if test -z "$gccflag"; then
2153da084b3Smrg    gccflag=-MD,
2163da084b3Smrg  fi
2173da084b3Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2183da084b3Smrg  stat=$?
219e1c0d025Smrg  if test $stat -ne 0; then
2203da084b3Smrg    rm -f "$tmpdepfile"
2213da084b3Smrg    exit $stat
2223da084b3Smrg  fi
2233da084b3Smrg  rm -f "$depfile"
2243da084b3Smrg  echo "$object : \\" > "$depfile"
225e1c0d025Smrg  # The second -e expression handles DOS-style file names with drive
226e1c0d025Smrg  # letters.
2273da084b3Smrg  sed -e 's/^[^:]*: / /' \
2283da084b3Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229e1c0d025Smrg## This next piece of magic avoids the "deleted header file" problem.
2303da084b3Smrg## The problem is that when a header file which appears in a .P file
2313da084b3Smrg## is deleted, the dependency causes make to die (because there is
2323da084b3Smrg## typically no way to rebuild the header).  We avoid this by adding
2333da084b3Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2343da084b3Smrg## this for us directly.
235e1c0d025Smrg## Some versions of gcc put a space before the ':'.  On the theory
2363da084b3Smrg## that the space means something, we add a space to the output as
23748c85eb7Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23848c85eb7Smrg## to the object.  Take care to not repeat it in the output.
2393da084b3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2403da084b3Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241e1c0d025Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242e1c0d025Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243e1c0d025Smrg    | sed -e 's/$/ :/' >> "$depfile"
2443da084b3Smrg  rm -f "$tmpdepfile"
2453da084b3Smrg  ;;
2463da084b3Smrg
2473da084b3Smrghp)
2483da084b3Smrg  # This case exists only to let depend.m4 do its work.  It works by
2493da084b3Smrg  # looking at the text of this script.  This case will never be run,
2503da084b3Smrg  # since it is checked for above.
2513da084b3Smrg  exit 1
2523da084b3Smrg  ;;
2533da084b3Smrg
2543da084b3Smrgsgi)
2553da084b3Smrg  if test "$libtool" = yes; then
2563da084b3Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2573da084b3Smrg  else
2583da084b3Smrg    "$@" -MDupdate "$tmpdepfile"
2593da084b3Smrg  fi
2603da084b3Smrg  stat=$?
261e1c0d025Smrg  if test $stat -ne 0; then
2623da084b3Smrg    rm -f "$tmpdepfile"
2633da084b3Smrg    exit $stat
2643da084b3Smrg  fi
2653da084b3Smrg  rm -f "$depfile"
2663da084b3Smrg
2673da084b3Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2683da084b3Smrg    echo "$object : \\" > "$depfile"
2693da084b3Smrg    # Clip off the initial element (the dependent).  Don't try to be
2703da084b3Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2713da084b3Smrg    # lines with more than a fixed number of characters (4096 in
2723da084b3Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273e1c0d025Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2743da084b3Smrg    # dependency line.
275e1c0d025Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276e1c0d025Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277e1c0d025Smrg      | tr "$nl" ' ' >> "$depfile"
27855acc8fcSmrg    echo >> "$depfile"
2793da084b3Smrg    # The second pass generates a dummy entry for each header file.
280e1c0d025Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281e1c0d025Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282e1c0d025Smrg      >> "$depfile"
2833da084b3Smrg  else
284e1c0d025Smrg    make_dummy_depfile
2853da084b3Smrg  fi
2863da084b3Smrg  rm -f "$tmpdepfile"
2873da084b3Smrg  ;;
2883da084b3Smrg
289e1c0d025Smrgxlc)
290e1c0d025Smrg  # This case exists only to let depend.m4 do its work.  It works by
291e1c0d025Smrg  # looking at the text of this script.  This case will never be run,
292e1c0d025Smrg  # since it is checked for above.
293e1c0d025Smrg  exit 1
294e1c0d025Smrg  ;;
295e1c0d025Smrg
2963da084b3Smrgaix)
2973da084b3Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2983da084b3Smrg  # in a .u file.  In older versions, this file always lives in the
299e1c0d025Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3003da084b3Smrg  # start of each line; $object doesn't have directory information.
3013da084b3Smrg  # Version 6 uses the directory in both cases.
302e1c0d025Smrg  set_dir_from "$object"
303e1c0d025Smrg  set_base_from "$object"
3043da084b3Smrg  if test "$libtool" = yes; then
305d63fdb69Smrg    tmpdepfile1=$dir$base.u
306d63fdb69Smrg    tmpdepfile2=$base.u
307d63fdb69Smrg    tmpdepfile3=$dir.libs/$base.u
3083da084b3Smrg    "$@" -Wc,-M
3093da084b3Smrg  else
310d63fdb69Smrg    tmpdepfile1=$dir$base.u
311d63fdb69Smrg    tmpdepfile2=$dir$base.u
312d63fdb69Smrg    tmpdepfile3=$dir$base.u
3133da084b3Smrg    "$@" -M
3143da084b3Smrg  fi
3153da084b3Smrg  stat=$?
316e1c0d025Smrg  if test $stat -ne 0; then
317d63fdb69Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3183da084b3Smrg    exit $stat
3193da084b3Smrg  fi
3203da084b3Smrg
321d63fdb69Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322d63fdb69Smrg  do
323d63fdb69Smrg    test -f "$tmpdepfile" && break
324d63fdb69Smrg  done
325e1c0d025Smrg  aix_post_process_depfile
326e1c0d025Smrg  ;;
327e1c0d025Smrg
328e1c0d025Smrgtcc)
329e1c0d025Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330e1c0d025Smrg  # FIXME: That version still under development at the moment of writing.
331e1c0d025Smrg  #        Make that this statement remains true also for stable, released
332e1c0d025Smrg  #        versions.
333e1c0d025Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334e1c0d025Smrg  # trailing '\', as in:
335e1c0d025Smrg  #
336e1c0d025Smrg  #   foo.o : \
337e1c0d025Smrg  #    foo.c \
338e1c0d025Smrg  #    foo.h \
339e1c0d025Smrg  #
340e1c0d025Smrg  # It will put a trailing '\' even on the last line, and will use leading
341e1c0d025Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342e1c0d025Smrg  # "Emit spaces for -MD").
343e1c0d025Smrg  "$@" -MD -MF "$tmpdepfile"
344e1c0d025Smrg  stat=$?
345e1c0d025Smrg  if test $stat -ne 0; then
346e1c0d025Smrg    rm -f "$tmpdepfile"
347e1c0d025Smrg    exit $stat
3483da084b3Smrg  fi
349e1c0d025Smrg  rm -f "$depfile"
350e1c0d025Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351e1c0d025Smrg  # We have to change lines of the first kind to '$object: \'.
352e1c0d025Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353e1c0d025Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354e1c0d025Smrg  # dummy dependency, to avoid the deleted-header problem.
355e1c0d025Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3563da084b3Smrg  rm -f "$tmpdepfile"
3573da084b3Smrg  ;;
3583da084b3Smrg
359e1c0d025Smrg## The order of this option in the case statement is important, since the
360e1c0d025Smrg## shell code in configure will try each of these formats in the order
361e1c0d025Smrg## listed in this file.  A plain '-MD' option would be understood by many
362e1c0d025Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363e1c0d025Smrgpgcc)
364e1c0d025Smrg  # Portland's C compiler understands '-MD'.
365e1c0d025Smrg  # Will always output deps to 'file.d' where file is the root name of the
366e1c0d025Smrg  # source file under compilation, even if file resides in a subdirectory.
367e1c0d025Smrg  # The object file name does not affect the name of the '.d' file.
368e1c0d025Smrg  # pgcc 10.2 will output
3693da084b3Smrg  #    foo.o: sub/foo.c sub/foo.h
370e1c0d025Smrg  # and will wrap long lines using '\' :
3713da084b3Smrg  #    foo.o: sub/foo.c ... \
3723da084b3Smrg  #     sub/foo.h ... \
3733da084b3Smrg  #     ...
374e1c0d025Smrg  set_dir_from "$object"
375e1c0d025Smrg  # Use the source, not the object, to determine the base name, since
376e1c0d025Smrg  # that's sadly what pgcc will do too.
377e1c0d025Smrg  set_base_from "$source"
378e1c0d025Smrg  tmpdepfile=$base.d
379e1c0d025Smrg
380e1c0d025Smrg  # For projects that build the same source file twice into different object
381e1c0d025Smrg  # files, the pgcc approach of using the *source* file root name can cause
382e1c0d025Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383e1c0d025Smrg  # the same $tmpdepfile.
384e1c0d025Smrg  lockdir=$base.d-lock
385e1c0d025Smrg  trap "
386e1c0d025Smrg    echo '$0: caught signal, cleaning up...' >&2
387e1c0d025Smrg    rmdir '$lockdir'
388e1c0d025Smrg    exit 1
389e1c0d025Smrg  " 1 2 13 15
390e1c0d025Smrg  numtries=100
391e1c0d025Smrg  i=$numtries
392e1c0d025Smrg  while test $i -gt 0; do
393e1c0d025Smrg    # mkdir is a portable test-and-set.
394e1c0d025Smrg    if mkdir "$lockdir" 2>/dev/null; then
395e1c0d025Smrg      # This process acquired the lock.
396e1c0d025Smrg      "$@" -MD
397e1c0d025Smrg      stat=$?
398e1c0d025Smrg      # Release the lock.
399e1c0d025Smrg      rmdir "$lockdir"
400e1c0d025Smrg      break
401e1c0d025Smrg    else
402e1c0d025Smrg      # If the lock is being held by a different process, wait
403e1c0d025Smrg      # until the winning process is done or we timeout.
404e1c0d025Smrg      while test -d "$lockdir" && test $i -gt 0; do
405e1c0d025Smrg        sleep 1
406e1c0d025Smrg        i=`expr $i - 1`
407e1c0d025Smrg      done
408e1c0d025Smrg    fi
409e1c0d025Smrg    i=`expr $i - 1`
410e1c0d025Smrg  done
411e1c0d025Smrg  trap - 1 2 13 15
412e1c0d025Smrg  if test $i -le 0; then
413e1c0d025Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414e1c0d025Smrg    echo "$0: check lockdir '$lockdir'" >&2
415e1c0d025Smrg    exit 1
416e1c0d025Smrg  fi
4173da084b3Smrg
418e1c0d025Smrg  if test $stat -ne 0; then
4193da084b3Smrg    rm -f "$tmpdepfile"
4203da084b3Smrg    exit $stat
4213da084b3Smrg  fi
4223da084b3Smrg  rm -f "$depfile"
4233da084b3Smrg  # Each line is of the form `foo.o: dependent.h',
4243da084b3Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4253da084b3Smrg  # Do two passes, one to just change these to
4263da084b3Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4273da084b3Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4283da084b3Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4293da084b3Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430e1c0d025Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431e1c0d025Smrg    | sed -e 's/$/ :/' >> "$depfile"
4323da084b3Smrg  rm -f "$tmpdepfile"
4333da084b3Smrg  ;;
4343da084b3Smrg
435d63fdb69Smrghp2)
436d63fdb69Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437d63fdb69Smrg  # compilers, which have integrated preprocessors.  The correct option
438d63fdb69Smrg  # to use with these is +Maked; it writes dependencies to a file named
439d63fdb69Smrg  # 'foo.d', which lands next to the object file, wherever that
440d63fdb69Smrg  # happens to be.
441d63fdb69Smrg  # Much of this is similar to the tru64 case; see comments there.
442e1c0d025Smrg  set_dir_from  "$object"
443e1c0d025Smrg  set_base_from "$object"
444d63fdb69Smrg  if test "$libtool" = yes; then
445d63fdb69Smrg    tmpdepfile1=$dir$base.d
446d63fdb69Smrg    tmpdepfile2=$dir.libs/$base.d
447d63fdb69Smrg    "$@" -Wc,+Maked
448d63fdb69Smrg  else
449d63fdb69Smrg    tmpdepfile1=$dir$base.d
450d63fdb69Smrg    tmpdepfile2=$dir$base.d
451d63fdb69Smrg    "$@" +Maked
452d63fdb69Smrg  fi
453d63fdb69Smrg  stat=$?
454e1c0d025Smrg  if test $stat -ne 0; then
455d63fdb69Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456d63fdb69Smrg     exit $stat
457d63fdb69Smrg  fi
458d63fdb69Smrg
459d63fdb69Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460d63fdb69Smrg  do
461d63fdb69Smrg    test -f "$tmpdepfile" && break
462d63fdb69Smrg  done
463d63fdb69Smrg  if test -f "$tmpdepfile"; then
464e1c0d025Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465e1c0d025Smrg    # Add 'dependent.h:' lines.
46655acc8fcSmrg    sed -ne '2,${
467e1c0d025Smrg               s/^ *//
468e1c0d025Smrg               s/ \\*$//
469e1c0d025Smrg               s/$/:/
470e1c0d025Smrg               p
471e1c0d025Smrg             }' "$tmpdepfile" >> "$depfile"
472d63fdb69Smrg  else
473e1c0d025Smrg    make_dummy_depfile
474d63fdb69Smrg  fi
475d63fdb69Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476d63fdb69Smrg  ;;
477d63fdb69Smrg
4783da084b3Smrgtru64)
479e1c0d025Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480e1c0d025Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481e1c0d025Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482e1c0d025Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483e1c0d025Smrg  # Subdirectories are respected.
484e1c0d025Smrg  set_dir_from  "$object"
485e1c0d025Smrg  set_base_from "$object"
486e1c0d025Smrg
487e1c0d025Smrg  if test "$libtool" = yes; then
488e1c0d025Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489e1c0d025Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490e1c0d025Smrg    # in $dir$base.o.d.  We have to check for both files, because
491e1c0d025Smrg    # one of the two compilations can be disabled.  We should prefer
492e1c0d025Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493e1c0d025Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494e1c0d025Smrg    # the former would cause a distcleancheck panic.
495e1c0d025Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496e1c0d025Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497e1c0d025Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498e1c0d025Smrg    "$@" -Wc,-MD
499e1c0d025Smrg  else
500e1c0d025Smrg    tmpdepfile1=$dir$base.d
501e1c0d025Smrg    tmpdepfile2=$dir$base.d
502e1c0d025Smrg    tmpdepfile3=$dir$base.d
503e1c0d025Smrg    "$@" -MD
504e1c0d025Smrg  fi
505e1c0d025Smrg
506e1c0d025Smrg  stat=$?
507e1c0d025Smrg  if test $stat -ne 0; then
508e1c0d025Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509e1c0d025Smrg    exit $stat
510e1c0d025Smrg  fi
511e1c0d025Smrg
512e1c0d025Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513e1c0d025Smrg  do
514e1c0d025Smrg    test -f "$tmpdepfile" && break
515e1c0d025Smrg  done
516e1c0d025Smrg  # Same post-processing that is required for AIX mode.
517e1c0d025Smrg  aix_post_process_depfile
518e1c0d025Smrg  ;;
5193da084b3Smrg
52048c85eb7Smrgmsvc7)
52148c85eb7Smrg  if test "$libtool" = yes; then
52248c85eb7Smrg    showIncludes=-Wc,-showIncludes
52348c85eb7Smrg  else
52448c85eb7Smrg    showIncludes=-showIncludes
52548c85eb7Smrg  fi
52648c85eb7Smrg  "$@" $showIncludes > "$tmpdepfile"
52748c85eb7Smrg  stat=$?
52848c85eb7Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529e1c0d025Smrg  if test $stat -ne 0; then
53048c85eb7Smrg    rm -f "$tmpdepfile"
53148c85eb7Smrg    exit $stat
53248c85eb7Smrg  fi
53348c85eb7Smrg  rm -f "$depfile"
53448c85eb7Smrg  echo "$object : \\" > "$depfile"
53548c85eb7Smrg  # The first sed program below extracts the file names and escapes
53648c85eb7Smrg  # backslashes for cygpath.  The second sed program outputs the file
53748c85eb7Smrg  # name when reading, but also accumulates all include files in the
53848c85eb7Smrg  # hold buffer in order to output them again at the end.  This only
53948c85eb7Smrg  # works with sed implementations that can handle large buffers.
54048c85eb7Smrg  sed < "$tmpdepfile" -n '
54148c85eb7Smrg/^Note: including file:  *\(.*\)/ {
54248c85eb7Smrg  s//\1/
54348c85eb7Smrg  s/\\/\\\\/g
54448c85eb7Smrg  p
54548c85eb7Smrg}' | $cygpath_u | sort -u | sed -n '
54648c85eb7Smrgs/ /\\ /g
547e1c0d025Smrgs/\(.*\)/'"$tab"'\1 \\/p
54848c85eb7Smrgs/.\(.*\) \\/\1:/
54948c85eb7SmrgH
55048c85eb7Smrg$ {
551e1c0d025Smrg  s/.*/'"$tab"'/
55248c85eb7Smrg  G
55348c85eb7Smrg  p
55448c85eb7Smrg}' >> "$depfile"
555e1c0d025Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55648c85eb7Smrg  rm -f "$tmpdepfile"
55748c85eb7Smrg  ;;
55848c85eb7Smrg
55948c85eb7Smrgmsvc7msys)
56048c85eb7Smrg  # This case exists only to let depend.m4 do its work.  It works by
56148c85eb7Smrg  # looking at the text of this script.  This case will never be run,
56248c85eb7Smrg  # since it is checked for above.
56348c85eb7Smrg  exit 1
56448c85eb7Smrg  ;;
56548c85eb7Smrg
5663da084b3Smrg#nosideeffect)
5673da084b3Smrg  # This comment above is used by automake to tell side-effect
5683da084b3Smrg  # dependency tracking mechanisms from slower ones.
5693da084b3Smrg
5703da084b3Smrgdashmstdout)
5713da084b3Smrg  # Important note: in order to support this mode, a compiler *must*
5723da084b3Smrg  # always write the preprocessed file to stdout, regardless of -o.
5733da084b3Smrg  "$@" || exit $?
5743da084b3Smrg
5753da084b3Smrg  # Remove the call to Libtool.
5763da084b3Smrg  if test "$libtool" = yes; then
57755acc8fcSmrg    while test "X$1" != 'X--mode=compile'; do
5783da084b3Smrg      shift
5793da084b3Smrg    done
5803da084b3Smrg    shift
5813da084b3Smrg  fi
5823da084b3Smrg
583e1c0d025Smrg  # Remove '-o $object'.
5843da084b3Smrg  IFS=" "
5853da084b3Smrg  for arg
5863da084b3Smrg  do
5873da084b3Smrg    case $arg in
5883da084b3Smrg    -o)
5893da084b3Smrg      shift
5903da084b3Smrg      ;;
5913da084b3Smrg    $object)
5923da084b3Smrg      shift
5933da084b3Smrg      ;;
5943da084b3Smrg    *)
5953da084b3Smrg      set fnord "$@" "$arg"
5963da084b3Smrg      shift # fnord
5973da084b3Smrg      shift # $arg
5983da084b3Smrg      ;;
5993da084b3Smrg    esac
6003da084b3Smrg  done
6013da084b3Smrg
6023da084b3Smrg  test -z "$dashmflag" && dashmflag=-M
603e1c0d025Smrg  # Require at least two characters before searching for ':'
6043da084b3Smrg  # in the target name.  This is to cope with DOS-style filenames:
605e1c0d025Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6063da084b3Smrg  "$@" $dashmflag |
607e1c0d025Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6083da084b3Smrg  rm -f "$depfile"
6093da084b3Smrg  cat < "$tmpdepfile" > "$depfile"
610e1c0d025Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611e1c0d025Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612e1c0d025Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613e1c0d025Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614e1c0d025Smrg    | sed -e 's/$/ :/' >> "$depfile"
6153da084b3Smrg  rm -f "$tmpdepfile"
6163da084b3Smrg  ;;
6173da084b3Smrg
6183da084b3SmrgdashXmstdout)
6193da084b3Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6203da084b3Smrg  # run, as this mode is specially recognized in the preamble.
6213da084b3Smrg  exit 1
6223da084b3Smrg  ;;
6233da084b3Smrg
6243da084b3Smrgmakedepend)
6253da084b3Smrg  "$@" || exit $?
6263da084b3Smrg  # Remove any Libtool call
6273da084b3Smrg  if test "$libtool" = yes; then
62855acc8fcSmrg    while test "X$1" != 'X--mode=compile'; do
6293da084b3Smrg      shift
6303da084b3Smrg    done
6313da084b3Smrg    shift
6323da084b3Smrg  fi
6333da084b3Smrg  # X makedepend
6343da084b3Smrg  shift
63555acc8fcSmrg  cleared=no eat=no
63655acc8fcSmrg  for arg
63755acc8fcSmrg  do
6383da084b3Smrg    case $cleared in
6393da084b3Smrg    no)
6403da084b3Smrg      set ""; shift
6413da084b3Smrg      cleared=yes ;;
6423da084b3Smrg    esac
64355acc8fcSmrg    if test $eat = yes; then
64455acc8fcSmrg      eat=no
64555acc8fcSmrg      continue
64655acc8fcSmrg    fi
6473da084b3Smrg    case "$arg" in
6483da084b3Smrg    -D*|-I*)
6493da084b3Smrg      set fnord "$@" "$arg"; shift ;;
6503da084b3Smrg    # Strip any option that makedepend may not understand.  Remove
6513da084b3Smrg    # the object too, otherwise makedepend will parse it as a source file.
65255acc8fcSmrg    -arch)
65355acc8fcSmrg      eat=yes ;;
6543da084b3Smrg    -*|$object)
6553da084b3Smrg      ;;
6563da084b3Smrg    *)
6573da084b3Smrg      set fnord "$@" "$arg"; shift ;;
6583da084b3Smrg    esac
6593da084b3Smrg  done
66055acc8fcSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6613da084b3Smrg  touch "$tmpdepfile"
6623da084b3Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6633da084b3Smrg  rm -f "$depfile"
66448c85eb7Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66548c85eb7Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66648c85eb7Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667e1c0d025Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668e1c0d025Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669e1c0d025Smrg  sed '1,2d' "$tmpdepfile" \
670e1c0d025Smrg    | tr ' ' "$nl" \
671e1c0d025Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672e1c0d025Smrg    | sed -e 's/$/ :/' >> "$depfile"
6733da084b3Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6743da084b3Smrg  ;;
6753da084b3Smrg
6763da084b3Smrgcpp)
6773da084b3Smrg  # Important note: in order to support this mode, a compiler *must*
6783da084b3Smrg  # always write the preprocessed file to stdout.
6793da084b3Smrg  "$@" || exit $?
6803da084b3Smrg
6813da084b3Smrg  # Remove the call to Libtool.
6823da084b3Smrg  if test "$libtool" = yes; then
68355acc8fcSmrg    while test "X$1" != 'X--mode=compile'; do
6843da084b3Smrg      shift
6853da084b3Smrg    done
6863da084b3Smrg    shift
6873da084b3Smrg  fi
6883da084b3Smrg
689e1c0d025Smrg  # Remove '-o $object'.
6903da084b3Smrg  IFS=" "
6913da084b3Smrg  for arg
6923da084b3Smrg  do
6933da084b3Smrg    case $arg in
6943da084b3Smrg    -o)
6953da084b3Smrg      shift
6963da084b3Smrg      ;;
6973da084b3Smrg    $object)
6983da084b3Smrg      shift
6993da084b3Smrg      ;;
7003da084b3Smrg    *)
7013da084b3Smrg      set fnord "$@" "$arg"
7023da084b3Smrg      shift # fnord
7033da084b3Smrg      shift # $arg
7043da084b3Smrg      ;;
7053da084b3Smrg    esac
7063da084b3Smrg  done
7073da084b3Smrg
708e1c0d025Smrg  "$@" -E \
709e1c0d025Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710e1c0d025Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711e1c0d025Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7123da084b3Smrg  rm -f "$depfile"
7133da084b3Smrg  echo "$object : \\" > "$depfile"
7143da084b3Smrg  cat < "$tmpdepfile" >> "$depfile"
7153da084b3Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7163da084b3Smrg  rm -f "$tmpdepfile"
7173da084b3Smrg  ;;
7183da084b3Smrg
7193da084b3Smrgmsvisualcpp)
7203da084b3Smrg  # Important note: in order to support this mode, a compiler *must*
72155acc8fcSmrg  # always write the preprocessed file to stdout.
7223da084b3Smrg  "$@" || exit $?
72355acc8fcSmrg
72455acc8fcSmrg  # Remove the call to Libtool.
72555acc8fcSmrg  if test "$libtool" = yes; then
72655acc8fcSmrg    while test "X$1" != 'X--mode=compile'; do
72755acc8fcSmrg      shift
72855acc8fcSmrg    done
72955acc8fcSmrg    shift
73055acc8fcSmrg  fi
73155acc8fcSmrg
7323da084b3Smrg  IFS=" "
7333da084b3Smrg  for arg
7343da084b3Smrg  do
7353da084b3Smrg    case "$arg" in
73655acc8fcSmrg    -o)
73755acc8fcSmrg      shift
73855acc8fcSmrg      ;;
73955acc8fcSmrg    $object)
74055acc8fcSmrg      shift
74155acc8fcSmrg      ;;
7423da084b3Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743e1c0d025Smrg        set fnord "$@"
744e1c0d025Smrg        shift
745e1c0d025Smrg        shift
746e1c0d025Smrg        ;;
7473da084b3Smrg    *)
748e1c0d025Smrg        set fnord "$@" "$arg"
749e1c0d025Smrg        shift
750e1c0d025Smrg        shift
751e1c0d025Smrg        ;;
7523da084b3Smrg    esac
7533da084b3Smrg  done
75455acc8fcSmrg  "$@" -E 2>/dev/null |
75555acc8fcSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7563da084b3Smrg  rm -f "$depfile"
7573da084b3Smrg  echo "$object : \\" > "$depfile"
758e1c0d025Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759e1c0d025Smrg  echo "$tab" >> "$depfile"
76055acc8fcSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7613da084b3Smrg  rm -f "$tmpdepfile"
7623da084b3Smrg  ;;
7633da084b3Smrg
76455acc8fcSmrgmsvcmsys)
76555acc8fcSmrg  # This case exists only to let depend.m4 do its work.  It works by
76655acc8fcSmrg  # looking at the text of this script.  This case will never be run,
76755acc8fcSmrg  # since it is checked for above.
76855acc8fcSmrg  exit 1
76955acc8fcSmrg  ;;
77055acc8fcSmrg
7713da084b3Smrgnone)
7723da084b3Smrg  exec "$@"
7733da084b3Smrg  ;;
7743da084b3Smrg
7753da084b3Smrg*)
7763da084b3Smrg  echo "Unknown depmode $depmode" 1>&2
7773da084b3Smrg  exit 1
7783da084b3Smrg  ;;
7793da084b3Smrgesac
7803da084b3Smrg
7813da084b3Smrgexit 0
7823da084b3Smrg
7833da084b3Smrg# Local Variables:
7843da084b3Smrg# mode: shell-script
7853da084b3Smrg# sh-indentation: 2
7862a53b785Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
7873da084b3Smrg# time-stamp-start: "scriptversion="
7883da084b3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7892a53b785Smrg# time-stamp-time-zone: "UTC0"
79055acc8fcSmrg# time-stamp-end: "; # UTC"
7913da084b3Smrg# End:
792