depcomp revision c37a63b8
1264fa531Smrg#! /bin/sh
2264fa531Smrg# depcomp - compile a program generating dependencies as side-effects
3c37a63b8Smrg
4c37a63b8Smrgscriptversion=2009-04-28.21; # UTC
5c37a63b8Smrg
6c37a63b8Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
7c37a63b8Smrg# Software Foundation, Inc.
8264fa531Smrg
9264fa531Smrg# This program is free software; you can redistribute it and/or modify
10264fa531Smrg# it under the terms of the GNU General Public License as published by
11264fa531Smrg# the Free Software Foundation; either version 2, or (at your option)
12264fa531Smrg# any later version.
13264fa531Smrg
14264fa531Smrg# This program is distributed in the hope that it will be useful,
15264fa531Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16264fa531Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17264fa531Smrg# GNU General Public License for more details.
18264fa531Smrg
19264fa531Smrg# You should have received a copy of the GNU General Public License
20c37a63b8Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21264fa531Smrg
22264fa531Smrg# As a special exception to the GNU General Public License, if you
23264fa531Smrg# distribute this file as part of a program that contains a
24264fa531Smrg# configuration script generated by Autoconf, you may include it under
25264fa531Smrg# the same distribution terms that you use for the rest of that program.
26264fa531Smrg
27264fa531Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28264fa531Smrg
29c37a63b8Smrgcase $1 in
30c37a63b8Smrg  '')
31c37a63b8Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
32c37a63b8Smrg     exit 1;
33c37a63b8Smrg     ;;
34c37a63b8Smrg  -h | --h*)
35c37a63b8Smrg    cat <<\EOF
36c37a63b8SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
37c37a63b8Smrg
38c37a63b8SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
39c37a63b8Smrgas side-effects.
40c37a63b8Smrg
41c37a63b8SmrgEnvironment variables:
42c37a63b8Smrg  depmode     Dependency tracking mode.
43c37a63b8Smrg  source      Source file read by `PROGRAMS ARGS'.
44c37a63b8Smrg  object      Object file output by `PROGRAMS ARGS'.
45c37a63b8Smrg  DEPDIR      directory where to store dependencies.
46c37a63b8Smrg  depfile     Dependency file to output.
47c37a63b8Smrg  tmpdepfile  Temporary file to use when outputing dependencies.
48c37a63b8Smrg  libtool     Whether libtool is used (yes/no).
49c37a63b8Smrg
50c37a63b8SmrgReport bugs to <bug-automake@gnu.org>.
51c37a63b8SmrgEOF
52c37a63b8Smrg    exit $?
53c37a63b8Smrg    ;;
54c37a63b8Smrg  -v | --v*)
55c37a63b8Smrg    echo "depcomp $scriptversion"
56c37a63b8Smrg    exit $?
57c37a63b8Smrg    ;;
58c37a63b8Smrgesac
59c37a63b8Smrg
60264fa531Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
61264fa531Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
62264fa531Smrg  exit 1
63264fa531Smrgfi
64264fa531Smrg
65c37a63b8Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
66c37a63b8Smrgdepfile=${depfile-`echo "$object" |
67c37a63b8Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
68264fa531Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
69264fa531Smrg
70264fa531Smrgrm -f "$tmpdepfile"
71264fa531Smrg
72264fa531Smrg# Some modes work just like other modes, but use different flags.  We
73264fa531Smrg# parameterize here, but still list the modes in the big case below,
74264fa531Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
75264fa531Smrg# here, because this file can only contain one case statement.
76264fa531Smrgif test "$depmode" = hp; then
77264fa531Smrg  # HP compiler uses -M and no extra arg.
78264fa531Smrg  gccflag=-M
79264fa531Smrg  depmode=gcc
80264fa531Smrgfi
81264fa531Smrg
82264fa531Smrgif test "$depmode" = dashXmstdout; then
83264fa531Smrg   # This is just like dashmstdout with a different argument.
84264fa531Smrg   dashmflag=-xM
85264fa531Smrg   depmode=dashmstdout
86264fa531Smrgfi
87264fa531Smrg
88c37a63b8Smrgcygpath_u="cygpath -u -f -"
89c37a63b8Smrgif test "$depmode" = msvcmsys; then
90c37a63b8Smrg   # This is just like msvisualcpp but w/o cygpath translation.
91c37a63b8Smrg   # Just convert the backslash-escaped backslashes to single forward
92c37a63b8Smrg   # slashes to satisfy depend.m4
93c37a63b8Smrg   cygpath_u="sed s,\\\\\\\\,/,g"
94c37a63b8Smrg   depmode=msvisualcpp
95c37a63b8Smrgfi
96c37a63b8Smrg
97264fa531Smrgcase "$depmode" in
98264fa531Smrggcc3)
99264fa531Smrg## gcc 3 implements dependency tracking that does exactly what
100264fa531Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
101264fa531Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
102c37a63b8Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
103c37a63b8Smrg## the command line argument order; so add the flags where they
104c37a63b8Smrg## appear in depend2.am.  Note that the slowdown incurred here
105c37a63b8Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
106c37a63b8Smrg  for arg
107c37a63b8Smrg  do
108c37a63b8Smrg    case $arg in
109c37a63b8Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
110c37a63b8Smrg    *)  set fnord "$@" "$arg" ;;
111c37a63b8Smrg    esac
112c37a63b8Smrg    shift # fnord
113c37a63b8Smrg    shift # $arg
114c37a63b8Smrg  done
115c37a63b8Smrg  "$@"
116264fa531Smrg  stat=$?
117264fa531Smrg  if test $stat -eq 0; then :
118264fa531Smrg  else
119264fa531Smrg    rm -f "$tmpdepfile"
120264fa531Smrg    exit $stat
121264fa531Smrg  fi
122264fa531Smrg  mv "$tmpdepfile" "$depfile"
123264fa531Smrg  ;;
124264fa531Smrg
125264fa531Smrggcc)
126264fa531Smrg## There are various ways to get dependency output from gcc.  Here's
127264fa531Smrg## why we pick this rather obscure method:
128264fa531Smrg## - Don't want to use -MD because we'd like the dependencies to end
129264fa531Smrg##   up in a subdir.  Having to rename by hand is ugly.
130264fa531Smrg##   (We might end up doing this anyway to support other compilers.)
131264fa531Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
132264fa531Smrg##   -MM, not -M (despite what the docs say).
133264fa531Smrg## - Using -M directly means running the compiler twice (even worse
134264fa531Smrg##   than renaming).
135264fa531Smrg  if test -z "$gccflag"; then
136264fa531Smrg    gccflag=-MD,
137264fa531Smrg  fi
138264fa531Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
139264fa531Smrg  stat=$?
140264fa531Smrg  if test $stat -eq 0; then :
141264fa531Smrg  else
142264fa531Smrg    rm -f "$tmpdepfile"
143264fa531Smrg    exit $stat
144264fa531Smrg  fi
145264fa531Smrg  rm -f "$depfile"
146264fa531Smrg  echo "$object : \\" > "$depfile"
147264fa531Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
148264fa531Smrg## The second -e expression handles DOS-style file names with drive letters.
149264fa531Smrg  sed -e 's/^[^:]*: / /' \
150264fa531Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
151264fa531Smrg## This next piece of magic avoids the `deleted header file' problem.
152264fa531Smrg## The problem is that when a header file which appears in a .P file
153264fa531Smrg## is deleted, the dependency causes make to die (because there is
154264fa531Smrg## typically no way to rebuild the header).  We avoid this by adding
155264fa531Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
156264fa531Smrg## this for us directly.
157264fa531Smrg  tr ' ' '
158264fa531Smrg' < "$tmpdepfile" |
159264fa531Smrg## Some versions of gcc put a space before the `:'.  On the theory
160264fa531Smrg## that the space means something, we add a space to the output as
161264fa531Smrg## well.
162264fa531Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
163264fa531Smrg## correctly.  Breaking it into two sed invocations is a workaround.
164264fa531Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
165264fa531Smrg  rm -f "$tmpdepfile"
166264fa531Smrg  ;;
167264fa531Smrg
168264fa531Smrghp)
169264fa531Smrg  # This case exists only to let depend.m4 do its work.  It works by
170264fa531Smrg  # looking at the text of this script.  This case will never be run,
171264fa531Smrg  # since it is checked for above.
172264fa531Smrg  exit 1
173264fa531Smrg  ;;
174264fa531Smrg
175264fa531Smrgsgi)
176264fa531Smrg  if test "$libtool" = yes; then
177264fa531Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
178264fa531Smrg  else
179264fa531Smrg    "$@" -MDupdate "$tmpdepfile"
180264fa531Smrg  fi
181264fa531Smrg  stat=$?
182264fa531Smrg  if test $stat -eq 0; then :
183264fa531Smrg  else
184264fa531Smrg    rm -f "$tmpdepfile"
185264fa531Smrg    exit $stat
186264fa531Smrg  fi
187264fa531Smrg  rm -f "$depfile"
188264fa531Smrg
189264fa531Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
190264fa531Smrg    echo "$object : \\" > "$depfile"
191264fa531Smrg
192264fa531Smrg    # Clip off the initial element (the dependent).  Don't try to be
193264fa531Smrg    # clever and replace this with sed code, as IRIX sed won't handle
194264fa531Smrg    # lines with more than a fixed number of characters (4096 in
195264fa531Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
196264fa531Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
197264fa531Smrg    # dependency line.
198264fa531Smrg    tr ' ' '
199264fa531Smrg' < "$tmpdepfile" \
200264fa531Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
201264fa531Smrg    tr '
202c37a63b8Smrg' ' ' >> "$depfile"
203c37a63b8Smrg    echo >> "$depfile"
204264fa531Smrg
205264fa531Smrg    # The second pass generates a dummy entry for each header file.
206264fa531Smrg    tr ' ' '
207264fa531Smrg' < "$tmpdepfile" \
208264fa531Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
209c37a63b8Smrg   >> "$depfile"
210264fa531Smrg  else
211264fa531Smrg    # The sourcefile does not contain any dependencies, so just
212264fa531Smrg    # store a dummy comment line, to avoid errors with the Makefile
213264fa531Smrg    # "include basename.Plo" scheme.
214264fa531Smrg    echo "#dummy" > "$depfile"
215264fa531Smrg  fi
216264fa531Smrg  rm -f "$tmpdepfile"
217264fa531Smrg  ;;
218264fa531Smrg
219264fa531Smrgaix)
220264fa531Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
221264fa531Smrg  # in a .u file.  In older versions, this file always lives in the
222264fa531Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
223264fa531Smrg  # start of each line; $object doesn't have directory information.
224264fa531Smrg  # Version 6 uses the directory in both cases.
225c37a63b8Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
226c37a63b8Smrg  test "x$dir" = "x$object" && dir=
227c37a63b8Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
228264fa531Smrg  if test "$libtool" = yes; then
229c37a63b8Smrg    tmpdepfile1=$dir$base.u
230c37a63b8Smrg    tmpdepfile2=$base.u
231c37a63b8Smrg    tmpdepfile3=$dir.libs/$base.u
232264fa531Smrg    "$@" -Wc,-M
233264fa531Smrg  else
234c37a63b8Smrg    tmpdepfile1=$dir$base.u
235c37a63b8Smrg    tmpdepfile2=$dir$base.u
236c37a63b8Smrg    tmpdepfile3=$dir$base.u
237264fa531Smrg    "$@" -M
238264fa531Smrg  fi
239264fa531Smrg  stat=$?
240264fa531Smrg
241264fa531Smrg  if test $stat -eq 0; then :
242264fa531Smrg  else
243c37a63b8Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
244264fa531Smrg    exit $stat
245264fa531Smrg  fi
246264fa531Smrg
247c37a63b8Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
248c37a63b8Smrg  do
249c37a63b8Smrg    test -f "$tmpdepfile" && break
250c37a63b8Smrg  done
251264fa531Smrg  if test -f "$tmpdepfile"; then
252264fa531Smrg    # Each line is of the form `foo.o: dependent.h'.
253264fa531Smrg    # Do two passes, one to just change these to
254264fa531Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
255c37a63b8Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
256c37a63b8Smrg    # That's a tab and a space in the [].
257c37a63b8Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
258264fa531Smrg  else
259264fa531Smrg    # The sourcefile does not contain any dependencies, so just
260264fa531Smrg    # store a dummy comment line, to avoid errors with the Makefile
261264fa531Smrg    # "include basename.Plo" scheme.
262264fa531Smrg    echo "#dummy" > "$depfile"
263264fa531Smrg  fi
264264fa531Smrg  rm -f "$tmpdepfile"
265264fa531Smrg  ;;
266264fa531Smrg
267264fa531Smrgicc)
268264fa531Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
269264fa531Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
270264fa531Smrg  # ICC 7.0 will fill foo.d with something like
271264fa531Smrg  #    foo.o: sub/foo.c
272264fa531Smrg  #    foo.o: sub/foo.h
273264fa531Smrg  # which is wrong.  We want:
274264fa531Smrg  #    sub/foo.o: sub/foo.c
275264fa531Smrg  #    sub/foo.o: sub/foo.h
276264fa531Smrg  #    sub/foo.c:
277264fa531Smrg  #    sub/foo.h:
278264fa531Smrg  # ICC 7.1 will output
279264fa531Smrg  #    foo.o: sub/foo.c sub/foo.h
280264fa531Smrg  # and will wrap long lines using \ :
281264fa531Smrg  #    foo.o: sub/foo.c ... \
282264fa531Smrg  #     sub/foo.h ... \
283264fa531Smrg  #     ...
284264fa531Smrg
285264fa531Smrg  "$@" -MD -MF "$tmpdepfile"
286264fa531Smrg  stat=$?
287264fa531Smrg  if test $stat -eq 0; then :
288264fa531Smrg  else
289264fa531Smrg    rm -f "$tmpdepfile"
290264fa531Smrg    exit $stat
291264fa531Smrg  fi
292264fa531Smrg  rm -f "$depfile"
293264fa531Smrg  # Each line is of the form `foo.o: dependent.h',
294264fa531Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
295264fa531Smrg  # Do two passes, one to just change these to
296264fa531Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
297264fa531Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
298264fa531Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
299264fa531Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
300264fa531Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
301264fa531Smrg    sed -e 's/$/ :/' >> "$depfile"
302264fa531Smrg  rm -f "$tmpdepfile"
303264fa531Smrg  ;;
304264fa531Smrg
305c37a63b8Smrghp2)
306c37a63b8Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
307c37a63b8Smrg  # compilers, which have integrated preprocessors.  The correct option
308c37a63b8Smrg  # to use with these is +Maked; it writes dependencies to a file named
309c37a63b8Smrg  # 'foo.d', which lands next to the object file, wherever that
310c37a63b8Smrg  # happens to be.
311c37a63b8Smrg  # Much of this is similar to the tru64 case; see comments there.
312c37a63b8Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
313c37a63b8Smrg  test "x$dir" = "x$object" && dir=
314c37a63b8Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
315c37a63b8Smrg  if test "$libtool" = yes; then
316c37a63b8Smrg    tmpdepfile1=$dir$base.d
317c37a63b8Smrg    tmpdepfile2=$dir.libs/$base.d
318c37a63b8Smrg    "$@" -Wc,+Maked
319c37a63b8Smrg  else
320c37a63b8Smrg    tmpdepfile1=$dir$base.d
321c37a63b8Smrg    tmpdepfile2=$dir$base.d
322c37a63b8Smrg    "$@" +Maked
323c37a63b8Smrg  fi
324c37a63b8Smrg  stat=$?
325c37a63b8Smrg  if test $stat -eq 0; then :
326c37a63b8Smrg  else
327c37a63b8Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
328c37a63b8Smrg     exit $stat
329c37a63b8Smrg  fi
330c37a63b8Smrg
331c37a63b8Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
332c37a63b8Smrg  do
333c37a63b8Smrg    test -f "$tmpdepfile" && break
334c37a63b8Smrg  done
335c37a63b8Smrg  if test -f "$tmpdepfile"; then
336c37a63b8Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
337c37a63b8Smrg    # Add `dependent.h:' lines.
338c37a63b8Smrg    sed -ne '2,${
339c37a63b8Smrg	       s/^ *//
340c37a63b8Smrg	       s/ \\*$//
341c37a63b8Smrg	       s/$/:/
342c37a63b8Smrg	       p
343c37a63b8Smrg	     }' "$tmpdepfile" >> "$depfile"
344c37a63b8Smrg  else
345c37a63b8Smrg    echo "#dummy" > "$depfile"
346c37a63b8Smrg  fi
347c37a63b8Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
348c37a63b8Smrg  ;;
349c37a63b8Smrg
350264fa531Smrgtru64)
351264fa531Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
352264fa531Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
353264fa531Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
354264fa531Smrg   # dependencies in `foo.d' instead, so we check for that too.
355264fa531Smrg   # Subdirectories are respected.
356264fa531Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
357264fa531Smrg   test "x$dir" = "x$object" && dir=
358264fa531Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
359264fa531Smrg
360264fa531Smrg   if test "$libtool" = yes; then
361c37a63b8Smrg      # With Tru64 cc, shared objects can also be used to make a
362c37a63b8Smrg      # static library.  This mechanism is used in libtool 1.4 series to
363c37a63b8Smrg      # handle both shared and static libraries in a single compilation.
364c37a63b8Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
365c37a63b8Smrg      #
366c37a63b8Smrg      # With libtool 1.5 this exception was removed, and libtool now
367c37a63b8Smrg      # generates 2 separate objects for the 2 libraries.  These two
368c37a63b8Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
369c37a63b8Smrg      # in $dir$base.o.d.  We have to check for both files, because
370c37a63b8Smrg      # one of the two compilations can be disabled.  We should prefer
371c37a63b8Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
372c37a63b8Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
373c37a63b8Smrg      # the former would cause a distcleancheck panic.
374c37a63b8Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
375c37a63b8Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
376c37a63b8Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
377c37a63b8Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
378264fa531Smrg      "$@" -Wc,-MD
379264fa531Smrg   else
380c37a63b8Smrg      tmpdepfile1=$dir$base.o.d
381c37a63b8Smrg      tmpdepfile2=$dir$base.d
382c37a63b8Smrg      tmpdepfile3=$dir$base.d
383c37a63b8Smrg      tmpdepfile4=$dir$base.d
384264fa531Smrg      "$@" -MD
385264fa531Smrg   fi
386264fa531Smrg
387264fa531Smrg   stat=$?
388264fa531Smrg   if test $stat -eq 0; then :
389264fa531Smrg   else
390c37a63b8Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
391264fa531Smrg      exit $stat
392264fa531Smrg   fi
393264fa531Smrg
394c37a63b8Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
395c37a63b8Smrg   do
396c37a63b8Smrg     test -f "$tmpdepfile" && break
397c37a63b8Smrg   done
398264fa531Smrg   if test -f "$tmpdepfile"; then
399264fa531Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
400264fa531Smrg      # That's a tab and a space in the [].
401264fa531Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
402264fa531Smrg   else
403264fa531Smrg      echo "#dummy" > "$depfile"
404264fa531Smrg   fi
405264fa531Smrg   rm -f "$tmpdepfile"
406264fa531Smrg   ;;
407264fa531Smrg
408264fa531Smrg#nosideeffect)
409264fa531Smrg  # This comment above is used by automake to tell side-effect
410264fa531Smrg  # dependency tracking mechanisms from slower ones.
411264fa531Smrg
412264fa531Smrgdashmstdout)
413264fa531Smrg  # Important note: in order to support this mode, a compiler *must*
414264fa531Smrg  # always write the preprocessed file to stdout, regardless of -o.
415264fa531Smrg  "$@" || exit $?
416264fa531Smrg
417264fa531Smrg  # Remove the call to Libtool.
418264fa531Smrg  if test "$libtool" = yes; then
419c37a63b8Smrg    while test "X$1" != 'X--mode=compile'; do
420264fa531Smrg      shift
421264fa531Smrg    done
422264fa531Smrg    shift
423264fa531Smrg  fi
424264fa531Smrg
425264fa531Smrg  # Remove `-o $object'.
426264fa531Smrg  IFS=" "
427264fa531Smrg  for arg
428264fa531Smrg  do
429264fa531Smrg    case $arg in
430264fa531Smrg    -o)
431264fa531Smrg      shift
432264fa531Smrg      ;;
433264fa531Smrg    $object)
434264fa531Smrg      shift
435264fa531Smrg      ;;
436264fa531Smrg    *)
437264fa531Smrg      set fnord "$@" "$arg"
438264fa531Smrg      shift # fnord
439264fa531Smrg      shift # $arg
440264fa531Smrg      ;;
441264fa531Smrg    esac
442264fa531Smrg  done
443264fa531Smrg
444264fa531Smrg  test -z "$dashmflag" && dashmflag=-M
445264fa531Smrg  # Require at least two characters before searching for `:'
446264fa531Smrg  # in the target name.  This is to cope with DOS-style filenames:
447264fa531Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
448264fa531Smrg  "$@" $dashmflag |
449264fa531Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
450264fa531Smrg  rm -f "$depfile"
451264fa531Smrg  cat < "$tmpdepfile" > "$depfile"
452264fa531Smrg  tr ' ' '
453264fa531Smrg' < "$tmpdepfile" | \
454264fa531Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
455264fa531Smrg## correctly.  Breaking it into two sed invocations is a workaround.
456264fa531Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
457264fa531Smrg  rm -f "$tmpdepfile"
458264fa531Smrg  ;;
459264fa531Smrg
460264fa531SmrgdashXmstdout)
461264fa531Smrg  # This case only exists to satisfy depend.m4.  It is never actually
462264fa531Smrg  # run, as this mode is specially recognized in the preamble.
463264fa531Smrg  exit 1
464264fa531Smrg  ;;
465264fa531Smrg
466264fa531Smrgmakedepend)
467264fa531Smrg  "$@" || exit $?
468264fa531Smrg  # Remove any Libtool call
469264fa531Smrg  if test "$libtool" = yes; then
470c37a63b8Smrg    while test "X$1" != 'X--mode=compile'; do
471264fa531Smrg      shift
472264fa531Smrg    done
473264fa531Smrg    shift
474264fa531Smrg  fi
475264fa531Smrg  # X makedepend
476264fa531Smrg  shift
477c37a63b8Smrg  cleared=no eat=no
478c37a63b8Smrg  for arg
479c37a63b8Smrg  do
480264fa531Smrg    case $cleared in
481264fa531Smrg    no)
482264fa531Smrg      set ""; shift
483264fa531Smrg      cleared=yes ;;
484264fa531Smrg    esac
485c37a63b8Smrg    if test $eat = yes; then
486c37a63b8Smrg      eat=no
487c37a63b8Smrg      continue
488c37a63b8Smrg    fi
489264fa531Smrg    case "$arg" in
490264fa531Smrg    -D*|-I*)
491264fa531Smrg      set fnord "$@" "$arg"; shift ;;
492264fa531Smrg    # Strip any option that makedepend may not understand.  Remove
493264fa531Smrg    # the object too, otherwise makedepend will parse it as a source file.
494c37a63b8Smrg    -arch)
495c37a63b8Smrg      eat=yes ;;
496264fa531Smrg    -*|$object)
497264fa531Smrg      ;;
498264fa531Smrg    *)
499264fa531Smrg      set fnord "$@" "$arg"; shift ;;
500264fa531Smrg    esac
501264fa531Smrg  done
502c37a63b8Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
503264fa531Smrg  touch "$tmpdepfile"
504264fa531Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
505264fa531Smrg  rm -f "$depfile"
506264fa531Smrg  cat < "$tmpdepfile" > "$depfile"
507264fa531Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
508264fa531Smrg' | \
509264fa531Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
510264fa531Smrg## correctly.  Breaking it into two sed invocations is a workaround.
511264fa531Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
512264fa531Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
513264fa531Smrg  ;;
514264fa531Smrg
515264fa531Smrgcpp)
516264fa531Smrg  # Important note: in order to support this mode, a compiler *must*
517264fa531Smrg  # always write the preprocessed file to stdout.
518264fa531Smrg  "$@" || exit $?
519264fa531Smrg
520264fa531Smrg  # Remove the call to Libtool.
521264fa531Smrg  if test "$libtool" = yes; then
522c37a63b8Smrg    while test "X$1" != 'X--mode=compile'; do
523264fa531Smrg      shift
524264fa531Smrg    done
525264fa531Smrg    shift
526264fa531Smrg  fi
527264fa531Smrg
528264fa531Smrg  # Remove `-o $object'.
529264fa531Smrg  IFS=" "
530264fa531Smrg  for arg
531264fa531Smrg  do
532264fa531Smrg    case $arg in
533264fa531Smrg    -o)
534264fa531Smrg      shift
535264fa531Smrg      ;;
536264fa531Smrg    $object)
537264fa531Smrg      shift
538264fa531Smrg      ;;
539264fa531Smrg    *)
540264fa531Smrg      set fnord "$@" "$arg"
541264fa531Smrg      shift # fnord
542264fa531Smrg      shift # $arg
543264fa531Smrg      ;;
544264fa531Smrg    esac
545264fa531Smrg  done
546264fa531Smrg
547264fa531Smrg  "$@" -E |
548c37a63b8Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
549c37a63b8Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
550264fa531Smrg    sed '$ s: \\$::' > "$tmpdepfile"
551264fa531Smrg  rm -f "$depfile"
552264fa531Smrg  echo "$object : \\" > "$depfile"
553264fa531Smrg  cat < "$tmpdepfile" >> "$depfile"
554264fa531Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
555264fa531Smrg  rm -f "$tmpdepfile"
556264fa531Smrg  ;;
557264fa531Smrg
558264fa531Smrgmsvisualcpp)
559264fa531Smrg  # Important note: in order to support this mode, a compiler *must*
560c37a63b8Smrg  # always write the preprocessed file to stdout.
561264fa531Smrg  "$@" || exit $?
562c37a63b8Smrg
563c37a63b8Smrg  # Remove the call to Libtool.
564c37a63b8Smrg  if test "$libtool" = yes; then
565c37a63b8Smrg    while test "X$1" != 'X--mode=compile'; do
566c37a63b8Smrg      shift
567c37a63b8Smrg    done
568c37a63b8Smrg    shift
569c37a63b8Smrg  fi
570c37a63b8Smrg
571264fa531Smrg  IFS=" "
572264fa531Smrg  for arg
573264fa531Smrg  do
574264fa531Smrg    case "$arg" in
575c37a63b8Smrg    -o)
576c37a63b8Smrg      shift
577c37a63b8Smrg      ;;
578c37a63b8Smrg    $object)
579c37a63b8Smrg      shift
580c37a63b8Smrg      ;;
581264fa531Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
582264fa531Smrg	set fnord "$@"
583264fa531Smrg	shift
584264fa531Smrg	shift
585264fa531Smrg	;;
586264fa531Smrg    *)
587264fa531Smrg	set fnord "$@" "$arg"
588264fa531Smrg	shift
589264fa531Smrg	shift
590264fa531Smrg	;;
591264fa531Smrg    esac
592264fa531Smrg  done
593c37a63b8Smrg  "$@" -E 2>/dev/null |
594c37a63b8Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
595264fa531Smrg  rm -f "$depfile"
596264fa531Smrg  echo "$object : \\" > "$depfile"
597c37a63b8Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
598264fa531Smrg  echo "	" >> "$depfile"
599c37a63b8Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
600264fa531Smrg  rm -f "$tmpdepfile"
601264fa531Smrg  ;;
602264fa531Smrg
603c37a63b8Smrgmsvcmsys)
604c37a63b8Smrg  # This case exists only to let depend.m4 do its work.  It works by
605c37a63b8Smrg  # looking at the text of this script.  This case will never be run,
606c37a63b8Smrg  # since it is checked for above.
607c37a63b8Smrg  exit 1
608c37a63b8Smrg  ;;
609c37a63b8Smrg
610264fa531Smrgnone)
611264fa531Smrg  exec "$@"
612264fa531Smrg  ;;
613264fa531Smrg
614264fa531Smrg*)
615264fa531Smrg  echo "Unknown depmode $depmode" 1>&2
616264fa531Smrg  exit 1
617264fa531Smrg  ;;
618264fa531Smrgesac
619264fa531Smrg
620264fa531Smrgexit 0
621c37a63b8Smrg
622c37a63b8Smrg# Local Variables:
623c37a63b8Smrg# mode: shell-script
624c37a63b8Smrg# sh-indentation: 2
625c37a63b8Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
626c37a63b8Smrg# time-stamp-start: "scriptversion="
627c37a63b8Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
628c37a63b8Smrg# time-stamp-time-zone: "UTC"
629c37a63b8Smrg# time-stamp-end: "; # UTC"
630c37a63b8Smrg# End:
631