1a6d9b409Smrg#! /bin/sh
2a6d9b409Smrg# depcomp - compile a program generating dependencies as side-effects
3a6d9b409Smrg
4838f5b0bSmrgscriptversion=2024-06-19.01; # UTC
5a6d9b409Smrg
6838f5b0bSmrg# Copyright (C) 1999-2024 Free Software Foundation, Inc.
7a6d9b409Smrg
8a6d9b409Smrg# This program is free software; you can redistribute it and/or modify
9a6d9b409Smrg# it under the terms of the GNU General Public License as published by
10a6d9b409Smrg# the Free Software Foundation; either version 2, or (at your option)
11a6d9b409Smrg# any later version.
12a6d9b409Smrg
13a6d9b409Smrg# This program is distributed in the hope that it will be useful,
14a6d9b409Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15a6d9b409Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16a6d9b409Smrg# GNU General Public License for more details.
17a6d9b409Smrg
18a6d9b409Smrg# You should have received a copy of the GNU General Public License
1992e95ad1Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20a6d9b409Smrg
21a6d9b409Smrg# As a special exception to the GNU General Public License, if you
22a6d9b409Smrg# distribute this file as part of a program that contains a
23a6d9b409Smrg# configuration script generated by Autoconf, you may include it under
24a6d9b409Smrg# the same distribution terms that you use for the rest of that program.
25a6d9b409Smrg
26a6d9b409Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27a6d9b409Smrg
28a6d9b409Smrgcase $1 in
29a6d9b409Smrg  '')
30b91640d3Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31b91640d3Smrg    exit 1;
32b91640d3Smrg    ;;
33a6d9b409Smrg  -h | --h*)
34a6d9b409Smrg    cat <<\EOF
35a6d9b409SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36a6d9b409Smrg
37a6d9b409SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38a6d9b409Smrgas side-effects.
39a6d9b409Smrg
40a6d9b409SmrgEnvironment variables:
41a6d9b409Smrg  depmode     Dependency tracking mode.
42b91640d3Smrg  source      Source file read by 'PROGRAMS ARGS'.
43b91640d3Smrg  object      Object file output by 'PROGRAMS ARGS'.
44a6d9b409Smrg  DEPDIR      directory where to store dependencies.
45a6d9b409Smrg  depfile     Dependency file to output.
46a097bd00Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47a6d9b409Smrg  libtool     Whether libtool is used (yes/no).
48a6d9b409Smrg
49a6d9b409SmrgReport bugs to <bug-automake@gnu.org>.
50838f5b0bSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
51838f5b0bSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>.
52a6d9b409SmrgEOF
53a6d9b409Smrg    exit $?
54a6d9b409Smrg    ;;
55a6d9b409Smrg  -v | --v*)
56838f5b0bSmrg    echo "depcomp (GNU Automake) $scriptversion"
57a6d9b409Smrg    exit $?
58a6d9b409Smrg    ;;
59a6d9b409Smrgesac
60a6d9b409Smrg
61b91640d3Smrg# Get the directory component of the given path, and save it in the
62b91640d3Smrg# global variables '$dir'.  Note that this directory component will
63b91640d3Smrg# be either empty or ending with a '/' character.  This is deliberate.
64b91640d3Smrgset_dir_from ()
65b91640d3Smrg{
66b91640d3Smrg  case $1 in
67b91640d3Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
68b91640d3Smrg      *) dir=;;
69b91640d3Smrg  esac
70b91640d3Smrg}
71b91640d3Smrg
72b91640d3Smrg# Get the suffix-stripped basename of the given path, and save it the
73b91640d3Smrg# global variable '$base'.
74b91640d3Smrgset_base_from ()
75b91640d3Smrg{
76b91640d3Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
77b91640d3Smrg}
78b91640d3Smrg
79b91640d3Smrg# If no dependency file was actually created by the compiler invocation,
80b91640d3Smrg# we still have to create a dummy depfile, to avoid errors with the
81b91640d3Smrg# Makefile "include basename.Plo" scheme.
82b91640d3Smrgmake_dummy_depfile ()
83b91640d3Smrg{
84b91640d3Smrg  echo "#dummy" > "$depfile"
85b91640d3Smrg}
86b91640d3Smrg
87b91640d3Smrg# Factor out some common post-processing of the generated depfile.
88b91640d3Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
89b91640d3Smrgaix_post_process_depfile ()
90b91640d3Smrg{
91b91640d3Smrg  # If the compiler actually managed to produce a dependency file,
92b91640d3Smrg  # post-process it.
93b91640d3Smrg  if test -f "$tmpdepfile"; then
94b91640d3Smrg    # Each line is of the form 'foo.o: dependency.h'.
95b91640d3Smrg    # Do two passes, one to just change these to
96b91640d3Smrg    #   $object: dependency.h
97b91640d3Smrg    # and one to simply output
98b91640d3Smrg    #   dependency.h:
99b91640d3Smrg    # which is needed to avoid the deleted-header problem.
100b91640d3Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
101b91640d3Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
102b91640d3Smrg    } > "$depfile"
103b91640d3Smrg    rm -f "$tmpdepfile"
104b91640d3Smrg  else
105b91640d3Smrg    make_dummy_depfile
106b91640d3Smrg  fi
107b91640d3Smrg}
108b91640d3Smrg
109b91640d3Smrg# A tabulation character.
110b91640d3Smrgtab='	'
111b91640d3Smrg# A newline character.
112b91640d3Smrgnl='
113b91640d3Smrg'
114b91640d3Smrg# Character ranges might be problematic outside the C locale.
115b91640d3Smrg# These definitions help.
116b91640d3Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
117b91640d3Smrglower=abcdefghijklmnopqrstuvwxyz
118b91640d3Smrgalpha=${upper}${lower}
119b91640d3Smrg
120a6d9b409Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
121a6d9b409Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
122a6d9b409Smrg  exit 1
123a6d9b409Smrgfi
124a6d9b409Smrg
125a6d9b409Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
126a6d9b409Smrgdepfile=${depfile-`echo "$object" |
127a6d9b409Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
128a6d9b409Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
129a6d9b409Smrg
130a6d9b409Smrgrm -f "$tmpdepfile"
131a6d9b409Smrg
132838f5b0bSmrg# Avoid interference from the environment.
133b91640d3Smrggccflag= dashmflag=
134b91640d3Smrg
135a6d9b409Smrg# Some modes work just like other modes, but use different flags.  We
136a6d9b409Smrg# parameterize here, but still list the modes in the big case below,
137a6d9b409Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
138a6d9b409Smrg# here, because this file can only contain one case statement.
139a6d9b409Smrgif test "$depmode" = hp; then
140a6d9b409Smrg  # HP compiler uses -M and no extra arg.
141a6d9b409Smrg  gccflag=-M
142a6d9b409Smrg  depmode=gcc
143a6d9b409Smrgfi
144a6d9b409Smrg
145a6d9b409Smrgif test "$depmode" = dashXmstdout; then
146b91640d3Smrg  # This is just like dashmstdout with a different argument.
147b91640d3Smrg  dashmflag=-xM
148b91640d3Smrg  depmode=dashmstdout
149a6d9b409Smrgfi
150a6d9b409Smrg
151efda2da8Smrgcygpath_u="cygpath -u -f -"
152efda2da8Smrgif test "$depmode" = msvcmsys; then
153b91640d3Smrg  # This is just like msvisualcpp but w/o cygpath translation.
154b91640d3Smrg  # Just convert the backslash-escaped backslashes to single forward
155b91640d3Smrg  # slashes to satisfy depend.m4
156b91640d3Smrg  cygpath_u='sed s,\\\\,/,g'
157b91640d3Smrg  depmode=msvisualcpp
158efda2da8Smrgfi
159efda2da8Smrg
160a097bd00Smrgif test "$depmode" = msvc7msys; then
161b91640d3Smrg  # This is just like msvc7 but w/o cygpath translation.
162b91640d3Smrg  # Just convert the backslash-escaped backslashes to single forward
163b91640d3Smrg  # slashes to satisfy depend.m4
164b91640d3Smrg  cygpath_u='sed s,\\\\,/,g'
165b91640d3Smrg  depmode=msvc7
166b91640d3Smrgfi
167b91640d3Smrg
168b91640d3Smrgif test "$depmode" = xlc; then
169b91640d3Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
170b91640d3Smrg  gccflag=-qmakedep=gcc,-MF
171b91640d3Smrg  depmode=gcc
172a097bd00Smrgfi
173a097bd00Smrg
174a6d9b409Smrgcase "$depmode" in
175a6d9b409Smrggcc3)
176a6d9b409Smrg## gcc 3 implements dependency tracking that does exactly what
177a6d9b409Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
178a6d9b409Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
179cae39615Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
180cae39615Smrg## the command line argument order; so add the flags where they
181cae39615Smrg## appear in depend2.am.  Note that the slowdown incurred here
182cae39615Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
183cae39615Smrg  for arg
184cae39615Smrg  do
185cae39615Smrg    case $arg in
186cae39615Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
187cae39615Smrg    *)  set fnord "$@" "$arg" ;;
188cae39615Smrg    esac
189cae39615Smrg    shift # fnord
190cae39615Smrg    shift # $arg
191cae39615Smrg  done
192cae39615Smrg  "$@"
193a6d9b409Smrg  stat=$?
194b91640d3Smrg  if test $stat -ne 0; then
195a6d9b409Smrg    rm -f "$tmpdepfile"
196a6d9b409Smrg    exit $stat
197a6d9b409Smrg  fi
198a6d9b409Smrg  mv "$tmpdepfile" "$depfile"
199a6d9b409Smrg  ;;
200a6d9b409Smrg
201a6d9b409Smrggcc)
202838f5b0bSmrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers.
203838f5b0bSmrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler.
204b91640d3Smrg## (see the conditional assignment to $gccflag above).
205a6d9b409Smrg## There are various ways to get dependency output from gcc.  Here's
206a6d9b409Smrg## why we pick this rather obscure method:
207a6d9b409Smrg## - Don't want to use -MD because we'd like the dependencies to end
208a6d9b409Smrg##   up in a subdir.  Having to rename by hand is ugly.
209a6d9b409Smrg##   (We might end up doing this anyway to support other compilers.)
210a6d9b409Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
211b91640d3Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
212b91640d3Smrg##   supported by the other compilers which use the 'gcc' depmode.
213a6d9b409Smrg## - Using -M directly means running the compiler twice (even worse
214a6d9b409Smrg##   than renaming).
215a6d9b409Smrg  if test -z "$gccflag"; then
216a6d9b409Smrg    gccflag=-MD,
217a6d9b409Smrg  fi
218a6d9b409Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
219a6d9b409Smrg  stat=$?
220b91640d3Smrg  if test $stat -ne 0; then
221a6d9b409Smrg    rm -f "$tmpdepfile"
222a6d9b409Smrg    exit $stat
223a6d9b409Smrg  fi
224a6d9b409Smrg  rm -f "$depfile"
225a6d9b409Smrg  echo "$object : \\" > "$depfile"
226b91640d3Smrg  # The second -e expression handles DOS-style file names with drive
227b91640d3Smrg  # letters.
228a6d9b409Smrg  sed -e 's/^[^:]*: / /' \
229a6d9b409Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
230b91640d3Smrg## This next piece of magic avoids the "deleted header file" problem.
231a6d9b409Smrg## The problem is that when a header file which appears in a .P file
232a6d9b409Smrg## is deleted, the dependency causes make to die (because there is
233a6d9b409Smrg## typically no way to rebuild the header).  We avoid this by adding
234a6d9b409Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
235a6d9b409Smrg## this for us directly.
236b91640d3Smrg## Some versions of gcc put a space before the ':'.  On the theory
237a6d9b409Smrg## that the space means something, we add a space to the output as
238a097bd00Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
239a097bd00Smrg## to the object.  Take care to not repeat it in the output.
240a6d9b409Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
241a6d9b409Smrg## correctly.  Breaking it into two sed invocations is a workaround.
242b91640d3Smrg  tr ' ' "$nl" < "$tmpdepfile" \
243b91640d3Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
244b91640d3Smrg    | sed -e 's/$/ :/' >> "$depfile"
245a6d9b409Smrg  rm -f "$tmpdepfile"
246a6d9b409Smrg  ;;
247a6d9b409Smrg
248a6d9b409Smrghp)
249a6d9b409Smrg  # This case exists only to let depend.m4 do its work.  It works by
250a6d9b409Smrg  # looking at the text of this script.  This case will never be run,
251a6d9b409Smrg  # since it is checked for above.
252a6d9b409Smrg  exit 1
253a6d9b409Smrg  ;;
254a6d9b409Smrg
255a6d9b409Smrgsgi)
256a6d9b409Smrg  if test "$libtool" = yes; then
257a6d9b409Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
258a6d9b409Smrg  else
259a6d9b409Smrg    "$@" -MDupdate "$tmpdepfile"
260a6d9b409Smrg  fi
261a6d9b409Smrg  stat=$?
262b91640d3Smrg  if test $stat -ne 0; then
263a6d9b409Smrg    rm -f "$tmpdepfile"
264a6d9b409Smrg    exit $stat
265a6d9b409Smrg  fi
266a6d9b409Smrg  rm -f "$depfile"
267a6d9b409Smrg
268a6d9b409Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
269a6d9b409Smrg    echo "$object : \\" > "$depfile"
270a6d9b409Smrg    # Clip off the initial element (the dependent).  Don't try to be
271a6d9b409Smrg    # clever and replace this with sed code, as IRIX sed won't handle
272a6d9b409Smrg    # lines with more than a fixed number of characters (4096 in
273a6d9b409Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
274b91640d3Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
275a6d9b409Smrg    # dependency line.
276b91640d3Smrg    tr ' ' "$nl" < "$tmpdepfile" \
277b91640d3Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
278b91640d3Smrg      | tr "$nl" ' ' >> "$depfile"
279efda2da8Smrg    echo >> "$depfile"
280a6d9b409Smrg    # The second pass generates a dummy entry for each header file.
281b91640d3Smrg    tr ' ' "$nl" < "$tmpdepfile" \
282b91640d3Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
283b91640d3Smrg      >> "$depfile"
284a6d9b409Smrg  else
285b91640d3Smrg    make_dummy_depfile
286a6d9b409Smrg  fi
287a6d9b409Smrg  rm -f "$tmpdepfile"
288a6d9b409Smrg  ;;
289a6d9b409Smrg
290b91640d3Smrgxlc)
291b91640d3Smrg  # This case exists only to let depend.m4 do its work.  It works by
292b91640d3Smrg  # looking at the text of this script.  This case will never be run,
293b91640d3Smrg  # since it is checked for above.
294b91640d3Smrg  exit 1
295b91640d3Smrg  ;;
296b91640d3Smrg
297a6d9b409Smrgaix)
298a6d9b409Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
299a6d9b409Smrg  # in a .u file.  In older versions, this file always lives in the
300b91640d3Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
301a6d9b409Smrg  # start of each line; $object doesn't have directory information.
302a6d9b409Smrg  # Version 6 uses the directory in both cases.
303b91640d3Smrg  set_dir_from "$object"
304b91640d3Smrg  set_base_from "$object"
305a6d9b409Smrg  if test "$libtool" = yes; then
306efda2da8Smrg    tmpdepfile1=$dir$base.u
307efda2da8Smrg    tmpdepfile2=$base.u
308efda2da8Smrg    tmpdepfile3=$dir.libs/$base.u
309a6d9b409Smrg    "$@" -Wc,-M
310a6d9b409Smrg  else
311efda2da8Smrg    tmpdepfile1=$dir$base.u
312efda2da8Smrg    tmpdepfile2=$dir$base.u
313efda2da8Smrg    tmpdepfile3=$dir$base.u
314a6d9b409Smrg    "$@" -M
315a6d9b409Smrg  fi
316a6d9b409Smrg  stat=$?
317b91640d3Smrg  if test $stat -ne 0; then
318efda2da8Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
319a6d9b409Smrg    exit $stat
320a6d9b409Smrg  fi
321a6d9b409Smrg
322efda2da8Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
323efda2da8Smrg  do
324efda2da8Smrg    test -f "$tmpdepfile" && break
325efda2da8Smrg  done
326b91640d3Smrg  aix_post_process_depfile
327b91640d3Smrg  ;;
328b91640d3Smrg
329b91640d3Smrgtcc)
330b91640d3Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
331b91640d3Smrg  # FIXME: That version still under development at the moment of writing.
332b91640d3Smrg  #        Make that this statement remains true also for stable, released
333b91640d3Smrg  #        versions.
334b91640d3Smrg  # It will wrap lines (doesn't matter whether long or short) with a
335b91640d3Smrg  # trailing '\', as in:
336b91640d3Smrg  #
337b91640d3Smrg  #   foo.o : \
338b91640d3Smrg  #    foo.c \
339b91640d3Smrg  #    foo.h \
340b91640d3Smrg  #
341b91640d3Smrg  # It will put a trailing '\' even on the last line, and will use leading
342b91640d3Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
343b91640d3Smrg  # "Emit spaces for -MD").
344b91640d3Smrg  "$@" -MD -MF "$tmpdepfile"
345b91640d3Smrg  stat=$?
346b91640d3Smrg  if test $stat -ne 0; then
347b91640d3Smrg    rm -f "$tmpdepfile"
348b91640d3Smrg    exit $stat
349a6d9b409Smrg  fi
350b91640d3Smrg  rm -f "$depfile"
351b91640d3Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
352b91640d3Smrg  # We have to change lines of the first kind to '$object: \'.
353b91640d3Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
354b91640d3Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
355b91640d3Smrg  # dummy dependency, to avoid the deleted-header problem.
356b91640d3Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
357a6d9b409Smrg  rm -f "$tmpdepfile"
358a6d9b409Smrg  ;;
359a6d9b409Smrg
360b91640d3Smrg## The order of this option in the case statement is important, since the
361b91640d3Smrg## shell code in configure will try each of these formats in the order
362b91640d3Smrg## listed in this file.  A plain '-MD' option would be understood by many
363b91640d3Smrg## compilers, so we must ensure this comes after the gcc and icc options.
364b91640d3Smrgpgcc)
365b91640d3Smrg  # Portland's C compiler understands '-MD'.
366b91640d3Smrg  # Will always output deps to 'file.d' where file is the root name of the
367b91640d3Smrg  # source file under compilation, even if file resides in a subdirectory.
368b91640d3Smrg  # The object file name does not affect the name of the '.d' file.
369b91640d3Smrg  # pgcc 10.2 will output
370a6d9b409Smrg  #    foo.o: sub/foo.c sub/foo.h
371b91640d3Smrg  # and will wrap long lines using '\' :
372a6d9b409Smrg  #    foo.o: sub/foo.c ... \
373a6d9b409Smrg  #     sub/foo.h ... \
374a6d9b409Smrg  #     ...
375b91640d3Smrg  set_dir_from "$object"
376b91640d3Smrg  # Use the source, not the object, to determine the base name, since
377b91640d3Smrg  # that's sadly what pgcc will do too.
378b91640d3Smrg  set_base_from "$source"
379b91640d3Smrg  tmpdepfile=$base.d
380b91640d3Smrg
381b91640d3Smrg  # For projects that build the same source file twice into different object
382b91640d3Smrg  # files, the pgcc approach of using the *source* file root name can cause
383b91640d3Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
384b91640d3Smrg  # the same $tmpdepfile.
385b91640d3Smrg  lockdir=$base.d-lock
386b91640d3Smrg  trap "
387b91640d3Smrg    echo '$0: caught signal, cleaning up...' >&2
388b91640d3Smrg    rmdir '$lockdir'
389b91640d3Smrg    exit 1
390b91640d3Smrg  " 1 2 13 15
391b91640d3Smrg  numtries=100
392b91640d3Smrg  i=$numtries
393b91640d3Smrg  while test $i -gt 0; do
394b91640d3Smrg    # mkdir is a portable test-and-set.
395b91640d3Smrg    if mkdir "$lockdir" 2>/dev/null; then
396b91640d3Smrg      # This process acquired the lock.
397b91640d3Smrg      "$@" -MD
398b91640d3Smrg      stat=$?
399b91640d3Smrg      # Release the lock.
400b91640d3Smrg      rmdir "$lockdir"
401b91640d3Smrg      break
402b91640d3Smrg    else
403b91640d3Smrg      # If the lock is being held by a different process, wait
404b91640d3Smrg      # until the winning process is done or we timeout.
405b91640d3Smrg      while test -d "$lockdir" && test $i -gt 0; do
406b91640d3Smrg        sleep 1
407b91640d3Smrg        i=`expr $i - 1`
408b91640d3Smrg      done
409b91640d3Smrg    fi
410b91640d3Smrg    i=`expr $i - 1`
411b91640d3Smrg  done
412b91640d3Smrg  trap - 1 2 13 15
413b91640d3Smrg  if test $i -le 0; then
414b91640d3Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
415b91640d3Smrg    echo "$0: check lockdir '$lockdir'" >&2
416b91640d3Smrg    exit 1
417b91640d3Smrg  fi
418a6d9b409Smrg
419b91640d3Smrg  if test $stat -ne 0; then
420a6d9b409Smrg    rm -f "$tmpdepfile"
421a6d9b409Smrg    exit $stat
422a6d9b409Smrg  fi
423a6d9b409Smrg  rm -f "$depfile"
424a6d9b409Smrg  # Each line is of the form `foo.o: dependent.h',
425a6d9b409Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
426a6d9b409Smrg  # Do two passes, one to just change these to
427a6d9b409Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
428a6d9b409Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
429a6d9b409Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
430a6d9b409Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
431b91640d3Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
432b91640d3Smrg    | sed -e 's/$/ :/' >> "$depfile"
433a6d9b409Smrg  rm -f "$tmpdepfile"
434a6d9b409Smrg  ;;
435a6d9b409Smrg
436cae39615Smrghp2)
437cae39615Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
438cae39615Smrg  # compilers, which have integrated preprocessors.  The correct option
439cae39615Smrg  # to use with these is +Maked; it writes dependencies to a file named
440cae39615Smrg  # 'foo.d', which lands next to the object file, wherever that
441cae39615Smrg  # happens to be.
442cae39615Smrg  # Much of this is similar to the tru64 case; see comments there.
443b91640d3Smrg  set_dir_from  "$object"
444b91640d3Smrg  set_base_from "$object"
445cae39615Smrg  if test "$libtool" = yes; then
446cae39615Smrg    tmpdepfile1=$dir$base.d
447cae39615Smrg    tmpdepfile2=$dir.libs/$base.d
448cae39615Smrg    "$@" -Wc,+Maked
449cae39615Smrg  else
450cae39615Smrg    tmpdepfile1=$dir$base.d
451cae39615Smrg    tmpdepfile2=$dir$base.d
452cae39615Smrg    "$@" +Maked
453cae39615Smrg  fi
454cae39615Smrg  stat=$?
455b91640d3Smrg  if test $stat -ne 0; then
456cae39615Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
457cae39615Smrg     exit $stat
458cae39615Smrg  fi
459cae39615Smrg
460cae39615Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
461cae39615Smrg  do
462cae39615Smrg    test -f "$tmpdepfile" && break
463cae39615Smrg  done
464cae39615Smrg  if test -f "$tmpdepfile"; then
465b91640d3Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
466b91640d3Smrg    # Add 'dependent.h:' lines.
467efda2da8Smrg    sed -ne '2,${
468b91640d3Smrg               s/^ *//
469b91640d3Smrg               s/ \\*$//
470b91640d3Smrg               s/$/:/
471b91640d3Smrg               p
472b91640d3Smrg             }' "$tmpdepfile" >> "$depfile"
473cae39615Smrg  else
474b91640d3Smrg    make_dummy_depfile
475cae39615Smrg  fi
476cae39615Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
477cae39615Smrg  ;;
478cae39615Smrg
479a6d9b409Smrgtru64)
480b91640d3Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
481b91640d3Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
482b91640d3Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
483b91640d3Smrg  # dependencies in 'foo.d' instead, so we check for that too.
484b91640d3Smrg  # Subdirectories are respected.
485b91640d3Smrg  set_dir_from  "$object"
486b91640d3Smrg  set_base_from "$object"
487b91640d3Smrg
488b91640d3Smrg  if test "$libtool" = yes; then
489b91640d3Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
490b91640d3Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
491b91640d3Smrg    # in $dir$base.o.d.  We have to check for both files, because
492b91640d3Smrg    # one of the two compilations can be disabled.  We should prefer
493b91640d3Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
494b91640d3Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
495b91640d3Smrg    # the former would cause a distcleancheck panic.
496b91640d3Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
497b91640d3Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
498b91640d3Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
499b91640d3Smrg    "$@" -Wc,-MD
500b91640d3Smrg  else
501b91640d3Smrg    tmpdepfile1=$dir$base.d
502b91640d3Smrg    tmpdepfile2=$dir$base.d
503b91640d3Smrg    tmpdepfile3=$dir$base.d
504b91640d3Smrg    "$@" -MD
505b91640d3Smrg  fi
506b91640d3Smrg
507b91640d3Smrg  stat=$?
508b91640d3Smrg  if test $stat -ne 0; then
509b91640d3Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
510b91640d3Smrg    exit $stat
511b91640d3Smrg  fi
512b91640d3Smrg
513b91640d3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
514b91640d3Smrg  do
515b91640d3Smrg    test -f "$tmpdepfile" && break
516b91640d3Smrg  done
517b91640d3Smrg  # Same post-processing that is required for AIX mode.
518b91640d3Smrg  aix_post_process_depfile
519b91640d3Smrg  ;;
520a6d9b409Smrg
521a097bd00Smrgmsvc7)
522a097bd00Smrg  if test "$libtool" = yes; then
523a097bd00Smrg    showIncludes=-Wc,-showIncludes
524a097bd00Smrg  else
525a097bd00Smrg    showIncludes=-showIncludes
526a097bd00Smrg  fi
527a097bd00Smrg  "$@" $showIncludes > "$tmpdepfile"
528a097bd00Smrg  stat=$?
529a097bd00Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
530b91640d3Smrg  if test $stat -ne 0; then
531a097bd00Smrg    rm -f "$tmpdepfile"
532a097bd00Smrg    exit $stat
533a097bd00Smrg  fi
534a097bd00Smrg  rm -f "$depfile"
535a097bd00Smrg  echo "$object : \\" > "$depfile"
536a097bd00Smrg  # The first sed program below extracts the file names and escapes
537a097bd00Smrg  # backslashes for cygpath.  The second sed program outputs the file
538a097bd00Smrg  # name when reading, but also accumulates all include files in the
539a097bd00Smrg  # hold buffer in order to output them again at the end.  This only
540a097bd00Smrg  # works with sed implementations that can handle large buffers.
541a097bd00Smrg  sed < "$tmpdepfile" -n '
542a097bd00Smrg/^Note: including file:  *\(.*\)/ {
543a097bd00Smrg  s//\1/
544a097bd00Smrg  s/\\/\\\\/g
545a097bd00Smrg  p
546a097bd00Smrg}' | $cygpath_u | sort -u | sed -n '
547a097bd00Smrgs/ /\\ /g
548b91640d3Smrgs/\(.*\)/'"$tab"'\1 \\/p
549a097bd00Smrgs/.\(.*\) \\/\1:/
550a097bd00SmrgH
551a097bd00Smrg$ {
552b91640d3Smrg  s/.*/'"$tab"'/
553a097bd00Smrg  G
554a097bd00Smrg  p
555a097bd00Smrg}' >> "$depfile"
556b91640d3Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
557a097bd00Smrg  rm -f "$tmpdepfile"
558a097bd00Smrg  ;;
559a097bd00Smrg
560a097bd00Smrgmsvc7msys)
561a097bd00Smrg  # This case exists only to let depend.m4 do its work.  It works by
562a097bd00Smrg  # looking at the text of this script.  This case will never be run,
563a097bd00Smrg  # since it is checked for above.
564a097bd00Smrg  exit 1
565a097bd00Smrg  ;;
566a097bd00Smrg
567a6d9b409Smrg#nosideeffect)
568a6d9b409Smrg  # This comment above is used by automake to tell side-effect
569a6d9b409Smrg  # dependency tracking mechanisms from slower ones.
570a6d9b409Smrg
571a6d9b409Smrgdashmstdout)
572a6d9b409Smrg  # Important note: in order to support this mode, a compiler *must*
573a6d9b409Smrg  # always write the preprocessed file to stdout, regardless of -o.
574a6d9b409Smrg  "$@" || exit $?
575a6d9b409Smrg
576a6d9b409Smrg  # Remove the call to Libtool.
577a6d9b409Smrg  if test "$libtool" = yes; then
578efda2da8Smrg    while test "X$1" != 'X--mode=compile'; do
579a6d9b409Smrg      shift
580a6d9b409Smrg    done
581a6d9b409Smrg    shift
582a6d9b409Smrg  fi
583a6d9b409Smrg
584b91640d3Smrg  # Remove '-o $object'.
585a6d9b409Smrg  IFS=" "
586a6d9b409Smrg  for arg
587a6d9b409Smrg  do
588a6d9b409Smrg    case $arg in
589a6d9b409Smrg    -o)
590a6d9b409Smrg      shift
591a6d9b409Smrg      ;;
592a6d9b409Smrg    $object)
593a6d9b409Smrg      shift
594a6d9b409Smrg      ;;
595a6d9b409Smrg    *)
596a6d9b409Smrg      set fnord "$@" "$arg"
597a6d9b409Smrg      shift # fnord
598a6d9b409Smrg      shift # $arg
599a6d9b409Smrg      ;;
600a6d9b409Smrg    esac
601a6d9b409Smrg  done
602a6d9b409Smrg
603a6d9b409Smrg  test -z "$dashmflag" && dashmflag=-M
604b91640d3Smrg  # Require at least two characters before searching for ':'
605a6d9b409Smrg  # in the target name.  This is to cope with DOS-style filenames:
606b91640d3Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
607a6d9b409Smrg  "$@" $dashmflag |
608b91640d3Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
609a6d9b409Smrg  rm -f "$depfile"
610a6d9b409Smrg  cat < "$tmpdepfile" > "$depfile"
611b91640d3Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
612b91640d3Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
613b91640d3Smrg  tr ' ' "$nl" < "$tmpdepfile" \
614b91640d3Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
615b91640d3Smrg    | sed -e 's/$/ :/' >> "$depfile"
616a6d9b409Smrg  rm -f "$tmpdepfile"
617a6d9b409Smrg  ;;
618a6d9b409Smrg
619a6d9b409SmrgdashXmstdout)
620a6d9b409Smrg  # This case only exists to satisfy depend.m4.  It is never actually
621a6d9b409Smrg  # run, as this mode is specially recognized in the preamble.
622a6d9b409Smrg  exit 1
623a6d9b409Smrg  ;;
624a6d9b409Smrg
625a6d9b409Smrgmakedepend)
626a6d9b409Smrg  "$@" || exit $?
627a6d9b409Smrg  # Remove any Libtool call
628a6d9b409Smrg  if test "$libtool" = yes; then
629efda2da8Smrg    while test "X$1" != 'X--mode=compile'; do
630a6d9b409Smrg      shift
631a6d9b409Smrg    done
632a6d9b409Smrg    shift
633a6d9b409Smrg  fi
634a6d9b409Smrg  # X makedepend
635a6d9b409Smrg  shift
636efda2da8Smrg  cleared=no eat=no
637efda2da8Smrg  for arg
638efda2da8Smrg  do
639a6d9b409Smrg    case $cleared in
640a6d9b409Smrg    no)
641a6d9b409Smrg      set ""; shift
642a6d9b409Smrg      cleared=yes ;;
643a6d9b409Smrg    esac
644efda2da8Smrg    if test $eat = yes; then
645efda2da8Smrg      eat=no
646efda2da8Smrg      continue
647efda2da8Smrg    fi
648a6d9b409Smrg    case "$arg" in
649a6d9b409Smrg    -D*|-I*)
650a6d9b409Smrg      set fnord "$@" "$arg"; shift ;;
651a6d9b409Smrg    # Strip any option that makedepend may not understand.  Remove
652a6d9b409Smrg    # the object too, otherwise makedepend will parse it as a source file.
653efda2da8Smrg    -arch)
654efda2da8Smrg      eat=yes ;;
655a6d9b409Smrg    -*|$object)
656a6d9b409Smrg      ;;
657a6d9b409Smrg    *)
658a6d9b409Smrg      set fnord "$@" "$arg"; shift ;;
659a6d9b409Smrg    esac
660a6d9b409Smrg  done
661efda2da8Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
662a6d9b409Smrg  touch "$tmpdepfile"
663a6d9b409Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
664a6d9b409Smrg  rm -f "$depfile"
665a097bd00Smrg  # makedepend may prepend the VPATH from the source file name to the object.
666a097bd00Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
667a097bd00Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
668b91640d3Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
669b91640d3Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
670b91640d3Smrg  sed '1,2d' "$tmpdepfile" \
671b91640d3Smrg    | tr ' ' "$nl" \
672b91640d3Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
673b91640d3Smrg    | sed -e 's/$/ :/' >> "$depfile"
674a6d9b409Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
675a6d9b409Smrg  ;;
676a6d9b409Smrg
677a6d9b409Smrgcpp)
678a6d9b409Smrg  # Important note: in order to support this mode, a compiler *must*
679a6d9b409Smrg  # always write the preprocessed file to stdout.
680a6d9b409Smrg  "$@" || exit $?
681a6d9b409Smrg
682a6d9b409Smrg  # Remove the call to Libtool.
683a6d9b409Smrg  if test "$libtool" = yes; then
684efda2da8Smrg    while test "X$1" != 'X--mode=compile'; do
685a6d9b409Smrg      shift
686a6d9b409Smrg    done
687a6d9b409Smrg    shift
688a6d9b409Smrg  fi
689a6d9b409Smrg
690b91640d3Smrg  # Remove '-o $object'.
691a6d9b409Smrg  IFS=" "
692a6d9b409Smrg  for arg
693a6d9b409Smrg  do
694a6d9b409Smrg    case $arg in
695a6d9b409Smrg    -o)
696a6d9b409Smrg      shift
697a6d9b409Smrg      ;;
698a6d9b409Smrg    $object)
699a6d9b409Smrg      shift
700a6d9b409Smrg      ;;
701a6d9b409Smrg    *)
702a6d9b409Smrg      set fnord "$@" "$arg"
703a6d9b409Smrg      shift # fnord
704a6d9b409Smrg      shift # $arg
705a6d9b409Smrg      ;;
706a6d9b409Smrg    esac
707a6d9b409Smrg  done
708a6d9b409Smrg
709b91640d3Smrg  "$@" -E \
710b91640d3Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711b91640d3Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
712b91640d3Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
713a6d9b409Smrg  rm -f "$depfile"
714a6d9b409Smrg  echo "$object : \\" > "$depfile"
715a6d9b409Smrg  cat < "$tmpdepfile" >> "$depfile"
716a6d9b409Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
717a6d9b409Smrg  rm -f "$tmpdepfile"
718a6d9b409Smrg  ;;
719a6d9b409Smrg
720a6d9b409Smrgmsvisualcpp)
721a6d9b409Smrg  # Important note: in order to support this mode, a compiler *must*
722efda2da8Smrg  # always write the preprocessed file to stdout.
723a6d9b409Smrg  "$@" || exit $?
724efda2da8Smrg
725efda2da8Smrg  # Remove the call to Libtool.
726efda2da8Smrg  if test "$libtool" = yes; then
727efda2da8Smrg    while test "X$1" != 'X--mode=compile'; do
728efda2da8Smrg      shift
729efda2da8Smrg    done
730efda2da8Smrg    shift
731efda2da8Smrg  fi
732efda2da8Smrg
733a6d9b409Smrg  IFS=" "
734a6d9b409Smrg  for arg
735a6d9b409Smrg  do
736a6d9b409Smrg    case "$arg" in
737efda2da8Smrg    -o)
738efda2da8Smrg      shift
739efda2da8Smrg      ;;
740efda2da8Smrg    $object)
741efda2da8Smrg      shift
742efda2da8Smrg      ;;
743a6d9b409Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
744b91640d3Smrg        set fnord "$@"
745b91640d3Smrg        shift
746b91640d3Smrg        shift
747b91640d3Smrg        ;;
748a6d9b409Smrg    *)
749b91640d3Smrg        set fnord "$@" "$arg"
750b91640d3Smrg        shift
751b91640d3Smrg        shift
752b91640d3Smrg        ;;
753a6d9b409Smrg    esac
754a6d9b409Smrg  done
755efda2da8Smrg  "$@" -E 2>/dev/null |
756efda2da8Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
757a6d9b409Smrg  rm -f "$depfile"
758a6d9b409Smrg  echo "$object : \\" > "$depfile"
759b91640d3Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
760b91640d3Smrg  echo "$tab" >> "$depfile"
761efda2da8Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
762a6d9b409Smrg  rm -f "$tmpdepfile"
763a6d9b409Smrg  ;;
764a6d9b409Smrg
765efda2da8Smrgmsvcmsys)
766efda2da8Smrg  # This case exists only to let depend.m4 do its work.  It works by
767efda2da8Smrg  # looking at the text of this script.  This case will never be run,
768efda2da8Smrg  # since it is checked for above.
769efda2da8Smrg  exit 1
770efda2da8Smrg  ;;
771efda2da8Smrg
772a6d9b409Smrgnone)
773a6d9b409Smrg  exec "$@"
774a6d9b409Smrg  ;;
775a6d9b409Smrg
776a6d9b409Smrg*)
777a6d9b409Smrg  echo "Unknown depmode $depmode" 1>&2
778a6d9b409Smrg  exit 1
779a6d9b409Smrg  ;;
780a6d9b409Smrgesac
781a6d9b409Smrg
782a6d9b409Smrgexit 0
783a6d9b409Smrg
784a6d9b409Smrg# Local Variables:
785a6d9b409Smrg# mode: shell-script
786a6d9b409Smrg# sh-indentation: 2
78792e95ad1Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
788a6d9b409Smrg# time-stamp-start: "scriptversion="
789a6d9b409Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
79092e95ad1Smrg# time-stamp-time-zone: "UTC0"
791efda2da8Smrg# time-stamp-end: "; # UTC"
792a6d9b409Smrg# End:
793