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