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