depcomp revision 0da4cdcc
19bd41f2cSmrg#! /bin/sh
29bd41f2cSmrg# depcomp - compile a program generating dependencies as side-effects
39bd41f2cSmrg
40da4cdccSmrgscriptversion=2012-03-27.16; # UTC
59bd41f2cSmrg
60da4cdccSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
70da4cdccSmrg# 2011, 2012 Free Software Foundation, Inc.
89bd41f2cSmrg
99bd41f2cSmrg# This program is free software; you can redistribute it and/or modify
109bd41f2cSmrg# it under the terms of the GNU General Public License as published by
119bd41f2cSmrg# the Free Software Foundation; either version 2, or (at your option)
129bd41f2cSmrg# any later version.
139bd41f2cSmrg
149bd41f2cSmrg# This program is distributed in the hope that it will be useful,
159bd41f2cSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
169bd41f2cSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
179bd41f2cSmrg# GNU General Public License for more details.
189bd41f2cSmrg
199bd41f2cSmrg# You should have received a copy of the GNU General Public License
200da4cdccSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
219bd41f2cSmrg
229bd41f2cSmrg# As a special exception to the GNU General Public License, if you
239bd41f2cSmrg# distribute this file as part of a program that contains a
249bd41f2cSmrg# configuration script generated by Autoconf, you may include it under
259bd41f2cSmrg# the same distribution terms that you use for the rest of that program.
269bd41f2cSmrg
279bd41f2cSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
289bd41f2cSmrg
299bd41f2cSmrgcase $1 in
309bd41f2cSmrg  '')
310da4cdccSmrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
329bd41f2cSmrg     exit 1;
339bd41f2cSmrg     ;;
349bd41f2cSmrg  -h | --h*)
359bd41f2cSmrg    cat <<\EOF
369bd41f2cSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
379bd41f2cSmrg
389bd41f2cSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
399bd41f2cSmrgas side-effects.
409bd41f2cSmrg
419bd41f2cSmrgEnvironment variables:
429bd41f2cSmrg  depmode     Dependency tracking mode.
430da4cdccSmrg  source      Source file read by 'PROGRAMS ARGS'.
440da4cdccSmrg  object      Object file output by 'PROGRAMS ARGS'.
459bd41f2cSmrg  DEPDIR      directory where to store dependencies.
469bd41f2cSmrg  depfile     Dependency file to output.
470da4cdccSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
489bd41f2cSmrg  libtool     Whether libtool is used (yes/no).
499bd41f2cSmrg
509bd41f2cSmrgReport bugs to <bug-automake@gnu.org>.
519bd41f2cSmrgEOF
529bd41f2cSmrg    exit $?
539bd41f2cSmrg    ;;
549bd41f2cSmrg  -v | --v*)
559bd41f2cSmrg    echo "depcomp $scriptversion"
569bd41f2cSmrg    exit $?
579bd41f2cSmrg    ;;
589bd41f2cSmrgesac
599bd41f2cSmrg
600da4cdccSmrg# A tabulation character.
610da4cdccSmrgtab='	'
620da4cdccSmrg# A newline character.
630da4cdccSmrgnl='
640da4cdccSmrg'
650da4cdccSmrg
669bd41f2cSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
679bd41f2cSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
689bd41f2cSmrg  exit 1
699bd41f2cSmrgfi
709bd41f2cSmrg
719bd41f2cSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
729bd41f2cSmrgdepfile=${depfile-`echo "$object" |
739bd41f2cSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
749bd41f2cSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
759bd41f2cSmrg
769bd41f2cSmrgrm -f "$tmpdepfile"
779bd41f2cSmrg
789bd41f2cSmrg# Some modes work just like other modes, but use different flags.  We
799bd41f2cSmrg# parameterize here, but still list the modes in the big case below,
809bd41f2cSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
819bd41f2cSmrg# here, because this file can only contain one case statement.
829bd41f2cSmrgif test "$depmode" = hp; then
839bd41f2cSmrg  # HP compiler uses -M and no extra arg.
849bd41f2cSmrg  gccflag=-M
859bd41f2cSmrg  depmode=gcc
869bd41f2cSmrgfi
879bd41f2cSmrg
889bd41f2cSmrgif test "$depmode" = dashXmstdout; then
899bd41f2cSmrg   # This is just like dashmstdout with a different argument.
909bd41f2cSmrg   dashmflag=-xM
919bd41f2cSmrg   depmode=dashmstdout
929bd41f2cSmrgfi
939bd41f2cSmrg
940da4cdccSmrgcygpath_u="cygpath -u -f -"
950da4cdccSmrgif test "$depmode" = msvcmsys; then
960da4cdccSmrg   # This is just like msvisualcpp but w/o cygpath translation.
970da4cdccSmrg   # Just convert the backslash-escaped backslashes to single forward
980da4cdccSmrg   # slashes to satisfy depend.m4
990da4cdccSmrg   cygpath_u='sed s,\\\\,/,g'
1000da4cdccSmrg   depmode=msvisualcpp
1010da4cdccSmrgfi
1020da4cdccSmrg
1030da4cdccSmrgif test "$depmode" = msvc7msys; then
1040da4cdccSmrg   # This is just like msvc7 but w/o cygpath translation.
1050da4cdccSmrg   # Just convert the backslash-escaped backslashes to single forward
1060da4cdccSmrg   # slashes to satisfy depend.m4
1070da4cdccSmrg   cygpath_u='sed s,\\\\,/,g'
1080da4cdccSmrg   depmode=msvc7
1090da4cdccSmrgfi
1100da4cdccSmrg
1110da4cdccSmrgif test "$depmode" = xlc; then
1120da4cdccSmrg   # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations.
1130da4cdccSmrg   gccflag=-qmakedep=gcc,-MF
1140da4cdccSmrg   depmode=gcc
1150da4cdccSmrgfi
1160da4cdccSmrg
1179bd41f2cSmrgcase "$depmode" in
1189bd41f2cSmrggcc3)
1199bd41f2cSmrg## gcc 3 implements dependency tracking that does exactly what
1209bd41f2cSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1219bd41f2cSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1229418810dSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1239418810dSmrg## the command line argument order; so add the flags where they
1249418810dSmrg## appear in depend2.am.  Note that the slowdown incurred here
1259418810dSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1269418810dSmrg  for arg
1279418810dSmrg  do
1289418810dSmrg    case $arg in
1299418810dSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1309418810dSmrg    *)  set fnord "$@" "$arg" ;;
1319418810dSmrg    esac
1329418810dSmrg    shift # fnord
1339418810dSmrg    shift # $arg
1349418810dSmrg  done
1359418810dSmrg  "$@"
1369bd41f2cSmrg  stat=$?
1379bd41f2cSmrg  if test $stat -eq 0; then :
1389bd41f2cSmrg  else
1399bd41f2cSmrg    rm -f "$tmpdepfile"
1409bd41f2cSmrg    exit $stat
1419bd41f2cSmrg  fi
1429bd41f2cSmrg  mv "$tmpdepfile" "$depfile"
1439bd41f2cSmrg  ;;
1449bd41f2cSmrg
1459bd41f2cSmrggcc)
1469bd41f2cSmrg## There are various ways to get dependency output from gcc.  Here's
1479bd41f2cSmrg## why we pick this rather obscure method:
1489bd41f2cSmrg## - Don't want to use -MD because we'd like the dependencies to end
1499bd41f2cSmrg##   up in a subdir.  Having to rename by hand is ugly.
1509bd41f2cSmrg##   (We might end up doing this anyway to support other compilers.)
1519bd41f2cSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
1529bd41f2cSmrg##   -MM, not -M (despite what the docs say).
1539bd41f2cSmrg## - Using -M directly means running the compiler twice (even worse
1549bd41f2cSmrg##   than renaming).
1559bd41f2cSmrg  if test -z "$gccflag"; then
1569bd41f2cSmrg    gccflag=-MD,
1579bd41f2cSmrg  fi
1589bd41f2cSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
1599bd41f2cSmrg  stat=$?
1609bd41f2cSmrg  if test $stat -eq 0; then :
1619bd41f2cSmrg  else
1629bd41f2cSmrg    rm -f "$tmpdepfile"
1639bd41f2cSmrg    exit $stat
1649bd41f2cSmrg  fi
1659bd41f2cSmrg  rm -f "$depfile"
1669bd41f2cSmrg  echo "$object : \\" > "$depfile"
1679bd41f2cSmrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
1689bd41f2cSmrg## The second -e expression handles DOS-style file names with drive letters.
1699bd41f2cSmrg  sed -e 's/^[^:]*: / /' \
1709bd41f2cSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
1710da4cdccSmrg## This next piece of magic avoids the "deleted header file" problem.
1729bd41f2cSmrg## The problem is that when a header file which appears in a .P file
1739bd41f2cSmrg## is deleted, the dependency causes make to die (because there is
1749bd41f2cSmrg## typically no way to rebuild the header).  We avoid this by adding
1759bd41f2cSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
1769bd41f2cSmrg## this for us directly.
1770da4cdccSmrg  tr ' ' "$nl" < "$tmpdepfile" |
1780da4cdccSmrg## Some versions of gcc put a space before the ':'.  On the theory
1799bd41f2cSmrg## that the space means something, we add a space to the output as
1800da4cdccSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
1810da4cdccSmrg## to the object.  Take care to not repeat it in the output.
1829bd41f2cSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
1839bd41f2cSmrg## correctly.  Breaking it into two sed invocations is a workaround.
1840da4cdccSmrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
1850da4cdccSmrg      | sed -e 's/$/ :/' >> "$depfile"
1869bd41f2cSmrg  rm -f "$tmpdepfile"
1879bd41f2cSmrg  ;;
1889bd41f2cSmrg
1899bd41f2cSmrghp)
1909bd41f2cSmrg  # This case exists only to let depend.m4 do its work.  It works by
1919bd41f2cSmrg  # looking at the text of this script.  This case will never be run,
1929bd41f2cSmrg  # since it is checked for above.
1939bd41f2cSmrg  exit 1
1949bd41f2cSmrg  ;;
1959bd41f2cSmrg
1969bd41f2cSmrgsgi)
1979bd41f2cSmrg  if test "$libtool" = yes; then
1989bd41f2cSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
1999bd41f2cSmrg  else
2009bd41f2cSmrg    "$@" -MDupdate "$tmpdepfile"
2019bd41f2cSmrg  fi
2029bd41f2cSmrg  stat=$?
2039bd41f2cSmrg  if test $stat -eq 0; then :
2049bd41f2cSmrg  else
2059bd41f2cSmrg    rm -f "$tmpdepfile"
2069bd41f2cSmrg    exit $stat
2079bd41f2cSmrg  fi
2089bd41f2cSmrg  rm -f "$depfile"
2099bd41f2cSmrg
2109bd41f2cSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2119bd41f2cSmrg    echo "$object : \\" > "$depfile"
2129bd41f2cSmrg
2139bd41f2cSmrg    # Clip off the initial element (the dependent).  Don't try to be
2149bd41f2cSmrg    # clever and replace this with sed code, as IRIX sed won't handle
2159bd41f2cSmrg    # lines with more than a fixed number of characters (4096 in
2169bd41f2cSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2170da4cdccSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
2189bd41f2cSmrg    # dependency line.
2190da4cdccSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2209bd41f2cSmrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
2210da4cdccSmrg    tr "$nl" ' ' >> "$depfile"
2220da4cdccSmrg    echo >> "$depfile"
2239bd41f2cSmrg
2249bd41f2cSmrg    # The second pass generates a dummy entry for each header file.
2250da4cdccSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2269bd41f2cSmrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2270da4cdccSmrg   >> "$depfile"
2289bd41f2cSmrg  else
2299bd41f2cSmrg    # The sourcefile does not contain any dependencies, so just
2309bd41f2cSmrg    # store a dummy comment line, to avoid errors with the Makefile
2319bd41f2cSmrg    # "include basename.Plo" scheme.
2329bd41f2cSmrg    echo "#dummy" > "$depfile"
2339bd41f2cSmrg  fi
2349bd41f2cSmrg  rm -f "$tmpdepfile"
2359bd41f2cSmrg  ;;
2369bd41f2cSmrg
2370da4cdccSmrgxlc)
2380da4cdccSmrg  # This case exists only to let depend.m4 do its work.  It works by
2390da4cdccSmrg  # looking at the text of this script.  This case will never be run,
2400da4cdccSmrg  # since it is checked for above.
2410da4cdccSmrg  exit 1
2420da4cdccSmrg  ;;
2430da4cdccSmrg
2449bd41f2cSmrgaix)
2459bd41f2cSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
2469bd41f2cSmrg  # in a .u file.  In older versions, this file always lives in the
2470da4cdccSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
2489bd41f2cSmrg  # start of each line; $object doesn't have directory information.
2499bd41f2cSmrg  # Version 6 uses the directory in both cases.
2509418810dSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
2519418810dSmrg  test "x$dir" = "x$object" && dir=
2529418810dSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
2539bd41f2cSmrg  if test "$libtool" = yes; then
2549418810dSmrg    tmpdepfile1=$dir$base.u
2559418810dSmrg    tmpdepfile2=$base.u
2569418810dSmrg    tmpdepfile3=$dir.libs/$base.u
2579bd41f2cSmrg    "$@" -Wc,-M
2589bd41f2cSmrg  else
2599418810dSmrg    tmpdepfile1=$dir$base.u
2609418810dSmrg    tmpdepfile2=$dir$base.u
2619418810dSmrg    tmpdepfile3=$dir$base.u
2629bd41f2cSmrg    "$@" -M
2639bd41f2cSmrg  fi
2649bd41f2cSmrg  stat=$?
2659bd41f2cSmrg
2669bd41f2cSmrg  if test $stat -eq 0; then :
2679bd41f2cSmrg  else
2689418810dSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
2699bd41f2cSmrg    exit $stat
2709bd41f2cSmrg  fi
2719bd41f2cSmrg
2729418810dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
2739418810dSmrg  do
2749418810dSmrg    test -f "$tmpdepfile" && break
2759418810dSmrg  done
2769bd41f2cSmrg  if test -f "$tmpdepfile"; then
2770da4cdccSmrg    # Each line is of the form 'foo.o: dependent.h'.
2789bd41f2cSmrg    # Do two passes, one to just change these to
2790da4cdccSmrg    # '$object: dependent.h' and one to simply 'dependent.h:'.
2809418810dSmrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
2810da4cdccSmrg    sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
2829bd41f2cSmrg  else
2839bd41f2cSmrg    # The sourcefile does not contain any dependencies, so just
2849bd41f2cSmrg    # store a dummy comment line, to avoid errors with the Makefile
2859bd41f2cSmrg    # "include basename.Plo" scheme.
2869bd41f2cSmrg    echo "#dummy" > "$depfile"
2879bd41f2cSmrg  fi
2889bd41f2cSmrg  rm -f "$tmpdepfile"
2899bd41f2cSmrg  ;;
2909bd41f2cSmrg
2919bd41f2cSmrgicc)
2920da4cdccSmrg  # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.
2930da4cdccSmrg  # However on
2940da4cdccSmrg  #    $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c
2959bd41f2cSmrg  # ICC 7.0 will fill foo.d with something like
2969bd41f2cSmrg  #    foo.o: sub/foo.c
2979bd41f2cSmrg  #    foo.o: sub/foo.h
2980da4cdccSmrg  # which is wrong.  We want
2999bd41f2cSmrg  #    sub/foo.o: sub/foo.c
3009bd41f2cSmrg  #    sub/foo.o: sub/foo.h
3019bd41f2cSmrg  #    sub/foo.c:
3029bd41f2cSmrg  #    sub/foo.h:
3039bd41f2cSmrg  # ICC 7.1 will output
3049bd41f2cSmrg  #    foo.o: sub/foo.c sub/foo.h
3050da4cdccSmrg  # and will wrap long lines using '\':
3069bd41f2cSmrg  #    foo.o: sub/foo.c ... \
3079bd41f2cSmrg  #     sub/foo.h ... \
3089bd41f2cSmrg  #     ...
3090da4cdccSmrg  # tcc 0.9.26 (FIXME still under development at the moment of writing)
3100da4cdccSmrg  # will emit a similar output, but also prepend the continuation lines
3110da4cdccSmrg  # with horizontal tabulation characters.
3129bd41f2cSmrg  "$@" -MD -MF "$tmpdepfile"
3139bd41f2cSmrg  stat=$?
3149bd41f2cSmrg  if test $stat -eq 0; then :
3159bd41f2cSmrg  else
3169bd41f2cSmrg    rm -f "$tmpdepfile"
3179bd41f2cSmrg    exit $stat
3189bd41f2cSmrg  fi
3199bd41f2cSmrg  rm -f "$depfile"
3200da4cdccSmrg  # Each line is of the form 'foo.o: dependent.h',
3210da4cdccSmrg  # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.
3229bd41f2cSmrg  # Do two passes, one to just change these to
3230da4cdccSmrg  # '$object: dependent.h' and one to simply 'dependent.h:'.
3240da4cdccSmrg  sed -e "s/^[ $tab][ $tab]*/  /" -e "s,^[^:]*:,$object :," \
3250da4cdccSmrg    < "$tmpdepfile" > "$depfile"
3260da4cdccSmrg  sed '
3270da4cdccSmrg    s/[ '"$tab"'][ '"$tab"']*/ /g
3280da4cdccSmrg    s/^ *//
3290da4cdccSmrg    s/ *\\*$//
3300da4cdccSmrg    s/^[^:]*: *//
3310da4cdccSmrg    /^$/d
3320da4cdccSmrg    /:$/d
3330da4cdccSmrg    s/$/ :/
3340da4cdccSmrg  ' < "$tmpdepfile" >> "$depfile"
3359bd41f2cSmrg  rm -f "$tmpdepfile"
3369bd41f2cSmrg  ;;
3379bd41f2cSmrg
3389418810dSmrghp2)
3399418810dSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
3409418810dSmrg  # compilers, which have integrated preprocessors.  The correct option
3419418810dSmrg  # to use with these is +Maked; it writes dependencies to a file named
3429418810dSmrg  # 'foo.d', which lands next to the object file, wherever that
3439418810dSmrg  # happens to be.
3449418810dSmrg  # Much of this is similar to the tru64 case; see comments there.
3459418810dSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
3469418810dSmrg  test "x$dir" = "x$object" && dir=
3479418810dSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
3489418810dSmrg  if test "$libtool" = yes; then
3499418810dSmrg    tmpdepfile1=$dir$base.d
3509418810dSmrg    tmpdepfile2=$dir.libs/$base.d
3519418810dSmrg    "$@" -Wc,+Maked
3529418810dSmrg  else
3539418810dSmrg    tmpdepfile1=$dir$base.d
3549418810dSmrg    tmpdepfile2=$dir$base.d
3559418810dSmrg    "$@" +Maked
3569418810dSmrg  fi
3579418810dSmrg  stat=$?
3589418810dSmrg  if test $stat -eq 0; then :
3599418810dSmrg  else
3609418810dSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
3619418810dSmrg     exit $stat
3629418810dSmrg  fi
3639418810dSmrg
3649418810dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
3659418810dSmrg  do
3669418810dSmrg    test -f "$tmpdepfile" && break
3679418810dSmrg  done
3689418810dSmrg  if test -f "$tmpdepfile"; then
3699418810dSmrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
3700da4cdccSmrg    # Add 'dependent.h:' lines.
3710da4cdccSmrg    sed -ne '2,${
3720da4cdccSmrg	       s/^ *//
3730da4cdccSmrg	       s/ \\*$//
3740da4cdccSmrg	       s/$/:/
3750da4cdccSmrg	       p
3760da4cdccSmrg	     }' "$tmpdepfile" >> "$depfile"
3779418810dSmrg  else
3789418810dSmrg    echo "#dummy" > "$depfile"
3799418810dSmrg  fi
3809418810dSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
3819418810dSmrg  ;;
3829418810dSmrg
3839bd41f2cSmrgtru64)
3849bd41f2cSmrg   # The Tru64 compiler uses -MD to generate dependencies as a side
3850da4cdccSmrg   # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
3869bd41f2cSmrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
3870da4cdccSmrg   # dependencies in 'foo.d' instead, so we check for that too.
3889bd41f2cSmrg   # Subdirectories are respected.
3899bd41f2cSmrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
3909bd41f2cSmrg   test "x$dir" = "x$object" && dir=
3919bd41f2cSmrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
3929bd41f2cSmrg
3939bd41f2cSmrg   if test "$libtool" = yes; then
3949bd41f2cSmrg      # With Tru64 cc, shared objects can also be used to make a
3959418810dSmrg      # static library.  This mechanism is used in libtool 1.4 series to
3969bd41f2cSmrg      # handle both shared and static libraries in a single compilation.
3979bd41f2cSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
3989bd41f2cSmrg      #
3999bd41f2cSmrg      # With libtool 1.5 this exception was removed, and libtool now
4009bd41f2cSmrg      # generates 2 separate objects for the 2 libraries.  These two
4019418810dSmrg      # compilations output dependencies in $dir.libs/$base.o.d and
4029bd41f2cSmrg      # in $dir$base.o.d.  We have to check for both files, because
4039bd41f2cSmrg      # one of the two compilations can be disabled.  We should prefer
4049bd41f2cSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4059bd41f2cSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
4069bd41f2cSmrg      # the former would cause a distcleancheck panic.
4079bd41f2cSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
4089bd41f2cSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
4099bd41f2cSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
4109bd41f2cSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
4119bd41f2cSmrg      "$@" -Wc,-MD
4129bd41f2cSmrg   else
4139bd41f2cSmrg      tmpdepfile1=$dir$base.o.d
4149bd41f2cSmrg      tmpdepfile2=$dir$base.d
4159bd41f2cSmrg      tmpdepfile3=$dir$base.d
4169bd41f2cSmrg      tmpdepfile4=$dir$base.d
4179bd41f2cSmrg      "$@" -MD
4189bd41f2cSmrg   fi
4199bd41f2cSmrg
4209bd41f2cSmrg   stat=$?
4219bd41f2cSmrg   if test $stat -eq 0; then :
4229bd41f2cSmrg   else
4239bd41f2cSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
4249bd41f2cSmrg      exit $stat
4259bd41f2cSmrg   fi
4269bd41f2cSmrg
4279bd41f2cSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
4289bd41f2cSmrg   do
4299bd41f2cSmrg     test -f "$tmpdepfile" && break
4309bd41f2cSmrg   done
4319bd41f2cSmrg   if test -f "$tmpdepfile"; then
4329bd41f2cSmrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
4330da4cdccSmrg      sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
4349bd41f2cSmrg   else
4359bd41f2cSmrg      echo "#dummy" > "$depfile"
4369bd41f2cSmrg   fi
4379bd41f2cSmrg   rm -f "$tmpdepfile"
4389bd41f2cSmrg   ;;
4399bd41f2cSmrg
4400da4cdccSmrgmsvc7)
4410da4cdccSmrg  if test "$libtool" = yes; then
4420da4cdccSmrg    showIncludes=-Wc,-showIncludes
4430da4cdccSmrg  else
4440da4cdccSmrg    showIncludes=-showIncludes
4450da4cdccSmrg  fi
4460da4cdccSmrg  "$@" $showIncludes > "$tmpdepfile"
4470da4cdccSmrg  stat=$?
4480da4cdccSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
4490da4cdccSmrg  if test "$stat" = 0; then :
4500da4cdccSmrg  else
4510da4cdccSmrg    rm -f "$tmpdepfile"
4520da4cdccSmrg    exit $stat
4530da4cdccSmrg  fi
4540da4cdccSmrg  rm -f "$depfile"
4550da4cdccSmrg  echo "$object : \\" > "$depfile"
4560da4cdccSmrg  # The first sed program below extracts the file names and escapes
4570da4cdccSmrg  # backslashes for cygpath.  The second sed program outputs the file
4580da4cdccSmrg  # name when reading, but also accumulates all include files in the
4590da4cdccSmrg  # hold buffer in order to output them again at the end.  This only
4600da4cdccSmrg  # works with sed implementations that can handle large buffers.
4610da4cdccSmrg  sed < "$tmpdepfile" -n '
4620da4cdccSmrg/^Note: including file:  *\(.*\)/ {
4630da4cdccSmrg  s//\1/
4640da4cdccSmrg  s/\\/\\\\/g
4650da4cdccSmrg  p
4660da4cdccSmrg}' | $cygpath_u | sort -u | sed -n '
4670da4cdccSmrgs/ /\\ /g
4680da4cdccSmrgs/\(.*\)/'"$tab"'\1 \\/p
4690da4cdccSmrgs/.\(.*\) \\/\1:/
4700da4cdccSmrgH
4710da4cdccSmrg$ {
4720da4cdccSmrg  s/.*/'"$tab"'/
4730da4cdccSmrg  G
4740da4cdccSmrg  p
4750da4cdccSmrg}' >> "$depfile"
4760da4cdccSmrg  rm -f "$tmpdepfile"
4770da4cdccSmrg  ;;
4780da4cdccSmrg
4790da4cdccSmrgmsvc7msys)
4800da4cdccSmrg  # This case exists only to let depend.m4 do its work.  It works by
4810da4cdccSmrg  # looking at the text of this script.  This case will never be run,
4820da4cdccSmrg  # since it is checked for above.
4830da4cdccSmrg  exit 1
4840da4cdccSmrg  ;;
4850da4cdccSmrg
4869bd41f2cSmrg#nosideeffect)
4879bd41f2cSmrg  # This comment above is used by automake to tell side-effect
4889bd41f2cSmrg  # dependency tracking mechanisms from slower ones.
4899bd41f2cSmrg
4909bd41f2cSmrgdashmstdout)
4919bd41f2cSmrg  # Important note: in order to support this mode, a compiler *must*
4929bd41f2cSmrg  # always write the preprocessed file to stdout, regardless of -o.
4939bd41f2cSmrg  "$@" || exit $?
4949bd41f2cSmrg
4959bd41f2cSmrg  # Remove the call to Libtool.
4969bd41f2cSmrg  if test "$libtool" = yes; then
4970da4cdccSmrg    while test "X$1" != 'X--mode=compile'; do
4989bd41f2cSmrg      shift
4999bd41f2cSmrg    done
5009bd41f2cSmrg    shift
5019bd41f2cSmrg  fi
5029bd41f2cSmrg
5030da4cdccSmrg  # Remove '-o $object'.
5049bd41f2cSmrg  IFS=" "
5059bd41f2cSmrg  for arg
5069bd41f2cSmrg  do
5079bd41f2cSmrg    case $arg in
5089bd41f2cSmrg    -o)
5099bd41f2cSmrg      shift
5109bd41f2cSmrg      ;;
5119bd41f2cSmrg    $object)
5129bd41f2cSmrg      shift
5139bd41f2cSmrg      ;;
5149bd41f2cSmrg    *)
5159bd41f2cSmrg      set fnord "$@" "$arg"
5169bd41f2cSmrg      shift # fnord
5179bd41f2cSmrg      shift # $arg
5189bd41f2cSmrg      ;;
5199bd41f2cSmrg    esac
5209bd41f2cSmrg  done
5219bd41f2cSmrg
5229bd41f2cSmrg  test -z "$dashmflag" && dashmflag=-M
5230da4cdccSmrg  # Require at least two characters before searching for ':'
5249bd41f2cSmrg  # in the target name.  This is to cope with DOS-style filenames:
5250da4cdccSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
5269bd41f2cSmrg  "$@" $dashmflag |
5270da4cdccSmrg    sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"
5289bd41f2cSmrg  rm -f "$depfile"
5299bd41f2cSmrg  cat < "$tmpdepfile" > "$depfile"
5300da4cdccSmrg  tr ' ' "$nl" < "$tmpdepfile" | \
5319bd41f2cSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
5329bd41f2cSmrg## correctly.  Breaking it into two sed invocations is a workaround.
5339bd41f2cSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
5349bd41f2cSmrg  rm -f "$tmpdepfile"
5359bd41f2cSmrg  ;;
5369bd41f2cSmrg
5379bd41f2cSmrgdashXmstdout)
5389bd41f2cSmrg  # This case only exists to satisfy depend.m4.  It is never actually
5399bd41f2cSmrg  # run, as this mode is specially recognized in the preamble.
5409bd41f2cSmrg  exit 1
5419bd41f2cSmrg  ;;
5429bd41f2cSmrg
5439bd41f2cSmrgmakedepend)
5449bd41f2cSmrg  "$@" || exit $?
5459bd41f2cSmrg  # Remove any Libtool call
5469bd41f2cSmrg  if test "$libtool" = yes; then
5470da4cdccSmrg    while test "X$1" != 'X--mode=compile'; do
5489bd41f2cSmrg      shift
5499bd41f2cSmrg    done
5509bd41f2cSmrg    shift
5519bd41f2cSmrg  fi
5529bd41f2cSmrg  # X makedepend
5539bd41f2cSmrg  shift
5540da4cdccSmrg  cleared=no eat=no
5550da4cdccSmrg  for arg
5560da4cdccSmrg  do
5579bd41f2cSmrg    case $cleared in
5589bd41f2cSmrg    no)
5599bd41f2cSmrg      set ""; shift
5609bd41f2cSmrg      cleared=yes ;;
5619bd41f2cSmrg    esac
5620da4cdccSmrg    if test $eat = yes; then
5630da4cdccSmrg      eat=no
5640da4cdccSmrg      continue
5650da4cdccSmrg    fi
5669bd41f2cSmrg    case "$arg" in
5679bd41f2cSmrg    -D*|-I*)
5689bd41f2cSmrg      set fnord "$@" "$arg"; shift ;;
5699bd41f2cSmrg    # Strip any option that makedepend may not understand.  Remove
5709bd41f2cSmrg    # the object too, otherwise makedepend will parse it as a source file.
5710da4cdccSmrg    -arch)
5720da4cdccSmrg      eat=yes ;;
5739bd41f2cSmrg    -*|$object)
5749bd41f2cSmrg      ;;
5759bd41f2cSmrg    *)
5769bd41f2cSmrg      set fnord "$@" "$arg"; shift ;;
5779bd41f2cSmrg    esac
5789bd41f2cSmrg  done
5790da4cdccSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
5809bd41f2cSmrg  touch "$tmpdepfile"
5819bd41f2cSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
5829bd41f2cSmrg  rm -f "$depfile"
5830da4cdccSmrg  # makedepend may prepend the VPATH from the source file name to the object.
5840da4cdccSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
5850da4cdccSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
5860da4cdccSmrg  sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \
5879bd41f2cSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
5889bd41f2cSmrg## correctly.  Breaking it into two sed invocations is a workaround.
5899bd41f2cSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
5909bd41f2cSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
5919bd41f2cSmrg  ;;
5929bd41f2cSmrg
5939bd41f2cSmrgcpp)
5949bd41f2cSmrg  # Important note: in order to support this mode, a compiler *must*
5959bd41f2cSmrg  # always write the preprocessed file to stdout.
5969bd41f2cSmrg  "$@" || exit $?
5979bd41f2cSmrg
5989bd41f2cSmrg  # Remove the call to Libtool.
5999bd41f2cSmrg  if test "$libtool" = yes; then
6000da4cdccSmrg    while test "X$1" != 'X--mode=compile'; do
6019bd41f2cSmrg      shift
6029bd41f2cSmrg    done
6039bd41f2cSmrg    shift
6049bd41f2cSmrg  fi
6059bd41f2cSmrg
6060da4cdccSmrg  # Remove '-o $object'.
6079bd41f2cSmrg  IFS=" "
6089bd41f2cSmrg  for arg
6099bd41f2cSmrg  do
6109bd41f2cSmrg    case $arg in
6119bd41f2cSmrg    -o)
6129bd41f2cSmrg      shift
6139bd41f2cSmrg      ;;
6149bd41f2cSmrg    $object)
6159bd41f2cSmrg      shift
6169bd41f2cSmrg      ;;
6179bd41f2cSmrg    *)
6189bd41f2cSmrg      set fnord "$@" "$arg"
6199bd41f2cSmrg      shift # fnord
6209bd41f2cSmrg      shift # $arg
6219bd41f2cSmrg      ;;
6229bd41f2cSmrg    esac
6239bd41f2cSmrg  done
6249bd41f2cSmrg
6259bd41f2cSmrg  "$@" -E |
6269bd41f2cSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
6279bd41f2cSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
6289bd41f2cSmrg    sed '$ s: \\$::' > "$tmpdepfile"
6299bd41f2cSmrg  rm -f "$depfile"
6309bd41f2cSmrg  echo "$object : \\" > "$depfile"
6319bd41f2cSmrg  cat < "$tmpdepfile" >> "$depfile"
6329bd41f2cSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
6339bd41f2cSmrg  rm -f "$tmpdepfile"
6349bd41f2cSmrg  ;;
6359bd41f2cSmrg
6369bd41f2cSmrgmsvisualcpp)
6379bd41f2cSmrg  # Important note: in order to support this mode, a compiler *must*
6380da4cdccSmrg  # always write the preprocessed file to stdout.
6399bd41f2cSmrg  "$@" || exit $?
6400da4cdccSmrg
6410da4cdccSmrg  # Remove the call to Libtool.
6420da4cdccSmrg  if test "$libtool" = yes; then
6430da4cdccSmrg    while test "X$1" != 'X--mode=compile'; do
6440da4cdccSmrg      shift
6450da4cdccSmrg    done
6460da4cdccSmrg    shift
6470da4cdccSmrg  fi
6480da4cdccSmrg
6499bd41f2cSmrg  IFS=" "
6509bd41f2cSmrg  for arg
6519bd41f2cSmrg  do
6529bd41f2cSmrg    case "$arg" in
6530da4cdccSmrg    -o)
6540da4cdccSmrg      shift
6550da4cdccSmrg      ;;
6560da4cdccSmrg    $object)
6570da4cdccSmrg      shift
6580da4cdccSmrg      ;;
6599bd41f2cSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
6609bd41f2cSmrg	set fnord "$@"
6619bd41f2cSmrg	shift
6629bd41f2cSmrg	shift
6639bd41f2cSmrg	;;
6649bd41f2cSmrg    *)
6659bd41f2cSmrg	set fnord "$@" "$arg"
6669bd41f2cSmrg	shift
6679bd41f2cSmrg	shift
6689bd41f2cSmrg	;;
6699bd41f2cSmrg    esac
6709bd41f2cSmrg  done
6710da4cdccSmrg  "$@" -E 2>/dev/null |
6720da4cdccSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
6739bd41f2cSmrg  rm -f "$depfile"
6749bd41f2cSmrg  echo "$object : \\" > "$depfile"
6750da4cdccSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
6760da4cdccSmrg  echo "$tab" >> "$depfile"
6770da4cdccSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
6789bd41f2cSmrg  rm -f "$tmpdepfile"
6799bd41f2cSmrg  ;;
6809bd41f2cSmrg
6810da4cdccSmrgmsvcmsys)
6820da4cdccSmrg  # This case exists only to let depend.m4 do its work.  It works by
6830da4cdccSmrg  # looking at the text of this script.  This case will never be run,
6840da4cdccSmrg  # since it is checked for above.
6850da4cdccSmrg  exit 1
6860da4cdccSmrg  ;;
6870da4cdccSmrg
6889bd41f2cSmrgnone)
6899bd41f2cSmrg  exec "$@"
6909bd41f2cSmrg  ;;
6919bd41f2cSmrg
6929bd41f2cSmrg*)
6939bd41f2cSmrg  echo "Unknown depmode $depmode" 1>&2
6949bd41f2cSmrg  exit 1
6959bd41f2cSmrg  ;;
6969bd41f2cSmrgesac
6979bd41f2cSmrg
6989bd41f2cSmrgexit 0
6999bd41f2cSmrg
7009bd41f2cSmrg# Local Variables:
7019bd41f2cSmrg# mode: shell-script
7029bd41f2cSmrg# sh-indentation: 2
7039bd41f2cSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
7049bd41f2cSmrg# time-stamp-start: "scriptversion="
7059bd41f2cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7060da4cdccSmrg# time-stamp-time-zone: "UTC"
7070da4cdccSmrg# time-stamp-end: "; # UTC"
7089bd41f2cSmrg# End:
709