191a17321Smrg#! /bin/sh
291a17321Smrg# depcomp - compile a program generating dependencies as side-effects
391a17321Smrg
491a17321Smrgscriptversion=2005-07-09.11
591a17321Smrg
691a17321Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
791a17321Smrg
891a17321Smrg# This program is free software; you can redistribute it and/or modify
991a17321Smrg# it under the terms of the GNU General Public License as published by
1091a17321Smrg# the Free Software Foundation; either version 2, or (at your option)
1191a17321Smrg# any later version.
1291a17321Smrg
1391a17321Smrg# This program is distributed in the hope that it will be useful,
1491a17321Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1591a17321Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1691a17321Smrg# GNU General Public License for more details.
1791a17321Smrg
1891a17321Smrg# You should have received a copy of the GNU General Public License
1991a17321Smrg# along with this program; if not, write to the Free Software
2091a17321Smrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
2191a17321Smrg# 02110-1301, USA.
2291a17321Smrg
2391a17321Smrg# As a special exception to the GNU General Public License, if you
2491a17321Smrg# distribute this file as part of a program that contains a
2591a17321Smrg# configuration script generated by Autoconf, you may include it under
2691a17321Smrg# the same distribution terms that you use for the rest of that program.
2791a17321Smrg
2891a17321Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2991a17321Smrg
3091a17321Smrgcase $1 in
3191a17321Smrg  '')
3291a17321Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
3391a17321Smrg     exit 1;
3491a17321Smrg     ;;
3591a17321Smrg  -h | --h*)
3691a17321Smrg    cat <<\EOF
3791a17321SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3891a17321Smrg
3991a17321SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
4091a17321Smrgas side-effects.
4191a17321Smrg
4291a17321SmrgEnvironment variables:
4391a17321Smrg  depmode     Dependency tracking mode.
4491a17321Smrg  source      Source file read by `PROGRAMS ARGS'.
4591a17321Smrg  object      Object file output by `PROGRAMS ARGS'.
4691a17321Smrg  DEPDIR      directory where to store dependencies.
4791a17321Smrg  depfile     Dependency file to output.
4891a17321Smrg  tmpdepfile  Temporary file to use when outputing dependencies.
4991a17321Smrg  libtool     Whether libtool is used (yes/no).
5091a17321Smrg
5191a17321SmrgReport bugs to <bug-automake@gnu.org>.
5291a17321SmrgEOF
5391a17321Smrg    exit $?
5491a17321Smrg    ;;
5591a17321Smrg  -v | --v*)
5691a17321Smrg    echo "depcomp $scriptversion"
5791a17321Smrg    exit $?
5891a17321Smrg    ;;
5991a17321Smrgesac
6091a17321Smrg
6191a17321Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
6291a17321Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
6391a17321Smrg  exit 1
6491a17321Smrgfi
6591a17321Smrg
6691a17321Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
6791a17321Smrgdepfile=${depfile-`echo "$object" |
6891a17321Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
6991a17321Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
7091a17321Smrg
7191a17321Smrgrm -f "$tmpdepfile"
7291a17321Smrg
7391a17321Smrg# Some modes work just like other modes, but use different flags.  We
7491a17321Smrg# parameterize here, but still list the modes in the big case below,
7591a17321Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
7691a17321Smrg# here, because this file can only contain one case statement.
7791a17321Smrgif test "$depmode" = hp; then
7891a17321Smrg  # HP compiler uses -M and no extra arg.
7991a17321Smrg  gccflag=-M
8091a17321Smrg  depmode=gcc
8191a17321Smrgfi
8291a17321Smrg
8391a17321Smrgif test "$depmode" = dashXmstdout; then
8491a17321Smrg   # This is just like dashmstdout with a different argument.
8591a17321Smrg   dashmflag=-xM
8691a17321Smrg   depmode=dashmstdout
8791a17321Smrgfi
8891a17321Smrg
8991a17321Smrgcase "$depmode" in
9091a17321Smrggcc3)
9191a17321Smrg## gcc 3 implements dependency tracking that does exactly what
9291a17321Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
9391a17321Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
9491a17321Smrg  "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
9591a17321Smrg  stat=$?
9691a17321Smrg  if test $stat -eq 0; then :
9791a17321Smrg  else
9891a17321Smrg    rm -f "$tmpdepfile"
9991a17321Smrg    exit $stat
10091a17321Smrg  fi
10191a17321Smrg  mv "$tmpdepfile" "$depfile"
10291a17321Smrg  ;;
10391a17321Smrg
10491a17321Smrggcc)
10591a17321Smrg## There are various ways to get dependency output from gcc.  Here's
10691a17321Smrg## why we pick this rather obscure method:
10791a17321Smrg## - Don't want to use -MD because we'd like the dependencies to end
10891a17321Smrg##   up in a subdir.  Having to rename by hand is ugly.
10991a17321Smrg##   (We might end up doing this anyway to support other compilers.)
11091a17321Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
11191a17321Smrg##   -MM, not -M (despite what the docs say).
11291a17321Smrg## - Using -M directly means running the compiler twice (even worse
11391a17321Smrg##   than renaming).
11491a17321Smrg  if test -z "$gccflag"; then
11591a17321Smrg    gccflag=-MD,
11691a17321Smrg  fi
11791a17321Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
11891a17321Smrg  stat=$?
11991a17321Smrg  if test $stat -eq 0; then :
12091a17321Smrg  else
12191a17321Smrg    rm -f "$tmpdepfile"
12291a17321Smrg    exit $stat
12391a17321Smrg  fi
12491a17321Smrg  rm -f "$depfile"
12591a17321Smrg  echo "$object : \\" > "$depfile"
12691a17321Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
12791a17321Smrg## The second -e expression handles DOS-style file names with drive letters.
12891a17321Smrg  sed -e 's/^[^:]*: / /' \
12991a17321Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
13091a17321Smrg## This next piece of magic avoids the `deleted header file' problem.
13191a17321Smrg## The problem is that when a header file which appears in a .P file
13291a17321Smrg## is deleted, the dependency causes make to die (because there is
13391a17321Smrg## typically no way to rebuild the header).  We avoid this by adding
13491a17321Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
13591a17321Smrg## this for us directly.
13691a17321Smrg  tr ' ' '
13791a17321Smrg' < "$tmpdepfile" |
13891a17321Smrg## Some versions of gcc put a space before the `:'.  On the theory
13991a17321Smrg## that the space means something, we add a space to the output as
14091a17321Smrg## well.
14191a17321Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
14291a17321Smrg## correctly.  Breaking it into two sed invocations is a workaround.
14391a17321Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
14491a17321Smrg  rm -f "$tmpdepfile"
14591a17321Smrg  ;;
14691a17321Smrg
14791a17321Smrghp)
14891a17321Smrg  # This case exists only to let depend.m4 do its work.  It works by
14991a17321Smrg  # looking at the text of this script.  This case will never be run,
15091a17321Smrg  # since it is checked for above.
15191a17321Smrg  exit 1
15291a17321Smrg  ;;
15391a17321Smrg
15491a17321Smrgsgi)
15591a17321Smrg  if test "$libtool" = yes; then
15691a17321Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
15791a17321Smrg  else
15891a17321Smrg    "$@" -MDupdate "$tmpdepfile"
15991a17321Smrg  fi
16091a17321Smrg  stat=$?
16191a17321Smrg  if test $stat -eq 0; then :
16291a17321Smrg  else
16391a17321Smrg    rm -f "$tmpdepfile"
16491a17321Smrg    exit $stat
16591a17321Smrg  fi
16691a17321Smrg  rm -f "$depfile"
16791a17321Smrg
16891a17321Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
16991a17321Smrg    echo "$object : \\" > "$depfile"
17091a17321Smrg
17191a17321Smrg    # Clip off the initial element (the dependent).  Don't try to be
17291a17321Smrg    # clever and replace this with sed code, as IRIX sed won't handle
17391a17321Smrg    # lines with more than a fixed number of characters (4096 in
17491a17321Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
17591a17321Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
17691a17321Smrg    # dependency line.
17791a17321Smrg    tr ' ' '
17891a17321Smrg' < "$tmpdepfile" \
17991a17321Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
18091a17321Smrg    tr '
18191a17321Smrg' ' ' >> $depfile
18291a17321Smrg    echo >> $depfile
18391a17321Smrg
18491a17321Smrg    # The second pass generates a dummy entry for each header file.
18591a17321Smrg    tr ' ' '
18691a17321Smrg' < "$tmpdepfile" \
18791a17321Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
18891a17321Smrg   >> $depfile
18991a17321Smrg  else
19091a17321Smrg    # The sourcefile does not contain any dependencies, so just
19191a17321Smrg    # store a dummy comment line, to avoid errors with the Makefile
19291a17321Smrg    # "include basename.Plo" scheme.
19391a17321Smrg    echo "#dummy" > "$depfile"
19491a17321Smrg  fi
19591a17321Smrg  rm -f "$tmpdepfile"
19691a17321Smrg  ;;
19791a17321Smrg
19891a17321Smrgaix)
19991a17321Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
20091a17321Smrg  # in a .u file.  In older versions, this file always lives in the
20191a17321Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
20291a17321Smrg  # start of each line; $object doesn't have directory information.
20391a17321Smrg  # Version 6 uses the directory in both cases.
20491a17321Smrg  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
20591a17321Smrg  tmpdepfile="$stripped.u"
20691a17321Smrg  if test "$libtool" = yes; then
20791a17321Smrg    "$@" -Wc,-M
20891a17321Smrg  else
20991a17321Smrg    "$@" -M
21091a17321Smrg  fi
21191a17321Smrg  stat=$?
21291a17321Smrg
21391a17321Smrg  if test -f "$tmpdepfile"; then :
21491a17321Smrg  else
21591a17321Smrg    stripped=`echo "$stripped" | sed 's,^.*/,,'`
21691a17321Smrg    tmpdepfile="$stripped.u"
21791a17321Smrg  fi
21891a17321Smrg
21991a17321Smrg  if test $stat -eq 0; then :
22091a17321Smrg  else
22191a17321Smrg    rm -f "$tmpdepfile"
22291a17321Smrg    exit $stat
22391a17321Smrg  fi
22491a17321Smrg
22591a17321Smrg  if test -f "$tmpdepfile"; then
22691a17321Smrg    outname="$stripped.o"
22791a17321Smrg    # Each line is of the form `foo.o: dependent.h'.
22891a17321Smrg    # Do two passes, one to just change these to
22991a17321Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
23091a17321Smrg    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
23191a17321Smrg    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
23291a17321Smrg  else
23391a17321Smrg    # The sourcefile does not contain any dependencies, so just
23491a17321Smrg    # store a dummy comment line, to avoid errors with the Makefile
23591a17321Smrg    # "include basename.Plo" scheme.
23691a17321Smrg    echo "#dummy" > "$depfile"
23791a17321Smrg  fi
23891a17321Smrg  rm -f "$tmpdepfile"
23991a17321Smrg  ;;
24091a17321Smrg
24191a17321Smrgicc)
24291a17321Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
24391a17321Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
24491a17321Smrg  # ICC 7.0 will fill foo.d with something like
24591a17321Smrg  #    foo.o: sub/foo.c
24691a17321Smrg  #    foo.o: sub/foo.h
24791a17321Smrg  # which is wrong.  We want:
24891a17321Smrg  #    sub/foo.o: sub/foo.c
24991a17321Smrg  #    sub/foo.o: sub/foo.h
25091a17321Smrg  #    sub/foo.c:
25191a17321Smrg  #    sub/foo.h:
25291a17321Smrg  # ICC 7.1 will output
25391a17321Smrg  #    foo.o: sub/foo.c sub/foo.h
25491a17321Smrg  # and will wrap long lines using \ :
25591a17321Smrg  #    foo.o: sub/foo.c ... \
25691a17321Smrg  #     sub/foo.h ... \
25791a17321Smrg  #     ...
25891a17321Smrg
25991a17321Smrg  "$@" -MD -MF "$tmpdepfile"
26091a17321Smrg  stat=$?
26191a17321Smrg  if test $stat -eq 0; then :
26291a17321Smrg  else
26391a17321Smrg    rm -f "$tmpdepfile"
26491a17321Smrg    exit $stat
26591a17321Smrg  fi
26691a17321Smrg  rm -f "$depfile"
26791a17321Smrg  # Each line is of the form `foo.o: dependent.h',
26891a17321Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
26991a17321Smrg  # Do two passes, one to just change these to
27091a17321Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
27191a17321Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
27291a17321Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
27391a17321Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
27491a17321Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
27591a17321Smrg    sed -e 's/$/ :/' >> "$depfile"
27691a17321Smrg  rm -f "$tmpdepfile"
27791a17321Smrg  ;;
27891a17321Smrg
27991a17321Smrgtru64)
28091a17321Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
28191a17321Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
28291a17321Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
28391a17321Smrg   # dependencies in `foo.d' instead, so we check for that too.
28491a17321Smrg   # Subdirectories are respected.
28591a17321Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
28691a17321Smrg   test "x$dir" = "x$object" && dir=
28791a17321Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
28891a17321Smrg
28991a17321Smrg   if test "$libtool" = yes; then
29091a17321Smrg      # With Tru64 cc, shared objects can also be used to make a
29191a17321Smrg      # static library.  This mecanism is used in libtool 1.4 series to
29291a17321Smrg      # handle both shared and static libraries in a single compilation.
29391a17321Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
29491a17321Smrg      #
29591a17321Smrg      # With libtool 1.5 this exception was removed, and libtool now
29691a17321Smrg      # generates 2 separate objects for the 2 libraries.  These two
29791a17321Smrg      # compilations output dependencies in in $dir.libs/$base.o.d and
29891a17321Smrg      # in $dir$base.o.d.  We have to check for both files, because
29991a17321Smrg      # one of the two compilations can be disabled.  We should prefer
30091a17321Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
30191a17321Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
30291a17321Smrg      # the former would cause a distcleancheck panic.
30391a17321Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
30491a17321Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
30591a17321Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
30691a17321Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
30791a17321Smrg      "$@" -Wc,-MD
30891a17321Smrg   else
30991a17321Smrg      tmpdepfile1=$dir$base.o.d
31091a17321Smrg      tmpdepfile2=$dir$base.d
31191a17321Smrg      tmpdepfile3=$dir$base.d
31291a17321Smrg      tmpdepfile4=$dir$base.d
31391a17321Smrg      "$@" -MD
31491a17321Smrg   fi
31591a17321Smrg
31691a17321Smrg   stat=$?
31791a17321Smrg   if test $stat -eq 0; then :
31891a17321Smrg   else
31991a17321Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
32091a17321Smrg      exit $stat
32191a17321Smrg   fi
32291a17321Smrg
32391a17321Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
32491a17321Smrg   do
32591a17321Smrg     test -f "$tmpdepfile" && break
32691a17321Smrg   done
32791a17321Smrg   if test -f "$tmpdepfile"; then
32891a17321Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
32991a17321Smrg      # That's a tab and a space in the [].
33091a17321Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
33191a17321Smrg   else
33291a17321Smrg      echo "#dummy" > "$depfile"
33391a17321Smrg   fi
33491a17321Smrg   rm -f "$tmpdepfile"
33591a17321Smrg   ;;
33691a17321Smrg
33791a17321Smrg#nosideeffect)
33891a17321Smrg  # This comment above is used by automake to tell side-effect
33991a17321Smrg  # dependency tracking mechanisms from slower ones.
34091a17321Smrg
34191a17321Smrgdashmstdout)
34291a17321Smrg  # Important note: in order to support this mode, a compiler *must*
34391a17321Smrg  # always write the preprocessed file to stdout, regardless of -o.
34491a17321Smrg  "$@" || exit $?
34591a17321Smrg
34691a17321Smrg  # Remove the call to Libtool.
34791a17321Smrg  if test "$libtool" = yes; then
34891a17321Smrg    while test $1 != '--mode=compile'; do
34991a17321Smrg      shift
35091a17321Smrg    done
35191a17321Smrg    shift
35291a17321Smrg  fi
35391a17321Smrg
35491a17321Smrg  # Remove `-o $object'.
35591a17321Smrg  IFS=" "
35691a17321Smrg  for arg
35791a17321Smrg  do
35891a17321Smrg    case $arg in
35991a17321Smrg    -o)
36091a17321Smrg      shift
36191a17321Smrg      ;;
36291a17321Smrg    $object)
36391a17321Smrg      shift
36491a17321Smrg      ;;
36591a17321Smrg    *)
36691a17321Smrg      set fnord "$@" "$arg"
36791a17321Smrg      shift # fnord
36891a17321Smrg      shift # $arg
36991a17321Smrg      ;;
37091a17321Smrg    esac
37191a17321Smrg  done
37291a17321Smrg
37391a17321Smrg  test -z "$dashmflag" && dashmflag=-M
37491a17321Smrg  # Require at least two characters before searching for `:'
37591a17321Smrg  # in the target name.  This is to cope with DOS-style filenames:
37691a17321Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
37791a17321Smrg  "$@" $dashmflag |
37891a17321Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
37991a17321Smrg  rm -f "$depfile"
38091a17321Smrg  cat < "$tmpdepfile" > "$depfile"
38191a17321Smrg  tr ' ' '
38291a17321Smrg' < "$tmpdepfile" | \
38391a17321Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
38491a17321Smrg## correctly.  Breaking it into two sed invocations is a workaround.
38591a17321Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
38691a17321Smrg  rm -f "$tmpdepfile"
38791a17321Smrg  ;;
38891a17321Smrg
38991a17321SmrgdashXmstdout)
39091a17321Smrg  # This case only exists to satisfy depend.m4.  It is never actually
39191a17321Smrg  # run, as this mode is specially recognized in the preamble.
39291a17321Smrg  exit 1
39391a17321Smrg  ;;
39491a17321Smrg
39591a17321Smrgmakedepend)
39691a17321Smrg  "$@" || exit $?
39791a17321Smrg  # Remove any Libtool call
39891a17321Smrg  if test "$libtool" = yes; then
39991a17321Smrg    while test $1 != '--mode=compile'; do
40091a17321Smrg      shift
40191a17321Smrg    done
40291a17321Smrg    shift
40391a17321Smrg  fi
40491a17321Smrg  # X makedepend
40591a17321Smrg  shift
40691a17321Smrg  cleared=no
40791a17321Smrg  for arg in "$@"; do
40891a17321Smrg    case $cleared in
40991a17321Smrg    no)
41091a17321Smrg      set ""; shift
41191a17321Smrg      cleared=yes ;;
41291a17321Smrg    esac
41391a17321Smrg    case "$arg" in
41491a17321Smrg    -D*|-I*)
41591a17321Smrg      set fnord "$@" "$arg"; shift ;;
41691a17321Smrg    # Strip any option that makedepend may not understand.  Remove
41791a17321Smrg    # the object too, otherwise makedepend will parse it as a source file.
41891a17321Smrg    -*|$object)
41991a17321Smrg      ;;
42091a17321Smrg    *)
42191a17321Smrg      set fnord "$@" "$arg"; shift ;;
42291a17321Smrg    esac
42391a17321Smrg  done
42491a17321Smrg  obj_suffix="`echo $object | sed 's/^.*\././'`"
42591a17321Smrg  touch "$tmpdepfile"
42691a17321Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
42791a17321Smrg  rm -f "$depfile"
42891a17321Smrg  cat < "$tmpdepfile" > "$depfile"
42991a17321Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
43091a17321Smrg' | \
43191a17321Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
43291a17321Smrg## correctly.  Breaking it into two sed invocations is a workaround.
43391a17321Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
43491a17321Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
43591a17321Smrg  ;;
43691a17321Smrg
43791a17321Smrgcpp)
43891a17321Smrg  # Important note: in order to support this mode, a compiler *must*
43991a17321Smrg  # always write the preprocessed file to stdout.
44091a17321Smrg  "$@" || exit $?
44191a17321Smrg
44291a17321Smrg  # Remove the call to Libtool.
44391a17321Smrg  if test "$libtool" = yes; then
44491a17321Smrg    while test $1 != '--mode=compile'; do
44591a17321Smrg      shift
44691a17321Smrg    done
44791a17321Smrg    shift
44891a17321Smrg  fi
44991a17321Smrg
45091a17321Smrg  # Remove `-o $object'.
45191a17321Smrg  IFS=" "
45291a17321Smrg  for arg
45391a17321Smrg  do
45491a17321Smrg    case $arg in
45591a17321Smrg    -o)
45691a17321Smrg      shift
45791a17321Smrg      ;;
45891a17321Smrg    $object)
45991a17321Smrg      shift
46091a17321Smrg      ;;
46191a17321Smrg    *)
46291a17321Smrg      set fnord "$@" "$arg"
46391a17321Smrg      shift # fnord
46491a17321Smrg      shift # $arg
46591a17321Smrg      ;;
46691a17321Smrg    esac
46791a17321Smrg  done
46891a17321Smrg
46991a17321Smrg  "$@" -E |
47091a17321Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
47191a17321Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
47291a17321Smrg    sed '$ s: \\$::' > "$tmpdepfile"
47391a17321Smrg  rm -f "$depfile"
47491a17321Smrg  echo "$object : \\" > "$depfile"
47591a17321Smrg  cat < "$tmpdepfile" >> "$depfile"
47691a17321Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
47791a17321Smrg  rm -f "$tmpdepfile"
47891a17321Smrg  ;;
47991a17321Smrg
48091a17321Smrgmsvisualcpp)
48191a17321Smrg  # Important note: in order to support this mode, a compiler *must*
48291a17321Smrg  # always write the preprocessed file to stdout, regardless of -o,
48391a17321Smrg  # because we must use -o when running libtool.
48491a17321Smrg  "$@" || exit $?
48591a17321Smrg  IFS=" "
48691a17321Smrg  for arg
48791a17321Smrg  do
48891a17321Smrg    case "$arg" in
48991a17321Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
49091a17321Smrg	set fnord "$@"
49191a17321Smrg	shift
49291a17321Smrg	shift
49391a17321Smrg	;;
49491a17321Smrg    *)
49591a17321Smrg	set fnord "$@" "$arg"
49691a17321Smrg	shift
49791a17321Smrg	shift
49891a17321Smrg	;;
49991a17321Smrg    esac
50091a17321Smrg  done
50191a17321Smrg  "$@" -E |
50291a17321Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
50391a17321Smrg  rm -f "$depfile"
50491a17321Smrg  echo "$object : \\" > "$depfile"
50591a17321Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
50691a17321Smrg  echo "	" >> "$depfile"
50791a17321Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
50891a17321Smrg  rm -f "$tmpdepfile"
50991a17321Smrg  ;;
51091a17321Smrg
51191a17321Smrgnone)
51291a17321Smrg  exec "$@"
51391a17321Smrg  ;;
51491a17321Smrg
51591a17321Smrg*)
51691a17321Smrg  echo "Unknown depmode $depmode" 1>&2
51791a17321Smrg  exit 1
51891a17321Smrg  ;;
51991a17321Smrgesac
52091a17321Smrg
52191a17321Smrgexit 0
52291a17321Smrg
52391a17321Smrg# Local Variables:
52491a17321Smrg# mode: shell-script
52591a17321Smrg# sh-indentation: 2
52691a17321Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
52791a17321Smrg# time-stamp-start: "scriptversion="
52891a17321Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
52991a17321Smrg# time-stamp-end: "$"
53091a17321Smrg# End:
531