1c582b7e3Smrg#! /bin/sh
2c582b7e3Smrg# depcomp - compile a program generating dependencies as side-effects
3c582b7e3Smrg
48ce07328Smrgscriptversion=2018-03-07.03; # UTC
5c582b7e3Smrg
68ce07328Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
7c582b7e3Smrg
8c582b7e3Smrg# This program is free software; you can redistribute it and/or modify
9c582b7e3Smrg# it under the terms of the GNU General Public License as published by
10c582b7e3Smrg# the Free Software Foundation; either version 2, or (at your option)
11c582b7e3Smrg# any later version.
12c582b7e3Smrg
13c582b7e3Smrg# This program is distributed in the hope that it will be useful,
14c582b7e3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15c582b7e3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c582b7e3Smrg# GNU General Public License for more details.
17c582b7e3Smrg
18c582b7e3Smrg# You should have received a copy of the GNU General Public License
198ce07328Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20c582b7e3Smrg
21c582b7e3Smrg# As a special exception to the GNU General Public License, if you
22c582b7e3Smrg# distribute this file as part of a program that contains a
23c582b7e3Smrg# configuration script generated by Autoconf, you may include it under
24c582b7e3Smrg# the same distribution terms that you use for the rest of that program.
25c582b7e3Smrg
26c582b7e3Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27c582b7e3Smrg
28c582b7e3Smrgcase $1 in
29c582b7e3Smrg  '')
30e3d74329Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31e3d74329Smrg    exit 1;
32e3d74329Smrg    ;;
33c582b7e3Smrg  -h | --h*)
34c582b7e3Smrg    cat <<\EOF
35c582b7e3SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36c582b7e3Smrg
37c582b7e3SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38c582b7e3Smrgas side-effects.
39c582b7e3Smrg
40c582b7e3SmrgEnvironment variables:
41c582b7e3Smrg  depmode     Dependency tracking mode.
420496e070Smrg  source      Source file read by 'PROGRAMS ARGS'.
430496e070Smrg  object      Object file output by 'PROGRAMS ARGS'.
44c582b7e3Smrg  DEPDIR      directory where to store dependencies.
45c582b7e3Smrg  depfile     Dependency file to output.
4642a55b46Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47c582b7e3Smrg  libtool     Whether libtool is used (yes/no).
48c582b7e3Smrg
49c582b7e3SmrgReport bugs to <bug-automake@gnu.org>.
50c582b7e3SmrgEOF
51c582b7e3Smrg    exit $?
52c582b7e3Smrg    ;;
53c582b7e3Smrg  -v | --v*)
54c582b7e3Smrg    echo "depcomp $scriptversion"
55c582b7e3Smrg    exit $?
56c582b7e3Smrg    ;;
57c582b7e3Smrgesac
58c582b7e3Smrg
59e3d74329Smrg# Get the directory component of the given path, and save it in the
60e3d74329Smrg# global variables '$dir'.  Note that this directory component will
61e3d74329Smrg# be either empty or ending with a '/' character.  This is deliberate.
62e3d74329Smrgset_dir_from ()
63e3d74329Smrg{
64e3d74329Smrg  case $1 in
65e3d74329Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66e3d74329Smrg      *) dir=;;
67e3d74329Smrg  esac
68e3d74329Smrg}
69e3d74329Smrg
70e3d74329Smrg# Get the suffix-stripped basename of the given path, and save it the
71e3d74329Smrg# global variable '$base'.
72e3d74329Smrgset_base_from ()
73e3d74329Smrg{
74e3d74329Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75e3d74329Smrg}
76e3d74329Smrg
77e3d74329Smrg# If no dependency file was actually created by the compiler invocation,
78e3d74329Smrg# we still have to create a dummy depfile, to avoid errors with the
79e3d74329Smrg# Makefile "include basename.Plo" scheme.
80e3d74329Smrgmake_dummy_depfile ()
81e3d74329Smrg{
82e3d74329Smrg  echo "#dummy" > "$depfile"
83e3d74329Smrg}
84e3d74329Smrg
85e3d74329Smrg# Factor out some common post-processing of the generated depfile.
86e3d74329Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87e3d74329Smrgaix_post_process_depfile ()
88e3d74329Smrg{
89e3d74329Smrg  # If the compiler actually managed to produce a dependency file,
90e3d74329Smrg  # post-process it.
91e3d74329Smrg  if test -f "$tmpdepfile"; then
92e3d74329Smrg    # Each line is of the form 'foo.o: dependency.h'.
93e3d74329Smrg    # Do two passes, one to just change these to
94e3d74329Smrg    #   $object: dependency.h
95e3d74329Smrg    # and one to simply output
96e3d74329Smrg    #   dependency.h:
97e3d74329Smrg    # which is needed to avoid the deleted-header problem.
98e3d74329Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99e3d74329Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100e3d74329Smrg    } > "$depfile"
101e3d74329Smrg    rm -f "$tmpdepfile"
102e3d74329Smrg  else
103e3d74329Smrg    make_dummy_depfile
104e3d74329Smrg  fi
105e3d74329Smrg}
106e3d74329Smrg
1070496e070Smrg# A tabulation character.
1080496e070Smrgtab='	'
1090496e070Smrg# A newline character.
1100496e070Smrgnl='
1110496e070Smrg'
112e3d74329Smrg# Character ranges might be problematic outside the C locale.
113e3d74329Smrg# These definitions help.
114e3d74329Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115e3d74329Smrglower=abcdefghijklmnopqrstuvwxyz
116e3d74329Smrgdigits=0123456789
117e3d74329Smrgalpha=${upper}${lower}
1180496e070Smrg
119c582b7e3Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120c582b7e3Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121c582b7e3Smrg  exit 1
122c582b7e3Smrgfi
123c582b7e3Smrg
124c582b7e3Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125c582b7e3Smrgdepfile=${depfile-`echo "$object" |
126c582b7e3Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127c582b7e3Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128c582b7e3Smrg
129c582b7e3Smrgrm -f "$tmpdepfile"
130c582b7e3Smrg
131e3d74329Smrg# Avoid interferences from the environment.
132e3d74329Smrggccflag= dashmflag=
133e3d74329Smrg
134c582b7e3Smrg# Some modes work just like other modes, but use different flags.  We
135c582b7e3Smrg# parameterize here, but still list the modes in the big case below,
136c582b7e3Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137c582b7e3Smrg# here, because this file can only contain one case statement.
138c582b7e3Smrgif test "$depmode" = hp; then
139c582b7e3Smrg  # HP compiler uses -M and no extra arg.
140c582b7e3Smrg  gccflag=-M
141c582b7e3Smrg  depmode=gcc
142c582b7e3Smrgfi
143c582b7e3Smrg
144c582b7e3Smrgif test "$depmode" = dashXmstdout; then
145e3d74329Smrg  # This is just like dashmstdout with a different argument.
146e3d74329Smrg  dashmflag=-xM
147e3d74329Smrg  depmode=dashmstdout
148c582b7e3Smrgfi
149c582b7e3Smrg
15019019ffeSmrgcygpath_u="cygpath -u -f -"
15119019ffeSmrgif test "$depmode" = msvcmsys; then
152e3d74329Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153e3d74329Smrg  # Just convert the backslash-escaped backslashes to single forward
154e3d74329Smrg  # slashes to satisfy depend.m4
155e3d74329Smrg  cygpath_u='sed s,\\\\,/,g'
156e3d74329Smrg  depmode=msvisualcpp
15719019ffeSmrgfi
15819019ffeSmrg
15942a55b46Smrgif test "$depmode" = msvc7msys; then
160e3d74329Smrg  # This is just like msvc7 but w/o cygpath translation.
161e3d74329Smrg  # Just convert the backslash-escaped backslashes to single forward
162e3d74329Smrg  # slashes to satisfy depend.m4
163e3d74329Smrg  cygpath_u='sed s,\\\\,/,g'
164e3d74329Smrg  depmode=msvc7
16542a55b46Smrgfi
16642a55b46Smrg
1670496e070Smrgif test "$depmode" = xlc; then
168e3d74329Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169e3d74329Smrg  gccflag=-qmakedep=gcc,-MF
170e3d74329Smrg  depmode=gcc
1710496e070Smrgfi
1720496e070Smrg
173c582b7e3Smrgcase "$depmode" in
174c582b7e3Smrggcc3)
175c582b7e3Smrg## gcc 3 implements dependency tracking that does exactly what
176c582b7e3Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177c582b7e3Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178c582b7e3Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179c582b7e3Smrg## the command line argument order; so add the flags where they
180c582b7e3Smrg## appear in depend2.am.  Note that the slowdown incurred here
181c582b7e3Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182c582b7e3Smrg  for arg
183c582b7e3Smrg  do
184c582b7e3Smrg    case $arg in
185c582b7e3Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186c582b7e3Smrg    *)  set fnord "$@" "$arg" ;;
187c582b7e3Smrg    esac
188c582b7e3Smrg    shift # fnord
189c582b7e3Smrg    shift # $arg
190c582b7e3Smrg  done
191c582b7e3Smrg  "$@"
192c582b7e3Smrg  stat=$?
193e3d74329Smrg  if test $stat -ne 0; then
194c582b7e3Smrg    rm -f "$tmpdepfile"
195c582b7e3Smrg    exit $stat
196c582b7e3Smrg  fi
197c582b7e3Smrg  mv "$tmpdepfile" "$depfile"
198c582b7e3Smrg  ;;
199c582b7e3Smrg
200c582b7e3Smrggcc)
201e3d74329Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202e3d74329Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203e3d74329Smrg## (see the conditional assignment to $gccflag above).
204c582b7e3Smrg## There are various ways to get dependency output from gcc.  Here's
205c582b7e3Smrg## why we pick this rather obscure method:
206c582b7e3Smrg## - Don't want to use -MD because we'd like the dependencies to end
207c582b7e3Smrg##   up in a subdir.  Having to rename by hand is ugly.
208c582b7e3Smrg##   (We might end up doing this anyway to support other compilers.)
209c582b7e3Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210e3d74329Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211e3d74329Smrg##   supported by the other compilers which use the 'gcc' depmode.
212c582b7e3Smrg## - Using -M directly means running the compiler twice (even worse
213c582b7e3Smrg##   than renaming).
214c582b7e3Smrg  if test -z "$gccflag"; then
215c582b7e3Smrg    gccflag=-MD,
216c582b7e3Smrg  fi
217c582b7e3Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218c582b7e3Smrg  stat=$?
219e3d74329Smrg  if test $stat -ne 0; then
220c582b7e3Smrg    rm -f "$tmpdepfile"
221c582b7e3Smrg    exit $stat
222c582b7e3Smrg  fi
223c582b7e3Smrg  rm -f "$depfile"
224c582b7e3Smrg  echo "$object : \\" > "$depfile"
225e3d74329Smrg  # The second -e expression handles DOS-style file names with drive
226e3d74329Smrg  # letters.
227c582b7e3Smrg  sed -e 's/^[^:]*: / /' \
228c582b7e3Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2290496e070Smrg## This next piece of magic avoids the "deleted header file" problem.
230c582b7e3Smrg## The problem is that when a header file which appears in a .P file
231c582b7e3Smrg## is deleted, the dependency causes make to die (because there is
232c582b7e3Smrg## typically no way to rebuild the header).  We avoid this by adding
233c582b7e3Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234c582b7e3Smrg## this for us directly.
2350496e070Smrg## Some versions of gcc put a space before the ':'.  On the theory
236c582b7e3Smrg## that the space means something, we add a space to the output as
23742a55b46Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23842a55b46Smrg## to the object.  Take care to not repeat it in the output.
239c582b7e3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240c582b7e3Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241e3d74329Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242e3d74329Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243e3d74329Smrg    | sed -e 's/$/ :/' >> "$depfile"
244c582b7e3Smrg  rm -f "$tmpdepfile"
245c582b7e3Smrg  ;;
246c582b7e3Smrg
247c582b7e3Smrghp)
248c582b7e3Smrg  # This case exists only to let depend.m4 do its work.  It works by
249c582b7e3Smrg  # looking at the text of this script.  This case will never be run,
250c582b7e3Smrg  # since it is checked for above.
251c582b7e3Smrg  exit 1
252c582b7e3Smrg  ;;
253c582b7e3Smrg
254c582b7e3Smrgsgi)
255c582b7e3Smrg  if test "$libtool" = yes; then
256c582b7e3Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257c582b7e3Smrg  else
258c582b7e3Smrg    "$@" -MDupdate "$tmpdepfile"
259c582b7e3Smrg  fi
260c582b7e3Smrg  stat=$?
261e3d74329Smrg  if test $stat -ne 0; then
262c582b7e3Smrg    rm -f "$tmpdepfile"
263c582b7e3Smrg    exit $stat
264c582b7e3Smrg  fi
265c582b7e3Smrg  rm -f "$depfile"
266c582b7e3Smrg
267c582b7e3Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268c582b7e3Smrg    echo "$object : \\" > "$depfile"
269c582b7e3Smrg    # Clip off the initial element (the dependent).  Don't try to be
270c582b7e3Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271c582b7e3Smrg    # lines with more than a fixed number of characters (4096 in
272c582b7e3Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2730496e070Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274c582b7e3Smrg    # dependency line.
2750496e070Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276e3d74329Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277e3d74329Smrg      | tr "$nl" ' ' >> "$depfile"
27819019ffeSmrg    echo >> "$depfile"
279c582b7e3Smrg    # The second pass generates a dummy entry for each header file.
2800496e070Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281e3d74329Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282e3d74329Smrg      >> "$depfile"
283c582b7e3Smrg  else
284e3d74329Smrg    make_dummy_depfile
285c582b7e3Smrg  fi
286c582b7e3Smrg  rm -f "$tmpdepfile"
287c582b7e3Smrg  ;;
288c582b7e3Smrg
2890496e070Smrgxlc)
2900496e070Smrg  # This case exists only to let depend.m4 do its work.  It works by
2910496e070Smrg  # looking at the text of this script.  This case will never be run,
2920496e070Smrg  # since it is checked for above.
2930496e070Smrg  exit 1
2940496e070Smrg  ;;
2950496e070Smrg
296c582b7e3Smrgaix)
297c582b7e3Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298c582b7e3Smrg  # in a .u file.  In older versions, this file always lives in the
2990496e070Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300c582b7e3Smrg  # start of each line; $object doesn't have directory information.
301c582b7e3Smrg  # Version 6 uses the directory in both cases.
302e3d74329Smrg  set_dir_from "$object"
303e3d74329Smrg  set_base_from "$object"
304c582b7e3Smrg  if test "$libtool" = yes; then
305c582b7e3Smrg    tmpdepfile1=$dir$base.u
306c582b7e3Smrg    tmpdepfile2=$base.u
307c582b7e3Smrg    tmpdepfile3=$dir.libs/$base.u
308c582b7e3Smrg    "$@" -Wc,-M
309c582b7e3Smrg  else
310c582b7e3Smrg    tmpdepfile1=$dir$base.u
311c582b7e3Smrg    tmpdepfile2=$dir$base.u
312c582b7e3Smrg    tmpdepfile3=$dir$base.u
313c582b7e3Smrg    "$@" -M
314c582b7e3Smrg  fi
315c582b7e3Smrg  stat=$?
316e3d74329Smrg  if test $stat -ne 0; then
317c582b7e3Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318c582b7e3Smrg    exit $stat
319c582b7e3Smrg  fi
320c582b7e3Smrg
321c582b7e3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322c582b7e3Smrg  do
323c582b7e3Smrg    test -f "$tmpdepfile" && break
324c582b7e3Smrg  done
325e3d74329Smrg  aix_post_process_depfile
326e3d74329Smrg  ;;
327e3d74329Smrg
328e3d74329Smrgtcc)
329e3d74329Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330e3d74329Smrg  # FIXME: That version still under development at the moment of writing.
331e3d74329Smrg  #        Make that this statement remains true also for stable, released
332e3d74329Smrg  #        versions.
333e3d74329Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334e3d74329Smrg  # trailing '\', as in:
335e3d74329Smrg  #
336e3d74329Smrg  #   foo.o : \
337e3d74329Smrg  #    foo.c \
338e3d74329Smrg  #    foo.h \
339e3d74329Smrg  #
340e3d74329Smrg  # It will put a trailing '\' even on the last line, and will use leading
341e3d74329Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342e3d74329Smrg  # "Emit spaces for -MD").
343e3d74329Smrg  "$@" -MD -MF "$tmpdepfile"
344e3d74329Smrg  stat=$?
345e3d74329Smrg  if test $stat -ne 0; then
346e3d74329Smrg    rm -f "$tmpdepfile"
347e3d74329Smrg    exit $stat
348c582b7e3Smrg  fi
349e3d74329Smrg  rm -f "$depfile"
350e3d74329Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351e3d74329Smrg  # We have to change lines of the first kind to '$object: \'.
352e3d74329Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353e3d74329Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354e3d74329Smrg  # dummy dependency, to avoid the deleted-header problem.
355e3d74329Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356c582b7e3Smrg  rm -f "$tmpdepfile"
357c582b7e3Smrg  ;;
358c582b7e3Smrg
359e3d74329Smrg## The order of this option in the case statement is important, since the
360e3d74329Smrg## shell code in configure will try each of these formats in the order
361e3d74329Smrg## listed in this file.  A plain '-MD' option would be understood by many
362e3d74329Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363e3d74329Smrgpgcc)
364e3d74329Smrg  # Portland's C compiler understands '-MD'.
365e3d74329Smrg  # Will always output deps to 'file.d' where file is the root name of the
366e3d74329Smrg  # source file under compilation, even if file resides in a subdirectory.
367e3d74329Smrg  # The object file name does not affect the name of the '.d' file.
368e3d74329Smrg  # pgcc 10.2 will output
369c582b7e3Smrg  #    foo.o: sub/foo.c sub/foo.h
370e3d74329Smrg  # and will wrap long lines using '\' :
371c582b7e3Smrg  #    foo.o: sub/foo.c ... \
372c582b7e3Smrg  #     sub/foo.h ... \
373c582b7e3Smrg  #     ...
374e3d74329Smrg  set_dir_from "$object"
375e3d74329Smrg  # Use the source, not the object, to determine the base name, since
376e3d74329Smrg  # that's sadly what pgcc will do too.
377e3d74329Smrg  set_base_from "$source"
378e3d74329Smrg  tmpdepfile=$base.d
379e3d74329Smrg
380e3d74329Smrg  # For projects that build the same source file twice into different object
381e3d74329Smrg  # files, the pgcc approach of using the *source* file root name can cause
382e3d74329Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383e3d74329Smrg  # the same $tmpdepfile.
384e3d74329Smrg  lockdir=$base.d-lock
385e3d74329Smrg  trap "
386e3d74329Smrg    echo '$0: caught signal, cleaning up...' >&2
387e3d74329Smrg    rmdir '$lockdir'
388e3d74329Smrg    exit 1
389e3d74329Smrg  " 1 2 13 15
390e3d74329Smrg  numtries=100
391e3d74329Smrg  i=$numtries
392e3d74329Smrg  while test $i -gt 0; do
393e3d74329Smrg    # mkdir is a portable test-and-set.
394e3d74329Smrg    if mkdir "$lockdir" 2>/dev/null; then
395e3d74329Smrg      # This process acquired the lock.
396e3d74329Smrg      "$@" -MD
397e3d74329Smrg      stat=$?
398e3d74329Smrg      # Release the lock.
399e3d74329Smrg      rmdir "$lockdir"
400e3d74329Smrg      break
401e3d74329Smrg    else
402e3d74329Smrg      # If the lock is being held by a different process, wait
403e3d74329Smrg      # until the winning process is done or we timeout.
404e3d74329Smrg      while test -d "$lockdir" && test $i -gt 0; do
405e3d74329Smrg        sleep 1
406e3d74329Smrg        i=`expr $i - 1`
407e3d74329Smrg      done
408e3d74329Smrg    fi
409e3d74329Smrg    i=`expr $i - 1`
410e3d74329Smrg  done
411e3d74329Smrg  trap - 1 2 13 15
412e3d74329Smrg  if test $i -le 0; then
413e3d74329Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414e3d74329Smrg    echo "$0: check lockdir '$lockdir'" >&2
415e3d74329Smrg    exit 1
416e3d74329Smrg  fi
417e3d74329Smrg
418e3d74329Smrg  if test $stat -ne 0; then
419c582b7e3Smrg    rm -f "$tmpdepfile"
420c582b7e3Smrg    exit $stat
421c582b7e3Smrg  fi
422c582b7e3Smrg  rm -f "$depfile"
423e3d74329Smrg  # Each line is of the form `foo.o: dependent.h',
424e3d74329Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425c582b7e3Smrg  # Do two passes, one to just change these to
426e3d74329Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427e3d74329Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428e3d74329Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429e3d74329Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430e3d74329Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431e3d74329Smrg    | sed -e 's/$/ :/' >> "$depfile"
432c582b7e3Smrg  rm -f "$tmpdepfile"
433c582b7e3Smrg  ;;
434c582b7e3Smrg
435c582b7e3Smrghp2)
436c582b7e3Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437c582b7e3Smrg  # compilers, which have integrated preprocessors.  The correct option
438c582b7e3Smrg  # to use with these is +Maked; it writes dependencies to a file named
439c582b7e3Smrg  # 'foo.d', which lands next to the object file, wherever that
440c582b7e3Smrg  # happens to be.
441c582b7e3Smrg  # Much of this is similar to the tru64 case; see comments there.
442e3d74329Smrg  set_dir_from  "$object"
443e3d74329Smrg  set_base_from "$object"
444c582b7e3Smrg  if test "$libtool" = yes; then
445c582b7e3Smrg    tmpdepfile1=$dir$base.d
446c582b7e3Smrg    tmpdepfile2=$dir.libs/$base.d
447c582b7e3Smrg    "$@" -Wc,+Maked
448c582b7e3Smrg  else
449c582b7e3Smrg    tmpdepfile1=$dir$base.d
450c582b7e3Smrg    tmpdepfile2=$dir$base.d
451c582b7e3Smrg    "$@" +Maked
452c582b7e3Smrg  fi
453c582b7e3Smrg  stat=$?
454e3d74329Smrg  if test $stat -ne 0; then
455c582b7e3Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456c582b7e3Smrg     exit $stat
457c582b7e3Smrg  fi
458c582b7e3Smrg
459c582b7e3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460c582b7e3Smrg  do
461c582b7e3Smrg    test -f "$tmpdepfile" && break
462c582b7e3Smrg  done
463c582b7e3Smrg  if test -f "$tmpdepfile"; then
464e3d74329Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4650496e070Smrg    # Add 'dependent.h:' lines.
46619019ffeSmrg    sed -ne '2,${
467e3d74329Smrg               s/^ *//
468e3d74329Smrg               s/ \\*$//
469e3d74329Smrg               s/$/:/
470e3d74329Smrg               p
471e3d74329Smrg             }' "$tmpdepfile" >> "$depfile"
472c582b7e3Smrg  else
473e3d74329Smrg    make_dummy_depfile
474c582b7e3Smrg  fi
475c582b7e3Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476c582b7e3Smrg  ;;
477c582b7e3Smrg
478c582b7e3Smrgtru64)
479e3d74329Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480e3d74329Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481e3d74329Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482e3d74329Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483e3d74329Smrg  # Subdirectories are respected.
484e3d74329Smrg  set_dir_from  "$object"
485e3d74329Smrg  set_base_from "$object"
486e3d74329Smrg
487e3d74329Smrg  if test "$libtool" = yes; then
488e3d74329Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489e3d74329Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490e3d74329Smrg    # in $dir$base.o.d.  We have to check for both files, because
491e3d74329Smrg    # one of the two compilations can be disabled.  We should prefer
492e3d74329Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493e3d74329Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494e3d74329Smrg    # the former would cause a distcleancheck panic.
495e3d74329Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496e3d74329Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497e3d74329Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498e3d74329Smrg    "$@" -Wc,-MD
499e3d74329Smrg  else
500e3d74329Smrg    tmpdepfile1=$dir$base.d
501e3d74329Smrg    tmpdepfile2=$dir$base.d
502e3d74329Smrg    tmpdepfile3=$dir$base.d
503e3d74329Smrg    "$@" -MD
504e3d74329Smrg  fi
505e3d74329Smrg
506e3d74329Smrg  stat=$?
507e3d74329Smrg  if test $stat -ne 0; then
508e3d74329Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509e3d74329Smrg    exit $stat
510e3d74329Smrg  fi
511e3d74329Smrg
512e3d74329Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513e3d74329Smrg  do
514e3d74329Smrg    test -f "$tmpdepfile" && break
515e3d74329Smrg  done
516e3d74329Smrg  # Same post-processing that is required for AIX mode.
517e3d74329Smrg  aix_post_process_depfile
518e3d74329Smrg  ;;
519c582b7e3Smrg
52042a55b46Smrgmsvc7)
52142a55b46Smrg  if test "$libtool" = yes; then
52242a55b46Smrg    showIncludes=-Wc,-showIncludes
52342a55b46Smrg  else
52442a55b46Smrg    showIncludes=-showIncludes
52542a55b46Smrg  fi
52642a55b46Smrg  "$@" $showIncludes > "$tmpdepfile"
52742a55b46Smrg  stat=$?
52842a55b46Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529e3d74329Smrg  if test $stat -ne 0; then
53042a55b46Smrg    rm -f "$tmpdepfile"
53142a55b46Smrg    exit $stat
53242a55b46Smrg  fi
53342a55b46Smrg  rm -f "$depfile"
53442a55b46Smrg  echo "$object : \\" > "$depfile"
53542a55b46Smrg  # The first sed program below extracts the file names and escapes
53642a55b46Smrg  # backslashes for cygpath.  The second sed program outputs the file
53742a55b46Smrg  # name when reading, but also accumulates all include files in the
53842a55b46Smrg  # hold buffer in order to output them again at the end.  This only
53942a55b46Smrg  # works with sed implementations that can handle large buffers.
54042a55b46Smrg  sed < "$tmpdepfile" -n '
54142a55b46Smrg/^Note: including file:  *\(.*\)/ {
54242a55b46Smrg  s//\1/
54342a55b46Smrg  s/\\/\\\\/g
54442a55b46Smrg  p
54542a55b46Smrg}' | $cygpath_u | sort -u | sed -n '
54642a55b46Smrgs/ /\\ /g
5470496e070Smrgs/\(.*\)/'"$tab"'\1 \\/p
54842a55b46Smrgs/.\(.*\) \\/\1:/
54942a55b46SmrgH
55042a55b46Smrg$ {
5510496e070Smrg  s/.*/'"$tab"'/
55242a55b46Smrg  G
55342a55b46Smrg  p
55442a55b46Smrg}' >> "$depfile"
555e3d74329Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55642a55b46Smrg  rm -f "$tmpdepfile"
55742a55b46Smrg  ;;
55842a55b46Smrg
55942a55b46Smrgmsvc7msys)
56042a55b46Smrg  # This case exists only to let depend.m4 do its work.  It works by
56142a55b46Smrg  # looking at the text of this script.  This case will never be run,
56242a55b46Smrg  # since it is checked for above.
56342a55b46Smrg  exit 1
56442a55b46Smrg  ;;
56542a55b46Smrg
566c582b7e3Smrg#nosideeffect)
567c582b7e3Smrg  # This comment above is used by automake to tell side-effect
568c582b7e3Smrg  # dependency tracking mechanisms from slower ones.
569c582b7e3Smrg
570c582b7e3Smrgdashmstdout)
571c582b7e3Smrg  # Important note: in order to support this mode, a compiler *must*
572c582b7e3Smrg  # always write the preprocessed file to stdout, regardless of -o.
573c582b7e3Smrg  "$@" || exit $?
574c582b7e3Smrg
575c582b7e3Smrg  # Remove the call to Libtool.
576c582b7e3Smrg  if test "$libtool" = yes; then
57719019ffeSmrg    while test "X$1" != 'X--mode=compile'; do
578c582b7e3Smrg      shift
579c582b7e3Smrg    done
580c582b7e3Smrg    shift
581c582b7e3Smrg  fi
582c582b7e3Smrg
5830496e070Smrg  # Remove '-o $object'.
584c582b7e3Smrg  IFS=" "
585c582b7e3Smrg  for arg
586c582b7e3Smrg  do
587c582b7e3Smrg    case $arg in
588c582b7e3Smrg    -o)
589c582b7e3Smrg      shift
590c582b7e3Smrg      ;;
591c582b7e3Smrg    $object)
592c582b7e3Smrg      shift
593c582b7e3Smrg      ;;
594c582b7e3Smrg    *)
595c582b7e3Smrg      set fnord "$@" "$arg"
596c582b7e3Smrg      shift # fnord
597c582b7e3Smrg      shift # $arg
598c582b7e3Smrg      ;;
599c582b7e3Smrg    esac
600c582b7e3Smrg  done
601c582b7e3Smrg
602c582b7e3Smrg  test -z "$dashmflag" && dashmflag=-M
6030496e070Smrg  # Require at least two characters before searching for ':'
604c582b7e3Smrg  # in the target name.  This is to cope with DOS-style filenames:
6050496e070Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606c582b7e3Smrg  "$@" $dashmflag |
607e3d74329Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608c582b7e3Smrg  rm -f "$depfile"
609c582b7e3Smrg  cat < "$tmpdepfile" > "$depfile"
610e3d74329Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611e3d74329Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612e3d74329Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613e3d74329Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614e3d74329Smrg    | sed -e 's/$/ :/' >> "$depfile"
615c582b7e3Smrg  rm -f "$tmpdepfile"
616c582b7e3Smrg  ;;
617c582b7e3Smrg
618c582b7e3SmrgdashXmstdout)
619c582b7e3Smrg  # This case only exists to satisfy depend.m4.  It is never actually
620c582b7e3Smrg  # run, as this mode is specially recognized in the preamble.
621c582b7e3Smrg  exit 1
622c582b7e3Smrg  ;;
623c582b7e3Smrg
624c582b7e3Smrgmakedepend)
625c582b7e3Smrg  "$@" || exit $?
626c582b7e3Smrg  # Remove any Libtool call
627c582b7e3Smrg  if test "$libtool" = yes; then
62819019ffeSmrg    while test "X$1" != 'X--mode=compile'; do
629c582b7e3Smrg      shift
630c582b7e3Smrg    done
631c582b7e3Smrg    shift
632c582b7e3Smrg  fi
633c582b7e3Smrg  # X makedepend
634c582b7e3Smrg  shift
63519019ffeSmrg  cleared=no eat=no
63619019ffeSmrg  for arg
63719019ffeSmrg  do
638c582b7e3Smrg    case $cleared in
639c582b7e3Smrg    no)
640c582b7e3Smrg      set ""; shift
641c582b7e3Smrg      cleared=yes ;;
642c582b7e3Smrg    esac
64319019ffeSmrg    if test $eat = yes; then
64419019ffeSmrg      eat=no
64519019ffeSmrg      continue
64619019ffeSmrg    fi
647c582b7e3Smrg    case "$arg" in
648c582b7e3Smrg    -D*|-I*)
649c582b7e3Smrg      set fnord "$@" "$arg"; shift ;;
650c582b7e3Smrg    # Strip any option that makedepend may not understand.  Remove
651c582b7e3Smrg    # the object too, otherwise makedepend will parse it as a source file.
65219019ffeSmrg    -arch)
65319019ffeSmrg      eat=yes ;;
654c582b7e3Smrg    -*|$object)
655c582b7e3Smrg      ;;
656c582b7e3Smrg    *)
657c582b7e3Smrg      set fnord "$@" "$arg"; shift ;;
658c582b7e3Smrg    esac
659c582b7e3Smrg  done
66019019ffeSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661c582b7e3Smrg  touch "$tmpdepfile"
662c582b7e3Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663c582b7e3Smrg  rm -f "$depfile"
66442a55b46Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66542a55b46Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66642a55b46Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667e3d74329Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668e3d74329Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669e3d74329Smrg  sed '1,2d' "$tmpdepfile" \
670e3d74329Smrg    | tr ' ' "$nl" \
671e3d74329Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672e3d74329Smrg    | sed -e 's/$/ :/' >> "$depfile"
673c582b7e3Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674c582b7e3Smrg  ;;
675c582b7e3Smrg
676c582b7e3Smrgcpp)
677c582b7e3Smrg  # Important note: in order to support this mode, a compiler *must*
678c582b7e3Smrg  # always write the preprocessed file to stdout.
679c582b7e3Smrg  "$@" || exit $?
680c582b7e3Smrg
681c582b7e3Smrg  # Remove the call to Libtool.
682c582b7e3Smrg  if test "$libtool" = yes; then
68319019ffeSmrg    while test "X$1" != 'X--mode=compile'; do
684c582b7e3Smrg      shift
685c582b7e3Smrg    done
686c582b7e3Smrg    shift
687c582b7e3Smrg  fi
688c582b7e3Smrg
6890496e070Smrg  # Remove '-o $object'.
690c582b7e3Smrg  IFS=" "
691c582b7e3Smrg  for arg
692c582b7e3Smrg  do
693c582b7e3Smrg    case $arg in
694c582b7e3Smrg    -o)
695c582b7e3Smrg      shift
696c582b7e3Smrg      ;;
697c582b7e3Smrg    $object)
698c582b7e3Smrg      shift
699c582b7e3Smrg      ;;
700c582b7e3Smrg    *)
701c582b7e3Smrg      set fnord "$@" "$arg"
702c582b7e3Smrg      shift # fnord
703c582b7e3Smrg      shift # $arg
704c582b7e3Smrg      ;;
705c582b7e3Smrg    esac
706c582b7e3Smrg  done
707c582b7e3Smrg
708e3d74329Smrg  "$@" -E \
709e3d74329Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710e3d74329Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711e3d74329Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712c582b7e3Smrg  rm -f "$depfile"
713c582b7e3Smrg  echo "$object : \\" > "$depfile"
714c582b7e3Smrg  cat < "$tmpdepfile" >> "$depfile"
715c582b7e3Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716c582b7e3Smrg  rm -f "$tmpdepfile"
717c582b7e3Smrg  ;;
718c582b7e3Smrg
719c582b7e3Smrgmsvisualcpp)
720c582b7e3Smrg  # Important note: in order to support this mode, a compiler *must*
72119019ffeSmrg  # always write the preprocessed file to stdout.
722c582b7e3Smrg  "$@" || exit $?
72319019ffeSmrg
72419019ffeSmrg  # Remove the call to Libtool.
72519019ffeSmrg  if test "$libtool" = yes; then
72619019ffeSmrg    while test "X$1" != 'X--mode=compile'; do
72719019ffeSmrg      shift
72819019ffeSmrg    done
72919019ffeSmrg    shift
73019019ffeSmrg  fi
73119019ffeSmrg
732c582b7e3Smrg  IFS=" "
733c582b7e3Smrg  for arg
734c582b7e3Smrg  do
735c582b7e3Smrg    case "$arg" in
73619019ffeSmrg    -o)
73719019ffeSmrg      shift
73819019ffeSmrg      ;;
73919019ffeSmrg    $object)
74019019ffeSmrg      shift
74119019ffeSmrg      ;;
742c582b7e3Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743e3d74329Smrg        set fnord "$@"
744e3d74329Smrg        shift
745e3d74329Smrg        shift
746e3d74329Smrg        ;;
747c582b7e3Smrg    *)
748e3d74329Smrg        set fnord "$@" "$arg"
749e3d74329Smrg        shift
750e3d74329Smrg        shift
751e3d74329Smrg        ;;
752c582b7e3Smrg    esac
753c582b7e3Smrg  done
75419019ffeSmrg  "$@" -E 2>/dev/null |
75519019ffeSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756c582b7e3Smrg  rm -f "$depfile"
757c582b7e3Smrg  echo "$object : \\" > "$depfile"
7580496e070Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7590496e070Smrg  echo "$tab" >> "$depfile"
76019019ffeSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761c582b7e3Smrg  rm -f "$tmpdepfile"
762c582b7e3Smrg  ;;
763c582b7e3Smrg
76419019ffeSmrgmsvcmsys)
76519019ffeSmrg  # This case exists only to let depend.m4 do its work.  It works by
76619019ffeSmrg  # looking at the text of this script.  This case will never be run,
76719019ffeSmrg  # since it is checked for above.
76819019ffeSmrg  exit 1
76919019ffeSmrg  ;;
77019019ffeSmrg
771c582b7e3Smrgnone)
772c582b7e3Smrg  exec "$@"
773c582b7e3Smrg  ;;
774c582b7e3Smrg
775c582b7e3Smrg*)
776c582b7e3Smrg  echo "Unknown depmode $depmode" 1>&2
777c582b7e3Smrg  exit 1
778c582b7e3Smrg  ;;
779c582b7e3Smrgesac
780c582b7e3Smrg
781c582b7e3Smrgexit 0
782c582b7e3Smrg
783c582b7e3Smrg# Local Variables:
784c582b7e3Smrg# mode: shell-script
785c582b7e3Smrg# sh-indentation: 2
7868ce07328Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
787c582b7e3Smrg# time-stamp-start: "scriptversion="
788c582b7e3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7898ce07328Smrg# time-stamp-time-zone: "UTC0"
79019019ffeSmrg# time-stamp-end: "; # UTC"
791c582b7e3Smrg# End:
792