depcomp revision f8a31ee4
1a0d3b6eaSmrg#! /bin/sh
2a0d3b6eaSmrg# depcomp - compile a program generating dependencies as side-effects
3a0d3b6eaSmrg
4f8a31ee4Smrgscriptversion=2009-04-28.21; # UTC
5a0d3b6eaSmrg
6f8a31ee4Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
7f8a31ee4Smrg# 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.
47a0d3b6eaSmrg  tmpdepfile  Temporary file to use when outputing 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
93f8a31ee4Smrg   cygpath_u="sed s,\\\\\\\\,/,g"
94f8a31ee4Smrg   depmode=msvisualcpp
95f8a31ee4Smrgfi
96f8a31ee4Smrg
97a0d3b6eaSmrgcase "$depmode" in
98a0d3b6eaSmrggcc3)
99a0d3b6eaSmrg## gcc 3 implements dependency tracking that does exactly what
100a0d3b6eaSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
101a0d3b6eaSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
102a0d3b6eaSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
103a0d3b6eaSmrg## the command line argument order; so add the flags where they
104a0d3b6eaSmrg## appear in depend2.am.  Note that the slowdown incurred here
105a0d3b6eaSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
106a0d3b6eaSmrg  for arg
107a0d3b6eaSmrg  do
108a0d3b6eaSmrg    case $arg in
109a0d3b6eaSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
110a0d3b6eaSmrg    *)  set fnord "$@" "$arg" ;;
111a0d3b6eaSmrg    esac
112a0d3b6eaSmrg    shift # fnord
113a0d3b6eaSmrg    shift # $arg
114a0d3b6eaSmrg  done
115a0d3b6eaSmrg  "$@"
116a0d3b6eaSmrg  stat=$?
117a0d3b6eaSmrg  if test $stat -eq 0; then :
118a0d3b6eaSmrg  else
119a0d3b6eaSmrg    rm -f "$tmpdepfile"
120a0d3b6eaSmrg    exit $stat
121a0d3b6eaSmrg  fi
122a0d3b6eaSmrg  mv "$tmpdepfile" "$depfile"
123a0d3b6eaSmrg  ;;
124a0d3b6eaSmrg
125a0d3b6eaSmrggcc)
126a0d3b6eaSmrg## There are various ways to get dependency output from gcc.  Here's
127a0d3b6eaSmrg## why we pick this rather obscure method:
128a0d3b6eaSmrg## - Don't want to use -MD because we'd like the dependencies to end
129a0d3b6eaSmrg##   up in a subdir.  Having to rename by hand is ugly.
130a0d3b6eaSmrg##   (We might end up doing this anyway to support other compilers.)
131a0d3b6eaSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
132a0d3b6eaSmrg##   -MM, not -M (despite what the docs say).
133a0d3b6eaSmrg## - Using -M directly means running the compiler twice (even worse
134a0d3b6eaSmrg##   than renaming).
135a0d3b6eaSmrg  if test -z "$gccflag"; then
136a0d3b6eaSmrg    gccflag=-MD,
137a0d3b6eaSmrg  fi
138a0d3b6eaSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
139a0d3b6eaSmrg  stat=$?
140a0d3b6eaSmrg  if test $stat -eq 0; then :
141a0d3b6eaSmrg  else
142a0d3b6eaSmrg    rm -f "$tmpdepfile"
143a0d3b6eaSmrg    exit $stat
144a0d3b6eaSmrg  fi
145a0d3b6eaSmrg  rm -f "$depfile"
146a0d3b6eaSmrg  echo "$object : \\" > "$depfile"
147a0d3b6eaSmrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
148a0d3b6eaSmrg## The second -e expression handles DOS-style file names with drive letters.
149a0d3b6eaSmrg  sed -e 's/^[^:]*: / /' \
150a0d3b6eaSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
151a0d3b6eaSmrg## This next piece of magic avoids the `deleted header file' problem.
152a0d3b6eaSmrg## The problem is that when a header file which appears in a .P file
153a0d3b6eaSmrg## is deleted, the dependency causes make to die (because there is
154a0d3b6eaSmrg## typically no way to rebuild the header).  We avoid this by adding
155a0d3b6eaSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
156a0d3b6eaSmrg## this for us directly.
157a0d3b6eaSmrg  tr ' ' '
158a0d3b6eaSmrg' < "$tmpdepfile" |
159a0d3b6eaSmrg## Some versions of gcc put a space before the `:'.  On the theory
160a0d3b6eaSmrg## that the space means something, we add a space to the output as
161a0d3b6eaSmrg## well.
162a0d3b6eaSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
163a0d3b6eaSmrg## correctly.  Breaking it into two sed invocations is a workaround.
164a0d3b6eaSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
165a0d3b6eaSmrg  rm -f "$tmpdepfile"
166a0d3b6eaSmrg  ;;
167a0d3b6eaSmrg
168a0d3b6eaSmrghp)
169a0d3b6eaSmrg  # This case exists only to let depend.m4 do its work.  It works by
170a0d3b6eaSmrg  # looking at the text of this script.  This case will never be run,
171a0d3b6eaSmrg  # since it is checked for above.
172a0d3b6eaSmrg  exit 1
173a0d3b6eaSmrg  ;;
174a0d3b6eaSmrg
175a0d3b6eaSmrgsgi)
176a0d3b6eaSmrg  if test "$libtool" = yes; then
177a0d3b6eaSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
178a0d3b6eaSmrg  else
179a0d3b6eaSmrg    "$@" -MDupdate "$tmpdepfile"
180a0d3b6eaSmrg  fi
181a0d3b6eaSmrg  stat=$?
182a0d3b6eaSmrg  if test $stat -eq 0; then :
183a0d3b6eaSmrg  else
184a0d3b6eaSmrg    rm -f "$tmpdepfile"
185a0d3b6eaSmrg    exit $stat
186a0d3b6eaSmrg  fi
187a0d3b6eaSmrg  rm -f "$depfile"
188a0d3b6eaSmrg
189a0d3b6eaSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
190a0d3b6eaSmrg    echo "$object : \\" > "$depfile"
191a0d3b6eaSmrg
192a0d3b6eaSmrg    # Clip off the initial element (the dependent).  Don't try to be
193a0d3b6eaSmrg    # clever and replace this with sed code, as IRIX sed won't handle
194a0d3b6eaSmrg    # lines with more than a fixed number of characters (4096 in
195a0d3b6eaSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
196a0d3b6eaSmrg    # the IRIX cc adds comments like `#:fec' to the end of the
197a0d3b6eaSmrg    # dependency line.
198a0d3b6eaSmrg    tr ' ' '
199a0d3b6eaSmrg' < "$tmpdepfile" \
200a0d3b6eaSmrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
201a0d3b6eaSmrg    tr '
202f8a31ee4Smrg' ' ' >> "$depfile"
203f8a31ee4Smrg    echo >> "$depfile"
204a0d3b6eaSmrg
205a0d3b6eaSmrg    # The second pass generates a dummy entry for each header file.
206a0d3b6eaSmrg    tr ' ' '
207a0d3b6eaSmrg' < "$tmpdepfile" \
208a0d3b6eaSmrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
209f8a31ee4Smrg   >> "$depfile"
210a0d3b6eaSmrg  else
211a0d3b6eaSmrg    # The sourcefile does not contain any dependencies, so just
212a0d3b6eaSmrg    # store a dummy comment line, to avoid errors with the Makefile
213a0d3b6eaSmrg    # "include basename.Plo" scheme.
214a0d3b6eaSmrg    echo "#dummy" > "$depfile"
215a0d3b6eaSmrg  fi
216a0d3b6eaSmrg  rm -f "$tmpdepfile"
217a0d3b6eaSmrg  ;;
218a0d3b6eaSmrg
219a0d3b6eaSmrgaix)
220a0d3b6eaSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
221a0d3b6eaSmrg  # in a .u file.  In older versions, this file always lives in the
222a0d3b6eaSmrg  # current directory.  Also, the AIX compiler puts `$object:' at the
223a0d3b6eaSmrg  # start of each line; $object doesn't have directory information.
224a0d3b6eaSmrg  # Version 6 uses the directory in both cases.
225f8a31ee4Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
226f8a31ee4Smrg  test "x$dir" = "x$object" && dir=
227f8a31ee4Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
228a0d3b6eaSmrg  if test "$libtool" = yes; then
229f8a31ee4Smrg    tmpdepfile1=$dir$base.u
230f8a31ee4Smrg    tmpdepfile2=$base.u
231f8a31ee4Smrg    tmpdepfile3=$dir.libs/$base.u
232a0d3b6eaSmrg    "$@" -Wc,-M
233a0d3b6eaSmrg  else
234f8a31ee4Smrg    tmpdepfile1=$dir$base.u
235f8a31ee4Smrg    tmpdepfile2=$dir$base.u
236f8a31ee4Smrg    tmpdepfile3=$dir$base.u
237a0d3b6eaSmrg    "$@" -M
238a0d3b6eaSmrg  fi
239a0d3b6eaSmrg  stat=$?
240a0d3b6eaSmrg
241a0d3b6eaSmrg  if test $stat -eq 0; then :
242a0d3b6eaSmrg  else
243f8a31ee4Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
244a0d3b6eaSmrg    exit $stat
245a0d3b6eaSmrg  fi
246a0d3b6eaSmrg
247f8a31ee4Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
248f8a31ee4Smrg  do
249f8a31ee4Smrg    test -f "$tmpdepfile" && break
250f8a31ee4Smrg  done
251a0d3b6eaSmrg  if test -f "$tmpdepfile"; then
252a0d3b6eaSmrg    # Each line is of the form `foo.o: dependent.h'.
253a0d3b6eaSmrg    # Do two passes, one to just change these to
254a0d3b6eaSmrg    # `$object: dependent.h' and one to simply `dependent.h:'.
255f8a31ee4Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
256f8a31ee4Smrg    # That's a tab and a space in the [].
257f8a31ee4Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
258a0d3b6eaSmrg  else
259a0d3b6eaSmrg    # The sourcefile does not contain any dependencies, so just
260a0d3b6eaSmrg    # store a dummy comment line, to avoid errors with the Makefile
261a0d3b6eaSmrg    # "include basename.Plo" scheme.
262a0d3b6eaSmrg    echo "#dummy" > "$depfile"
263a0d3b6eaSmrg  fi
264a0d3b6eaSmrg  rm -f "$tmpdepfile"
265a0d3b6eaSmrg  ;;
266a0d3b6eaSmrg
267a0d3b6eaSmrgicc)
268a0d3b6eaSmrg  # Intel's C compiler understands `-MD -MF file'.  However on
269a0d3b6eaSmrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
270a0d3b6eaSmrg  # ICC 7.0 will fill foo.d with something like
271a0d3b6eaSmrg  #    foo.o: sub/foo.c
272a0d3b6eaSmrg  #    foo.o: sub/foo.h
273a0d3b6eaSmrg  # which is wrong.  We want:
274a0d3b6eaSmrg  #    sub/foo.o: sub/foo.c
275a0d3b6eaSmrg  #    sub/foo.o: sub/foo.h
276a0d3b6eaSmrg  #    sub/foo.c:
277a0d3b6eaSmrg  #    sub/foo.h:
278a0d3b6eaSmrg  # ICC 7.1 will output
279a0d3b6eaSmrg  #    foo.o: sub/foo.c sub/foo.h
280a0d3b6eaSmrg  # and will wrap long lines using \ :
281a0d3b6eaSmrg  #    foo.o: sub/foo.c ... \
282a0d3b6eaSmrg  #     sub/foo.h ... \
283a0d3b6eaSmrg  #     ...
284a0d3b6eaSmrg
285a0d3b6eaSmrg  "$@" -MD -MF "$tmpdepfile"
286a0d3b6eaSmrg  stat=$?
287a0d3b6eaSmrg  if test $stat -eq 0; then :
288a0d3b6eaSmrg  else
289a0d3b6eaSmrg    rm -f "$tmpdepfile"
290a0d3b6eaSmrg    exit $stat
291a0d3b6eaSmrg  fi
292a0d3b6eaSmrg  rm -f "$depfile"
293a0d3b6eaSmrg  # Each line is of the form `foo.o: dependent.h',
294a0d3b6eaSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
295a0d3b6eaSmrg  # Do two passes, one to just change these to
296a0d3b6eaSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
297a0d3b6eaSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
298a0d3b6eaSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
299a0d3b6eaSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
300a0d3b6eaSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
301a0d3b6eaSmrg    sed -e 's/$/ :/' >> "$depfile"
302a0d3b6eaSmrg  rm -f "$tmpdepfile"
303a0d3b6eaSmrg  ;;
304a0d3b6eaSmrg
305a0d3b6eaSmrghp2)
306a0d3b6eaSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
307a0d3b6eaSmrg  # compilers, which have integrated preprocessors.  The correct option
308a0d3b6eaSmrg  # to use with these is +Maked; it writes dependencies to a file named
309a0d3b6eaSmrg  # 'foo.d', which lands next to the object file, wherever that
310a0d3b6eaSmrg  # happens to be.
311a0d3b6eaSmrg  # Much of this is similar to the tru64 case; see comments there.
312a0d3b6eaSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
313a0d3b6eaSmrg  test "x$dir" = "x$object" && dir=
314a0d3b6eaSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
315a0d3b6eaSmrg  if test "$libtool" = yes; then
316a0d3b6eaSmrg    tmpdepfile1=$dir$base.d
317a0d3b6eaSmrg    tmpdepfile2=$dir.libs/$base.d
318a0d3b6eaSmrg    "$@" -Wc,+Maked
319a0d3b6eaSmrg  else
320a0d3b6eaSmrg    tmpdepfile1=$dir$base.d
321a0d3b6eaSmrg    tmpdepfile2=$dir$base.d
322a0d3b6eaSmrg    "$@" +Maked
323a0d3b6eaSmrg  fi
324a0d3b6eaSmrg  stat=$?
325a0d3b6eaSmrg  if test $stat -eq 0; then :
326a0d3b6eaSmrg  else
327a0d3b6eaSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
328a0d3b6eaSmrg     exit $stat
329a0d3b6eaSmrg  fi
330a0d3b6eaSmrg
331a0d3b6eaSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
332a0d3b6eaSmrg  do
333a0d3b6eaSmrg    test -f "$tmpdepfile" && break
334a0d3b6eaSmrg  done
335a0d3b6eaSmrg  if test -f "$tmpdepfile"; then
336a0d3b6eaSmrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
337a0d3b6eaSmrg    # Add `dependent.h:' lines.
338f8a31ee4Smrg    sed -ne '2,${
339f8a31ee4Smrg	       s/^ *//
340f8a31ee4Smrg	       s/ \\*$//
341f8a31ee4Smrg	       s/$/:/
342f8a31ee4Smrg	       p
343f8a31ee4Smrg	     }' "$tmpdepfile" >> "$depfile"
344a0d3b6eaSmrg  else
345a0d3b6eaSmrg    echo "#dummy" > "$depfile"
346a0d3b6eaSmrg  fi
347a0d3b6eaSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
348a0d3b6eaSmrg  ;;
349a0d3b6eaSmrg
350a0d3b6eaSmrgtru64)
351a0d3b6eaSmrg   # The Tru64 compiler uses -MD to generate dependencies as a side
352a0d3b6eaSmrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
353a0d3b6eaSmrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
354a0d3b6eaSmrg   # dependencies in `foo.d' instead, so we check for that too.
355a0d3b6eaSmrg   # Subdirectories are respected.
356a0d3b6eaSmrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
357a0d3b6eaSmrg   test "x$dir" = "x$object" && dir=
358a0d3b6eaSmrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
359a0d3b6eaSmrg
360a0d3b6eaSmrg   if test "$libtool" = yes; then
361a0d3b6eaSmrg      # With Tru64 cc, shared objects can also be used to make a
362a0d3b6eaSmrg      # static library.  This mechanism is used in libtool 1.4 series to
363a0d3b6eaSmrg      # handle both shared and static libraries in a single compilation.
364a0d3b6eaSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
365a0d3b6eaSmrg      #
366a0d3b6eaSmrg      # With libtool 1.5 this exception was removed, and libtool now
367a0d3b6eaSmrg      # generates 2 separate objects for the 2 libraries.  These two
368a0d3b6eaSmrg      # compilations output dependencies in $dir.libs/$base.o.d and
369a0d3b6eaSmrg      # in $dir$base.o.d.  We have to check for both files, because
370a0d3b6eaSmrg      # one of the two compilations can be disabled.  We should prefer
371a0d3b6eaSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
372a0d3b6eaSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
373a0d3b6eaSmrg      # the former would cause a distcleancheck panic.
374a0d3b6eaSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
375a0d3b6eaSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
376a0d3b6eaSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
377a0d3b6eaSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
378a0d3b6eaSmrg      "$@" -Wc,-MD
379a0d3b6eaSmrg   else
380a0d3b6eaSmrg      tmpdepfile1=$dir$base.o.d
381a0d3b6eaSmrg      tmpdepfile2=$dir$base.d
382a0d3b6eaSmrg      tmpdepfile3=$dir$base.d
383a0d3b6eaSmrg      tmpdepfile4=$dir$base.d
384a0d3b6eaSmrg      "$@" -MD
385a0d3b6eaSmrg   fi
386a0d3b6eaSmrg
387a0d3b6eaSmrg   stat=$?
388a0d3b6eaSmrg   if test $stat -eq 0; then :
389a0d3b6eaSmrg   else
390a0d3b6eaSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
391a0d3b6eaSmrg      exit $stat
392a0d3b6eaSmrg   fi
393a0d3b6eaSmrg
394a0d3b6eaSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
395a0d3b6eaSmrg   do
396a0d3b6eaSmrg     test -f "$tmpdepfile" && break
397a0d3b6eaSmrg   done
398a0d3b6eaSmrg   if test -f "$tmpdepfile"; then
399a0d3b6eaSmrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
400a0d3b6eaSmrg      # That's a tab and a space in the [].
401a0d3b6eaSmrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
402a0d3b6eaSmrg   else
403a0d3b6eaSmrg      echo "#dummy" > "$depfile"
404a0d3b6eaSmrg   fi
405a0d3b6eaSmrg   rm -f "$tmpdepfile"
406a0d3b6eaSmrg   ;;
407a0d3b6eaSmrg
408a0d3b6eaSmrg#nosideeffect)
409a0d3b6eaSmrg  # This comment above is used by automake to tell side-effect
410a0d3b6eaSmrg  # dependency tracking mechanisms from slower ones.
411a0d3b6eaSmrg
412a0d3b6eaSmrgdashmstdout)
413a0d3b6eaSmrg  # Important note: in order to support this mode, a compiler *must*
414a0d3b6eaSmrg  # always write the preprocessed file to stdout, regardless of -o.
415a0d3b6eaSmrg  "$@" || exit $?
416a0d3b6eaSmrg
417a0d3b6eaSmrg  # Remove the call to Libtool.
418a0d3b6eaSmrg  if test "$libtool" = yes; then
419f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
420a0d3b6eaSmrg      shift
421a0d3b6eaSmrg    done
422a0d3b6eaSmrg    shift
423a0d3b6eaSmrg  fi
424a0d3b6eaSmrg
425a0d3b6eaSmrg  # Remove `-o $object'.
426a0d3b6eaSmrg  IFS=" "
427a0d3b6eaSmrg  for arg
428a0d3b6eaSmrg  do
429a0d3b6eaSmrg    case $arg in
430a0d3b6eaSmrg    -o)
431a0d3b6eaSmrg      shift
432a0d3b6eaSmrg      ;;
433a0d3b6eaSmrg    $object)
434a0d3b6eaSmrg      shift
435a0d3b6eaSmrg      ;;
436a0d3b6eaSmrg    *)
437a0d3b6eaSmrg      set fnord "$@" "$arg"
438a0d3b6eaSmrg      shift # fnord
439a0d3b6eaSmrg      shift # $arg
440a0d3b6eaSmrg      ;;
441a0d3b6eaSmrg    esac
442a0d3b6eaSmrg  done
443a0d3b6eaSmrg
444a0d3b6eaSmrg  test -z "$dashmflag" && dashmflag=-M
445a0d3b6eaSmrg  # Require at least two characters before searching for `:'
446a0d3b6eaSmrg  # in the target name.  This is to cope with DOS-style filenames:
447a0d3b6eaSmrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
448a0d3b6eaSmrg  "$@" $dashmflag |
449a0d3b6eaSmrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
450a0d3b6eaSmrg  rm -f "$depfile"
451a0d3b6eaSmrg  cat < "$tmpdepfile" > "$depfile"
452a0d3b6eaSmrg  tr ' ' '
453a0d3b6eaSmrg' < "$tmpdepfile" | \
454a0d3b6eaSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
455a0d3b6eaSmrg## correctly.  Breaking it into two sed invocations is a workaround.
456a0d3b6eaSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
457a0d3b6eaSmrg  rm -f "$tmpdepfile"
458a0d3b6eaSmrg  ;;
459a0d3b6eaSmrg
460a0d3b6eaSmrgdashXmstdout)
461a0d3b6eaSmrg  # This case only exists to satisfy depend.m4.  It is never actually
462a0d3b6eaSmrg  # run, as this mode is specially recognized in the preamble.
463a0d3b6eaSmrg  exit 1
464a0d3b6eaSmrg  ;;
465a0d3b6eaSmrg
466a0d3b6eaSmrgmakedepend)
467a0d3b6eaSmrg  "$@" || exit $?
468a0d3b6eaSmrg  # Remove any Libtool call
469a0d3b6eaSmrg  if test "$libtool" = yes; then
470f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
471a0d3b6eaSmrg      shift
472a0d3b6eaSmrg    done
473a0d3b6eaSmrg    shift
474a0d3b6eaSmrg  fi
475a0d3b6eaSmrg  # X makedepend
476a0d3b6eaSmrg  shift
477f8a31ee4Smrg  cleared=no eat=no
478f8a31ee4Smrg  for arg
479f8a31ee4Smrg  do
480a0d3b6eaSmrg    case $cleared in
481a0d3b6eaSmrg    no)
482a0d3b6eaSmrg      set ""; shift
483a0d3b6eaSmrg      cleared=yes ;;
484a0d3b6eaSmrg    esac
485f8a31ee4Smrg    if test $eat = yes; then
486f8a31ee4Smrg      eat=no
487f8a31ee4Smrg      continue
488f8a31ee4Smrg    fi
489a0d3b6eaSmrg    case "$arg" in
490a0d3b6eaSmrg    -D*|-I*)
491a0d3b6eaSmrg      set fnord "$@" "$arg"; shift ;;
492a0d3b6eaSmrg    # Strip any option that makedepend may not understand.  Remove
493a0d3b6eaSmrg    # the object too, otherwise makedepend will parse it as a source file.
494f8a31ee4Smrg    -arch)
495f8a31ee4Smrg      eat=yes ;;
496a0d3b6eaSmrg    -*|$object)
497a0d3b6eaSmrg      ;;
498a0d3b6eaSmrg    *)
499a0d3b6eaSmrg      set fnord "$@" "$arg"; shift ;;
500a0d3b6eaSmrg    esac
501a0d3b6eaSmrg  done
502f8a31ee4Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
503a0d3b6eaSmrg  touch "$tmpdepfile"
504a0d3b6eaSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
505a0d3b6eaSmrg  rm -f "$depfile"
506a0d3b6eaSmrg  cat < "$tmpdepfile" > "$depfile"
507a0d3b6eaSmrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
508a0d3b6eaSmrg' | \
509a0d3b6eaSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
510a0d3b6eaSmrg## correctly.  Breaking it into two sed invocations is a workaround.
511a0d3b6eaSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
512a0d3b6eaSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
513a0d3b6eaSmrg  ;;
514a0d3b6eaSmrg
515a0d3b6eaSmrgcpp)
516a0d3b6eaSmrg  # Important note: in order to support this mode, a compiler *must*
517a0d3b6eaSmrg  # always write the preprocessed file to stdout.
518a0d3b6eaSmrg  "$@" || exit $?
519a0d3b6eaSmrg
520a0d3b6eaSmrg  # Remove the call to Libtool.
521a0d3b6eaSmrg  if test "$libtool" = yes; then
522f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
523a0d3b6eaSmrg      shift
524a0d3b6eaSmrg    done
525a0d3b6eaSmrg    shift
526a0d3b6eaSmrg  fi
527a0d3b6eaSmrg
528a0d3b6eaSmrg  # Remove `-o $object'.
529a0d3b6eaSmrg  IFS=" "
530a0d3b6eaSmrg  for arg
531a0d3b6eaSmrg  do
532a0d3b6eaSmrg    case $arg in
533a0d3b6eaSmrg    -o)
534a0d3b6eaSmrg      shift
535a0d3b6eaSmrg      ;;
536a0d3b6eaSmrg    $object)
537a0d3b6eaSmrg      shift
538a0d3b6eaSmrg      ;;
539a0d3b6eaSmrg    *)
540a0d3b6eaSmrg      set fnord "$@" "$arg"
541a0d3b6eaSmrg      shift # fnord
542a0d3b6eaSmrg      shift # $arg
543a0d3b6eaSmrg      ;;
544a0d3b6eaSmrg    esac
545a0d3b6eaSmrg  done
546a0d3b6eaSmrg
547a0d3b6eaSmrg  "$@" -E |
548a0d3b6eaSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
549a0d3b6eaSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
550a0d3b6eaSmrg    sed '$ s: \\$::' > "$tmpdepfile"
551a0d3b6eaSmrg  rm -f "$depfile"
552a0d3b6eaSmrg  echo "$object : \\" > "$depfile"
553a0d3b6eaSmrg  cat < "$tmpdepfile" >> "$depfile"
554a0d3b6eaSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
555a0d3b6eaSmrg  rm -f "$tmpdepfile"
556a0d3b6eaSmrg  ;;
557a0d3b6eaSmrg
558a0d3b6eaSmrgmsvisualcpp)
559a0d3b6eaSmrg  # Important note: in order to support this mode, a compiler *must*
560f8a31ee4Smrg  # always write the preprocessed file to stdout.
561a0d3b6eaSmrg  "$@" || exit $?
562f8a31ee4Smrg
563f8a31ee4Smrg  # Remove the call to Libtool.
564f8a31ee4Smrg  if test "$libtool" = yes; then
565f8a31ee4Smrg    while test "X$1" != 'X--mode=compile'; do
566f8a31ee4Smrg      shift
567f8a31ee4Smrg    done
568f8a31ee4Smrg    shift
569f8a31ee4Smrg  fi
570f8a31ee4Smrg
571a0d3b6eaSmrg  IFS=" "
572a0d3b6eaSmrg  for arg
573a0d3b6eaSmrg  do
574a0d3b6eaSmrg    case "$arg" in
575f8a31ee4Smrg    -o)
576f8a31ee4Smrg      shift
577f8a31ee4Smrg      ;;
578f8a31ee4Smrg    $object)
579f8a31ee4Smrg      shift
580f8a31ee4Smrg      ;;
581a0d3b6eaSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
582a0d3b6eaSmrg	set fnord "$@"
583a0d3b6eaSmrg	shift
584a0d3b6eaSmrg	shift
585a0d3b6eaSmrg	;;
586a0d3b6eaSmrg    *)
587a0d3b6eaSmrg	set fnord "$@" "$arg"
588a0d3b6eaSmrg	shift
589a0d3b6eaSmrg	shift
590a0d3b6eaSmrg	;;
591a0d3b6eaSmrg    esac
592a0d3b6eaSmrg  done
593f8a31ee4Smrg  "$@" -E 2>/dev/null |
594f8a31ee4Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
595a0d3b6eaSmrg  rm -f "$depfile"
596a0d3b6eaSmrg  echo "$object : \\" > "$depfile"
597f8a31ee4Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
598a0d3b6eaSmrg  echo "	" >> "$depfile"
599f8a31ee4Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
600a0d3b6eaSmrg  rm -f "$tmpdepfile"
601a0d3b6eaSmrg  ;;
602a0d3b6eaSmrg
603f8a31ee4Smrgmsvcmsys)
604f8a31ee4Smrg  # This case exists only to let depend.m4 do its work.  It works by
605f8a31ee4Smrg  # looking at the text of this script.  This case will never be run,
606f8a31ee4Smrg  # since it is checked for above.
607f8a31ee4Smrg  exit 1
608f8a31ee4Smrg  ;;
609f8a31ee4Smrg
610a0d3b6eaSmrgnone)
611a0d3b6eaSmrg  exec "$@"
612a0d3b6eaSmrg  ;;
613a0d3b6eaSmrg
614a0d3b6eaSmrg*)
615a0d3b6eaSmrg  echo "Unknown depmode $depmode" 1>&2
616a0d3b6eaSmrg  exit 1
617a0d3b6eaSmrg  ;;
618a0d3b6eaSmrgesac
619a0d3b6eaSmrg
620a0d3b6eaSmrgexit 0
621a0d3b6eaSmrg
622a0d3b6eaSmrg# Local Variables:
623a0d3b6eaSmrg# mode: shell-script
624a0d3b6eaSmrg# sh-indentation: 2
625a0d3b6eaSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
626a0d3b6eaSmrg# time-stamp-start: "scriptversion="
627a0d3b6eaSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
628f8a31ee4Smrg# time-stamp-time-zone: "UTC"
629f8a31ee4Smrg# time-stamp-end: "; # UTC"
630a0d3b6eaSmrg# End:
631