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