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