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