1a0d3b6eaSmrg#! /bin/sh
2a0d3b6eaSmrg# depcomp - compile a program generating dependencies as side-effects
3a0d3b6eaSmrg
409113985Smrgscriptversion=2018-03-07.03; # UTC
5a0d3b6eaSmrg
609113985Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
7a0d3b6eaSmrg
8a0d3b6eaSmrg# This program is free software; you can redistribute it and/or modify
9a0d3b6eaSmrg# it under the terms of the GNU General Public License as published by
10a0d3b6eaSmrg# the Free Software Foundation; either version 2, or (at your option)
11a0d3b6eaSmrg# any later version.
12a0d3b6eaSmrg
13a0d3b6eaSmrg# This program is distributed in the hope that it will be useful,
14a0d3b6eaSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15a0d3b6eaSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16a0d3b6eaSmrg# GNU General Public License for more details.
17a0d3b6eaSmrg
18a0d3b6eaSmrg# You should have received a copy of the GNU General Public License
1909113985Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20a0d3b6eaSmrg
21a0d3b6eaSmrg# As a special exception to the GNU General Public License, if you
22a0d3b6eaSmrg# distribute this file as part of a program that contains a
23a0d3b6eaSmrg# configuration script generated by Autoconf, you may include it under
24a0d3b6eaSmrg# the same distribution terms that you use for the rest of that program.
25a0d3b6eaSmrg
26a0d3b6eaSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27a0d3b6eaSmrg
28a0d3b6eaSmrgcase $1 in
29a0d3b6eaSmrg  '')
304a908991Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
314a908991Smrg    exit 1;
324a908991Smrg    ;;
33a0d3b6eaSmrg  -h | --h*)
34a0d3b6eaSmrg    cat <<\EOF
35a0d3b6eaSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36a0d3b6eaSmrg
37a0d3b6eaSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38a0d3b6eaSmrgas side-effects.
39a0d3b6eaSmrg
40a0d3b6eaSmrgEnvironment variables:
41a0d3b6eaSmrg  depmode     Dependency tracking mode.
424a908991Smrg  source      Source file read by 'PROGRAMS ARGS'.
434a908991Smrg  object      Object file output by 'PROGRAMS ARGS'.
44a0d3b6eaSmrg  DEPDIR      directory where to store dependencies.
45a0d3b6eaSmrg  depfile     Dependency file to output.
46966b534aSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
47a0d3b6eaSmrg  libtool     Whether libtool is used (yes/no).
48a0d3b6eaSmrg
49a0d3b6eaSmrgReport bugs to <bug-automake@gnu.org>.
50a0d3b6eaSmrgEOF
51a0d3b6eaSmrg    exit $?
52a0d3b6eaSmrg    ;;
53a0d3b6eaSmrg  -v | --v*)
54a0d3b6eaSmrg    echo "depcomp $scriptversion"
55a0d3b6eaSmrg    exit $?
56a0d3b6eaSmrg    ;;
57a0d3b6eaSmrgesac
58a0d3b6eaSmrg
594a908991Smrg# Get the directory component of the given path, and save it in the
604a908991Smrg# global variables '$dir'.  Note that this directory component will
614a908991Smrg# be either empty or ending with a '/' character.  This is deliberate.
624a908991Smrgset_dir_from ()
634a908991Smrg{
644a908991Smrg  case $1 in
654a908991Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
664a908991Smrg      *) dir=;;
674a908991Smrg  esac
684a908991Smrg}
694a908991Smrg
704a908991Smrg# Get the suffix-stripped basename of the given path, and save it the
714a908991Smrg# global variable '$base'.
724a908991Smrgset_base_from ()
734a908991Smrg{
744a908991Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
754a908991Smrg}
764a908991Smrg
774a908991Smrg# If no dependency file was actually created by the compiler invocation,
784a908991Smrg# we still have to create a dummy depfile, to avoid errors with the
794a908991Smrg# Makefile "include basename.Plo" scheme.
804a908991Smrgmake_dummy_depfile ()
814a908991Smrg{
824a908991Smrg  echo "#dummy" > "$depfile"
834a908991Smrg}
844a908991Smrg
854a908991Smrg# Factor out some common post-processing of the generated depfile.
864a908991Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
874a908991Smrgaix_post_process_depfile ()
884a908991Smrg{
894a908991Smrg  # If the compiler actually managed to produce a dependency file,
904a908991Smrg  # post-process it.
914a908991Smrg  if test -f "$tmpdepfile"; then
924a908991Smrg    # Each line is of the form 'foo.o: dependency.h'.
934a908991Smrg    # Do two passes, one to just change these to
944a908991Smrg    #   $object: dependency.h
954a908991Smrg    # and one to simply output
964a908991Smrg    #   dependency.h:
974a908991Smrg    # which is needed to avoid the deleted-header problem.
984a908991Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
994a908991Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1004a908991Smrg    } > "$depfile"
1014a908991Smrg    rm -f "$tmpdepfile"
1024a908991Smrg  else
1034a908991Smrg    make_dummy_depfile
1044a908991Smrg  fi
1054a908991Smrg}
1064a908991Smrg
1074a908991Smrg# A tabulation character.
1084a908991Smrgtab='	'
1094a908991Smrg# A newline character.
1104a908991Smrgnl='
1114a908991Smrg'
1124a908991Smrg# Character ranges might be problematic outside the C locale.
1134a908991Smrg# These definitions help.
1144a908991Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1154a908991Smrglower=abcdefghijklmnopqrstuvwxyz
1164a908991Smrgdigits=0123456789
1174a908991Smrgalpha=${upper}${lower}
1184a908991Smrg
119a0d3b6eaSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120a0d3b6eaSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121a0d3b6eaSmrg  exit 1
122a0d3b6eaSmrgfi
123a0d3b6eaSmrg
124a0d3b6eaSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125a0d3b6eaSmrgdepfile=${depfile-`echo "$object" |
126a0d3b6eaSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127a0d3b6eaSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128a0d3b6eaSmrg
129a0d3b6eaSmrgrm -f "$tmpdepfile"
130a0d3b6eaSmrg
1314a908991Smrg# Avoid interferences from the environment.
1324a908991Smrggccflag= dashmflag=
1334a908991Smrg
134a0d3b6eaSmrg# Some modes work just like other modes, but use different flags.  We
135a0d3b6eaSmrg# parameterize here, but still list the modes in the big case below,
136a0d3b6eaSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137a0d3b6eaSmrg# here, because this file can only contain one case statement.
138a0d3b6eaSmrgif test "$depmode" = hp; then
139a0d3b6eaSmrg  # HP compiler uses -M and no extra arg.
140a0d3b6eaSmrg  gccflag=-M
141a0d3b6eaSmrg  depmode=gcc
142a0d3b6eaSmrgfi
143a0d3b6eaSmrg
144a0d3b6eaSmrgif test "$depmode" = dashXmstdout; then
1454a908991Smrg  # This is just like dashmstdout with a different argument.
1464a908991Smrg  dashmflag=-xM
1474a908991Smrg  depmode=dashmstdout
148a0d3b6eaSmrgfi
149a0d3b6eaSmrg
150f8a31ee4Smrgcygpath_u="cygpath -u -f -"
151f8a31ee4Smrgif test "$depmode" = msvcmsys; then
1524a908991Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1534a908991Smrg  # Just convert the backslash-escaped backslashes to single forward
1544a908991Smrg  # slashes to satisfy depend.m4
1554a908991Smrg  cygpath_u='sed s,\\\\,/,g'
1564a908991Smrg  depmode=msvisualcpp
157f8a31ee4Smrgfi
158f8a31ee4Smrg
159966b534aSmrgif test "$depmode" = msvc7msys; then
1604a908991Smrg  # This is just like msvc7 but w/o cygpath translation.
1614a908991Smrg  # Just convert the backslash-escaped backslashes to single forward
1624a908991Smrg  # slashes to satisfy depend.m4
1634a908991Smrg  cygpath_u='sed s,\\\\,/,g'
1644a908991Smrg  depmode=msvc7
1654a908991Smrgfi
1664a908991Smrg
1674a908991Smrgif test "$depmode" = xlc; then
1684a908991Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1694a908991Smrg  gccflag=-qmakedep=gcc,-MF
1704a908991Smrg  depmode=gcc
171966b534aSmrgfi
172966b534aSmrg
173a0d3b6eaSmrgcase "$depmode" in
174a0d3b6eaSmrggcc3)
175a0d3b6eaSmrg## gcc 3 implements dependency tracking that does exactly what
176a0d3b6eaSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177a0d3b6eaSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178a0d3b6eaSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179a0d3b6eaSmrg## the command line argument order; so add the flags where they
180a0d3b6eaSmrg## appear in depend2.am.  Note that the slowdown incurred here
181a0d3b6eaSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182a0d3b6eaSmrg  for arg
183a0d3b6eaSmrg  do
184a0d3b6eaSmrg    case $arg in
185a0d3b6eaSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186a0d3b6eaSmrg    *)  set fnord "$@" "$arg" ;;
187a0d3b6eaSmrg    esac
188a0d3b6eaSmrg    shift # fnord
189a0d3b6eaSmrg    shift # $arg
190a0d3b6eaSmrg  done
191a0d3b6eaSmrg  "$@"
192a0d3b6eaSmrg  stat=$?
1934a908991Smrg  if test $stat -ne 0; then
194a0d3b6eaSmrg    rm -f "$tmpdepfile"
195a0d3b6eaSmrg    exit $stat
196a0d3b6eaSmrg  fi
197a0d3b6eaSmrg  mv "$tmpdepfile" "$depfile"
198a0d3b6eaSmrg  ;;
199a0d3b6eaSmrg
200a0d3b6eaSmrggcc)
2014a908991Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2024a908991Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2034a908991Smrg## (see the conditional assignment to $gccflag above).
204a0d3b6eaSmrg## There are various ways to get dependency output from gcc.  Here's
205a0d3b6eaSmrg## why we pick this rather obscure method:
206a0d3b6eaSmrg## - Don't want to use -MD because we'd like the dependencies to end
207a0d3b6eaSmrg##   up in a subdir.  Having to rename by hand is ugly.
208a0d3b6eaSmrg##   (We might end up doing this anyway to support other compilers.)
209a0d3b6eaSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2104a908991Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2114a908991Smrg##   supported by the other compilers which use the 'gcc' depmode.
212a0d3b6eaSmrg## - Using -M directly means running the compiler twice (even worse
213a0d3b6eaSmrg##   than renaming).
214a0d3b6eaSmrg  if test -z "$gccflag"; then
215a0d3b6eaSmrg    gccflag=-MD,
216a0d3b6eaSmrg  fi
217a0d3b6eaSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
218a0d3b6eaSmrg  stat=$?
2194a908991Smrg  if test $stat -ne 0; then
220a0d3b6eaSmrg    rm -f "$tmpdepfile"
221a0d3b6eaSmrg    exit $stat
222a0d3b6eaSmrg  fi
223a0d3b6eaSmrg  rm -f "$depfile"
224a0d3b6eaSmrg  echo "$object : \\" > "$depfile"
2254a908991Smrg  # The second -e expression handles DOS-style file names with drive
2264a908991Smrg  # letters.
227a0d3b6eaSmrg  sed -e 's/^[^:]*: / /' \
228a0d3b6eaSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2294a908991Smrg## This next piece of magic avoids the "deleted header file" problem.
230a0d3b6eaSmrg## The problem is that when a header file which appears in a .P file
231a0d3b6eaSmrg## is deleted, the dependency causes make to die (because there is
232a0d3b6eaSmrg## typically no way to rebuild the header).  We avoid this by adding
233a0d3b6eaSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234a0d3b6eaSmrg## this for us directly.
2354a908991Smrg## Some versions of gcc put a space before the ':'.  On the theory
236a0d3b6eaSmrg## that the space means something, we add a space to the output as
237966b534aSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238966b534aSmrg## to the object.  Take care to not repeat it in the output.
239a0d3b6eaSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
240a0d3b6eaSmrg## correctly.  Breaking it into two sed invocations is a workaround.
2414a908991Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2424a908991Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2434a908991Smrg    | sed -e 's/$/ :/' >> "$depfile"
244a0d3b6eaSmrg  rm -f "$tmpdepfile"
245a0d3b6eaSmrg  ;;
246a0d3b6eaSmrg
247a0d3b6eaSmrghp)
248a0d3b6eaSmrg  # This case exists only to let depend.m4 do its work.  It works by
249a0d3b6eaSmrg  # looking at the text of this script.  This case will never be run,
250a0d3b6eaSmrg  # since it is checked for above.
251a0d3b6eaSmrg  exit 1
252a0d3b6eaSmrg  ;;
253a0d3b6eaSmrg
254a0d3b6eaSmrgsgi)
255a0d3b6eaSmrg  if test "$libtool" = yes; then
256a0d3b6eaSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257a0d3b6eaSmrg  else
258a0d3b6eaSmrg    "$@" -MDupdate "$tmpdepfile"
259a0d3b6eaSmrg  fi
260a0d3b6eaSmrg  stat=$?
2614a908991Smrg  if test $stat -ne 0; then
262a0d3b6eaSmrg    rm -f "$tmpdepfile"
263a0d3b6eaSmrg    exit $stat
264a0d3b6eaSmrg  fi
265a0d3b6eaSmrg  rm -f "$depfile"
266a0d3b6eaSmrg
267a0d3b6eaSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268a0d3b6eaSmrg    echo "$object : \\" > "$depfile"
269a0d3b6eaSmrg    # Clip off the initial element (the dependent).  Don't try to be
270a0d3b6eaSmrg    # clever and replace this with sed code, as IRIX sed won't handle
271a0d3b6eaSmrg    # lines with more than a fixed number of characters (4096 in
272a0d3b6eaSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2734a908991Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274a0d3b6eaSmrg    # dependency line.
2754a908991Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2764a908991Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2774a908991Smrg      | tr "$nl" ' ' >> "$depfile"
278f8a31ee4Smrg    echo >> "$depfile"
279a0d3b6eaSmrg    # The second pass generates a dummy entry for each header file.
2804a908991Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2814a908991Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2824a908991Smrg      >> "$depfile"
283a0d3b6eaSmrg  else
2844a908991Smrg    make_dummy_depfile
285a0d3b6eaSmrg  fi
286a0d3b6eaSmrg  rm -f "$tmpdepfile"
287a0d3b6eaSmrg  ;;
288a0d3b6eaSmrg
2894a908991Smrgxlc)
2904a908991Smrg  # This case exists only to let depend.m4 do its work.  It works by
2914a908991Smrg  # looking at the text of this script.  This case will never be run,
2924a908991Smrg  # since it is checked for above.
2934a908991Smrg  exit 1
2944a908991Smrg  ;;
2954a908991Smrg
296a0d3b6eaSmrgaix)
297a0d3b6eaSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
298a0d3b6eaSmrg  # in a .u file.  In older versions, this file always lives in the
2994a908991Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300a0d3b6eaSmrg  # start of each line; $object doesn't have directory information.
301a0d3b6eaSmrg  # Version 6 uses the directory in both cases.
3024a908991Smrg  set_dir_from "$object"
3034a908991Smrg  set_base_from "$object"
304a0d3b6eaSmrg  if test "$libtool" = yes; then
305f8a31ee4Smrg    tmpdepfile1=$dir$base.u
306f8a31ee4Smrg    tmpdepfile2=$base.u
307f8a31ee4Smrg    tmpdepfile3=$dir.libs/$base.u
308a0d3b6eaSmrg    "$@" -Wc,-M
309a0d3b6eaSmrg  else
310f8a31ee4Smrg    tmpdepfile1=$dir$base.u
311f8a31ee4Smrg    tmpdepfile2=$dir$base.u
312f8a31ee4Smrg    tmpdepfile3=$dir$base.u
313a0d3b6eaSmrg    "$@" -M
314a0d3b6eaSmrg  fi
315a0d3b6eaSmrg  stat=$?
3164a908991Smrg  if test $stat -ne 0; then
317f8a31ee4Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318a0d3b6eaSmrg    exit $stat
319a0d3b6eaSmrg  fi
320a0d3b6eaSmrg
321f8a31ee4Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322f8a31ee4Smrg  do
323f8a31ee4Smrg    test -f "$tmpdepfile" && break
324f8a31ee4Smrg  done
3254a908991Smrg  aix_post_process_depfile
3264a908991Smrg  ;;
3274a908991Smrg
3284a908991Smrgtcc)
3294a908991Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3304a908991Smrg  # FIXME: That version still under development at the moment of writing.
3314a908991Smrg  #        Make that this statement remains true also for stable, released
3324a908991Smrg  #        versions.
3334a908991Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3344a908991Smrg  # trailing '\', as in:
3354a908991Smrg  #
3364a908991Smrg  #   foo.o : \
3374a908991Smrg  #    foo.c \
3384a908991Smrg  #    foo.h \
3394a908991Smrg  #
3404a908991Smrg  # It will put a trailing '\' even on the last line, and will use leading
3414a908991Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3424a908991Smrg  # "Emit spaces for -MD").
3434a908991Smrg  "$@" -MD -MF "$tmpdepfile"
3444a908991Smrg  stat=$?
3454a908991Smrg  if test $stat -ne 0; then
3464a908991Smrg    rm -f "$tmpdepfile"
3474a908991Smrg    exit $stat
348a0d3b6eaSmrg  fi
3494a908991Smrg  rm -f "$depfile"
3504a908991Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3514a908991Smrg  # We have to change lines of the first kind to '$object: \'.
3524a908991Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3534a908991Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3544a908991Smrg  # dummy dependency, to avoid the deleted-header problem.
3554a908991Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356a0d3b6eaSmrg  rm -f "$tmpdepfile"
357a0d3b6eaSmrg  ;;
358a0d3b6eaSmrg
3594a908991Smrg## The order of this option in the case statement is important, since the
3604a908991Smrg## shell code in configure will try each of these formats in the order
3614a908991Smrg## listed in this file.  A plain '-MD' option would be understood by many
3624a908991Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3634a908991Smrgpgcc)
3644a908991Smrg  # Portland's C compiler understands '-MD'.
3654a908991Smrg  # Will always output deps to 'file.d' where file is the root name of the
3664a908991Smrg  # source file under compilation, even if file resides in a subdirectory.
3674a908991Smrg  # The object file name does not affect the name of the '.d' file.
3684a908991Smrg  # pgcc 10.2 will output
369a0d3b6eaSmrg  #    foo.o: sub/foo.c sub/foo.h
3704a908991Smrg  # and will wrap long lines using '\' :
371a0d3b6eaSmrg  #    foo.o: sub/foo.c ... \
372a0d3b6eaSmrg  #     sub/foo.h ... \
373a0d3b6eaSmrg  #     ...
3744a908991Smrg  set_dir_from "$object"
3754a908991Smrg  # Use the source, not the object, to determine the base name, since
3764a908991Smrg  # that's sadly what pgcc will do too.
3774a908991Smrg  set_base_from "$source"
3784a908991Smrg  tmpdepfile=$base.d
3794a908991Smrg
3804a908991Smrg  # For projects that build the same source file twice into different object
3814a908991Smrg  # files, the pgcc approach of using the *source* file root name can cause
3824a908991Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3834a908991Smrg  # the same $tmpdepfile.
3844a908991Smrg  lockdir=$base.d-lock
3854a908991Smrg  trap "
3864a908991Smrg    echo '$0: caught signal, cleaning up...' >&2
3874a908991Smrg    rmdir '$lockdir'
3884a908991Smrg    exit 1
3894a908991Smrg  " 1 2 13 15
3904a908991Smrg  numtries=100
3914a908991Smrg  i=$numtries
3924a908991Smrg  while test $i -gt 0; do
3934a908991Smrg    # mkdir is a portable test-and-set.
3944a908991Smrg    if mkdir "$lockdir" 2>/dev/null; then
3954a908991Smrg      # This process acquired the lock.
3964a908991Smrg      "$@" -MD
3974a908991Smrg      stat=$?
3984a908991Smrg      # Release the lock.
3994a908991Smrg      rmdir "$lockdir"
4004a908991Smrg      break
4014a908991Smrg    else
4024a908991Smrg      # If the lock is being held by a different process, wait
4034a908991Smrg      # until the winning process is done or we timeout.
4044a908991Smrg      while test -d "$lockdir" && test $i -gt 0; do
4054a908991Smrg        sleep 1
4064a908991Smrg        i=`expr $i - 1`
4074a908991Smrg      done
4084a908991Smrg    fi
4094a908991Smrg    i=`expr $i - 1`
4104a908991Smrg  done
4114a908991Smrg  trap - 1 2 13 15
4124a908991Smrg  if test $i -le 0; then
4134a908991Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4144a908991Smrg    echo "$0: check lockdir '$lockdir'" >&2
4154a908991Smrg    exit 1
4164a908991Smrg  fi
417a0d3b6eaSmrg
4184a908991Smrg  if test $stat -ne 0; then
419a0d3b6eaSmrg    rm -f "$tmpdepfile"
420a0d3b6eaSmrg    exit $stat
421a0d3b6eaSmrg  fi
422a0d3b6eaSmrg  rm -f "$depfile"
423a0d3b6eaSmrg  # Each line is of the form `foo.o: dependent.h',
424a0d3b6eaSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425a0d3b6eaSmrg  # Do two passes, one to just change these to
426a0d3b6eaSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427a0d3b6eaSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428a0d3b6eaSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429a0d3b6eaSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
4304a908991Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4314a908991Smrg    | sed -e 's/$/ :/' >> "$depfile"
432a0d3b6eaSmrg  rm -f "$tmpdepfile"
433a0d3b6eaSmrg  ;;
434a0d3b6eaSmrg
435a0d3b6eaSmrghp2)
436a0d3b6eaSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437a0d3b6eaSmrg  # compilers, which have integrated preprocessors.  The correct option
438a0d3b6eaSmrg  # to use with these is +Maked; it writes dependencies to a file named
439a0d3b6eaSmrg  # 'foo.d', which lands next to the object file, wherever that
440a0d3b6eaSmrg  # happens to be.
441a0d3b6eaSmrg  # Much of this is similar to the tru64 case; see comments there.
4424a908991Smrg  set_dir_from  "$object"
4434a908991Smrg  set_base_from "$object"
444a0d3b6eaSmrg  if test "$libtool" = yes; then
445a0d3b6eaSmrg    tmpdepfile1=$dir$base.d
446a0d3b6eaSmrg    tmpdepfile2=$dir.libs/$base.d
447a0d3b6eaSmrg    "$@" -Wc,+Maked
448a0d3b6eaSmrg  else
449a0d3b6eaSmrg    tmpdepfile1=$dir$base.d
450a0d3b6eaSmrg    tmpdepfile2=$dir$base.d
451a0d3b6eaSmrg    "$@" +Maked
452a0d3b6eaSmrg  fi
453a0d3b6eaSmrg  stat=$?
4544a908991Smrg  if test $stat -ne 0; then
455a0d3b6eaSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456a0d3b6eaSmrg     exit $stat
457a0d3b6eaSmrg  fi
458a0d3b6eaSmrg
459a0d3b6eaSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460a0d3b6eaSmrg  do
461a0d3b6eaSmrg    test -f "$tmpdepfile" && break
462a0d3b6eaSmrg  done
463a0d3b6eaSmrg  if test -f "$tmpdepfile"; then
4644a908991Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4654a908991Smrg    # Add 'dependent.h:' lines.
466f8a31ee4Smrg    sed -ne '2,${
4674a908991Smrg               s/^ *//
4684a908991Smrg               s/ \\*$//
4694a908991Smrg               s/$/:/
4704a908991Smrg               p
4714a908991Smrg             }' "$tmpdepfile" >> "$depfile"
472a0d3b6eaSmrg  else
4734a908991Smrg    make_dummy_depfile
474a0d3b6eaSmrg  fi
475a0d3b6eaSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476a0d3b6eaSmrg  ;;
477a0d3b6eaSmrg
478a0d3b6eaSmrgtru64)
4794a908991Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4804a908991Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4814a908991Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4824a908991Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4834a908991Smrg  # Subdirectories are respected.
4844a908991Smrg  set_dir_from  "$object"
4854a908991Smrg  set_base_from "$object"
4864a908991Smrg
4874a908991Smrg  if test "$libtool" = yes; then
4884a908991Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4894a908991Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4904a908991Smrg    # in $dir$base.o.d.  We have to check for both files, because
4914a908991Smrg    # one of the two compilations can be disabled.  We should prefer
4924a908991Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4934a908991Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4944a908991Smrg    # the former would cause a distcleancheck panic.
4954a908991Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4964a908991Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4974a908991Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4984a908991Smrg    "$@" -Wc,-MD
4994a908991Smrg  else
5004a908991Smrg    tmpdepfile1=$dir$base.d
5014a908991Smrg    tmpdepfile2=$dir$base.d
5024a908991Smrg    tmpdepfile3=$dir$base.d
5034a908991Smrg    "$@" -MD
5044a908991Smrg  fi
5054a908991Smrg
5064a908991Smrg  stat=$?
5074a908991Smrg  if test $stat -ne 0; then
5084a908991Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5094a908991Smrg    exit $stat
5104a908991Smrg  fi
5114a908991Smrg
5124a908991Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5134a908991Smrg  do
5144a908991Smrg    test -f "$tmpdepfile" && break
5154a908991Smrg  done
5164a908991Smrg  # Same post-processing that is required for AIX mode.
5174a908991Smrg  aix_post_process_depfile
5184a908991Smrg  ;;
519a0d3b6eaSmrg
520966b534aSmrgmsvc7)
521966b534aSmrg  if test "$libtool" = yes; then
522966b534aSmrg    showIncludes=-Wc,-showIncludes
523966b534aSmrg  else
524966b534aSmrg    showIncludes=-showIncludes
525966b534aSmrg  fi
526966b534aSmrg  "$@" $showIncludes > "$tmpdepfile"
527966b534aSmrg  stat=$?
528966b534aSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
5294a908991Smrg  if test $stat -ne 0; then
530966b534aSmrg    rm -f "$tmpdepfile"
531966b534aSmrg    exit $stat
532966b534aSmrg  fi
533966b534aSmrg  rm -f "$depfile"
534966b534aSmrg  echo "$object : \\" > "$depfile"
535966b534aSmrg  # The first sed program below extracts the file names and escapes
536966b534aSmrg  # backslashes for cygpath.  The second sed program outputs the file
537966b534aSmrg  # name when reading, but also accumulates all include files in the
538966b534aSmrg  # hold buffer in order to output them again at the end.  This only
539966b534aSmrg  # works with sed implementations that can handle large buffers.
540966b534aSmrg  sed < "$tmpdepfile" -n '
541966b534aSmrg/^Note: including file:  *\(.*\)/ {
542966b534aSmrg  s//\1/
543966b534aSmrg  s/\\/\\\\/g
544966b534aSmrg  p
545966b534aSmrg}' | $cygpath_u | sort -u | sed -n '
546966b534aSmrgs/ /\\ /g
5474a908991Smrgs/\(.*\)/'"$tab"'\1 \\/p
548966b534aSmrgs/.\(.*\) \\/\1:/
549966b534aSmrgH
550966b534aSmrg$ {
5514a908991Smrg  s/.*/'"$tab"'/
552966b534aSmrg  G
553966b534aSmrg  p
554966b534aSmrg}' >> "$depfile"
5554a908991Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556966b534aSmrg  rm -f "$tmpdepfile"
557966b534aSmrg  ;;
558966b534aSmrg
559966b534aSmrgmsvc7msys)
560966b534aSmrg  # This case exists only to let depend.m4 do its work.  It works by
561966b534aSmrg  # looking at the text of this script.  This case will never be run,
562966b534aSmrg  # since it is checked for above.
563966b534aSmrg  exit 1
564966b534aSmrg  ;;
565966b534aSmrg
566a0d3b6eaSmrg#nosideeffect)
567a0d3b6eaSmrg  # This comment above is used by automake to tell side-effect
568a0d3b6eaSmrg  # dependency tracking mechanisms from slower ones.
569a0d3b6eaSmrg
570a0d3b6eaSmrgdashmstdout)
571a0d3b6eaSmrg  # Important note: in order to support this mode, a compiler *must*
572a0d3b6eaSmrg  # always write the preprocessed file to stdout, regardless of -o.
573a0d3b6eaSmrg  "$@" || exit $?
574a0d3b6eaSmrg
575a0d3b6eaSmrg  # Remove the call to Libtool.
576a0d3b6eaSmrg  if test "$libtool" = yes; then
577f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
578a0d3b6eaSmrg      shift
579a0d3b6eaSmrg    done
580a0d3b6eaSmrg    shift
581a0d3b6eaSmrg  fi
582a0d3b6eaSmrg
5834a908991Smrg  # Remove '-o $object'.
584a0d3b6eaSmrg  IFS=" "
585a0d3b6eaSmrg  for arg
586a0d3b6eaSmrg  do
587a0d3b6eaSmrg    case $arg in
588a0d3b6eaSmrg    -o)
589a0d3b6eaSmrg      shift
590a0d3b6eaSmrg      ;;
591a0d3b6eaSmrg    $object)
592a0d3b6eaSmrg      shift
593a0d3b6eaSmrg      ;;
594a0d3b6eaSmrg    *)
595a0d3b6eaSmrg      set fnord "$@" "$arg"
596a0d3b6eaSmrg      shift # fnord
597a0d3b6eaSmrg      shift # $arg
598a0d3b6eaSmrg      ;;
599a0d3b6eaSmrg    esac
600a0d3b6eaSmrg  done
601a0d3b6eaSmrg
602a0d3b6eaSmrg  test -z "$dashmflag" && dashmflag=-M
6034a908991Smrg  # Require at least two characters before searching for ':'
604a0d3b6eaSmrg  # in the target name.  This is to cope with DOS-style filenames:
6054a908991Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606a0d3b6eaSmrg  "$@" $dashmflag |
6074a908991Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608a0d3b6eaSmrg  rm -f "$depfile"
609a0d3b6eaSmrg  cat < "$tmpdepfile" > "$depfile"
6104a908991Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6114a908991Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6124a908991Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6134a908991Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6144a908991Smrg    | sed -e 's/$/ :/' >> "$depfile"
615a0d3b6eaSmrg  rm -f "$tmpdepfile"
616a0d3b6eaSmrg  ;;
617a0d3b6eaSmrg
618a0d3b6eaSmrgdashXmstdout)
619a0d3b6eaSmrg  # This case only exists to satisfy depend.m4.  It is never actually
620a0d3b6eaSmrg  # run, as this mode is specially recognized in the preamble.
621a0d3b6eaSmrg  exit 1
622a0d3b6eaSmrg  ;;
623a0d3b6eaSmrg
624a0d3b6eaSmrgmakedepend)
625a0d3b6eaSmrg  "$@" || exit $?
626a0d3b6eaSmrg  # Remove any Libtool call
627a0d3b6eaSmrg  if test "$libtool" = yes; then
628f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
629a0d3b6eaSmrg      shift
630a0d3b6eaSmrg    done
631a0d3b6eaSmrg    shift
632a0d3b6eaSmrg  fi
633a0d3b6eaSmrg  # X makedepend
634a0d3b6eaSmrg  shift
635f8a31ee4Smrg  cleared=no eat=no
636f8a31ee4Smrg  for arg
637f8a31ee4Smrg  do
638a0d3b6eaSmrg    case $cleared in
639a0d3b6eaSmrg    no)
640a0d3b6eaSmrg      set ""; shift
641a0d3b6eaSmrg      cleared=yes ;;
642a0d3b6eaSmrg    esac
643f8a31ee4Smrg    if test $eat = yes; then
644f8a31ee4Smrg      eat=no
645f8a31ee4Smrg      continue
646f8a31ee4Smrg    fi
647a0d3b6eaSmrg    case "$arg" in
648a0d3b6eaSmrg    -D*|-I*)
649a0d3b6eaSmrg      set fnord "$@" "$arg"; shift ;;
650a0d3b6eaSmrg    # Strip any option that makedepend may not understand.  Remove
651a0d3b6eaSmrg    # the object too, otherwise makedepend will parse it as a source file.
652f8a31ee4Smrg    -arch)
653f8a31ee4Smrg      eat=yes ;;
654a0d3b6eaSmrg    -*|$object)
655a0d3b6eaSmrg      ;;
656a0d3b6eaSmrg    *)
657a0d3b6eaSmrg      set fnord "$@" "$arg"; shift ;;
658a0d3b6eaSmrg    esac
659a0d3b6eaSmrg  done
660f8a31ee4Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661a0d3b6eaSmrg  touch "$tmpdepfile"
662a0d3b6eaSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663a0d3b6eaSmrg  rm -f "$depfile"
664966b534aSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665966b534aSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666966b534aSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6674a908991Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6684a908991Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6694a908991Smrg  sed '1,2d' "$tmpdepfile" \
6704a908991Smrg    | tr ' ' "$nl" \
6714a908991Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6724a908991Smrg    | sed -e 's/$/ :/' >> "$depfile"
673a0d3b6eaSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674a0d3b6eaSmrg  ;;
675a0d3b6eaSmrg
676a0d3b6eaSmrgcpp)
677a0d3b6eaSmrg  # Important note: in order to support this mode, a compiler *must*
678a0d3b6eaSmrg  # always write the preprocessed file to stdout.
679a0d3b6eaSmrg  "$@" || exit $?
680a0d3b6eaSmrg
681a0d3b6eaSmrg  # Remove the call to Libtool.
682a0d3b6eaSmrg  if test "$libtool" = yes; then
683f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
684a0d3b6eaSmrg      shift
685a0d3b6eaSmrg    done
686a0d3b6eaSmrg    shift
687a0d3b6eaSmrg  fi
688a0d3b6eaSmrg
6894a908991Smrg  # Remove '-o $object'.
690a0d3b6eaSmrg  IFS=" "
691a0d3b6eaSmrg  for arg
692a0d3b6eaSmrg  do
693a0d3b6eaSmrg    case $arg in
694a0d3b6eaSmrg    -o)
695a0d3b6eaSmrg      shift
696a0d3b6eaSmrg      ;;
697a0d3b6eaSmrg    $object)
698a0d3b6eaSmrg      shift
699a0d3b6eaSmrg      ;;
700a0d3b6eaSmrg    *)
701a0d3b6eaSmrg      set fnord "$@" "$arg"
702a0d3b6eaSmrg      shift # fnord
703a0d3b6eaSmrg      shift # $arg
704a0d3b6eaSmrg      ;;
705a0d3b6eaSmrg    esac
706a0d3b6eaSmrg  done
707a0d3b6eaSmrg
7084a908991Smrg  "$@" -E \
7094a908991Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7104a908991Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7114a908991Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712a0d3b6eaSmrg  rm -f "$depfile"
713a0d3b6eaSmrg  echo "$object : \\" > "$depfile"
714a0d3b6eaSmrg  cat < "$tmpdepfile" >> "$depfile"
715a0d3b6eaSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716a0d3b6eaSmrg  rm -f "$tmpdepfile"
717a0d3b6eaSmrg  ;;
718a0d3b6eaSmrg
719a0d3b6eaSmrgmsvisualcpp)
720a0d3b6eaSmrg  # Important note: in order to support this mode, a compiler *must*
721f8a31ee4Smrg  # always write the preprocessed file to stdout.
722a0d3b6eaSmrg  "$@" || exit $?
723f8a31ee4Smrg
724f8a31ee4Smrg  # Remove the call to Libtool.
725f8a31ee4Smrg  if test "$libtool" = yes; then
726f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
727f8a31ee4Smrg      shift
728f8a31ee4Smrg    done
729f8a31ee4Smrg    shift
730f8a31ee4Smrg  fi
731f8a31ee4Smrg
732a0d3b6eaSmrg  IFS=" "
733a0d3b6eaSmrg  for arg
734a0d3b6eaSmrg  do
735a0d3b6eaSmrg    case "$arg" in
736f8a31ee4Smrg    -o)
737f8a31ee4Smrg      shift
738f8a31ee4Smrg      ;;
739f8a31ee4Smrg    $object)
740f8a31ee4Smrg      shift
741f8a31ee4Smrg      ;;
742a0d3b6eaSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7434a908991Smrg        set fnord "$@"
7444a908991Smrg        shift
7454a908991Smrg        shift
7464a908991Smrg        ;;
747a0d3b6eaSmrg    *)
7484a908991Smrg        set fnord "$@" "$arg"
7494a908991Smrg        shift
7504a908991Smrg        shift
7514a908991Smrg        ;;
752a0d3b6eaSmrg    esac
753a0d3b6eaSmrg  done
754f8a31ee4Smrg  "$@" -E 2>/dev/null |
755f8a31ee4Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756a0d3b6eaSmrg  rm -f "$depfile"
757a0d3b6eaSmrg  echo "$object : \\" > "$depfile"
7584a908991Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7594a908991Smrg  echo "$tab" >> "$depfile"
760f8a31ee4Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761a0d3b6eaSmrg  rm -f "$tmpdepfile"
762a0d3b6eaSmrg  ;;
763a0d3b6eaSmrg
764f8a31ee4Smrgmsvcmsys)
765f8a31ee4Smrg  # This case exists only to let depend.m4 do its work.  It works by
766f8a31ee4Smrg  # looking at the text of this script.  This case will never be run,
767f8a31ee4Smrg  # since it is checked for above.
768f8a31ee4Smrg  exit 1
769f8a31ee4Smrg  ;;
770f8a31ee4Smrg
771a0d3b6eaSmrgnone)
772a0d3b6eaSmrg  exec "$@"
773a0d3b6eaSmrg  ;;
774a0d3b6eaSmrg
775a0d3b6eaSmrg*)
776a0d3b6eaSmrg  echo "Unknown depmode $depmode" 1>&2
777a0d3b6eaSmrg  exit 1
778a0d3b6eaSmrg  ;;
779a0d3b6eaSmrgesac
780a0d3b6eaSmrg
781a0d3b6eaSmrgexit 0
782a0d3b6eaSmrg
783a0d3b6eaSmrg# Local Variables:
784a0d3b6eaSmrg# mode: shell-script
785a0d3b6eaSmrg# sh-indentation: 2
78609113985Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
787a0d3b6eaSmrg# time-stamp-start: "scriptversion="
788a0d3b6eaSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
78909113985Smrg# time-stamp-time-zone: "UTC0"
790f8a31ee4Smrg# time-stamp-end: "; # UTC"
791a0d3b6eaSmrg# End:
792