Chris@0: #! /bin/sh Chris@0: Chris@0: # depcomp - compile a program generating dependencies as side-effects Chris@0: # Copyright 1999, 2000 Free Software Foundation, Inc. Chris@0: Chris@0: # This program is free software; you can redistribute it and/or modify Chris@0: # it under the terms of the GNU General Public License as published by Chris@0: # the Free Software Foundation; either version 2, or (at your option) Chris@0: # any later version. Chris@0: Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA Chris@0: # 02111-1307, USA. Chris@0: Chris@0: # As a special exception to the GNU General Public License, if you Chris@0: # distribute this file as part of a program that contains a Chris@0: # configuration script generated by Autoconf, you may include it under Chris@0: # the same distribution terms that you use for the rest of that program. Chris@0: Chris@0: # Originally written by Alexandre Oliva . Chris@0: Chris@0: if test -z "$depmode" || test -z "$source" || test -z "$object"; then Chris@0: echo "depcomp: Variables source, object and depmode must be set" 1>&2 Chris@0: exit 1 Chris@0: fi Chris@0: # `libtool' can also be set to `yes' or `no'. Chris@0: Chris@0: if test -z "$depfile"; then Chris@0: base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'` Chris@0: dir=`echo "$object" | sed 's,/.*$,/,'` Chris@0: if test "$dir" = "$object"; then Chris@0: dir= Chris@0: fi Chris@0: # FIXME: should be _deps on DOS. Chris@0: depfile="$dir.deps/$base" Chris@0: fi Chris@0: Chris@0: tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} Chris@0: Chris@0: rm -f "$tmpdepfile" Chris@0: Chris@0: # Some modes work just like other modes, but use different flags. We Chris@0: # parameterize here, but still list the modes in the big case below, Chris@0: # to make depend.m4 easier to write. Note that we *cannot* use a case Chris@0: # here, because this file can only contain one case statement. Chris@0: if test "$depmode" = hp; then Chris@0: # HP compiler uses -M and no extra arg. Chris@0: gccflag=-M Chris@0: depmode=gcc Chris@0: fi Chris@0: Chris@0: if test "$depmode" = dashXmstdout; then Chris@0: # This is just like dashmstdout with a different argument. Chris@0: dashmflag=-xM Chris@0: depmode=dashmstdout Chris@0: fi Chris@0: Chris@0: case "$depmode" in Chris@0: gcc3) Chris@0: ## gcc 3 implements dependency tracking that does exactly what Chris@0: ## we want. Yay! Note: for some reason libtool 1.4 doesn't like Chris@0: ## it if -MD -MP comes after the -MF stuff. Hmm. Chris@0: "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" Chris@0: stat=$? Chris@0: if test $stat -eq 0; then : Chris@0: else Chris@0: rm -f "$tmpdepfile" Chris@0: exit $stat Chris@0: fi Chris@0: mv "$tmpdepfile" "$depfile" Chris@0: ;; Chris@0: Chris@0: gcc) Chris@0: ## There are various ways to get dependency output from gcc. Here's Chris@0: ## why we pick this rather obscure method: Chris@0: ## - Don't want to use -MD because we'd like the dependencies to end Chris@0: ## up in a subdir. Having to rename by hand is ugly. Chris@0: ## (We might end up doing this anyway to support other compilers.) Chris@0: ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like Chris@0: ## -MM, not -M (despite what the docs say). Chris@0: ## - Using -M directly means running the compiler twice (even worse Chris@0: ## than renaming). Chris@0: if test -z "$gccflag"; then Chris@0: gccflag=-MD, Chris@0: fi Chris@0: "$@" -Wp,"$gccflag$tmpdepfile" Chris@0: stat=$? Chris@0: if test $stat -eq 0; then : Chris@0: else Chris@0: rm -f "$tmpdepfile" Chris@0: exit $stat Chris@0: fi Chris@0: rm -f "$depfile" Chris@0: echo "$object : \\" > "$depfile" Chris@0: alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz Chris@0: ## The second -e expression handles DOS-style file names with drive letters. Chris@0: sed -e 's/^[^:]*: / /' \ Chris@0: -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" Chris@0: ## This next piece of magic avoids the `deleted header file' problem. Chris@0: ## The problem is that when a header file which appears in a .P file Chris@0: ## is deleted, the dependency causes make to die (because there is Chris@0: ## typically no way to rebuild the header). We avoid this by adding Chris@0: ## dummy dependencies for each header file. Too bad gcc doesn't do Chris@0: ## this for us directly. Chris@0: tr ' ' ' Chris@0: ' < "$tmpdepfile" | Chris@0: ## Some versions of gcc put a space before the `:'. On the theory Chris@0: ## that the space means something, we add a space to the output as Chris@0: ## well. Chris@0: ## Some versions of the HPUX 10.20 sed can't process this invocation Chris@0: ## correctly. Breaking it into two sed invocations is a workaround. Chris@0: sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" Chris@0: rm -f "$tmpdepfile" Chris@0: ;; Chris@0: Chris@0: hp) Chris@0: # This case exists only to let depend.m4 do its work. It works by Chris@0: # looking at the text of this script. This case will never be run, Chris@0: # since it is checked for above. Chris@0: exit 1 Chris@0: ;; Chris@0: Chris@0: sgi) Chris@0: if test "$libtool" = yes; then Chris@0: "$@" "-Wp,-MDupdate,$tmpdepfile" Chris@0: else Chris@0: "$@" -MDupdate "$tmpdepfile" Chris@0: fi Chris@0: stat=$? Chris@0: if test $stat -eq 0; then : Chris@0: else Chris@0: rm -f "$tmpdepfile" Chris@0: exit $stat Chris@0: fi Chris@0: rm -f "$depfile" Chris@0: Chris@0: if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files Chris@0: echo "$object : \\" > "$depfile" Chris@0: Chris@0: # Clip off the initial element (the dependent). Don't try to be Chris@0: # clever and replace this with sed code, as IRIX sed won't handle Chris@0: # lines with more than a fixed number of characters (4096 in Chris@0: # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; Chris@0: # the IRIX cc adds comments like `#:fec' to the end of the Chris@0: # dependency line. Chris@0: tr ' ' ' Chris@0: ' < "$tmpdepfile" \ Chris@0: | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ Chris@0: tr ' Chris@0: ' ' ' >> $depfile Chris@0: echo >> $depfile Chris@0: Chris@0: # The second pass generates a dummy entry for each header file. Chris@0: tr ' ' ' Chris@0: ' < "$tmpdepfile" \ Chris@0: | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ Chris@0: >> $depfile Chris@0: else Chris@0: # The sourcefile does not contain any dependencies, so just Chris@0: # store a dummy comment line, to avoid errors with the Makefile Chris@0: # "include basename.Plo" scheme. Chris@0: echo "#dummy" > "$depfile" Chris@0: fi Chris@0: rm -f "$tmpdepfile" Chris@0: ;; Chris@0: Chris@0: aix) Chris@0: # The C for AIX Compiler uses -M and outputs the dependencies Chris@0: # in a .u file. This file always lives in the current directory. Chris@0: # Also, the AIX compiler puts `$object:' at the start of each line; Chris@0: # $object doesn't have directory information. Chris@0: stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'` Chris@0: tmpdepfile="$stripped.u" Chris@0: outname="$stripped.o" Chris@0: if test "$libtool" = yes; then Chris@0: "$@" -Wc,-M Chris@0: else Chris@0: "$@" -M Chris@0: fi Chris@0: Chris@0: stat=$? Chris@0: if test $stat -eq 0; then : Chris@0: else Chris@0: rm -f "$tmpdepfile" Chris@0: exit $stat Chris@0: fi Chris@0: Chris@0: if test -f "$tmpdepfile"; then Chris@0: # Each line is of the form `foo.o: dependent.h'. Chris@0: # Do two passes, one to just change these to Chris@0: # `$object: dependent.h' and one to simply `dependent.h:'. Chris@0: sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" Chris@0: sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" Chris@0: else Chris@0: # The sourcefile does not contain any dependencies, so just Chris@0: # store a dummy comment line, to avoid errors with the Makefile Chris@0: # "include basename.Plo" scheme. Chris@0: echo "#dummy" > "$depfile" Chris@0: fi Chris@0: rm -f "$tmpdepfile" Chris@0: ;; Chris@0: Chris@0: icc) Chris@0: # Must come before tru64. Chris@0: Chris@0: # Intel's C compiler understands `-MD -MF file'. However Chris@0: # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c Chris@0: # will fill foo.d with something like Chris@0: # foo.o: sub/foo.c Chris@0: # foo.o: sub/foo.h Chris@0: # which is wrong. We want: Chris@0: # sub/foo.o: sub/foo.c Chris@0: # sub/foo.o: sub/foo.h Chris@0: # sub/foo.c: Chris@0: # sub/foo.h: Chris@0: Chris@0: "$@" -MD -MF "$tmpdepfile" Chris@0: stat=$? Chris@0: if test $stat -eq 0; then : Chris@0: else Chris@0: rm -f "$tmpdepfile" Chris@0: exit $stat Chris@0: fi Chris@0: rm -f "$depfile" Chris@0: # Each line is of the form `foo.o: dependent.h'. Chris@0: # Do two passes, one to just change these to Chris@0: # `$object: dependent.h' and one to simply `dependent.h:'. Chris@0: sed -e "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" Chris@0: sed -e "s,^[^:]*: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" Chris@0: rm -f "$tmpdepfile" Chris@0: ;; Chris@0: Chris@0: tru64) Chris@0: # The Tru64 compiler uses -MD to generate dependencies as a side Chris@0: # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. Chris@0: # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put Chris@0: # dependencies in `foo.d' instead, so we check for that too. Chris@0: # Subdirectories are respected. Chris@0: dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` Chris@0: test "x$dir" = "x$object" && dir= Chris@0: base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` Chris@0: Chris@0: if test "$libtool" = yes; then Chris@0: tmpdepfile1="$dir.libs/$base.lo.d" Chris@0: tmpdepfile2="$dir.libs/$base.d" Chris@0: "$@" -Wc,-MD Chris@0: else Chris@0: tmpdepfile1="$dir$base.o.d" Chris@0: tmpdepfile2="$dir$base.d" Chris@0: "$@" -MD Chris@0: fi Chris@0: Chris@0: stat=$? Chris@0: if test $stat -eq 0; then : Chris@0: else Chris@0: rm -f "$tmpdepfile1" "$tmpdepfile2" Chris@0: exit $stat Chris@0: fi Chris@0: Chris@0: if test -f "$tmpdepfile1"; then Chris@0: tmpdepfile="$tmpdepfile1" Chris@0: else Chris@0: tmpdepfile="$tmpdepfile2" Chris@0: fi Chris@0: if test -f "$tmpdepfile"; then Chris@0: sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" Chris@0: # That's a space and a tab in the []. Chris@0: sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" Chris@0: else Chris@0: echo "#dummy" > "$depfile" Chris@0: fi Chris@0: rm -f "$tmpdepfile" Chris@0: ;; Chris@0: Chris@0: #nosideeffect) Chris@0: # This comment above is used by automake to tell side-effect Chris@0: # dependency tracking mechanisms from slower ones. Chris@0: Chris@0: dashmstdout) Chris@0: # Important note: in order to support this mode, a compiler *must* Chris@0: # always write the proprocessed file to stdout, regardless of -o. Chris@0: "$@" || exit $? Chris@0: Chris@0: # Remove the call to Libtool. Chris@0: if test "$libtool" = yes; then Chris@0: while test $1 != '--mode=compile'; do Chris@0: shift Chris@0: done Chris@0: shift Chris@0: fi Chris@0: Chris@0: # Remove `-o $object'. Chris@0: IFS=" " Chris@0: for arg Chris@0: do Chris@0: case $arg in Chris@0: -o) Chris@0: shift Chris@0: ;; Chris@0: $object) Chris@0: shift Chris@0: ;; Chris@0: *) Chris@0: set fnord "$@" "$arg" Chris@0: shift # fnord Chris@0: shift # $arg Chris@0: ;; Chris@0: esac Chris@0: done Chris@0: Chris@0: test -z "$dashmflag" && dashmflag=-M Chris@0: # Require at least two characters before searching for `:' Chris@0: # in the target name. This is to cope with DOS-style filenames: Chris@0: # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise. Chris@0: "$@" $dashmflag | Chris@0: sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" Chris@0: rm -f "$depfile" Chris@0: cat < "$tmpdepfile" > "$depfile" Chris@0: tr ' ' ' Chris@0: ' < "$tmpdepfile" | \ Chris@0: ## Some versions of the HPUX 10.20 sed can't process this invocation Chris@0: ## correctly. Breaking it into two sed invocations is a workaround. Chris@0: sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" Chris@0: rm -f "$tmpdepfile" Chris@0: ;; Chris@0: Chris@0: dashXmstdout) Chris@0: # This case only exists to satisfy depend.m4. It is never actually Chris@0: # run, as this mode is specially recognized in the preamble. Chris@0: exit 1 Chris@0: ;; Chris@0: Chris@0: makedepend) Chris@0: "$@" || exit $? Chris@0: # Remove any Libtool call Chris@0: if test "$libtool" = yes; then Chris@0: while test $1 != '--mode=compile'; do Chris@0: shift Chris@0: done Chris@0: shift Chris@0: fi Chris@0: # X makedepend Chris@0: shift Chris@0: cleared=no Chris@0: for arg in "$@"; do Chris@0: case $cleared in Chris@0: no) Chris@0: set ""; shift Chris@0: cleared=yes ;; Chris@0: esac Chris@0: case "$arg" in Chris@0: -D*|-I*) Chris@0: set fnord "$@" "$arg"; shift ;; Chris@0: # Strip any option that makedepend may not understand. Remove Chris@0: # the object too, otherwise makedepend will parse it as a source file. Chris@0: -*|$object) Chris@0: ;; Chris@0: *) Chris@0: set fnord "$@" "$arg"; shift ;; Chris@0: esac Chris@0: done Chris@0: obj_suffix="`echo $object | sed 's/^.*\././'`" Chris@0: touch "$tmpdepfile" Chris@0: ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" Chris@0: rm -f "$depfile" Chris@0: cat < "$tmpdepfile" > "$depfile" Chris@0: sed '1,2d' "$tmpdepfile" | tr ' ' ' Chris@0: ' | \ Chris@0: ## Some versions of the HPUX 10.20 sed can't process this invocation Chris@0: ## correctly. Breaking it into two sed invocations is a workaround. Chris@0: sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" Chris@0: rm -f "$tmpdepfile" "$tmpdepfile".bak Chris@0: ;; Chris@0: Chris@0: cpp) Chris@0: # Important note: in order to support this mode, a compiler *must* Chris@0: # always write the proprocessed file to stdout. Chris@0: "$@" || exit $? Chris@0: Chris@0: # Remove the call to Libtool. Chris@0: if test "$libtool" = yes; then Chris@0: while test $1 != '--mode=compile'; do Chris@0: shift Chris@0: done Chris@0: shift Chris@0: fi Chris@0: Chris@0: # Remove `-o $object'. Chris@0: IFS=" " Chris@0: for arg Chris@0: do Chris@0: case $arg in Chris@0: -o) Chris@0: shift Chris@0: ;; Chris@0: $object) Chris@0: shift Chris@0: ;; Chris@0: *) Chris@0: set fnord "$@" "$arg" Chris@0: shift # fnord Chris@0: shift # $arg Chris@0: ;; Chris@0: esac Chris@0: done Chris@0: Chris@0: "$@" -E | Chris@0: sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | Chris@0: sed '$ s: \\$::' > "$tmpdepfile" Chris@0: rm -f "$depfile" Chris@0: echo "$object : \\" > "$depfile" Chris@0: cat < "$tmpdepfile" >> "$depfile" Chris@0: sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" Chris@0: rm -f "$tmpdepfile" Chris@0: ;; Chris@0: Chris@0: msvisualcpp) Chris@0: # Important note: in order to support this mode, a compiler *must* Chris@0: # always write the proprocessed file to stdout, regardless of -o, Chris@0: # because we must use -o when running libtool. Chris@0: "$@" || exit $? Chris@0: IFS=" " Chris@0: for arg Chris@0: do Chris@0: case "$arg" in Chris@0: "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") Chris@0: set fnord "$@" Chris@0: shift Chris@0: shift Chris@0: ;; Chris@0: *) Chris@0: set fnord "$@" "$arg" Chris@0: shift Chris@0: shift Chris@0: ;; Chris@0: esac Chris@0: done Chris@0: "$@" -E | Chris@0: sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" Chris@0: rm -f "$depfile" Chris@0: echo "$object : \\" > "$depfile" Chris@0: . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" Chris@0: echo " " >> "$depfile" Chris@0: . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" Chris@0: rm -f "$tmpdepfile" Chris@0: ;; Chris@0: Chris@0: none) Chris@0: exec "$@" Chris@0: ;; Chris@0: Chris@0: *) Chris@0: echo "Unknown depmode $depmode" 1>&2 Chris@0: exit 1 Chris@0: ;; Chris@0: esac Chris@0: Chris@0: exit 0