3 # depcomp - compile a program generating dependencies as side-effects
4 # Copyright 1999, 2000 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
23 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
24 echo "depcomp: Variables source, object and depmode must be set" 1>&2
27 # `libtool' can also be set to `yes' or `no'.
29 depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
30 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
34 # Some modes work just like other modes, but use different flags. We
35 # parameterize here, but still list the modes in the big case below,
36 # to make depend.m4 easier to write. Note that we *cannot* use a case
37 # here, because this file can only contain one case statement.
38 if test "$depmode" = hp; then
39 # HP compiler uses -M and no extra arg.
44 if test "$depmode" = dashXmstdout; then
45 # This is just like dashmstdout with a different argument.
52 ## gcc 3 implements dependency tracking that does exactly what
54 "$@" -MT "$object" -MF "$tmpdepfile" -MD -MP
56 if test $stat -eq 0; then :
61 mv "$tmpdepfile" "$depfile"
65 ## There are various ways to get dependency output from gcc. Here's
66 ## why we pick this rather obscure method:
67 ## - Don't want to use -MD because we'd like the dependencies to end
68 ## up in a subdir. Having to rename by hand is ugly.
69 ## (We might end up doing this anyway to support other compilers.)
70 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
71 ## -MM, not -M (despite what the docs say).
72 ## - Using -M directly means running the compiler twice (even worse
74 if test -z "$gccflag"; then
77 "$@" -Wp,"$gccflag$tmpdepfile"
79 if test $stat -eq 0; then :
85 echo "$object : \\" > "$depfile"
86 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
87 ## The second -e expression handles DOS-style file names with drive letters.
88 sed -e 's/^[^:]*: / /' \
89 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
90 ## This next piece of magic avoids the `deleted header file' problem.
91 ## The problem is that when a header file which appears in a .P file
92 ## is deleted, the dependency causes make to die (because there is
93 ## typically no way to rebuild the header). We avoid this by adding
94 ## dummy dependencies for each header file. Too bad gcc doesn't do
95 ## this for us directly.
98 ## Some versions of gcc put a space before the `:'. On the theory
99 ## that the space means something, we add a space to the output as
101 ## Some versions of the HPUX 10.20 sed can't process this invocation
102 ## correctly. Breaking it into two sed invocations is a workaround.
103 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
108 # This case exists only to let depend.m4 do its work. It works by
109 # looking at the text of this script. This case will never be run,
110 # since it is checked for above.
115 if test "$libtool" = yes; then
116 "$@" "-Wp,-MDupdate,$tmpdepfile"
118 "$@" -MDupdate "$tmpdepfile"
121 if test $stat -eq 0; then :
128 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
129 echo "$object : \\" > "$depfile"
131 # Clip off the initial element (the dependent). Don't try to be
132 # clever and replace this with sed code, as IRIX sed won't handle
133 # lines with more than a fixed number of characters (4096 in
134 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
135 # the IRIX cc adds comments like `#:fec' to the end of the
139 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
144 # The second pass generates a dummy entry for each header file.
147 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
150 # The sourcefile does not contain any dependencies, so just
151 # store a dummy comment line, to avoid errors with the Makefile
152 # "include basename.Plo" scheme.
153 echo "#dummy" > "$depfile"
159 # The C for AIX Compiler uses -M and outputs the dependencies
160 # in a .u file. This file always lives in the current directory.
161 # Also, the AIX compiler puts `$object:' at the start of each line;
162 # $object doesn't have directory information.
163 stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
164 tmpdepfile="$stripped.u"
165 outname="$stripped.o"
166 if test "$libtool" = yes; then
173 if test $stat -eq 0; then :
179 if test -f "$tmpdepfile"; then
180 # Each line is of the form `foo.o: dependent.h'.
181 # Do two passes, one to just change these to
182 # `$object: dependent.h' and one to simply `dependent.h:'.
183 sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
184 sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
186 # The sourcefile does not contain any dependencies, so just
187 # store a dummy comment line, to avoid errors with the Makefile
188 # "include basename.Plo" scheme.
189 echo "#dummy" > "$depfile"
195 # The Tru64 AIX compiler uses -MD to generate dependencies as a side
196 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
197 # Subdirectories are respected.
199 tmpdepfile="$object.d"
200 if test "$libtool" = yes; then
207 if test $stat -eq 0; then :
213 if test -f "$tmpdepfile"; then
214 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
215 # That's a space and a tab in the [].
216 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
218 echo "#dummy" > "$depfile"
224 # This comment above is used by automake to tell side-effect
225 # dependency tracking mechanisms from slower ones.
228 # Important note: in order to support this mode, a compiler *must*
229 # always write the proprocessed file to stdout, regardless of -o,
230 # because we must use -o when running libtool.
231 test -z "$dashmflag" && dashmflag=-M
234 *" --mode=compile "*) # this is libtool, let us make it quiet
236 do # cycle over the arguments
239 # insert --quiet before "--mode=compile"
240 set fnord "$@" --quiet
244 set fnord "$@" "$arg"
250 "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
256 if test "$stat" != 0; then exit $stat; fi
258 cat < "$tmpdepfile" > "$depfile"
260 ' < "$tmpdepfile" | \
261 ## Some versions of the HPUX 10.20 sed can't process this invocation
262 ## correctly. Breaking it into two sed invocations is a workaround.
263 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
268 # This case only exists to satisfy depend.m4. It is never actually
269 # run, as this mode is specially recognized in the preamble.
285 set fnord "$@" "$arg"; shift;;
289 set fnord "$@" "$arg"; shift;;
292 obj_suffix="`echo $object | sed 's/^.*\././'`"
294 ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
300 if test "$stat" != 0; then exit $stat; fi
302 cat < "$tmpdepfile" > "$depfile"
303 tail +3 "$tmpdepfile" | tr ' ' '
305 ## Some versions of the HPUX 10.20 sed can't process this invocation
306 ## correctly. Breaking it into two sed invocations is a workaround.
307 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
308 rm -f "$tmpdepfile" "$tmpdepfile".bak
312 # Important note: in order to support this mode, a compiler *must*
313 # always write the proprocessed file to stdout, regardless of -o,
314 # because we must use -o when running libtool.
317 *" --mode=compile "*)
319 do # cycle over the arguments
322 # insert --quiet before "--mode=compile"
323 set fnord "$@" --quiet
327 set fnord "$@" "$arg"
334 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
335 sed '$ s: \\$::' > "$tmpdepfile"
341 if test "$stat" != 0; then exit $stat; fi
343 echo "$object : \\" > "$depfile"
344 cat < "$tmpdepfile" >> "$depfile"
345 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
350 # Important note: in order to support this mode, a compiler *must*
351 # always write the proprocessed file to stdout, regardless of -o,
352 # because we must use -o when running libtool.
355 *" --mode=compile "*)
357 do # cycle over the arguments
360 # insert --quiet before "--mode=compile"
361 set fnord "$@" --quiet
365 set fnord "$@" "$arg"
372 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
378 if test "$stat" != 0; then exit $stat; fi
380 echo "$object : \\" > "$depfile"
381 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
382 echo " " >> "$depfile"
383 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
392 echo "Unknown depmode $depmode" 1>&2