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 # The Tru64 AIX compiler uses -MD to generate dependencies as a side
202 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
203 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
204 # dependencies in `foo.d' instead, so we check for that too.
205 # Subdirectories are respected.
207 tmpdepfile1
="$object.d"
208 tmpdepfile2
=`echo "$object" | sed -e 's/.o$/.d/'`
209 if test "$libtool" = yes; then
216 if test $stat -eq 0; then :
218 rm -f "$tmpdepfile1" "$tmpdepfile2"
222 if test -f "$tmpdepfile1"; then
223 tmpdepfile
="$tmpdepfile1"
225 tmpdepfile
="$tmpdepfile2"
227 if test -f "$tmpdepfile"; then
228 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
229 # That's a space and a tab in the [].
230 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
232 echo "#dummy" > "$depfile"
238 # This comment above is used by automake to tell side-effect
239 # dependency tracking mechanisms from slower ones.
242 # Important note: in order to support this mode, a compiler *must*
243 # always write the proprocessed file to stdout, regardless of -o,
244 # because we must use -o when running libtool.
245 test -z "$dashmflag" && dashmflag
=-M
248 *" --mode=compile "*) # this is libtool, let us make it quiet
250 do # cycle over the arguments
253 # insert --quiet before "--mode=compile"
254 set fnord
"$@" --quiet
258 set fnord
"$@" "$arg"
264 "$@" $dashmflag |
sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
270 if test "$stat" != 0; then exit $stat; fi
272 cat < "$tmpdepfile" > "$depfile"
274 ' < "$tmpdepfile" | \
275 ## Some versions of the HPUX 10.20 sed can't process this invocation
276 ## correctly. Breaking it into two sed invocations is a workaround.
277 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
282 # This case only exists to satisfy depend.m4. It is never actually
283 # run, as this mode is specially recognized in the preamble.
299 set fnord
"$@" "$arg"; shift;;
303 set fnord
"$@" "$arg"; shift;;
306 obj_suffix
="`echo $object | sed 's/^.*\././'`"
308 ${MAKEDEPEND-makedepend} 2>/dev
/null
-o"$obj_suffix" -f"$tmpdepfile" "$@"
314 if test "$stat" != 0; then exit $stat; fi
316 cat < "$tmpdepfile" > "$depfile"
317 tail +3 "$tmpdepfile" |
tr ' ' '
319 ## Some versions of the HPUX 10.20 sed can't process this invocation
320 ## correctly. Breaking it into two sed invocations is a workaround.
321 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
322 rm -f "$tmpdepfile" "$tmpdepfile".bak
326 # Important note: in order to support this mode, a compiler *must*
327 # always write the proprocessed file to stdout, regardless of -o,
328 # because we must use -o when running libtool.
331 *" --mode=compile "*)
333 do # cycle over the arguments
336 # insert --quiet before "--mode=compile"
337 set fnord
"$@" --quiet
341 set fnord
"$@" "$arg"
348 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
349 sed '$ s: \\$::' > "$tmpdepfile"
355 if test "$stat" != 0; then exit $stat; fi
357 echo "$object : \\" > "$depfile"
358 cat < "$tmpdepfile" >> "$depfile"
359 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
364 # Important note: in order to support this mode, a compiler *must*
365 # always write the proprocessed file to stdout, regardless of -o,
366 # because we must use -o when running libtool.
369 *" --mode=compile "*)
371 do # cycle over the arguments
374 # insert --quiet before "--mode=compile"
375 set fnord
"$@" --quiet
379 set fnord
"$@" "$arg"
386 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' |
sort |
uniq > "$tmpdepfile"
392 if test "$stat" != 0; then exit $stat; fi
394 echo "$object : \\" > "$depfile"
395 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
396 echo " " >> "$depfile"
397 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
406 echo "Unknown depmode $depmode" 1>&2