depcomp revision 38ae7e4efe803ea78b6499cd05a394db32623e41
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# depcomp - compile a program generating dependencies as side-effects
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# Foundation, Inc.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# This program is free software; you can redistribute it and/or modify
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# it under the terms of the GNU General Public License as published by
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# the Free Software Foundation; either version 2, or (at your option)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# any later version.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# This program is distributed in the hope that it will be useful,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# but WITHOUT ANY WARRANTY; without even the implied warranty of
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# GNU General Public License for more details.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# You should have received a copy of the GNU General Public License
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# along with this program; if not, write to the Free Software
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# 02110-1301, USA.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# As a special exception to the GNU General Public License, if you
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# distribute this file as part of a program that contains a
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# configuration script generated by Autoconf, you may include it under
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# the same distribution terms that you use for the rest of that program.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync echo "$0: No command. Try \`$0 --help' for more information." 1>&2
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncRun PROGRAMS ARGS to compile a file, generating dependencies
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync tmpdepfile Temporary file to use when outputing dependencies.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncif test -z "$depmode" || test -z "$source" || test -z "$object"; then
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync echo "depcomp: Variables source, object and depmode must be set" 1>&2
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsynctmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# Some modes work just like other modes, but use different flags. We
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# parameterize here, but still list the modes in the big case below,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# to make depend.m4 easier to write. Note that we *cannot* use a case
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# here, because this file can only contain one case statement.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # This is just like dashmstdout with a different argument.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## gcc 3 implements dependency tracking that does exactly what
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## we want. Yay! Note: for some reason libtool 1.4 doesn't like
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## it if -MD -MP comes after the -MF stuff. Hmm.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## Unfortunately, FreeBSD c89 acceptance of flags depends upon
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## the command line argument order; so add the flags where they
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## appear in depend2.am. Note that the slowdown incurred here
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## affects only configure: in makefiles, %FASTDEP% shortcuts this.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if test $stat -eq 0; then :
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## There are various ways to get dependency output from gcc. Here's
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## why we pick this rather obscure method:
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## - Don't want to use -MD because we'd like the dependencies to end
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## up in a subdir. Having to rename by hand is ugly.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## (We might end up doing this anyway to support other compilers.)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## -MM, not -M (despite what the docs say).
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## - Using -M directly means running the compiler twice (even worse
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## than renaming).
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if test $stat -eq 0; then :
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## The second -e expression handles DOS-style file names with drive letters.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## This next piece of magic avoids the `deleted header file' problem.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## The problem is that when a header file which appears in a .P file
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## is deleted, the dependency causes make to die (because there is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## typically no way to rebuild the header). We avoid this by adding
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## dummy dependencies for each header file. Too bad gcc doesn't do
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## this for us directly.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## Some versions of gcc put a space before the `:'. On the theory
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## that the space means something, we add a space to the output as
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## Some versions of the HPUX 10.20 sed can't process this invocation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## correctly. Breaking it into two sed invocations is a workaround.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # This case exists only to let depend.m4 do its work. It works by
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # looking at the text of this script. This case will never be run,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if test $stat -eq 0; then :
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # Clip off the initial element (the dependent). Don't try to be
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # clever and replace this with sed code, as IRIX sed won't handle
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # lines with more than a fixed number of characters (4096 in
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # the IRIX cc adds comments like `#:fec' to the end of the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # The second pass generates a dummy entry for each header file.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # The sourcefile does not contain any dependencies, so just
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # store a dummy comment line, to avoid errors with the Makefile
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # The C for AIX Compiler uses -M and outputs the dependencies
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # in a .u file. In older versions, this file always lives in the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # current directory. Also, the AIX compiler puts `$object:' at the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # start of each line; $object doesn't have directory information.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if test $stat -eq 0; then :
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # `$object: dependent.h' and one to simply `dependent.h:'.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # The sourcefile does not contain any dependencies, so just
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # store a dummy comment line, to avoid errors with the Makefile
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # Intel's C compiler understands `-MD -MF file'. However on
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if test $stat -eq 0; then :
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # `$object: dependent.h' and one to simply `dependent.h:'.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # Some versions of the HPUX 10.20 sed can't process this invocation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # correctly. Breaking it into two sed invocations is a workaround.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # compilers, which have integrated preprocessors. The correct option
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # to use with these is +Maked; it writes dependencies to a file named
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # 'foo.d', which lands next to the object file, wherever that
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # Much of this is similar to the tru64 case; see comments there.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if test $stat -eq 0; then :
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # The Tru64 compiler uses -MD to generate dependencies as a side
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # dependencies in `foo.d' instead, so we check for that too.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # With Tru64 cc, shared objects can also be used to make a
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # static library. This mechanism is used in libtool 1.4 series to
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # handle both shared and static libraries in a single compilation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # With libtool 1.5 this exception was removed, and libtool now
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # generates 2 separate objects for the 2 libraries. These two
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # compilations output dependencies in $dir.libs/$base.o.d and
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # in $dir$base.o.d. We have to check for both files, because
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # one of the two compilations can be disabled. We should prefer
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # automatically cleaned when .libs/ is deleted, while ignoring
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if test $stat -eq 0; then :
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#nosideeffect)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # This comment above is used by automake to tell side-effect
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # Important note: in order to support this mode, a compiler *must*
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # always write the preprocessed file to stdout, regardless of -o.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # Require at least two characters before searching for `:'
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # in the target name. This is to cope with DOS-style filenames:
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## Some versions of the HPUX 10.20 sed can't process this invocation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## correctly. Breaking it into two sed invocations is a workaround.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # This case only exists to satisfy depend.m4. It is never actually
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # run, as this mode is specially recognized in the preamble.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # Strip any option that makedepend may not understand. Remove
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # the object too, otherwise makedepend will parse it as a source file.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## Some versions of the HPUX 10.20 sed can't process this invocation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync## correctly. Breaking it into two sed invocations is a workaround.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # Important note: in order to support this mode, a compiler *must*
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # Important note: in order to support this mode, a compiler *must*
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync # always write the preprocessed file to stdout, regardless of -o,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# Local Variables:
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# mode: shell-script
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# sh-indentation: 2
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# eval: (add-hook 'write-file-hooks 'time-stamp)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# time-stamp-start: "scriptversion="
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# time-stamp-format: "%:y-%02m-%02d.%02H"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync# time-stamp-end: "$"