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