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