depcomp revision 421c997b
17a84e134Smrg#! /bin/sh
27a84e134Smrg# depcomp - compile a program generating dependencies as side-effects
37a84e134Smrg
4421c997bSmrgscriptversion=2011-12-04.11; # UTC
57a84e134Smrg
6421c997bSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
7421c997bSmrg# 2011 Free Software Foundation, Inc.
87a84e134Smrg
97a84e134Smrg# This program is free software; you can redistribute it and/or modify
107a84e134Smrg# it under the terms of the GNU General Public License as published by
117a84e134Smrg# the Free Software Foundation; either version 2, or (at your option)
127a84e134Smrg# any later version.
137a84e134Smrg
147a84e134Smrg# This program is distributed in the hope that it will be useful,
157a84e134Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
167a84e134Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
177a84e134Smrg# GNU General Public License for more details.
187a84e134Smrg
197a84e134Smrg# You should have received a copy of the GNU General Public License
20e1e1713cSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
217a84e134Smrg
227a84e134Smrg# As a special exception to the GNU General Public License, if you
237a84e134Smrg# distribute this file as part of a program that contains a
247a84e134Smrg# configuration script generated by Autoconf, you may include it under
257a84e134Smrg# the same distribution terms that you use for the rest of that program.
267a84e134Smrg
277a84e134Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
287a84e134Smrg
297a84e134Smrgcase $1 in
307a84e134Smrg  '')
317a84e134Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
327a84e134Smrg     exit 1;
337a84e134Smrg     ;;
347a84e134Smrg  -h | --h*)
357a84e134Smrg    cat <<\EOF
367a84e134SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
377a84e134Smrg
387a84e134SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
397a84e134Smrgas side-effects.
407a84e134Smrg
417a84e134SmrgEnvironment variables:
427a84e134Smrg  depmode     Dependency tracking mode.
437a84e134Smrg  source      Source file read by `PROGRAMS ARGS'.
447a84e134Smrg  object      Object file output by `PROGRAMS ARGS'.
457a84e134Smrg  DEPDIR      directory where to store dependencies.
467a84e134Smrg  depfile     Dependency file to output.
47421c997bSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
487a84e134Smrg  libtool     Whether libtool is used (yes/no).
497a84e134Smrg
507a84e134SmrgReport bugs to <bug-automake@gnu.org>.
517a84e134SmrgEOF
527a84e134Smrg    exit $?
537a84e134Smrg    ;;
547a84e134Smrg  -v | --v*)
557a84e134Smrg    echo "depcomp $scriptversion"
567a84e134Smrg    exit $?
577a84e134Smrg    ;;
587a84e134Smrgesac
597a84e134Smrg
607a84e134Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
617a84e134Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
627a84e134Smrg  exit 1
637a84e134Smrgfi
647a84e134Smrg
657a84e134Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
667a84e134Smrgdepfile=${depfile-`echo "$object" |
677a84e134Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
687a84e134Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
697a84e134Smrg
707a84e134Smrgrm -f "$tmpdepfile"
717a84e134Smrg
727a84e134Smrg# Some modes work just like other modes, but use different flags.  We
737a84e134Smrg# parameterize here, but still list the modes in the big case below,
747a84e134Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
757a84e134Smrg# here, because this file can only contain one case statement.
767a84e134Smrgif test "$depmode" = hp; then
777a84e134Smrg  # HP compiler uses -M and no extra arg.
787a84e134Smrg  gccflag=-M
797a84e134Smrg  depmode=gcc
807a84e134Smrgfi
817a84e134Smrg
827a84e134Smrgif test "$depmode" = dashXmstdout; then
837a84e134Smrg   # This is just like dashmstdout with a different argument.
847a84e134Smrg   dashmflag=-xM
857a84e134Smrg   depmode=dashmstdout
867a84e134Smrgfi
877a84e134Smrg
88e1e1713cSmrgcygpath_u="cygpath -u -f -"
89e1e1713cSmrgif test "$depmode" = msvcmsys; then
90e1e1713cSmrg   # This is just like msvisualcpp but w/o cygpath translation.
91e1e1713cSmrg   # Just convert the backslash-escaped backslashes to single forward
92e1e1713cSmrg   # slashes to satisfy depend.m4
93421c997bSmrg   cygpath_u='sed s,\\\\,/,g'
94e1e1713cSmrg   depmode=msvisualcpp
95e1e1713cSmrgfi
96e1e1713cSmrg
97421c997bSmrgif test "$depmode" = msvc7msys; then
98421c997bSmrg   # This is just like msvc7 but w/o cygpath translation.
99421c997bSmrg   # Just convert the backslash-escaped backslashes to single forward
100421c997bSmrg   # slashes to satisfy depend.m4
101421c997bSmrg   cygpath_u='sed s,\\\\,/,g'
102421c997bSmrg   depmode=msvc7
103421c997bSmrgfi
104421c997bSmrg
1057a84e134Smrgcase "$depmode" in
1067a84e134Smrggcc3)
1077a84e134Smrg## gcc 3 implements dependency tracking that does exactly what
1087a84e134Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1097a84e134Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1107a84e134Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1117a84e134Smrg## the command line argument order; so add the flags where they
1127a84e134Smrg## appear in depend2.am.  Note that the slowdown incurred here
1137a84e134Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1147a84e134Smrg  for arg
1157a84e134Smrg  do
1167a84e134Smrg    case $arg in
1177a84e134Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1187a84e134Smrg    *)  set fnord "$@" "$arg" ;;
1197a84e134Smrg    esac
1207a84e134Smrg    shift # fnord
1217a84e134Smrg    shift # $arg
1227a84e134Smrg  done
1237a84e134Smrg  "$@"
1247a84e134Smrg  stat=$?
1257a84e134Smrg  if test $stat -eq 0; then :
1267a84e134Smrg  else
1277a84e134Smrg    rm -f "$tmpdepfile"
1287a84e134Smrg    exit $stat
1297a84e134Smrg  fi
1307a84e134Smrg  mv "$tmpdepfile" "$depfile"
1317a84e134Smrg  ;;
1327a84e134Smrg
1337a84e134Smrggcc)
1347a84e134Smrg## There are various ways to get dependency output from gcc.  Here's
1357a84e134Smrg## why we pick this rather obscure method:
1367a84e134Smrg## - Don't want to use -MD because we'd like the dependencies to end
1377a84e134Smrg##   up in a subdir.  Having to rename by hand is ugly.
1387a84e134Smrg##   (We might end up doing this anyway to support other compilers.)
1397a84e134Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
1407a84e134Smrg##   -MM, not -M (despite what the docs say).
1417a84e134Smrg## - Using -M directly means running the compiler twice (even worse
1427a84e134Smrg##   than renaming).
1437a84e134Smrg  if test -z "$gccflag"; then
1447a84e134Smrg    gccflag=-MD,
1457a84e134Smrg  fi
1467a84e134Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
1477a84e134Smrg  stat=$?
1487a84e134Smrg  if test $stat -eq 0; then :
1497a84e134Smrg  else
1507a84e134Smrg    rm -f "$tmpdepfile"
1517a84e134Smrg    exit $stat
1527a84e134Smrg  fi
1537a84e134Smrg  rm -f "$depfile"
1547a84e134Smrg  echo "$object : \\" > "$depfile"
1557a84e134Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
1567a84e134Smrg## The second -e expression handles DOS-style file names with drive letters.
1577a84e134Smrg  sed -e 's/^[^:]*: / /' \
1587a84e134Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
1597a84e134Smrg## This next piece of magic avoids the `deleted header file' problem.
1607a84e134Smrg## The problem is that when a header file which appears in a .P file
1617a84e134Smrg## is deleted, the dependency causes make to die (because there is
1627a84e134Smrg## typically no way to rebuild the header).  We avoid this by adding
1637a84e134Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
1647a84e134Smrg## this for us directly.
1657a84e134Smrg  tr ' ' '
1667a84e134Smrg' < "$tmpdepfile" |
1677a84e134Smrg## Some versions of gcc put a space before the `:'.  On the theory
1687a84e134Smrg## that the space means something, we add a space to the output as
169421c997bSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
170421c997bSmrg## to the object.  Take care to not repeat it in the output.
1717a84e134Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
1727a84e134Smrg## correctly.  Breaking it into two sed invocations is a workaround.
173421c997bSmrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
174421c997bSmrg      | sed -e 's/$/ :/' >> "$depfile"
1757a84e134Smrg  rm -f "$tmpdepfile"
1767a84e134Smrg  ;;
1777a84e134Smrg
1787a84e134Smrghp)
1797a84e134Smrg  # This case exists only to let depend.m4 do its work.  It works by
1807a84e134Smrg  # looking at the text of this script.  This case will never be run,
1817a84e134Smrg  # since it is checked for above.
1827a84e134Smrg  exit 1
1837a84e134Smrg  ;;
1847a84e134Smrg
1857a84e134Smrgsgi)
1867a84e134Smrg  if test "$libtool" = yes; then
1877a84e134Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
1887a84e134Smrg  else
1897a84e134Smrg    "$@" -MDupdate "$tmpdepfile"
1907a84e134Smrg  fi
1917a84e134Smrg  stat=$?
1927a84e134Smrg  if test $stat -eq 0; then :
1937a84e134Smrg  else
1947a84e134Smrg    rm -f "$tmpdepfile"
1957a84e134Smrg    exit $stat
1967a84e134Smrg  fi
1977a84e134Smrg  rm -f "$depfile"
1987a84e134Smrg
1997a84e134Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2007a84e134Smrg    echo "$object : \\" > "$depfile"
2017a84e134Smrg
2027a84e134Smrg    # Clip off the initial element (the dependent).  Don't try to be
2037a84e134Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2047a84e134Smrg    # lines with more than a fixed number of characters (4096 in
2057a84e134Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2067a84e134Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
2077a84e134Smrg    # dependency line.
2087a84e134Smrg    tr ' ' '
2097a84e134Smrg' < "$tmpdepfile" \
2107a84e134Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
2117a84e134Smrg    tr '
212e1e1713cSmrg' ' ' >> "$depfile"
213e1e1713cSmrg    echo >> "$depfile"
2147a84e134Smrg
2157a84e134Smrg    # The second pass generates a dummy entry for each header file.
2167a84e134Smrg    tr ' ' '
2177a84e134Smrg' < "$tmpdepfile" \
2187a84e134Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
219e1e1713cSmrg   >> "$depfile"
2207a84e134Smrg  else
2217a84e134Smrg    # The sourcefile does not contain any dependencies, so just
2227a84e134Smrg    # store a dummy comment line, to avoid errors with the Makefile
2237a84e134Smrg    # "include basename.Plo" scheme.
2247a84e134Smrg    echo "#dummy" > "$depfile"
2257a84e134Smrg  fi
2267a84e134Smrg  rm -f "$tmpdepfile"
2277a84e134Smrg  ;;
2287a84e134Smrg
2297a84e134Smrgaix)
2307a84e134Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2317a84e134Smrg  # in a .u file.  In older versions, this file always lives in the
2327a84e134Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
2337a84e134Smrg  # start of each line; $object doesn't have directory information.
2347a84e134Smrg  # Version 6 uses the directory in both cases.
235ab902922Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
236ab902922Smrg  test "x$dir" = "x$object" && dir=
237ab902922Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
2387a84e134Smrg  if test "$libtool" = yes; then
239ab902922Smrg    tmpdepfile1=$dir$base.u
240ab902922Smrg    tmpdepfile2=$base.u
241ab902922Smrg    tmpdepfile3=$dir.libs/$base.u
2427a84e134Smrg    "$@" -Wc,-M
2437a84e134Smrg  else
244ab902922Smrg    tmpdepfile1=$dir$base.u
245ab902922Smrg    tmpdepfile2=$dir$base.u
246ab902922Smrg    tmpdepfile3=$dir$base.u
2477a84e134Smrg    "$@" -M
2487a84e134Smrg  fi
2497a84e134Smrg  stat=$?
2507a84e134Smrg
2517a84e134Smrg  if test $stat -eq 0; then :
2527a84e134Smrg  else
253ab902922Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
2547a84e134Smrg    exit $stat
2557a84e134Smrg  fi
2567a84e134Smrg
257ab902922Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
258ab902922Smrg  do
259ab902922Smrg    test -f "$tmpdepfile" && break
260ab902922Smrg  done
2617a84e134Smrg  if test -f "$tmpdepfile"; then
2627a84e134Smrg    # Each line is of the form `foo.o: dependent.h'.
2637a84e134Smrg    # Do two passes, one to just change these to
2647a84e134Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
265ab902922Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
266ab902922Smrg    # That's a tab and a space in the [].
267ab902922Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
2687a84e134Smrg  else
2697a84e134Smrg    # The sourcefile does not contain any dependencies, so just
2707a84e134Smrg    # store a dummy comment line, to avoid errors with the Makefile
2717a84e134Smrg    # "include basename.Plo" scheme.
2727a84e134Smrg    echo "#dummy" > "$depfile"
2737a84e134Smrg  fi
2747a84e134Smrg  rm -f "$tmpdepfile"
2757a84e134Smrg  ;;
2767a84e134Smrg
2777a84e134Smrgicc)
2787a84e134Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
2797a84e134Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
2807a84e134Smrg  # ICC 7.0 will fill foo.d with something like
2817a84e134Smrg  #    foo.o: sub/foo.c
2827a84e134Smrg  #    foo.o: sub/foo.h
2837a84e134Smrg  # which is wrong.  We want:
2847a84e134Smrg  #    sub/foo.o: sub/foo.c
2857a84e134Smrg  #    sub/foo.o: sub/foo.h
2867a84e134Smrg  #    sub/foo.c:
2877a84e134Smrg  #    sub/foo.h:
2887a84e134Smrg  # ICC 7.1 will output
2897a84e134Smrg  #    foo.o: sub/foo.c sub/foo.h
2907a84e134Smrg  # and will wrap long lines using \ :
2917a84e134Smrg  #    foo.o: sub/foo.c ... \
2927a84e134Smrg  #     sub/foo.h ... \
2937a84e134Smrg  #     ...
2947a84e134Smrg
2957a84e134Smrg  "$@" -MD -MF "$tmpdepfile"
2967a84e134Smrg  stat=$?
2977a84e134Smrg  if test $stat -eq 0; then :
2987a84e134Smrg  else
2997a84e134Smrg    rm -f "$tmpdepfile"
3007a84e134Smrg    exit $stat
3017a84e134Smrg  fi
3027a84e134Smrg  rm -f "$depfile"
3037a84e134Smrg  # Each line is of the form `foo.o: dependent.h',
3047a84e134Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
3057a84e134Smrg  # Do two passes, one to just change these to
3067a84e134Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
3077a84e134Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
3087a84e134Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
3097a84e134Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
3107a84e134Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
3117a84e134Smrg    sed -e 's/$/ :/' >> "$depfile"
3127a84e134Smrg  rm -f "$tmpdepfile"
3137a84e134Smrg  ;;
3147a84e134Smrg
3157a84e134Smrghp2)
3167a84e134Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
3177a84e134Smrg  # compilers, which have integrated preprocessors.  The correct option
3187a84e134Smrg  # to use with these is +Maked; it writes dependencies to a file named
3197a84e134Smrg  # 'foo.d', which lands next to the object file, wherever that
3207a84e134Smrg  # happens to be.
3217a84e134Smrg  # Much of this is similar to the tru64 case; see comments there.
3227a84e134Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
3237a84e134Smrg  test "x$dir" = "x$object" && dir=
3247a84e134Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
3257a84e134Smrg  if test "$libtool" = yes; then
3267a84e134Smrg    tmpdepfile1=$dir$base.d
3277a84e134Smrg    tmpdepfile2=$dir.libs/$base.d
3287a84e134Smrg    "$@" -Wc,+Maked
3297a84e134Smrg  else
3307a84e134Smrg    tmpdepfile1=$dir$base.d
3317a84e134Smrg    tmpdepfile2=$dir$base.d
3327a84e134Smrg    "$@" +Maked
3337a84e134Smrg  fi
3347a84e134Smrg  stat=$?
3357a84e134Smrg  if test $stat -eq 0; then :
3367a84e134Smrg  else
3377a84e134Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
3387a84e134Smrg     exit $stat
3397a84e134Smrg  fi
3407a84e134Smrg
3417a84e134Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
3427a84e134Smrg  do
3437a84e134Smrg    test -f "$tmpdepfile" && break
3447a84e134Smrg  done
3457a84e134Smrg  if test -f "$tmpdepfile"; then
3467a84e134Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
3477a84e134Smrg    # Add `dependent.h:' lines.
348e1e1713cSmrg    sed -ne '2,${
349e1e1713cSmrg	       s/^ *//
350e1e1713cSmrg	       s/ \\*$//
351e1e1713cSmrg	       s/$/:/
352e1e1713cSmrg	       p
353e1e1713cSmrg	     }' "$tmpdepfile" >> "$depfile"
3547a84e134Smrg  else
3557a84e134Smrg    echo "#dummy" > "$depfile"
3567a84e134Smrg  fi
3577a84e134Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
3587a84e134Smrg  ;;
3597a84e134Smrg
3607a84e134Smrgtru64)
3617a84e134Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
3627a84e134Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
3637a84e134Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
3647a84e134Smrg   # dependencies in `foo.d' instead, so we check for that too.
3657a84e134Smrg   # Subdirectories are respected.
3667a84e134Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
3677a84e134Smrg   test "x$dir" = "x$object" && dir=
3687a84e134Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
3697a84e134Smrg
3707a84e134Smrg   if test "$libtool" = yes; then
3717a84e134Smrg      # With Tru64 cc, shared objects can also be used to make a
3727a84e134Smrg      # static library.  This mechanism is used in libtool 1.4 series to
3737a84e134Smrg      # handle both shared and static libraries in a single compilation.
3747a84e134Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
3757a84e134Smrg      #
3767a84e134Smrg      # With libtool 1.5 this exception was removed, and libtool now
3777a84e134Smrg      # generates 2 separate objects for the 2 libraries.  These two
3787a84e134Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
3797a84e134Smrg      # in $dir$base.o.d.  We have to check for both files, because
3807a84e134Smrg      # one of the two compilations can be disabled.  We should prefer
3817a84e134Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
3827a84e134Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
3837a84e134Smrg      # the former would cause a distcleancheck panic.
3847a84e134Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
3857a84e134Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
3867a84e134Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
3877a84e134Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
3887a84e134Smrg      "$@" -Wc,-MD
3897a84e134Smrg   else
3907a84e134Smrg      tmpdepfile1=$dir$base.o.d
3917a84e134Smrg      tmpdepfile2=$dir$base.d
3927a84e134Smrg      tmpdepfile3=$dir$base.d
3937a84e134Smrg      tmpdepfile4=$dir$base.d
3947a84e134Smrg      "$@" -MD
3957a84e134Smrg   fi
3967a84e134Smrg
3977a84e134Smrg   stat=$?
3987a84e134Smrg   if test $stat -eq 0; then :
3997a84e134Smrg   else
4007a84e134Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
4017a84e134Smrg      exit $stat
4027a84e134Smrg   fi
4037a84e134Smrg
4047a84e134Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
4057a84e134Smrg   do
4067a84e134Smrg     test -f "$tmpdepfile" && break
4077a84e134Smrg   done
4087a84e134Smrg   if test -f "$tmpdepfile"; then
4097a84e134Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
4107a84e134Smrg      # That's a tab and a space in the [].
4117a84e134Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
4127a84e134Smrg   else
4137a84e134Smrg      echo "#dummy" > "$depfile"
4147a84e134Smrg   fi
4157a84e134Smrg   rm -f "$tmpdepfile"
4167a84e134Smrg   ;;
4177a84e134Smrg
418421c997bSmrgmsvc7)
419421c997bSmrg  if test "$libtool" = yes; then
420421c997bSmrg    showIncludes=-Wc,-showIncludes
421421c997bSmrg  else
422421c997bSmrg    showIncludes=-showIncludes
423421c997bSmrg  fi
424421c997bSmrg  "$@" $showIncludes > "$tmpdepfile"
425421c997bSmrg  stat=$?
426421c997bSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
427421c997bSmrg  if test "$stat" = 0; then :
428421c997bSmrg  else
429421c997bSmrg    rm -f "$tmpdepfile"
430421c997bSmrg    exit $stat
431421c997bSmrg  fi
432421c997bSmrg  rm -f "$depfile"
433421c997bSmrg  echo "$object : \\" > "$depfile"
434421c997bSmrg  # The first sed program below extracts the file names and escapes
435421c997bSmrg  # backslashes for cygpath.  The second sed program outputs the file
436421c997bSmrg  # name when reading, but also accumulates all include files in the
437421c997bSmrg  # hold buffer in order to output them again at the end.  This only
438421c997bSmrg  # works with sed implementations that can handle large buffers.
439421c997bSmrg  sed < "$tmpdepfile" -n '
440421c997bSmrg/^Note: including file:  *\(.*\)/ {
441421c997bSmrg  s//\1/
442421c997bSmrg  s/\\/\\\\/g
443421c997bSmrg  p
444421c997bSmrg}' | $cygpath_u | sort -u | sed -n '
445421c997bSmrgs/ /\\ /g
446421c997bSmrgs/\(.*\)/	\1 \\/p
447421c997bSmrgs/.\(.*\) \\/\1:/
448421c997bSmrgH
449421c997bSmrg$ {
450421c997bSmrg  s/.*/	/
451421c997bSmrg  G
452421c997bSmrg  p
453421c997bSmrg}' >> "$depfile"
454421c997bSmrg  rm -f "$tmpdepfile"
455421c997bSmrg  ;;
456421c997bSmrg
457421c997bSmrgmsvc7msys)
458421c997bSmrg  # This case exists only to let depend.m4 do its work.  It works by
459421c997bSmrg  # looking at the text of this script.  This case will never be run,
460421c997bSmrg  # since it is checked for above.
461421c997bSmrg  exit 1
462421c997bSmrg  ;;
463421c997bSmrg
4647a84e134Smrg#nosideeffect)
4657a84e134Smrg  # This comment above is used by automake to tell side-effect
4667a84e134Smrg  # dependency tracking mechanisms from slower ones.
4677a84e134Smrg
4687a84e134Smrgdashmstdout)
4697a84e134Smrg  # Important note: in order to support this mode, a compiler *must*
4707a84e134Smrg  # always write the preprocessed file to stdout, regardless of -o.
4717a84e134Smrg  "$@" || exit $?
4727a84e134Smrg
4737a84e134Smrg  # Remove the call to Libtool.
4747a84e134Smrg  if test "$libtool" = yes; then
475e1e1713cSmrg    while test "X$1" != 'X--mode=compile'; do
4767a84e134Smrg      shift
4777a84e134Smrg    done
4787a84e134Smrg    shift
4797a84e134Smrg  fi
4807a84e134Smrg
4817a84e134Smrg  # Remove `-o $object'.
4827a84e134Smrg  IFS=" "
4837a84e134Smrg  for arg
4847a84e134Smrg  do
4857a84e134Smrg    case $arg in
4867a84e134Smrg    -o)
4877a84e134Smrg      shift
4887a84e134Smrg      ;;
4897a84e134Smrg    $object)
4907a84e134Smrg      shift
4917a84e134Smrg      ;;
4927a84e134Smrg    *)
4937a84e134Smrg      set fnord "$@" "$arg"
4947a84e134Smrg      shift # fnord
4957a84e134Smrg      shift # $arg
4967a84e134Smrg      ;;
4977a84e134Smrg    esac
4987a84e134Smrg  done
4997a84e134Smrg
5007a84e134Smrg  test -z "$dashmflag" && dashmflag=-M
5017a84e134Smrg  # Require at least two characters before searching for `:'
5027a84e134Smrg  # in the target name.  This is to cope with DOS-style filenames:
5037a84e134Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
5047a84e134Smrg  "$@" $dashmflag |
5057a84e134Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
5067a84e134Smrg  rm -f "$depfile"
5077a84e134Smrg  cat < "$tmpdepfile" > "$depfile"
5087a84e134Smrg  tr ' ' '
5097a84e134Smrg' < "$tmpdepfile" | \
5107a84e134Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
5117a84e134Smrg## correctly.  Breaking it into two sed invocations is a workaround.
5127a84e134Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
5137a84e134Smrg  rm -f "$tmpdepfile"
5147a84e134Smrg  ;;
5157a84e134Smrg
5167a84e134SmrgdashXmstdout)
5177a84e134Smrg  # This case only exists to satisfy depend.m4.  It is never actually
5187a84e134Smrg  # run, as this mode is specially recognized in the preamble.
5197a84e134Smrg  exit 1
5207a84e134Smrg  ;;
5217a84e134Smrg
5227a84e134Smrgmakedepend)
5237a84e134Smrg  "$@" || exit $?
5247a84e134Smrg  # Remove any Libtool call
5257a84e134Smrg  if test "$libtool" = yes; then
526e1e1713cSmrg    while test "X$1" != 'X--mode=compile'; do
5277a84e134Smrg      shift
5287a84e134Smrg    done
5297a84e134Smrg    shift
5307a84e134Smrg  fi
5317a84e134Smrg  # X makedepend
5327a84e134Smrg  shift
533e1e1713cSmrg  cleared=no eat=no
534e1e1713cSmrg  for arg
535e1e1713cSmrg  do
5367a84e134Smrg    case $cleared in
5377a84e134Smrg    no)
5387a84e134Smrg      set ""; shift
5397a84e134Smrg      cleared=yes ;;
5407a84e134Smrg    esac
541e1e1713cSmrg    if test $eat = yes; then
542e1e1713cSmrg      eat=no
543e1e1713cSmrg      continue
544e1e1713cSmrg    fi
5457a84e134Smrg    case "$arg" in
5467a84e134Smrg    -D*|-I*)
5477a84e134Smrg      set fnord "$@" "$arg"; shift ;;
5487a84e134Smrg    # Strip any option that makedepend may not understand.  Remove
5497a84e134Smrg    # the object too, otherwise makedepend will parse it as a source file.
550e1e1713cSmrg    -arch)
551e1e1713cSmrg      eat=yes ;;
5527a84e134Smrg    -*|$object)
5537a84e134Smrg      ;;
5547a84e134Smrg    *)
5557a84e134Smrg      set fnord "$@" "$arg"; shift ;;
5567a84e134Smrg    esac
5577a84e134Smrg  done
558e1e1713cSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
5597a84e134Smrg  touch "$tmpdepfile"
5607a84e134Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
5617a84e134Smrg  rm -f "$depfile"
562421c997bSmrg  # makedepend may prepend the VPATH from the source file name to the object.
563421c997bSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
564421c997bSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
5657a84e134Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
5667a84e134Smrg' | \
5677a84e134Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
5687a84e134Smrg## correctly.  Breaking it into two sed invocations is a workaround.
5697a84e134Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
5707a84e134Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
5717a84e134Smrg  ;;
5727a84e134Smrg
5737a84e134Smrgcpp)
5747a84e134Smrg  # Important note: in order to support this mode, a compiler *must*
5757a84e134Smrg  # always write the preprocessed file to stdout.
5767a84e134Smrg  "$@" || exit $?
5777a84e134Smrg
5787a84e134Smrg  # Remove the call to Libtool.
5797a84e134Smrg  if test "$libtool" = yes; then
580e1e1713cSmrg    while test "X$1" != 'X--mode=compile'; do
5817a84e134Smrg      shift
5827a84e134Smrg    done
5837a84e134Smrg    shift
5847a84e134Smrg  fi
5857a84e134Smrg
5867a84e134Smrg  # Remove `-o $object'.
5877a84e134Smrg  IFS=" "
5887a84e134Smrg  for arg
5897a84e134Smrg  do
5907a84e134Smrg    case $arg in
5917a84e134Smrg    -o)
5927a84e134Smrg      shift
5937a84e134Smrg      ;;
5947a84e134Smrg    $object)
5957a84e134Smrg      shift
5967a84e134Smrg      ;;
5977a84e134Smrg    *)
5987a84e134Smrg      set fnord "$@" "$arg"
5997a84e134Smrg      shift # fnord
6007a84e134Smrg      shift # $arg
6017a84e134Smrg      ;;
6027a84e134Smrg    esac
6037a84e134Smrg  done
6047a84e134Smrg
6057a84e134Smrg  "$@" -E |
6067a84e134Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
6077a84e134Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
6087a84e134Smrg    sed '$ s: \\$::' > "$tmpdepfile"
6097a84e134Smrg  rm -f "$depfile"
6107a84e134Smrg  echo "$object : \\" > "$depfile"
6117a84e134Smrg  cat < "$tmpdepfile" >> "$depfile"
6127a84e134Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
6137a84e134Smrg  rm -f "$tmpdepfile"
6147a84e134Smrg  ;;
6157a84e134Smrg
6167a84e134Smrgmsvisualcpp)
6177a84e134Smrg  # Important note: in order to support this mode, a compiler *must*
618e1e1713cSmrg  # always write the preprocessed file to stdout.
6197a84e134Smrg  "$@" || exit $?
620e1e1713cSmrg
621e1e1713cSmrg  # Remove the call to Libtool.
622e1e1713cSmrg  if test "$libtool" = yes; then
623e1e1713cSmrg    while test "X$1" != 'X--mode=compile'; do
624e1e1713cSmrg      shift
625e1e1713cSmrg    done
626e1e1713cSmrg    shift
627e1e1713cSmrg  fi
628e1e1713cSmrg
6297a84e134Smrg  IFS=" "
6307a84e134Smrg  for arg
6317a84e134Smrg  do
6327a84e134Smrg    case "$arg" in
633e1e1713cSmrg    -o)
634e1e1713cSmrg      shift
635e1e1713cSmrg      ;;
636e1e1713cSmrg    $object)
637e1e1713cSmrg      shift
638e1e1713cSmrg      ;;
6397a84e134Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
6407a84e134Smrg	set fnord "$@"
6417a84e134Smrg	shift
6427a84e134Smrg	shift
6437a84e134Smrg	;;
6447a84e134Smrg    *)
6457a84e134Smrg	set fnord "$@" "$arg"
6467a84e134Smrg	shift
6477a84e134Smrg	shift
6487a84e134Smrg	;;
6497a84e134Smrg    esac
6507a84e134Smrg  done
651e1e1713cSmrg  "$@" -E 2>/dev/null |
652e1e1713cSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
6537a84e134Smrg  rm -f "$depfile"
6547a84e134Smrg  echo "$object : \\" > "$depfile"
655e1e1713cSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
6567a84e134Smrg  echo "	" >> "$depfile"
657e1e1713cSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
6587a84e134Smrg  rm -f "$tmpdepfile"
6597a84e134Smrg  ;;
6607a84e134Smrg
661e1e1713cSmrgmsvcmsys)
662e1e1713cSmrg  # This case exists only to let depend.m4 do its work.  It works by
663e1e1713cSmrg  # looking at the text of this script.  This case will never be run,
664e1e1713cSmrg  # since it is checked for above.
665e1e1713cSmrg  exit 1
666e1e1713cSmrg  ;;
667e1e1713cSmrg
6687a84e134Smrgnone)
6697a84e134Smrg  exec "$@"
6707a84e134Smrg  ;;
6717a84e134Smrg
6727a84e134Smrg*)
6737a84e134Smrg  echo "Unknown depmode $depmode" 1>&2
6747a84e134Smrg  exit 1
6757a84e134Smrg  ;;
6767a84e134Smrgesac
6777a84e134Smrg
6787a84e134Smrgexit 0
6797a84e134Smrg
6807a84e134Smrg# Local Variables:
6817a84e134Smrg# mode: shell-script
6827a84e134Smrg# sh-indentation: 2
6837a84e134Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
6847a84e134Smrg# time-stamp-start: "scriptversion="
6857a84e134Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
686e1e1713cSmrg# time-stamp-time-zone: "UTC"
687e1e1713cSmrg# time-stamp-end: "; # UTC"
6887a84e134Smrg# End:
689