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