depcomp revision a6844aab
12c393a42Smrg#! /bin/sh
22c393a42Smrg# depcomp - compile a program generating dependencies as side-effects
32c393a42Smrg
4a6844aabSmrgscriptversion=2009-04-28.21; # UTC
52c393a42Smrg
6a6844aabSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
7a6844aabSmrg# Software Foundation, Inc.
82c393a42Smrg
92c393a42Smrg# This program is free software; you can redistribute it and/or modify
102c393a42Smrg# it under the terms of the GNU General Public License as published by
112c393a42Smrg# the Free Software Foundation; either version 2, or (at your option)
122c393a42Smrg# any later version.
132c393a42Smrg
142c393a42Smrg# This program is distributed in the hope that it will be useful,
152c393a42Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
162c393a42Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
172c393a42Smrg# GNU General Public License for more details.
182c393a42Smrg
192c393a42Smrg# You should have received a copy of the GNU General Public License
20a6844aabSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
212c393a42Smrg
222c393a42Smrg# As a special exception to the GNU General Public License, if you
232c393a42Smrg# distribute this file as part of a program that contains a
242c393a42Smrg# configuration script generated by Autoconf, you may include it under
252c393a42Smrg# the same distribution terms that you use for the rest of that program.
262c393a42Smrg
272c393a42Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
282c393a42Smrg
292c393a42Smrgcase $1 in
302c393a42Smrg  '')
312c393a42Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
322c393a42Smrg     exit 1;
332c393a42Smrg     ;;
342c393a42Smrg  -h | --h*)
352c393a42Smrg    cat <<\EOF
362c393a42SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
372c393a42Smrg
382c393a42SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
392c393a42Smrgas side-effects.
402c393a42Smrg
412c393a42SmrgEnvironment variables:
422c393a42Smrg  depmode     Dependency tracking mode.
432c393a42Smrg  source      Source file read by `PROGRAMS ARGS'.
442c393a42Smrg  object      Object file output by `PROGRAMS ARGS'.
452c393a42Smrg  DEPDIR      directory where to store dependencies.
462c393a42Smrg  depfile     Dependency file to output.
472c393a42Smrg  tmpdepfile  Temporary file to use when outputing dependencies.
482c393a42Smrg  libtool     Whether libtool is used (yes/no).
492c393a42Smrg
502c393a42SmrgReport bugs to <bug-automake@gnu.org>.
512c393a42SmrgEOF
522c393a42Smrg    exit $?
532c393a42Smrg    ;;
542c393a42Smrg  -v | --v*)
552c393a42Smrg    echo "depcomp $scriptversion"
562c393a42Smrg    exit $?
572c393a42Smrg    ;;
582c393a42Smrgesac
592c393a42Smrg
602c393a42Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
612c393a42Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
622c393a42Smrg  exit 1
632c393a42Smrgfi
642c393a42Smrg
652c393a42Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
662c393a42Smrgdepfile=${depfile-`echo "$object" |
672c393a42Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
682c393a42Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
692c393a42Smrg
702c393a42Smrgrm -f "$tmpdepfile"
712c393a42Smrg
722c393a42Smrg# Some modes work just like other modes, but use different flags.  We
732c393a42Smrg# parameterize here, but still list the modes in the big case below,
742c393a42Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
752c393a42Smrg# here, because this file can only contain one case statement.
762c393a42Smrgif test "$depmode" = hp; then
772c393a42Smrg  # HP compiler uses -M and no extra arg.
782c393a42Smrg  gccflag=-M
792c393a42Smrg  depmode=gcc
802c393a42Smrgfi
812c393a42Smrg
822c393a42Smrgif test "$depmode" = dashXmstdout; then
832c393a42Smrg   # This is just like dashmstdout with a different argument.
842c393a42Smrg   dashmflag=-xM
852c393a42Smrg   depmode=dashmstdout
862c393a42Smrgfi
872c393a42Smrg
88a6844aabSmrgcygpath_u="cygpath -u -f -"
89a6844aabSmrgif test "$depmode" = msvcmsys; then
90a6844aabSmrg   # This is just like msvisualcpp but w/o cygpath translation.
91a6844aabSmrg   # Just convert the backslash-escaped backslashes to single forward
92a6844aabSmrg   # slashes to satisfy depend.m4
93a6844aabSmrg   cygpath_u="sed s,\\\\\\\\,/,g"
94a6844aabSmrg   depmode=msvisualcpp
95a6844aabSmrgfi
96a6844aabSmrg
972c393a42Smrgcase "$depmode" in
982c393a42Smrggcc3)
992c393a42Smrg## gcc 3 implements dependency tracking that does exactly what
1002c393a42Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1012c393a42Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
102a6844aabSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
103a6844aabSmrg## the command line argument order; so add the flags where they
104a6844aabSmrg## appear in depend2.am.  Note that the slowdown incurred here
105a6844aabSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
106a6844aabSmrg  for arg
107a6844aabSmrg  do
108a6844aabSmrg    case $arg in
109a6844aabSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
110a6844aabSmrg    *)  set fnord "$@" "$arg" ;;
111a6844aabSmrg    esac
112a6844aabSmrg    shift # fnord
113a6844aabSmrg    shift # $arg
114a6844aabSmrg  done
115a6844aabSmrg  "$@"
1162c393a42Smrg  stat=$?
1172c393a42Smrg  if test $stat -eq 0; then :
1182c393a42Smrg  else
1192c393a42Smrg    rm -f "$tmpdepfile"
1202c393a42Smrg    exit $stat
1212c393a42Smrg  fi
1222c393a42Smrg  mv "$tmpdepfile" "$depfile"
1232c393a42Smrg  ;;
1242c393a42Smrg
1252c393a42Smrggcc)
1262c393a42Smrg## There are various ways to get dependency output from gcc.  Here's
1272c393a42Smrg## why we pick this rather obscure method:
1282c393a42Smrg## - Don't want to use -MD because we'd like the dependencies to end
1292c393a42Smrg##   up in a subdir.  Having to rename by hand is ugly.
1302c393a42Smrg##   (We might end up doing this anyway to support other compilers.)
1312c393a42Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
1322c393a42Smrg##   -MM, not -M (despite what the docs say).
1332c393a42Smrg## - Using -M directly means running the compiler twice (even worse
1342c393a42Smrg##   than renaming).
1352c393a42Smrg  if test -z "$gccflag"; then
1362c393a42Smrg    gccflag=-MD,
1372c393a42Smrg  fi
1382c393a42Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
1392c393a42Smrg  stat=$?
1402c393a42Smrg  if test $stat -eq 0; then :
1412c393a42Smrg  else
1422c393a42Smrg    rm -f "$tmpdepfile"
1432c393a42Smrg    exit $stat
1442c393a42Smrg  fi
1452c393a42Smrg  rm -f "$depfile"
1462c393a42Smrg  echo "$object : \\" > "$depfile"
1472c393a42Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
1482c393a42Smrg## The second -e expression handles DOS-style file names with drive letters.
1492c393a42Smrg  sed -e 's/^[^:]*: / /' \
1502c393a42Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
1512c393a42Smrg## This next piece of magic avoids the `deleted header file' problem.
1522c393a42Smrg## The problem is that when a header file which appears in a .P file
1532c393a42Smrg## is deleted, the dependency causes make to die (because there is
1542c393a42Smrg## typically no way to rebuild the header).  We avoid this by adding
1552c393a42Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
1562c393a42Smrg## this for us directly.
1572c393a42Smrg  tr ' ' '
1582c393a42Smrg' < "$tmpdepfile" |
1592c393a42Smrg## Some versions of gcc put a space before the `:'.  On the theory
1602c393a42Smrg## that the space means something, we add a space to the output as
1612c393a42Smrg## well.
1622c393a42Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
1632c393a42Smrg## correctly.  Breaking it into two sed invocations is a workaround.
1642c393a42Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
1652c393a42Smrg  rm -f "$tmpdepfile"
1662c393a42Smrg  ;;
1672c393a42Smrg
1682c393a42Smrghp)
1692c393a42Smrg  # This case exists only to let depend.m4 do its work.  It works by
1702c393a42Smrg  # looking at the text of this script.  This case will never be run,
1712c393a42Smrg  # since it is checked for above.
1722c393a42Smrg  exit 1
1732c393a42Smrg  ;;
1742c393a42Smrg
1752c393a42Smrgsgi)
1762c393a42Smrg  if test "$libtool" = yes; then
1772c393a42Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
1782c393a42Smrg  else
1792c393a42Smrg    "$@" -MDupdate "$tmpdepfile"
1802c393a42Smrg  fi
1812c393a42Smrg  stat=$?
1822c393a42Smrg  if test $stat -eq 0; then :
1832c393a42Smrg  else
1842c393a42Smrg    rm -f "$tmpdepfile"
1852c393a42Smrg    exit $stat
1862c393a42Smrg  fi
1872c393a42Smrg  rm -f "$depfile"
1882c393a42Smrg
1892c393a42Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
1902c393a42Smrg    echo "$object : \\" > "$depfile"
1912c393a42Smrg
1922c393a42Smrg    # Clip off the initial element (the dependent).  Don't try to be
1932c393a42Smrg    # clever and replace this with sed code, as IRIX sed won't handle
1942c393a42Smrg    # lines with more than a fixed number of characters (4096 in
1952c393a42Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
1962c393a42Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
1972c393a42Smrg    # dependency line.
1982c393a42Smrg    tr ' ' '
1992c393a42Smrg' < "$tmpdepfile" \
2002c393a42Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
2012c393a42Smrg    tr '
202a6844aabSmrg' ' ' >> "$depfile"
203a6844aabSmrg    echo >> "$depfile"
2042c393a42Smrg
2052c393a42Smrg    # The second pass generates a dummy entry for each header file.
2062c393a42Smrg    tr ' ' '
2072c393a42Smrg' < "$tmpdepfile" \
2082c393a42Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
209a6844aabSmrg   >> "$depfile"
2102c393a42Smrg  else
2112c393a42Smrg    # The sourcefile does not contain any dependencies, so just
2122c393a42Smrg    # store a dummy comment line, to avoid errors with the Makefile
2132c393a42Smrg    # "include basename.Plo" scheme.
2142c393a42Smrg    echo "#dummy" > "$depfile"
2152c393a42Smrg  fi
2162c393a42Smrg  rm -f "$tmpdepfile"
2172c393a42Smrg  ;;
2182c393a42Smrg
2192c393a42Smrgaix)
2202c393a42Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2212c393a42Smrg  # in a .u file.  In older versions, this file always lives in the
2222c393a42Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
2232c393a42Smrg  # start of each line; $object doesn't have directory information.
2242c393a42Smrg  # Version 6 uses the directory in both cases.
225a6844aabSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
226a6844aabSmrg  test "x$dir" = "x$object" && dir=
227a6844aabSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
2282c393a42Smrg  if test "$libtool" = yes; then
229a6844aabSmrg    tmpdepfile1=$dir$base.u
230a6844aabSmrg    tmpdepfile2=$base.u
231a6844aabSmrg    tmpdepfile3=$dir.libs/$base.u
2322c393a42Smrg    "$@" -Wc,-M
2332c393a42Smrg  else
234a6844aabSmrg    tmpdepfile1=$dir$base.u
235a6844aabSmrg    tmpdepfile2=$dir$base.u
236a6844aabSmrg    tmpdepfile3=$dir$base.u
2372c393a42Smrg    "$@" -M
2382c393a42Smrg  fi
2392c393a42Smrg  stat=$?
2402c393a42Smrg
2412c393a42Smrg  if test $stat -eq 0; then :
2422c393a42Smrg  else
243a6844aabSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
2442c393a42Smrg    exit $stat
2452c393a42Smrg  fi
2462c393a42Smrg
247a6844aabSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
248a6844aabSmrg  do
249a6844aabSmrg    test -f "$tmpdepfile" && break
250a6844aabSmrg  done
2512c393a42Smrg  if test -f "$tmpdepfile"; then
2522c393a42Smrg    # Each line is of the form `foo.o: dependent.h'.
2532c393a42Smrg    # Do two passes, one to just change these to
2542c393a42Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
255a6844aabSmrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
256a6844aabSmrg    # That's a tab and a space in the [].
257a6844aabSmrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
2582c393a42Smrg  else
2592c393a42Smrg    # The sourcefile does not contain any dependencies, so just
2602c393a42Smrg    # store a dummy comment line, to avoid errors with the Makefile
2612c393a42Smrg    # "include basename.Plo" scheme.
2622c393a42Smrg    echo "#dummy" > "$depfile"
2632c393a42Smrg  fi
2642c393a42Smrg  rm -f "$tmpdepfile"
2652c393a42Smrg  ;;
2662c393a42Smrg
2672c393a42Smrgicc)
2682c393a42Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
2692c393a42Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
2702c393a42Smrg  # ICC 7.0 will fill foo.d with something like
2712c393a42Smrg  #    foo.o: sub/foo.c
2722c393a42Smrg  #    foo.o: sub/foo.h
2732c393a42Smrg  # which is wrong.  We want:
2742c393a42Smrg  #    sub/foo.o: sub/foo.c
2752c393a42Smrg  #    sub/foo.o: sub/foo.h
2762c393a42Smrg  #    sub/foo.c:
2772c393a42Smrg  #    sub/foo.h:
2782c393a42Smrg  # ICC 7.1 will output
2792c393a42Smrg  #    foo.o: sub/foo.c sub/foo.h
2802c393a42Smrg  # and will wrap long lines using \ :
2812c393a42Smrg  #    foo.o: sub/foo.c ... \
2822c393a42Smrg  #     sub/foo.h ... \
2832c393a42Smrg  #     ...
2842c393a42Smrg
2852c393a42Smrg  "$@" -MD -MF "$tmpdepfile"
2862c393a42Smrg  stat=$?
2872c393a42Smrg  if test $stat -eq 0; then :
2882c393a42Smrg  else
2892c393a42Smrg    rm -f "$tmpdepfile"
2902c393a42Smrg    exit $stat
2912c393a42Smrg  fi
2922c393a42Smrg  rm -f "$depfile"
2932c393a42Smrg  # Each line is of the form `foo.o: dependent.h',
2942c393a42Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
2952c393a42Smrg  # Do two passes, one to just change these to
2962c393a42Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
2972c393a42Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
2982c393a42Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
2992c393a42Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
3002c393a42Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
3012c393a42Smrg    sed -e 's/$/ :/' >> "$depfile"
3022c393a42Smrg  rm -f "$tmpdepfile"
3032c393a42Smrg  ;;
3042c393a42Smrg
305a6844aabSmrghp2)
306a6844aabSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
307a6844aabSmrg  # compilers, which have integrated preprocessors.  The correct option
308a6844aabSmrg  # to use with these is +Maked; it writes dependencies to a file named
309a6844aabSmrg  # 'foo.d', which lands next to the object file, wherever that
310a6844aabSmrg  # happens to be.
311a6844aabSmrg  # Much of this is similar to the tru64 case; see comments there.
312a6844aabSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
313a6844aabSmrg  test "x$dir" = "x$object" && dir=
314a6844aabSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
315a6844aabSmrg  if test "$libtool" = yes; then
316a6844aabSmrg    tmpdepfile1=$dir$base.d
317a6844aabSmrg    tmpdepfile2=$dir.libs/$base.d
318a6844aabSmrg    "$@" -Wc,+Maked
319a6844aabSmrg  else
320a6844aabSmrg    tmpdepfile1=$dir$base.d
321a6844aabSmrg    tmpdepfile2=$dir$base.d
322a6844aabSmrg    "$@" +Maked
323a6844aabSmrg  fi
324a6844aabSmrg  stat=$?
325a6844aabSmrg  if test $stat -eq 0; then :
326a6844aabSmrg  else
327a6844aabSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
328a6844aabSmrg     exit $stat
329a6844aabSmrg  fi
330a6844aabSmrg
331a6844aabSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
332a6844aabSmrg  do
333a6844aabSmrg    test -f "$tmpdepfile" && break
334a6844aabSmrg  done
335a6844aabSmrg  if test -f "$tmpdepfile"; then
336a6844aabSmrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
337a6844aabSmrg    # Add `dependent.h:' lines.
338a6844aabSmrg    sed -ne '2,${
339a6844aabSmrg	       s/^ *//
340a6844aabSmrg	       s/ \\*$//
341a6844aabSmrg	       s/$/:/
342a6844aabSmrg	       p
343a6844aabSmrg	     }' "$tmpdepfile" >> "$depfile"
344a6844aabSmrg  else
345a6844aabSmrg    echo "#dummy" > "$depfile"
346a6844aabSmrg  fi
347a6844aabSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
348a6844aabSmrg  ;;
349a6844aabSmrg
3502c393a42Smrgtru64)
3512c393a42Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
3522c393a42Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
3532c393a42Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
3542c393a42Smrg   # dependencies in `foo.d' instead, so we check for that too.
3552c393a42Smrg   # Subdirectories are respected.
3562c393a42Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
3572c393a42Smrg   test "x$dir" = "x$object" && dir=
3582c393a42Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
3592c393a42Smrg
3602c393a42Smrg   if test "$libtool" = yes; then
3612c393a42Smrg      # With Tru64 cc, shared objects can also be used to make a
362a6844aabSmrg      # static library.  This mechanism is used in libtool 1.4 series to
3632c393a42Smrg      # handle both shared and static libraries in a single compilation.
3642c393a42Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
3652c393a42Smrg      #
3662c393a42Smrg      # With libtool 1.5 this exception was removed, and libtool now
3672c393a42Smrg      # generates 2 separate objects for the 2 libraries.  These two
368a6844aabSmrg      # compilations output dependencies in $dir.libs/$base.o.d and
3692c393a42Smrg      # in $dir$base.o.d.  We have to check for both files, because
3702c393a42Smrg      # one of the two compilations can be disabled.  We should prefer
3712c393a42Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
3722c393a42Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
3732c393a42Smrg      # the former would cause a distcleancheck panic.
3742c393a42Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
3752c393a42Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
3762c393a42Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
3772c393a42Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
3782c393a42Smrg      "$@" -Wc,-MD
3792c393a42Smrg   else
3802c393a42Smrg      tmpdepfile1=$dir$base.o.d
3812c393a42Smrg      tmpdepfile2=$dir$base.d
3822c393a42Smrg      tmpdepfile3=$dir$base.d
3832c393a42Smrg      tmpdepfile4=$dir$base.d
3842c393a42Smrg      "$@" -MD
3852c393a42Smrg   fi
3862c393a42Smrg
3872c393a42Smrg   stat=$?
3882c393a42Smrg   if test $stat -eq 0; then :
3892c393a42Smrg   else
3902c393a42Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
3912c393a42Smrg      exit $stat
3922c393a42Smrg   fi
3932c393a42Smrg
3942c393a42Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
3952c393a42Smrg   do
3962c393a42Smrg     test -f "$tmpdepfile" && break
3972c393a42Smrg   done
3982c393a42Smrg   if test -f "$tmpdepfile"; then
3992c393a42Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
4002c393a42Smrg      # That's a tab and a space in the [].
4012c393a42Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
4022c393a42Smrg   else
4032c393a42Smrg      echo "#dummy" > "$depfile"
4042c393a42Smrg   fi
4052c393a42Smrg   rm -f "$tmpdepfile"
4062c393a42Smrg   ;;
4072c393a42Smrg
4082c393a42Smrg#nosideeffect)
4092c393a42Smrg  # This comment above is used by automake to tell side-effect
4102c393a42Smrg  # dependency tracking mechanisms from slower ones.
4112c393a42Smrg
4122c393a42Smrgdashmstdout)
4132c393a42Smrg  # Important note: in order to support this mode, a compiler *must*
4142c393a42Smrg  # always write the preprocessed file to stdout, regardless of -o.
4152c393a42Smrg  "$@" || exit $?
4162c393a42Smrg
4172c393a42Smrg  # Remove the call to Libtool.
4182c393a42Smrg  if test "$libtool" = yes; then
419a6844aabSmrg    while test "X$1" != 'X--mode=compile'; do
4202c393a42Smrg      shift
4212c393a42Smrg    done
4222c393a42Smrg    shift
4232c393a42Smrg  fi
4242c393a42Smrg
4252c393a42Smrg  # Remove `-o $object'.
4262c393a42Smrg  IFS=" "
4272c393a42Smrg  for arg
4282c393a42Smrg  do
4292c393a42Smrg    case $arg in
4302c393a42Smrg    -o)
4312c393a42Smrg      shift
4322c393a42Smrg      ;;
4332c393a42Smrg    $object)
4342c393a42Smrg      shift
4352c393a42Smrg      ;;
4362c393a42Smrg    *)
4372c393a42Smrg      set fnord "$@" "$arg"
4382c393a42Smrg      shift # fnord
4392c393a42Smrg      shift # $arg
4402c393a42Smrg      ;;
4412c393a42Smrg    esac
4422c393a42Smrg  done
4432c393a42Smrg
4442c393a42Smrg  test -z "$dashmflag" && dashmflag=-M
4452c393a42Smrg  # Require at least two characters before searching for `:'
4462c393a42Smrg  # in the target name.  This is to cope with DOS-style filenames:
4472c393a42Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
4482c393a42Smrg  "$@" $dashmflag |
4492c393a42Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
4502c393a42Smrg  rm -f "$depfile"
4512c393a42Smrg  cat < "$tmpdepfile" > "$depfile"
4522c393a42Smrg  tr ' ' '
4532c393a42Smrg' < "$tmpdepfile" | \
4542c393a42Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
4552c393a42Smrg## correctly.  Breaking it into two sed invocations is a workaround.
4562c393a42Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
4572c393a42Smrg  rm -f "$tmpdepfile"
4582c393a42Smrg  ;;
4592c393a42Smrg
4602c393a42SmrgdashXmstdout)
4612c393a42Smrg  # This case only exists to satisfy depend.m4.  It is never actually
4622c393a42Smrg  # run, as this mode is specially recognized in the preamble.
4632c393a42Smrg  exit 1
4642c393a42Smrg  ;;
4652c393a42Smrg
4662c393a42Smrgmakedepend)
4672c393a42Smrg  "$@" || exit $?
4682c393a42Smrg  # Remove any Libtool call
4692c393a42Smrg  if test "$libtool" = yes; then
470a6844aabSmrg    while test "X$1" != 'X--mode=compile'; do
4712c393a42Smrg      shift
4722c393a42Smrg    done
4732c393a42Smrg    shift
4742c393a42Smrg  fi
4752c393a42Smrg  # X makedepend
4762c393a42Smrg  shift
477a6844aabSmrg  cleared=no eat=no
478a6844aabSmrg  for arg
479a6844aabSmrg  do
4802c393a42Smrg    case $cleared in
4812c393a42Smrg    no)
4822c393a42Smrg      set ""; shift
4832c393a42Smrg      cleared=yes ;;
4842c393a42Smrg    esac
485a6844aabSmrg    if test $eat = yes; then
486a6844aabSmrg      eat=no
487a6844aabSmrg      continue
488a6844aabSmrg    fi
4892c393a42Smrg    case "$arg" in
4902c393a42Smrg    -D*|-I*)
4912c393a42Smrg      set fnord "$@" "$arg"; shift ;;
4922c393a42Smrg    # Strip any option that makedepend may not understand.  Remove
4932c393a42Smrg    # the object too, otherwise makedepend will parse it as a source file.
494a6844aabSmrg    -arch)
495a6844aabSmrg      eat=yes ;;
4962c393a42Smrg    -*|$object)
4972c393a42Smrg      ;;
4982c393a42Smrg    *)
4992c393a42Smrg      set fnord "$@" "$arg"; shift ;;
5002c393a42Smrg    esac
5012c393a42Smrg  done
502a6844aabSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
5032c393a42Smrg  touch "$tmpdepfile"
5042c393a42Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
5052c393a42Smrg  rm -f "$depfile"
5062c393a42Smrg  cat < "$tmpdepfile" > "$depfile"
5072c393a42Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
5082c393a42Smrg' | \
5092c393a42Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
5102c393a42Smrg## correctly.  Breaking it into two sed invocations is a workaround.
5112c393a42Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
5122c393a42Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
5132c393a42Smrg  ;;
5142c393a42Smrg
5152c393a42Smrgcpp)
5162c393a42Smrg  # Important note: in order to support this mode, a compiler *must*
5172c393a42Smrg  # always write the preprocessed file to stdout.
5182c393a42Smrg  "$@" || exit $?
5192c393a42Smrg
5202c393a42Smrg  # Remove the call to Libtool.
5212c393a42Smrg  if test "$libtool" = yes; then
522a6844aabSmrg    while test "X$1" != 'X--mode=compile'; do
5232c393a42Smrg      shift
5242c393a42Smrg    done
5252c393a42Smrg    shift
5262c393a42Smrg  fi
5272c393a42Smrg
5282c393a42Smrg  # Remove `-o $object'.
5292c393a42Smrg  IFS=" "
5302c393a42Smrg  for arg
5312c393a42Smrg  do
5322c393a42Smrg    case $arg in
5332c393a42Smrg    -o)
5342c393a42Smrg      shift
5352c393a42Smrg      ;;
5362c393a42Smrg    $object)
5372c393a42Smrg      shift
5382c393a42Smrg      ;;
5392c393a42Smrg    *)
5402c393a42Smrg      set fnord "$@" "$arg"
5412c393a42Smrg      shift # fnord
5422c393a42Smrg      shift # $arg
5432c393a42Smrg      ;;
5442c393a42Smrg    esac
5452c393a42Smrg  done
5462c393a42Smrg
5472c393a42Smrg  "$@" -E |
5482c393a42Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
5492c393a42Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
5502c393a42Smrg    sed '$ s: \\$::' > "$tmpdepfile"
5512c393a42Smrg  rm -f "$depfile"
5522c393a42Smrg  echo "$object : \\" > "$depfile"
5532c393a42Smrg  cat < "$tmpdepfile" >> "$depfile"
5542c393a42Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
5552c393a42Smrg  rm -f "$tmpdepfile"
5562c393a42Smrg  ;;
5572c393a42Smrg
5582c393a42Smrgmsvisualcpp)
5592c393a42Smrg  # Important note: in order to support this mode, a compiler *must*
560a6844aabSmrg  # always write the preprocessed file to stdout.
5612c393a42Smrg  "$@" || exit $?
562a6844aabSmrg
563a6844aabSmrg  # Remove the call to Libtool.
564a6844aabSmrg  if test "$libtool" = yes; then
565a6844aabSmrg    while test "X$1" != 'X--mode=compile'; do
566a6844aabSmrg      shift
567a6844aabSmrg    done
568a6844aabSmrg    shift
569a6844aabSmrg  fi
570a6844aabSmrg
5712c393a42Smrg  IFS=" "
5722c393a42Smrg  for arg
5732c393a42Smrg  do
5742c393a42Smrg    case "$arg" in
575a6844aabSmrg    -o)
576a6844aabSmrg      shift
577a6844aabSmrg      ;;
578a6844aabSmrg    $object)
579a6844aabSmrg      shift
580a6844aabSmrg      ;;
5812c393a42Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
5822c393a42Smrg	set fnord "$@"
5832c393a42Smrg	shift
5842c393a42Smrg	shift
5852c393a42Smrg	;;
5862c393a42Smrg    *)
5872c393a42Smrg	set fnord "$@" "$arg"
5882c393a42Smrg	shift
5892c393a42Smrg	shift
5902c393a42Smrg	;;
5912c393a42Smrg    esac
5922c393a42Smrg  done
593a6844aabSmrg  "$@" -E 2>/dev/null |
594a6844aabSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
5952c393a42Smrg  rm -f "$depfile"
5962c393a42Smrg  echo "$object : \\" > "$depfile"
597a6844aabSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
5982c393a42Smrg  echo "	" >> "$depfile"
599a6844aabSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
6002c393a42Smrg  rm -f "$tmpdepfile"
6012c393a42Smrg  ;;
6022c393a42Smrg
603a6844aabSmrgmsvcmsys)
604a6844aabSmrg  # This case exists only to let depend.m4 do its work.  It works by
605a6844aabSmrg  # looking at the text of this script.  This case will never be run,
606a6844aabSmrg  # since it is checked for above.
607a6844aabSmrg  exit 1
608a6844aabSmrg  ;;
609a6844aabSmrg
6102c393a42Smrgnone)
6112c393a42Smrg  exec "$@"
6122c393a42Smrg  ;;
6132c393a42Smrg
6142c393a42Smrg*)
6152c393a42Smrg  echo "Unknown depmode $depmode" 1>&2
6162c393a42Smrg  exit 1
6172c393a42Smrg  ;;
6182c393a42Smrgesac
6192c393a42Smrg
6202c393a42Smrgexit 0
6212c393a42Smrg
6222c393a42Smrg# Local Variables:
6232c393a42Smrg# mode: shell-script
6242c393a42Smrg# sh-indentation: 2
6252c393a42Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
6262c393a42Smrg# time-stamp-start: "scriptversion="
6272c393a42Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
628a6844aabSmrg# time-stamp-time-zone: "UTC"
629a6844aabSmrg# time-stamp-end: "; # UTC"
6302c393a42Smrg# End:
631