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