depcomp revision 966b534a
1a0d3b6eaSmrg#! /bin/sh
2a0d3b6eaSmrg# depcomp - compile a program generating dependencies as side-effects
3a0d3b6eaSmrg
4966b534aSmrgscriptversion=2011-12-04.11; # UTC
5a0d3b6eaSmrg
6966b534aSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
7966b534aSmrg# 2011 Free Software Foundation, Inc.
8a0d3b6eaSmrg
9a0d3b6eaSmrg# This program is free software; you can redistribute it and/or modify
10a0d3b6eaSmrg# it under the terms of the GNU General Public License as published by
11a0d3b6eaSmrg# the Free Software Foundation; either version 2, or (at your option)
12a0d3b6eaSmrg# any later version.
13a0d3b6eaSmrg
14a0d3b6eaSmrg# This program is distributed in the hope that it will be useful,
15a0d3b6eaSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16a0d3b6eaSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a0d3b6eaSmrg# GNU General Public License for more details.
18a0d3b6eaSmrg
19a0d3b6eaSmrg# You should have received a copy of the GNU General Public License
20f8a31ee4Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21a0d3b6eaSmrg
22a0d3b6eaSmrg# As a special exception to the GNU General Public License, if you
23a0d3b6eaSmrg# distribute this file as part of a program that contains a
24a0d3b6eaSmrg# configuration script generated by Autoconf, you may include it under
25a0d3b6eaSmrg# the same distribution terms that you use for the rest of that program.
26a0d3b6eaSmrg
27a0d3b6eaSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28a0d3b6eaSmrg
29a0d3b6eaSmrgcase $1 in
30a0d3b6eaSmrg  '')
31a0d3b6eaSmrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
32a0d3b6eaSmrg     exit 1;
33a0d3b6eaSmrg     ;;
34a0d3b6eaSmrg  -h | --h*)
35a0d3b6eaSmrg    cat <<\EOF
36a0d3b6eaSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
37a0d3b6eaSmrg
38a0d3b6eaSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
39a0d3b6eaSmrgas side-effects.
40a0d3b6eaSmrg
41a0d3b6eaSmrgEnvironment variables:
42a0d3b6eaSmrg  depmode     Dependency tracking mode.
43a0d3b6eaSmrg  source      Source file read by `PROGRAMS ARGS'.
44a0d3b6eaSmrg  object      Object file output by `PROGRAMS ARGS'.
45a0d3b6eaSmrg  DEPDIR      directory where to store dependencies.
46a0d3b6eaSmrg  depfile     Dependency file to output.
47966b534aSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
48a0d3b6eaSmrg  libtool     Whether libtool is used (yes/no).
49a0d3b6eaSmrg
50a0d3b6eaSmrgReport bugs to <bug-automake@gnu.org>.
51a0d3b6eaSmrgEOF
52a0d3b6eaSmrg    exit $?
53a0d3b6eaSmrg    ;;
54a0d3b6eaSmrg  -v | --v*)
55a0d3b6eaSmrg    echo "depcomp $scriptversion"
56a0d3b6eaSmrg    exit $?
57a0d3b6eaSmrg    ;;
58a0d3b6eaSmrgesac
59a0d3b6eaSmrg
60a0d3b6eaSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
61a0d3b6eaSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
62a0d3b6eaSmrg  exit 1
63a0d3b6eaSmrgfi
64a0d3b6eaSmrg
65a0d3b6eaSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
66a0d3b6eaSmrgdepfile=${depfile-`echo "$object" |
67a0d3b6eaSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
68a0d3b6eaSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
69a0d3b6eaSmrg
70a0d3b6eaSmrgrm -f "$tmpdepfile"
71a0d3b6eaSmrg
72a0d3b6eaSmrg# Some modes work just like other modes, but use different flags.  We
73a0d3b6eaSmrg# parameterize here, but still list the modes in the big case below,
74a0d3b6eaSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
75a0d3b6eaSmrg# here, because this file can only contain one case statement.
76a0d3b6eaSmrgif test "$depmode" = hp; then
77a0d3b6eaSmrg  # HP compiler uses -M and no extra arg.
78a0d3b6eaSmrg  gccflag=-M
79a0d3b6eaSmrg  depmode=gcc
80a0d3b6eaSmrgfi
81a0d3b6eaSmrg
82a0d3b6eaSmrgif test "$depmode" = dashXmstdout; then
83a0d3b6eaSmrg   # This is just like dashmstdout with a different argument.
84a0d3b6eaSmrg   dashmflag=-xM
85a0d3b6eaSmrg   depmode=dashmstdout
86a0d3b6eaSmrgfi
87a0d3b6eaSmrg
88f8a31ee4Smrgcygpath_u="cygpath -u -f -"
89f8a31ee4Smrgif test "$depmode" = msvcmsys; then
90f8a31ee4Smrg   # This is just like msvisualcpp but w/o cygpath translation.
91f8a31ee4Smrg   # Just convert the backslash-escaped backslashes to single forward
92f8a31ee4Smrg   # slashes to satisfy depend.m4
93966b534aSmrg   cygpath_u='sed s,\\\\,/,g'
94f8a31ee4Smrg   depmode=msvisualcpp
95f8a31ee4Smrgfi
96f8a31ee4Smrg
97966b534aSmrgif test "$depmode" = msvc7msys; then
98966b534aSmrg   # This is just like msvc7 but w/o cygpath translation.
99966b534aSmrg   # Just convert the backslash-escaped backslashes to single forward
100966b534aSmrg   # slashes to satisfy depend.m4
101966b534aSmrg   cygpath_u='sed s,\\\\,/,g'
102966b534aSmrg   depmode=msvc7
103966b534aSmrgfi
104966b534aSmrg
105a0d3b6eaSmrgcase "$depmode" in
106a0d3b6eaSmrggcc3)
107a0d3b6eaSmrg## gcc 3 implements dependency tracking that does exactly what
108a0d3b6eaSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
109a0d3b6eaSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
110a0d3b6eaSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
111a0d3b6eaSmrg## the command line argument order; so add the flags where they
112a0d3b6eaSmrg## appear in depend2.am.  Note that the slowdown incurred here
113a0d3b6eaSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
114a0d3b6eaSmrg  for arg
115a0d3b6eaSmrg  do
116a0d3b6eaSmrg    case $arg in
117a0d3b6eaSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
118a0d3b6eaSmrg    *)  set fnord "$@" "$arg" ;;
119a0d3b6eaSmrg    esac
120a0d3b6eaSmrg    shift # fnord
121a0d3b6eaSmrg    shift # $arg
122a0d3b6eaSmrg  done
123a0d3b6eaSmrg  "$@"
124a0d3b6eaSmrg  stat=$?
125a0d3b6eaSmrg  if test $stat -eq 0; then :
126a0d3b6eaSmrg  else
127a0d3b6eaSmrg    rm -f "$tmpdepfile"
128a0d3b6eaSmrg    exit $stat
129a0d3b6eaSmrg  fi
130a0d3b6eaSmrg  mv "$tmpdepfile" "$depfile"
131a0d3b6eaSmrg  ;;
132a0d3b6eaSmrg
133a0d3b6eaSmrggcc)
134a0d3b6eaSmrg## There are various ways to get dependency output from gcc.  Here's
135a0d3b6eaSmrg## why we pick this rather obscure method:
136a0d3b6eaSmrg## - Don't want to use -MD because we'd like the dependencies to end
137a0d3b6eaSmrg##   up in a subdir.  Having to rename by hand is ugly.
138a0d3b6eaSmrg##   (We might end up doing this anyway to support other compilers.)
139a0d3b6eaSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
140a0d3b6eaSmrg##   -MM, not -M (despite what the docs say).
141a0d3b6eaSmrg## - Using -M directly means running the compiler twice (even worse
142a0d3b6eaSmrg##   than renaming).
143a0d3b6eaSmrg  if test -z "$gccflag"; then
144a0d3b6eaSmrg    gccflag=-MD,
145a0d3b6eaSmrg  fi
146a0d3b6eaSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
147a0d3b6eaSmrg  stat=$?
148a0d3b6eaSmrg  if test $stat -eq 0; then :
149a0d3b6eaSmrg  else
150a0d3b6eaSmrg    rm -f "$tmpdepfile"
151a0d3b6eaSmrg    exit $stat
152a0d3b6eaSmrg  fi
153a0d3b6eaSmrg  rm -f "$depfile"
154a0d3b6eaSmrg  echo "$object : \\" > "$depfile"
155a0d3b6eaSmrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
156a0d3b6eaSmrg## The second -e expression handles DOS-style file names with drive letters.
157a0d3b6eaSmrg  sed -e 's/^[^:]*: / /' \
158a0d3b6eaSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
159a0d3b6eaSmrg## This next piece of magic avoids the `deleted header file' problem.
160a0d3b6eaSmrg## The problem is that when a header file which appears in a .P file
161a0d3b6eaSmrg## is deleted, the dependency causes make to die (because there is
162a0d3b6eaSmrg## typically no way to rebuild the header).  We avoid this by adding
163a0d3b6eaSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
164a0d3b6eaSmrg## this for us directly.
165a0d3b6eaSmrg  tr ' ' '
166a0d3b6eaSmrg' < "$tmpdepfile" |
167a0d3b6eaSmrg## Some versions of gcc put a space before the `:'.  On the theory
168a0d3b6eaSmrg## that the space means something, we add a space to the output as
169966b534aSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
170966b534aSmrg## to the object.  Take care to not repeat it in the output.
171a0d3b6eaSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
172a0d3b6eaSmrg## correctly.  Breaking it into two sed invocations is a workaround.
173966b534aSmrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
174966b534aSmrg      | sed -e 's/$/ :/' >> "$depfile"
175a0d3b6eaSmrg  rm -f "$tmpdepfile"
176a0d3b6eaSmrg  ;;
177a0d3b6eaSmrg
178a0d3b6eaSmrghp)
179a0d3b6eaSmrg  # This case exists only to let depend.m4 do its work.  It works by
180a0d3b6eaSmrg  # looking at the text of this script.  This case will never be run,
181a0d3b6eaSmrg  # since it is checked for above.
182a0d3b6eaSmrg  exit 1
183a0d3b6eaSmrg  ;;
184a0d3b6eaSmrg
185a0d3b6eaSmrgsgi)
186a0d3b6eaSmrg  if test "$libtool" = yes; then
187a0d3b6eaSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
188a0d3b6eaSmrg  else
189a0d3b6eaSmrg    "$@" -MDupdate "$tmpdepfile"
190a0d3b6eaSmrg  fi
191a0d3b6eaSmrg  stat=$?
192a0d3b6eaSmrg  if test $stat -eq 0; then :
193a0d3b6eaSmrg  else
194a0d3b6eaSmrg    rm -f "$tmpdepfile"
195a0d3b6eaSmrg    exit $stat
196a0d3b6eaSmrg  fi
197a0d3b6eaSmrg  rm -f "$depfile"
198a0d3b6eaSmrg
199a0d3b6eaSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
200a0d3b6eaSmrg    echo "$object : \\" > "$depfile"
201a0d3b6eaSmrg
202a0d3b6eaSmrg    # Clip off the initial element (the dependent).  Don't try to be
203a0d3b6eaSmrg    # clever and replace this with sed code, as IRIX sed won't handle
204a0d3b6eaSmrg    # lines with more than a fixed number of characters (4096 in
205a0d3b6eaSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
206a0d3b6eaSmrg    # the IRIX cc adds comments like `#:fec' to the end of the
207a0d3b6eaSmrg    # dependency line.
208a0d3b6eaSmrg    tr ' ' '
209a0d3b6eaSmrg' < "$tmpdepfile" \
210a0d3b6eaSmrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
211a0d3b6eaSmrg    tr '
212f8a31ee4Smrg' ' ' >> "$depfile"
213f8a31ee4Smrg    echo >> "$depfile"
214a0d3b6eaSmrg
215a0d3b6eaSmrg    # The second pass generates a dummy entry for each header file.
216a0d3b6eaSmrg    tr ' ' '
217a0d3b6eaSmrg' < "$tmpdepfile" \
218a0d3b6eaSmrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
219f8a31ee4Smrg   >> "$depfile"
220a0d3b6eaSmrg  else
221a0d3b6eaSmrg    # The sourcefile does not contain any dependencies, so just
222a0d3b6eaSmrg    # store a dummy comment line, to avoid errors with the Makefile
223a0d3b6eaSmrg    # "include basename.Plo" scheme.
224a0d3b6eaSmrg    echo "#dummy" > "$depfile"
225a0d3b6eaSmrg  fi
226a0d3b6eaSmrg  rm -f "$tmpdepfile"
227a0d3b6eaSmrg  ;;
228a0d3b6eaSmrg
229a0d3b6eaSmrgaix)
230a0d3b6eaSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
231a0d3b6eaSmrg  # in a .u file.  In older versions, this file always lives in the
232a0d3b6eaSmrg  # current directory.  Also, the AIX compiler puts `$object:' at the
233a0d3b6eaSmrg  # start of each line; $object doesn't have directory information.
234a0d3b6eaSmrg  # Version 6 uses the directory in both cases.
235f8a31ee4Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
236f8a31ee4Smrg  test "x$dir" = "x$object" && dir=
237f8a31ee4Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
238a0d3b6eaSmrg  if test "$libtool" = yes; then
239f8a31ee4Smrg    tmpdepfile1=$dir$base.u
240f8a31ee4Smrg    tmpdepfile2=$base.u
241f8a31ee4Smrg    tmpdepfile3=$dir.libs/$base.u
242a0d3b6eaSmrg    "$@" -Wc,-M
243a0d3b6eaSmrg  else
244f8a31ee4Smrg    tmpdepfile1=$dir$base.u
245f8a31ee4Smrg    tmpdepfile2=$dir$base.u
246f8a31ee4Smrg    tmpdepfile3=$dir$base.u
247a0d3b6eaSmrg    "$@" -M
248a0d3b6eaSmrg  fi
249a0d3b6eaSmrg  stat=$?
250a0d3b6eaSmrg
251a0d3b6eaSmrg  if test $stat -eq 0; then :
252a0d3b6eaSmrg  else
253f8a31ee4Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
254a0d3b6eaSmrg    exit $stat
255a0d3b6eaSmrg  fi
256a0d3b6eaSmrg
257f8a31ee4Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
258f8a31ee4Smrg  do
259f8a31ee4Smrg    test -f "$tmpdepfile" && break
260f8a31ee4Smrg  done
261a0d3b6eaSmrg  if test -f "$tmpdepfile"; then
262a0d3b6eaSmrg    # Each line is of the form `foo.o: dependent.h'.
263a0d3b6eaSmrg    # Do two passes, one to just change these to
264a0d3b6eaSmrg    # `$object: dependent.h' and one to simply `dependent.h:'.
265f8a31ee4Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
266f8a31ee4Smrg    # That's a tab and a space in the [].
267f8a31ee4Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
268a0d3b6eaSmrg  else
269a0d3b6eaSmrg    # The sourcefile does not contain any dependencies, so just
270a0d3b6eaSmrg    # store a dummy comment line, to avoid errors with the Makefile
271a0d3b6eaSmrg    # "include basename.Plo" scheme.
272a0d3b6eaSmrg    echo "#dummy" > "$depfile"
273a0d3b6eaSmrg  fi
274a0d3b6eaSmrg  rm -f "$tmpdepfile"
275a0d3b6eaSmrg  ;;
276a0d3b6eaSmrg
277a0d3b6eaSmrgicc)
278a0d3b6eaSmrg  # Intel's C compiler understands `-MD -MF file'.  However on
279a0d3b6eaSmrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
280a0d3b6eaSmrg  # ICC 7.0 will fill foo.d with something like
281a0d3b6eaSmrg  #    foo.o: sub/foo.c
282a0d3b6eaSmrg  #    foo.o: sub/foo.h
283a0d3b6eaSmrg  # which is wrong.  We want:
284a0d3b6eaSmrg  #    sub/foo.o: sub/foo.c
285a0d3b6eaSmrg  #    sub/foo.o: sub/foo.h
286a0d3b6eaSmrg  #    sub/foo.c:
287a0d3b6eaSmrg  #    sub/foo.h:
288a0d3b6eaSmrg  # ICC 7.1 will output
289a0d3b6eaSmrg  #    foo.o: sub/foo.c sub/foo.h
290a0d3b6eaSmrg  # and will wrap long lines using \ :
291a0d3b6eaSmrg  #    foo.o: sub/foo.c ... \
292a0d3b6eaSmrg  #     sub/foo.h ... \
293a0d3b6eaSmrg  #     ...
294a0d3b6eaSmrg
295a0d3b6eaSmrg  "$@" -MD -MF "$tmpdepfile"
296a0d3b6eaSmrg  stat=$?
297a0d3b6eaSmrg  if test $stat -eq 0; then :
298a0d3b6eaSmrg  else
299a0d3b6eaSmrg    rm -f "$tmpdepfile"
300a0d3b6eaSmrg    exit $stat
301a0d3b6eaSmrg  fi
302a0d3b6eaSmrg  rm -f "$depfile"
303a0d3b6eaSmrg  # Each line is of the form `foo.o: dependent.h',
304a0d3b6eaSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
305a0d3b6eaSmrg  # Do two passes, one to just change these to
306a0d3b6eaSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
307a0d3b6eaSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
308a0d3b6eaSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
309a0d3b6eaSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
310a0d3b6eaSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
311a0d3b6eaSmrg    sed -e 's/$/ :/' >> "$depfile"
312a0d3b6eaSmrg  rm -f "$tmpdepfile"
313a0d3b6eaSmrg  ;;
314a0d3b6eaSmrg
315a0d3b6eaSmrghp2)
316a0d3b6eaSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
317a0d3b6eaSmrg  # compilers, which have integrated preprocessors.  The correct option
318a0d3b6eaSmrg  # to use with these is +Maked; it writes dependencies to a file named
319a0d3b6eaSmrg  # 'foo.d', which lands next to the object file, wherever that
320a0d3b6eaSmrg  # happens to be.
321a0d3b6eaSmrg  # Much of this is similar to the tru64 case; see comments there.
322a0d3b6eaSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
323a0d3b6eaSmrg  test "x$dir" = "x$object" && dir=
324a0d3b6eaSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
325a0d3b6eaSmrg  if test "$libtool" = yes; then
326a0d3b6eaSmrg    tmpdepfile1=$dir$base.d
327a0d3b6eaSmrg    tmpdepfile2=$dir.libs/$base.d
328a0d3b6eaSmrg    "$@" -Wc,+Maked
329a0d3b6eaSmrg  else
330a0d3b6eaSmrg    tmpdepfile1=$dir$base.d
331a0d3b6eaSmrg    tmpdepfile2=$dir$base.d
332a0d3b6eaSmrg    "$@" +Maked
333a0d3b6eaSmrg  fi
334a0d3b6eaSmrg  stat=$?
335a0d3b6eaSmrg  if test $stat -eq 0; then :
336a0d3b6eaSmrg  else
337a0d3b6eaSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
338a0d3b6eaSmrg     exit $stat
339a0d3b6eaSmrg  fi
340a0d3b6eaSmrg
341a0d3b6eaSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
342a0d3b6eaSmrg  do
343a0d3b6eaSmrg    test -f "$tmpdepfile" && break
344a0d3b6eaSmrg  done
345a0d3b6eaSmrg  if test -f "$tmpdepfile"; then
346a0d3b6eaSmrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
347a0d3b6eaSmrg    # Add `dependent.h:' lines.
348f8a31ee4Smrg    sed -ne '2,${
349f8a31ee4Smrg	       s/^ *//
350f8a31ee4Smrg	       s/ \\*$//
351f8a31ee4Smrg	       s/$/:/
352f8a31ee4Smrg	       p
353f8a31ee4Smrg	     }' "$tmpdepfile" >> "$depfile"
354a0d3b6eaSmrg  else
355a0d3b6eaSmrg    echo "#dummy" > "$depfile"
356a0d3b6eaSmrg  fi
357a0d3b6eaSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
358a0d3b6eaSmrg  ;;
359a0d3b6eaSmrg
360a0d3b6eaSmrgtru64)
361a0d3b6eaSmrg   # The Tru64 compiler uses -MD to generate dependencies as a side
362a0d3b6eaSmrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
363a0d3b6eaSmrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
364a0d3b6eaSmrg   # dependencies in `foo.d' instead, so we check for that too.
365a0d3b6eaSmrg   # Subdirectories are respected.
366a0d3b6eaSmrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
367a0d3b6eaSmrg   test "x$dir" = "x$object" && dir=
368a0d3b6eaSmrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
369a0d3b6eaSmrg
370a0d3b6eaSmrg   if test "$libtool" = yes; then
371a0d3b6eaSmrg      # With Tru64 cc, shared objects can also be used to make a
372a0d3b6eaSmrg      # static library.  This mechanism is used in libtool 1.4 series to
373a0d3b6eaSmrg      # handle both shared and static libraries in a single compilation.
374a0d3b6eaSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
375a0d3b6eaSmrg      #
376a0d3b6eaSmrg      # With libtool 1.5 this exception was removed, and libtool now
377a0d3b6eaSmrg      # generates 2 separate objects for the 2 libraries.  These two
378a0d3b6eaSmrg      # compilations output dependencies in $dir.libs/$base.o.d and
379a0d3b6eaSmrg      # in $dir$base.o.d.  We have to check for both files, because
380a0d3b6eaSmrg      # one of the two compilations can be disabled.  We should prefer
381a0d3b6eaSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
382a0d3b6eaSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
383a0d3b6eaSmrg      # the former would cause a distcleancheck panic.
384a0d3b6eaSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
385a0d3b6eaSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
386a0d3b6eaSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
387a0d3b6eaSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
388a0d3b6eaSmrg      "$@" -Wc,-MD
389a0d3b6eaSmrg   else
390a0d3b6eaSmrg      tmpdepfile1=$dir$base.o.d
391a0d3b6eaSmrg      tmpdepfile2=$dir$base.d
392a0d3b6eaSmrg      tmpdepfile3=$dir$base.d
393a0d3b6eaSmrg      tmpdepfile4=$dir$base.d
394a0d3b6eaSmrg      "$@" -MD
395a0d3b6eaSmrg   fi
396a0d3b6eaSmrg
397a0d3b6eaSmrg   stat=$?
398a0d3b6eaSmrg   if test $stat -eq 0; then :
399a0d3b6eaSmrg   else
400a0d3b6eaSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
401a0d3b6eaSmrg      exit $stat
402a0d3b6eaSmrg   fi
403a0d3b6eaSmrg
404a0d3b6eaSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
405a0d3b6eaSmrg   do
406a0d3b6eaSmrg     test -f "$tmpdepfile" && break
407a0d3b6eaSmrg   done
408a0d3b6eaSmrg   if test -f "$tmpdepfile"; then
409a0d3b6eaSmrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
410a0d3b6eaSmrg      # That's a tab and a space in the [].
411a0d3b6eaSmrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
412a0d3b6eaSmrg   else
413a0d3b6eaSmrg      echo "#dummy" > "$depfile"
414a0d3b6eaSmrg   fi
415a0d3b6eaSmrg   rm -f "$tmpdepfile"
416a0d3b6eaSmrg   ;;
417a0d3b6eaSmrg
418966b534aSmrgmsvc7)
419966b534aSmrg  if test "$libtool" = yes; then
420966b534aSmrg    showIncludes=-Wc,-showIncludes
421966b534aSmrg  else
422966b534aSmrg    showIncludes=-showIncludes
423966b534aSmrg  fi
424966b534aSmrg  "$@" $showIncludes > "$tmpdepfile"
425966b534aSmrg  stat=$?
426966b534aSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
427966b534aSmrg  if test "$stat" = 0; then :
428966b534aSmrg  else
429966b534aSmrg    rm -f "$tmpdepfile"
430966b534aSmrg    exit $stat
431966b534aSmrg  fi
432966b534aSmrg  rm -f "$depfile"
433966b534aSmrg  echo "$object : \\" > "$depfile"
434966b534aSmrg  # The first sed program below extracts the file names and escapes
435966b534aSmrg  # backslashes for cygpath.  The second sed program outputs the file
436966b534aSmrg  # name when reading, but also accumulates all include files in the
437966b534aSmrg  # hold buffer in order to output them again at the end.  This only
438966b534aSmrg  # works with sed implementations that can handle large buffers.
439966b534aSmrg  sed < "$tmpdepfile" -n '
440966b534aSmrg/^Note: including file:  *\(.*\)/ {
441966b534aSmrg  s//\1/
442966b534aSmrg  s/\\/\\\\/g
443966b534aSmrg  p
444966b534aSmrg}' | $cygpath_u | sort -u | sed -n '
445966b534aSmrgs/ /\\ /g
446966b534aSmrgs/\(.*\)/	\1 \\/p
447966b534aSmrgs/.\(.*\) \\/\1:/
448966b534aSmrgH
449966b534aSmrg$ {
450966b534aSmrg  s/.*/	/
451966b534aSmrg  G
452966b534aSmrg  p
453966b534aSmrg}' >> "$depfile"
454966b534aSmrg  rm -f "$tmpdepfile"
455966b534aSmrg  ;;
456966b534aSmrg
457966b534aSmrgmsvc7msys)
458966b534aSmrg  # This case exists only to let depend.m4 do its work.  It works by
459966b534aSmrg  # looking at the text of this script.  This case will never be run,
460966b534aSmrg  # since it is checked for above.
461966b534aSmrg  exit 1
462966b534aSmrg  ;;
463966b534aSmrg
464a0d3b6eaSmrg#nosideeffect)
465a0d3b6eaSmrg  # This comment above is used by automake to tell side-effect
466a0d3b6eaSmrg  # dependency tracking mechanisms from slower ones.
467a0d3b6eaSmrg
468a0d3b6eaSmrgdashmstdout)
469a0d3b6eaSmrg  # Important note: in order to support this mode, a compiler *must*
470a0d3b6eaSmrg  # always write the preprocessed file to stdout, regardless of -o.
471a0d3b6eaSmrg  "$@" || exit $?
472a0d3b6eaSmrg
473a0d3b6eaSmrg  # Remove the call to Libtool.
474a0d3b6eaSmrg  if test "$libtool" = yes; then
475f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
476a0d3b6eaSmrg      shift
477a0d3b6eaSmrg    done
478a0d3b6eaSmrg    shift
479a0d3b6eaSmrg  fi
480a0d3b6eaSmrg
481a0d3b6eaSmrg  # Remove `-o $object'.
482a0d3b6eaSmrg  IFS=" "
483a0d3b6eaSmrg  for arg
484a0d3b6eaSmrg  do
485a0d3b6eaSmrg    case $arg in
486a0d3b6eaSmrg    -o)
487a0d3b6eaSmrg      shift
488a0d3b6eaSmrg      ;;
489a0d3b6eaSmrg    $object)
490a0d3b6eaSmrg      shift
491a0d3b6eaSmrg      ;;
492a0d3b6eaSmrg    *)
493a0d3b6eaSmrg      set fnord "$@" "$arg"
494a0d3b6eaSmrg      shift # fnord
495a0d3b6eaSmrg      shift # $arg
496a0d3b6eaSmrg      ;;
497a0d3b6eaSmrg    esac
498a0d3b6eaSmrg  done
499a0d3b6eaSmrg
500a0d3b6eaSmrg  test -z "$dashmflag" && dashmflag=-M
501a0d3b6eaSmrg  # Require at least two characters before searching for `:'
502a0d3b6eaSmrg  # in the target name.  This is to cope with DOS-style filenames:
503a0d3b6eaSmrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
504a0d3b6eaSmrg  "$@" $dashmflag |
505a0d3b6eaSmrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
506a0d3b6eaSmrg  rm -f "$depfile"
507a0d3b6eaSmrg  cat < "$tmpdepfile" > "$depfile"
508a0d3b6eaSmrg  tr ' ' '
509a0d3b6eaSmrg' < "$tmpdepfile" | \
510a0d3b6eaSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
511a0d3b6eaSmrg## correctly.  Breaking it into two sed invocations is a workaround.
512a0d3b6eaSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
513a0d3b6eaSmrg  rm -f "$tmpdepfile"
514a0d3b6eaSmrg  ;;
515a0d3b6eaSmrg
516a0d3b6eaSmrgdashXmstdout)
517a0d3b6eaSmrg  # This case only exists to satisfy depend.m4.  It is never actually
518a0d3b6eaSmrg  # run, as this mode is specially recognized in the preamble.
519a0d3b6eaSmrg  exit 1
520a0d3b6eaSmrg  ;;
521a0d3b6eaSmrg
522a0d3b6eaSmrgmakedepend)
523a0d3b6eaSmrg  "$@" || exit $?
524a0d3b6eaSmrg  # Remove any Libtool call
525a0d3b6eaSmrg  if test "$libtool" = yes; then
526f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
527a0d3b6eaSmrg      shift
528a0d3b6eaSmrg    done
529a0d3b6eaSmrg    shift
530a0d3b6eaSmrg  fi
531a0d3b6eaSmrg  # X makedepend
532a0d3b6eaSmrg  shift
533f8a31ee4Smrg  cleared=no eat=no
534f8a31ee4Smrg  for arg
535f8a31ee4Smrg  do
536a0d3b6eaSmrg    case $cleared in
537a0d3b6eaSmrg    no)
538a0d3b6eaSmrg      set ""; shift
539a0d3b6eaSmrg      cleared=yes ;;
540a0d3b6eaSmrg    esac
541f8a31ee4Smrg    if test $eat = yes; then
542f8a31ee4Smrg      eat=no
543f8a31ee4Smrg      continue
544f8a31ee4Smrg    fi
545a0d3b6eaSmrg    case "$arg" in
546a0d3b6eaSmrg    -D*|-I*)
547a0d3b6eaSmrg      set fnord "$@" "$arg"; shift ;;
548a0d3b6eaSmrg    # Strip any option that makedepend may not understand.  Remove
549a0d3b6eaSmrg    # the object too, otherwise makedepend will parse it as a source file.
550f8a31ee4Smrg    -arch)
551f8a31ee4Smrg      eat=yes ;;
552a0d3b6eaSmrg    -*|$object)
553a0d3b6eaSmrg      ;;
554a0d3b6eaSmrg    *)
555a0d3b6eaSmrg      set fnord "$@" "$arg"; shift ;;
556a0d3b6eaSmrg    esac
557a0d3b6eaSmrg  done
558f8a31ee4Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
559a0d3b6eaSmrg  touch "$tmpdepfile"
560a0d3b6eaSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
561a0d3b6eaSmrg  rm -f "$depfile"
562966b534aSmrg  # makedepend may prepend the VPATH from the source file name to the object.
563966b534aSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
564966b534aSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
565a0d3b6eaSmrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
566a0d3b6eaSmrg' | \
567a0d3b6eaSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
568a0d3b6eaSmrg## correctly.  Breaking it into two sed invocations is a workaround.
569a0d3b6eaSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
570a0d3b6eaSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
571a0d3b6eaSmrg  ;;
572a0d3b6eaSmrg
573a0d3b6eaSmrgcpp)
574a0d3b6eaSmrg  # Important note: in order to support this mode, a compiler *must*
575a0d3b6eaSmrg  # always write the preprocessed file to stdout.
576a0d3b6eaSmrg  "$@" || exit $?
577a0d3b6eaSmrg
578a0d3b6eaSmrg  # Remove the call to Libtool.
579a0d3b6eaSmrg  if test "$libtool" = yes; then
580f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
581a0d3b6eaSmrg      shift
582a0d3b6eaSmrg    done
583a0d3b6eaSmrg    shift
584a0d3b6eaSmrg  fi
585a0d3b6eaSmrg
586a0d3b6eaSmrg  # Remove `-o $object'.
587a0d3b6eaSmrg  IFS=" "
588a0d3b6eaSmrg  for arg
589a0d3b6eaSmrg  do
590a0d3b6eaSmrg    case $arg in
591a0d3b6eaSmrg    -o)
592a0d3b6eaSmrg      shift
593a0d3b6eaSmrg      ;;
594a0d3b6eaSmrg    $object)
595a0d3b6eaSmrg      shift
596a0d3b6eaSmrg      ;;
597a0d3b6eaSmrg    *)
598a0d3b6eaSmrg      set fnord "$@" "$arg"
599a0d3b6eaSmrg      shift # fnord
600a0d3b6eaSmrg      shift # $arg
601a0d3b6eaSmrg      ;;
602a0d3b6eaSmrg    esac
603a0d3b6eaSmrg  done
604a0d3b6eaSmrg
605a0d3b6eaSmrg  "$@" -E |
606a0d3b6eaSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
607a0d3b6eaSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
608a0d3b6eaSmrg    sed '$ s: \\$::' > "$tmpdepfile"
609a0d3b6eaSmrg  rm -f "$depfile"
610a0d3b6eaSmrg  echo "$object : \\" > "$depfile"
611a0d3b6eaSmrg  cat < "$tmpdepfile" >> "$depfile"
612a0d3b6eaSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
613a0d3b6eaSmrg  rm -f "$tmpdepfile"
614a0d3b6eaSmrg  ;;
615a0d3b6eaSmrg
616a0d3b6eaSmrgmsvisualcpp)
617a0d3b6eaSmrg  # Important note: in order to support this mode, a compiler *must*
618f8a31ee4Smrg  # always write the preprocessed file to stdout.
619a0d3b6eaSmrg  "$@" || exit $?
620f8a31ee4Smrg
621f8a31ee4Smrg  # Remove the call to Libtool.
622f8a31ee4Smrg  if test "$libtool" = yes; then
623f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
624f8a31ee4Smrg      shift
625f8a31ee4Smrg    done
626f8a31ee4Smrg    shift
627f8a31ee4Smrg  fi
628f8a31ee4Smrg
629a0d3b6eaSmrg  IFS=" "
630a0d3b6eaSmrg  for arg
631a0d3b6eaSmrg  do
632a0d3b6eaSmrg    case "$arg" in
633f8a31ee4Smrg    -o)
634f8a31ee4Smrg      shift
635f8a31ee4Smrg      ;;
636f8a31ee4Smrg    $object)
637f8a31ee4Smrg      shift
638f8a31ee4Smrg      ;;
639a0d3b6eaSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
640a0d3b6eaSmrg	set fnord "$@"
641a0d3b6eaSmrg	shift
642a0d3b6eaSmrg	shift
643a0d3b6eaSmrg	;;
644a0d3b6eaSmrg    *)
645a0d3b6eaSmrg	set fnord "$@" "$arg"
646a0d3b6eaSmrg	shift
647a0d3b6eaSmrg	shift
648a0d3b6eaSmrg	;;
649a0d3b6eaSmrg    esac
650a0d3b6eaSmrg  done
651f8a31ee4Smrg  "$@" -E 2>/dev/null |
652f8a31ee4Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
653a0d3b6eaSmrg  rm -f "$depfile"
654a0d3b6eaSmrg  echo "$object : \\" > "$depfile"
655f8a31ee4Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
656a0d3b6eaSmrg  echo "	" >> "$depfile"
657f8a31ee4Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
658a0d3b6eaSmrg  rm -f "$tmpdepfile"
659a0d3b6eaSmrg  ;;
660a0d3b6eaSmrg
661f8a31ee4Smrgmsvcmsys)
662f8a31ee4Smrg  # This case exists only to let depend.m4 do its work.  It works by
663f8a31ee4Smrg  # looking at the text of this script.  This case will never be run,
664f8a31ee4Smrg  # since it is checked for above.
665f8a31ee4Smrg  exit 1
666f8a31ee4Smrg  ;;
667f8a31ee4Smrg
668a0d3b6eaSmrgnone)
669a0d3b6eaSmrg  exec "$@"
670a0d3b6eaSmrg  ;;
671a0d3b6eaSmrg
672a0d3b6eaSmrg*)
673a0d3b6eaSmrg  echo "Unknown depmode $depmode" 1>&2
674a0d3b6eaSmrg  exit 1
675a0d3b6eaSmrg  ;;
676a0d3b6eaSmrgesac
677a0d3b6eaSmrg
678a0d3b6eaSmrgexit 0
679a0d3b6eaSmrg
680a0d3b6eaSmrg# Local Variables:
681a0d3b6eaSmrg# mode: shell-script
682a0d3b6eaSmrg# sh-indentation: 2
683a0d3b6eaSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
684a0d3b6eaSmrg# time-stamp-start: "scriptversion="
685a0d3b6eaSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
686f8a31ee4Smrg# time-stamp-time-zone: "UTC"
687f8a31ee4Smrg# time-stamp-end: "; # UTC"
688a0d3b6eaSmrg# End:
689