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