depcomp revision 1b8adde7ba7d5e04395c141c5400dc2cffd7d809
0N/A#! /bin/sh
0N/A# depcomp - compile a program generating dependencies as side-effects
0N/A
0N/Ascriptversion=2004-05-31.23
0N/A
0N/A# Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
0N/A
0N/A# This program is free software; you can redistribute it and/or modify
0N/A# it under the terms of the GNU General Public License as published by
0N/A# the Free Software Foundation; either version 2, or (at your option)
0N/A# any later version.
0N/A
0N/A# This program is distributed in the hope that it will be useful,
0N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
0N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0N/A# GNU General Public License for more details.
0N/A
0N/A# You should have received a copy of the GNU General Public License
873N/A# along with this program; if not, write to the Free Software
0N/A# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
0N/A# 02111-1307, USA.
0N/A
0N/A# As a special exception to the GNU General Public License, if you
0N/A# distribute this file as part of a program that contains a
3231N/A# configuration script generated by Autoconf, you may include it under
0N/A# the same distribution terms that you use for the rest of that program.
0N/A
0N/A# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
0N/A
0N/Acase $1 in
0N/A '')
0N/A echo "$0: No command. Try \`$0 --help' for more information." 1>&2
0N/A exit 1;
0N/A ;;
0N/A -h | --h*)
2464N/A cat <<\EOF
0N/AUsage: depcomp [--help] [--version] PROGRAM [ARGS]
0N/A
0N/ARun PROGRAMS ARGS to compile a file, generating dependencies
0N/Aas side-effects.
2464N/A
0N/AEnvironment variables:
3853N/A depmode Dependency tracking mode.
0N/A source Source file read by `PROGRAMS ARGS'.
0N/A object Object file output by `PROGRAMS ARGS'.
0N/A DEPDIR directory where to store dependencies.
0N/A depfile Dependency file to output.
868N/A tmpdepfile Temporary file to use when outputing dependencies.
0N/A libtool Whether libtool is used (yes/no).
2464N/A
0N/AReport bugs to <bug-automake@gnu.org>.
1400N/AEOF
0N/A exit 0
0N/A ;;
0N/A -v | --v*)
0N/A echo "depcomp $scriptversion"
0N/A exit 0
0N/A ;;
0N/Aesac
0N/A
0N/Aif test -z "$depmode" || test -z "$source" || test -z "$object"; then
2095N/A echo "depcomp: Variables source, object and depmode must be set" 1>&2
2095N/A exit 1
2095N/Afi
2095N/A
2095N/A# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
2095N/Adepfile=${depfile-`echo "$object" |
0N/A sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1400N/Atmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1400N/A
1400N/Arm -f "$tmpdepfile"
1400N/A
1400N/A# Some modes work just like other modes, but use different flags. We
0N/A# parameterize here, but still list the modes in the big case below,
0N/A# to make depend.m4 easier to write. Note that we *cannot* use a case
0N/A# here, because this file can only contain one case statement.
0N/Aif test "$depmode" = hp; then
0N/A # HP compiler uses -M and no extra arg.
0N/A gccflag=-M
0N/A depmode=gcc
0N/Afi
0N/A
0N/Aif test "$depmode" = dashXmstdout; then
0N/A # This is just like dashmstdout with a different argument.
0N/A dashmflag=-xM
0N/A depmode=dashmstdout
0N/Afi
0N/A
0N/Acase "$depmode" in
0N/Agcc3)
0N/A## gcc 3 implements dependency tracking that does exactly what
0N/A## we want. Yay! Note: for some reason libtool 1.4 doesn't like
0N/A## it if -MD -MP comes after the -MF stuff. Hmm.
0N/A "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
0N/A stat=$?
2464N/A if test $stat -eq 0; then :
0N/A else
0N/A rm -f "$tmpdepfile"
0N/A exit $stat
0N/A fi
0N/A mv "$tmpdepfile" "$depfile"
0N/A ;;
0N/A
0N/Agcc)
0N/A## There are various ways to get dependency output from gcc. Here's
0N/A## why we pick this rather obscure method:
0N/A## - Don't want to use -MD because we'd like the dependencies to end
0N/A## up in a subdir. Having to rename by hand is ugly.
0N/A## (We might end up doing this anyway to support other compilers.)
0N/A## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
0N/A## -MM, not -M (despite what the docs say).
0N/A## - Using -M directly means running the compiler twice (even worse
0N/A## than renaming).
0N/A if test -z "$gccflag"; then
0N/A gccflag=-MD,
0N/A fi
2464N/A "$@" -Wp,"$gccflag$tmpdepfile"
0N/A stat=$?
0N/A if test $stat -eq 0; then :
0N/A else
0N/A rm -f "$tmpdepfile"
0N/A exit $stat
0N/A fi
0N/A rm -f "$depfile"
0N/A echo "$object : \\" > "$depfile"
0N/A alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
0N/A## The second -e expression handles DOS-style file names with drive letters.
0N/A sed -e 's/^[^:]*: / /' \
0N/A -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
0N/A## This next piece of magic avoids the `deleted header file' problem.
0N/A## The problem is that when a header file which appears in a .P file
0N/A## is deleted, the dependency causes make to die (because there is
0N/A## typically no way to rebuild the header). We avoid this by adding
0N/A## dummy dependencies for each header file. Too bad gcc doesn't do
0N/A## this for us directly.
0N/A tr ' ' '
0N/A' < "$tmpdepfile" |
0N/A## Some versions of gcc put a space before the `:'. On the theory
0N/A## that the space means something, we add a space to the output as
0N/A## well.
0N/A## Some versions of the HPUX 10.20 sed can't process this invocation
0N/A## correctly. Breaking it into two sed invocations is a workaround.
0N/A sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
0N/A rm -f "$tmpdepfile"
0N/A ;;
2464N/A
0N/Ahp)
0N/A # This case exists only to let depend.m4 do its work. It works by
0N/A # looking at the text of this script. This case will never be run,
0N/A # since it is checked for above.
0N/A exit 1
0N/A ;;
0N/A
0N/Asgi)
0N/A if test "$libtool" = yes; then
0N/A "$@" "-Wp,-MDupdate,$tmpdepfile"
0N/A else
0N/A "$@" -MDupdate "$tmpdepfile"
0N/A fi
0N/A stat=$?
0N/A if test $stat -eq 0; then :
0N/A else
0N/A rm -f "$tmpdepfile"
0N/A exit $stat
0N/A fi
0N/A rm -f "$depfile"
0N/A
0N/A if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
0N/A echo "$object : \\" > "$depfile"
0N/A
0N/A # Clip off the initial element (the dependent). Don't try to be
0N/A # clever and replace this with sed code, as IRIX sed won't handle
0N/A # lines with more than a fixed number of characters (4096 in
0N/A # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
0N/A # the IRIX cc adds comments like `#:fec' to the end of the
0N/A # dependency line.
0N/A tr ' ' '
0N/A' < "$tmpdepfile" \
0N/A | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
0N/A tr '
0N/A' ' ' >> $depfile
0N/A echo >> $depfile
0N/A
0N/A # The second pass generates a dummy entry for each header file.
0N/A tr ' ' '
0N/A' < "$tmpdepfile" \
0N/A | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
0N/A >> $depfile
0N/A else
0N/A # The sourcefile does not contain any dependencies, so just
0N/A # store a dummy comment line, to avoid errors with the Makefile
0N/A # "include basename.Plo" scheme.
0N/A echo "#dummy" > "$depfile"
0N/A fi
0N/A rm -f "$tmpdepfile"
0N/A ;;
0N/A
0N/Aaix)
0N/A # The C for AIX Compiler uses -M and outputs the dependencies
0N/A # in a .u file. In older versions, this file always lives in the
0N/A # current directory. Also, the AIX compiler puts `$object:' at the
0N/A # start of each line; $object doesn't have directory information.
0N/A # Version 6 uses the directory in both cases.
0N/A stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
0N/A tmpdepfile="$stripped.u"
0N/A if test "$libtool" = yes; then
0N/A "$@" -Wc,-M
0N/A else
0N/A "$@" -M
0N/A fi
0N/A stat=$?
0N/A
0N/A if test -f "$tmpdepfile"; then :
0N/A else
0N/A stripped=`echo "$stripped" | sed 's,^.*/,,'`
0N/A tmpdepfile="$stripped.u"
0N/A fi
0N/A
0N/A if test $stat -eq 0; then :
0N/A else
0N/A rm -f "$tmpdepfile"
0N/A exit $stat
0N/A fi
0N/A
0N/A if test -f "$tmpdepfile"; then
0N/A outname="$stripped.o"
0N/A # Each line is of the form `foo.o: dependent.h'.
0N/A # Do two passes, one to just change these to
0N/A # `$object: dependent.h' and one to simply `dependent.h:'.
0N/A sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
0N/A sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
0N/A else
0N/A # The sourcefile does not contain any dependencies, so just
0N/A # store a dummy comment line, to avoid errors with the Makefile
0N/A # "include basename.Plo" scheme.
0N/A echo "#dummy" > "$depfile"
0N/A fi
0N/A rm -f "$tmpdepfile"
0N/A ;;
0N/A
0N/Aicc)
0N/A # Intel's C compiler understands `-MD -MF file'. However on
0N/A # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
0N/A # ICC 7.0 will fill foo.d with something like
0N/A # foo.o: sub/foo.c
3853N/A # foo.o: sub/foo.h
3853N/A # which is wrong. We want:
3853N/A # sub/foo.o: sub/foo.c
0N/A # sub/foo.o: sub/foo.h
0N/A # sub/foo.c:
3853N/A # sub/foo.h:
3853N/A # ICC 7.1 will output
3853N/A # foo.o: sub/foo.c sub/foo.h
3853N/A # and will wrap long lines using \ :
0N/A # foo.o: sub/foo.c ... \
0N/A # sub/foo.h ... \
0N/A # ...
0N/A
0N/A "$@" -MD -MF "$tmpdepfile"
0N/A stat=$?
0N/A if test $stat -eq 0; then :
0N/A else
0N/A rm -f "$tmpdepfile"
0N/A exit $stat
0N/A fi
0N/A rm -f "$depfile"
0N/A # Each line is of the form `foo.o: dependent.h',
0N/A # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
0N/A # Do two passes, one to just change these to
0N/A # `$object: dependent.h' and one to simply `dependent.h:'.
0N/A sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
0N/A # Some versions of the HPUX 10.20 sed can't process this invocation
0N/A # correctly. Breaking it into two sed invocations is a workaround.
0N/A sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
0N/A sed -e 's/$/ :/' >> "$depfile"
0N/A rm -f "$tmpdepfile"
0N/A ;;
0N/A
0N/Atru64)
0N/A # The Tru64 compiler uses -MD to generate dependencies as a side
0N/A # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
0N/A # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
0N/A # dependencies in `foo.d' instead, so we check for that too.
0N/A # Subdirectories are respected.
0N/A dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
0N/A test "x$dir" = "x$object" && dir=
0N/A base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
0N/A
0N/A if test "$libtool" = yes; then
0N/A # Dependencies are output in .lo.d with libtool 1.4.
0N/A # With libtool 1.5 they are output both in $dir.libs/$base.o.d
0N/A # and in $dir.libs/$base.o.d and $dir$base.o.d. We process the
0N/A # latter, because the former will be cleaned when $dir.libs is
0N/A # erased.
0N/A tmpdepfile1="$dir.libs/$base.lo.d"
0N/A tmpdepfile2="$dir$base.o.d"
0N/A tmpdepfile3="$dir.libs/$base.d"
0N/A "$@" -Wc,-MD
0N/A else
0N/A tmpdepfile1="$dir$base.o.d"
0N/A tmpdepfile2="$dir$base.d"
0N/A tmpdepfile3="$dir$base.d"
0N/A "$@" -MD
0N/A fi
0N/A
0N/A stat=$?
0N/A if test $stat -eq 0; then :
0N/A else
0N/A rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
0N/A exit $stat
0N/A fi
0N/A
0N/A if test -f "$tmpdepfile1"; then
0N/A tmpdepfile="$tmpdepfile1"
0N/A elif test -f "$tmpdepfile2"; then
0N/A tmpdepfile="$tmpdepfile2"
0N/A else
0N/A tmpdepfile="$tmpdepfile3"
0N/A fi
0N/A if test -f "$tmpdepfile"; then
0N/A sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
0N/A # That's a tab and a space in the [].
0N/A sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
0N/A else
0N/A echo "#dummy" > "$depfile"
0N/A fi
0N/A rm -f "$tmpdepfile"
0N/A ;;
0N/A
0N/A#nosideeffect)
0N/A # This comment above is used by automake to tell side-effect
0N/A # dependency tracking mechanisms from slower ones.
0N/A
0N/Adashmstdout)
0N/A # Important note: in order to support this mode, a compiler *must*
0N/A # always write the preprocessed file to stdout, regardless of -o.
0N/A "$@" || exit $?
0N/A
0N/A # Remove the call to Libtool.
0N/A if test "$libtool" = yes; then
0N/A while test $1 != '--mode=compile'; do
0N/A shift
0N/A done
0N/A shift
0N/A fi
0N/A
0N/A # Remove `-o $object'.
0N/A IFS=" "
0N/A for arg
0N/A do
0N/A case $arg in
0N/A -o)
0N/A shift
0N/A ;;
0N/A $object)
2464N/A shift
0N/A ;;
0N/A *)
0N/A set fnord "$@" "$arg"
0N/A shift # fnord
0N/A shift # $arg
0N/A ;;
2086N/A esac
2086N/A done
2086N/A
0N/A test -z "$dashmflag" && dashmflag=-M
0N/A # Require at least two characters before searching for `:'
0N/A # in the target name. This is to cope with DOS-style filenames:
0N/A # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
0N/A "$@" $dashmflag |
0N/A sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
0N/A rm -f "$depfile"
0N/A cat < "$tmpdepfile" > "$depfile"
0N/A tr ' ' '
0N/A' < "$tmpdepfile" | \
0N/A## Some versions of the HPUX 10.20 sed can't process this invocation
0N/A## correctly. Breaking it into two sed invocations is a workaround.
0N/A sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
0N/A rm -f "$tmpdepfile"
0N/A ;;
0N/A
0N/AdashXmstdout)
0N/A # This case only exists to satisfy depend.m4. It is never actually
0N/A # run, as this mode is specially recognized in the preamble.
0N/A exit 1
0N/A ;;
0N/A
2464N/Amakedepend)
0N/A "$@" || exit $?
2464N/A # Remove any Libtool call
0N/A if test "$libtool" = yes; then
2464N/A while test $1 != '--mode=compile'; do
2464N/A shift
2464N/A done
2464N/A shift
2464N/A fi
2464N/A # X makedepend
2464N/A shift
0N/A cleared=no
2464N/A for arg in "$@"; do
2464N/A case $cleared in
2464N/A no)
2464N/A set ""; shift
2464N/A cleared=yes ;;
2464N/A esac
0N/A case "$arg" in
2464N/A -D*|-I*)
2464N/A set fnord "$@" "$arg"; shift ;;
2464N/A # Strip any option that makedepend may not understand. Remove
2464N/A # the object too, otherwise makedepend will parse it as a source file.
2464N/A -*|$object)
2464N/A ;;
2464N/A *)
2464N/A set fnord "$@" "$arg"; shift ;;
868N/A esac
2464N/A done
2464N/A obj_suffix="`echo $object | sed 's/^.*\././'`"
2464N/A touch "$tmpdepfile"
2464N/A ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
0N/A rm -f "$depfile"
2464N/A cat < "$tmpdepfile" > "$depfile"
2464N/A sed '1,2d' "$tmpdepfile" | tr ' ' '
2464N/A' | \
2464N/A## Some versions of the HPUX 10.20 sed can't process this invocation
2464N/A## correctly. Breaking it into two sed invocations is a workaround.
0N/A sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
0N/A rm -f "$tmpdepfile" "$tmpdepfile".bak
0N/A ;;
0N/A
0N/Acpp)
0N/A # Important note: in order to support this mode, a compiler *must*
0N/A # always write the preprocessed file to stdout.
0N/A "$@" || exit $?
0N/A
0N/A # Remove the call to Libtool.
0N/A if test "$libtool" = yes; then
0N/A while test $1 != '--mode=compile'; do
0N/A shift
0N/A done
0N/A shift
0N/A fi
0N/A
0N/A # Remove `-o $object'.
1057N/A IFS=" "
0N/A for arg
0N/A do
0N/A case $arg in
0N/A -o)
0N/A shift
0N/A ;;
0N/A $object)
0N/A shift
0N/A ;;
0N/A *)
0N/A set fnord "$@" "$arg"
0N/A shift # fnord
0N/A shift # $arg
0N/A ;;
0N/A esac
0N/A done
0N/A
0N/A "$@" -E |
0N/A sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
0N/A sed '$ s: \\$::' > "$tmpdepfile"
0N/A rm -f "$depfile"
0N/A echo "$object : \\" > "$depfile"
0N/A cat < "$tmpdepfile" >> "$depfile"
0N/A sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
0N/A rm -f "$tmpdepfile"
0N/A ;;
0N/A
0N/Amsvisualcpp)
0N/A # Important note: in order to support this mode, a compiler *must*
0N/A # always write the preprocessed file to stdout, regardless of -o,
0N/A # because we must use -o when running libtool.
0N/A "$@" || exit $?
0N/A IFS=" "
0N/A for arg
0N/A do
0N/A case "$arg" in
0N/A "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
0N/A set fnord "$@"
0N/A shift
0N/A shift
0N/A ;;
0N/A *)
0N/A set fnord "$@" "$arg"
0N/A shift
0N/A shift
0N/A ;;
0N/A esac
0N/A done
0N/A "$@" -E |
0N/A sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
0N/A rm -f "$depfile"
0N/A echo "$object : \\" > "$depfile"
0N/A . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
0N/A echo " " >> "$depfile"
0N/A . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
0N/A rm -f "$tmpdepfile"
0N/A ;;
0N/A
0N/Anone)
0N/A exec "$@"
0N/A ;;
0N/A
0N/A*)
0N/A echo "Unknown depmode $depmode" 1>&2
0N/A exit 1
0N/A ;;
0N/Aesac
0N/A
0N/Aexit 0
0N/A
0N/A# Local Variables:
0N/A# mode: shell-script
0N/A# sh-indentation: 2
0N/A# eval: (add-hook 'write-file-hooks 'time-stamp)
0N/A# time-stamp-start: "scriptversion="
0N/A# time-stamp-format: "%:y-%02m-%02d.%02H"
0N/A# time-stamp-end: "$"
0N/A# End:
0N/A