1126a8a12Smrg#! /bin/sh
2126a8a12Smrg# depcomp - compile a program generating dependencies as side-effects
3126a8a12Smrg
46bea0e4fSmrgscriptversion=2024-06-19.01; # UTC
5126a8a12Smrg
66bea0e4fSmrg# Copyright (C) 1999-2024 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
193fb97780Smrg# along with this program.  If not, see <https://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>.
506bea0e4fSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
516bea0e4fSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>.
52126a8a12SmrgEOF
53126a8a12Smrg    exit $?
54126a8a12Smrg    ;;
55126a8a12Smrg  -v | --v*)
566bea0e4fSmrg    echo "depcomp (GNU Automake) $scriptversion"
57126a8a12Smrg    exit $?
58126a8a12Smrg    ;;
59126a8a12Smrgesac
60126a8a12Smrg
610a6b08f8Smrg# Get the directory component of the given path, and save it in the
620a6b08f8Smrg# global variables '$dir'.  Note that this directory component will
630a6b08f8Smrg# be either empty or ending with a '/' character.  This is deliberate.
640a6b08f8Smrgset_dir_from ()
650a6b08f8Smrg{
660a6b08f8Smrg  case $1 in
670a6b08f8Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
680a6b08f8Smrg      *) dir=;;
690a6b08f8Smrg  esac
700a6b08f8Smrg}
710a6b08f8Smrg
720a6b08f8Smrg# Get the suffix-stripped basename of the given path, and save it the
730a6b08f8Smrg# global variable '$base'.
740a6b08f8Smrgset_base_from ()
750a6b08f8Smrg{
760a6b08f8Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
770a6b08f8Smrg}
780a6b08f8Smrg
790a6b08f8Smrg# If no dependency file was actually created by the compiler invocation,
800a6b08f8Smrg# we still have to create a dummy depfile, to avoid errors with the
810a6b08f8Smrg# Makefile "include basename.Plo" scheme.
820a6b08f8Smrgmake_dummy_depfile ()
830a6b08f8Smrg{
840a6b08f8Smrg  echo "#dummy" > "$depfile"
850a6b08f8Smrg}
860a6b08f8Smrg
870a6b08f8Smrg# Factor out some common post-processing of the generated depfile.
880a6b08f8Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
890a6b08f8Smrgaix_post_process_depfile ()
900a6b08f8Smrg{
910a6b08f8Smrg  # If the compiler actually managed to produce a dependency file,
920a6b08f8Smrg  # post-process it.
930a6b08f8Smrg  if test -f "$tmpdepfile"; then
940a6b08f8Smrg    # Each line is of the form 'foo.o: dependency.h'.
950a6b08f8Smrg    # Do two passes, one to just change these to
960a6b08f8Smrg    #   $object: dependency.h
970a6b08f8Smrg    # and one to simply output
980a6b08f8Smrg    #   dependency.h:
990a6b08f8Smrg    # which is needed to avoid the deleted-header problem.
1000a6b08f8Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
1010a6b08f8Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1020a6b08f8Smrg    } > "$depfile"
1030a6b08f8Smrg    rm -f "$tmpdepfile"
1040a6b08f8Smrg  else
1050a6b08f8Smrg    make_dummy_depfile
1060a6b08f8Smrg  fi
1070a6b08f8Smrg}
1080a6b08f8Smrg
1090a6b08f8Smrg# A tabulation character.
1100a6b08f8Smrgtab='	'
1110a6b08f8Smrg# A newline character.
1120a6b08f8Smrgnl='
1130a6b08f8Smrg'
1140a6b08f8Smrg# Character ranges might be problematic outside the C locale.
1150a6b08f8Smrg# These definitions help.
1160a6b08f8Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1170a6b08f8Smrglower=abcdefghijklmnopqrstuvwxyz
1180a6b08f8Smrgalpha=${upper}${lower}
1190a6b08f8Smrg
120126a8a12Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
121126a8a12Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
122126a8a12Smrg  exit 1
123126a8a12Smrgfi
124126a8a12Smrg
125126a8a12Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
126126a8a12Smrgdepfile=${depfile-`echo "$object" |
127126a8a12Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
128126a8a12Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
129126a8a12Smrg
130126a8a12Smrgrm -f "$tmpdepfile"
131126a8a12Smrg
1326bea0e4fSmrg# Avoid interference from the environment.
1330a6b08f8Smrggccflag= dashmflag=
1340a6b08f8Smrg
135126a8a12Smrg# Some modes work just like other modes, but use different flags.  We
136126a8a12Smrg# parameterize here, but still list the modes in the big case below,
137126a8a12Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
138126a8a12Smrg# here, because this file can only contain one case statement.
139126a8a12Smrgif test "$depmode" = hp; then
140126a8a12Smrg  # HP compiler uses -M and no extra arg.
141126a8a12Smrg  gccflag=-M
142126a8a12Smrg  depmode=gcc
143126a8a12Smrgfi
144126a8a12Smrg
145126a8a12Smrgif test "$depmode" = dashXmstdout; then
1460a6b08f8Smrg  # This is just like dashmstdout with a different argument.
1470a6b08f8Smrg  dashmflag=-xM
1480a6b08f8Smrg  depmode=dashmstdout
149126a8a12Smrgfi
150126a8a12Smrg
151d656433aSmrgcygpath_u="cygpath -u -f -"
152d656433aSmrgif test "$depmode" = msvcmsys; then
1530a6b08f8Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1540a6b08f8Smrg  # Just convert the backslash-escaped backslashes to single forward
1550a6b08f8Smrg  # slashes to satisfy depend.m4
1560a6b08f8Smrg  cygpath_u='sed s,\\\\,/,g'
1570a6b08f8Smrg  depmode=msvisualcpp
1580a6b08f8Smrgfi
1590a6b08f8Smrg
1600a6b08f8Smrgif test "$depmode" = msvc7msys; then
1610a6b08f8Smrg  # This is just like msvc7 but w/o cygpath translation.
1620a6b08f8Smrg  # Just convert the backslash-escaped backslashes to single forward
1630a6b08f8Smrg  # slashes to satisfy depend.m4
1640a6b08f8Smrg  cygpath_u='sed s,\\\\,/,g'
1650a6b08f8Smrg  depmode=msvc7
1660a6b08f8Smrgfi
1670a6b08f8Smrg
1680a6b08f8Smrgif test "$depmode" = xlc; then
1690a6b08f8Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1700a6b08f8Smrg  gccflag=-qmakedep=gcc,-MF
1710a6b08f8Smrg  depmode=gcc
172d656433aSmrgfi
173d656433aSmrg
174126a8a12Smrgcase "$depmode" in
175126a8a12Smrggcc3)
176126a8a12Smrg## gcc 3 implements dependency tracking that does exactly what
177126a8a12Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
178126a8a12Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
179126a8a12Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
180126a8a12Smrg## the command line argument order; so add the flags where they
181126a8a12Smrg## appear in depend2.am.  Note that the slowdown incurred here
182126a8a12Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
183126a8a12Smrg  for arg
184126a8a12Smrg  do
185126a8a12Smrg    case $arg in
186126a8a12Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
187126a8a12Smrg    *)  set fnord "$@" "$arg" ;;
188126a8a12Smrg    esac
189126a8a12Smrg    shift # fnord
190126a8a12Smrg    shift # $arg
191126a8a12Smrg  done
192126a8a12Smrg  "$@"
193126a8a12Smrg  stat=$?
1940a6b08f8Smrg  if test $stat -ne 0; then
195126a8a12Smrg    rm -f "$tmpdepfile"
196126a8a12Smrg    exit $stat
197126a8a12Smrg  fi
198126a8a12Smrg  mv "$tmpdepfile" "$depfile"
199126a8a12Smrg  ;;
200126a8a12Smrg
201126a8a12Smrggcc)
2026bea0e4fSmrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers.
2036bea0e4fSmrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler.
2040a6b08f8Smrg## (see the conditional assignment to $gccflag above).
205126a8a12Smrg## There are various ways to get dependency output from gcc.  Here's
206126a8a12Smrg## why we pick this rather obscure method:
207126a8a12Smrg## - Don't want to use -MD because we'd like the dependencies to end
208126a8a12Smrg##   up in a subdir.  Having to rename by hand is ugly.
209126a8a12Smrg##   (We might end up doing this anyway to support other compilers.)
210126a8a12Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2110a6b08f8Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2120a6b08f8Smrg##   supported by the other compilers which use the 'gcc' depmode.
213126a8a12Smrg## - Using -M directly means running the compiler twice (even worse
214126a8a12Smrg##   than renaming).
215126a8a12Smrg  if test -z "$gccflag"; then
216126a8a12Smrg    gccflag=-MD,
217126a8a12Smrg  fi
218126a8a12Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
219126a8a12Smrg  stat=$?
2200a6b08f8Smrg  if test $stat -ne 0; then
221126a8a12Smrg    rm -f "$tmpdepfile"
222126a8a12Smrg    exit $stat
223126a8a12Smrg  fi
224126a8a12Smrg  rm -f "$depfile"
225126a8a12Smrg  echo "$object : \\" > "$depfile"
2260a6b08f8Smrg  # The second -e expression handles DOS-style file names with drive
2270a6b08f8Smrg  # letters.
228126a8a12Smrg  sed -e 's/^[^:]*: / /' \
229126a8a12Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2300a6b08f8Smrg## This next piece of magic avoids the "deleted header file" problem.
231126a8a12Smrg## The problem is that when a header file which appears in a .P file
232126a8a12Smrg## is deleted, the dependency causes make to die (because there is
233126a8a12Smrg## typically no way to rebuild the header).  We avoid this by adding
234126a8a12Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
235126a8a12Smrg## this for us directly.
2360a6b08f8Smrg## Some versions of gcc put a space before the ':'.  On the theory
237126a8a12Smrg## that the space means something, we add a space to the output as
2380a6b08f8Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2390a6b08f8Smrg## to the object.  Take care to not repeat it in the output.
240126a8a12Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
241126a8a12Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2420a6b08f8Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2430a6b08f8Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2440a6b08f8Smrg    | sed -e 's/$/ :/' >> "$depfile"
245126a8a12Smrg  rm -f "$tmpdepfile"
246126a8a12Smrg  ;;
247126a8a12Smrg
248126a8a12Smrghp)
249126a8a12Smrg  # This case exists only to let depend.m4 do its work.  It works by
250126a8a12Smrg  # looking at the text of this script.  This case will never be run,
251126a8a12Smrg  # since it is checked for above.
252126a8a12Smrg  exit 1
253126a8a12Smrg  ;;
254126a8a12Smrg
255126a8a12Smrgsgi)
256126a8a12Smrg  if test "$libtool" = yes; then
257126a8a12Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
258126a8a12Smrg  else
259126a8a12Smrg    "$@" -MDupdate "$tmpdepfile"
260126a8a12Smrg  fi
261126a8a12Smrg  stat=$?
2620a6b08f8Smrg  if test $stat -ne 0; then
263126a8a12Smrg    rm -f "$tmpdepfile"
264126a8a12Smrg    exit $stat
265126a8a12Smrg  fi
266126a8a12Smrg  rm -f "$depfile"
267126a8a12Smrg
268126a8a12Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
269126a8a12Smrg    echo "$object : \\" > "$depfile"
270126a8a12Smrg    # Clip off the initial element (the dependent).  Don't try to be
271126a8a12Smrg    # clever and replace this with sed code, as IRIX sed won't handle
272126a8a12Smrg    # lines with more than a fixed number of characters (4096 in
273126a8a12Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2740a6b08f8Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
275126a8a12Smrg    # dependency line.
2760a6b08f8Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2770a6b08f8Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2780a6b08f8Smrg      | tr "$nl" ' ' >> "$depfile"
279d656433aSmrg    echo >> "$depfile"
280126a8a12Smrg    # The second pass generates a dummy entry for each header file.
2810a6b08f8Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2820a6b08f8Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2830a6b08f8Smrg      >> "$depfile"
284126a8a12Smrg  else
2850a6b08f8Smrg    make_dummy_depfile
286126a8a12Smrg  fi
287126a8a12Smrg  rm -f "$tmpdepfile"
288126a8a12Smrg  ;;
289126a8a12Smrg
2900a6b08f8Smrgxlc)
2910a6b08f8Smrg  # This case exists only to let depend.m4 do its work.  It works by
2920a6b08f8Smrg  # looking at the text of this script.  This case will never be run,
2930a6b08f8Smrg  # since it is checked for above.
2940a6b08f8Smrg  exit 1
2950a6b08f8Smrg  ;;
2960a6b08f8Smrg
297126a8a12Smrgaix)
298126a8a12Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
299126a8a12Smrg  # in a .u file.  In older versions, this file always lives in the
3000a6b08f8Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
301126a8a12Smrg  # start of each line; $object doesn't have directory information.
302126a8a12Smrg  # Version 6 uses the directory in both cases.
3030a6b08f8Smrg  set_dir_from "$object"
3040a6b08f8Smrg  set_base_from "$object"
305126a8a12Smrg  if test "$libtool" = yes; then
306d656433aSmrg    tmpdepfile1=$dir$base.u
307d656433aSmrg    tmpdepfile2=$base.u
308d656433aSmrg    tmpdepfile3=$dir.libs/$base.u
309126a8a12Smrg    "$@" -Wc,-M
310126a8a12Smrg  else
311d656433aSmrg    tmpdepfile1=$dir$base.u
312d656433aSmrg    tmpdepfile2=$dir$base.u
313d656433aSmrg    tmpdepfile3=$dir$base.u
314126a8a12Smrg    "$@" -M
315126a8a12Smrg  fi
316126a8a12Smrg  stat=$?
3170a6b08f8Smrg  if test $stat -ne 0; then
318d656433aSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
319126a8a12Smrg    exit $stat
320126a8a12Smrg  fi
321126a8a12Smrg
322d656433aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
323d656433aSmrg  do
324d656433aSmrg    test -f "$tmpdepfile" && break
325d656433aSmrg  done
3260a6b08f8Smrg  aix_post_process_depfile
3270a6b08f8Smrg  ;;
3280a6b08f8Smrg
3290a6b08f8Smrgtcc)
3300a6b08f8Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3310a6b08f8Smrg  # FIXME: That version still under development at the moment of writing.
3320a6b08f8Smrg  #        Make that this statement remains true also for stable, released
3330a6b08f8Smrg  #        versions.
3340a6b08f8Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3350a6b08f8Smrg  # trailing '\', as in:
3360a6b08f8Smrg  #
3370a6b08f8Smrg  #   foo.o : \
3380a6b08f8Smrg  #    foo.c \
3390a6b08f8Smrg  #    foo.h \
3400a6b08f8Smrg  #
3410a6b08f8Smrg  # It will put a trailing '\' even on the last line, and will use leading
3420a6b08f8Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3430a6b08f8Smrg  # "Emit spaces for -MD").
3440a6b08f8Smrg  "$@" -MD -MF "$tmpdepfile"
3450a6b08f8Smrg  stat=$?
3460a6b08f8Smrg  if test $stat -ne 0; then
3470a6b08f8Smrg    rm -f "$tmpdepfile"
3480a6b08f8Smrg    exit $stat
349126a8a12Smrg  fi
3500a6b08f8Smrg  rm -f "$depfile"
3510a6b08f8Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3520a6b08f8Smrg  # We have to change lines of the first kind to '$object: \'.
3530a6b08f8Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3540a6b08f8Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3550a6b08f8Smrg  # dummy dependency, to avoid the deleted-header problem.
3560a6b08f8Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
357126a8a12Smrg  rm -f "$tmpdepfile"
358126a8a12Smrg  ;;
359126a8a12Smrg
3600a6b08f8Smrg## The order of this option in the case statement is important, since the
3610a6b08f8Smrg## shell code in configure will try each of these formats in the order
3620a6b08f8Smrg## listed in this file.  A plain '-MD' option would be understood by many
3630a6b08f8Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3640a6b08f8Smrgpgcc)
3650a6b08f8Smrg  # Portland's C compiler understands '-MD'.
3660a6b08f8Smrg  # Will always output deps to 'file.d' where file is the root name of the
3670a6b08f8Smrg  # source file under compilation, even if file resides in a subdirectory.
3680a6b08f8Smrg  # The object file name does not affect the name of the '.d' file.
3690a6b08f8Smrg  # pgcc 10.2 will output
370126a8a12Smrg  #    foo.o: sub/foo.c sub/foo.h
3710a6b08f8Smrg  # and will wrap long lines using '\' :
372126a8a12Smrg  #    foo.o: sub/foo.c ... \
373126a8a12Smrg  #     sub/foo.h ... \
374126a8a12Smrg  #     ...
3750a6b08f8Smrg  set_dir_from "$object"
3760a6b08f8Smrg  # Use the source, not the object, to determine the base name, since
3770a6b08f8Smrg  # that's sadly what pgcc will do too.
3780a6b08f8Smrg  set_base_from "$source"
3790a6b08f8Smrg  tmpdepfile=$base.d
3800a6b08f8Smrg
3810a6b08f8Smrg  # For projects that build the same source file twice into different object
3820a6b08f8Smrg  # files, the pgcc approach of using the *source* file root name can cause
3830a6b08f8Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3840a6b08f8Smrg  # the same $tmpdepfile.
3850a6b08f8Smrg  lockdir=$base.d-lock
3860a6b08f8Smrg  trap "
3870a6b08f8Smrg    echo '$0: caught signal, cleaning up...' >&2
3880a6b08f8Smrg    rmdir '$lockdir'
3890a6b08f8Smrg    exit 1
3900a6b08f8Smrg  " 1 2 13 15
3910a6b08f8Smrg  numtries=100
3920a6b08f8Smrg  i=$numtries
3930a6b08f8Smrg  while test $i -gt 0; do
3940a6b08f8Smrg    # mkdir is a portable test-and-set.
3950a6b08f8Smrg    if mkdir "$lockdir" 2>/dev/null; then
3960a6b08f8Smrg      # This process acquired the lock.
3970a6b08f8Smrg      "$@" -MD
3980a6b08f8Smrg      stat=$?
3990a6b08f8Smrg      # Release the lock.
4000a6b08f8Smrg      rmdir "$lockdir"
4010a6b08f8Smrg      break
4020a6b08f8Smrg    else
4030a6b08f8Smrg      # If the lock is being held by a different process, wait
4040a6b08f8Smrg      # until the winning process is done or we timeout.
4050a6b08f8Smrg      while test -d "$lockdir" && test $i -gt 0; do
4060a6b08f8Smrg        sleep 1
4070a6b08f8Smrg        i=`expr $i - 1`
4080a6b08f8Smrg      done
4090a6b08f8Smrg    fi
4100a6b08f8Smrg    i=`expr $i - 1`
4110a6b08f8Smrg  done
4120a6b08f8Smrg  trap - 1 2 13 15
4130a6b08f8Smrg  if test $i -le 0; then
4140a6b08f8Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4150a6b08f8Smrg    echo "$0: check lockdir '$lockdir'" >&2
4160a6b08f8Smrg    exit 1
4170a6b08f8Smrg  fi
418126a8a12Smrg
4190a6b08f8Smrg  if test $stat -ne 0; then
420126a8a12Smrg    rm -f "$tmpdepfile"
421126a8a12Smrg    exit $stat
422126a8a12Smrg  fi
423126a8a12Smrg  rm -f "$depfile"
424126a8a12Smrg  # Each line is of the form `foo.o: dependent.h',
425126a8a12Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
426126a8a12Smrg  # Do two passes, one to just change these to
427126a8a12Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
428126a8a12Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
429126a8a12Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
430126a8a12Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4310a6b08f8Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4320a6b08f8Smrg    | sed -e 's/$/ :/' >> "$depfile"
433126a8a12Smrg  rm -f "$tmpdepfile"
434126a8a12Smrg  ;;
435126a8a12Smrg
436126a8a12Smrghp2)
437126a8a12Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
438126a8a12Smrg  # compilers, which have integrated preprocessors.  The correct option
439126a8a12Smrg  # to use with these is +Maked; it writes dependencies to a file named
440126a8a12Smrg  # 'foo.d', which lands next to the object file, wherever that
441126a8a12Smrg  # happens to be.
442126a8a12Smrg  # Much of this is similar to the tru64 case; see comments there.
4430a6b08f8Smrg  set_dir_from  "$object"
4440a6b08f8Smrg  set_base_from "$object"
445126a8a12Smrg  if test "$libtool" = yes; then
446126a8a12Smrg    tmpdepfile1=$dir$base.d
447126a8a12Smrg    tmpdepfile2=$dir.libs/$base.d
448126a8a12Smrg    "$@" -Wc,+Maked
449126a8a12Smrg  else
450126a8a12Smrg    tmpdepfile1=$dir$base.d
451126a8a12Smrg    tmpdepfile2=$dir$base.d
452126a8a12Smrg    "$@" +Maked
453126a8a12Smrg  fi
454126a8a12Smrg  stat=$?
4550a6b08f8Smrg  if test $stat -ne 0; then
456126a8a12Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
457126a8a12Smrg     exit $stat
458126a8a12Smrg  fi
459126a8a12Smrg
460126a8a12Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
461126a8a12Smrg  do
462126a8a12Smrg    test -f "$tmpdepfile" && break
463126a8a12Smrg  done
464126a8a12Smrg  if test -f "$tmpdepfile"; then
4650a6b08f8Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4660a6b08f8Smrg    # Add 'dependent.h:' lines.
467d656433aSmrg    sed -ne '2,${
4680a6b08f8Smrg               s/^ *//
4690a6b08f8Smrg               s/ \\*$//
4700a6b08f8Smrg               s/$/:/
4710a6b08f8Smrg               p
4720a6b08f8Smrg             }' "$tmpdepfile" >> "$depfile"
473126a8a12Smrg  else
4740a6b08f8Smrg    make_dummy_depfile
475126a8a12Smrg  fi
476126a8a12Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
477126a8a12Smrg  ;;
478126a8a12Smrg
479126a8a12Smrgtru64)
4800a6b08f8Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4810a6b08f8Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4820a6b08f8Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4830a6b08f8Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4840a6b08f8Smrg  # Subdirectories are respected.
4850a6b08f8Smrg  set_dir_from  "$object"
4860a6b08f8Smrg  set_base_from "$object"
4870a6b08f8Smrg
4880a6b08f8Smrg  if test "$libtool" = yes; then
4890a6b08f8Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4900a6b08f8Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4910a6b08f8Smrg    # in $dir$base.o.d.  We have to check for both files, because
4920a6b08f8Smrg    # one of the two compilations can be disabled.  We should prefer
4930a6b08f8Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4940a6b08f8Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4950a6b08f8Smrg    # the former would cause a distcleancheck panic.
4960a6b08f8Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4970a6b08f8Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4980a6b08f8Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4990a6b08f8Smrg    "$@" -Wc,-MD
5000a6b08f8Smrg  else
5010a6b08f8Smrg    tmpdepfile1=$dir$base.d
5020a6b08f8Smrg    tmpdepfile2=$dir$base.d
5030a6b08f8Smrg    tmpdepfile3=$dir$base.d
5040a6b08f8Smrg    "$@" -MD
5050a6b08f8Smrg  fi
5060a6b08f8Smrg
5070a6b08f8Smrg  stat=$?
5080a6b08f8Smrg  if test $stat -ne 0; then
5090a6b08f8Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5100a6b08f8Smrg    exit $stat
5110a6b08f8Smrg  fi
5120a6b08f8Smrg
5130a6b08f8Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5140a6b08f8Smrg  do
5150a6b08f8Smrg    test -f "$tmpdepfile" && break
5160a6b08f8Smrg  done
5170a6b08f8Smrg  # Same post-processing that is required for AIX mode.
5180a6b08f8Smrg  aix_post_process_depfile
5190a6b08f8Smrg  ;;
5200a6b08f8Smrg
5210a6b08f8Smrgmsvc7)
5220a6b08f8Smrg  if test "$libtool" = yes; then
5230a6b08f8Smrg    showIncludes=-Wc,-showIncludes
5240a6b08f8Smrg  else
5250a6b08f8Smrg    showIncludes=-showIncludes
5260a6b08f8Smrg  fi
5270a6b08f8Smrg  "$@" $showIncludes > "$tmpdepfile"
5280a6b08f8Smrg  stat=$?
5290a6b08f8Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5300a6b08f8Smrg  if test $stat -ne 0; then
5310a6b08f8Smrg    rm -f "$tmpdepfile"
5320a6b08f8Smrg    exit $stat
5330a6b08f8Smrg  fi
5340a6b08f8Smrg  rm -f "$depfile"
5350a6b08f8Smrg  echo "$object : \\" > "$depfile"
5360a6b08f8Smrg  # The first sed program below extracts the file names and escapes
5370a6b08f8Smrg  # backslashes for cygpath.  The second sed program outputs the file
5380a6b08f8Smrg  # name when reading, but also accumulates all include files in the
5390a6b08f8Smrg  # hold buffer in order to output them again at the end.  This only
5400a6b08f8Smrg  # works with sed implementations that can handle large buffers.
5410a6b08f8Smrg  sed < "$tmpdepfile" -n '
5420a6b08f8Smrg/^Note: including file:  *\(.*\)/ {
5430a6b08f8Smrg  s//\1/
5440a6b08f8Smrg  s/\\/\\\\/g
5450a6b08f8Smrg  p
5460a6b08f8Smrg}' | $cygpath_u | sort -u | sed -n '
5470a6b08f8Smrgs/ /\\ /g
5480a6b08f8Smrgs/\(.*\)/'"$tab"'\1 \\/p
5490a6b08f8Smrgs/.\(.*\) \\/\1:/
5500a6b08f8SmrgH
5510a6b08f8Smrg$ {
5520a6b08f8Smrg  s/.*/'"$tab"'/
5530a6b08f8Smrg  G
5540a6b08f8Smrg  p
5550a6b08f8Smrg}' >> "$depfile"
5560a6b08f8Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5570a6b08f8Smrg  rm -f "$tmpdepfile"
5580a6b08f8Smrg  ;;
5590a6b08f8Smrg
5600a6b08f8Smrgmsvc7msys)
5610a6b08f8Smrg  # This case exists only to let depend.m4 do its work.  It works by
5620a6b08f8Smrg  # looking at the text of this script.  This case will never be run,
5630a6b08f8Smrg  # since it is checked for above.
5640a6b08f8Smrg  exit 1
5650a6b08f8Smrg  ;;
566126a8a12Smrg
567126a8a12Smrg#nosideeffect)
568126a8a12Smrg  # This comment above is used by automake to tell side-effect
569126a8a12Smrg  # dependency tracking mechanisms from slower ones.
570126a8a12Smrg
571126a8a12Smrgdashmstdout)
572126a8a12Smrg  # Important note: in order to support this mode, a compiler *must*
573126a8a12Smrg  # always write the preprocessed file to stdout, regardless of -o.
574126a8a12Smrg  "$@" || exit $?
575126a8a12Smrg
576126a8a12Smrg  # Remove the call to Libtool.
577126a8a12Smrg  if test "$libtool" = yes; then
578d656433aSmrg    while test "X$1" != 'X--mode=compile'; do
579126a8a12Smrg      shift
580126a8a12Smrg    done
581126a8a12Smrg    shift
582126a8a12Smrg  fi
583126a8a12Smrg
5840a6b08f8Smrg  # Remove '-o $object'.
585126a8a12Smrg  IFS=" "
586126a8a12Smrg  for arg
587126a8a12Smrg  do
588126a8a12Smrg    case $arg in
589126a8a12Smrg    -o)
590126a8a12Smrg      shift
591126a8a12Smrg      ;;
592126a8a12Smrg    $object)
593126a8a12Smrg      shift
594126a8a12Smrg      ;;
595126a8a12Smrg    *)
596126a8a12Smrg      set fnord "$@" "$arg"
597126a8a12Smrg      shift # fnord
598126a8a12Smrg      shift # $arg
599126a8a12Smrg      ;;
600126a8a12Smrg    esac
601126a8a12Smrg  done
602126a8a12Smrg
603126a8a12Smrg  test -z "$dashmflag" && dashmflag=-M
6040a6b08f8Smrg  # Require at least two characters before searching for ':'
605126a8a12Smrg  # in the target name.  This is to cope with DOS-style filenames:
6060a6b08f8Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
607126a8a12Smrg  "$@" $dashmflag |
6080a6b08f8Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
609126a8a12Smrg  rm -f "$depfile"
610126a8a12Smrg  cat < "$tmpdepfile" > "$depfile"
6110a6b08f8Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6120a6b08f8Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6130a6b08f8Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6140a6b08f8Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6150a6b08f8Smrg    | sed -e 's/$/ :/' >> "$depfile"
616126a8a12Smrg  rm -f "$tmpdepfile"
617126a8a12Smrg  ;;
618126a8a12Smrg
619126a8a12SmrgdashXmstdout)
620126a8a12Smrg  # This case only exists to satisfy depend.m4.  It is never actually
621126a8a12Smrg  # run, as this mode is specially recognized in the preamble.
622126a8a12Smrg  exit 1
623126a8a12Smrg  ;;
624126a8a12Smrg
625126a8a12Smrgmakedepend)
626126a8a12Smrg  "$@" || exit $?
627126a8a12Smrg  # Remove any Libtool call
628126a8a12Smrg  if test "$libtool" = yes; then
629d656433aSmrg    while test "X$1" != 'X--mode=compile'; do
630126a8a12Smrg      shift
631126a8a12Smrg    done
632126a8a12Smrg    shift
633126a8a12Smrg  fi
634126a8a12Smrg  # X makedepend
635126a8a12Smrg  shift
636d656433aSmrg  cleared=no eat=no
637d656433aSmrg  for arg
638d656433aSmrg  do
639126a8a12Smrg    case $cleared in
640126a8a12Smrg    no)
641126a8a12Smrg      set ""; shift
642126a8a12Smrg      cleared=yes ;;
643126a8a12Smrg    esac
644d656433aSmrg    if test $eat = yes; then
645d656433aSmrg      eat=no
646d656433aSmrg      continue
647d656433aSmrg    fi
648126a8a12Smrg    case "$arg" in
649126a8a12Smrg    -D*|-I*)
650126a8a12Smrg      set fnord "$@" "$arg"; shift ;;
651126a8a12Smrg    # Strip any option that makedepend may not understand.  Remove
652126a8a12Smrg    # the object too, otherwise makedepend will parse it as a source file.
653d656433aSmrg    -arch)
654d656433aSmrg      eat=yes ;;
655126a8a12Smrg    -*|$object)
656126a8a12Smrg      ;;
657126a8a12Smrg    *)
658126a8a12Smrg      set fnord "$@" "$arg"; shift ;;
659126a8a12Smrg    esac
660126a8a12Smrg  done
661d656433aSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
662126a8a12Smrg  touch "$tmpdepfile"
663126a8a12Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
664126a8a12Smrg  rm -f "$depfile"
6650a6b08f8Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6660a6b08f8Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6670a6b08f8Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6680a6b08f8Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6690a6b08f8Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6700a6b08f8Smrg  sed '1,2d' "$tmpdepfile" \
6710a6b08f8Smrg    | tr ' ' "$nl" \
6720a6b08f8Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6730a6b08f8Smrg    | sed -e 's/$/ :/' >> "$depfile"
674126a8a12Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
675126a8a12Smrg  ;;
676126a8a12Smrg
677126a8a12Smrgcpp)
678126a8a12Smrg  # Important note: in order to support this mode, a compiler *must*
679126a8a12Smrg  # always write the preprocessed file to stdout.
680126a8a12Smrg  "$@" || exit $?
681126a8a12Smrg
682126a8a12Smrg  # Remove the call to Libtool.
683126a8a12Smrg  if test "$libtool" = yes; then
684d656433aSmrg    while test "X$1" != 'X--mode=compile'; do
685126a8a12Smrg      shift
686126a8a12Smrg    done
687126a8a12Smrg    shift
688126a8a12Smrg  fi
689126a8a12Smrg
6900a6b08f8Smrg  # Remove '-o $object'.
691126a8a12Smrg  IFS=" "
692126a8a12Smrg  for arg
693126a8a12Smrg  do
694126a8a12Smrg    case $arg in
695126a8a12Smrg    -o)
696126a8a12Smrg      shift
697126a8a12Smrg      ;;
698126a8a12Smrg    $object)
699126a8a12Smrg      shift
700126a8a12Smrg      ;;
701126a8a12Smrg    *)
702126a8a12Smrg      set fnord "$@" "$arg"
703126a8a12Smrg      shift # fnord
704126a8a12Smrg      shift # $arg
705126a8a12Smrg      ;;
706126a8a12Smrg    esac
707126a8a12Smrg  done
708126a8a12Smrg
7090a6b08f8Smrg  "$@" -E \
7100a6b08f8Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7110a6b08f8Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7120a6b08f8Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
713126a8a12Smrg  rm -f "$depfile"
714126a8a12Smrg  echo "$object : \\" > "$depfile"
715126a8a12Smrg  cat < "$tmpdepfile" >> "$depfile"
716126a8a12Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
717126a8a12Smrg  rm -f "$tmpdepfile"
718126a8a12Smrg  ;;
719126a8a12Smrg
720126a8a12Smrgmsvisualcpp)
721126a8a12Smrg  # Important note: in order to support this mode, a compiler *must*
722d656433aSmrg  # always write the preprocessed file to stdout.
723126a8a12Smrg  "$@" || exit $?
724d656433aSmrg
725d656433aSmrg  # Remove the call to Libtool.
726d656433aSmrg  if test "$libtool" = yes; then
727d656433aSmrg    while test "X$1" != 'X--mode=compile'; do
728d656433aSmrg      shift
729d656433aSmrg    done
730d656433aSmrg    shift
731d656433aSmrg  fi
732d656433aSmrg
733126a8a12Smrg  IFS=" "
734126a8a12Smrg  for arg
735126a8a12Smrg  do
736126a8a12Smrg    case "$arg" in
737d656433aSmrg    -o)
738d656433aSmrg      shift
739d656433aSmrg      ;;
740d656433aSmrg    $object)
741d656433aSmrg      shift
742d656433aSmrg      ;;
743126a8a12Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7440a6b08f8Smrg        set fnord "$@"
7450a6b08f8Smrg        shift
7460a6b08f8Smrg        shift
7470a6b08f8Smrg        ;;
748126a8a12Smrg    *)
7490a6b08f8Smrg        set fnord "$@" "$arg"
7500a6b08f8Smrg        shift
7510a6b08f8Smrg        shift
7520a6b08f8Smrg        ;;
753126a8a12Smrg    esac
754126a8a12Smrg  done
755d656433aSmrg  "$@" -E 2>/dev/null |
756d656433aSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
757126a8a12Smrg  rm -f "$depfile"
758126a8a12Smrg  echo "$object : \\" > "$depfile"
7590a6b08f8Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7600a6b08f8Smrg  echo "$tab" >> "$depfile"
761d656433aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
762126a8a12Smrg  rm -f "$tmpdepfile"
763126a8a12Smrg  ;;
764126a8a12Smrg
765d656433aSmrgmsvcmsys)
766d656433aSmrg  # This case exists only to let depend.m4 do its work.  It works by
767d656433aSmrg  # looking at the text of this script.  This case will never be run,
768d656433aSmrg  # since it is checked for above.
769d656433aSmrg  exit 1
770d656433aSmrg  ;;
771d656433aSmrg
772126a8a12Smrgnone)
773126a8a12Smrg  exec "$@"
774126a8a12Smrg  ;;
775126a8a12Smrg
776126a8a12Smrg*)
777126a8a12Smrg  echo "Unknown depmode $depmode" 1>&2
778126a8a12Smrg  exit 1
779126a8a12Smrg  ;;
780126a8a12Smrgesac
781126a8a12Smrg
782126a8a12Smrgexit 0
783126a8a12Smrg
784126a8a12Smrg# Local Variables:
785126a8a12Smrg# mode: shell-script
786126a8a12Smrg# sh-indentation: 2
7873fb97780Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
788126a8a12Smrg# time-stamp-start: "scriptversion="
789126a8a12Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
790300346aeSmrg# time-stamp-time-zone: "UTC0"
791d656433aSmrg# time-stamp-end: "; # UTC"
792126a8a12Smrg# End:
793