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