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