depcomp revision 1
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding# depcomp - compile a program generating dependencies as side-effects
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# This program is free software; you can redistribute it and/or modify
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd# it under the terms of the GNU General Public License as published by
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd# the Free Software Foundation; either version 2, or (at your option)
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd# any later version.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd# 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.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# You should have received a copy of the GNU General Public License
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# along with this program; if not, write to the Free Software
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# 02111-1307, USA.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# As a special exception to the GNU General Public License, if you
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# distribute this file as part of a program that contains a
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# configuration script generated by Autoconf, you may include it under
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# the same distribution terms that you use for the rest of that program.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding echo "$0: No command. Try \`$0 --help' for more information." 1>&2
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingRun 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
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding 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
4192c91889a84b18aec0b046a94a2b2863be204cstoddard# here, because this file can only contain one case statement.
b6055b7832a0e4d0818416252fff5925aaebae4brbb # This is just like dashmstdout with a different argument.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding## gcc 3 implements dependency tracking that does exactly what
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding## we want. Yay! Note: for some reason libtool 1.4 doesn't like
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding## it if -MD -MP comes after the -MF stuff. Hmm.
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein if test $stat -eq 0; then :
84854ca5d35fb9f101da948858097c88457eece8coar## There are various ways to get dependency output from gcc. Here's
84854ca5d35fb9f101da948858097c88457eece8coar## 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.)
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard## - 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
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp## than renaming).
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if test $stat -eq 0; then :
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar## The second -e expression handles DOS-style file names with drive letters.
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar## This next piece of magic avoids the `deleted header file' problem.
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar## The problem is that when a header file which appears in a .P file
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar## is deleted, the dependency causes make to die (because there is
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar## typically no way to rebuild the header). We avoid this by adding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm## dummy dependencies for each header file. Too bad gcc doesn't do
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding## this for us directly.
066877f1a045103acfdd376d48cdd473c33f409bdougm## Some versions of gcc put a space before the `:'. On the theory
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding## 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
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm## correctly. Breaking it into two sed invocations is a workaround.
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar # This case exists only to let depend.m4 do its work. It works by
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar # looking at the text of this script. This case will never be run,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if test $stat -eq 0; then :
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard # Clip off the initial element (the dependent). Don't try to be
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard # clever and replace this with sed code, as IRIX sed won't handle
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard # lines with more than a fixed number of characters (4096 in
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard # the IRIX cc adds comments like `#:fec' to the end of the
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp # The second pass generates a dummy entry for each header file.
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp # The sourcefile does not contain any dependencies, so just
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp # store a dummy comment line, to avoid errors with the Makefile
6a3b299491bf7f9ba09b943b7238b170111b69ccnd # The C for AIX Compiler uses -M and outputs the dependencies
6a3b299491bf7f9ba09b943b7238b170111b69ccnd # in a .u file. In older versions, this file always lives in the
6a3b299491bf7f9ba09b943b7238b170111b69ccnd # current directory. Also, the AIX compiler puts `$object:' at the
6a3b299491bf7f9ba09b943b7238b170111b69ccnd # start of each line; $object doesn't have directory information.
baa9f185fdeb3034b62691b9e0ac5a46a064b5f3nd if test $stat -eq 0; then :
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp # `$object: dependent.h' and one to simply `dependent.h:'.
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
6a3b299491bf7f9ba09b943b7238b170111b69ccnd sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp # The sourcefile does not contain any dependencies, so just
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp # store a dummy comment line, to avoid errors with the Makefile
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp # Intel's C compiler understands `-MD -MF file'. However on
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if test $stat -eq 0; then :
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar # `$object: dependent.h' and one to simply `dependent.h:'.
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard # Some versions of the HPUX 10.20 sed can't process this invocation
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar # correctly. Breaking it into two sed invocations is a workaround.
b4a6dfb838d9820516bbca38bd466fca7d31809bcoar sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
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'.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding # 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$//'`
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard # Dependencies are output in .lo.d with libtool 1.4.
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard # With libtool 1.5 they are output both in $dir.libs/$base.o.d
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard # and in $dir.libs/$base.o.d and $dir$base.o.d. We process the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding # latter, because the former will be cleaned when $dir.libs is
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard if test $stat -eq 0; then :
ba6c07204bd224fa5d4cd0e6b8bf256d6daffb74nd sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
d312e7ba70aeb1594af9f3271e4802a6f48a3c4bbrianp sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard#nosideeffect)
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard # This comment above is used by automake to tell side-effect
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard # Important note: in order to support this mode, a compiler *must*
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard # always write the preprocessed file to stdout, regardless of -o.
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard # Require at least two characters before searching for `:'
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard # in the target name. This is to cope with DOS-style filenames:
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding## Some versions of the HPUX 10.20 sed can't process this invocation
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard## correctly. Breaking it into two sed invocations is a workaround.
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding # This case only exists to satisfy depend.m4. It is never actually
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding # run, as this mode is specially recognized in the preamble.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding # Strip any option that makedepend may not understand. Remove
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding # 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"
d6d558e3b9da8a69f7a990987a2636a2a37e7802nd # Important note: in order to support this mode, a compiler *must*
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding # Important note: in order to support this mode, a compiler *must*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding # always write the preprocessed file to stdout, regardless of -o,
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
34da94d6797f36c17df72a559d9a25435ac0d6f3stoddard . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
d6d558e3b9da8a69f7a990987a2636a2a37e7802nd# Local Variables:
d4f351074a8f7af5e41aa0a70410816436608e3dianh# mode: shell-script
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard# sh-indentation: 2
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard# eval: (add-hook 'write-file-hooks 'time-stamp)
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard# time-stamp-start: "scriptversion="
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard# time-stamp-format: "%:y-%02m-%02d.%02H"
0e53795adff9a7b18ac2db4a87ed2c60e063672cstoddard# time-stamp-end: "$"