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