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