depcomp revision 81c81b28
1af7c02bdSmrg#! /bin/sh
2af7c02bdSmrg# depcomp - compile a program generating dependencies as side-effects
3af7c02bdSmrg
481c81b28Smrgscriptversion=2009-04-28.21; # UTC
5af7c02bdSmrg
681c81b28Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
781c81b28Smrg# Software Foundation, Inc.
8af7c02bdSmrg
9af7c02bdSmrg# This program is free software; you can redistribute it and/or modify
10af7c02bdSmrg# it under the terms of the GNU General Public License as published by
11af7c02bdSmrg# the Free Software Foundation; either version 2, or (at your option)
12af7c02bdSmrg# any later version.
13af7c02bdSmrg
14af7c02bdSmrg# This program is distributed in the hope that it will be useful,
15af7c02bdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16af7c02bdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17af7c02bdSmrg# GNU General Public License for more details.
18af7c02bdSmrg
19af7c02bdSmrg# You should have received a copy of the GNU General Public License
2081c81b28Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21af7c02bdSmrg
22af7c02bdSmrg# As a special exception to the GNU General Public License, if you
23af7c02bdSmrg# distribute this file as part of a program that contains a
24af7c02bdSmrg# configuration script generated by Autoconf, you may include it under
25af7c02bdSmrg# the same distribution terms that you use for the rest of that program.
26af7c02bdSmrg
27af7c02bdSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28af7c02bdSmrg
29af7c02bdSmrgcase $1 in
30af7c02bdSmrg  '')
31af7c02bdSmrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
32af7c02bdSmrg     exit 1;
33af7c02bdSmrg     ;;
34af7c02bdSmrg  -h | --h*)
35af7c02bdSmrg    cat <<\EOF
36af7c02bdSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
37af7c02bdSmrg
38af7c02bdSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
39af7c02bdSmrgas side-effects.
40af7c02bdSmrg
41af7c02bdSmrgEnvironment variables:
42af7c02bdSmrg  depmode     Dependency tracking mode.
43af7c02bdSmrg  source      Source file read by `PROGRAMS ARGS'.
44af7c02bdSmrg  object      Object file output by `PROGRAMS ARGS'.
45af7c02bdSmrg  DEPDIR      directory where to store dependencies.
46af7c02bdSmrg  depfile     Dependency file to output.
47af7c02bdSmrg  tmpdepfile  Temporary file to use when outputing dependencies.
48af7c02bdSmrg  libtool     Whether libtool is used (yes/no).
49af7c02bdSmrg
50af7c02bdSmrgReport bugs to <bug-automake@gnu.org>.
51af7c02bdSmrgEOF
52af7c02bdSmrg    exit $?
53af7c02bdSmrg    ;;
54af7c02bdSmrg  -v | --v*)
55af7c02bdSmrg    echo "depcomp $scriptversion"
56af7c02bdSmrg    exit $?
57af7c02bdSmrg    ;;
58af7c02bdSmrgesac
59af7c02bdSmrg
60af7c02bdSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
61af7c02bdSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
62af7c02bdSmrg  exit 1
63af7c02bdSmrgfi
64af7c02bdSmrg
65af7c02bdSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
66af7c02bdSmrgdepfile=${depfile-`echo "$object" |
67af7c02bdSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
68af7c02bdSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
69af7c02bdSmrg
70af7c02bdSmrgrm -f "$tmpdepfile"
71af7c02bdSmrg
72af7c02bdSmrg# Some modes work just like other modes, but use different flags.  We
73af7c02bdSmrg# parameterize here, but still list the modes in the big case below,
74af7c02bdSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
75af7c02bdSmrg# here, because this file can only contain one case statement.
76af7c02bdSmrgif test "$depmode" = hp; then
77af7c02bdSmrg  # HP compiler uses -M and no extra arg.
78af7c02bdSmrg  gccflag=-M
79af7c02bdSmrg  depmode=gcc
80af7c02bdSmrgfi
81af7c02bdSmrg
82af7c02bdSmrgif test "$depmode" = dashXmstdout; then
83af7c02bdSmrg   # This is just like dashmstdout with a different argument.
84af7c02bdSmrg   dashmflag=-xM
85af7c02bdSmrg   depmode=dashmstdout
86af7c02bdSmrgfi
87af7c02bdSmrg
8881c81b28Smrgcygpath_u="cygpath -u -f -"
8981c81b28Smrgif test "$depmode" = msvcmsys; then
9081c81b28Smrg   # This is just like msvisualcpp but w/o cygpath translation.
9181c81b28Smrg   # Just convert the backslash-escaped backslashes to single forward
9281c81b28Smrg   # slashes to satisfy depend.m4
9381c81b28Smrg   cygpath_u="sed s,\\\\\\\\,/,g"
9481c81b28Smrg   depmode=msvisualcpp
9581c81b28Smrgfi
9681c81b28Smrg
97af7c02bdSmrgcase "$depmode" in
98af7c02bdSmrggcc3)
99af7c02bdSmrg## gcc 3 implements dependency tracking that does exactly what
100af7c02bdSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
101af7c02bdSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
10281c81b28Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
10381c81b28Smrg## the command line argument order; so add the flags where they
10481c81b28Smrg## appear in depend2.am.  Note that the slowdown incurred here
10581c81b28Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
10681c81b28Smrg  for arg
10781c81b28Smrg  do
10881c81b28Smrg    case $arg in
10981c81b28Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
11081c81b28Smrg    *)  set fnord "$@" "$arg" ;;
11181c81b28Smrg    esac
11281c81b28Smrg    shift # fnord
11381c81b28Smrg    shift # $arg
11481c81b28Smrg  done
11581c81b28Smrg  "$@"
116af7c02bdSmrg  stat=$?
117af7c02bdSmrg  if test $stat -eq 0; then :
118af7c02bdSmrg  else
119af7c02bdSmrg    rm -f "$tmpdepfile"
120af7c02bdSmrg    exit $stat
121af7c02bdSmrg  fi
122af7c02bdSmrg  mv "$tmpdepfile" "$depfile"
123af7c02bdSmrg  ;;
124af7c02bdSmrg
125af7c02bdSmrggcc)
126af7c02bdSmrg## There are various ways to get dependency output from gcc.  Here's
127af7c02bdSmrg## why we pick this rather obscure method:
128af7c02bdSmrg## - Don't want to use -MD because we'd like the dependencies to end
129af7c02bdSmrg##   up in a subdir.  Having to rename by hand is ugly.
130af7c02bdSmrg##   (We might end up doing this anyway to support other compilers.)
131af7c02bdSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
132af7c02bdSmrg##   -MM, not -M (despite what the docs say).
133af7c02bdSmrg## - Using -M directly means running the compiler twice (even worse
134af7c02bdSmrg##   than renaming).
135af7c02bdSmrg  if test -z "$gccflag"; then
136af7c02bdSmrg    gccflag=-MD,
137af7c02bdSmrg  fi
138af7c02bdSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
139af7c02bdSmrg  stat=$?
140af7c02bdSmrg  if test $stat -eq 0; then :
141af7c02bdSmrg  else
142af7c02bdSmrg    rm -f "$tmpdepfile"
143af7c02bdSmrg    exit $stat
144af7c02bdSmrg  fi
145af7c02bdSmrg  rm -f "$depfile"
146af7c02bdSmrg  echo "$object : \\" > "$depfile"
147af7c02bdSmrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
148af7c02bdSmrg## The second -e expression handles DOS-style file names with drive letters.
149af7c02bdSmrg  sed -e 's/^[^:]*: / /' \
150af7c02bdSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
151af7c02bdSmrg## This next piece of magic avoids the `deleted header file' problem.
152af7c02bdSmrg## The problem is that when a header file which appears in a .P file
153af7c02bdSmrg## is deleted, the dependency causes make to die (because there is
154af7c02bdSmrg## typically no way to rebuild the header).  We avoid this by adding
155af7c02bdSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
156af7c02bdSmrg## this for us directly.
157af7c02bdSmrg  tr ' ' '
158af7c02bdSmrg' < "$tmpdepfile" |
159af7c02bdSmrg## Some versions of gcc put a space before the `:'.  On the theory
160af7c02bdSmrg## that the space means something, we add a space to the output as
161af7c02bdSmrg## well.
162af7c02bdSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
163af7c02bdSmrg## correctly.  Breaking it into two sed invocations is a workaround.
164af7c02bdSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
165af7c02bdSmrg  rm -f "$tmpdepfile"
166af7c02bdSmrg  ;;
167af7c02bdSmrg
168af7c02bdSmrghp)
169af7c02bdSmrg  # This case exists only to let depend.m4 do its work.  It works by
170af7c02bdSmrg  # looking at the text of this script.  This case will never be run,
171af7c02bdSmrg  # since it is checked for above.
172af7c02bdSmrg  exit 1
173af7c02bdSmrg  ;;
174af7c02bdSmrg
175af7c02bdSmrgsgi)
176af7c02bdSmrg  if test "$libtool" = yes; then
177af7c02bdSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
178af7c02bdSmrg  else
179af7c02bdSmrg    "$@" -MDupdate "$tmpdepfile"
180af7c02bdSmrg  fi
181af7c02bdSmrg  stat=$?
182af7c02bdSmrg  if test $stat -eq 0; then :
183af7c02bdSmrg  else
184af7c02bdSmrg    rm -f "$tmpdepfile"
185af7c02bdSmrg    exit $stat
186af7c02bdSmrg  fi
187af7c02bdSmrg  rm -f "$depfile"
188af7c02bdSmrg
189af7c02bdSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
190af7c02bdSmrg    echo "$object : \\" > "$depfile"
191af7c02bdSmrg
192af7c02bdSmrg    # Clip off the initial element (the dependent).  Don't try to be
193af7c02bdSmrg    # clever and replace this with sed code, as IRIX sed won't handle
194af7c02bdSmrg    # lines with more than a fixed number of characters (4096 in
195af7c02bdSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
196af7c02bdSmrg    # the IRIX cc adds comments like `#:fec' to the end of the
197af7c02bdSmrg    # dependency line.
198af7c02bdSmrg    tr ' ' '
199af7c02bdSmrg' < "$tmpdepfile" \
200af7c02bdSmrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
201af7c02bdSmrg    tr '
20281c81b28Smrg' ' ' >> "$depfile"
20381c81b28Smrg    echo >> "$depfile"
204af7c02bdSmrg
205af7c02bdSmrg    # The second pass generates a dummy entry for each header file.
206af7c02bdSmrg    tr ' ' '
207af7c02bdSmrg' < "$tmpdepfile" \
208af7c02bdSmrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
20981c81b28Smrg   >> "$depfile"
210af7c02bdSmrg  else
211af7c02bdSmrg    # The sourcefile does not contain any dependencies, so just
212af7c02bdSmrg    # store a dummy comment line, to avoid errors with the Makefile
213af7c02bdSmrg    # "include basename.Plo" scheme.
214af7c02bdSmrg    echo "#dummy" > "$depfile"
215af7c02bdSmrg  fi
216af7c02bdSmrg  rm -f "$tmpdepfile"
217af7c02bdSmrg  ;;
218af7c02bdSmrg
219af7c02bdSmrgaix)
220af7c02bdSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
221af7c02bdSmrg  # in a .u file.  In older versions, this file always lives in the
222af7c02bdSmrg  # current directory.  Also, the AIX compiler puts `$object:' at the
223af7c02bdSmrg  # start of each line; $object doesn't have directory information.
224af7c02bdSmrg  # Version 6 uses the directory in both cases.
22581c81b28Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
22681c81b28Smrg  test "x$dir" = "x$object" && dir=
22781c81b28Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
228af7c02bdSmrg  if test "$libtool" = yes; then
22981c81b28Smrg    tmpdepfile1=$dir$base.u
23081c81b28Smrg    tmpdepfile2=$base.u
23181c81b28Smrg    tmpdepfile3=$dir.libs/$base.u
232af7c02bdSmrg    "$@" -Wc,-M
233af7c02bdSmrg  else
23481c81b28Smrg    tmpdepfile1=$dir$base.u
23581c81b28Smrg    tmpdepfile2=$dir$base.u
23681c81b28Smrg    tmpdepfile3=$dir$base.u
237af7c02bdSmrg    "$@" -M
238af7c02bdSmrg  fi
239af7c02bdSmrg  stat=$?
240af7c02bdSmrg
241af7c02bdSmrg  if test $stat -eq 0; then :
242af7c02bdSmrg  else
24381c81b28Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
244af7c02bdSmrg    exit $stat
245af7c02bdSmrg  fi
246af7c02bdSmrg
24781c81b28Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
24881c81b28Smrg  do
24981c81b28Smrg    test -f "$tmpdepfile" && break
25081c81b28Smrg  done
251af7c02bdSmrg  if test -f "$tmpdepfile"; then
252af7c02bdSmrg    # Each line is of the form `foo.o: dependent.h'.
253af7c02bdSmrg    # Do two passes, one to just change these to
254af7c02bdSmrg    # `$object: dependent.h' and one to simply `dependent.h:'.
25581c81b28Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
25681c81b28Smrg    # That's a tab and a space in the [].
25781c81b28Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
258af7c02bdSmrg  else
259af7c02bdSmrg    # The sourcefile does not contain any dependencies, so just
260af7c02bdSmrg    # store a dummy comment line, to avoid errors with the Makefile
261af7c02bdSmrg    # "include basename.Plo" scheme.
262af7c02bdSmrg    echo "#dummy" > "$depfile"
263af7c02bdSmrg  fi
264af7c02bdSmrg  rm -f "$tmpdepfile"
265af7c02bdSmrg  ;;
266af7c02bdSmrg
267af7c02bdSmrgicc)
268af7c02bdSmrg  # Intel's C compiler understands `-MD -MF file'.  However on
269af7c02bdSmrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
270af7c02bdSmrg  # ICC 7.0 will fill foo.d with something like
271af7c02bdSmrg  #    foo.o: sub/foo.c
272af7c02bdSmrg  #    foo.o: sub/foo.h
273af7c02bdSmrg  # which is wrong.  We want:
274af7c02bdSmrg  #    sub/foo.o: sub/foo.c
275af7c02bdSmrg  #    sub/foo.o: sub/foo.h
276af7c02bdSmrg  #    sub/foo.c:
277af7c02bdSmrg  #    sub/foo.h:
278af7c02bdSmrg  # ICC 7.1 will output
279af7c02bdSmrg  #    foo.o: sub/foo.c sub/foo.h
280af7c02bdSmrg  # and will wrap long lines using \ :
281af7c02bdSmrg  #    foo.o: sub/foo.c ... \
282af7c02bdSmrg  #     sub/foo.h ... \
283af7c02bdSmrg  #     ...
284af7c02bdSmrg
285af7c02bdSmrg  "$@" -MD -MF "$tmpdepfile"
286af7c02bdSmrg  stat=$?
287af7c02bdSmrg  if test $stat -eq 0; then :
288af7c02bdSmrg  else
289af7c02bdSmrg    rm -f "$tmpdepfile"
290af7c02bdSmrg    exit $stat
291af7c02bdSmrg  fi
292af7c02bdSmrg  rm -f "$depfile"
293af7c02bdSmrg  # Each line is of the form `foo.o: dependent.h',
294af7c02bdSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
295af7c02bdSmrg  # Do two passes, one to just change these to
296af7c02bdSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
297af7c02bdSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
298af7c02bdSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
299af7c02bdSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
300af7c02bdSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
301af7c02bdSmrg    sed -e 's/$/ :/' >> "$depfile"
302af7c02bdSmrg  rm -f "$tmpdepfile"
303af7c02bdSmrg  ;;
304af7c02bdSmrg
30581c81b28Smrghp2)
30681c81b28Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
30781c81b28Smrg  # compilers, which have integrated preprocessors.  The correct option
30881c81b28Smrg  # to use with these is +Maked; it writes dependencies to a file named
30981c81b28Smrg  # 'foo.d', which lands next to the object file, wherever that
31081c81b28Smrg  # happens to be.
31181c81b28Smrg  # Much of this is similar to the tru64 case; see comments there.
31281c81b28Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
31381c81b28Smrg  test "x$dir" = "x$object" && dir=
31481c81b28Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
31581c81b28Smrg  if test "$libtool" = yes; then
31681c81b28Smrg    tmpdepfile1=$dir$base.d
31781c81b28Smrg    tmpdepfile2=$dir.libs/$base.d
31881c81b28Smrg    "$@" -Wc,+Maked
31981c81b28Smrg  else
32081c81b28Smrg    tmpdepfile1=$dir$base.d
32181c81b28Smrg    tmpdepfile2=$dir$base.d
32281c81b28Smrg    "$@" +Maked
32381c81b28Smrg  fi
32481c81b28Smrg  stat=$?
32581c81b28Smrg  if test $stat -eq 0; then :
32681c81b28Smrg  else
32781c81b28Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
32881c81b28Smrg     exit $stat
32981c81b28Smrg  fi
33081c81b28Smrg
33181c81b28Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
33281c81b28Smrg  do
33381c81b28Smrg    test -f "$tmpdepfile" && break
33481c81b28Smrg  done
33581c81b28Smrg  if test -f "$tmpdepfile"; then
33681c81b28Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
33781c81b28Smrg    # Add `dependent.h:' lines.
33881c81b28Smrg    sed -ne '2,${
33981c81b28Smrg	       s/^ *//
34081c81b28Smrg	       s/ \\*$//
34181c81b28Smrg	       s/$/:/
34281c81b28Smrg	       p
34381c81b28Smrg	     }' "$tmpdepfile" >> "$depfile"
34481c81b28Smrg  else
34581c81b28Smrg    echo "#dummy" > "$depfile"
34681c81b28Smrg  fi
34781c81b28Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
34881c81b28Smrg  ;;
34981c81b28Smrg
350af7c02bdSmrgtru64)
351af7c02bdSmrg   # The Tru64 compiler uses -MD to generate dependencies as a side
352af7c02bdSmrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
353af7c02bdSmrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
354af7c02bdSmrg   # dependencies in `foo.d' instead, so we check for that too.
355af7c02bdSmrg   # Subdirectories are respected.
356af7c02bdSmrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
357af7c02bdSmrg   test "x$dir" = "x$object" && dir=
358af7c02bdSmrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
359af7c02bdSmrg
360af7c02bdSmrg   if test "$libtool" = yes; then
361af7c02bdSmrg      # With Tru64 cc, shared objects can also be used to make a
36281c81b28Smrg      # static library.  This mechanism is used in libtool 1.4 series to
363af7c02bdSmrg      # handle both shared and static libraries in a single compilation.
364af7c02bdSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
365af7c02bdSmrg      #
366af7c02bdSmrg      # With libtool 1.5 this exception was removed, and libtool now
367af7c02bdSmrg      # generates 2 separate objects for the 2 libraries.  These two
36881c81b28Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
369af7c02bdSmrg      # in $dir$base.o.d.  We have to check for both files, because
370af7c02bdSmrg      # one of the two compilations can be disabled.  We should prefer
371af7c02bdSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
372af7c02bdSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
373af7c02bdSmrg      # the former would cause a distcleancheck panic.
374af7c02bdSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
375af7c02bdSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
376af7c02bdSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
377af7c02bdSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
378af7c02bdSmrg      "$@" -Wc,-MD
379af7c02bdSmrg   else
380af7c02bdSmrg      tmpdepfile1=$dir$base.o.d
381af7c02bdSmrg      tmpdepfile2=$dir$base.d
382af7c02bdSmrg      tmpdepfile3=$dir$base.d
383af7c02bdSmrg      tmpdepfile4=$dir$base.d
384af7c02bdSmrg      "$@" -MD
385af7c02bdSmrg   fi
386af7c02bdSmrg
387af7c02bdSmrg   stat=$?
388af7c02bdSmrg   if test $stat -eq 0; then :
389af7c02bdSmrg   else
390af7c02bdSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
391af7c02bdSmrg      exit $stat
392af7c02bdSmrg   fi
393af7c02bdSmrg
394af7c02bdSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
395af7c02bdSmrg   do
396af7c02bdSmrg     test -f "$tmpdepfile" && break
397af7c02bdSmrg   done
398af7c02bdSmrg   if test -f "$tmpdepfile"; then
399af7c02bdSmrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
400af7c02bdSmrg      # That's a tab and a space in the [].
401af7c02bdSmrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
402af7c02bdSmrg   else
403af7c02bdSmrg      echo "#dummy" > "$depfile"
404af7c02bdSmrg   fi
405af7c02bdSmrg   rm -f "$tmpdepfile"
406af7c02bdSmrg   ;;
407af7c02bdSmrg
408af7c02bdSmrg#nosideeffect)
409af7c02bdSmrg  # This comment above is used by automake to tell side-effect
410af7c02bdSmrg  # dependency tracking mechanisms from slower ones.
411af7c02bdSmrg
412af7c02bdSmrgdashmstdout)
413af7c02bdSmrg  # Important note: in order to support this mode, a compiler *must*
414af7c02bdSmrg  # always write the preprocessed file to stdout, regardless of -o.
415af7c02bdSmrg  "$@" || exit $?
416af7c02bdSmrg
417af7c02bdSmrg  # Remove the call to Libtool.
418af7c02bdSmrg  if test "$libtool" = yes; then
41981c81b28Smrg    while test "X$1" != 'X--mode=compile'; do
420af7c02bdSmrg      shift
421af7c02bdSmrg    done
422af7c02bdSmrg    shift
423af7c02bdSmrg  fi
424af7c02bdSmrg
425af7c02bdSmrg  # Remove `-o $object'.
426af7c02bdSmrg  IFS=" "
427af7c02bdSmrg  for arg
428af7c02bdSmrg  do
429af7c02bdSmrg    case $arg in
430af7c02bdSmrg    -o)
431af7c02bdSmrg      shift
432af7c02bdSmrg      ;;
433af7c02bdSmrg    $object)
434af7c02bdSmrg      shift
435af7c02bdSmrg      ;;
436af7c02bdSmrg    *)
437af7c02bdSmrg      set fnord "$@" "$arg"
438af7c02bdSmrg      shift # fnord
439af7c02bdSmrg      shift # $arg
440af7c02bdSmrg      ;;
441af7c02bdSmrg    esac
442af7c02bdSmrg  done
443af7c02bdSmrg
444af7c02bdSmrg  test -z "$dashmflag" && dashmflag=-M
445af7c02bdSmrg  # Require at least two characters before searching for `:'
446af7c02bdSmrg  # in the target name.  This is to cope with DOS-style filenames:
447af7c02bdSmrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
448af7c02bdSmrg  "$@" $dashmflag |
449af7c02bdSmrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
450af7c02bdSmrg  rm -f "$depfile"
451af7c02bdSmrg  cat < "$tmpdepfile" > "$depfile"
452af7c02bdSmrg  tr ' ' '
453af7c02bdSmrg' < "$tmpdepfile" | \
454af7c02bdSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
455af7c02bdSmrg## correctly.  Breaking it into two sed invocations is a workaround.
456af7c02bdSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
457af7c02bdSmrg  rm -f "$tmpdepfile"
458af7c02bdSmrg  ;;
459af7c02bdSmrg
460af7c02bdSmrgdashXmstdout)
461af7c02bdSmrg  # This case only exists to satisfy depend.m4.  It is never actually
462af7c02bdSmrg  # run, as this mode is specially recognized in the preamble.
463af7c02bdSmrg  exit 1
464af7c02bdSmrg  ;;
465af7c02bdSmrg
466af7c02bdSmrgmakedepend)
467af7c02bdSmrg  "$@" || exit $?
468af7c02bdSmrg  # Remove any Libtool call
469af7c02bdSmrg  if test "$libtool" = yes; then
47081c81b28Smrg    while test "X$1" != 'X--mode=compile'; do
471af7c02bdSmrg      shift
472af7c02bdSmrg    done
473af7c02bdSmrg    shift
474af7c02bdSmrg  fi
475af7c02bdSmrg  # X makedepend
476af7c02bdSmrg  shift
47781c81b28Smrg  cleared=no eat=no
47881c81b28Smrg  for arg
47981c81b28Smrg  do
480af7c02bdSmrg    case $cleared in
481af7c02bdSmrg    no)
482af7c02bdSmrg      set ""; shift
483af7c02bdSmrg      cleared=yes ;;
484af7c02bdSmrg    esac
48581c81b28Smrg    if test $eat = yes; then
48681c81b28Smrg      eat=no
48781c81b28Smrg      continue
48881c81b28Smrg    fi
489af7c02bdSmrg    case "$arg" in
490af7c02bdSmrg    -D*|-I*)
491af7c02bdSmrg      set fnord "$@" "$arg"; shift ;;
492af7c02bdSmrg    # Strip any option that makedepend may not understand.  Remove
493af7c02bdSmrg    # the object too, otherwise makedepend will parse it as a source file.
49481c81b28Smrg    -arch)
49581c81b28Smrg      eat=yes ;;
496af7c02bdSmrg    -*|$object)
497af7c02bdSmrg      ;;
498af7c02bdSmrg    *)
499af7c02bdSmrg      set fnord "$@" "$arg"; shift ;;
500af7c02bdSmrg    esac
501af7c02bdSmrg  done
50281c81b28Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
503af7c02bdSmrg  touch "$tmpdepfile"
504af7c02bdSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
505af7c02bdSmrg  rm -f "$depfile"
506af7c02bdSmrg  cat < "$tmpdepfile" > "$depfile"
507af7c02bdSmrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
508af7c02bdSmrg' | \
509af7c02bdSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
510af7c02bdSmrg## correctly.  Breaking it into two sed invocations is a workaround.
511af7c02bdSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
512af7c02bdSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
513af7c02bdSmrg  ;;
514af7c02bdSmrg
515af7c02bdSmrgcpp)
516af7c02bdSmrg  # Important note: in order to support this mode, a compiler *must*
517af7c02bdSmrg  # always write the preprocessed file to stdout.
518af7c02bdSmrg  "$@" || exit $?
519af7c02bdSmrg
520af7c02bdSmrg  # Remove the call to Libtool.
521af7c02bdSmrg  if test "$libtool" = yes; then
52281c81b28Smrg    while test "X$1" != 'X--mode=compile'; do
523af7c02bdSmrg      shift
524af7c02bdSmrg    done
525af7c02bdSmrg    shift
526af7c02bdSmrg  fi
527af7c02bdSmrg
528af7c02bdSmrg  # Remove `-o $object'.
529af7c02bdSmrg  IFS=" "
530af7c02bdSmrg  for arg
531af7c02bdSmrg  do
532af7c02bdSmrg    case $arg in
533af7c02bdSmrg    -o)
534af7c02bdSmrg      shift
535af7c02bdSmrg      ;;
536af7c02bdSmrg    $object)
537af7c02bdSmrg      shift
538af7c02bdSmrg      ;;
539af7c02bdSmrg    *)
540af7c02bdSmrg      set fnord "$@" "$arg"
541af7c02bdSmrg      shift # fnord
542af7c02bdSmrg      shift # $arg
543af7c02bdSmrg      ;;
544af7c02bdSmrg    esac
545af7c02bdSmrg  done
546af7c02bdSmrg
547af7c02bdSmrg  "$@" -E |
548af7c02bdSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
549af7c02bdSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
550af7c02bdSmrg    sed '$ s: \\$::' > "$tmpdepfile"
551af7c02bdSmrg  rm -f "$depfile"
552af7c02bdSmrg  echo "$object : \\" > "$depfile"
553af7c02bdSmrg  cat < "$tmpdepfile" >> "$depfile"
554af7c02bdSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
555af7c02bdSmrg  rm -f "$tmpdepfile"
556af7c02bdSmrg  ;;
557af7c02bdSmrg
558af7c02bdSmrgmsvisualcpp)
559af7c02bdSmrg  # Important note: in order to support this mode, a compiler *must*
56081c81b28Smrg  # always write the preprocessed file to stdout.
561af7c02bdSmrg  "$@" || exit $?
56281c81b28Smrg
56381c81b28Smrg  # Remove the call to Libtool.
56481c81b28Smrg  if test "$libtool" = yes; then
56581c81b28Smrg    while test "X$1" != 'X--mode=compile'; do
56681c81b28Smrg      shift
56781c81b28Smrg    done
56881c81b28Smrg    shift
56981c81b28Smrg  fi
57081c81b28Smrg
571af7c02bdSmrg  IFS=" "
572af7c02bdSmrg  for arg
573af7c02bdSmrg  do
574af7c02bdSmrg    case "$arg" in
57581c81b28Smrg    -o)
57681c81b28Smrg      shift
57781c81b28Smrg      ;;
57881c81b28Smrg    $object)
57981c81b28Smrg      shift
58081c81b28Smrg      ;;
581af7c02bdSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
582af7c02bdSmrg	set fnord "$@"
583af7c02bdSmrg	shift
584af7c02bdSmrg	shift
585af7c02bdSmrg	;;
586af7c02bdSmrg    *)
587af7c02bdSmrg	set fnord "$@" "$arg"
588af7c02bdSmrg	shift
589af7c02bdSmrg	shift
590af7c02bdSmrg	;;
591af7c02bdSmrg    esac
592af7c02bdSmrg  done
59381c81b28Smrg  "$@" -E 2>/dev/null |
59481c81b28Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
595af7c02bdSmrg  rm -f "$depfile"
596af7c02bdSmrg  echo "$object : \\" > "$depfile"
59781c81b28Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
598af7c02bdSmrg  echo "	" >> "$depfile"
59981c81b28Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
600af7c02bdSmrg  rm -f "$tmpdepfile"
601af7c02bdSmrg  ;;
602af7c02bdSmrg
60381c81b28Smrgmsvcmsys)
60481c81b28Smrg  # This case exists only to let depend.m4 do its work.  It works by
60581c81b28Smrg  # looking at the text of this script.  This case will never be run,
60681c81b28Smrg  # since it is checked for above.
60781c81b28Smrg  exit 1
60881c81b28Smrg  ;;
60981c81b28Smrg
610af7c02bdSmrgnone)
611af7c02bdSmrg  exec "$@"
612af7c02bdSmrg  ;;
613af7c02bdSmrg
614af7c02bdSmrg*)
615af7c02bdSmrg  echo "Unknown depmode $depmode" 1>&2
616af7c02bdSmrg  exit 1
617af7c02bdSmrg  ;;
618af7c02bdSmrgesac
619af7c02bdSmrg
620af7c02bdSmrgexit 0
621af7c02bdSmrg
622af7c02bdSmrg# Local Variables:
623af7c02bdSmrg# mode: shell-script
624af7c02bdSmrg# sh-indentation: 2
625af7c02bdSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
626af7c02bdSmrg# time-stamp-start: "scriptversion="
627af7c02bdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
62881c81b28Smrg# time-stamp-time-zone: "UTC"
62981c81b28Smrg# time-stamp-end: "; # UTC"
630af7c02bdSmrg# End:
631