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