depcomp revision 126a8a12
1126a8a12Smrg#! /bin/sh
2126a8a12Smrg# depcomp - compile a program generating dependencies as side-effects
3126a8a12Smrg
4126a8a12Smrgscriptversion=2006-10-15.18
5126a8a12Smrg
6126a8a12Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
7126a8a12Smrg# Foundation, Inc.
8126a8a12Smrg
9126a8a12Smrg# This program is free software; you can redistribute it and/or modify
10126a8a12Smrg# it under the terms of the GNU General Public License as published by
11126a8a12Smrg# the Free Software Foundation; either version 2, or (at your option)
12126a8a12Smrg# any later version.
13126a8a12Smrg
14126a8a12Smrg# This program is distributed in the hope that it will be useful,
15126a8a12Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16126a8a12Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17126a8a12Smrg# GNU General Public License for more details.
18126a8a12Smrg
19126a8a12Smrg# You should have received a copy of the GNU General Public License
20126a8a12Smrg# along with this program; if not, write to the Free Software
21126a8a12Smrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22126a8a12Smrg# 02110-1301, USA.
23126a8a12Smrg
24126a8a12Smrg# As a special exception to the GNU General Public License, if you
25126a8a12Smrg# distribute this file as part of a program that contains a
26126a8a12Smrg# configuration script generated by Autoconf, you may include it under
27126a8a12Smrg# the same distribution terms that you use for the rest of that program.
28126a8a12Smrg
29126a8a12Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
30126a8a12Smrg
31126a8a12Smrgcase $1 in
32126a8a12Smrg  '')
33126a8a12Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
34126a8a12Smrg     exit 1;
35126a8a12Smrg     ;;
36126a8a12Smrg  -h | --h*)
37126a8a12Smrg    cat <<\EOF
38126a8a12SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
39126a8a12Smrg
40126a8a12SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
41126a8a12Smrgas side-effects.
42126a8a12Smrg
43126a8a12SmrgEnvironment variables:
44126a8a12Smrg  depmode     Dependency tracking mode.
45126a8a12Smrg  source      Source file read by `PROGRAMS ARGS'.
46126a8a12Smrg  object      Object file output by `PROGRAMS ARGS'.
47126a8a12Smrg  DEPDIR      directory where to store dependencies.
48126a8a12Smrg  depfile     Dependency file to output.
49126a8a12Smrg  tmpdepfile  Temporary file to use when outputing dependencies.
50126a8a12Smrg  libtool     Whether libtool is used (yes/no).
51126a8a12Smrg
52126a8a12SmrgReport bugs to <bug-automake@gnu.org>.
53126a8a12SmrgEOF
54126a8a12Smrg    exit $?
55126a8a12Smrg    ;;
56126a8a12Smrg  -v | --v*)
57126a8a12Smrg    echo "depcomp $scriptversion"
58126a8a12Smrg    exit $?
59126a8a12Smrg    ;;
60126a8a12Smrgesac
61126a8a12Smrg
62126a8a12Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
63126a8a12Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
64126a8a12Smrg  exit 1
65126a8a12Smrgfi
66126a8a12Smrg
67126a8a12Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
68126a8a12Smrgdepfile=${depfile-`echo "$object" |
69126a8a12Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
70126a8a12Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
71126a8a12Smrg
72126a8a12Smrgrm -f "$tmpdepfile"
73126a8a12Smrg
74126a8a12Smrg# Some modes work just like other modes, but use different flags.  We
75126a8a12Smrg# parameterize here, but still list the modes in the big case below,
76126a8a12Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
77126a8a12Smrg# here, because this file can only contain one case statement.
78126a8a12Smrgif test "$depmode" = hp; then
79126a8a12Smrg  # HP compiler uses -M and no extra arg.
80126a8a12Smrg  gccflag=-M
81126a8a12Smrg  depmode=gcc
82126a8a12Smrgfi
83126a8a12Smrg
84126a8a12Smrgif test "$depmode" = dashXmstdout; then
85126a8a12Smrg   # This is just like dashmstdout with a different argument.
86126a8a12Smrg   dashmflag=-xM
87126a8a12Smrg   depmode=dashmstdout
88126a8a12Smrgfi
89126a8a12Smrg
90126a8a12Smrgcase "$depmode" in
91126a8a12Smrggcc3)
92126a8a12Smrg## gcc 3 implements dependency tracking that does exactly what
93126a8a12Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
94126a8a12Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
95126a8a12Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
96126a8a12Smrg## the command line argument order; so add the flags where they
97126a8a12Smrg## appear in depend2.am.  Note that the slowdown incurred here
98126a8a12Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
99126a8a12Smrg  for arg
100126a8a12Smrg  do
101126a8a12Smrg    case $arg in
102126a8a12Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
103126a8a12Smrg    *)  set fnord "$@" "$arg" ;;
104126a8a12Smrg    esac
105126a8a12Smrg    shift # fnord
106126a8a12Smrg    shift # $arg
107126a8a12Smrg  done
108126a8a12Smrg  "$@"
109126a8a12Smrg  stat=$?
110126a8a12Smrg  if test $stat -eq 0; then :
111126a8a12Smrg  else
112126a8a12Smrg    rm -f "$tmpdepfile"
113126a8a12Smrg    exit $stat
114126a8a12Smrg  fi
115126a8a12Smrg  mv "$tmpdepfile" "$depfile"
116126a8a12Smrg  ;;
117126a8a12Smrg
118126a8a12Smrggcc)
119126a8a12Smrg## There are various ways to get dependency output from gcc.  Here's
120126a8a12Smrg## why we pick this rather obscure method:
121126a8a12Smrg## - Don't want to use -MD because we'd like the dependencies to end
122126a8a12Smrg##   up in a subdir.  Having to rename by hand is ugly.
123126a8a12Smrg##   (We might end up doing this anyway to support other compilers.)
124126a8a12Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
125126a8a12Smrg##   -MM, not -M (despite what the docs say).
126126a8a12Smrg## - Using -M directly means running the compiler twice (even worse
127126a8a12Smrg##   than renaming).
128126a8a12Smrg  if test -z "$gccflag"; then
129126a8a12Smrg    gccflag=-MD,
130126a8a12Smrg  fi
131126a8a12Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
132126a8a12Smrg  stat=$?
133126a8a12Smrg  if test $stat -eq 0; then :
134126a8a12Smrg  else
135126a8a12Smrg    rm -f "$tmpdepfile"
136126a8a12Smrg    exit $stat
137126a8a12Smrg  fi
138126a8a12Smrg  rm -f "$depfile"
139126a8a12Smrg  echo "$object : \\" > "$depfile"
140126a8a12Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
141126a8a12Smrg## The second -e expression handles DOS-style file names with drive letters.
142126a8a12Smrg  sed -e 's/^[^:]*: / /' \
143126a8a12Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
144126a8a12Smrg## This next piece of magic avoids the `deleted header file' problem.
145126a8a12Smrg## The problem is that when a header file which appears in a .P file
146126a8a12Smrg## is deleted, the dependency causes make to die (because there is
147126a8a12Smrg## typically no way to rebuild the header).  We avoid this by adding
148126a8a12Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
149126a8a12Smrg## this for us directly.
150126a8a12Smrg  tr ' ' '
151126a8a12Smrg' < "$tmpdepfile" |
152126a8a12Smrg## Some versions of gcc put a space before the `:'.  On the theory
153126a8a12Smrg## that the space means something, we add a space to the output as
154126a8a12Smrg## well.
155126a8a12Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
156126a8a12Smrg## correctly.  Breaking it into two sed invocations is a workaround.
157126a8a12Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
158126a8a12Smrg  rm -f "$tmpdepfile"
159126a8a12Smrg  ;;
160126a8a12Smrg
161126a8a12Smrghp)
162126a8a12Smrg  # This case exists only to let depend.m4 do its work.  It works by
163126a8a12Smrg  # looking at the text of this script.  This case will never be run,
164126a8a12Smrg  # since it is checked for above.
165126a8a12Smrg  exit 1
166126a8a12Smrg  ;;
167126a8a12Smrg
168126a8a12Smrgsgi)
169126a8a12Smrg  if test "$libtool" = yes; then
170126a8a12Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
171126a8a12Smrg  else
172126a8a12Smrg    "$@" -MDupdate "$tmpdepfile"
173126a8a12Smrg  fi
174126a8a12Smrg  stat=$?
175126a8a12Smrg  if test $stat -eq 0; then :
176126a8a12Smrg  else
177126a8a12Smrg    rm -f "$tmpdepfile"
178126a8a12Smrg    exit $stat
179126a8a12Smrg  fi
180126a8a12Smrg  rm -f "$depfile"
181126a8a12Smrg
182126a8a12Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
183126a8a12Smrg    echo "$object : \\" > "$depfile"
184126a8a12Smrg
185126a8a12Smrg    # Clip off the initial element (the dependent).  Don't try to be
186126a8a12Smrg    # clever and replace this with sed code, as IRIX sed won't handle
187126a8a12Smrg    # lines with more than a fixed number of characters (4096 in
188126a8a12Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
189126a8a12Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
190126a8a12Smrg    # dependency line.
191126a8a12Smrg    tr ' ' '
192126a8a12Smrg' < "$tmpdepfile" \
193126a8a12Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
194126a8a12Smrg    tr '
195126a8a12Smrg' ' ' >> $depfile
196126a8a12Smrg    echo >> $depfile
197126a8a12Smrg
198126a8a12Smrg    # The second pass generates a dummy entry for each header file.
199126a8a12Smrg    tr ' ' '
200126a8a12Smrg' < "$tmpdepfile" \
201126a8a12Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
202126a8a12Smrg   >> $depfile
203126a8a12Smrg  else
204126a8a12Smrg    # The sourcefile does not contain any dependencies, so just
205126a8a12Smrg    # store a dummy comment line, to avoid errors with the Makefile
206126a8a12Smrg    # "include basename.Plo" scheme.
207126a8a12Smrg    echo "#dummy" > "$depfile"
208126a8a12Smrg  fi
209126a8a12Smrg  rm -f "$tmpdepfile"
210126a8a12Smrg  ;;
211126a8a12Smrg
212126a8a12Smrgaix)
213126a8a12Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
214126a8a12Smrg  # in a .u file.  In older versions, this file always lives in the
215126a8a12Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
216126a8a12Smrg  # start of each line; $object doesn't have directory information.
217126a8a12Smrg  # Version 6 uses the directory in both cases.
218126a8a12Smrg  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
219126a8a12Smrg  tmpdepfile="$stripped.u"
220126a8a12Smrg  if test "$libtool" = yes; then
221126a8a12Smrg    "$@" -Wc,-M
222126a8a12Smrg  else
223126a8a12Smrg    "$@" -M
224126a8a12Smrg  fi
225126a8a12Smrg  stat=$?
226126a8a12Smrg
227126a8a12Smrg  if test -f "$tmpdepfile"; then :
228126a8a12Smrg  else
229126a8a12Smrg    stripped=`echo "$stripped" | sed 's,^.*/,,'`
230126a8a12Smrg    tmpdepfile="$stripped.u"
231126a8a12Smrg  fi
232126a8a12Smrg
233126a8a12Smrg  if test $stat -eq 0; then :
234126a8a12Smrg  else
235126a8a12Smrg    rm -f "$tmpdepfile"
236126a8a12Smrg    exit $stat
237126a8a12Smrg  fi
238126a8a12Smrg
239126a8a12Smrg  if test -f "$tmpdepfile"; then
240126a8a12Smrg    outname="$stripped.o"
241126a8a12Smrg    # Each line is of the form `foo.o: dependent.h'.
242126a8a12Smrg    # Do two passes, one to just change these to
243126a8a12Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
244126a8a12Smrg    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
245126a8a12Smrg    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
246126a8a12Smrg  else
247126a8a12Smrg    # The sourcefile does not contain any dependencies, so just
248126a8a12Smrg    # store a dummy comment line, to avoid errors with the Makefile
249126a8a12Smrg    # "include basename.Plo" scheme.
250126a8a12Smrg    echo "#dummy" > "$depfile"
251126a8a12Smrg  fi
252126a8a12Smrg  rm -f "$tmpdepfile"
253126a8a12Smrg  ;;
254126a8a12Smrg
255126a8a12Smrgicc)
256126a8a12Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
257126a8a12Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
258126a8a12Smrg  # ICC 7.0 will fill foo.d with something like
259126a8a12Smrg  #    foo.o: sub/foo.c
260126a8a12Smrg  #    foo.o: sub/foo.h
261126a8a12Smrg  # which is wrong.  We want:
262126a8a12Smrg  #    sub/foo.o: sub/foo.c
263126a8a12Smrg  #    sub/foo.o: sub/foo.h
264126a8a12Smrg  #    sub/foo.c:
265126a8a12Smrg  #    sub/foo.h:
266126a8a12Smrg  # ICC 7.1 will output
267126a8a12Smrg  #    foo.o: sub/foo.c sub/foo.h
268126a8a12Smrg  # and will wrap long lines using \ :
269126a8a12Smrg  #    foo.o: sub/foo.c ... \
270126a8a12Smrg  #     sub/foo.h ... \
271126a8a12Smrg  #     ...
272126a8a12Smrg
273126a8a12Smrg  "$@" -MD -MF "$tmpdepfile"
274126a8a12Smrg  stat=$?
275126a8a12Smrg  if test $stat -eq 0; then :
276126a8a12Smrg  else
277126a8a12Smrg    rm -f "$tmpdepfile"
278126a8a12Smrg    exit $stat
279126a8a12Smrg  fi
280126a8a12Smrg  rm -f "$depfile"
281126a8a12Smrg  # Each line is of the form `foo.o: dependent.h',
282126a8a12Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
283126a8a12Smrg  # Do two passes, one to just change these to
284126a8a12Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
285126a8a12Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
286126a8a12Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
287126a8a12Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
288126a8a12Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
289126a8a12Smrg    sed -e 's/$/ :/' >> "$depfile"
290126a8a12Smrg  rm -f "$tmpdepfile"
291126a8a12Smrg  ;;
292126a8a12Smrg
293126a8a12Smrghp2)
294126a8a12Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
295126a8a12Smrg  # compilers, which have integrated preprocessors.  The correct option
296126a8a12Smrg  # to use with these is +Maked; it writes dependencies to a file named
297126a8a12Smrg  # 'foo.d', which lands next to the object file, wherever that
298126a8a12Smrg  # happens to be.
299126a8a12Smrg  # Much of this is similar to the tru64 case; see comments there.
300126a8a12Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
301126a8a12Smrg  test "x$dir" = "x$object" && dir=
302126a8a12Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
303126a8a12Smrg  if test "$libtool" = yes; then
304126a8a12Smrg    tmpdepfile1=$dir$base.d
305126a8a12Smrg    tmpdepfile2=$dir.libs/$base.d
306126a8a12Smrg    "$@" -Wc,+Maked
307126a8a12Smrg  else
308126a8a12Smrg    tmpdepfile1=$dir$base.d
309126a8a12Smrg    tmpdepfile2=$dir$base.d
310126a8a12Smrg    "$@" +Maked
311126a8a12Smrg  fi
312126a8a12Smrg  stat=$?
313126a8a12Smrg  if test $stat -eq 0; then :
314126a8a12Smrg  else
315126a8a12Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
316126a8a12Smrg     exit $stat
317126a8a12Smrg  fi
318126a8a12Smrg
319126a8a12Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
320126a8a12Smrg  do
321126a8a12Smrg    test -f "$tmpdepfile" && break
322126a8a12Smrg  done
323126a8a12Smrg  if test -f "$tmpdepfile"; then
324126a8a12Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
325126a8a12Smrg    # Add `dependent.h:' lines.
326126a8a12Smrg    sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
327126a8a12Smrg  else
328126a8a12Smrg    echo "#dummy" > "$depfile"
329126a8a12Smrg  fi
330126a8a12Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
331126a8a12Smrg  ;;
332126a8a12Smrg
333126a8a12Smrgtru64)
334126a8a12Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
335126a8a12Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
336126a8a12Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
337126a8a12Smrg   # dependencies in `foo.d' instead, so we check for that too.
338126a8a12Smrg   # Subdirectories are respected.
339126a8a12Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
340126a8a12Smrg   test "x$dir" = "x$object" && dir=
341126a8a12Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
342126a8a12Smrg
343126a8a12Smrg   if test "$libtool" = yes; then
344126a8a12Smrg      # With Tru64 cc, shared objects can also be used to make a
345126a8a12Smrg      # static library.  This mechanism is used in libtool 1.4 series to
346126a8a12Smrg      # handle both shared and static libraries in a single compilation.
347126a8a12Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
348126a8a12Smrg      #
349126a8a12Smrg      # With libtool 1.5 this exception was removed, and libtool now
350126a8a12Smrg      # generates 2 separate objects for the 2 libraries.  These two
351126a8a12Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
352126a8a12Smrg      # in $dir$base.o.d.  We have to check for both files, because
353126a8a12Smrg      # one of the two compilations can be disabled.  We should prefer
354126a8a12Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
355126a8a12Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
356126a8a12Smrg      # the former would cause a distcleancheck panic.
357126a8a12Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
358126a8a12Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
359126a8a12Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
360126a8a12Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
361126a8a12Smrg      "$@" -Wc,-MD
362126a8a12Smrg   else
363126a8a12Smrg      tmpdepfile1=$dir$base.o.d
364126a8a12Smrg      tmpdepfile2=$dir$base.d
365126a8a12Smrg      tmpdepfile3=$dir$base.d
366126a8a12Smrg      tmpdepfile4=$dir$base.d
367126a8a12Smrg      "$@" -MD
368126a8a12Smrg   fi
369126a8a12Smrg
370126a8a12Smrg   stat=$?
371126a8a12Smrg   if test $stat -eq 0; then :
372126a8a12Smrg   else
373126a8a12Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
374126a8a12Smrg      exit $stat
375126a8a12Smrg   fi
376126a8a12Smrg
377126a8a12Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
378126a8a12Smrg   do
379126a8a12Smrg     test -f "$tmpdepfile" && break
380126a8a12Smrg   done
381126a8a12Smrg   if test -f "$tmpdepfile"; then
382126a8a12Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
383126a8a12Smrg      # That's a tab and a space in the [].
384126a8a12Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
385126a8a12Smrg   else
386126a8a12Smrg      echo "#dummy" > "$depfile"
387126a8a12Smrg   fi
388126a8a12Smrg   rm -f "$tmpdepfile"
389126a8a12Smrg   ;;
390126a8a12Smrg
391126a8a12Smrg#nosideeffect)
392126a8a12Smrg  # This comment above is used by automake to tell side-effect
393126a8a12Smrg  # dependency tracking mechanisms from slower ones.
394126a8a12Smrg
395126a8a12Smrgdashmstdout)
396126a8a12Smrg  # Important note: in order to support this mode, a compiler *must*
397126a8a12Smrg  # always write the preprocessed file to stdout, regardless of -o.
398126a8a12Smrg  "$@" || exit $?
399126a8a12Smrg
400126a8a12Smrg  # Remove the call to Libtool.
401126a8a12Smrg  if test "$libtool" = yes; then
402126a8a12Smrg    while test $1 != '--mode=compile'; do
403126a8a12Smrg      shift
404126a8a12Smrg    done
405126a8a12Smrg    shift
406126a8a12Smrg  fi
407126a8a12Smrg
408126a8a12Smrg  # Remove `-o $object'.
409126a8a12Smrg  IFS=" "
410126a8a12Smrg  for arg
411126a8a12Smrg  do
412126a8a12Smrg    case $arg in
413126a8a12Smrg    -o)
414126a8a12Smrg      shift
415126a8a12Smrg      ;;
416126a8a12Smrg    $object)
417126a8a12Smrg      shift
418126a8a12Smrg      ;;
419126a8a12Smrg    *)
420126a8a12Smrg      set fnord "$@" "$arg"
421126a8a12Smrg      shift # fnord
422126a8a12Smrg      shift # $arg
423126a8a12Smrg      ;;
424126a8a12Smrg    esac
425126a8a12Smrg  done
426126a8a12Smrg
427126a8a12Smrg  test -z "$dashmflag" && dashmflag=-M
428126a8a12Smrg  # Require at least two characters before searching for `:'
429126a8a12Smrg  # in the target name.  This is to cope with DOS-style filenames:
430126a8a12Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
431126a8a12Smrg  "$@" $dashmflag |
432126a8a12Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
433126a8a12Smrg  rm -f "$depfile"
434126a8a12Smrg  cat < "$tmpdepfile" > "$depfile"
435126a8a12Smrg  tr ' ' '
436126a8a12Smrg' < "$tmpdepfile" | \
437126a8a12Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
438126a8a12Smrg## correctly.  Breaking it into two sed invocations is a workaround.
439126a8a12Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
440126a8a12Smrg  rm -f "$tmpdepfile"
441126a8a12Smrg  ;;
442126a8a12Smrg
443126a8a12SmrgdashXmstdout)
444126a8a12Smrg  # This case only exists to satisfy depend.m4.  It is never actually
445126a8a12Smrg  # run, as this mode is specially recognized in the preamble.
446126a8a12Smrg  exit 1
447126a8a12Smrg  ;;
448126a8a12Smrg
449126a8a12Smrgmakedepend)
450126a8a12Smrg  "$@" || exit $?
451126a8a12Smrg  # Remove any Libtool call
452126a8a12Smrg  if test "$libtool" = yes; then
453126a8a12Smrg    while test $1 != '--mode=compile'; do
454126a8a12Smrg      shift
455126a8a12Smrg    done
456126a8a12Smrg    shift
457126a8a12Smrg  fi
458126a8a12Smrg  # X makedepend
459126a8a12Smrg  shift
460126a8a12Smrg  cleared=no
461126a8a12Smrg  for arg in "$@"; do
462126a8a12Smrg    case $cleared in
463126a8a12Smrg    no)
464126a8a12Smrg      set ""; shift
465126a8a12Smrg      cleared=yes ;;
466126a8a12Smrg    esac
467126a8a12Smrg    case "$arg" in
468126a8a12Smrg    -D*|-I*)
469126a8a12Smrg      set fnord "$@" "$arg"; shift ;;
470126a8a12Smrg    # Strip any option that makedepend may not understand.  Remove
471126a8a12Smrg    # the object too, otherwise makedepend will parse it as a source file.
472126a8a12Smrg    -*|$object)
473126a8a12Smrg      ;;
474126a8a12Smrg    *)
475126a8a12Smrg      set fnord "$@" "$arg"; shift ;;
476126a8a12Smrg    esac
477126a8a12Smrg  done
478126a8a12Smrg  obj_suffix="`echo $object | sed 's/^.*\././'`"
479126a8a12Smrg  touch "$tmpdepfile"
480126a8a12Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
481126a8a12Smrg  rm -f "$depfile"
482126a8a12Smrg  cat < "$tmpdepfile" > "$depfile"
483126a8a12Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
484126a8a12Smrg' | \
485126a8a12Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
486126a8a12Smrg## correctly.  Breaking it into two sed invocations is a workaround.
487126a8a12Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
488126a8a12Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
489126a8a12Smrg  ;;
490126a8a12Smrg
491126a8a12Smrgcpp)
492126a8a12Smrg  # Important note: in order to support this mode, a compiler *must*
493126a8a12Smrg  # always write the preprocessed file to stdout.
494126a8a12Smrg  "$@" || exit $?
495126a8a12Smrg
496126a8a12Smrg  # Remove the call to Libtool.
497126a8a12Smrg  if test "$libtool" = yes; then
498126a8a12Smrg    while test $1 != '--mode=compile'; do
499126a8a12Smrg      shift
500126a8a12Smrg    done
501126a8a12Smrg    shift
502126a8a12Smrg  fi
503126a8a12Smrg
504126a8a12Smrg  # Remove `-o $object'.
505126a8a12Smrg  IFS=" "
506126a8a12Smrg  for arg
507126a8a12Smrg  do
508126a8a12Smrg    case $arg in
509126a8a12Smrg    -o)
510126a8a12Smrg      shift
511126a8a12Smrg      ;;
512126a8a12Smrg    $object)
513126a8a12Smrg      shift
514126a8a12Smrg      ;;
515126a8a12Smrg    *)
516126a8a12Smrg      set fnord "$@" "$arg"
517126a8a12Smrg      shift # fnord
518126a8a12Smrg      shift # $arg
519126a8a12Smrg      ;;
520126a8a12Smrg    esac
521126a8a12Smrg  done
522126a8a12Smrg
523126a8a12Smrg  "$@" -E |
524126a8a12Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
525126a8a12Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
526126a8a12Smrg    sed '$ s: \\$::' > "$tmpdepfile"
527126a8a12Smrg  rm -f "$depfile"
528126a8a12Smrg  echo "$object : \\" > "$depfile"
529126a8a12Smrg  cat < "$tmpdepfile" >> "$depfile"
530126a8a12Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
531126a8a12Smrg  rm -f "$tmpdepfile"
532126a8a12Smrg  ;;
533126a8a12Smrg
534126a8a12Smrgmsvisualcpp)
535126a8a12Smrg  # Important note: in order to support this mode, a compiler *must*
536126a8a12Smrg  # always write the preprocessed file to stdout, regardless of -o,
537126a8a12Smrg  # because we must use -o when running libtool.
538126a8a12Smrg  "$@" || exit $?
539126a8a12Smrg  IFS=" "
540126a8a12Smrg  for arg
541126a8a12Smrg  do
542126a8a12Smrg    case "$arg" in
543126a8a12Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
544126a8a12Smrg	set fnord "$@"
545126a8a12Smrg	shift
546126a8a12Smrg	shift
547126a8a12Smrg	;;
548126a8a12Smrg    *)
549126a8a12Smrg	set fnord "$@" "$arg"
550126a8a12Smrg	shift
551126a8a12Smrg	shift
552126a8a12Smrg	;;
553126a8a12Smrg    esac
554126a8a12Smrg  done
555126a8a12Smrg  "$@" -E |
556126a8a12Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
557126a8a12Smrg  rm -f "$depfile"
558126a8a12Smrg  echo "$object : \\" > "$depfile"
559126a8a12Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
560126a8a12Smrg  echo "	" >> "$depfile"
561126a8a12Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
562126a8a12Smrg  rm -f "$tmpdepfile"
563126a8a12Smrg  ;;
564126a8a12Smrg
565126a8a12Smrgnone)
566126a8a12Smrg  exec "$@"
567126a8a12Smrg  ;;
568126a8a12Smrg
569126a8a12Smrg*)
570126a8a12Smrg  echo "Unknown depmode $depmode" 1>&2
571126a8a12Smrg  exit 1
572126a8a12Smrg  ;;
573126a8a12Smrgesac
574126a8a12Smrg
575126a8a12Smrgexit 0
576126a8a12Smrg
577126a8a12Smrg# Local Variables:
578126a8a12Smrg# mode: shell-script
579126a8a12Smrg# sh-indentation: 2
580126a8a12Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
581126a8a12Smrg# time-stamp-start: "scriptversion="
582126a8a12Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
583126a8a12Smrg# time-stamp-end: "$"
584126a8a12Smrg# End:
585