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).
136 ' < "$tmpdepfile" |
sed 's/^.*\.o://' |
tr '
140 ' < "$tmpdepfile" | \
141 ## Some versions of the HPUX 10.20 sed can't process this invocation
142 ## correctly. Breaking it into two sed invocations is a workaround.
143 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
145 # The sourcefile does not contain any dependencies, so just
146 # store a dummy comment line, to avoid errors with the Makefile
147 # "include basename.Plo" scheme.
148 echo "#dummy" > "$depfile"
154 # The C for AIX Compiler uses -M and outputs the dependencies
156 tmpdepfile
=`echo "$object" | sed 's/\(.*\)\..*$/\1.u/'`
157 if test "$libtool" = yes; then
164 if test $stat -eq 0; then :
170 if test -f "$tmpdepfile"; then
171 echo "$object : \\" > "$depfile"
173 # Clip off the initial element (the dependent). Don't try to be
174 # clever and replace this with sed code, as IRIX sed won't handle
175 # lines with more than a fixed number of characters (4096 in
176 # IRIX 6.2 sed, 8192 in IRIX 6.5).
178 ' < "$tmpdepfile" |
sed 's/^[^\.]*\.o://' |
tr '
182 ' < "$tmpdepfile" | \
183 ## Some versions of the HPUX 10.20 sed can't process this invocation
184 ## correctly. Breaking it into two sed invocations is a workaround.
185 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
187 # The sourcefile does not contain any dependencies, so just
188 # store a dummy comment line, to avoid errors with the Makefile
189 # "include basename.Plo" scheme.
190 echo "#dummy" > "$depfile"
196 # This comment above is used by automake to tell side-effect
197 # dependency tracking mechanisms from slower ones.
200 # Important note: in order to support this mode, a compiler *must*
201 # always write the proprocessed file to stdout, regardless of -o,
202 # because we must use -o when running libtool.
203 test -z "$dashmflag" && dashmflag
=-M
206 *" --mode=compile "*) # this is libtool, let us make it quiet
208 do # cycle over the arguments
211 # insert --quiet before "--mode=compile"
212 set fnord
"$@" --quiet
216 set fnord
"$@" "$arg"
222 "$@" $dashmflag |
sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
228 if test "$stat" != 0; then exit $stat; fi
230 cat < "$tmpdepfile" > "$depfile"
232 ' < "$tmpdepfile" | \
233 ## Some versions of the HPUX 10.20 sed can't process this invocation
234 ## correctly. Breaking it into two sed invocations is a workaround.
235 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
240 # This case only exists to satisfy depend.m4. It is never actually
241 # run, as this mode is specially recognized in the preamble.
257 set fnord
"$@" "$arg"; shift;;
261 set fnord
"$@" "$arg"; shift;;
264 obj_suffix
="`echo $object | sed 's/^.*\././'`"
266 ${MAKEDEPEND-makedepend} 2>/dev
/null
-o"$obj_suffix" -f"$tmpdepfile" "$@"
272 if test "$stat" != 0; then exit $stat; fi
274 cat < "$tmpdepfile" > "$depfile"
275 tail +3 "$tmpdepfile" |
tr ' ' '
277 ## Some versions of the HPUX 10.20 sed can't process this invocation
278 ## correctly. Breaking it into two sed invocations is a workaround.
279 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
280 rm -f "$tmpdepfile" "$tmpdepfile".bak
284 # Important note: in order to support this mode, a compiler *must*
285 # always write the proprocessed file to stdout, regardless of -o,
286 # because we must use -o when running libtool.
289 *" --mode=compile "*)
291 do # cycle over the arguments
294 # insert --quiet before "--mode=compile"
295 set fnord
"$@" --quiet
299 set fnord
"$@" "$arg"
306 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
307 sed '$ s: \\$::' > "$tmpdepfile"
313 if test "$stat" != 0; then exit $stat; fi
315 echo "$object : \\" > "$depfile"
316 cat < "$tmpdepfile" >> "$depfile"
317 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
322 # Important note: in order to support this mode, a compiler *must*
323 # always write the proprocessed file to stdout, regardless of -o,
324 # because we must use -o when running libtool.
327 *" --mode=compile "*)
329 do # cycle over the arguments
332 # insert --quiet before "--mode=compile"
333 set fnord
"$@" --quiet
337 set fnord
"$@" "$arg"
344 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' |
sort |
uniq > "$tmpdepfile"
350 if test "$stat" != 0; then exit $stat; fi
352 echo "$object : \\" > "$depfile"
353 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
354 echo " " >> "$depfile"
355 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
364 echo "Unknown depmode $depmode" 1>&2