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