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