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