depcomp revision de78e416
115fb4814Smrg#! /bin/sh
215fb4814Smrg# depcomp - compile a program generating dependencies as side-effects
315fb4814Smrg
4de78e416Smrgscriptversion=2006-10-15.18
515fb4814Smrg
6de78e416Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
7de78e416Smrg# Foundation, Inc.
815fb4814Smrg
915fb4814Smrg# This program is free software; you can redistribute it and/or modify
1015fb4814Smrg# it under the terms of the GNU General Public License as published by
1115fb4814Smrg# the Free Software Foundation; either version 2, or (at your option)
1215fb4814Smrg# any later version.
1315fb4814Smrg
1415fb4814Smrg# This program is distributed in the hope that it will be useful,
1515fb4814Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1615fb4814Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1715fb4814Smrg# GNU General Public License for more details.
1815fb4814Smrg
1915fb4814Smrg# You should have received a copy of the GNU General Public License
2015fb4814Smrg# along with this program; if not, write to the Free Software
2115fb4814Smrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
2215fb4814Smrg# 02110-1301, USA.
2315fb4814Smrg
2415fb4814Smrg# As a special exception to the GNU General Public License, if you
2515fb4814Smrg# distribute this file as part of a program that contains a
2615fb4814Smrg# configuration script generated by Autoconf, you may include it under
2715fb4814Smrg# the same distribution terms that you use for the rest of that program.
2815fb4814Smrg
2915fb4814Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
3015fb4814Smrg
3115fb4814Smrgcase $1 in
3215fb4814Smrg  '')
3315fb4814Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
3415fb4814Smrg     exit 1;
3515fb4814Smrg     ;;
3615fb4814Smrg  -h | --h*)
3715fb4814Smrg    cat <<\EOF
3815fb4814SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3915fb4814Smrg
4015fb4814SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
4115fb4814Smrgas side-effects.
4215fb4814Smrg
4315fb4814SmrgEnvironment variables:
4415fb4814Smrg  depmode     Dependency tracking mode.
4515fb4814Smrg  source      Source file read by `PROGRAMS ARGS'.
4615fb4814Smrg  object      Object file output by `PROGRAMS ARGS'.
4715fb4814Smrg  DEPDIR      directory where to store dependencies.
4815fb4814Smrg  depfile     Dependency file to output.
4915fb4814Smrg  tmpdepfile  Temporary file to use when outputing dependencies.
5015fb4814Smrg  libtool     Whether libtool is used (yes/no).
5115fb4814Smrg
5215fb4814SmrgReport bugs to <bug-automake@gnu.org>.
5315fb4814SmrgEOF
5415fb4814Smrg    exit $?
5515fb4814Smrg    ;;
5615fb4814Smrg  -v | --v*)
5715fb4814Smrg    echo "depcomp $scriptversion"
5815fb4814Smrg    exit $?
5915fb4814Smrg    ;;
6015fb4814Smrgesac
6115fb4814Smrg
6215fb4814Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
6315fb4814Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
6415fb4814Smrg  exit 1
6515fb4814Smrgfi
6615fb4814Smrg
6715fb4814Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
6815fb4814Smrgdepfile=${depfile-`echo "$object" |
6915fb4814Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
7015fb4814Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
7115fb4814Smrg
7215fb4814Smrgrm -f "$tmpdepfile"
7315fb4814Smrg
7415fb4814Smrg# Some modes work just like other modes, but use different flags.  We
7515fb4814Smrg# parameterize here, but still list the modes in the big case below,
7615fb4814Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
7715fb4814Smrg# here, because this file can only contain one case statement.
7815fb4814Smrgif test "$depmode" = hp; then
7915fb4814Smrg  # HP compiler uses -M and no extra arg.
8015fb4814Smrg  gccflag=-M
8115fb4814Smrg  depmode=gcc
8215fb4814Smrgfi
8315fb4814Smrg
8415fb4814Smrgif test "$depmode" = dashXmstdout; then
8515fb4814Smrg   # This is just like dashmstdout with a different argument.
8615fb4814Smrg   dashmflag=-xM
8715fb4814Smrg   depmode=dashmstdout
8815fb4814Smrgfi
8915fb4814Smrg
9015fb4814Smrgcase "$depmode" in
9115fb4814Smrggcc3)
9215fb4814Smrg## gcc 3 implements dependency tracking that does exactly what
9315fb4814Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
9415fb4814Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
95de78e416Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
96de78e416Smrg## the command line argument order; so add the flags where they
97de78e416Smrg## appear in depend2.am.  Note that the slowdown incurred here
98de78e416Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
99de78e416Smrg  for arg
100de78e416Smrg  do
101de78e416Smrg    case $arg in
102de78e416Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
103de78e416Smrg    *)  set fnord "$@" "$arg" ;;
104de78e416Smrg    esac
105de78e416Smrg    shift # fnord
106de78e416Smrg    shift # $arg
107de78e416Smrg  done
108de78e416Smrg  "$@"
10915fb4814Smrg  stat=$?
11015fb4814Smrg  if test $stat -eq 0; then :
11115fb4814Smrg  else
11215fb4814Smrg    rm -f "$tmpdepfile"
11315fb4814Smrg    exit $stat
11415fb4814Smrg  fi
11515fb4814Smrg  mv "$tmpdepfile" "$depfile"
11615fb4814Smrg  ;;
11715fb4814Smrg
11815fb4814Smrggcc)
11915fb4814Smrg## There are various ways to get dependency output from gcc.  Here's
12015fb4814Smrg## why we pick this rather obscure method:
12115fb4814Smrg## - Don't want to use -MD because we'd like the dependencies to end
12215fb4814Smrg##   up in a subdir.  Having to rename by hand is ugly.
12315fb4814Smrg##   (We might end up doing this anyway to support other compilers.)
12415fb4814Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
12515fb4814Smrg##   -MM, not -M (despite what the docs say).
12615fb4814Smrg## - Using -M directly means running the compiler twice (even worse
12715fb4814Smrg##   than renaming).
12815fb4814Smrg  if test -z "$gccflag"; then
12915fb4814Smrg    gccflag=-MD,
13015fb4814Smrg  fi
13115fb4814Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
13215fb4814Smrg  stat=$?
13315fb4814Smrg  if test $stat -eq 0; then :
13415fb4814Smrg  else
13515fb4814Smrg    rm -f "$tmpdepfile"
13615fb4814Smrg    exit $stat
13715fb4814Smrg  fi
13815fb4814Smrg  rm -f "$depfile"
13915fb4814Smrg  echo "$object : \\" > "$depfile"
14015fb4814Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
14115fb4814Smrg## The second -e expression handles DOS-style file names with drive letters.
14215fb4814Smrg  sed -e 's/^[^:]*: / /' \
14315fb4814Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
14415fb4814Smrg## This next piece of magic avoids the `deleted header file' problem.
14515fb4814Smrg## The problem is that when a header file which appears in a .P file
14615fb4814Smrg## is deleted, the dependency causes make to die (because there is
14715fb4814Smrg## typically no way to rebuild the header).  We avoid this by adding
14815fb4814Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
14915fb4814Smrg## this for us directly.
15015fb4814Smrg  tr ' ' '
15115fb4814Smrg' < "$tmpdepfile" |
15215fb4814Smrg## Some versions of gcc put a space before the `:'.  On the theory
15315fb4814Smrg## that the space means something, we add a space to the output as
15415fb4814Smrg## well.
15515fb4814Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
15615fb4814Smrg## correctly.  Breaking it into two sed invocations is a workaround.
15715fb4814Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
15815fb4814Smrg  rm -f "$tmpdepfile"
15915fb4814Smrg  ;;
16015fb4814Smrg
16115fb4814Smrghp)
16215fb4814Smrg  # This case exists only to let depend.m4 do its work.  It works by
16315fb4814Smrg  # looking at the text of this script.  This case will never be run,
16415fb4814Smrg  # since it is checked for above.
16515fb4814Smrg  exit 1
16615fb4814Smrg  ;;
16715fb4814Smrg
16815fb4814Smrgsgi)
16915fb4814Smrg  if test "$libtool" = yes; then
17015fb4814Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
17115fb4814Smrg  else
17215fb4814Smrg    "$@" -MDupdate "$tmpdepfile"
17315fb4814Smrg  fi
17415fb4814Smrg  stat=$?
17515fb4814Smrg  if test $stat -eq 0; then :
17615fb4814Smrg  else
17715fb4814Smrg    rm -f "$tmpdepfile"
17815fb4814Smrg    exit $stat
17915fb4814Smrg  fi
18015fb4814Smrg  rm -f "$depfile"
18115fb4814Smrg
18215fb4814Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
18315fb4814Smrg    echo "$object : \\" > "$depfile"
18415fb4814Smrg
18515fb4814Smrg    # Clip off the initial element (the dependent).  Don't try to be
18615fb4814Smrg    # clever and replace this with sed code, as IRIX sed won't handle
18715fb4814Smrg    # lines with more than a fixed number of characters (4096 in
18815fb4814Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
18915fb4814Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
19015fb4814Smrg    # dependency line.
19115fb4814Smrg    tr ' ' '
19215fb4814Smrg' < "$tmpdepfile" \
19315fb4814Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
19415fb4814Smrg    tr '
19515fb4814Smrg' ' ' >> $depfile
19615fb4814Smrg    echo >> $depfile
19715fb4814Smrg
19815fb4814Smrg    # The second pass generates a dummy entry for each header file.
19915fb4814Smrg    tr ' ' '
20015fb4814Smrg' < "$tmpdepfile" \
20115fb4814Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
20215fb4814Smrg   >> $depfile
20315fb4814Smrg  else
20415fb4814Smrg    # The sourcefile does not contain any dependencies, so just
20515fb4814Smrg    # store a dummy comment line, to avoid errors with the Makefile
20615fb4814Smrg    # "include basename.Plo" scheme.
20715fb4814Smrg    echo "#dummy" > "$depfile"
20815fb4814Smrg  fi
20915fb4814Smrg  rm -f "$tmpdepfile"
21015fb4814Smrg  ;;
21115fb4814Smrg
21215fb4814Smrgaix)
21315fb4814Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
21415fb4814Smrg  # in a .u file.  In older versions, this file always lives in the
21515fb4814Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
21615fb4814Smrg  # start of each line; $object doesn't have directory information.
21715fb4814Smrg  # Version 6 uses the directory in both cases.
21815fb4814Smrg  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
21915fb4814Smrg  tmpdepfile="$stripped.u"
22015fb4814Smrg  if test "$libtool" = yes; then
22115fb4814Smrg    "$@" -Wc,-M
22215fb4814Smrg  else
22315fb4814Smrg    "$@" -M
22415fb4814Smrg  fi
22515fb4814Smrg  stat=$?
22615fb4814Smrg
22715fb4814Smrg  if test -f "$tmpdepfile"; then :
22815fb4814Smrg  else
22915fb4814Smrg    stripped=`echo "$stripped" | sed 's,^.*/,,'`
23015fb4814Smrg    tmpdepfile="$stripped.u"
23115fb4814Smrg  fi
23215fb4814Smrg
23315fb4814Smrg  if test $stat -eq 0; then :
23415fb4814Smrg  else
23515fb4814Smrg    rm -f "$tmpdepfile"
23615fb4814Smrg    exit $stat
23715fb4814Smrg  fi
23815fb4814Smrg
23915fb4814Smrg  if test -f "$tmpdepfile"; then
24015fb4814Smrg    outname="$stripped.o"
24115fb4814Smrg    # Each line is of the form `foo.o: dependent.h'.
24215fb4814Smrg    # Do two passes, one to just change these to
24315fb4814Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
24415fb4814Smrg    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
24515fb4814Smrg    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
24615fb4814Smrg  else
24715fb4814Smrg    # The sourcefile does not contain any dependencies, so just
24815fb4814Smrg    # store a dummy comment line, to avoid errors with the Makefile
24915fb4814Smrg    # "include basename.Plo" scheme.
25015fb4814Smrg    echo "#dummy" > "$depfile"
25115fb4814Smrg  fi
25215fb4814Smrg  rm -f "$tmpdepfile"
25315fb4814Smrg  ;;
25415fb4814Smrg
25515fb4814Smrgicc)
25615fb4814Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
25715fb4814Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
25815fb4814Smrg  # ICC 7.0 will fill foo.d with something like
25915fb4814Smrg  #    foo.o: sub/foo.c
26015fb4814Smrg  #    foo.o: sub/foo.h
26115fb4814Smrg  # which is wrong.  We want:
26215fb4814Smrg  #    sub/foo.o: sub/foo.c
26315fb4814Smrg  #    sub/foo.o: sub/foo.h
26415fb4814Smrg  #    sub/foo.c:
26515fb4814Smrg  #    sub/foo.h:
26615fb4814Smrg  # ICC 7.1 will output
26715fb4814Smrg  #    foo.o: sub/foo.c sub/foo.h
26815fb4814Smrg  # and will wrap long lines using \ :
26915fb4814Smrg  #    foo.o: sub/foo.c ... \
27015fb4814Smrg  #     sub/foo.h ... \
27115fb4814Smrg  #     ...
27215fb4814Smrg
27315fb4814Smrg  "$@" -MD -MF "$tmpdepfile"
27415fb4814Smrg  stat=$?
27515fb4814Smrg  if test $stat -eq 0; then :
27615fb4814Smrg  else
27715fb4814Smrg    rm -f "$tmpdepfile"
27815fb4814Smrg    exit $stat
27915fb4814Smrg  fi
28015fb4814Smrg  rm -f "$depfile"
28115fb4814Smrg  # Each line is of the form `foo.o: dependent.h',
28215fb4814Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
28315fb4814Smrg  # Do two passes, one to just change these to
28415fb4814Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
28515fb4814Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
28615fb4814Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
28715fb4814Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
28815fb4814Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
28915fb4814Smrg    sed -e 's/$/ :/' >> "$depfile"
29015fb4814Smrg  rm -f "$tmpdepfile"
29115fb4814Smrg  ;;
29215fb4814Smrg
293de78e416Smrghp2)
294de78e416Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
295de78e416Smrg  # compilers, which have integrated preprocessors.  The correct option
296de78e416Smrg  # to use with these is +Maked; it writes dependencies to a file named
297de78e416Smrg  # 'foo.d', which lands next to the object file, wherever that
298de78e416Smrg  # happens to be.
299de78e416Smrg  # Much of this is similar to the tru64 case; see comments there.
300de78e416Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
301de78e416Smrg  test "x$dir" = "x$object" && dir=
302de78e416Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
303de78e416Smrg  if test "$libtool" = yes; then
304de78e416Smrg    tmpdepfile1=$dir$base.d
305de78e416Smrg    tmpdepfile2=$dir.libs/$base.d
306de78e416Smrg    "$@" -Wc,+Maked
307de78e416Smrg  else
308de78e416Smrg    tmpdepfile1=$dir$base.d
309de78e416Smrg    tmpdepfile2=$dir$base.d
310de78e416Smrg    "$@" +Maked
311de78e416Smrg  fi
312de78e416Smrg  stat=$?
313de78e416Smrg  if test $stat -eq 0; then :
314de78e416Smrg  else
315de78e416Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
316de78e416Smrg     exit $stat
317de78e416Smrg  fi
318de78e416Smrg
319de78e416Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
320de78e416Smrg  do
321de78e416Smrg    test -f "$tmpdepfile" && break
322de78e416Smrg  done
323de78e416Smrg  if test -f "$tmpdepfile"; then
324de78e416Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
325de78e416Smrg    # Add `dependent.h:' lines.
326de78e416Smrg    sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
327de78e416Smrg  else
328de78e416Smrg    echo "#dummy" > "$depfile"
329de78e416Smrg  fi
330de78e416Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
331de78e416Smrg  ;;
332de78e416Smrg
33315fb4814Smrgtru64)
33415fb4814Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
33515fb4814Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
33615fb4814Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
33715fb4814Smrg   # dependencies in `foo.d' instead, so we check for that too.
33815fb4814Smrg   # Subdirectories are respected.
33915fb4814Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
34015fb4814Smrg   test "x$dir" = "x$object" && dir=
34115fb4814Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
34215fb4814Smrg
34315fb4814Smrg   if test "$libtool" = yes; then
34415fb4814Smrg      # With Tru64 cc, shared objects can also be used to make a
345de78e416Smrg      # static library.  This mechanism is used in libtool 1.4 series to
34615fb4814Smrg      # handle both shared and static libraries in a single compilation.
34715fb4814Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
34815fb4814Smrg      #
34915fb4814Smrg      # With libtool 1.5 this exception was removed, and libtool now
35015fb4814Smrg      # generates 2 separate objects for the 2 libraries.  These two
351de78e416Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
35215fb4814Smrg      # in $dir$base.o.d.  We have to check for both files, because
35315fb4814Smrg      # one of the two compilations can be disabled.  We should prefer
35415fb4814Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
35515fb4814Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
35615fb4814Smrg      # the former would cause a distcleancheck panic.
35715fb4814Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
35815fb4814Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
35915fb4814Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
36015fb4814Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
36115fb4814Smrg      "$@" -Wc,-MD
36215fb4814Smrg   else
36315fb4814Smrg      tmpdepfile1=$dir$base.o.d
36415fb4814Smrg      tmpdepfile2=$dir$base.d
36515fb4814Smrg      tmpdepfile3=$dir$base.d
36615fb4814Smrg      tmpdepfile4=$dir$base.d
36715fb4814Smrg      "$@" -MD
36815fb4814Smrg   fi
36915fb4814Smrg
37015fb4814Smrg   stat=$?
37115fb4814Smrg   if test $stat -eq 0; then :
37215fb4814Smrg   else
37315fb4814Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
37415fb4814Smrg      exit $stat
37515fb4814Smrg   fi
37615fb4814Smrg
37715fb4814Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
37815fb4814Smrg   do
37915fb4814Smrg     test -f "$tmpdepfile" && break
38015fb4814Smrg   done
38115fb4814Smrg   if test -f "$tmpdepfile"; then
38215fb4814Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
38315fb4814Smrg      # That's a tab and a space in the [].
38415fb4814Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
38515fb4814Smrg   else
38615fb4814Smrg      echo "#dummy" > "$depfile"
38715fb4814Smrg   fi
38815fb4814Smrg   rm -f "$tmpdepfile"
38915fb4814Smrg   ;;
39015fb4814Smrg
39115fb4814Smrg#nosideeffect)
39215fb4814Smrg  # This comment above is used by automake to tell side-effect
39315fb4814Smrg  # dependency tracking mechanisms from slower ones.
39415fb4814Smrg
39515fb4814Smrgdashmstdout)
39615fb4814Smrg  # Important note: in order to support this mode, a compiler *must*
39715fb4814Smrg  # always write the preprocessed file to stdout, regardless of -o.
39815fb4814Smrg  "$@" || exit $?
39915fb4814Smrg
40015fb4814Smrg  # Remove the call to Libtool.
40115fb4814Smrg  if test "$libtool" = yes; then
40215fb4814Smrg    while test $1 != '--mode=compile'; do
40315fb4814Smrg      shift
40415fb4814Smrg    done
40515fb4814Smrg    shift
40615fb4814Smrg  fi
40715fb4814Smrg
40815fb4814Smrg  # Remove `-o $object'.
40915fb4814Smrg  IFS=" "
41015fb4814Smrg  for arg
41115fb4814Smrg  do
41215fb4814Smrg    case $arg in
41315fb4814Smrg    -o)
41415fb4814Smrg      shift
41515fb4814Smrg      ;;
41615fb4814Smrg    $object)
41715fb4814Smrg      shift
41815fb4814Smrg      ;;
41915fb4814Smrg    *)
42015fb4814Smrg      set fnord "$@" "$arg"
42115fb4814Smrg      shift # fnord
42215fb4814Smrg      shift # $arg
42315fb4814Smrg      ;;
42415fb4814Smrg    esac
42515fb4814Smrg  done
42615fb4814Smrg
42715fb4814Smrg  test -z "$dashmflag" && dashmflag=-M
42815fb4814Smrg  # Require at least two characters before searching for `:'
42915fb4814Smrg  # in the target name.  This is to cope with DOS-style filenames:
43015fb4814Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
43115fb4814Smrg  "$@" $dashmflag |
43215fb4814Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
43315fb4814Smrg  rm -f "$depfile"
43415fb4814Smrg  cat < "$tmpdepfile" > "$depfile"
43515fb4814Smrg  tr ' ' '
43615fb4814Smrg' < "$tmpdepfile" | \
43715fb4814Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
43815fb4814Smrg## correctly.  Breaking it into two sed invocations is a workaround.
43915fb4814Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
44015fb4814Smrg  rm -f "$tmpdepfile"
44115fb4814Smrg  ;;
44215fb4814Smrg
44315fb4814SmrgdashXmstdout)
44415fb4814Smrg  # This case only exists to satisfy depend.m4.  It is never actually
44515fb4814Smrg  # run, as this mode is specially recognized in the preamble.
44615fb4814Smrg  exit 1
44715fb4814Smrg  ;;
44815fb4814Smrg
44915fb4814Smrgmakedepend)
45015fb4814Smrg  "$@" || exit $?
45115fb4814Smrg  # Remove any Libtool call
45215fb4814Smrg  if test "$libtool" = yes; then
45315fb4814Smrg    while test $1 != '--mode=compile'; do
45415fb4814Smrg      shift
45515fb4814Smrg    done
45615fb4814Smrg    shift
45715fb4814Smrg  fi
45815fb4814Smrg  # X makedepend
45915fb4814Smrg  shift
46015fb4814Smrg  cleared=no
46115fb4814Smrg  for arg in "$@"; do
46215fb4814Smrg    case $cleared in
46315fb4814Smrg    no)
46415fb4814Smrg      set ""; shift
46515fb4814Smrg      cleared=yes ;;
46615fb4814Smrg    esac
46715fb4814Smrg    case "$arg" in
46815fb4814Smrg    -D*|-I*)
46915fb4814Smrg      set fnord "$@" "$arg"; shift ;;
47015fb4814Smrg    # Strip any option that makedepend may not understand.  Remove
47115fb4814Smrg    # the object too, otherwise makedepend will parse it as a source file.
47215fb4814Smrg    -*|$object)
47315fb4814Smrg      ;;
47415fb4814Smrg    *)
47515fb4814Smrg      set fnord "$@" "$arg"; shift ;;
47615fb4814Smrg    esac
47715fb4814Smrg  done
47815fb4814Smrg  obj_suffix="`echo $object | sed 's/^.*\././'`"
47915fb4814Smrg  touch "$tmpdepfile"
48015fb4814Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
48115fb4814Smrg  rm -f "$depfile"
48215fb4814Smrg  cat < "$tmpdepfile" > "$depfile"
48315fb4814Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
48415fb4814Smrg' | \
48515fb4814Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
48615fb4814Smrg## correctly.  Breaking it into two sed invocations is a workaround.
48715fb4814Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
48815fb4814Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
48915fb4814Smrg  ;;
49015fb4814Smrg
49115fb4814Smrgcpp)
49215fb4814Smrg  # Important note: in order to support this mode, a compiler *must*
49315fb4814Smrg  # always write the preprocessed file to stdout.
49415fb4814Smrg  "$@" || exit $?
49515fb4814Smrg
49615fb4814Smrg  # Remove the call to Libtool.
49715fb4814Smrg  if test "$libtool" = yes; then
49815fb4814Smrg    while test $1 != '--mode=compile'; do
49915fb4814Smrg      shift
50015fb4814Smrg    done
50115fb4814Smrg    shift
50215fb4814Smrg  fi
50315fb4814Smrg
50415fb4814Smrg  # Remove `-o $object'.
50515fb4814Smrg  IFS=" "
50615fb4814Smrg  for arg
50715fb4814Smrg  do
50815fb4814Smrg    case $arg in
50915fb4814Smrg    -o)
51015fb4814Smrg      shift
51115fb4814Smrg      ;;
51215fb4814Smrg    $object)
51315fb4814Smrg      shift
51415fb4814Smrg      ;;
51515fb4814Smrg    *)
51615fb4814Smrg      set fnord "$@" "$arg"
51715fb4814Smrg      shift # fnord
51815fb4814Smrg      shift # $arg
51915fb4814Smrg      ;;
52015fb4814Smrg    esac
52115fb4814Smrg  done
52215fb4814Smrg
52315fb4814Smrg  "$@" -E |
52415fb4814Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
52515fb4814Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
52615fb4814Smrg    sed '$ s: \\$::' > "$tmpdepfile"
52715fb4814Smrg  rm -f "$depfile"
52815fb4814Smrg  echo "$object : \\" > "$depfile"
52915fb4814Smrg  cat < "$tmpdepfile" >> "$depfile"
53015fb4814Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
53115fb4814Smrg  rm -f "$tmpdepfile"
53215fb4814Smrg  ;;
53315fb4814Smrg
53415fb4814Smrgmsvisualcpp)
53515fb4814Smrg  # Important note: in order to support this mode, a compiler *must*
53615fb4814Smrg  # always write the preprocessed file to stdout, regardless of -o,
53715fb4814Smrg  # because we must use -o when running libtool.
53815fb4814Smrg  "$@" || exit $?
53915fb4814Smrg  IFS=" "
54015fb4814Smrg  for arg
54115fb4814Smrg  do
54215fb4814Smrg    case "$arg" in
54315fb4814Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
54415fb4814Smrg	set fnord "$@"
54515fb4814Smrg	shift
54615fb4814Smrg	shift
54715fb4814Smrg	;;
54815fb4814Smrg    *)
54915fb4814Smrg	set fnord "$@" "$arg"
55015fb4814Smrg	shift
55115fb4814Smrg	shift
55215fb4814Smrg	;;
55315fb4814Smrg    esac
55415fb4814Smrg  done
55515fb4814Smrg  "$@" -E |
55615fb4814Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
55715fb4814Smrg  rm -f "$depfile"
55815fb4814Smrg  echo "$object : \\" > "$depfile"
55915fb4814Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
56015fb4814Smrg  echo "	" >> "$depfile"
56115fb4814Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
56215fb4814Smrg  rm -f "$tmpdepfile"
56315fb4814Smrg  ;;
56415fb4814Smrg
56515fb4814Smrgnone)
56615fb4814Smrg  exec "$@"
56715fb4814Smrg  ;;
56815fb4814Smrg
56915fb4814Smrg*)
57015fb4814Smrg  echo "Unknown depmode $depmode" 1>&2
57115fb4814Smrg  exit 1
57215fb4814Smrg  ;;
57315fb4814Smrgesac
57415fb4814Smrg
57515fb4814Smrgexit 0
57615fb4814Smrg
57715fb4814Smrg# Local Variables:
57815fb4814Smrg# mode: shell-script
57915fb4814Smrg# sh-indentation: 2
58015fb4814Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
58115fb4814Smrg# time-stamp-start: "scriptversion="
58215fb4814Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
58315fb4814Smrg# time-stamp-end: "$"
58415fb4814Smrg# End:
585