depcomp revision 8abc0ccf
17a0395d0Smrg#! /bin/sh
27a0395d0Smrg# depcomp - compile a program generating dependencies as side-effects
37a0395d0Smrg
48abc0ccfSmrgscriptversion=2012-03-27.16; # UTC
57a0395d0Smrg
68abc0ccfSmrg# Copyright (C) 1999-2012 Free Software Foundation, Inc.
77a0395d0Smrg
87a0395d0Smrg# This program is free software; you can redistribute it and/or modify
97a0395d0Smrg# it under the terms of the GNU General Public License as published by
107a0395d0Smrg# the Free Software Foundation; either version 2, or (at your option)
117a0395d0Smrg# any later version.
127a0395d0Smrg
137a0395d0Smrg# This program is distributed in the hope that it will be useful,
147a0395d0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
157a0395d0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
167a0395d0Smrg# GNU General Public License for more details.
177a0395d0Smrg
187a0395d0Smrg# You should have received a copy of the GNU General Public License
197366012aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
207a0395d0Smrg
217a0395d0Smrg# As a special exception to the GNU General Public License, if you
227a0395d0Smrg# distribute this file as part of a program that contains a
237a0395d0Smrg# configuration script generated by Autoconf, you may include it under
247a0395d0Smrg# the same distribution terms that you use for the rest of that program.
257a0395d0Smrg
267a0395d0Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
277a0395d0Smrg
287a0395d0Smrgcase $1 in
297a0395d0Smrg  '')
308abc0ccfSmrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
317a0395d0Smrg     exit 1;
327a0395d0Smrg     ;;
337a0395d0Smrg  -h | --h*)
347a0395d0Smrg    cat <<\EOF
357a0395d0SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
367a0395d0Smrg
377a0395d0SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
387a0395d0Smrgas side-effects.
397a0395d0Smrg
407a0395d0SmrgEnvironment variables:
417a0395d0Smrg  depmode     Dependency tracking mode.
428abc0ccfSmrg  source      Source file read by 'PROGRAMS ARGS'.
438abc0ccfSmrg  object      Object file output by 'PROGRAMS ARGS'.
447a0395d0Smrg  DEPDIR      directory where to store dependencies.
457a0395d0Smrg  depfile     Dependency file to output.
468abc0ccfSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
477a0395d0Smrg  libtool     Whether libtool is used (yes/no).
487a0395d0Smrg
497a0395d0SmrgReport bugs to <bug-automake@gnu.org>.
507a0395d0SmrgEOF
517a0395d0Smrg    exit $?
527a0395d0Smrg    ;;
537a0395d0Smrg  -v | --v*)
547a0395d0Smrg    echo "depcomp $scriptversion"
557a0395d0Smrg    exit $?
567a0395d0Smrg    ;;
577a0395d0Smrgesac
587a0395d0Smrg
598abc0ccfSmrg# A tabulation character.
608abc0ccfSmrgtab='	'
618abc0ccfSmrg# A newline character.
628abc0ccfSmrgnl='
638abc0ccfSmrg'
648abc0ccfSmrg
657a0395d0Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
667a0395d0Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
677a0395d0Smrg  exit 1
687a0395d0Smrgfi
697a0395d0Smrg
707a0395d0Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
717a0395d0Smrgdepfile=${depfile-`echo "$object" |
727a0395d0Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
737a0395d0Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
747a0395d0Smrg
757a0395d0Smrgrm -f "$tmpdepfile"
767a0395d0Smrg
777a0395d0Smrg# Some modes work just like other modes, but use different flags.  We
787a0395d0Smrg# parameterize here, but still list the modes in the big case below,
797a0395d0Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
807a0395d0Smrg# here, because this file can only contain one case statement.
817a0395d0Smrgif test "$depmode" = hp; then
827a0395d0Smrg  # HP compiler uses -M and no extra arg.
837a0395d0Smrg  gccflag=-M
847a0395d0Smrg  depmode=gcc
857a0395d0Smrgfi
867a0395d0Smrg
877a0395d0Smrgif test "$depmode" = dashXmstdout; then
887a0395d0Smrg   # This is just like dashmstdout with a different argument.
897a0395d0Smrg   dashmflag=-xM
907a0395d0Smrg   depmode=dashmstdout
917a0395d0Smrgfi
927a0395d0Smrg
937366012aSmrgcygpath_u="cygpath -u -f -"
947366012aSmrgif test "$depmode" = msvcmsys; then
957366012aSmrg   # This is just like msvisualcpp but w/o cygpath translation.
967366012aSmrg   # Just convert the backslash-escaped backslashes to single forward
977366012aSmrg   # slashes to satisfy depend.m4
988abc0ccfSmrg   cygpath_u='sed s,\\\\,/,g'
997366012aSmrg   depmode=msvisualcpp
1007366012aSmrgfi
1017366012aSmrg
1028abc0ccfSmrgif test "$depmode" = msvc7msys; then
1038abc0ccfSmrg   # This is just like msvc7 but w/o cygpath translation.
1048abc0ccfSmrg   # Just convert the backslash-escaped backslashes to single forward
1058abc0ccfSmrg   # slashes to satisfy depend.m4
1068abc0ccfSmrg   cygpath_u='sed s,\\\\,/,g'
1078abc0ccfSmrg   depmode=msvc7
1088abc0ccfSmrgfi
1098abc0ccfSmrg
1108abc0ccfSmrgif test "$depmode" = xlc; then
1118abc0ccfSmrg   # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations.
1128abc0ccfSmrg   gccflag=-qmakedep=gcc,-MF
1138abc0ccfSmrg   depmode=gcc
1148abc0ccfSmrgfi
1158abc0ccfSmrg
1167a0395d0Smrgcase "$depmode" in
1177a0395d0Smrggcc3)
1187a0395d0Smrg## gcc 3 implements dependency tracking that does exactly what
1197a0395d0Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1207a0395d0Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1217a0395d0Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1227a0395d0Smrg## the command line argument order; so add the flags where they
1237a0395d0Smrg## appear in depend2.am.  Note that the slowdown incurred here
1247a0395d0Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1257a0395d0Smrg  for arg
1267a0395d0Smrg  do
1277a0395d0Smrg    case $arg in
1287a0395d0Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1297a0395d0Smrg    *)  set fnord "$@" "$arg" ;;
1307a0395d0Smrg    esac
1317a0395d0Smrg    shift # fnord
1327a0395d0Smrg    shift # $arg
1337a0395d0Smrg  done
1347a0395d0Smrg  "$@"
1357a0395d0Smrg  stat=$?
1367a0395d0Smrg  if test $stat -eq 0; then :
1377a0395d0Smrg  else
1387a0395d0Smrg    rm -f "$tmpdepfile"
1397a0395d0Smrg    exit $stat
1407a0395d0Smrg  fi
1417a0395d0Smrg  mv "$tmpdepfile" "$depfile"
1427a0395d0Smrg  ;;
1437a0395d0Smrg
1447a0395d0Smrggcc)
1457a0395d0Smrg## There are various ways to get dependency output from gcc.  Here's
1467a0395d0Smrg## why we pick this rather obscure method:
1477a0395d0Smrg## - Don't want to use -MD because we'd like the dependencies to end
1487a0395d0Smrg##   up in a subdir.  Having to rename by hand is ugly.
1497a0395d0Smrg##   (We might end up doing this anyway to support other compilers.)
1507a0395d0Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
1517a0395d0Smrg##   -MM, not -M (despite what the docs say).
1527a0395d0Smrg## - Using -M directly means running the compiler twice (even worse
1537a0395d0Smrg##   than renaming).
1547a0395d0Smrg  if test -z "$gccflag"; then
1557a0395d0Smrg    gccflag=-MD,
1567a0395d0Smrg  fi
1577a0395d0Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
1587a0395d0Smrg  stat=$?
1597a0395d0Smrg  if test $stat -eq 0; then :
1607a0395d0Smrg  else
1617a0395d0Smrg    rm -f "$tmpdepfile"
1627a0395d0Smrg    exit $stat
1637a0395d0Smrg  fi
1647a0395d0Smrg  rm -f "$depfile"
1657a0395d0Smrg  echo "$object : \\" > "$depfile"
1667a0395d0Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
1677a0395d0Smrg## The second -e expression handles DOS-style file names with drive letters.
1687a0395d0Smrg  sed -e 's/^[^:]*: / /' \
1697a0395d0Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
1708abc0ccfSmrg## This next piece of magic avoids the "deleted header file" problem.
1717a0395d0Smrg## The problem is that when a header file which appears in a .P file
1727a0395d0Smrg## is deleted, the dependency causes make to die (because there is
1737a0395d0Smrg## typically no way to rebuild the header).  We avoid this by adding
1747a0395d0Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
1757a0395d0Smrg## this for us directly.
1768abc0ccfSmrg  tr ' ' "$nl" < "$tmpdepfile" |
1778abc0ccfSmrg## Some versions of gcc put a space before the ':'.  On the theory
1787a0395d0Smrg## that the space means something, we add a space to the output as
1798abc0ccfSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
1808abc0ccfSmrg## to the object.  Take care to not repeat it in the output.
1817a0395d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
1827a0395d0Smrg## correctly.  Breaking it into two sed invocations is a workaround.
1838abc0ccfSmrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
1848abc0ccfSmrg      | sed -e 's/$/ :/' >> "$depfile"
1857a0395d0Smrg  rm -f "$tmpdepfile"
1867a0395d0Smrg  ;;
1877a0395d0Smrg
1887a0395d0Smrghp)
1897a0395d0Smrg  # This case exists only to let depend.m4 do its work.  It works by
1907a0395d0Smrg  # looking at the text of this script.  This case will never be run,
1917a0395d0Smrg  # since it is checked for above.
1927a0395d0Smrg  exit 1
1937a0395d0Smrg  ;;
1947a0395d0Smrg
1957a0395d0Smrgsgi)
1967a0395d0Smrg  if test "$libtool" = yes; then
1977a0395d0Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
1987a0395d0Smrg  else
1997a0395d0Smrg    "$@" -MDupdate "$tmpdepfile"
2007a0395d0Smrg  fi
2017a0395d0Smrg  stat=$?
2027a0395d0Smrg  if test $stat -eq 0; then :
2037a0395d0Smrg  else
2047a0395d0Smrg    rm -f "$tmpdepfile"
2057a0395d0Smrg    exit $stat
2067a0395d0Smrg  fi
2077a0395d0Smrg  rm -f "$depfile"
2087a0395d0Smrg
2097a0395d0Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2107a0395d0Smrg    echo "$object : \\" > "$depfile"
2117a0395d0Smrg
2127a0395d0Smrg    # Clip off the initial element (the dependent).  Don't try to be
2137a0395d0Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2147a0395d0Smrg    # lines with more than a fixed number of characters (4096 in
2157a0395d0Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2168abc0ccfSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
2177a0395d0Smrg    # dependency line.
2188abc0ccfSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2197a0395d0Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
2208abc0ccfSmrg    tr "$nl" ' ' >> "$depfile"
2217366012aSmrg    echo >> "$depfile"
2227a0395d0Smrg
2237a0395d0Smrg    # The second pass generates a dummy entry for each header file.
2248abc0ccfSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2257a0395d0Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2267366012aSmrg   >> "$depfile"
2277a0395d0Smrg  else
2287a0395d0Smrg    # The sourcefile does not contain any dependencies, so just
2297a0395d0Smrg    # store a dummy comment line, to avoid errors with the Makefile
2307a0395d0Smrg    # "include basename.Plo" scheme.
2317a0395d0Smrg    echo "#dummy" > "$depfile"
2327a0395d0Smrg  fi
2337a0395d0Smrg  rm -f "$tmpdepfile"
2347a0395d0Smrg  ;;
2357a0395d0Smrg
2368abc0ccfSmrgxlc)
2378abc0ccfSmrg  # This case exists only to let depend.m4 do its work.  It works by
2388abc0ccfSmrg  # looking at the text of this script.  This case will never be run,
2398abc0ccfSmrg  # since it is checked for above.
2408abc0ccfSmrg  exit 1
2418abc0ccfSmrg  ;;
2428abc0ccfSmrg
2437a0395d0Smrgaix)
2447a0395d0Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2457a0395d0Smrg  # in a .u file.  In older versions, this file always lives in the
2468abc0ccfSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
2477a0395d0Smrg  # start of each line; $object doesn't have directory information.
2487a0395d0Smrg  # Version 6 uses the directory in both cases.
2497a0395d0Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
2507a0395d0Smrg  test "x$dir" = "x$object" && dir=
2517a0395d0Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
2527a0395d0Smrg  if test "$libtool" = yes; then
2537a0395d0Smrg    tmpdepfile1=$dir$base.u
2547a0395d0Smrg    tmpdepfile2=$base.u
2557a0395d0Smrg    tmpdepfile3=$dir.libs/$base.u
2567a0395d0Smrg    "$@" -Wc,-M
2577a0395d0Smrg  else
2587a0395d0Smrg    tmpdepfile1=$dir$base.u
2597a0395d0Smrg    tmpdepfile2=$dir$base.u
2607a0395d0Smrg    tmpdepfile3=$dir$base.u
2617a0395d0Smrg    "$@" -M
2627a0395d0Smrg  fi
2637a0395d0Smrg  stat=$?
2647a0395d0Smrg
2657a0395d0Smrg  if test $stat -eq 0; then :
2667a0395d0Smrg  else
2677a0395d0Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
2687a0395d0Smrg    exit $stat
2697a0395d0Smrg  fi
2707a0395d0Smrg
2717a0395d0Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
2727a0395d0Smrg  do
2737a0395d0Smrg    test -f "$tmpdepfile" && break
2747a0395d0Smrg  done
2757a0395d0Smrg  if test -f "$tmpdepfile"; then
2768abc0ccfSmrg    # Each line is of the form 'foo.o: dependent.h'.
2777a0395d0Smrg    # Do two passes, one to just change these to
2788abc0ccfSmrg    # '$object: dependent.h' and one to simply 'dependent.h:'.
2797a0395d0Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
2808abc0ccfSmrg    sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
2817a0395d0Smrg  else
2827a0395d0Smrg    # The sourcefile does not contain any dependencies, so just
2837a0395d0Smrg    # store a dummy comment line, to avoid errors with the Makefile
2847a0395d0Smrg    # "include basename.Plo" scheme.
2857a0395d0Smrg    echo "#dummy" > "$depfile"
2867a0395d0Smrg  fi
2877a0395d0Smrg  rm -f "$tmpdepfile"
2887a0395d0Smrg  ;;
2897a0395d0Smrg
2907a0395d0Smrgicc)
2918abc0ccfSmrg  # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.
2928abc0ccfSmrg  # However on
2938abc0ccfSmrg  #    $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c
2947a0395d0Smrg  # ICC 7.0 will fill foo.d with something like
2957a0395d0Smrg  #    foo.o: sub/foo.c
2967a0395d0Smrg  #    foo.o: sub/foo.h
2978abc0ccfSmrg  # which is wrong.  We want
2987a0395d0Smrg  #    sub/foo.o: sub/foo.c
2997a0395d0Smrg  #    sub/foo.o: sub/foo.h
3007a0395d0Smrg  #    sub/foo.c:
3017a0395d0Smrg  #    sub/foo.h:
3027a0395d0Smrg  # ICC 7.1 will output
3037a0395d0Smrg  #    foo.o: sub/foo.c sub/foo.h
3048abc0ccfSmrg  # and will wrap long lines using '\':
3057a0395d0Smrg  #    foo.o: sub/foo.c ... \
3067a0395d0Smrg  #     sub/foo.h ... \
3077a0395d0Smrg  #     ...
3088abc0ccfSmrg  # tcc 0.9.26 (FIXME still under development at the moment of writing)
3098abc0ccfSmrg  # will emit a similar output, but also prepend the continuation lines
3108abc0ccfSmrg  # with horizontal tabulation characters.
3117a0395d0Smrg  "$@" -MD -MF "$tmpdepfile"
3127a0395d0Smrg  stat=$?
3137a0395d0Smrg  if test $stat -eq 0; then :
3147a0395d0Smrg  else
3157a0395d0Smrg    rm -f "$tmpdepfile"
3167a0395d0Smrg    exit $stat
3177a0395d0Smrg  fi
3187a0395d0Smrg  rm -f "$depfile"
3198abc0ccfSmrg  # Each line is of the form 'foo.o: dependent.h',
3208abc0ccfSmrg  # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.
3217a0395d0Smrg  # Do two passes, one to just change these to
3228abc0ccfSmrg  # '$object: dependent.h' and one to simply 'dependent.h:'.
3238abc0ccfSmrg  sed -e "s/^[ $tab][ $tab]*/  /" -e "s,^[^:]*:,$object :," \
3248abc0ccfSmrg    < "$tmpdepfile" > "$depfile"
3258abc0ccfSmrg  sed '
3268abc0ccfSmrg    s/[ '"$tab"'][ '"$tab"']*/ /g
3278abc0ccfSmrg    s/^ *//
3288abc0ccfSmrg    s/ *\\*$//
3298abc0ccfSmrg    s/^[^:]*: *//
3308abc0ccfSmrg    /^$/d
3318abc0ccfSmrg    /:$/d
3328abc0ccfSmrg    s/$/ :/
3338abc0ccfSmrg  ' < "$tmpdepfile" >> "$depfile"
3347a0395d0Smrg  rm -f "$tmpdepfile"
3357a0395d0Smrg  ;;
3367a0395d0Smrg
3377a0395d0Smrghp2)
3387a0395d0Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
3397a0395d0Smrg  # compilers, which have integrated preprocessors.  The correct option
3407a0395d0Smrg  # to use with these is +Maked; it writes dependencies to a file named
3417a0395d0Smrg  # 'foo.d', which lands next to the object file, wherever that
3427a0395d0Smrg  # happens to be.
3437a0395d0Smrg  # Much of this is similar to the tru64 case; see comments there.
3447a0395d0Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
3457a0395d0Smrg  test "x$dir" = "x$object" && dir=
3467a0395d0Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
3477a0395d0Smrg  if test "$libtool" = yes; then
3487a0395d0Smrg    tmpdepfile1=$dir$base.d
3497a0395d0Smrg    tmpdepfile2=$dir.libs/$base.d
3507a0395d0Smrg    "$@" -Wc,+Maked
3517a0395d0Smrg  else
3527a0395d0Smrg    tmpdepfile1=$dir$base.d
3537a0395d0Smrg    tmpdepfile2=$dir$base.d
3547a0395d0Smrg    "$@" +Maked
3557a0395d0Smrg  fi
3567a0395d0Smrg  stat=$?
3577a0395d0Smrg  if test $stat -eq 0; then :
3587a0395d0Smrg  else
3597a0395d0Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
3607a0395d0Smrg     exit $stat
3617a0395d0Smrg  fi
3627a0395d0Smrg
3637a0395d0Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
3647a0395d0Smrg  do
3657a0395d0Smrg    test -f "$tmpdepfile" && break
3667a0395d0Smrg  done
3677a0395d0Smrg  if test -f "$tmpdepfile"; then
3687a0395d0Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
3698abc0ccfSmrg    # Add 'dependent.h:' lines.
3707366012aSmrg    sed -ne '2,${
3717366012aSmrg	       s/^ *//
3727366012aSmrg	       s/ \\*$//
3737366012aSmrg	       s/$/:/
3747366012aSmrg	       p
3757366012aSmrg	     }' "$tmpdepfile" >> "$depfile"
3767a0395d0Smrg  else
3777a0395d0Smrg    echo "#dummy" > "$depfile"
3787a0395d0Smrg  fi
3797a0395d0Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
3807a0395d0Smrg  ;;
3817a0395d0Smrg
3827a0395d0Smrgtru64)
3837a0395d0Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
3848abc0ccfSmrg   # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
3857a0395d0Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
3868abc0ccfSmrg   # dependencies in 'foo.d' instead, so we check for that too.
3877a0395d0Smrg   # Subdirectories are respected.
3887a0395d0Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
3897a0395d0Smrg   test "x$dir" = "x$object" && dir=
3907a0395d0Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
3917a0395d0Smrg
3927a0395d0Smrg   if test "$libtool" = yes; then
3937a0395d0Smrg      # With Tru64 cc, shared objects can also be used to make a
3947a0395d0Smrg      # static library.  This mechanism is used in libtool 1.4 series to
3957a0395d0Smrg      # handle both shared and static libraries in a single compilation.
3967a0395d0Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
3977a0395d0Smrg      #
3987a0395d0Smrg      # With libtool 1.5 this exception was removed, and libtool now
3997a0395d0Smrg      # generates 2 separate objects for the 2 libraries.  These two
4007a0395d0Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
4017a0395d0Smrg      # in $dir$base.o.d.  We have to check for both files, because
4027a0395d0Smrg      # one of the two compilations can be disabled.  We should prefer
4037a0395d0Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4047a0395d0Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
4057a0395d0Smrg      # the former would cause a distcleancheck panic.
4067a0395d0Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
4077a0395d0Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
4087a0395d0Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
4097a0395d0Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
4107a0395d0Smrg      "$@" -Wc,-MD
4117a0395d0Smrg   else
4127a0395d0Smrg      tmpdepfile1=$dir$base.o.d
4137a0395d0Smrg      tmpdepfile2=$dir$base.d
4147a0395d0Smrg      tmpdepfile3=$dir$base.d
4157a0395d0Smrg      tmpdepfile4=$dir$base.d
4167a0395d0Smrg      "$@" -MD
4177a0395d0Smrg   fi
4187a0395d0Smrg
4197a0395d0Smrg   stat=$?
4207a0395d0Smrg   if test $stat -eq 0; then :
4217a0395d0Smrg   else
4227a0395d0Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
4237a0395d0Smrg      exit $stat
4247a0395d0Smrg   fi
4257a0395d0Smrg
4267a0395d0Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
4277a0395d0Smrg   do
4287a0395d0Smrg     test -f "$tmpdepfile" && break
4297a0395d0Smrg   done
4307a0395d0Smrg   if test -f "$tmpdepfile"; then
4317a0395d0Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
4328abc0ccfSmrg      sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
4337a0395d0Smrg   else
4347a0395d0Smrg      echo "#dummy" > "$depfile"
4357a0395d0Smrg   fi
4367a0395d0Smrg   rm -f "$tmpdepfile"
4377a0395d0Smrg   ;;
4387a0395d0Smrg
4398abc0ccfSmrgmsvc7)
4408abc0ccfSmrg  if test "$libtool" = yes; then
4418abc0ccfSmrg    showIncludes=-Wc,-showIncludes
4428abc0ccfSmrg  else
4438abc0ccfSmrg    showIncludes=-showIncludes
4448abc0ccfSmrg  fi
4458abc0ccfSmrg  "$@" $showIncludes > "$tmpdepfile"
4468abc0ccfSmrg  stat=$?
4478abc0ccfSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
4488abc0ccfSmrg  if test "$stat" = 0; then :
4498abc0ccfSmrg  else
4508abc0ccfSmrg    rm -f "$tmpdepfile"
4518abc0ccfSmrg    exit $stat
4528abc0ccfSmrg  fi
4538abc0ccfSmrg  rm -f "$depfile"
4548abc0ccfSmrg  echo "$object : \\" > "$depfile"
4558abc0ccfSmrg  # The first sed program below extracts the file names and escapes
4568abc0ccfSmrg  # backslashes for cygpath.  The second sed program outputs the file
4578abc0ccfSmrg  # name when reading, but also accumulates all include files in the
4588abc0ccfSmrg  # hold buffer in order to output them again at the end.  This only
4598abc0ccfSmrg  # works with sed implementations that can handle large buffers.
4608abc0ccfSmrg  sed < "$tmpdepfile" -n '
4618abc0ccfSmrg/^Note: including file:  *\(.*\)/ {
4628abc0ccfSmrg  s//\1/
4638abc0ccfSmrg  s/\\/\\\\/g
4648abc0ccfSmrg  p
4658abc0ccfSmrg}' | $cygpath_u | sort -u | sed -n '
4668abc0ccfSmrgs/ /\\ /g
4678abc0ccfSmrgs/\(.*\)/'"$tab"'\1 \\/p
4688abc0ccfSmrgs/.\(.*\) \\/\1:/
4698abc0ccfSmrgH
4708abc0ccfSmrg$ {
4718abc0ccfSmrg  s/.*/'"$tab"'/
4728abc0ccfSmrg  G
4738abc0ccfSmrg  p
4748abc0ccfSmrg}' >> "$depfile"
4758abc0ccfSmrg  rm -f "$tmpdepfile"
4768abc0ccfSmrg  ;;
4778abc0ccfSmrg
4788abc0ccfSmrgmsvc7msys)
4798abc0ccfSmrg  # This case exists only to let depend.m4 do its work.  It works by
4808abc0ccfSmrg  # looking at the text of this script.  This case will never be run,
4818abc0ccfSmrg  # since it is checked for above.
4828abc0ccfSmrg  exit 1
4838abc0ccfSmrg  ;;
4848abc0ccfSmrg
4857a0395d0Smrg#nosideeffect)
4867a0395d0Smrg  # This comment above is used by automake to tell side-effect
4877a0395d0Smrg  # dependency tracking mechanisms from slower ones.
4887a0395d0Smrg
4897a0395d0Smrgdashmstdout)
4907a0395d0Smrg  # Important note: in order to support this mode, a compiler *must*
4917a0395d0Smrg  # always write the preprocessed file to stdout, regardless of -o.
4927a0395d0Smrg  "$@" || exit $?
4937a0395d0Smrg
4947a0395d0Smrg  # Remove the call to Libtool.
4957a0395d0Smrg  if test "$libtool" = yes; then
4967366012aSmrg    while test "X$1" != 'X--mode=compile'; do
4977a0395d0Smrg      shift
4987a0395d0Smrg    done
4997a0395d0Smrg    shift
5007a0395d0Smrg  fi
5017a0395d0Smrg
5028abc0ccfSmrg  # Remove '-o $object'.
5037a0395d0Smrg  IFS=" "
5047a0395d0Smrg  for arg
5057a0395d0Smrg  do
5067a0395d0Smrg    case $arg in
5077a0395d0Smrg    -o)
5087a0395d0Smrg      shift
5097a0395d0Smrg      ;;
5107a0395d0Smrg    $object)
5117a0395d0Smrg      shift
5127a0395d0Smrg      ;;
5137a0395d0Smrg    *)
5147a0395d0Smrg      set fnord "$@" "$arg"
5157a0395d0Smrg      shift # fnord
5167a0395d0Smrg      shift # $arg
5177a0395d0Smrg      ;;
5187a0395d0Smrg    esac
5197a0395d0Smrg  done
5207a0395d0Smrg
5217a0395d0Smrg  test -z "$dashmflag" && dashmflag=-M
5228abc0ccfSmrg  # Require at least two characters before searching for ':'
5237a0395d0Smrg  # in the target name.  This is to cope with DOS-style filenames:
5248abc0ccfSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
5257a0395d0Smrg  "$@" $dashmflag |
5268abc0ccfSmrg    sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"
5277a0395d0Smrg  rm -f "$depfile"
5287a0395d0Smrg  cat < "$tmpdepfile" > "$depfile"
5298abc0ccfSmrg  tr ' ' "$nl" < "$tmpdepfile" | \
5307a0395d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
5317a0395d0Smrg## correctly.  Breaking it into two sed invocations is a workaround.
5327a0395d0Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
5337a0395d0Smrg  rm -f "$tmpdepfile"
5347a0395d0Smrg  ;;
5357a0395d0Smrg
5367a0395d0SmrgdashXmstdout)
5377a0395d0Smrg  # This case only exists to satisfy depend.m4.  It is never actually
5387a0395d0Smrg  # run, as this mode is specially recognized in the preamble.
5397a0395d0Smrg  exit 1
5407a0395d0Smrg  ;;
5417a0395d0Smrg
5427a0395d0Smrgmakedepend)
5437a0395d0Smrg  "$@" || exit $?
5447a0395d0Smrg  # Remove any Libtool call
5457a0395d0Smrg  if test "$libtool" = yes; then
5467366012aSmrg    while test "X$1" != 'X--mode=compile'; do
5477a0395d0Smrg      shift
5487a0395d0Smrg    done
5497a0395d0Smrg    shift
5507a0395d0Smrg  fi
5517a0395d0Smrg  # X makedepend
5527a0395d0Smrg  shift
5537366012aSmrg  cleared=no eat=no
5547366012aSmrg  for arg
5557366012aSmrg  do
5567a0395d0Smrg    case $cleared in
5577a0395d0Smrg    no)
5587a0395d0Smrg      set ""; shift
5597a0395d0Smrg      cleared=yes ;;
5607a0395d0Smrg    esac
5617366012aSmrg    if test $eat = yes; then
5627366012aSmrg      eat=no
5637366012aSmrg      continue
5647366012aSmrg    fi
5657a0395d0Smrg    case "$arg" in
5667a0395d0Smrg    -D*|-I*)
5677a0395d0Smrg      set fnord "$@" "$arg"; shift ;;
5687a0395d0Smrg    # Strip any option that makedepend may not understand.  Remove
5697a0395d0Smrg    # the object too, otherwise makedepend will parse it as a source file.
5707366012aSmrg    -arch)
5717366012aSmrg      eat=yes ;;
5727a0395d0Smrg    -*|$object)
5737a0395d0Smrg      ;;
5747a0395d0Smrg    *)
5757a0395d0Smrg      set fnord "$@" "$arg"; shift ;;
5767a0395d0Smrg    esac
5777a0395d0Smrg  done
5787366012aSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
5797a0395d0Smrg  touch "$tmpdepfile"
5807a0395d0Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
5817a0395d0Smrg  rm -f "$depfile"
5828abc0ccfSmrg  # makedepend may prepend the VPATH from the source file name to the object.
5838abc0ccfSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
5848abc0ccfSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
5858abc0ccfSmrg  sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \
5867a0395d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
5877a0395d0Smrg## correctly.  Breaking it into two sed invocations is a workaround.
5887a0395d0Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
5897a0395d0Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
5907a0395d0Smrg  ;;
5917a0395d0Smrg
5927a0395d0Smrgcpp)
5937a0395d0Smrg  # Important note: in order to support this mode, a compiler *must*
5947a0395d0Smrg  # always write the preprocessed file to stdout.
5957a0395d0Smrg  "$@" || exit $?
5967a0395d0Smrg
5977a0395d0Smrg  # Remove the call to Libtool.
5987a0395d0Smrg  if test "$libtool" = yes; then
5997366012aSmrg    while test "X$1" != 'X--mode=compile'; do
6007a0395d0Smrg      shift
6017a0395d0Smrg    done
6027a0395d0Smrg    shift
6037a0395d0Smrg  fi
6047a0395d0Smrg
6058abc0ccfSmrg  # Remove '-o $object'.
6067a0395d0Smrg  IFS=" "
6077a0395d0Smrg  for arg
6087a0395d0Smrg  do
6097a0395d0Smrg    case $arg in
6107a0395d0Smrg    -o)
6117a0395d0Smrg      shift
6127a0395d0Smrg      ;;
6137a0395d0Smrg    $object)
6147a0395d0Smrg      shift
6157a0395d0Smrg      ;;
6167a0395d0Smrg    *)
6177a0395d0Smrg      set fnord "$@" "$arg"
6187a0395d0Smrg      shift # fnord
6197a0395d0Smrg      shift # $arg
6207a0395d0Smrg      ;;
6217a0395d0Smrg    esac
6227a0395d0Smrg  done
6237a0395d0Smrg
6247a0395d0Smrg  "$@" -E |
6257a0395d0Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
6267a0395d0Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
6277a0395d0Smrg    sed '$ s: \\$::' > "$tmpdepfile"
6287a0395d0Smrg  rm -f "$depfile"
6297a0395d0Smrg  echo "$object : \\" > "$depfile"
6307a0395d0Smrg  cat < "$tmpdepfile" >> "$depfile"
6317a0395d0Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
6327a0395d0Smrg  rm -f "$tmpdepfile"
6337a0395d0Smrg  ;;
6347a0395d0Smrg
6357a0395d0Smrgmsvisualcpp)
6367a0395d0Smrg  # Important note: in order to support this mode, a compiler *must*
6377366012aSmrg  # always write the preprocessed file to stdout.
6387a0395d0Smrg  "$@" || exit $?
6397366012aSmrg
6407366012aSmrg  # Remove the call to Libtool.
6417366012aSmrg  if test "$libtool" = yes; then
6427366012aSmrg    while test "X$1" != 'X--mode=compile'; do
6437366012aSmrg      shift
6447366012aSmrg    done
6457366012aSmrg    shift
6467366012aSmrg  fi
6477366012aSmrg
6487a0395d0Smrg  IFS=" "
6497a0395d0Smrg  for arg
6507a0395d0Smrg  do
6517a0395d0Smrg    case "$arg" in
6527366012aSmrg    -o)
6537366012aSmrg      shift
6547366012aSmrg      ;;
6557366012aSmrg    $object)
6567366012aSmrg      shift
6577366012aSmrg      ;;
6587a0395d0Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
6597a0395d0Smrg	set fnord "$@"
6607a0395d0Smrg	shift
6617a0395d0Smrg	shift
6627a0395d0Smrg	;;
6637a0395d0Smrg    *)
6647a0395d0Smrg	set fnord "$@" "$arg"
6657a0395d0Smrg	shift
6667a0395d0Smrg	shift
6677a0395d0Smrg	;;
6687a0395d0Smrg    esac
6697a0395d0Smrg  done
6707366012aSmrg  "$@" -E 2>/dev/null |
6717366012aSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
6727a0395d0Smrg  rm -f "$depfile"
6737a0395d0Smrg  echo "$object : \\" > "$depfile"
6748abc0ccfSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
6758abc0ccfSmrg  echo "$tab" >> "$depfile"
6767366012aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
6777a0395d0Smrg  rm -f "$tmpdepfile"
6787a0395d0Smrg  ;;
6797a0395d0Smrg
6807366012aSmrgmsvcmsys)
6817366012aSmrg  # This case exists only to let depend.m4 do its work.  It works by
6827366012aSmrg  # looking at the text of this script.  This case will never be run,
6837366012aSmrg  # since it is checked for above.
6847366012aSmrg  exit 1
6857366012aSmrg  ;;
6867366012aSmrg
6877a0395d0Smrgnone)
6887a0395d0Smrg  exec "$@"
6897a0395d0Smrg  ;;
6907a0395d0Smrg
6917a0395d0Smrg*)
6927a0395d0Smrg  echo "Unknown depmode $depmode" 1>&2
6937a0395d0Smrg  exit 1
6947a0395d0Smrg  ;;
6957a0395d0Smrgesac
6967a0395d0Smrg
6977a0395d0Smrgexit 0
6987a0395d0Smrg
6997a0395d0Smrg# Local Variables:
7007a0395d0Smrg# mode: shell-script
7017a0395d0Smrg# sh-indentation: 2
7027a0395d0Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
7037a0395d0Smrg# time-stamp-start: "scriptversion="
7047a0395d0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7057366012aSmrg# time-stamp-time-zone: "UTC"
7067366012aSmrg# time-stamp-end: "; # UTC"
7077a0395d0Smrg# End:
708