depcomp revision e19dfac4
127702724Smrg#! /bin/sh
227702724Smrg# depcomp - compile a program generating dependencies as side-effects
327702724Smrg
4e19dfac4Smrgscriptversion=2007-03-29.01
527702724Smrg
6e19dfac4Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007 Free Software
7e19dfac4Smrg# Foundation, Inc.
827702724Smrg
927702724Smrg# This program is free software; you can redistribute it and/or modify
1027702724Smrg# it under the terms of the GNU General Public License as published by
1127702724Smrg# the Free Software Foundation; either version 2, or (at your option)
1227702724Smrg# any later version.
1327702724Smrg
1427702724Smrg# This program is distributed in the hope that it will be useful,
1527702724Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1627702724Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1727702724Smrg# GNU General Public License for more details.
1827702724Smrg
1927702724Smrg# You should have received a copy of the GNU General Public License
2027702724Smrg# along with this program; if not, write to the Free Software
2127702724Smrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
2227702724Smrg# 02110-1301, USA.
2327702724Smrg
2427702724Smrg# As a special exception to the GNU General Public License, if you
2527702724Smrg# distribute this file as part of a program that contains a
2627702724Smrg# configuration script generated by Autoconf, you may include it under
2727702724Smrg# the same distribution terms that you use for the rest of that program.
2827702724Smrg
2927702724Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
3027702724Smrg
3127702724Smrgcase $1 in
3227702724Smrg  '')
3327702724Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
3427702724Smrg     exit 1;
3527702724Smrg     ;;
3627702724Smrg  -h | --h*)
3727702724Smrg    cat <<\EOF
3827702724SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3927702724Smrg
4027702724SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
4127702724Smrgas side-effects.
4227702724Smrg
4327702724SmrgEnvironment variables:
4427702724Smrg  depmode     Dependency tracking mode.
4527702724Smrg  source      Source file read by `PROGRAMS ARGS'.
4627702724Smrg  object      Object file output by `PROGRAMS ARGS'.
4727702724Smrg  DEPDIR      directory where to store dependencies.
4827702724Smrg  depfile     Dependency file to output.
4927702724Smrg  tmpdepfile  Temporary file to use when outputing dependencies.
5027702724Smrg  libtool     Whether libtool is used (yes/no).
5127702724Smrg
5227702724SmrgReport bugs to <bug-automake@gnu.org>.
5327702724SmrgEOF
5427702724Smrg    exit $?
5527702724Smrg    ;;
5627702724Smrg  -v | --v*)
5727702724Smrg    echo "depcomp $scriptversion"
5827702724Smrg    exit $?
5927702724Smrg    ;;
6027702724Smrgesac
6127702724Smrg
6227702724Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
6327702724Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
6427702724Smrg  exit 1
6527702724Smrgfi
6627702724Smrg
6727702724Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
6827702724Smrgdepfile=${depfile-`echo "$object" |
6927702724Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
7027702724Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
7127702724Smrg
7227702724Smrgrm -f "$tmpdepfile"
7327702724Smrg
7427702724Smrg# Some modes work just like other modes, but use different flags.  We
7527702724Smrg# parameterize here, but still list the modes in the big case below,
7627702724Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
7727702724Smrg# here, because this file can only contain one case statement.
7827702724Smrgif test "$depmode" = hp; then
7927702724Smrg  # HP compiler uses -M and no extra arg.
8027702724Smrg  gccflag=-M
8127702724Smrg  depmode=gcc
8227702724Smrgfi
8327702724Smrg
8427702724Smrgif test "$depmode" = dashXmstdout; then
8527702724Smrg   # This is just like dashmstdout with a different argument.
8627702724Smrg   dashmflag=-xM
8727702724Smrg   depmode=dashmstdout
8827702724Smrgfi
8927702724Smrg
9027702724Smrgcase "$depmode" in
9127702724Smrggcc3)
9227702724Smrg## gcc 3 implements dependency tracking that does exactly what
9327702724Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
9427702724Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
95e19dfac4Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
96e19dfac4Smrg## the command line argument order; so add the flags where they
97e19dfac4Smrg## appear in depend2.am.  Note that the slowdown incurred here
98e19dfac4Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
99e19dfac4Smrg  for arg
100e19dfac4Smrg  do
101e19dfac4Smrg    case $arg in
102e19dfac4Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
103e19dfac4Smrg    *)  set fnord "$@" "$arg" ;;
104e19dfac4Smrg    esac
105e19dfac4Smrg    shift # fnord
106e19dfac4Smrg    shift # $arg
107e19dfac4Smrg  done
108e19dfac4Smrg  "$@"
10927702724Smrg  stat=$?
11027702724Smrg  if test $stat -eq 0; then :
11127702724Smrg  else
11227702724Smrg    rm -f "$tmpdepfile"
11327702724Smrg    exit $stat
11427702724Smrg  fi
11527702724Smrg  mv "$tmpdepfile" "$depfile"
11627702724Smrg  ;;
11727702724Smrg
11827702724Smrggcc)
11927702724Smrg## There are various ways to get dependency output from gcc.  Here's
12027702724Smrg## why we pick this rather obscure method:
12127702724Smrg## - Don't want to use -MD because we'd like the dependencies to end
12227702724Smrg##   up in a subdir.  Having to rename by hand is ugly.
12327702724Smrg##   (We might end up doing this anyway to support other compilers.)
12427702724Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
12527702724Smrg##   -MM, not -M (despite what the docs say).
12627702724Smrg## - Using -M directly means running the compiler twice (even worse
12727702724Smrg##   than renaming).
12827702724Smrg  if test -z "$gccflag"; then
12927702724Smrg    gccflag=-MD,
13027702724Smrg  fi
13127702724Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
13227702724Smrg  stat=$?
13327702724Smrg  if test $stat -eq 0; then :
13427702724Smrg  else
13527702724Smrg    rm -f "$tmpdepfile"
13627702724Smrg    exit $stat
13727702724Smrg  fi
13827702724Smrg  rm -f "$depfile"
13927702724Smrg  echo "$object : \\" > "$depfile"
14027702724Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
14127702724Smrg## The second -e expression handles DOS-style file names with drive letters.
14227702724Smrg  sed -e 's/^[^:]*: / /' \
14327702724Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
14427702724Smrg## This next piece of magic avoids the `deleted header file' problem.
14527702724Smrg## The problem is that when a header file which appears in a .P file
14627702724Smrg## is deleted, the dependency causes make to die (because there is
14727702724Smrg## typically no way to rebuild the header).  We avoid this by adding
14827702724Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
14927702724Smrg## this for us directly.
15027702724Smrg  tr ' ' '
15127702724Smrg' < "$tmpdepfile" |
15227702724Smrg## Some versions of gcc put a space before the `:'.  On the theory
15327702724Smrg## that the space means something, we add a space to the output as
15427702724Smrg## well.
15527702724Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
15627702724Smrg## correctly.  Breaking it into two sed invocations is a workaround.
15727702724Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
15827702724Smrg  rm -f "$tmpdepfile"
15927702724Smrg  ;;
16027702724Smrg
16127702724Smrghp)
16227702724Smrg  # This case exists only to let depend.m4 do its work.  It works by
16327702724Smrg  # looking at the text of this script.  This case will never be run,
16427702724Smrg  # since it is checked for above.
16527702724Smrg  exit 1
16627702724Smrg  ;;
16727702724Smrg
16827702724Smrgsgi)
16927702724Smrg  if test "$libtool" = yes; then
17027702724Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
17127702724Smrg  else
17227702724Smrg    "$@" -MDupdate "$tmpdepfile"
17327702724Smrg  fi
17427702724Smrg  stat=$?
17527702724Smrg  if test $stat -eq 0; then :
17627702724Smrg  else
17727702724Smrg    rm -f "$tmpdepfile"
17827702724Smrg    exit $stat
17927702724Smrg  fi
18027702724Smrg  rm -f "$depfile"
18127702724Smrg
18227702724Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
18327702724Smrg    echo "$object : \\" > "$depfile"
18427702724Smrg
18527702724Smrg    # Clip off the initial element (the dependent).  Don't try to be
18627702724Smrg    # clever and replace this with sed code, as IRIX sed won't handle
18727702724Smrg    # lines with more than a fixed number of characters (4096 in
18827702724Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
18927702724Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
19027702724Smrg    # dependency line.
19127702724Smrg    tr ' ' '
19227702724Smrg' < "$tmpdepfile" \
19327702724Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
19427702724Smrg    tr '
19527702724Smrg' ' ' >> $depfile
19627702724Smrg    echo >> $depfile
19727702724Smrg
19827702724Smrg    # The second pass generates a dummy entry for each header file.
19927702724Smrg    tr ' ' '
20027702724Smrg' < "$tmpdepfile" \
20127702724Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
20227702724Smrg   >> $depfile
20327702724Smrg  else
20427702724Smrg    # The sourcefile does not contain any dependencies, so just
20527702724Smrg    # store a dummy comment line, to avoid errors with the Makefile
20627702724Smrg    # "include basename.Plo" scheme.
20727702724Smrg    echo "#dummy" > "$depfile"
20827702724Smrg  fi
20927702724Smrg  rm -f "$tmpdepfile"
21027702724Smrg  ;;
21127702724Smrg
21227702724Smrgaix)
21327702724Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
21427702724Smrg  # in a .u file.  In older versions, this file always lives in the
21527702724Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
21627702724Smrg  # start of each line; $object doesn't have directory information.
21727702724Smrg  # Version 6 uses the directory in both cases.
218e19dfac4Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
219e19dfac4Smrg  test "x$dir" = "x$object" && dir=
220e19dfac4Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
22127702724Smrg  if test "$libtool" = yes; then
222e19dfac4Smrg    tmpdepfile1=$dir$base.u
223e19dfac4Smrg    tmpdepfile2=$base.u
224e19dfac4Smrg    tmpdepfile3=$dir.libs/$base.u
22527702724Smrg    "$@" -Wc,-M
22627702724Smrg  else
227e19dfac4Smrg    tmpdepfile1=$dir$base.u
228e19dfac4Smrg    tmpdepfile2=$dir$base.u
229e19dfac4Smrg    tmpdepfile3=$dir$base.u
23027702724Smrg    "$@" -M
23127702724Smrg  fi
23227702724Smrg  stat=$?
23327702724Smrg
23427702724Smrg  if test $stat -eq 0; then :
23527702724Smrg  else
236e19dfac4Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
23727702724Smrg    exit $stat
23827702724Smrg  fi
23927702724Smrg
240e19dfac4Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
241e19dfac4Smrg  do
242e19dfac4Smrg    test -f "$tmpdepfile" && break
243e19dfac4Smrg  done
24427702724Smrg  if test -f "$tmpdepfile"; then
24527702724Smrg    # Each line is of the form `foo.o: dependent.h'.
24627702724Smrg    # Do two passes, one to just change these to
24727702724Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
248e19dfac4Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
249e19dfac4Smrg    # That's a tab and a space in the [].
250e19dfac4Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
25127702724Smrg  else
25227702724Smrg    # The sourcefile does not contain any dependencies, so just
25327702724Smrg    # store a dummy comment line, to avoid errors with the Makefile
25427702724Smrg    # "include basename.Plo" scheme.
25527702724Smrg    echo "#dummy" > "$depfile"
25627702724Smrg  fi
25727702724Smrg  rm -f "$tmpdepfile"
25827702724Smrg  ;;
25927702724Smrg
26027702724Smrgicc)
26127702724Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
26227702724Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
26327702724Smrg  # ICC 7.0 will fill foo.d with something like
26427702724Smrg  #    foo.o: sub/foo.c
26527702724Smrg  #    foo.o: sub/foo.h
26627702724Smrg  # which is wrong.  We want:
26727702724Smrg  #    sub/foo.o: sub/foo.c
26827702724Smrg  #    sub/foo.o: sub/foo.h
26927702724Smrg  #    sub/foo.c:
27027702724Smrg  #    sub/foo.h:
27127702724Smrg  # ICC 7.1 will output
27227702724Smrg  #    foo.o: sub/foo.c sub/foo.h
27327702724Smrg  # and will wrap long lines using \ :
27427702724Smrg  #    foo.o: sub/foo.c ... \
27527702724Smrg  #     sub/foo.h ... \
27627702724Smrg  #     ...
27727702724Smrg
27827702724Smrg  "$@" -MD -MF "$tmpdepfile"
27927702724Smrg  stat=$?
28027702724Smrg  if test $stat -eq 0; then :
28127702724Smrg  else
28227702724Smrg    rm -f "$tmpdepfile"
28327702724Smrg    exit $stat
28427702724Smrg  fi
28527702724Smrg  rm -f "$depfile"
28627702724Smrg  # Each line is of the form `foo.o: dependent.h',
28727702724Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
28827702724Smrg  # Do two passes, one to just change these to
28927702724Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
29027702724Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
29127702724Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
29227702724Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
29327702724Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
29427702724Smrg    sed -e 's/$/ :/' >> "$depfile"
29527702724Smrg  rm -f "$tmpdepfile"
29627702724Smrg  ;;
29727702724Smrg
298e19dfac4Smrghp2)
299e19dfac4Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
300e19dfac4Smrg  # compilers, which have integrated preprocessors.  The correct option
301e19dfac4Smrg  # to use with these is +Maked; it writes dependencies to a file named
302e19dfac4Smrg  # 'foo.d', which lands next to the object file, wherever that
303e19dfac4Smrg  # happens to be.
304e19dfac4Smrg  # Much of this is similar to the tru64 case; see comments there.
305e19dfac4Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
306e19dfac4Smrg  test "x$dir" = "x$object" && dir=
307e19dfac4Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
308e19dfac4Smrg  if test "$libtool" = yes; then
309e19dfac4Smrg    tmpdepfile1=$dir$base.d
310e19dfac4Smrg    tmpdepfile2=$dir.libs/$base.d
311e19dfac4Smrg    "$@" -Wc,+Maked
312e19dfac4Smrg  else
313e19dfac4Smrg    tmpdepfile1=$dir$base.d
314e19dfac4Smrg    tmpdepfile2=$dir$base.d
315e19dfac4Smrg    "$@" +Maked
316e19dfac4Smrg  fi
317e19dfac4Smrg  stat=$?
318e19dfac4Smrg  if test $stat -eq 0; then :
319e19dfac4Smrg  else
320e19dfac4Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
321e19dfac4Smrg     exit $stat
322e19dfac4Smrg  fi
323e19dfac4Smrg
324e19dfac4Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
325e19dfac4Smrg  do
326e19dfac4Smrg    test -f "$tmpdepfile" && break
327e19dfac4Smrg  done
328e19dfac4Smrg  if test -f "$tmpdepfile"; then
329e19dfac4Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
330e19dfac4Smrg    # Add `dependent.h:' lines.
331e19dfac4Smrg    sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
332e19dfac4Smrg  else
333e19dfac4Smrg    echo "#dummy" > "$depfile"
334e19dfac4Smrg  fi
335e19dfac4Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
336e19dfac4Smrg  ;;
337e19dfac4Smrg
33827702724Smrgtru64)
33927702724Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
34027702724Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
34127702724Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
34227702724Smrg   # dependencies in `foo.d' instead, so we check for that too.
34327702724Smrg   # Subdirectories are respected.
34427702724Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
34527702724Smrg   test "x$dir" = "x$object" && dir=
34627702724Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
34727702724Smrg
34827702724Smrg   if test "$libtool" = yes; then
34927702724Smrg      # With Tru64 cc, shared objects can also be used to make a
350e19dfac4Smrg      # static library.  This mechanism is used in libtool 1.4 series to
35127702724Smrg      # handle both shared and static libraries in a single compilation.
35227702724Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
35327702724Smrg      #
35427702724Smrg      # With libtool 1.5 this exception was removed, and libtool now
35527702724Smrg      # generates 2 separate objects for the 2 libraries.  These two
356e19dfac4Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
35727702724Smrg      # in $dir$base.o.d.  We have to check for both files, because
35827702724Smrg      # one of the two compilations can be disabled.  We should prefer
35927702724Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
36027702724Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
36127702724Smrg      # the former would cause a distcleancheck panic.
36227702724Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
36327702724Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
36427702724Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
36527702724Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
36627702724Smrg      "$@" -Wc,-MD
36727702724Smrg   else
36827702724Smrg      tmpdepfile1=$dir$base.o.d
36927702724Smrg      tmpdepfile2=$dir$base.d
37027702724Smrg      tmpdepfile3=$dir$base.d
37127702724Smrg      tmpdepfile4=$dir$base.d
37227702724Smrg      "$@" -MD
37327702724Smrg   fi
37427702724Smrg
37527702724Smrg   stat=$?
37627702724Smrg   if test $stat -eq 0; then :
37727702724Smrg   else
37827702724Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
37927702724Smrg      exit $stat
38027702724Smrg   fi
38127702724Smrg
38227702724Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
38327702724Smrg   do
38427702724Smrg     test -f "$tmpdepfile" && break
38527702724Smrg   done
38627702724Smrg   if test -f "$tmpdepfile"; then
38727702724Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
38827702724Smrg      # That's a tab and a space in the [].
38927702724Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
39027702724Smrg   else
39127702724Smrg      echo "#dummy" > "$depfile"
39227702724Smrg   fi
39327702724Smrg   rm -f "$tmpdepfile"
39427702724Smrg   ;;
39527702724Smrg
39627702724Smrg#nosideeffect)
39727702724Smrg  # This comment above is used by automake to tell side-effect
39827702724Smrg  # dependency tracking mechanisms from slower ones.
39927702724Smrg
40027702724Smrgdashmstdout)
40127702724Smrg  # Important note: in order to support this mode, a compiler *must*
40227702724Smrg  # always write the preprocessed file to stdout, regardless of -o.
40327702724Smrg  "$@" || exit $?
40427702724Smrg
40527702724Smrg  # Remove the call to Libtool.
40627702724Smrg  if test "$libtool" = yes; then
40727702724Smrg    while test $1 != '--mode=compile'; do
40827702724Smrg      shift
40927702724Smrg    done
41027702724Smrg    shift
41127702724Smrg  fi
41227702724Smrg
41327702724Smrg  # Remove `-o $object'.
41427702724Smrg  IFS=" "
41527702724Smrg  for arg
41627702724Smrg  do
41727702724Smrg    case $arg in
41827702724Smrg    -o)
41927702724Smrg      shift
42027702724Smrg      ;;
42127702724Smrg    $object)
42227702724Smrg      shift
42327702724Smrg      ;;
42427702724Smrg    *)
42527702724Smrg      set fnord "$@" "$arg"
42627702724Smrg      shift # fnord
42727702724Smrg      shift # $arg
42827702724Smrg      ;;
42927702724Smrg    esac
43027702724Smrg  done
43127702724Smrg
43227702724Smrg  test -z "$dashmflag" && dashmflag=-M
43327702724Smrg  # Require at least two characters before searching for `:'
43427702724Smrg  # in the target name.  This is to cope with DOS-style filenames:
43527702724Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
43627702724Smrg  "$@" $dashmflag |
43727702724Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
43827702724Smrg  rm -f "$depfile"
43927702724Smrg  cat < "$tmpdepfile" > "$depfile"
44027702724Smrg  tr ' ' '
44127702724Smrg' < "$tmpdepfile" | \
44227702724Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
44327702724Smrg## correctly.  Breaking it into two sed invocations is a workaround.
44427702724Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
44527702724Smrg  rm -f "$tmpdepfile"
44627702724Smrg  ;;
44727702724Smrg
44827702724SmrgdashXmstdout)
44927702724Smrg  # This case only exists to satisfy depend.m4.  It is never actually
45027702724Smrg  # run, as this mode is specially recognized in the preamble.
45127702724Smrg  exit 1
45227702724Smrg  ;;
45327702724Smrg
45427702724Smrgmakedepend)
45527702724Smrg  "$@" || exit $?
45627702724Smrg  # Remove any Libtool call
45727702724Smrg  if test "$libtool" = yes; then
45827702724Smrg    while test $1 != '--mode=compile'; do
45927702724Smrg      shift
46027702724Smrg    done
46127702724Smrg    shift
46227702724Smrg  fi
46327702724Smrg  # X makedepend
46427702724Smrg  shift
46527702724Smrg  cleared=no
46627702724Smrg  for arg in "$@"; do
46727702724Smrg    case $cleared in
46827702724Smrg    no)
46927702724Smrg      set ""; shift
47027702724Smrg      cleared=yes ;;
47127702724Smrg    esac
47227702724Smrg    case "$arg" in
47327702724Smrg    -D*|-I*)
47427702724Smrg      set fnord "$@" "$arg"; shift ;;
47527702724Smrg    # Strip any option that makedepend may not understand.  Remove
47627702724Smrg    # the object too, otherwise makedepend will parse it as a source file.
47727702724Smrg    -*|$object)
47827702724Smrg      ;;
47927702724Smrg    *)
48027702724Smrg      set fnord "$@" "$arg"; shift ;;
48127702724Smrg    esac
48227702724Smrg  done
48327702724Smrg  obj_suffix="`echo $object | sed 's/^.*\././'`"
48427702724Smrg  touch "$tmpdepfile"
48527702724Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
48627702724Smrg  rm -f "$depfile"
48727702724Smrg  cat < "$tmpdepfile" > "$depfile"
48827702724Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
48927702724Smrg' | \
49027702724Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
49127702724Smrg## correctly.  Breaking it into two sed invocations is a workaround.
49227702724Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
49327702724Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
49427702724Smrg  ;;
49527702724Smrg
49627702724Smrgcpp)
49727702724Smrg  # Important note: in order to support this mode, a compiler *must*
49827702724Smrg  # always write the preprocessed file to stdout.
49927702724Smrg  "$@" || exit $?
50027702724Smrg
50127702724Smrg  # Remove the call to Libtool.
50227702724Smrg  if test "$libtool" = yes; then
50327702724Smrg    while test $1 != '--mode=compile'; do
50427702724Smrg      shift
50527702724Smrg    done
50627702724Smrg    shift
50727702724Smrg  fi
50827702724Smrg
50927702724Smrg  # Remove `-o $object'.
51027702724Smrg  IFS=" "
51127702724Smrg  for arg
51227702724Smrg  do
51327702724Smrg    case $arg in
51427702724Smrg    -o)
51527702724Smrg      shift
51627702724Smrg      ;;
51727702724Smrg    $object)
51827702724Smrg      shift
51927702724Smrg      ;;
52027702724Smrg    *)
52127702724Smrg      set fnord "$@" "$arg"
52227702724Smrg      shift # fnord
52327702724Smrg      shift # $arg
52427702724Smrg      ;;
52527702724Smrg    esac
52627702724Smrg  done
52727702724Smrg
52827702724Smrg  "$@" -E |
52927702724Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
53027702724Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
53127702724Smrg    sed '$ s: \\$::' > "$tmpdepfile"
53227702724Smrg  rm -f "$depfile"
53327702724Smrg  echo "$object : \\" > "$depfile"
53427702724Smrg  cat < "$tmpdepfile" >> "$depfile"
53527702724Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
53627702724Smrg  rm -f "$tmpdepfile"
53727702724Smrg  ;;
53827702724Smrg
53927702724Smrgmsvisualcpp)
54027702724Smrg  # Important note: in order to support this mode, a compiler *must*
54127702724Smrg  # always write the preprocessed file to stdout, regardless of -o,
54227702724Smrg  # because we must use -o when running libtool.
54327702724Smrg  "$@" || exit $?
54427702724Smrg  IFS=" "
54527702724Smrg  for arg
54627702724Smrg  do
54727702724Smrg    case "$arg" in
54827702724Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
54927702724Smrg	set fnord "$@"
55027702724Smrg	shift
55127702724Smrg	shift
55227702724Smrg	;;
55327702724Smrg    *)
55427702724Smrg	set fnord "$@" "$arg"
55527702724Smrg	shift
55627702724Smrg	shift
55727702724Smrg	;;
55827702724Smrg    esac
55927702724Smrg  done
56027702724Smrg  "$@" -E |
56127702724Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
56227702724Smrg  rm -f "$depfile"
56327702724Smrg  echo "$object : \\" > "$depfile"
56427702724Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
56527702724Smrg  echo "	" >> "$depfile"
56627702724Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
56727702724Smrg  rm -f "$tmpdepfile"
56827702724Smrg  ;;
56927702724Smrg
57027702724Smrgnone)
57127702724Smrg  exec "$@"
57227702724Smrg  ;;
57327702724Smrg
57427702724Smrg*)
57527702724Smrg  echo "Unknown depmode $depmode" 1>&2
57627702724Smrg  exit 1
57727702724Smrg  ;;
57827702724Smrgesac
57927702724Smrg
58027702724Smrgexit 0
58127702724Smrg
58227702724Smrg# Local Variables:
58327702724Smrg# mode: shell-script
58427702724Smrg# sh-indentation: 2
58527702724Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
58627702724Smrg# time-stamp-start: "scriptversion="
58727702724Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
58827702724Smrg# time-stamp-end: "$"
58927702724Smrg# End:
590