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