depcomp revision a8fdb4bc
1a8fdb4bcSmrg#! /bin/sh
2a8fdb4bcSmrg# depcomp - compile a program generating dependencies as side-effects
3a8fdb4bcSmrg
4a8fdb4bcSmrgscriptversion=2007-03-29.01
5a8fdb4bcSmrg
6a8fdb4bcSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007 Free Software
7a8fdb4bcSmrg# Foundation, Inc.
8a8fdb4bcSmrg
9a8fdb4bcSmrg# This program is free software; you can redistribute it and/or modify
10a8fdb4bcSmrg# it under the terms of the GNU General Public License as published by
11a8fdb4bcSmrg# the Free Software Foundation; either version 2, or (at your option)
12a8fdb4bcSmrg# any later version.
13a8fdb4bcSmrg
14a8fdb4bcSmrg# This program is distributed in the hope that it will be useful,
15a8fdb4bcSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16a8fdb4bcSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a8fdb4bcSmrg# GNU General Public License for more details.
18a8fdb4bcSmrg
19a8fdb4bcSmrg# You should have received a copy of the GNU General Public License
20a8fdb4bcSmrg# along with this program; if not, write to the Free Software
21a8fdb4bcSmrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22a8fdb4bcSmrg# 02110-1301, USA.
23a8fdb4bcSmrg
24a8fdb4bcSmrg# As a special exception to the GNU General Public License, if you
25a8fdb4bcSmrg# distribute this file as part of a program that contains a
26a8fdb4bcSmrg# configuration script generated by Autoconf, you may include it under
27a8fdb4bcSmrg# the same distribution terms that you use for the rest of that program.
28a8fdb4bcSmrg
29a8fdb4bcSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
30a8fdb4bcSmrg
31a8fdb4bcSmrgcase $1 in
32a8fdb4bcSmrg  '')
33a8fdb4bcSmrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
34a8fdb4bcSmrg     exit 1;
35a8fdb4bcSmrg     ;;
36a8fdb4bcSmrg  -h | --h*)
37a8fdb4bcSmrg    cat <<\EOF
38a8fdb4bcSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
39a8fdb4bcSmrg
40a8fdb4bcSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
41a8fdb4bcSmrgas side-effects.
42a8fdb4bcSmrg
43a8fdb4bcSmrgEnvironment variables:
44a8fdb4bcSmrg  depmode     Dependency tracking mode.
45a8fdb4bcSmrg  source      Source file read by `PROGRAMS ARGS'.
46a8fdb4bcSmrg  object      Object file output by `PROGRAMS ARGS'.
47a8fdb4bcSmrg  DEPDIR      directory where to store dependencies.
48a8fdb4bcSmrg  depfile     Dependency file to output.
49a8fdb4bcSmrg  tmpdepfile  Temporary file to use when outputing dependencies.
50a8fdb4bcSmrg  libtool     Whether libtool is used (yes/no).
51a8fdb4bcSmrg
52a8fdb4bcSmrgReport bugs to <bug-automake@gnu.org>.
53a8fdb4bcSmrgEOF
54a8fdb4bcSmrg    exit $?
55a8fdb4bcSmrg    ;;
56a8fdb4bcSmrg  -v | --v*)
57a8fdb4bcSmrg    echo "depcomp $scriptversion"
58a8fdb4bcSmrg    exit $?
59a8fdb4bcSmrg    ;;
60a8fdb4bcSmrgesac
61a8fdb4bcSmrg
62a8fdb4bcSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
63a8fdb4bcSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
64a8fdb4bcSmrg  exit 1
65a8fdb4bcSmrgfi
66a8fdb4bcSmrg
67a8fdb4bcSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
68a8fdb4bcSmrgdepfile=${depfile-`echo "$object" |
69a8fdb4bcSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
70a8fdb4bcSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
71a8fdb4bcSmrg
72a8fdb4bcSmrgrm -f "$tmpdepfile"
73a8fdb4bcSmrg
74a8fdb4bcSmrg# Some modes work just like other modes, but use different flags.  We
75a8fdb4bcSmrg# parameterize here, but still list the modes in the big case below,
76a8fdb4bcSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
77a8fdb4bcSmrg# here, because this file can only contain one case statement.
78a8fdb4bcSmrgif test "$depmode" = hp; then
79a8fdb4bcSmrg  # HP compiler uses -M and no extra arg.
80a8fdb4bcSmrg  gccflag=-M
81a8fdb4bcSmrg  depmode=gcc
82a8fdb4bcSmrgfi
83a8fdb4bcSmrg
84a8fdb4bcSmrgif test "$depmode" = dashXmstdout; then
85a8fdb4bcSmrg   # This is just like dashmstdout with a different argument.
86a8fdb4bcSmrg   dashmflag=-xM
87a8fdb4bcSmrg   depmode=dashmstdout
88a8fdb4bcSmrgfi
89a8fdb4bcSmrg
90a8fdb4bcSmrgcase "$depmode" in
91a8fdb4bcSmrggcc3)
92a8fdb4bcSmrg## gcc 3 implements dependency tracking that does exactly what
93a8fdb4bcSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
94a8fdb4bcSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
95a8fdb4bcSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
96a8fdb4bcSmrg## the command line argument order; so add the flags where they
97a8fdb4bcSmrg## appear in depend2.am.  Note that the slowdown incurred here
98a8fdb4bcSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
99a8fdb4bcSmrg  for arg
100a8fdb4bcSmrg  do
101a8fdb4bcSmrg    case $arg in
102a8fdb4bcSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
103a8fdb4bcSmrg    *)  set fnord "$@" "$arg" ;;
104a8fdb4bcSmrg    esac
105a8fdb4bcSmrg    shift # fnord
106a8fdb4bcSmrg    shift # $arg
107a8fdb4bcSmrg  done
108a8fdb4bcSmrg  "$@"
109a8fdb4bcSmrg  stat=$?
110a8fdb4bcSmrg  if test $stat -eq 0; then :
111a8fdb4bcSmrg  else
112a8fdb4bcSmrg    rm -f "$tmpdepfile"
113a8fdb4bcSmrg    exit $stat
114a8fdb4bcSmrg  fi
115a8fdb4bcSmrg  mv "$tmpdepfile" "$depfile"
116a8fdb4bcSmrg  ;;
117a8fdb4bcSmrg
118a8fdb4bcSmrggcc)
119a8fdb4bcSmrg## There are various ways to get dependency output from gcc.  Here's
120a8fdb4bcSmrg## why we pick this rather obscure method:
121a8fdb4bcSmrg## - Don't want to use -MD because we'd like the dependencies to end
122a8fdb4bcSmrg##   up in a subdir.  Having to rename by hand is ugly.
123a8fdb4bcSmrg##   (We might end up doing this anyway to support other compilers.)
124a8fdb4bcSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
125a8fdb4bcSmrg##   -MM, not -M (despite what the docs say).
126a8fdb4bcSmrg## - Using -M directly means running the compiler twice (even worse
127a8fdb4bcSmrg##   than renaming).
128a8fdb4bcSmrg  if test -z "$gccflag"; then
129a8fdb4bcSmrg    gccflag=-MD,
130a8fdb4bcSmrg  fi
131a8fdb4bcSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
132a8fdb4bcSmrg  stat=$?
133a8fdb4bcSmrg  if test $stat -eq 0; then :
134a8fdb4bcSmrg  else
135a8fdb4bcSmrg    rm -f "$tmpdepfile"
136a8fdb4bcSmrg    exit $stat
137a8fdb4bcSmrg  fi
138a8fdb4bcSmrg  rm -f "$depfile"
139a8fdb4bcSmrg  echo "$object : \\" > "$depfile"
140a8fdb4bcSmrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
141a8fdb4bcSmrg## The second -e expression handles DOS-style file names with drive letters.
142a8fdb4bcSmrg  sed -e 's/^[^:]*: / /' \
143a8fdb4bcSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
144a8fdb4bcSmrg## This next piece of magic avoids the `deleted header file' problem.
145a8fdb4bcSmrg## The problem is that when a header file which appears in a .P file
146a8fdb4bcSmrg## is deleted, the dependency causes make to die (because there is
147a8fdb4bcSmrg## typically no way to rebuild the header).  We avoid this by adding
148a8fdb4bcSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
149a8fdb4bcSmrg## this for us directly.
150a8fdb4bcSmrg  tr ' ' '
151a8fdb4bcSmrg' < "$tmpdepfile" |
152a8fdb4bcSmrg## Some versions of gcc put a space before the `:'.  On the theory
153a8fdb4bcSmrg## that the space means something, we add a space to the output as
154a8fdb4bcSmrg## well.
155a8fdb4bcSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
156a8fdb4bcSmrg## correctly.  Breaking it into two sed invocations is a workaround.
157a8fdb4bcSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
158a8fdb4bcSmrg  rm -f "$tmpdepfile"
159a8fdb4bcSmrg  ;;
160a8fdb4bcSmrg
161a8fdb4bcSmrghp)
162a8fdb4bcSmrg  # This case exists only to let depend.m4 do its work.  It works by
163a8fdb4bcSmrg  # looking at the text of this script.  This case will never be run,
164a8fdb4bcSmrg  # since it is checked for above.
165a8fdb4bcSmrg  exit 1
166a8fdb4bcSmrg  ;;
167a8fdb4bcSmrg
168a8fdb4bcSmrgsgi)
169a8fdb4bcSmrg  if test "$libtool" = yes; then
170a8fdb4bcSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
171a8fdb4bcSmrg  else
172a8fdb4bcSmrg    "$@" -MDupdate "$tmpdepfile"
173a8fdb4bcSmrg  fi
174a8fdb4bcSmrg  stat=$?
175a8fdb4bcSmrg  if test $stat -eq 0; then :
176a8fdb4bcSmrg  else
177a8fdb4bcSmrg    rm -f "$tmpdepfile"
178a8fdb4bcSmrg    exit $stat
179a8fdb4bcSmrg  fi
180a8fdb4bcSmrg  rm -f "$depfile"
181a8fdb4bcSmrg
182a8fdb4bcSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
183a8fdb4bcSmrg    echo "$object : \\" > "$depfile"
184a8fdb4bcSmrg
185a8fdb4bcSmrg    # Clip off the initial element (the dependent).  Don't try to be
186a8fdb4bcSmrg    # clever and replace this with sed code, as IRIX sed won't handle
187a8fdb4bcSmrg    # lines with more than a fixed number of characters (4096 in
188a8fdb4bcSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
189a8fdb4bcSmrg    # the IRIX cc adds comments like `#:fec' to the end of the
190a8fdb4bcSmrg    # dependency line.
191a8fdb4bcSmrg    tr ' ' '
192a8fdb4bcSmrg' < "$tmpdepfile" \
193a8fdb4bcSmrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
194a8fdb4bcSmrg    tr '
195a8fdb4bcSmrg' ' ' >> $depfile
196a8fdb4bcSmrg    echo >> $depfile
197a8fdb4bcSmrg
198a8fdb4bcSmrg    # The second pass generates a dummy entry for each header file.
199a8fdb4bcSmrg    tr ' ' '
200a8fdb4bcSmrg' < "$tmpdepfile" \
201a8fdb4bcSmrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
202a8fdb4bcSmrg   >> $depfile
203a8fdb4bcSmrg  else
204a8fdb4bcSmrg    # The sourcefile does not contain any dependencies, so just
205a8fdb4bcSmrg    # store a dummy comment line, to avoid errors with the Makefile
206a8fdb4bcSmrg    # "include basename.Plo" scheme.
207a8fdb4bcSmrg    echo "#dummy" > "$depfile"
208a8fdb4bcSmrg  fi
209a8fdb4bcSmrg  rm -f "$tmpdepfile"
210a8fdb4bcSmrg  ;;
211a8fdb4bcSmrg
212a8fdb4bcSmrgaix)
213a8fdb4bcSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
214a8fdb4bcSmrg  # in a .u file.  In older versions, this file always lives in the
215a8fdb4bcSmrg  # current directory.  Also, the AIX compiler puts `$object:' at the
216a8fdb4bcSmrg  # start of each line; $object doesn't have directory information.
217a8fdb4bcSmrg  # Version 6 uses the directory in both cases.
218a8fdb4bcSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
219a8fdb4bcSmrg  test "x$dir" = "x$object" && dir=
220a8fdb4bcSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
221a8fdb4bcSmrg  if test "$libtool" = yes; then
222a8fdb4bcSmrg    tmpdepfile1=$dir$base.u
223a8fdb4bcSmrg    tmpdepfile2=$base.u
224a8fdb4bcSmrg    tmpdepfile3=$dir.libs/$base.u
225a8fdb4bcSmrg    "$@" -Wc,-M
226a8fdb4bcSmrg  else
227a8fdb4bcSmrg    tmpdepfile1=$dir$base.u
228a8fdb4bcSmrg    tmpdepfile2=$dir$base.u
229a8fdb4bcSmrg    tmpdepfile3=$dir$base.u
230a8fdb4bcSmrg    "$@" -M
231a8fdb4bcSmrg  fi
232a8fdb4bcSmrg  stat=$?
233a8fdb4bcSmrg
234a8fdb4bcSmrg  if test $stat -eq 0; then :
235a8fdb4bcSmrg  else
236a8fdb4bcSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
237a8fdb4bcSmrg    exit $stat
238a8fdb4bcSmrg  fi
239a8fdb4bcSmrg
240a8fdb4bcSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
241a8fdb4bcSmrg  do
242a8fdb4bcSmrg    test -f "$tmpdepfile" && break
243a8fdb4bcSmrg  done
244a8fdb4bcSmrg  if test -f "$tmpdepfile"; then
245a8fdb4bcSmrg    # Each line is of the form `foo.o: dependent.h'.
246a8fdb4bcSmrg    # Do two passes, one to just change these to
247a8fdb4bcSmrg    # `$object: dependent.h' and one to simply `dependent.h:'.
248a8fdb4bcSmrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
249a8fdb4bcSmrg    # That's a tab and a space in the [].
250a8fdb4bcSmrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
251a8fdb4bcSmrg  else
252a8fdb4bcSmrg    # The sourcefile does not contain any dependencies, so just
253a8fdb4bcSmrg    # store a dummy comment line, to avoid errors with the Makefile
254a8fdb4bcSmrg    # "include basename.Plo" scheme.
255a8fdb4bcSmrg    echo "#dummy" > "$depfile"
256a8fdb4bcSmrg  fi
257a8fdb4bcSmrg  rm -f "$tmpdepfile"
258a8fdb4bcSmrg  ;;
259a8fdb4bcSmrg
260a8fdb4bcSmrgicc)
261a8fdb4bcSmrg  # Intel's C compiler understands `-MD -MF file'.  However on
262a8fdb4bcSmrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
263a8fdb4bcSmrg  # ICC 7.0 will fill foo.d with something like
264a8fdb4bcSmrg  #    foo.o: sub/foo.c
265a8fdb4bcSmrg  #    foo.o: sub/foo.h
266a8fdb4bcSmrg  # which is wrong.  We want:
267a8fdb4bcSmrg  #    sub/foo.o: sub/foo.c
268a8fdb4bcSmrg  #    sub/foo.o: sub/foo.h
269a8fdb4bcSmrg  #    sub/foo.c:
270a8fdb4bcSmrg  #    sub/foo.h:
271a8fdb4bcSmrg  # ICC 7.1 will output
272a8fdb4bcSmrg  #    foo.o: sub/foo.c sub/foo.h
273a8fdb4bcSmrg  # and will wrap long lines using \ :
274a8fdb4bcSmrg  #    foo.o: sub/foo.c ... \
275a8fdb4bcSmrg  #     sub/foo.h ... \
276a8fdb4bcSmrg  #     ...
277a8fdb4bcSmrg
278a8fdb4bcSmrg  "$@" -MD -MF "$tmpdepfile"
279a8fdb4bcSmrg  stat=$?
280a8fdb4bcSmrg  if test $stat -eq 0; then :
281a8fdb4bcSmrg  else
282a8fdb4bcSmrg    rm -f "$tmpdepfile"
283a8fdb4bcSmrg    exit $stat
284a8fdb4bcSmrg  fi
285a8fdb4bcSmrg  rm -f "$depfile"
286a8fdb4bcSmrg  # Each line is of the form `foo.o: dependent.h',
287a8fdb4bcSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
288a8fdb4bcSmrg  # Do two passes, one to just change these to
289a8fdb4bcSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
290a8fdb4bcSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
291a8fdb4bcSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
292a8fdb4bcSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
293a8fdb4bcSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
294a8fdb4bcSmrg    sed -e 's/$/ :/' >> "$depfile"
295a8fdb4bcSmrg  rm -f "$tmpdepfile"
296a8fdb4bcSmrg  ;;
297a8fdb4bcSmrg
298a8fdb4bcSmrghp2)
299a8fdb4bcSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
300a8fdb4bcSmrg  # compilers, which have integrated preprocessors.  The correct option
301a8fdb4bcSmrg  # to use with these is +Maked; it writes dependencies to a file named
302a8fdb4bcSmrg  # 'foo.d', which lands next to the object file, wherever that
303a8fdb4bcSmrg  # happens to be.
304a8fdb4bcSmrg  # Much of this is similar to the tru64 case; see comments there.
305a8fdb4bcSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
306a8fdb4bcSmrg  test "x$dir" = "x$object" && dir=
307a8fdb4bcSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
308a8fdb4bcSmrg  if test "$libtool" = yes; then
309a8fdb4bcSmrg    tmpdepfile1=$dir$base.d
310a8fdb4bcSmrg    tmpdepfile2=$dir.libs/$base.d
311a8fdb4bcSmrg    "$@" -Wc,+Maked
312a8fdb4bcSmrg  else
313a8fdb4bcSmrg    tmpdepfile1=$dir$base.d
314a8fdb4bcSmrg    tmpdepfile2=$dir$base.d
315a8fdb4bcSmrg    "$@" +Maked
316a8fdb4bcSmrg  fi
317a8fdb4bcSmrg  stat=$?
318a8fdb4bcSmrg  if test $stat -eq 0; then :
319a8fdb4bcSmrg  else
320a8fdb4bcSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
321a8fdb4bcSmrg     exit $stat
322a8fdb4bcSmrg  fi
323a8fdb4bcSmrg
324a8fdb4bcSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
325a8fdb4bcSmrg  do
326a8fdb4bcSmrg    test -f "$tmpdepfile" && break
327a8fdb4bcSmrg  done
328a8fdb4bcSmrg  if test -f "$tmpdepfile"; then
329a8fdb4bcSmrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
330a8fdb4bcSmrg    # Add `dependent.h:' lines.
331a8fdb4bcSmrg    sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
332a8fdb4bcSmrg  else
333a8fdb4bcSmrg    echo "#dummy" > "$depfile"
334a8fdb4bcSmrg  fi
335a8fdb4bcSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
336a8fdb4bcSmrg  ;;
337a8fdb4bcSmrg
338a8fdb4bcSmrgtru64)
339a8fdb4bcSmrg   # The Tru64 compiler uses -MD to generate dependencies as a side
340a8fdb4bcSmrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
341a8fdb4bcSmrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
342a8fdb4bcSmrg   # dependencies in `foo.d' instead, so we check for that too.
343a8fdb4bcSmrg   # Subdirectories are respected.
344a8fdb4bcSmrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
345a8fdb4bcSmrg   test "x$dir" = "x$object" && dir=
346a8fdb4bcSmrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
347a8fdb4bcSmrg
348a8fdb4bcSmrg   if test "$libtool" = yes; then
349a8fdb4bcSmrg      # With Tru64 cc, shared objects can also be used to make a
350a8fdb4bcSmrg      # static library.  This mechanism is used in libtool 1.4 series to
351a8fdb4bcSmrg      # handle both shared and static libraries in a single compilation.
352a8fdb4bcSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
353a8fdb4bcSmrg      #
354a8fdb4bcSmrg      # With libtool 1.5 this exception was removed, and libtool now
355a8fdb4bcSmrg      # generates 2 separate objects for the 2 libraries.  These two
356a8fdb4bcSmrg      # compilations output dependencies in $dir.libs/$base.o.d and
357a8fdb4bcSmrg      # in $dir$base.o.d.  We have to check for both files, because
358a8fdb4bcSmrg      # one of the two compilations can be disabled.  We should prefer
359a8fdb4bcSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
360a8fdb4bcSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
361a8fdb4bcSmrg      # the former would cause a distcleancheck panic.
362a8fdb4bcSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
363a8fdb4bcSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
364a8fdb4bcSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
365a8fdb4bcSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
366a8fdb4bcSmrg      "$@" -Wc,-MD
367a8fdb4bcSmrg   else
368a8fdb4bcSmrg      tmpdepfile1=$dir$base.o.d
369a8fdb4bcSmrg      tmpdepfile2=$dir$base.d
370a8fdb4bcSmrg      tmpdepfile3=$dir$base.d
371a8fdb4bcSmrg      tmpdepfile4=$dir$base.d
372a8fdb4bcSmrg      "$@" -MD
373a8fdb4bcSmrg   fi
374a8fdb4bcSmrg
375a8fdb4bcSmrg   stat=$?
376a8fdb4bcSmrg   if test $stat -eq 0; then :
377a8fdb4bcSmrg   else
378a8fdb4bcSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
379a8fdb4bcSmrg      exit $stat
380a8fdb4bcSmrg   fi
381a8fdb4bcSmrg
382a8fdb4bcSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
383a8fdb4bcSmrg   do
384a8fdb4bcSmrg     test -f "$tmpdepfile" && break
385a8fdb4bcSmrg   done
386a8fdb4bcSmrg   if test -f "$tmpdepfile"; then
387a8fdb4bcSmrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
388a8fdb4bcSmrg      # That's a tab and a space in the [].
389a8fdb4bcSmrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
390a8fdb4bcSmrg   else
391a8fdb4bcSmrg      echo "#dummy" > "$depfile"
392a8fdb4bcSmrg   fi
393a8fdb4bcSmrg   rm -f "$tmpdepfile"
394a8fdb4bcSmrg   ;;
395a8fdb4bcSmrg
396a8fdb4bcSmrg#nosideeffect)
397a8fdb4bcSmrg  # This comment above is used by automake to tell side-effect
398a8fdb4bcSmrg  # dependency tracking mechanisms from slower ones.
399a8fdb4bcSmrg
400a8fdb4bcSmrgdashmstdout)
401a8fdb4bcSmrg  # Important note: in order to support this mode, a compiler *must*
402a8fdb4bcSmrg  # always write the preprocessed file to stdout, regardless of -o.
403a8fdb4bcSmrg  "$@" || exit $?
404a8fdb4bcSmrg
405a8fdb4bcSmrg  # Remove the call to Libtool.
406a8fdb4bcSmrg  if test "$libtool" = yes; then
407a8fdb4bcSmrg    while test $1 != '--mode=compile'; do
408a8fdb4bcSmrg      shift
409a8fdb4bcSmrg    done
410a8fdb4bcSmrg    shift
411a8fdb4bcSmrg  fi
412a8fdb4bcSmrg
413a8fdb4bcSmrg  # Remove `-o $object'.
414a8fdb4bcSmrg  IFS=" "
415a8fdb4bcSmrg  for arg
416a8fdb4bcSmrg  do
417a8fdb4bcSmrg    case $arg in
418a8fdb4bcSmrg    -o)
419a8fdb4bcSmrg      shift
420a8fdb4bcSmrg      ;;
421a8fdb4bcSmrg    $object)
422a8fdb4bcSmrg      shift
423a8fdb4bcSmrg      ;;
424a8fdb4bcSmrg    *)
425a8fdb4bcSmrg      set fnord "$@" "$arg"
426a8fdb4bcSmrg      shift # fnord
427a8fdb4bcSmrg      shift # $arg
428a8fdb4bcSmrg      ;;
429a8fdb4bcSmrg    esac
430a8fdb4bcSmrg  done
431a8fdb4bcSmrg
432a8fdb4bcSmrg  test -z "$dashmflag" && dashmflag=-M
433a8fdb4bcSmrg  # Require at least two characters before searching for `:'
434a8fdb4bcSmrg  # in the target name.  This is to cope with DOS-style filenames:
435a8fdb4bcSmrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
436a8fdb4bcSmrg  "$@" $dashmflag |
437a8fdb4bcSmrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
438a8fdb4bcSmrg  rm -f "$depfile"
439a8fdb4bcSmrg  cat < "$tmpdepfile" > "$depfile"
440a8fdb4bcSmrg  tr ' ' '
441a8fdb4bcSmrg' < "$tmpdepfile" | \
442a8fdb4bcSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
443a8fdb4bcSmrg## correctly.  Breaking it into two sed invocations is a workaround.
444a8fdb4bcSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
445a8fdb4bcSmrg  rm -f "$tmpdepfile"
446a8fdb4bcSmrg  ;;
447a8fdb4bcSmrg
448a8fdb4bcSmrgdashXmstdout)
449a8fdb4bcSmrg  # This case only exists to satisfy depend.m4.  It is never actually
450a8fdb4bcSmrg  # run, as this mode is specially recognized in the preamble.
451a8fdb4bcSmrg  exit 1
452a8fdb4bcSmrg  ;;
453a8fdb4bcSmrg
454a8fdb4bcSmrgmakedepend)
455a8fdb4bcSmrg  "$@" || exit $?
456a8fdb4bcSmrg  # Remove any Libtool call
457a8fdb4bcSmrg  if test "$libtool" = yes; then
458a8fdb4bcSmrg    while test $1 != '--mode=compile'; do
459a8fdb4bcSmrg      shift
460a8fdb4bcSmrg    done
461a8fdb4bcSmrg    shift
462a8fdb4bcSmrg  fi
463a8fdb4bcSmrg  # X makedepend
464a8fdb4bcSmrg  shift
465a8fdb4bcSmrg  cleared=no
466a8fdb4bcSmrg  for arg in "$@"; do
467a8fdb4bcSmrg    case $cleared in
468a8fdb4bcSmrg    no)
469a8fdb4bcSmrg      set ""; shift
470a8fdb4bcSmrg      cleared=yes ;;
471a8fdb4bcSmrg    esac
472a8fdb4bcSmrg    case "$arg" in
473a8fdb4bcSmrg    -D*|-I*)
474a8fdb4bcSmrg      set fnord "$@" "$arg"; shift ;;
475a8fdb4bcSmrg    # Strip any option that makedepend may not understand.  Remove
476a8fdb4bcSmrg    # the object too, otherwise makedepend will parse it as a source file.
477a8fdb4bcSmrg    -*|$object)
478a8fdb4bcSmrg      ;;
479a8fdb4bcSmrg    *)
480a8fdb4bcSmrg      set fnord "$@" "$arg"; shift ;;
481a8fdb4bcSmrg    esac
482a8fdb4bcSmrg  done
483a8fdb4bcSmrg  obj_suffix="`echo $object | sed 's/^.*\././'`"
484a8fdb4bcSmrg  touch "$tmpdepfile"
485a8fdb4bcSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
486a8fdb4bcSmrg  rm -f "$depfile"
487a8fdb4bcSmrg  cat < "$tmpdepfile" > "$depfile"
488a8fdb4bcSmrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
489a8fdb4bcSmrg' | \
490a8fdb4bcSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
491a8fdb4bcSmrg## correctly.  Breaking it into two sed invocations is a workaround.
492a8fdb4bcSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
493a8fdb4bcSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
494a8fdb4bcSmrg  ;;
495a8fdb4bcSmrg
496a8fdb4bcSmrgcpp)
497a8fdb4bcSmrg  # Important note: in order to support this mode, a compiler *must*
498a8fdb4bcSmrg  # always write the preprocessed file to stdout.
499a8fdb4bcSmrg  "$@" || exit $?
500a8fdb4bcSmrg
501a8fdb4bcSmrg  # Remove the call to Libtool.
502a8fdb4bcSmrg  if test "$libtool" = yes; then
503a8fdb4bcSmrg    while test $1 != '--mode=compile'; do
504a8fdb4bcSmrg      shift
505a8fdb4bcSmrg    done
506a8fdb4bcSmrg    shift
507a8fdb4bcSmrg  fi
508a8fdb4bcSmrg
509a8fdb4bcSmrg  # Remove `-o $object'.
510a8fdb4bcSmrg  IFS=" "
511a8fdb4bcSmrg  for arg
512a8fdb4bcSmrg  do
513a8fdb4bcSmrg    case $arg in
514a8fdb4bcSmrg    -o)
515a8fdb4bcSmrg      shift
516a8fdb4bcSmrg      ;;
517a8fdb4bcSmrg    $object)
518a8fdb4bcSmrg      shift
519a8fdb4bcSmrg      ;;
520a8fdb4bcSmrg    *)
521a8fdb4bcSmrg      set fnord "$@" "$arg"
522a8fdb4bcSmrg      shift # fnord
523a8fdb4bcSmrg      shift # $arg
524a8fdb4bcSmrg      ;;
525a8fdb4bcSmrg    esac
526a8fdb4bcSmrg  done
527a8fdb4bcSmrg
528a8fdb4bcSmrg  "$@" -E |
529a8fdb4bcSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
530a8fdb4bcSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
531a8fdb4bcSmrg    sed '$ s: \\$::' > "$tmpdepfile"
532a8fdb4bcSmrg  rm -f "$depfile"
533a8fdb4bcSmrg  echo "$object : \\" > "$depfile"
534a8fdb4bcSmrg  cat < "$tmpdepfile" >> "$depfile"
535a8fdb4bcSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
536a8fdb4bcSmrg  rm -f "$tmpdepfile"
537a8fdb4bcSmrg  ;;
538a8fdb4bcSmrg
539a8fdb4bcSmrgmsvisualcpp)
540a8fdb4bcSmrg  # Important note: in order to support this mode, a compiler *must*
541a8fdb4bcSmrg  # always write the preprocessed file to stdout, regardless of -o,
542a8fdb4bcSmrg  # because we must use -o when running libtool.
543a8fdb4bcSmrg  "$@" || exit $?
544a8fdb4bcSmrg  IFS=" "
545a8fdb4bcSmrg  for arg
546a8fdb4bcSmrg  do
547a8fdb4bcSmrg    case "$arg" in
548a8fdb4bcSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
549a8fdb4bcSmrg	set fnord "$@"
550a8fdb4bcSmrg	shift
551a8fdb4bcSmrg	shift
552a8fdb4bcSmrg	;;
553a8fdb4bcSmrg    *)
554a8fdb4bcSmrg	set fnord "$@" "$arg"
555a8fdb4bcSmrg	shift
556a8fdb4bcSmrg	shift
557a8fdb4bcSmrg	;;
558a8fdb4bcSmrg    esac
559a8fdb4bcSmrg  done
560a8fdb4bcSmrg  "$@" -E |
561a8fdb4bcSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
562a8fdb4bcSmrg  rm -f "$depfile"
563a8fdb4bcSmrg  echo "$object : \\" > "$depfile"
564a8fdb4bcSmrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
565a8fdb4bcSmrg  echo "	" >> "$depfile"
566a8fdb4bcSmrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
567a8fdb4bcSmrg  rm -f "$tmpdepfile"
568a8fdb4bcSmrg  ;;
569a8fdb4bcSmrg
570a8fdb4bcSmrgnone)
571a8fdb4bcSmrg  exec "$@"
572a8fdb4bcSmrg  ;;
573a8fdb4bcSmrg
574a8fdb4bcSmrg*)
575a8fdb4bcSmrg  echo "Unknown depmode $depmode" 1>&2
576a8fdb4bcSmrg  exit 1
577a8fdb4bcSmrg  ;;
578a8fdb4bcSmrgesac
579a8fdb4bcSmrg
580a8fdb4bcSmrgexit 0
581a8fdb4bcSmrg
582a8fdb4bcSmrg# Local Variables:
583a8fdb4bcSmrg# mode: shell-script
584a8fdb4bcSmrg# sh-indentation: 2
585a8fdb4bcSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
586a8fdb4bcSmrg# time-stamp-start: "scriptversion="
587a8fdb4bcSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
588a8fdb4bcSmrg# time-stamp-end: "$"
589a8fdb4bcSmrg# End:
590