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 if test -z "$depfile"; then
35 base
=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'`
36 dir
=`echo "$object" | sed 's,/.*$,/,'`
37 if test "$dir" = "$object"; then
40 # FIXME: should be _deps on DOS.
41 depfile
="$dir.deps/$base"
44 tmpdepfile
=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
48 # Some modes work just like other modes, but use different flags. We
49 # parameterize here, but still list the modes in the big case below,
50 # to make depend.m4 easier to write. Note that we *cannot* use a case
51 # here, because this file can only contain one case statement.
52 if test "$depmode" = hp
; then
53 # HP compiler uses -M and no extra arg.
58 if test "$depmode" = dashXmstdout
; then
59 # This is just like dashmstdout with a different argument.
66 ## gcc 3 implements dependency tracking that does exactly what
67 ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
68 ## it if -MD -MP comes after the -MF stuff. Hmm.
69 "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
71 if test $stat -eq 0; then :
76 mv "$tmpdepfile" "$depfile"
80 ## There are various ways to get dependency output from gcc. Here's
81 ## why we pick this rather obscure method:
82 ## - Don't want to use -MD because we'd like the dependencies to end
83 ## up in a subdir. Having to rename by hand is ugly.
84 ## (We might end up doing this anyway to support other compilers.)
85 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
86 ## -MM, not -M (despite what the docs say).
87 ## - Using -M directly means running the compiler twice (even worse
89 if test -z "$gccflag"; then
92 "$@" -Wp,"$gccflag$tmpdepfile"
94 if test $stat -eq 0; then :
100 echo "$object : \\" > "$depfile"
101 alpha
=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
102 ## The second -e expression handles DOS-style file names with drive letters.
103 sed -e 's/^[^:]*: / /' \
104 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
105 ## This next piece of magic avoids the `deleted header file' problem.
106 ## The problem is that when a header file which appears in a .P file
107 ## is deleted, the dependency causes make to die (because there is
108 ## typically no way to rebuild the header). We avoid this by adding
109 ## dummy dependencies for each header file. Too bad gcc doesn't do
110 ## this for us directly.
113 ## Some versions of gcc put a space before the `:'. On the theory
114 ## that the space means something, we add a space to the output as
116 ## Some versions of the HPUX 10.20 sed can't process this invocation
117 ## correctly. Breaking it into two sed invocations is a workaround.
118 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
123 # This case exists only to let depend.m4 do its work. It works by
124 # looking at the text of this script. This case will never be run,
125 # since it is checked for above.
130 if test "$libtool" = yes; then
131 "$@" "-Wp,-MDupdate,$tmpdepfile"
133 "$@" -MDupdate "$tmpdepfile"
136 if test $stat -eq 0; then :
143 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
144 echo "$object : \\" > "$depfile"
146 # Clip off the initial element (the dependent). Don't try to be
147 # clever and replace this with sed code, as IRIX sed won't handle
148 # lines with more than a fixed number of characters (4096 in
149 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
150 # the IRIX cc adds comments like `#:fec' to the end of the
154 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
159 # The second pass generates a dummy entry for each header file.
162 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
165 # The sourcefile does not contain any dependencies, so just
166 # store a dummy comment line, to avoid errors with the Makefile
167 # "include basename.Plo" scheme.
168 echo "#dummy" > "$depfile"
174 # The C for AIX Compiler uses -M and outputs the dependencies
175 # in a .u file. This file always lives in the current directory.
176 # Also, the AIX compiler puts `$object:' at the start of each line;
177 # $object doesn't have directory information.
178 stripped
=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
179 tmpdepfile
="$stripped.u"
180 outname
="$stripped.o"
181 if test "$libtool" = yes; then
188 if test $stat -eq 0; then :
194 if test -f "$tmpdepfile"; then
195 # Each line is of the form `foo.o: dependent.h'.
196 # Do two passes, one to just change these to
197 # `$object: dependent.h' and one to simply `dependent.h:'.
198 sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
199 sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
201 # The sourcefile does not contain any dependencies, so just
202 # store a dummy comment line, to avoid errors with the Makefile
203 # "include basename.Plo" scheme.
204 echo "#dummy" > "$depfile"
210 # The Tru64 compiler uses -MD to generate dependencies as a side
211 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
212 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
213 # dependencies in `foo.d' instead, so we check for that too.
214 # Subdirectories are respected.
216 base
=`echo "$object" | sed -e 's/\.o$//' -e 's/\.lo$//'`
217 tmpdepfile1
="$base.o.d"
218 tmpdepfile2
="$base.d"
219 if test "$libtool" = yes; then
226 if test $stat -eq 0; then :
228 rm -f "$tmpdepfile1" "$tmpdepfile2"
232 if test -f "$tmpdepfile1"; then
233 tmpdepfile
="$tmpdepfile1"
235 tmpdepfile
="$tmpdepfile2"
237 if test -f "$tmpdepfile"; then
238 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
239 # That's a space and a tab in the [].
240 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
242 echo "#dummy" > "$depfile"
248 # This comment above is used by automake to tell side-effect
249 # dependency tracking mechanisms from slower ones.
252 # Important note: in order to support this mode, a compiler *must*
253 # always write the proprocessed file to stdout, regardless of -o,
254 # because we must use -o when running libtool.
255 test -z "$dashmflag" && dashmflag
=-M
258 *" --mode=compile "*) # this is libtool, let us make it quiet
260 do # cycle over the arguments
263 # insert --quiet before "--mode=compile"
264 set fnord
"$@" --quiet
268 set fnord
"$@" "$arg"
274 "$@" $dashmflag |
sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
280 if test "$stat" != 0; then exit $stat; fi
282 cat < "$tmpdepfile" > "$depfile"
284 ' < "$tmpdepfile" | \
285 ## Some versions of the HPUX 10.20 sed can't process this invocation
286 ## correctly. Breaking it into two sed invocations is a workaround.
287 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
292 # This case only exists to satisfy depend.m4. It is never actually
293 # run, as this mode is specially recognized in the preamble.
309 set fnord
"$@" "$arg"; shift;;
313 set fnord
"$@" "$arg"; shift;;
316 obj_suffix
="`echo $object | sed 's/^.*\././'`"
318 ${MAKEDEPEND-makedepend} 2>/dev
/null
-o"$obj_suffix" -f"$tmpdepfile" "$@"
324 if test "$stat" != 0; then exit $stat; fi
326 cat < "$tmpdepfile" > "$depfile"
327 sed '1,2d' "$tmpdepfile" |
tr ' ' '
329 ## Some versions of the HPUX 10.20 sed can't process this invocation
330 ## correctly. Breaking it into two sed invocations is a workaround.
331 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
332 rm -f "$tmpdepfile" "$tmpdepfile".bak
336 # Important note: in order to support this mode, a compiler *must*
337 # always write the proprocessed file to stdout, regardless of -o,
338 # because we must use -o when running libtool.
341 *" --mode=compile "*)
343 do # cycle over the arguments
346 # insert --quiet before "--mode=compile"
347 set fnord
"$@" --quiet
351 set fnord
"$@" "$arg"
358 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
359 sed '$ s: \\$::' > "$tmpdepfile"
365 if test "$stat" != 0; then exit $stat; fi
367 echo "$object : \\" > "$depfile"
368 cat < "$tmpdepfile" >> "$depfile"
369 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
374 # Important note: in order to support this mode, a compiler *must*
375 # always write the proprocessed file to stdout, regardless of -o,
376 # because we must use -o when running libtool.
379 *" --mode=compile "*)
381 do # cycle over the arguments
384 # insert --quiet before "--mode=compile"
385 set fnord
"$@" --quiet
389 set fnord
"$@" "$arg"
398 "-Gm"|
"/Gm"|
"-Gi"|
"/Gi"|
"-ZI"|
"/ZI")
404 set fnord
"$@" "$arg"
411 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' |
sort |
uniq > "$tmpdepfile"
417 if test "$stat" != 0; then exit $stat; fi
419 echo "$object : \\" > "$depfile"
420 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
421 echo " " >> "$depfile"
422 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
431 echo "Unknown depmode $depmode" 1>&2