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 # As a special exception to the GNU General Public License, if you
22 # distribute this file as part of a program that contains a
23 # configuration script generated by Autoconf, you may include it under
24 # the same distribution terms that you use for the rest of that program.
26 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28 if test -z "$depmode" ||
test -z "$source" ||
test -z "$object"; then
29 echo "depcomp: Variables source, object and depmode must be set" 1>&2
32 # `libtool' can also be set to `yes' or `no'.
34 depfile
=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
35 tmpdepfile
=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
39 # Some modes work just like other modes, but use different flags. We
40 # parameterize here, but still list the modes in the big case below,
41 # to make depend.m4 easier to write. Note that we *cannot* use a case
42 # here, because this file can only contain one case statement.
43 if test "$depmode" = hp
; then
44 # HP compiler uses -M and no extra arg.
49 if test "$depmode" = dashXmstdout
; then
50 # This is just like dashmstdout with a different argument.
57 ## gcc 3 implements dependency tracking that does exactly what
58 ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
59 ## it if -MD -MP comes after the -MF stuff. Hmm.
60 "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
62 if test $stat -eq 0; then :
67 mv "$tmpdepfile" "$depfile"
71 ## There are various ways to get dependency output from gcc. Here's
72 ## why we pick this rather obscure method:
73 ## - Don't want to use -MD because we'd like the dependencies to end
74 ## up in a subdir. Having to rename by hand is ugly.
75 ## (We might end up doing this anyway to support other compilers.)
76 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
77 ## -MM, not -M (despite what the docs say).
78 ## - Using -M directly means running the compiler twice (even worse
80 if test -z "$gccflag"; then
83 "$@" -Wp,"$gccflag$tmpdepfile"
85 if test $stat -eq 0; then :
91 echo "$object : \\" > "$depfile"
92 alpha
=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
93 ## The second -e expression handles DOS-style file names with drive letters.
94 sed -e 's/^[^:]*: / /' \
95 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
96 ## This next piece of magic avoids the `deleted header file' problem.
97 ## The problem is that when a header file which appears in a .P file
98 ## is deleted, the dependency causes make to die (because there is
99 ## typically no way to rebuild the header). We avoid this by adding
100 ## dummy dependencies for each header file. Too bad gcc doesn't do
101 ## this for us directly.
104 ## Some versions of gcc put a space before the `:'. On the theory
105 ## that the space means something, we add a space to the output as
107 ## Some versions of the HPUX 10.20 sed can't process this invocation
108 ## correctly. Breaking it into two sed invocations is a workaround.
109 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
114 # This case exists only to let depend.m4 do its work. It works by
115 # looking at the text of this script. This case will never be run,
116 # since it is checked for above.
121 if test "$libtool" = yes; then
122 "$@" "-Wp,-MDupdate,$tmpdepfile"
124 "$@" -MDupdate "$tmpdepfile"
127 if test $stat -eq 0; then :
134 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
135 echo "$object : \\" > "$depfile"
137 # Clip off the initial element (the dependent). Don't try to be
138 # clever and replace this with sed code, as IRIX sed won't handle
139 # lines with more than a fixed number of characters (4096 in
140 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
141 # the IRIX cc adds comments like `#:fec' to the end of the
145 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
150 # The second pass generates a dummy entry for each header file.
153 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
156 # The sourcefile does not contain any dependencies, so just
157 # store a dummy comment line, to avoid errors with the Makefile
158 # "include basename.Plo" scheme.
159 echo "#dummy" > "$depfile"
165 # The C for AIX Compiler uses -M and outputs the dependencies
166 # in a .u file. This file always lives in the current directory.
167 # Also, the AIX compiler puts `$object:' at the start of each line;
168 # $object doesn't have directory information.
169 stripped
=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
170 tmpdepfile
="$stripped.u"
171 outname
="$stripped.o"
172 if test "$libtool" = yes; then
179 if test $stat -eq 0; then :
185 if test -f "$tmpdepfile"; then
186 # Each line is of the form `foo.o: dependent.h'.
187 # Do two passes, one to just change these to
188 # `$object: dependent.h' and one to simply `dependent.h:'.
189 sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
190 sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
192 # The sourcefile does not contain any dependencies, so just
193 # store a dummy comment line, to avoid errors with the Makefile
194 # "include basename.Plo" scheme.
195 echo "#dummy" > "$depfile"
201 # Must come before tru64.
203 # Intel's C compiler understands `-MD -MF file'. However
204 # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
205 # will fill foo.d with something like
208 # which is wrong. We want:
209 # sub/foo.o: sub/foo.c
210 # sub/foo.o: sub/foo.h
214 "$@" -MD -MF "$tmpdepfile"
216 if test $stat -eq 0; then :
222 # Each line is of the form `foo.o: dependent.h'.
223 # Do two passes, one to just change these to
224 # `$object: dependent.h' and one to simply `dependent.h:'.
225 sed -e "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
226 sed -e "s,^[^:]*: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
231 # The Tru64 AIX compiler uses -MD to generate dependencies as a side
232 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
233 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
234 # dependencies in `foo.d' instead, so we check for that too.
235 # Subdirectories are respected.
237 tmpdepfile1
="$object.d"
238 tmpdepfile2
=`echo "$object" | sed -e 's/.o$/.d/'`
239 if test "$libtool" = yes; then
246 if test $stat -eq 0; then :
248 rm -f "$tmpdepfile1" "$tmpdepfile2"
252 if test -f "$tmpdepfile1"; then
253 tmpdepfile
="$tmpdepfile1"
255 tmpdepfile
="$tmpdepfile2"
257 if test -f "$tmpdepfile"; then
258 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
259 # That's a space and a tab in the [].
260 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
262 echo "#dummy" > "$depfile"
268 # This comment above is used by automake to tell side-effect
269 # dependency tracking mechanisms from slower ones.
272 # Important note: in order to support this mode, a compiler *must*
273 # always write the proprocessed file to stdout, regardless of -o,
274 # because we must use -o when running libtool.
275 test -z "$dashmflag" && dashmflag
=-M
278 *" --mode=compile "*) # this is libtool, let us make it quiet
280 do # cycle over the arguments
283 # insert --quiet before "--mode=compile"
284 set fnord
"$@" --quiet
288 set fnord
"$@" "$arg"
294 "$@" $dashmflag |
sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
300 if test "$stat" != 0; then exit $stat; fi
302 cat < "$tmpdepfile" > "$depfile"
304 ' < "$tmpdepfile" | \
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"
312 # This case only exists to satisfy depend.m4. It is never actually
313 # run, as this mode is specially recognized in the preamble.
329 set fnord
"$@" "$arg"; shift;;
333 set fnord
"$@" "$arg"; shift;;
336 obj_suffix
="`echo $object | sed 's/^.*\././'`"
338 ${MAKEDEPEND-makedepend} 2>/dev
/null
-o"$obj_suffix" -f"$tmpdepfile" "$@"
344 if test "$stat" != 0; then exit $stat; fi
346 cat < "$tmpdepfile" > "$depfile"
347 tail +3 "$tmpdepfile" |
tr ' ' '
349 ## Some versions of the HPUX 10.20 sed can't process this invocation
350 ## correctly. Breaking it into two sed invocations is a workaround.
351 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
352 rm -f "$tmpdepfile" "$tmpdepfile".bak
356 # Important note: in order to support this mode, a compiler *must*
357 # always write the proprocessed file to stdout, regardless of -o,
358 # because we must use -o when running libtool.
361 *" --mode=compile "*)
363 do # cycle over the arguments
366 # insert --quiet before "--mode=compile"
367 set fnord
"$@" --quiet
371 set fnord
"$@" "$arg"
378 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
379 sed '$ s: \\$::' > "$tmpdepfile"
385 if test "$stat" != 0; then exit $stat; fi
387 echo "$object : \\" > "$depfile"
388 cat < "$tmpdepfile" >> "$depfile"
389 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
394 # Important note: in order to support this mode, a compiler *must*
395 # always write the proprocessed file to stdout, regardless of -o,
396 # because we must use -o when running libtool.
399 *" --mode=compile "*)
401 do # cycle over the arguments
404 # insert --quiet before "--mode=compile"
405 set fnord
"$@" --quiet
409 set fnord
"$@" "$arg"
416 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' |
sort |
uniq > "$tmpdepfile"
422 if test "$stat" != 0; then exit $stat; fi
424 echo "$object : \\" > "$depfile"
425 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
426 echo " " >> "$depfile"
427 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
436 echo "Unknown depmode $depmode" 1>&2