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