1706f2543Smrg#! /bin/sh
2706f2543Smrg# depcomp - compile a program generating dependencies as side-effects
3706f2543Smrg
4706f2543Smrgscriptversion=2006-10-15.18
5706f2543Smrg
6706f2543Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
7706f2543Smrg# Foundation, Inc.
8706f2543Smrg
9706f2543Smrg# This program is free software; you can redistribute it and/or modify
10706f2543Smrg# it under the terms of the GNU General Public License as published by
11706f2543Smrg# the Free Software Foundation; either version 2, or (at your option)
12706f2543Smrg# any later version.
13706f2543Smrg
14706f2543Smrg# This program is distributed in the hope that it will be useful,
15706f2543Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16706f2543Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17706f2543Smrg# GNU General Public License for more details.
18706f2543Smrg
19706f2543Smrg# You should have received a copy of the GNU General Public License
20706f2543Smrg# along with this program; if not, write to the Free Software
21706f2543Smrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22706f2543Smrg# 02110-1301, USA.
23706f2543Smrg
24706f2543Smrg# As a special exception to the GNU General Public License, if you
25706f2543Smrg# distribute this file as part of a program that contains a
26706f2543Smrg# configuration script generated by Autoconf, you may include it under
27706f2543Smrg# the same distribution terms that you use for the rest of that program.
28706f2543Smrg
29706f2543Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
30706f2543Smrg
31706f2543Smrgcase $1 in
32706f2543Smrg  '')
33706f2543Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
34706f2543Smrg     exit 1;
35706f2543Smrg     ;;
36706f2543Smrg  -h | --h*)
37706f2543Smrg    cat <<\EOF
38706f2543SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
39706f2543Smrg
40706f2543SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
41706f2543Smrgas side-effects.
42706f2543Smrg
43706f2543SmrgEnvironment variables:
44706f2543Smrg  depmode     Dependency tracking mode.
45706f2543Smrg  source      Source file read by `PROGRAMS ARGS'.
46706f2543Smrg  object      Object file output by `PROGRAMS ARGS'.
47706f2543Smrg  DEPDIR      directory where to store dependencies.
48706f2543Smrg  depfile     Dependency file to output.
49706f2543Smrg  tmpdepfile  Temporary file to use when outputing dependencies.
50706f2543Smrg  libtool     Whether libtool is used (yes/no).
51706f2543Smrg
52706f2543SmrgReport bugs to <bug-automake@gnu.org>.
53706f2543SmrgEOF
54706f2543Smrg    exit $?
55706f2543Smrg    ;;
56706f2543Smrg  -v | --v*)
57706f2543Smrg    echo "depcomp $scriptversion"
58706f2543Smrg    exit $?
59706f2543Smrg    ;;
60706f2543Smrgesac
61706f2543Smrg
62706f2543Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
63706f2543Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
64706f2543Smrg  exit 1
65706f2543Smrgfi
66706f2543Smrg
67706f2543Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
68706f2543Smrgdepfile=${depfile-`echo "$object" |
69706f2543Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
70706f2543Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
71706f2543Smrg
72706f2543Smrgrm -f "$tmpdepfile"
73706f2543Smrg
74706f2543Smrg# Some modes work just like other modes, but use different flags.  We
75706f2543Smrg# parameterize here, but still list the modes in the big case below,
76706f2543Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
77706f2543Smrg# here, because this file can only contain one case statement.
78706f2543Smrgif test "$depmode" = hp; then
79706f2543Smrg  # HP compiler uses -M and no extra arg.
80706f2543Smrg  gccflag=-M
81706f2543Smrg  depmode=gcc
82706f2543Smrgfi
83706f2543Smrg
84706f2543Smrgif test "$depmode" = dashXmstdout; then
85706f2543Smrg   # This is just like dashmstdout with a different argument.
86706f2543Smrg   dashmflag=-xM
87706f2543Smrg   depmode=dashmstdout
88706f2543Smrgfi
89706f2543Smrg
90706f2543Smrgcase "$depmode" in
91706f2543Smrggcc3)
92706f2543Smrg## gcc 3 implements dependency tracking that does exactly what
93706f2543Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
94706f2543Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
95706f2543Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
96706f2543Smrg## the command line argument order; so add the flags where they
97706f2543Smrg## appear in depend2.am.  Note that the slowdown incurred here
98706f2543Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
99706f2543Smrg  for arg
100706f2543Smrg  do
101706f2543Smrg    case $arg in
102706f2543Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
103706f2543Smrg    *)  set fnord "$@" "$arg" ;;
104706f2543Smrg    esac
105706f2543Smrg    shift # fnord
106706f2543Smrg    shift # $arg
107706f2543Smrg  done
108706f2543Smrg  "$@"
109706f2543Smrg  stat=$?
110706f2543Smrg  if test $stat -eq 0; then :
111706f2543Smrg  else
112706f2543Smrg    rm -f "$tmpdepfile"
113706f2543Smrg    exit $stat
114706f2543Smrg  fi
115706f2543Smrg  mv "$tmpdepfile" "$depfile"
116706f2543Smrg  ;;
117706f2543Smrg
118706f2543Smrggcc)
119706f2543Smrg## There are various ways to get dependency output from gcc.  Here's
120706f2543Smrg## why we pick this rather obscure method:
121706f2543Smrg## - Don't want to use -MD because we'd like the dependencies to end
122706f2543Smrg##   up in a subdir.  Having to rename by hand is ugly.
123706f2543Smrg##   (We might end up doing this anyway to support other compilers.)
124706f2543Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
125706f2543Smrg##   -MM, not -M (despite what the docs say).
126706f2543Smrg## - Using -M directly means running the compiler twice (even worse
127706f2543Smrg##   than renaming).
128706f2543Smrg  if test -z "$gccflag"; then
129706f2543Smrg    gccflag=-MD,
130706f2543Smrg  fi
131706f2543Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
132706f2543Smrg  stat=$?
133706f2543Smrg  if test $stat -eq 0; then :
134706f2543Smrg  else
135706f2543Smrg    rm -f "$tmpdepfile"
136706f2543Smrg    exit $stat
137706f2543Smrg  fi
138706f2543Smrg  rm -f "$depfile"
139706f2543Smrg  echo "$object : \\" > "$depfile"
140706f2543Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
141706f2543Smrg## The second -e expression handles DOS-style file names with drive letters.
142706f2543Smrg  sed -e 's/^[^:]*: / /' \
143706f2543Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
144706f2543Smrg## This next piece of magic avoids the `deleted header file' problem.
145706f2543Smrg## The problem is that when a header file which appears in a .P file
146706f2543Smrg## is deleted, the dependency causes make to die (because there is
147706f2543Smrg## typically no way to rebuild the header).  We avoid this by adding
148706f2543Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
149706f2543Smrg## this for us directly.
150706f2543Smrg  tr ' ' '
151706f2543Smrg' < "$tmpdepfile" |
152706f2543Smrg## Some versions of gcc put a space before the `:'.  On the theory
153706f2543Smrg## that the space means something, we add a space to the output as
154706f2543Smrg## well.
155706f2543Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
156706f2543Smrg## correctly.  Breaking it into two sed invocations is a workaround.
157706f2543Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
158706f2543Smrg  rm -f "$tmpdepfile"
159706f2543Smrg  ;;
160706f2543Smrg
161706f2543Smrghp)
162706f2543Smrg  # This case exists only to let depend.m4 do its work.  It works by
163706f2543Smrg  # looking at the text of this script.  This case will never be run,
164706f2543Smrg  # since it is checked for above.
165706f2543Smrg  exit 1
166706f2543Smrg  ;;
167706f2543Smrg
168706f2543Smrgsgi)
169706f2543Smrg  if test "$libtool" = yes; then
170706f2543Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
171706f2543Smrg  else
172706f2543Smrg    "$@" -MDupdate "$tmpdepfile"
173706f2543Smrg  fi
174706f2543Smrg  stat=$?
175706f2543Smrg  if test $stat -eq 0; then :
176706f2543Smrg  else
177706f2543Smrg    rm -f "$tmpdepfile"
178706f2543Smrg    exit $stat
179706f2543Smrg  fi
180706f2543Smrg  rm -f "$depfile"
181706f2543Smrg
182706f2543Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
183706f2543Smrg    echo "$object : \\" > "$depfile"
184706f2543Smrg
185706f2543Smrg    # Clip off the initial element (the dependent).  Don't try to be
186706f2543Smrg    # clever and replace this with sed code, as IRIX sed won't handle
187706f2543Smrg    # lines with more than a fixed number of characters (4096 in
188706f2543Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
189706f2543Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
190706f2543Smrg    # dependency line.
191706f2543Smrg    tr ' ' '
192706f2543Smrg' < "$tmpdepfile" \
193706f2543Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
194706f2543Smrg    tr '
195706f2543Smrg' ' ' >> $depfile
196706f2543Smrg    echo >> $depfile
197706f2543Smrg
198706f2543Smrg    # The second pass generates a dummy entry for each header file.
199706f2543Smrg    tr ' ' '
200706f2543Smrg' < "$tmpdepfile" \
201706f2543Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
202706f2543Smrg   >> $depfile
203706f2543Smrg  else
204706f2543Smrg    # The sourcefile does not contain any dependencies, so just
205706f2543Smrg    # store a dummy comment line, to avoid errors with the Makefile
206706f2543Smrg    # "include basename.Plo" scheme.
207706f2543Smrg    echo "#dummy" > "$depfile"
208706f2543Smrg  fi
209706f2543Smrg  rm -f "$tmpdepfile"
210706f2543Smrg  ;;
211706f2543Smrg
212706f2543Smrgaix)
213706f2543Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
214706f2543Smrg  # in a .u file.  In older versions, this file always lives in the
215706f2543Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
216706f2543Smrg  # start of each line; $object doesn't have directory information.
217706f2543Smrg  # Version 6 uses the directory in both cases.
218706f2543Smrg  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
219706f2543Smrg  tmpdepfile="$stripped.u"
220706f2543Smrg  if test "$libtool" = yes; then
221706f2543Smrg    "$@" -Wc,-M
222706f2543Smrg  else
223706f2543Smrg    "$@" -M
224706f2543Smrg  fi
225706f2543Smrg  stat=$?
226706f2543Smrg
227706f2543Smrg  if test -f "$tmpdepfile"; then :
228706f2543Smrg  else
229706f2543Smrg    stripped=`echo "$stripped" | sed 's,^.*/,,'`
230706f2543Smrg    tmpdepfile="$stripped.u"
231706f2543Smrg  fi
232706f2543Smrg
233706f2543Smrg  if test $stat -eq 0; then :
234706f2543Smrg  else
235706f2543Smrg    rm -f "$tmpdepfile"
236706f2543Smrg    exit $stat
237706f2543Smrg  fi
238706f2543Smrg
239706f2543Smrg  if test -f "$tmpdepfile"; then
240706f2543Smrg    outname="$stripped.o"
241706f2543Smrg    # Each line is of the form `foo.o: dependent.h'.
242706f2543Smrg    # Do two passes, one to just change these to
243706f2543Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
244706f2543Smrg    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
245706f2543Smrg    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
246706f2543Smrg  else
247706f2543Smrg    # The sourcefile does not contain any dependencies, so just
248706f2543Smrg    # store a dummy comment line, to avoid errors with the Makefile
249706f2543Smrg    # "include basename.Plo" scheme.
250706f2543Smrg    echo "#dummy" > "$depfile"
251706f2543Smrg  fi
252706f2543Smrg  rm -f "$tmpdepfile"
253706f2543Smrg  ;;
254706f2543Smrg
255706f2543Smrgicc)
256706f2543Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
257706f2543Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
258706f2543Smrg  # ICC 7.0 will fill foo.d with something like
259706f2543Smrg  #    foo.o: sub/foo.c
260706f2543Smrg  #    foo.o: sub/foo.h
261706f2543Smrg  # which is wrong.  We want:
262706f2543Smrg  #    sub/foo.o: sub/foo.c
263706f2543Smrg  #    sub/foo.o: sub/foo.h
264706f2543Smrg  #    sub/foo.c:
265706f2543Smrg  #    sub/foo.h:
266706f2543Smrg  # ICC 7.1 will output
267706f2543Smrg  #    foo.o: sub/foo.c sub/foo.h
268706f2543Smrg  # and will wrap long lines using \ :
269706f2543Smrg  #    foo.o: sub/foo.c ... \
270706f2543Smrg  #     sub/foo.h ... \
271706f2543Smrg  #     ...
272706f2543Smrg
273706f2543Smrg  "$@" -MD -MF "$tmpdepfile"
274706f2543Smrg  stat=$?
275706f2543Smrg  if test $stat -eq 0; then :
276706f2543Smrg  else
277706f2543Smrg    rm -f "$tmpdepfile"
278706f2543Smrg    exit $stat
279706f2543Smrg  fi
280706f2543Smrg  rm -f "$depfile"
281706f2543Smrg  # Each line is of the form `foo.o: dependent.h',
282706f2543Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
283706f2543Smrg  # Do two passes, one to just change these to
284706f2543Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
285706f2543Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
286706f2543Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
287706f2543Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
288706f2543Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
289706f2543Smrg    sed -e 's/$/ :/' >> "$depfile"
290706f2543Smrg  rm -f "$tmpdepfile"
291706f2543Smrg  ;;
292706f2543Smrg
293706f2543Smrghp2)
294706f2543Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
295706f2543Smrg  # compilers, which have integrated preprocessors.  The correct option
296706f2543Smrg  # to use with these is +Maked; it writes dependencies to a file named
297706f2543Smrg  # 'foo.d', which lands next to the object file, wherever that
298706f2543Smrg  # happens to be.
299706f2543Smrg  # Much of this is similar to the tru64 case; see comments there.
300706f2543Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
301706f2543Smrg  test "x$dir" = "x$object" && dir=
302706f2543Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
303706f2543Smrg  if test "$libtool" = yes; then
304706f2543Smrg    tmpdepfile1=$dir$base.d
305706f2543Smrg    tmpdepfile2=$dir.libs/$base.d
306706f2543Smrg    "$@" -Wc,+Maked
307706f2543Smrg  else
308706f2543Smrg    tmpdepfile1=$dir$base.d
309706f2543Smrg    tmpdepfile2=$dir$base.d
310706f2543Smrg    "$@" +Maked
311706f2543Smrg  fi
312706f2543Smrg  stat=$?
313706f2543Smrg  if test $stat -eq 0; then :
314706f2543Smrg  else
315706f2543Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
316706f2543Smrg     exit $stat
317706f2543Smrg  fi
318706f2543Smrg
319706f2543Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
320706f2543Smrg  do
321706f2543Smrg    test -f "$tmpdepfile" && break
322706f2543Smrg  done
323706f2543Smrg  if test -f "$tmpdepfile"; then
324706f2543Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
325706f2543Smrg    # Add `dependent.h:' lines.
326706f2543Smrg    sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
327706f2543Smrg  else
328706f2543Smrg    echo "#dummy" > "$depfile"
329706f2543Smrg  fi
330706f2543Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
331706f2543Smrg  ;;
332706f2543Smrg
333706f2543Smrgtru64)
334706f2543Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
335706f2543Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
336706f2543Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
337706f2543Smrg   # dependencies in `foo.d' instead, so we check for that too.
338706f2543Smrg   # Subdirectories are respected.
339706f2543Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
340706f2543Smrg   test "x$dir" = "x$object" && dir=
341706f2543Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
342706f2543Smrg
343706f2543Smrg   if test "$libtool" = yes; then
344706f2543Smrg      # With Tru64 cc, shared objects can also be used to make a
345706f2543Smrg      # static library.  This mechanism is used in libtool 1.4 series to
346706f2543Smrg      # handle both shared and static libraries in a single compilation.
347706f2543Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
348706f2543Smrg      #
349706f2543Smrg      # With libtool 1.5 this exception was removed, and libtool now
350706f2543Smrg      # generates 2 separate objects for the 2 libraries.  These two
351706f2543Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
352706f2543Smrg      # in $dir$base.o.d.  We have to check for both files, because
353706f2543Smrg      # one of the two compilations can be disabled.  We should prefer
354706f2543Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
355706f2543Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
356706f2543Smrg      # the former would cause a distcleancheck panic.
357706f2543Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
358706f2543Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
359706f2543Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
360706f2543Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
361706f2543Smrg      "$@" -Wc,-MD
362706f2543Smrg   else
363706f2543Smrg      tmpdepfile1=$dir$base.o.d
364706f2543Smrg      tmpdepfile2=$dir$base.d
365706f2543Smrg      tmpdepfile3=$dir$base.d
366706f2543Smrg      tmpdepfile4=$dir$base.d
367706f2543Smrg      "$@" -MD
368706f2543Smrg   fi
369706f2543Smrg
370706f2543Smrg   stat=$?
371706f2543Smrg   if test $stat -eq 0; then :
372706f2543Smrg   else
373706f2543Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
374706f2543Smrg      exit $stat
375706f2543Smrg   fi
376706f2543Smrg
377706f2543Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
378706f2543Smrg   do
379706f2543Smrg     test -f "$tmpdepfile" && break
380706f2543Smrg   done
381706f2543Smrg   if test -f "$tmpdepfile"; then
382706f2543Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
383706f2543Smrg      # That's a tab and a space in the [].
384706f2543Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
385706f2543Smrg   else
386706f2543Smrg      echo "#dummy" > "$depfile"
387706f2543Smrg   fi
388706f2543Smrg   rm -f "$tmpdepfile"
389706f2543Smrg   ;;
390706f2543Smrg
391706f2543Smrg#nosideeffect)
392706f2543Smrg  # This comment above is used by automake to tell side-effect
393706f2543Smrg  # dependency tracking mechanisms from slower ones.
394706f2543Smrg
395706f2543Smrgdashmstdout)
396706f2543Smrg  # Important note: in order to support this mode, a compiler *must*
397706f2543Smrg  # always write the preprocessed file to stdout, regardless of -o.
398706f2543Smrg  "$@" || exit $?
399706f2543Smrg
400706f2543Smrg  # Remove the call to Libtool.
401706f2543Smrg  if test "$libtool" = yes; then
402706f2543Smrg    while test $1 != '--mode=compile'; do
403706f2543Smrg      shift
404706f2543Smrg    done
405706f2543Smrg    shift
406706f2543Smrg  fi
407706f2543Smrg
408706f2543Smrg  # Remove `-o $object'.
409706f2543Smrg  IFS=" "
410706f2543Smrg  for arg
411706f2543Smrg  do
412706f2543Smrg    case $arg in
413706f2543Smrg    -o)
414706f2543Smrg      shift
415706f2543Smrg      ;;
416706f2543Smrg    $object)
417706f2543Smrg      shift
418706f2543Smrg      ;;
419706f2543Smrg    *)
420706f2543Smrg      set fnord "$@" "$arg"
421706f2543Smrg      shift # fnord
422706f2543Smrg      shift # $arg
423706f2543Smrg      ;;
424706f2543Smrg    esac
425706f2543Smrg  done
426706f2543Smrg
427706f2543Smrg  test -z "$dashmflag" && dashmflag=-M
428706f2543Smrg  # Require at least two characters before searching for `:'
429706f2543Smrg  # in the target name.  This is to cope with DOS-style filenames:
430706f2543Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
431706f2543Smrg  "$@" $dashmflag |
432706f2543Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
433706f2543Smrg  rm -f "$depfile"
434706f2543Smrg  cat < "$tmpdepfile" > "$depfile"
435706f2543Smrg  tr ' ' '
436706f2543Smrg' < "$tmpdepfile" | \
437706f2543Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
438706f2543Smrg## correctly.  Breaking it into two sed invocations is a workaround.
439706f2543Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
440706f2543Smrg  rm -f "$tmpdepfile"
441706f2543Smrg  ;;
442706f2543Smrg
443706f2543SmrgdashXmstdout)
444706f2543Smrg  # This case only exists to satisfy depend.m4.  It is never actually
445706f2543Smrg  # run, as this mode is specially recognized in the preamble.
446706f2543Smrg  exit 1
447706f2543Smrg  ;;
448706f2543Smrg
449706f2543Smrgmakedepend)
450706f2543Smrg  "$@" || exit $?
451706f2543Smrg  # Remove any Libtool call
452706f2543Smrg  if test "$libtool" = yes; then
453706f2543Smrg    while test $1 != '--mode=compile'; do
454706f2543Smrg      shift
455706f2543Smrg    done
456706f2543Smrg    shift
457706f2543Smrg  fi
458706f2543Smrg  # X makedepend
459706f2543Smrg  shift
460706f2543Smrg  cleared=no
461706f2543Smrg  for arg in "$@"; do
462706f2543Smrg    case $cleared in
463706f2543Smrg    no)
464706f2543Smrg      set ""; shift
465706f2543Smrg      cleared=yes ;;
466706f2543Smrg    esac
467706f2543Smrg    case "$arg" in
468706f2543Smrg    -D*|-I*)
469706f2543Smrg      set fnord "$@" "$arg"; shift ;;
470706f2543Smrg    # Strip any option that makedepend may not understand.  Remove
471706f2543Smrg    # the object too, otherwise makedepend will parse it as a source file.
472706f2543Smrg    -*|$object)
473706f2543Smrg      ;;
474706f2543Smrg    *)
475706f2543Smrg      set fnord "$@" "$arg"; shift ;;
476706f2543Smrg    esac
477706f2543Smrg  done
478706f2543Smrg  obj_suffix="`echo $object | sed 's/^.*\././'`"
479706f2543Smrg  touch "$tmpdepfile"
480706f2543Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
481706f2543Smrg  rm -f "$depfile"
482706f2543Smrg  cat < "$tmpdepfile" > "$depfile"
483706f2543Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
484706f2543Smrg' | \
485706f2543Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
486706f2543Smrg## correctly.  Breaking it into two sed invocations is a workaround.
487706f2543Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
488706f2543Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
489706f2543Smrg  ;;
490706f2543Smrg
491706f2543Smrgcpp)
492706f2543Smrg  # Important note: in order to support this mode, a compiler *must*
493706f2543Smrg  # always write the preprocessed file to stdout.
494706f2543Smrg  "$@" || exit $?
495706f2543Smrg
496706f2543Smrg  # Remove the call to Libtool.
497706f2543Smrg  if test "$libtool" = yes; then
498706f2543Smrg    while test $1 != '--mode=compile'; do
499706f2543Smrg      shift
500706f2543Smrg    done
501706f2543Smrg    shift
502706f2543Smrg  fi
503706f2543Smrg
504706f2543Smrg  # Remove `-o $object'.
505706f2543Smrg  IFS=" "
506706f2543Smrg  for arg
507706f2543Smrg  do
508706f2543Smrg    case $arg in
509706f2543Smrg    -o)
510706f2543Smrg      shift
511706f2543Smrg      ;;
512706f2543Smrg    $object)
513706f2543Smrg      shift
514706f2543Smrg      ;;
515706f2543Smrg    *)
516706f2543Smrg      set fnord "$@" "$arg"
517706f2543Smrg      shift # fnord
518706f2543Smrg      shift # $arg
519706f2543Smrg      ;;
520706f2543Smrg    esac
521706f2543Smrg  done
522706f2543Smrg
523706f2543Smrg  "$@" -E |
524706f2543Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
525706f2543Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
526706f2543Smrg    sed '$ s: \\$::' > "$tmpdepfile"
527706f2543Smrg  rm -f "$depfile"
528706f2543Smrg  echo "$object : \\" > "$depfile"
529706f2543Smrg  cat < "$tmpdepfile" >> "$depfile"
530706f2543Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
531706f2543Smrg  rm -f "$tmpdepfile"
532706f2543Smrg  ;;
533706f2543Smrg
534706f2543Smrgmsvisualcpp)
535706f2543Smrg  # Important note: in order to support this mode, a compiler *must*
536706f2543Smrg  # always write the preprocessed file to stdout, regardless of -o,
537706f2543Smrg  # because we must use -o when running libtool.
538706f2543Smrg  "$@" || exit $?
539706f2543Smrg  IFS=" "
540706f2543Smrg  for arg
541706f2543Smrg  do
542706f2543Smrg    case "$arg" in
543706f2543Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
544706f2543Smrg	set fnord "$@"
545706f2543Smrg	shift
546706f2543Smrg	shift
547706f2543Smrg	;;
548706f2543Smrg    *)
549706f2543Smrg	set fnord "$@" "$arg"
550706f2543Smrg	shift
551706f2543Smrg	shift
552706f2543Smrg	;;
553706f2543Smrg    esac
554706f2543Smrg  done
555706f2543Smrg  "$@" -E |
556706f2543Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
557706f2543Smrg  rm -f "$depfile"
558706f2543Smrg  echo "$object : \\" > "$depfile"
559706f2543Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
560706f2543Smrg  echo "	" >> "$depfile"
561706f2543Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
562706f2543Smrg  rm -f "$tmpdepfile"
563706f2543Smrg  ;;
564706f2543Smrg
565706f2543Smrgnone)
566706f2543Smrg  exec "$@"
567706f2543Smrg  ;;
568706f2543Smrg
569706f2543Smrg*)
570706f2543Smrg  echo "Unknown depmode $depmode" 1>&2
571706f2543Smrg  exit 1
572706f2543Smrg  ;;
573706f2543Smrgesac
574706f2543Smrg
575706f2543Smrgexit 0
576706f2543Smrg
577706f2543Smrg# Local Variables:
578706f2543Smrg# mode: shell-script
579706f2543Smrg# sh-indentation: 2
580706f2543Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
581706f2543Smrg# time-stamp-start: "scriptversion="
582706f2543Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
583706f2543Smrg# time-stamp-end: "$"
584706f2543Smrg# End:
585