depcomp revision 7e4fd55a
1b8f75c19Smrg#! /bin/sh
2b8f75c19Smrg# depcomp - compile a program generating dependencies as side-effects
37e4fd55aSmrg
47e4fd55aSmrgscriptversion=2009-04-28.21; # UTC
57e4fd55aSmrg
67e4fd55aSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
77e4fd55aSmrg# Software Foundation, Inc.
8b8f75c19Smrg
9b8f75c19Smrg# This program is free software; you can redistribute it and/or modify
10b8f75c19Smrg# it under the terms of the GNU General Public License as published by
11b8f75c19Smrg# the Free Software Foundation; either version 2, or (at your option)
12b8f75c19Smrg# any later version.
13b8f75c19Smrg
14b8f75c19Smrg# This program is distributed in the hope that it will be useful,
15b8f75c19Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16b8f75c19Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17b8f75c19Smrg# GNU General Public License for more details.
18b8f75c19Smrg
19b8f75c19Smrg# You should have received a copy of the GNU General Public License
207e4fd55aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21b8f75c19Smrg
22b8f75c19Smrg# As a special exception to the GNU General Public License, if you
23b8f75c19Smrg# distribute this file as part of a program that contains a
24b8f75c19Smrg# configuration script generated by Autoconf, you may include it under
25b8f75c19Smrg# the same distribution terms that you use for the rest of that program.
26b8f75c19Smrg
27b8f75c19Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28b8f75c19Smrg
297e4fd55aSmrgcase $1 in
307e4fd55aSmrg  '')
317e4fd55aSmrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
327e4fd55aSmrg     exit 1;
337e4fd55aSmrg     ;;
347e4fd55aSmrg  -h | --h*)
357e4fd55aSmrg    cat <<\EOF
367e4fd55aSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
377e4fd55aSmrg
387e4fd55aSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
397e4fd55aSmrgas side-effects.
407e4fd55aSmrg
417e4fd55aSmrgEnvironment variables:
427e4fd55aSmrg  depmode     Dependency tracking mode.
437e4fd55aSmrg  source      Source file read by `PROGRAMS ARGS'.
447e4fd55aSmrg  object      Object file output by `PROGRAMS ARGS'.
457e4fd55aSmrg  DEPDIR      directory where to store dependencies.
467e4fd55aSmrg  depfile     Dependency file to output.
477e4fd55aSmrg  tmpdepfile  Temporary file to use when outputing dependencies.
487e4fd55aSmrg  libtool     Whether libtool is used (yes/no).
497e4fd55aSmrg
507e4fd55aSmrgReport bugs to <bug-automake@gnu.org>.
517e4fd55aSmrgEOF
527e4fd55aSmrg    exit $?
537e4fd55aSmrg    ;;
547e4fd55aSmrg  -v | --v*)
557e4fd55aSmrg    echo "depcomp $scriptversion"
567e4fd55aSmrg    exit $?
577e4fd55aSmrg    ;;
587e4fd55aSmrgesac
597e4fd55aSmrg
60b8f75c19Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
61b8f75c19Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
62b8f75c19Smrg  exit 1
63b8f75c19Smrgfi
64b8f75c19Smrg
657e4fd55aSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
667e4fd55aSmrgdepfile=${depfile-`echo "$object" |
677e4fd55aSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
68b8f75c19Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
69b8f75c19Smrg
70b8f75c19Smrgrm -f "$tmpdepfile"
71b8f75c19Smrg
72b8f75c19Smrg# Some modes work just like other modes, but use different flags.  We
73b8f75c19Smrg# parameterize here, but still list the modes in the big case below,
74b8f75c19Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
75b8f75c19Smrg# here, because this file can only contain one case statement.
76b8f75c19Smrgif test "$depmode" = hp; then
77b8f75c19Smrg  # HP compiler uses -M and no extra arg.
78b8f75c19Smrg  gccflag=-M
79b8f75c19Smrg  depmode=gcc
80b8f75c19Smrgfi
81b8f75c19Smrg
82b8f75c19Smrgif test "$depmode" = dashXmstdout; then
83b8f75c19Smrg   # This is just like dashmstdout with a different argument.
84b8f75c19Smrg   dashmflag=-xM
85b8f75c19Smrg   depmode=dashmstdout
86b8f75c19Smrgfi
87b8f75c19Smrg
887e4fd55aSmrgcygpath_u="cygpath -u -f -"
897e4fd55aSmrgif test "$depmode" = msvcmsys; then
907e4fd55aSmrg   # This is just like msvisualcpp but w/o cygpath translation.
917e4fd55aSmrg   # Just convert the backslash-escaped backslashes to single forward
927e4fd55aSmrg   # slashes to satisfy depend.m4
937e4fd55aSmrg   cygpath_u="sed s,\\\\\\\\,/,g"
947e4fd55aSmrg   depmode=msvisualcpp
957e4fd55aSmrgfi
967e4fd55aSmrg
97b8f75c19Smrgcase "$depmode" in
98b8f75c19Smrggcc3)
99b8f75c19Smrg## gcc 3 implements dependency tracking that does exactly what
100b8f75c19Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
101b8f75c19Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1027e4fd55aSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1037e4fd55aSmrg## the command line argument order; so add the flags where they
1047e4fd55aSmrg## appear in depend2.am.  Note that the slowdown incurred here
1057e4fd55aSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1067e4fd55aSmrg  for arg
1077e4fd55aSmrg  do
1087e4fd55aSmrg    case $arg in
1097e4fd55aSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1107e4fd55aSmrg    *)  set fnord "$@" "$arg" ;;
1117e4fd55aSmrg    esac
1127e4fd55aSmrg    shift # fnord
1137e4fd55aSmrg    shift # $arg
1147e4fd55aSmrg  done
1157e4fd55aSmrg  "$@"
116b8f75c19Smrg  stat=$?
117b8f75c19Smrg  if test $stat -eq 0; then :
118b8f75c19Smrg  else
119b8f75c19Smrg    rm -f "$tmpdepfile"
120b8f75c19Smrg    exit $stat
121b8f75c19Smrg  fi
122b8f75c19Smrg  mv "$tmpdepfile" "$depfile"
123b8f75c19Smrg  ;;
124b8f75c19Smrg
125b8f75c19Smrggcc)
126b8f75c19Smrg## There are various ways to get dependency output from gcc.  Here's
127b8f75c19Smrg## why we pick this rather obscure method:
128b8f75c19Smrg## - Don't want to use -MD because we'd like the dependencies to end
129b8f75c19Smrg##   up in a subdir.  Having to rename by hand is ugly.
130b8f75c19Smrg##   (We might end up doing this anyway to support other compilers.)
131b8f75c19Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
132b8f75c19Smrg##   -MM, not -M (despite what the docs say).
133b8f75c19Smrg## - Using -M directly means running the compiler twice (even worse
134b8f75c19Smrg##   than renaming).
135b8f75c19Smrg  if test -z "$gccflag"; then
136b8f75c19Smrg    gccflag=-MD,
137b8f75c19Smrg  fi
138b8f75c19Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
139b8f75c19Smrg  stat=$?
140b8f75c19Smrg  if test $stat -eq 0; then :
141b8f75c19Smrg  else
142b8f75c19Smrg    rm -f "$tmpdepfile"
143b8f75c19Smrg    exit $stat
144b8f75c19Smrg  fi
145b8f75c19Smrg  rm -f "$depfile"
146b8f75c19Smrg  echo "$object : \\" > "$depfile"
147b8f75c19Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
148b8f75c19Smrg## The second -e expression handles DOS-style file names with drive letters.
149b8f75c19Smrg  sed -e 's/^[^:]*: / /' \
150b8f75c19Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
151b8f75c19Smrg## This next piece of magic avoids the `deleted header file' problem.
152b8f75c19Smrg## The problem is that when a header file which appears in a .P file
153b8f75c19Smrg## is deleted, the dependency causes make to die (because there is
154b8f75c19Smrg## typically no way to rebuild the header).  We avoid this by adding
155b8f75c19Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
156b8f75c19Smrg## this for us directly.
157b8f75c19Smrg  tr ' ' '
158b8f75c19Smrg' < "$tmpdepfile" |
159b8f75c19Smrg## Some versions of gcc put a space before the `:'.  On the theory
160b8f75c19Smrg## that the space means something, we add a space to the output as
161b8f75c19Smrg## well.
162b8f75c19Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
163b8f75c19Smrg## correctly.  Breaking it into two sed invocations is a workaround.
164b8f75c19Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
165b8f75c19Smrg  rm -f "$tmpdepfile"
166b8f75c19Smrg  ;;
167b8f75c19Smrg
168b8f75c19Smrghp)
169b8f75c19Smrg  # This case exists only to let depend.m4 do its work.  It works by
170b8f75c19Smrg  # looking at the text of this script.  This case will never be run,
171b8f75c19Smrg  # since it is checked for above.
172b8f75c19Smrg  exit 1
173b8f75c19Smrg  ;;
174b8f75c19Smrg
175b8f75c19Smrgsgi)
176b8f75c19Smrg  if test "$libtool" = yes; then
177b8f75c19Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
178b8f75c19Smrg  else
179b8f75c19Smrg    "$@" -MDupdate "$tmpdepfile"
180b8f75c19Smrg  fi
181b8f75c19Smrg  stat=$?
182b8f75c19Smrg  if test $stat -eq 0; then :
183b8f75c19Smrg  else
184b8f75c19Smrg    rm -f "$tmpdepfile"
185b8f75c19Smrg    exit $stat
186b8f75c19Smrg  fi
187b8f75c19Smrg  rm -f "$depfile"
188b8f75c19Smrg
189b8f75c19Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
190b8f75c19Smrg    echo "$object : \\" > "$depfile"
191b8f75c19Smrg
192b8f75c19Smrg    # Clip off the initial element (the dependent).  Don't try to be
193b8f75c19Smrg    # clever and replace this with sed code, as IRIX sed won't handle
194b8f75c19Smrg    # lines with more than a fixed number of characters (4096 in
195b8f75c19Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
196b8f75c19Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
197b8f75c19Smrg    # dependency line.
198b8f75c19Smrg    tr ' ' '
199b8f75c19Smrg' < "$tmpdepfile" \
200b8f75c19Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
201b8f75c19Smrg    tr '
2027e4fd55aSmrg' ' ' >> "$depfile"
2037e4fd55aSmrg    echo >> "$depfile"
204b8f75c19Smrg
205b8f75c19Smrg    # The second pass generates a dummy entry for each header file.
206b8f75c19Smrg    tr ' ' '
207b8f75c19Smrg' < "$tmpdepfile" \
208b8f75c19Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2097e4fd55aSmrg   >> "$depfile"
210b8f75c19Smrg  else
211b8f75c19Smrg    # The sourcefile does not contain any dependencies, so just
212b8f75c19Smrg    # store a dummy comment line, to avoid errors with the Makefile
213b8f75c19Smrg    # "include basename.Plo" scheme.
214b8f75c19Smrg    echo "#dummy" > "$depfile"
215b8f75c19Smrg  fi
216b8f75c19Smrg  rm -f "$tmpdepfile"
217b8f75c19Smrg  ;;
218b8f75c19Smrg
219b8f75c19Smrgaix)
220b8f75c19Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
221b8f75c19Smrg  # in a .u file.  In older versions, this file always lives in the
222b8f75c19Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
223b8f75c19Smrg  # start of each line; $object doesn't have directory information.
224b8f75c19Smrg  # Version 6 uses the directory in both cases.
2257e4fd55aSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
2267e4fd55aSmrg  test "x$dir" = "x$object" && dir=
2277e4fd55aSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
228b8f75c19Smrg  if test "$libtool" = yes; then
2297e4fd55aSmrg    tmpdepfile1=$dir$base.u
2307e4fd55aSmrg    tmpdepfile2=$base.u
2317e4fd55aSmrg    tmpdepfile3=$dir.libs/$base.u
232b8f75c19Smrg    "$@" -Wc,-M
233b8f75c19Smrg  else
2347e4fd55aSmrg    tmpdepfile1=$dir$base.u
2357e4fd55aSmrg    tmpdepfile2=$dir$base.u
2367e4fd55aSmrg    tmpdepfile3=$dir$base.u
237b8f75c19Smrg    "$@" -M
238b8f75c19Smrg  fi
239b8f75c19Smrg  stat=$?
240b8f75c19Smrg
241b8f75c19Smrg  if test $stat -eq 0; then :
242b8f75c19Smrg  else
2437e4fd55aSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
244b8f75c19Smrg    exit $stat
245b8f75c19Smrg  fi
246b8f75c19Smrg
2477e4fd55aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
2487e4fd55aSmrg  do
2497e4fd55aSmrg    test -f "$tmpdepfile" && break
2507e4fd55aSmrg  done
251b8f75c19Smrg  if test -f "$tmpdepfile"; then
252b8f75c19Smrg    # Each line is of the form `foo.o: dependent.h'.
253b8f75c19Smrg    # Do two passes, one to just change these to
254b8f75c19Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
2557e4fd55aSmrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
2567e4fd55aSmrg    # That's a tab and a space in the [].
2577e4fd55aSmrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
258b8f75c19Smrg  else
259b8f75c19Smrg    # The sourcefile does not contain any dependencies, so just
260b8f75c19Smrg    # store a dummy comment line, to avoid errors with the Makefile
261b8f75c19Smrg    # "include basename.Plo" scheme.
262b8f75c19Smrg    echo "#dummy" > "$depfile"
263b8f75c19Smrg  fi
264b8f75c19Smrg  rm -f "$tmpdepfile"
265b8f75c19Smrg  ;;
266b8f75c19Smrg
267b8f75c19Smrgicc)
268b8f75c19Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
269b8f75c19Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
270b8f75c19Smrg  # ICC 7.0 will fill foo.d with something like
271b8f75c19Smrg  #    foo.o: sub/foo.c
272b8f75c19Smrg  #    foo.o: sub/foo.h
273b8f75c19Smrg  # which is wrong.  We want:
274b8f75c19Smrg  #    sub/foo.o: sub/foo.c
275b8f75c19Smrg  #    sub/foo.o: sub/foo.h
276b8f75c19Smrg  #    sub/foo.c:
277b8f75c19Smrg  #    sub/foo.h:
278b8f75c19Smrg  # ICC 7.1 will output
279b8f75c19Smrg  #    foo.o: sub/foo.c sub/foo.h
280b8f75c19Smrg  # and will wrap long lines using \ :
281b8f75c19Smrg  #    foo.o: sub/foo.c ... \
282b8f75c19Smrg  #     sub/foo.h ... \
283b8f75c19Smrg  #     ...
284b8f75c19Smrg
285b8f75c19Smrg  "$@" -MD -MF "$tmpdepfile"
286b8f75c19Smrg  stat=$?
287b8f75c19Smrg  if test $stat -eq 0; then :
288b8f75c19Smrg  else
289b8f75c19Smrg    rm -f "$tmpdepfile"
290b8f75c19Smrg    exit $stat
291b8f75c19Smrg  fi
292b8f75c19Smrg  rm -f "$depfile"
293b8f75c19Smrg  # Each line is of the form `foo.o: dependent.h',
294b8f75c19Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
295b8f75c19Smrg  # Do two passes, one to just change these to
296b8f75c19Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
297b8f75c19Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
298b8f75c19Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
299b8f75c19Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
300b8f75c19Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
301b8f75c19Smrg    sed -e 's/$/ :/' >> "$depfile"
302b8f75c19Smrg  rm -f "$tmpdepfile"
303b8f75c19Smrg  ;;
304b8f75c19Smrg
3057e4fd55aSmrghp2)
3067e4fd55aSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
3077e4fd55aSmrg  # compilers, which have integrated preprocessors.  The correct option
3087e4fd55aSmrg  # to use with these is +Maked; it writes dependencies to a file named
3097e4fd55aSmrg  # 'foo.d', which lands next to the object file, wherever that
3107e4fd55aSmrg  # happens to be.
3117e4fd55aSmrg  # Much of this is similar to the tru64 case; see comments there.
3127e4fd55aSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
3137e4fd55aSmrg  test "x$dir" = "x$object" && dir=
3147e4fd55aSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
3157e4fd55aSmrg  if test "$libtool" = yes; then
3167e4fd55aSmrg    tmpdepfile1=$dir$base.d
3177e4fd55aSmrg    tmpdepfile2=$dir.libs/$base.d
3187e4fd55aSmrg    "$@" -Wc,+Maked
3197e4fd55aSmrg  else
3207e4fd55aSmrg    tmpdepfile1=$dir$base.d
3217e4fd55aSmrg    tmpdepfile2=$dir$base.d
3227e4fd55aSmrg    "$@" +Maked
3237e4fd55aSmrg  fi
3247e4fd55aSmrg  stat=$?
3257e4fd55aSmrg  if test $stat -eq 0; then :
3267e4fd55aSmrg  else
3277e4fd55aSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
3287e4fd55aSmrg     exit $stat
3297e4fd55aSmrg  fi
3307e4fd55aSmrg
3317e4fd55aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
3327e4fd55aSmrg  do
3337e4fd55aSmrg    test -f "$tmpdepfile" && break
3347e4fd55aSmrg  done
3357e4fd55aSmrg  if test -f "$tmpdepfile"; then
3367e4fd55aSmrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
3377e4fd55aSmrg    # Add `dependent.h:' lines.
3387e4fd55aSmrg    sed -ne '2,${
3397e4fd55aSmrg	       s/^ *//
3407e4fd55aSmrg	       s/ \\*$//
3417e4fd55aSmrg	       s/$/:/
3427e4fd55aSmrg	       p
3437e4fd55aSmrg	     }' "$tmpdepfile" >> "$depfile"
3447e4fd55aSmrg  else
3457e4fd55aSmrg    echo "#dummy" > "$depfile"
3467e4fd55aSmrg  fi
3477e4fd55aSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
3487e4fd55aSmrg  ;;
3497e4fd55aSmrg
350b8f75c19Smrgtru64)
351b8f75c19Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
352b8f75c19Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
353b8f75c19Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
354b8f75c19Smrg   # dependencies in `foo.d' instead, so we check for that too.
355b8f75c19Smrg   # Subdirectories are respected.
356b8f75c19Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
357b8f75c19Smrg   test "x$dir" = "x$object" && dir=
358b8f75c19Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
359b8f75c19Smrg
360b8f75c19Smrg   if test "$libtool" = yes; then
3617e4fd55aSmrg      # With Tru64 cc, shared objects can also be used to make a
3627e4fd55aSmrg      # static library.  This mechanism is used in libtool 1.4 series to
3637e4fd55aSmrg      # handle both shared and static libraries in a single compilation.
3647e4fd55aSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
3657e4fd55aSmrg      #
3667e4fd55aSmrg      # With libtool 1.5 this exception was removed, and libtool now
3677e4fd55aSmrg      # generates 2 separate objects for the 2 libraries.  These two
3687e4fd55aSmrg      # compilations output dependencies in $dir.libs/$base.o.d and
3697e4fd55aSmrg      # in $dir$base.o.d.  We have to check for both files, because
3707e4fd55aSmrg      # one of the two compilations can be disabled.  We should prefer
3717e4fd55aSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
3727e4fd55aSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
3737e4fd55aSmrg      # the former would cause a distcleancheck panic.
3747e4fd55aSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
3757e4fd55aSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
3767e4fd55aSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
3777e4fd55aSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
378b8f75c19Smrg      "$@" -Wc,-MD
379b8f75c19Smrg   else
3807e4fd55aSmrg      tmpdepfile1=$dir$base.o.d
3817e4fd55aSmrg      tmpdepfile2=$dir$base.d
3827e4fd55aSmrg      tmpdepfile3=$dir$base.d
3837e4fd55aSmrg      tmpdepfile4=$dir$base.d
384b8f75c19Smrg      "$@" -MD
385b8f75c19Smrg   fi
386b8f75c19Smrg
387b8f75c19Smrg   stat=$?
388b8f75c19Smrg   if test $stat -eq 0; then :
389b8f75c19Smrg   else
3907e4fd55aSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
391b8f75c19Smrg      exit $stat
392b8f75c19Smrg   fi
393b8f75c19Smrg
3947e4fd55aSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
3957e4fd55aSmrg   do
3967e4fd55aSmrg     test -f "$tmpdepfile" && break
3977e4fd55aSmrg   done
398b8f75c19Smrg   if test -f "$tmpdepfile"; then
399b8f75c19Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
400b8f75c19Smrg      # That's a tab and a space in the [].
401b8f75c19Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
402b8f75c19Smrg   else
403b8f75c19Smrg      echo "#dummy" > "$depfile"
404b8f75c19Smrg   fi
405b8f75c19Smrg   rm -f "$tmpdepfile"
406b8f75c19Smrg   ;;
407b8f75c19Smrg
408b8f75c19Smrg#nosideeffect)
409b8f75c19Smrg  # This comment above is used by automake to tell side-effect
410b8f75c19Smrg  # dependency tracking mechanisms from slower ones.
411b8f75c19Smrg
412b8f75c19Smrgdashmstdout)
413b8f75c19Smrg  # Important note: in order to support this mode, a compiler *must*
414b8f75c19Smrg  # always write the preprocessed file to stdout, regardless of -o.
415b8f75c19Smrg  "$@" || exit $?
416b8f75c19Smrg
417b8f75c19Smrg  # Remove the call to Libtool.
418b8f75c19Smrg  if test "$libtool" = yes; then
4197e4fd55aSmrg    while test "X$1" != 'X--mode=compile'; do
420b8f75c19Smrg      shift
421b8f75c19Smrg    done
422b8f75c19Smrg    shift
423b8f75c19Smrg  fi
424b8f75c19Smrg
425b8f75c19Smrg  # Remove `-o $object'.
426b8f75c19Smrg  IFS=" "
427b8f75c19Smrg  for arg
428b8f75c19Smrg  do
429b8f75c19Smrg    case $arg in
430b8f75c19Smrg    -o)
431b8f75c19Smrg      shift
432b8f75c19Smrg      ;;
433b8f75c19Smrg    $object)
434b8f75c19Smrg      shift
435b8f75c19Smrg      ;;
436b8f75c19Smrg    *)
437b8f75c19Smrg      set fnord "$@" "$arg"
438b8f75c19Smrg      shift # fnord
439b8f75c19Smrg      shift # $arg
440b8f75c19Smrg      ;;
441b8f75c19Smrg    esac
442b8f75c19Smrg  done
443b8f75c19Smrg
444b8f75c19Smrg  test -z "$dashmflag" && dashmflag=-M
445b8f75c19Smrg  # Require at least two characters before searching for `:'
446b8f75c19Smrg  # in the target name.  This is to cope with DOS-style filenames:
447b8f75c19Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
448b8f75c19Smrg  "$@" $dashmflag |
449b8f75c19Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
450b8f75c19Smrg  rm -f "$depfile"
451b8f75c19Smrg  cat < "$tmpdepfile" > "$depfile"
452b8f75c19Smrg  tr ' ' '
453b8f75c19Smrg' < "$tmpdepfile" | \
454b8f75c19Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
455b8f75c19Smrg## correctly.  Breaking it into two sed invocations is a workaround.
456b8f75c19Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
457b8f75c19Smrg  rm -f "$tmpdepfile"
458b8f75c19Smrg  ;;
459b8f75c19Smrg
460b8f75c19SmrgdashXmstdout)
461b8f75c19Smrg  # This case only exists to satisfy depend.m4.  It is never actually
462b8f75c19Smrg  # run, as this mode is specially recognized in the preamble.
463b8f75c19Smrg  exit 1
464b8f75c19Smrg  ;;
465b8f75c19Smrg
466b8f75c19Smrgmakedepend)
467b8f75c19Smrg  "$@" || exit $?
468b8f75c19Smrg  # Remove any Libtool call
469b8f75c19Smrg  if test "$libtool" = yes; then
4707e4fd55aSmrg    while test "X$1" != 'X--mode=compile'; do
471b8f75c19Smrg      shift
472b8f75c19Smrg    done
473b8f75c19Smrg    shift
474b8f75c19Smrg  fi
475b8f75c19Smrg  # X makedepend
476b8f75c19Smrg  shift
4777e4fd55aSmrg  cleared=no eat=no
4787e4fd55aSmrg  for arg
4797e4fd55aSmrg  do
480b8f75c19Smrg    case $cleared in
481b8f75c19Smrg    no)
482b8f75c19Smrg      set ""; shift
483b8f75c19Smrg      cleared=yes ;;
484b8f75c19Smrg    esac
4857e4fd55aSmrg    if test $eat = yes; then
4867e4fd55aSmrg      eat=no
4877e4fd55aSmrg      continue
4887e4fd55aSmrg    fi
489b8f75c19Smrg    case "$arg" in
490b8f75c19Smrg    -D*|-I*)
491b8f75c19Smrg      set fnord "$@" "$arg"; shift ;;
492b8f75c19Smrg    # Strip any option that makedepend may not understand.  Remove
493b8f75c19Smrg    # the object too, otherwise makedepend will parse it as a source file.
4947e4fd55aSmrg    -arch)
4957e4fd55aSmrg      eat=yes ;;
496b8f75c19Smrg    -*|$object)
497b8f75c19Smrg      ;;
498b8f75c19Smrg    *)
499b8f75c19Smrg      set fnord "$@" "$arg"; shift ;;
500b8f75c19Smrg    esac
501b8f75c19Smrg  done
5027e4fd55aSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
503b8f75c19Smrg  touch "$tmpdepfile"
504b8f75c19Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
505b8f75c19Smrg  rm -f "$depfile"
506b8f75c19Smrg  cat < "$tmpdepfile" > "$depfile"
507b8f75c19Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
508b8f75c19Smrg' | \
509b8f75c19Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
510b8f75c19Smrg## correctly.  Breaking it into two sed invocations is a workaround.
511b8f75c19Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
512b8f75c19Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
513b8f75c19Smrg  ;;
514b8f75c19Smrg
515b8f75c19Smrgcpp)
516b8f75c19Smrg  # Important note: in order to support this mode, a compiler *must*
517b8f75c19Smrg  # always write the preprocessed file to stdout.
518b8f75c19Smrg  "$@" || exit $?
519b8f75c19Smrg
520b8f75c19Smrg  # Remove the call to Libtool.
521b8f75c19Smrg  if test "$libtool" = yes; then
5227e4fd55aSmrg    while test "X$1" != 'X--mode=compile'; do
523b8f75c19Smrg      shift
524b8f75c19Smrg    done
525b8f75c19Smrg    shift
526b8f75c19Smrg  fi
527b8f75c19Smrg
528b8f75c19Smrg  # Remove `-o $object'.
529b8f75c19Smrg  IFS=" "
530b8f75c19Smrg  for arg
531b8f75c19Smrg  do
532b8f75c19Smrg    case $arg in
533b8f75c19Smrg    -o)
534b8f75c19Smrg      shift
535b8f75c19Smrg      ;;
536b8f75c19Smrg    $object)
537b8f75c19Smrg      shift
538b8f75c19Smrg      ;;
539b8f75c19Smrg    *)
540b8f75c19Smrg      set fnord "$@" "$arg"
541b8f75c19Smrg      shift # fnord
542b8f75c19Smrg      shift # $arg
543b8f75c19Smrg      ;;
544b8f75c19Smrg    esac
545b8f75c19Smrg  done
546b8f75c19Smrg
547b8f75c19Smrg  "$@" -E |
5487e4fd55aSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
5497e4fd55aSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
550b8f75c19Smrg    sed '$ s: \\$::' > "$tmpdepfile"
551b8f75c19Smrg  rm -f "$depfile"
552b8f75c19Smrg  echo "$object : \\" > "$depfile"
553b8f75c19Smrg  cat < "$tmpdepfile" >> "$depfile"
554b8f75c19Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
555b8f75c19Smrg  rm -f "$tmpdepfile"
556b8f75c19Smrg  ;;
557b8f75c19Smrg
558b8f75c19Smrgmsvisualcpp)
559b8f75c19Smrg  # Important note: in order to support this mode, a compiler *must*
5607e4fd55aSmrg  # always write the preprocessed file to stdout.
561b8f75c19Smrg  "$@" || exit $?
5627e4fd55aSmrg
5637e4fd55aSmrg  # Remove the call to Libtool.
5647e4fd55aSmrg  if test "$libtool" = yes; then
5657e4fd55aSmrg    while test "X$1" != 'X--mode=compile'; do
5667e4fd55aSmrg      shift
5677e4fd55aSmrg    done
5687e4fd55aSmrg    shift
5697e4fd55aSmrg  fi
5707e4fd55aSmrg
571b8f75c19Smrg  IFS=" "
572b8f75c19Smrg  for arg
573b8f75c19Smrg  do
574b8f75c19Smrg    case "$arg" in
5757e4fd55aSmrg    -o)
5767e4fd55aSmrg      shift
5777e4fd55aSmrg      ;;
5787e4fd55aSmrg    $object)
5797e4fd55aSmrg      shift
5807e4fd55aSmrg      ;;
581b8f75c19Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
582b8f75c19Smrg	set fnord "$@"
583b8f75c19Smrg	shift
584b8f75c19Smrg	shift
585b8f75c19Smrg	;;
586b8f75c19Smrg    *)
587b8f75c19Smrg	set fnord "$@" "$arg"
588b8f75c19Smrg	shift
589b8f75c19Smrg	shift
590b8f75c19Smrg	;;
591b8f75c19Smrg    esac
592b8f75c19Smrg  done
5937e4fd55aSmrg  "$@" -E 2>/dev/null |
5947e4fd55aSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
595b8f75c19Smrg  rm -f "$depfile"
596b8f75c19Smrg  echo "$object : \\" > "$depfile"
5977e4fd55aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
598b8f75c19Smrg  echo "	" >> "$depfile"
5997e4fd55aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
600b8f75c19Smrg  rm -f "$tmpdepfile"
601b8f75c19Smrg  ;;
602b8f75c19Smrg
6037e4fd55aSmrgmsvcmsys)
6047e4fd55aSmrg  # This case exists only to let depend.m4 do its work.  It works by
6057e4fd55aSmrg  # looking at the text of this script.  This case will never be run,
6067e4fd55aSmrg  # since it is checked for above.
6077e4fd55aSmrg  exit 1
6087e4fd55aSmrg  ;;
6097e4fd55aSmrg
610b8f75c19Smrgnone)
611b8f75c19Smrg  exec "$@"
612b8f75c19Smrg  ;;
613b8f75c19Smrg
614b8f75c19Smrg*)
615b8f75c19Smrg  echo "Unknown depmode $depmode" 1>&2
616b8f75c19Smrg  exit 1
617b8f75c19Smrg  ;;
618b8f75c19Smrgesac
619b8f75c19Smrg
620b8f75c19Smrgexit 0
6217e4fd55aSmrg
6227e4fd55aSmrg# Local Variables:
6237e4fd55aSmrg# mode: shell-script
6247e4fd55aSmrg# sh-indentation: 2
6257e4fd55aSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
6267e4fd55aSmrg# time-stamp-start: "scriptversion="
6277e4fd55aSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
6287e4fd55aSmrg# time-stamp-time-zone: "UTC"
6297e4fd55aSmrg# time-stamp-end: "; # UTC"
6307e4fd55aSmrg# End:
631