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