depcomp revision b4d38c65
115fb4814Smrg#! /bin/sh
215fb4814Smrg# depcomp - compile a program generating dependencies as side-effects
315fb4814Smrg
4b4d38c65Smrgscriptversion=2011-12-04.11; # UTC
515fb4814Smrg
6b4d38c65Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
7b4d38c65Smrg# 2011 Free Software 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
20b4d38c65Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2115fb4814Smrg
2215fb4814Smrg# As a special exception to the GNU General Public License, if you
2315fb4814Smrg# distribute this file as part of a program that contains a
2415fb4814Smrg# configuration script generated by Autoconf, you may include it under
2515fb4814Smrg# the same distribution terms that you use for the rest of that program.
2615fb4814Smrg
2715fb4814Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2815fb4814Smrg
2915fb4814Smrgcase $1 in
3015fb4814Smrg  '')
3115fb4814Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
3215fb4814Smrg     exit 1;
3315fb4814Smrg     ;;
3415fb4814Smrg  -h | --h*)
3515fb4814Smrg    cat <<\EOF
3615fb4814SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3715fb4814Smrg
3815fb4814SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3915fb4814Smrgas side-effects.
4015fb4814Smrg
4115fb4814SmrgEnvironment variables:
4215fb4814Smrg  depmode     Dependency tracking mode.
4315fb4814Smrg  source      Source file read by `PROGRAMS ARGS'.
4415fb4814Smrg  object      Object file output by `PROGRAMS ARGS'.
4515fb4814Smrg  DEPDIR      directory where to store dependencies.
4615fb4814Smrg  depfile     Dependency file to output.
47b4d38c65Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4815fb4814Smrg  libtool     Whether libtool is used (yes/no).
4915fb4814Smrg
5015fb4814SmrgReport bugs to <bug-automake@gnu.org>.
5115fb4814SmrgEOF
5215fb4814Smrg    exit $?
5315fb4814Smrg    ;;
5415fb4814Smrg  -v | --v*)
5515fb4814Smrg    echo "depcomp $scriptversion"
5615fb4814Smrg    exit $?
5715fb4814Smrg    ;;
5815fb4814Smrgesac
5915fb4814Smrg
6015fb4814Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
6115fb4814Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
6215fb4814Smrg  exit 1
6315fb4814Smrgfi
6415fb4814Smrg
6515fb4814Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
6615fb4814Smrgdepfile=${depfile-`echo "$object" |
6715fb4814Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
6815fb4814Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
6915fb4814Smrg
7015fb4814Smrgrm -f "$tmpdepfile"
7115fb4814Smrg
7215fb4814Smrg# Some modes work just like other modes, but use different flags.  We
7315fb4814Smrg# parameterize here, but still list the modes in the big case below,
7415fb4814Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
7515fb4814Smrg# here, because this file can only contain one case statement.
7615fb4814Smrgif test "$depmode" = hp; then
7715fb4814Smrg  # HP compiler uses -M and no extra arg.
7815fb4814Smrg  gccflag=-M
7915fb4814Smrg  depmode=gcc
8015fb4814Smrgfi
8115fb4814Smrg
8215fb4814Smrgif test "$depmode" = dashXmstdout; then
8315fb4814Smrg   # This is just like dashmstdout with a different argument.
8415fb4814Smrg   dashmflag=-xM
8515fb4814Smrg   depmode=dashmstdout
8615fb4814Smrgfi
8715fb4814Smrg
88b4d38c65Smrgcygpath_u="cygpath -u -f -"
89b4d38c65Smrgif test "$depmode" = msvcmsys; then
90b4d38c65Smrg   # This is just like msvisualcpp but w/o cygpath translation.
91b4d38c65Smrg   # Just convert the backslash-escaped backslashes to single forward
92b4d38c65Smrg   # slashes to satisfy depend.m4
93b4d38c65Smrg   cygpath_u='sed s,\\\\,/,g'
94b4d38c65Smrg   depmode=msvisualcpp
95b4d38c65Smrgfi
96b4d38c65Smrg
97b4d38c65Smrgif test "$depmode" = msvc7msys; then
98b4d38c65Smrg   # This is just like msvc7 but w/o cygpath translation.
99b4d38c65Smrg   # Just convert the backslash-escaped backslashes to single forward
100b4d38c65Smrg   # slashes to satisfy depend.m4
101b4d38c65Smrg   cygpath_u='sed s,\\\\,/,g'
102b4d38c65Smrg   depmode=msvc7
103b4d38c65Smrgfi
104b4d38c65Smrg
10515fb4814Smrgcase "$depmode" in
10615fb4814Smrggcc3)
10715fb4814Smrg## gcc 3 implements dependency tracking that does exactly what
10815fb4814Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
10915fb4814Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
110de78e416Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
111de78e416Smrg## the command line argument order; so add the flags where they
112de78e416Smrg## appear in depend2.am.  Note that the slowdown incurred here
113de78e416Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
114de78e416Smrg  for arg
115de78e416Smrg  do
116de78e416Smrg    case $arg in
117de78e416Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
118de78e416Smrg    *)  set fnord "$@" "$arg" ;;
119de78e416Smrg    esac
120de78e416Smrg    shift # fnord
121de78e416Smrg    shift # $arg
122de78e416Smrg  done
123de78e416Smrg  "$@"
12415fb4814Smrg  stat=$?
12515fb4814Smrg  if test $stat -eq 0; then :
12615fb4814Smrg  else
12715fb4814Smrg    rm -f "$tmpdepfile"
12815fb4814Smrg    exit $stat
12915fb4814Smrg  fi
13015fb4814Smrg  mv "$tmpdepfile" "$depfile"
13115fb4814Smrg  ;;
13215fb4814Smrg
13315fb4814Smrggcc)
13415fb4814Smrg## There are various ways to get dependency output from gcc.  Here's
13515fb4814Smrg## why we pick this rather obscure method:
13615fb4814Smrg## - Don't want to use -MD because we'd like the dependencies to end
13715fb4814Smrg##   up in a subdir.  Having to rename by hand is ugly.
13815fb4814Smrg##   (We might end up doing this anyway to support other compilers.)
13915fb4814Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
14015fb4814Smrg##   -MM, not -M (despite what the docs say).
14115fb4814Smrg## - Using -M directly means running the compiler twice (even worse
14215fb4814Smrg##   than renaming).
14315fb4814Smrg  if test -z "$gccflag"; then
14415fb4814Smrg    gccflag=-MD,
14515fb4814Smrg  fi
14615fb4814Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
14715fb4814Smrg  stat=$?
14815fb4814Smrg  if test $stat -eq 0; then :
14915fb4814Smrg  else
15015fb4814Smrg    rm -f "$tmpdepfile"
15115fb4814Smrg    exit $stat
15215fb4814Smrg  fi
15315fb4814Smrg  rm -f "$depfile"
15415fb4814Smrg  echo "$object : \\" > "$depfile"
15515fb4814Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
15615fb4814Smrg## The second -e expression handles DOS-style file names with drive letters.
15715fb4814Smrg  sed -e 's/^[^:]*: / /' \
15815fb4814Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
15915fb4814Smrg## This next piece of magic avoids the `deleted header file' problem.
16015fb4814Smrg## The problem is that when a header file which appears in a .P file
16115fb4814Smrg## is deleted, the dependency causes make to die (because there is
16215fb4814Smrg## typically no way to rebuild the header).  We avoid this by adding
16315fb4814Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
16415fb4814Smrg## this for us directly.
16515fb4814Smrg  tr ' ' '
16615fb4814Smrg' < "$tmpdepfile" |
16715fb4814Smrg## Some versions of gcc put a space before the `:'.  On the theory
16815fb4814Smrg## that the space means something, we add a space to the output as
169b4d38c65Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
170b4d38c65Smrg## to the object.  Take care to not repeat it in the output.
17115fb4814Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
17215fb4814Smrg## correctly.  Breaking it into two sed invocations is a workaround.
173b4d38c65Smrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
174b4d38c65Smrg      | sed -e 's/$/ :/' >> "$depfile"
17515fb4814Smrg  rm -f "$tmpdepfile"
17615fb4814Smrg  ;;
17715fb4814Smrg
17815fb4814Smrghp)
17915fb4814Smrg  # This case exists only to let depend.m4 do its work.  It works by
18015fb4814Smrg  # looking at the text of this script.  This case will never be run,
18115fb4814Smrg  # since it is checked for above.
18215fb4814Smrg  exit 1
18315fb4814Smrg  ;;
18415fb4814Smrg
18515fb4814Smrgsgi)
18615fb4814Smrg  if test "$libtool" = yes; then
18715fb4814Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
18815fb4814Smrg  else
18915fb4814Smrg    "$@" -MDupdate "$tmpdepfile"
19015fb4814Smrg  fi
19115fb4814Smrg  stat=$?
19215fb4814Smrg  if test $stat -eq 0; then :
19315fb4814Smrg  else
19415fb4814Smrg    rm -f "$tmpdepfile"
19515fb4814Smrg    exit $stat
19615fb4814Smrg  fi
19715fb4814Smrg  rm -f "$depfile"
19815fb4814Smrg
19915fb4814Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
20015fb4814Smrg    echo "$object : \\" > "$depfile"
20115fb4814Smrg
20215fb4814Smrg    # Clip off the initial element (the dependent).  Don't try to be
20315fb4814Smrg    # clever and replace this with sed code, as IRIX sed won't handle
20415fb4814Smrg    # lines with more than a fixed number of characters (4096 in
20515fb4814Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
20615fb4814Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
20715fb4814Smrg    # dependency line.
20815fb4814Smrg    tr ' ' '
20915fb4814Smrg' < "$tmpdepfile" \
21015fb4814Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
21115fb4814Smrg    tr '
212b4d38c65Smrg' ' ' >> "$depfile"
213b4d38c65Smrg    echo >> "$depfile"
21415fb4814Smrg
21515fb4814Smrg    # The second pass generates a dummy entry for each header file.
21615fb4814Smrg    tr ' ' '
21715fb4814Smrg' < "$tmpdepfile" \
21815fb4814Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
219b4d38c65Smrg   >> "$depfile"
22015fb4814Smrg  else
22115fb4814Smrg    # The sourcefile does not contain any dependencies, so just
22215fb4814Smrg    # store a dummy comment line, to avoid errors with the Makefile
22315fb4814Smrg    # "include basename.Plo" scheme.
22415fb4814Smrg    echo "#dummy" > "$depfile"
22515fb4814Smrg  fi
22615fb4814Smrg  rm -f "$tmpdepfile"
22715fb4814Smrg  ;;
22815fb4814Smrg
22915fb4814Smrgaix)
23015fb4814Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
23115fb4814Smrg  # in a .u file.  In older versions, this file always lives in the
23215fb4814Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
23315fb4814Smrg  # start of each line; $object doesn't have directory information.
23415fb4814Smrg  # Version 6 uses the directory in both cases.
235b4d38c65Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
236b4d38c65Smrg  test "x$dir" = "x$object" && dir=
237b4d38c65Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
23815fb4814Smrg  if test "$libtool" = yes; then
239b4d38c65Smrg    tmpdepfile1=$dir$base.u
240b4d38c65Smrg    tmpdepfile2=$base.u
241b4d38c65Smrg    tmpdepfile3=$dir.libs/$base.u
24215fb4814Smrg    "$@" -Wc,-M
24315fb4814Smrg  else
244b4d38c65Smrg    tmpdepfile1=$dir$base.u
245b4d38c65Smrg    tmpdepfile2=$dir$base.u
246b4d38c65Smrg    tmpdepfile3=$dir$base.u
24715fb4814Smrg    "$@" -M
24815fb4814Smrg  fi
24915fb4814Smrg  stat=$?
25015fb4814Smrg
25115fb4814Smrg  if test $stat -eq 0; then :
25215fb4814Smrg  else
253b4d38c65Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
25415fb4814Smrg    exit $stat
25515fb4814Smrg  fi
25615fb4814Smrg
257b4d38c65Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
258b4d38c65Smrg  do
259b4d38c65Smrg    test -f "$tmpdepfile" && break
260b4d38c65Smrg  done
26115fb4814Smrg  if test -f "$tmpdepfile"; then
26215fb4814Smrg    # Each line is of the form `foo.o: dependent.h'.
26315fb4814Smrg    # Do two passes, one to just change these to
26415fb4814Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
265b4d38c65Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
266b4d38c65Smrg    # That's a tab and a space in the [].
267b4d38c65Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
26815fb4814Smrg  else
26915fb4814Smrg    # The sourcefile does not contain any dependencies, so just
27015fb4814Smrg    # store a dummy comment line, to avoid errors with the Makefile
27115fb4814Smrg    # "include basename.Plo" scheme.
27215fb4814Smrg    echo "#dummy" > "$depfile"
27315fb4814Smrg  fi
27415fb4814Smrg  rm -f "$tmpdepfile"
27515fb4814Smrg  ;;
27615fb4814Smrg
27715fb4814Smrgicc)
27815fb4814Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
27915fb4814Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
28015fb4814Smrg  # ICC 7.0 will fill foo.d with something like
28115fb4814Smrg  #    foo.o: sub/foo.c
28215fb4814Smrg  #    foo.o: sub/foo.h
28315fb4814Smrg  # which is wrong.  We want:
28415fb4814Smrg  #    sub/foo.o: sub/foo.c
28515fb4814Smrg  #    sub/foo.o: sub/foo.h
28615fb4814Smrg  #    sub/foo.c:
28715fb4814Smrg  #    sub/foo.h:
28815fb4814Smrg  # ICC 7.1 will output
28915fb4814Smrg  #    foo.o: sub/foo.c sub/foo.h
29015fb4814Smrg  # and will wrap long lines using \ :
29115fb4814Smrg  #    foo.o: sub/foo.c ... \
29215fb4814Smrg  #     sub/foo.h ... \
29315fb4814Smrg  #     ...
29415fb4814Smrg
29515fb4814Smrg  "$@" -MD -MF "$tmpdepfile"
29615fb4814Smrg  stat=$?
29715fb4814Smrg  if test $stat -eq 0; then :
29815fb4814Smrg  else
29915fb4814Smrg    rm -f "$tmpdepfile"
30015fb4814Smrg    exit $stat
30115fb4814Smrg  fi
30215fb4814Smrg  rm -f "$depfile"
30315fb4814Smrg  # Each line is of the form `foo.o: dependent.h',
30415fb4814Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
30515fb4814Smrg  # Do two passes, one to just change these to
30615fb4814Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
30715fb4814Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
30815fb4814Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
30915fb4814Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
31015fb4814Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
31115fb4814Smrg    sed -e 's/$/ :/' >> "$depfile"
31215fb4814Smrg  rm -f "$tmpdepfile"
31315fb4814Smrg  ;;
31415fb4814Smrg
315de78e416Smrghp2)
316de78e416Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
317de78e416Smrg  # compilers, which have integrated preprocessors.  The correct option
318de78e416Smrg  # to use with these is +Maked; it writes dependencies to a file named
319de78e416Smrg  # 'foo.d', which lands next to the object file, wherever that
320de78e416Smrg  # happens to be.
321de78e416Smrg  # Much of this is similar to the tru64 case; see comments there.
322de78e416Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
323de78e416Smrg  test "x$dir" = "x$object" && dir=
324de78e416Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
325de78e416Smrg  if test "$libtool" = yes; then
326de78e416Smrg    tmpdepfile1=$dir$base.d
327de78e416Smrg    tmpdepfile2=$dir.libs/$base.d
328de78e416Smrg    "$@" -Wc,+Maked
329de78e416Smrg  else
330de78e416Smrg    tmpdepfile1=$dir$base.d
331de78e416Smrg    tmpdepfile2=$dir$base.d
332de78e416Smrg    "$@" +Maked
333de78e416Smrg  fi
334de78e416Smrg  stat=$?
335de78e416Smrg  if test $stat -eq 0; then :
336de78e416Smrg  else
337de78e416Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
338de78e416Smrg     exit $stat
339de78e416Smrg  fi
340de78e416Smrg
341de78e416Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
342de78e416Smrg  do
343de78e416Smrg    test -f "$tmpdepfile" && break
344de78e416Smrg  done
345de78e416Smrg  if test -f "$tmpdepfile"; then
346de78e416Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
347de78e416Smrg    # Add `dependent.h:' lines.
348b4d38c65Smrg    sed -ne '2,${
349b4d38c65Smrg	       s/^ *//
350b4d38c65Smrg	       s/ \\*$//
351b4d38c65Smrg	       s/$/:/
352b4d38c65Smrg	       p
353b4d38c65Smrg	     }' "$tmpdepfile" >> "$depfile"
354de78e416Smrg  else
355de78e416Smrg    echo "#dummy" > "$depfile"
356de78e416Smrg  fi
357de78e416Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
358de78e416Smrg  ;;
359de78e416Smrg
36015fb4814Smrgtru64)
36115fb4814Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
36215fb4814Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
36315fb4814Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
36415fb4814Smrg   # dependencies in `foo.d' instead, so we check for that too.
36515fb4814Smrg   # Subdirectories are respected.
36615fb4814Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
36715fb4814Smrg   test "x$dir" = "x$object" && dir=
36815fb4814Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
36915fb4814Smrg
37015fb4814Smrg   if test "$libtool" = yes; then
37115fb4814Smrg      # With Tru64 cc, shared objects can also be used to make a
372de78e416Smrg      # static library.  This mechanism is used in libtool 1.4 series to
37315fb4814Smrg      # handle both shared and static libraries in a single compilation.
37415fb4814Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
37515fb4814Smrg      #
37615fb4814Smrg      # With libtool 1.5 this exception was removed, and libtool now
37715fb4814Smrg      # generates 2 separate objects for the 2 libraries.  These two
378de78e416Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
37915fb4814Smrg      # in $dir$base.o.d.  We have to check for both files, because
38015fb4814Smrg      # one of the two compilations can be disabled.  We should prefer
38115fb4814Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
38215fb4814Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
38315fb4814Smrg      # the former would cause a distcleancheck panic.
38415fb4814Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
38515fb4814Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
38615fb4814Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
38715fb4814Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
38815fb4814Smrg      "$@" -Wc,-MD
38915fb4814Smrg   else
39015fb4814Smrg      tmpdepfile1=$dir$base.o.d
39115fb4814Smrg      tmpdepfile2=$dir$base.d
39215fb4814Smrg      tmpdepfile3=$dir$base.d
39315fb4814Smrg      tmpdepfile4=$dir$base.d
39415fb4814Smrg      "$@" -MD
39515fb4814Smrg   fi
39615fb4814Smrg
39715fb4814Smrg   stat=$?
39815fb4814Smrg   if test $stat -eq 0; then :
39915fb4814Smrg   else
40015fb4814Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
40115fb4814Smrg      exit $stat
40215fb4814Smrg   fi
40315fb4814Smrg
40415fb4814Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
40515fb4814Smrg   do
40615fb4814Smrg     test -f "$tmpdepfile" && break
40715fb4814Smrg   done
40815fb4814Smrg   if test -f "$tmpdepfile"; then
40915fb4814Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
41015fb4814Smrg      # That's a tab and a space in the [].
41115fb4814Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
41215fb4814Smrg   else
41315fb4814Smrg      echo "#dummy" > "$depfile"
41415fb4814Smrg   fi
41515fb4814Smrg   rm -f "$tmpdepfile"
41615fb4814Smrg   ;;
41715fb4814Smrg
418b4d38c65Smrgmsvc7)
419b4d38c65Smrg  if test "$libtool" = yes; then
420b4d38c65Smrg    showIncludes=-Wc,-showIncludes
421b4d38c65Smrg  else
422b4d38c65Smrg    showIncludes=-showIncludes
423b4d38c65Smrg  fi
424b4d38c65Smrg  "$@" $showIncludes > "$tmpdepfile"
425b4d38c65Smrg  stat=$?
426b4d38c65Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
427b4d38c65Smrg  if test "$stat" = 0; then :
428b4d38c65Smrg  else
429b4d38c65Smrg    rm -f "$tmpdepfile"
430b4d38c65Smrg    exit $stat
431b4d38c65Smrg  fi
432b4d38c65Smrg  rm -f "$depfile"
433b4d38c65Smrg  echo "$object : \\" > "$depfile"
434b4d38c65Smrg  # The first sed program below extracts the file names and escapes
435b4d38c65Smrg  # backslashes for cygpath.  The second sed program outputs the file
436b4d38c65Smrg  # name when reading, but also accumulates all include files in the
437b4d38c65Smrg  # hold buffer in order to output them again at the end.  This only
438b4d38c65Smrg  # works with sed implementations that can handle large buffers.
439b4d38c65Smrg  sed < "$tmpdepfile" -n '
440b4d38c65Smrg/^Note: including file:  *\(.*\)/ {
441b4d38c65Smrg  s//\1/
442b4d38c65Smrg  s/\\/\\\\/g
443b4d38c65Smrg  p
444b4d38c65Smrg}' | $cygpath_u | sort -u | sed -n '
445b4d38c65Smrgs/ /\\ /g
446b4d38c65Smrgs/\(.*\)/	\1 \\/p
447b4d38c65Smrgs/.\(.*\) \\/\1:/
448b4d38c65SmrgH
449b4d38c65Smrg$ {
450b4d38c65Smrg  s/.*/	/
451b4d38c65Smrg  G
452b4d38c65Smrg  p
453b4d38c65Smrg}' >> "$depfile"
454b4d38c65Smrg  rm -f "$tmpdepfile"
455b4d38c65Smrg  ;;
456b4d38c65Smrg
457b4d38c65Smrgmsvc7msys)
458b4d38c65Smrg  # This case exists only to let depend.m4 do its work.  It works by
459b4d38c65Smrg  # looking at the text of this script.  This case will never be run,
460b4d38c65Smrg  # since it is checked for above.
461b4d38c65Smrg  exit 1
462b4d38c65Smrg  ;;
463b4d38c65Smrg
46415fb4814Smrg#nosideeffect)
46515fb4814Smrg  # This comment above is used by automake to tell side-effect
46615fb4814Smrg  # dependency tracking mechanisms from slower ones.
46715fb4814Smrg
46815fb4814Smrgdashmstdout)
46915fb4814Smrg  # Important note: in order to support this mode, a compiler *must*
47015fb4814Smrg  # always write the preprocessed file to stdout, regardless of -o.
47115fb4814Smrg  "$@" || exit $?
47215fb4814Smrg
47315fb4814Smrg  # Remove the call to Libtool.
47415fb4814Smrg  if test "$libtool" = yes; then
475b4d38c65Smrg    while test "X$1" != 'X--mode=compile'; do
47615fb4814Smrg      shift
47715fb4814Smrg    done
47815fb4814Smrg    shift
47915fb4814Smrg  fi
48015fb4814Smrg
48115fb4814Smrg  # Remove `-o $object'.
48215fb4814Smrg  IFS=" "
48315fb4814Smrg  for arg
48415fb4814Smrg  do
48515fb4814Smrg    case $arg in
48615fb4814Smrg    -o)
48715fb4814Smrg      shift
48815fb4814Smrg      ;;
48915fb4814Smrg    $object)
49015fb4814Smrg      shift
49115fb4814Smrg      ;;
49215fb4814Smrg    *)
49315fb4814Smrg      set fnord "$@" "$arg"
49415fb4814Smrg      shift # fnord
49515fb4814Smrg      shift # $arg
49615fb4814Smrg      ;;
49715fb4814Smrg    esac
49815fb4814Smrg  done
49915fb4814Smrg
50015fb4814Smrg  test -z "$dashmflag" && dashmflag=-M
50115fb4814Smrg  # Require at least two characters before searching for `:'
50215fb4814Smrg  # in the target name.  This is to cope with DOS-style filenames:
50315fb4814Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
50415fb4814Smrg  "$@" $dashmflag |
50515fb4814Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
50615fb4814Smrg  rm -f "$depfile"
50715fb4814Smrg  cat < "$tmpdepfile" > "$depfile"
50815fb4814Smrg  tr ' ' '
50915fb4814Smrg' < "$tmpdepfile" | \
51015fb4814Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
51115fb4814Smrg## correctly.  Breaking it into two sed invocations is a workaround.
51215fb4814Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
51315fb4814Smrg  rm -f "$tmpdepfile"
51415fb4814Smrg  ;;
51515fb4814Smrg
51615fb4814SmrgdashXmstdout)
51715fb4814Smrg  # This case only exists to satisfy depend.m4.  It is never actually
51815fb4814Smrg  # run, as this mode is specially recognized in the preamble.
51915fb4814Smrg  exit 1
52015fb4814Smrg  ;;
52115fb4814Smrg
52215fb4814Smrgmakedepend)
52315fb4814Smrg  "$@" || exit $?
52415fb4814Smrg  # Remove any Libtool call
52515fb4814Smrg  if test "$libtool" = yes; then
526b4d38c65Smrg    while test "X$1" != 'X--mode=compile'; do
52715fb4814Smrg      shift
52815fb4814Smrg    done
52915fb4814Smrg    shift
53015fb4814Smrg  fi
53115fb4814Smrg  # X makedepend
53215fb4814Smrg  shift
533b4d38c65Smrg  cleared=no eat=no
534b4d38c65Smrg  for arg
535b4d38c65Smrg  do
53615fb4814Smrg    case $cleared in
53715fb4814Smrg    no)
53815fb4814Smrg      set ""; shift
53915fb4814Smrg      cleared=yes ;;
54015fb4814Smrg    esac
541b4d38c65Smrg    if test $eat = yes; then
542b4d38c65Smrg      eat=no
543b4d38c65Smrg      continue
544b4d38c65Smrg    fi
54515fb4814Smrg    case "$arg" in
54615fb4814Smrg    -D*|-I*)
54715fb4814Smrg      set fnord "$@" "$arg"; shift ;;
54815fb4814Smrg    # Strip any option that makedepend may not understand.  Remove
54915fb4814Smrg    # the object too, otherwise makedepend will parse it as a source file.
550b4d38c65Smrg    -arch)
551b4d38c65Smrg      eat=yes ;;
55215fb4814Smrg    -*|$object)
55315fb4814Smrg      ;;
55415fb4814Smrg    *)
55515fb4814Smrg      set fnord "$@" "$arg"; shift ;;
55615fb4814Smrg    esac
55715fb4814Smrg  done
558b4d38c65Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
55915fb4814Smrg  touch "$tmpdepfile"
56015fb4814Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
56115fb4814Smrg  rm -f "$depfile"
562b4d38c65Smrg  # makedepend may prepend the VPATH from the source file name to the object.
563b4d38c65Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
564b4d38c65Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
56515fb4814Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
56615fb4814Smrg' | \
56715fb4814Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
56815fb4814Smrg## correctly.  Breaking it into two sed invocations is a workaround.
56915fb4814Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
57015fb4814Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
57115fb4814Smrg  ;;
57215fb4814Smrg
57315fb4814Smrgcpp)
57415fb4814Smrg  # Important note: in order to support this mode, a compiler *must*
57515fb4814Smrg  # always write the preprocessed file to stdout.
57615fb4814Smrg  "$@" || exit $?
57715fb4814Smrg
57815fb4814Smrg  # Remove the call to Libtool.
57915fb4814Smrg  if test "$libtool" = yes; then
580b4d38c65Smrg    while test "X$1" != 'X--mode=compile'; do
58115fb4814Smrg      shift
58215fb4814Smrg    done
58315fb4814Smrg    shift
58415fb4814Smrg  fi
58515fb4814Smrg
58615fb4814Smrg  # Remove `-o $object'.
58715fb4814Smrg  IFS=" "
58815fb4814Smrg  for arg
58915fb4814Smrg  do
59015fb4814Smrg    case $arg in
59115fb4814Smrg    -o)
59215fb4814Smrg      shift
59315fb4814Smrg      ;;
59415fb4814Smrg    $object)
59515fb4814Smrg      shift
59615fb4814Smrg      ;;
59715fb4814Smrg    *)
59815fb4814Smrg      set fnord "$@" "$arg"
59915fb4814Smrg      shift # fnord
60015fb4814Smrg      shift # $arg
60115fb4814Smrg      ;;
60215fb4814Smrg    esac
60315fb4814Smrg  done
60415fb4814Smrg
60515fb4814Smrg  "$@" -E |
60615fb4814Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
60715fb4814Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
60815fb4814Smrg    sed '$ s: \\$::' > "$tmpdepfile"
60915fb4814Smrg  rm -f "$depfile"
61015fb4814Smrg  echo "$object : \\" > "$depfile"
61115fb4814Smrg  cat < "$tmpdepfile" >> "$depfile"
61215fb4814Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
61315fb4814Smrg  rm -f "$tmpdepfile"
61415fb4814Smrg  ;;
61515fb4814Smrg
61615fb4814Smrgmsvisualcpp)
61715fb4814Smrg  # Important note: in order to support this mode, a compiler *must*
618b4d38c65Smrg  # always write the preprocessed file to stdout.
61915fb4814Smrg  "$@" || exit $?
620b4d38c65Smrg
621b4d38c65Smrg  # Remove the call to Libtool.
622b4d38c65Smrg  if test "$libtool" = yes; then
623b4d38c65Smrg    while test "X$1" != 'X--mode=compile'; do
624b4d38c65Smrg      shift
625b4d38c65Smrg    done
626b4d38c65Smrg    shift
627b4d38c65Smrg  fi
628b4d38c65Smrg
62915fb4814Smrg  IFS=" "
63015fb4814Smrg  for arg
63115fb4814Smrg  do
63215fb4814Smrg    case "$arg" in
633b4d38c65Smrg    -o)
634b4d38c65Smrg      shift
635b4d38c65Smrg      ;;
636b4d38c65Smrg    $object)
637b4d38c65Smrg      shift
638b4d38c65Smrg      ;;
63915fb4814Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
64015fb4814Smrg	set fnord "$@"
64115fb4814Smrg	shift
64215fb4814Smrg	shift
64315fb4814Smrg	;;
64415fb4814Smrg    *)
64515fb4814Smrg	set fnord "$@" "$arg"
64615fb4814Smrg	shift
64715fb4814Smrg	shift
64815fb4814Smrg	;;
64915fb4814Smrg    esac
65015fb4814Smrg  done
651b4d38c65Smrg  "$@" -E 2>/dev/null |
652b4d38c65Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
65315fb4814Smrg  rm -f "$depfile"
65415fb4814Smrg  echo "$object : \\" > "$depfile"
655b4d38c65Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
65615fb4814Smrg  echo "	" >> "$depfile"
657b4d38c65Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
65815fb4814Smrg  rm -f "$tmpdepfile"
65915fb4814Smrg  ;;
66015fb4814Smrg
661b4d38c65Smrgmsvcmsys)
662b4d38c65Smrg  # This case exists only to let depend.m4 do its work.  It works by
663b4d38c65Smrg  # looking at the text of this script.  This case will never be run,
664b4d38c65Smrg  # since it is checked for above.
665b4d38c65Smrg  exit 1
666b4d38c65Smrg  ;;
667b4d38c65Smrg
66815fb4814Smrgnone)
66915fb4814Smrg  exec "$@"
67015fb4814Smrg  ;;
67115fb4814Smrg
67215fb4814Smrg*)
67315fb4814Smrg  echo "Unknown depmode $depmode" 1>&2
67415fb4814Smrg  exit 1
67515fb4814Smrg  ;;
67615fb4814Smrgesac
67715fb4814Smrg
67815fb4814Smrgexit 0
67915fb4814Smrg
68015fb4814Smrg# Local Variables:
68115fb4814Smrg# mode: shell-script
68215fb4814Smrg# sh-indentation: 2
68315fb4814Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
68415fb4814Smrg# time-stamp-start: "scriptversion="
68515fb4814Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
686b4d38c65Smrg# time-stamp-time-zone: "UTC"
687b4d38c65Smrg# time-stamp-end: "; # UTC"
68815fb4814Smrg# End:
689