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