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 if "$@" -MT "$object" -MF "$tmpdepfile" -MD -MP; then :
60 mv "$tmpdepfile" "$depfile"
64 ## There are various ways to get dependency output from gcc. Here's
65 ## why we pick this rather obscure method:
66 ## - Don't want to use -MD because we'd like the dependencies to end
67 ## up in a subdir. Having to rename by hand is ugly.
68 ## (We might end up doing this anyway to support other compilers.)
69 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
70 ## -MM, not -M (despite what the docs say).
71 ## - Using -M directly means running the compiler twice (even worse
73 if test -z "$gccflag"; then
76 if "$@" -Wp,"$gccflag$tmpdepfile"; then :
83 echo "$object : \\" > "$depfile"
84 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
85 ## The second -e expression handles DOS-style file names with drive letters.
86 sed -e 's/^[^:]*: / /' \
87 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
88 ## This next piece of magic avoids the `deleted header file' problem.
89 ## The problem is that when a header file which appears in a .P file
90 ## is deleted, the dependency causes make to die (because there is
91 ## typically no way to rebuild the header). We avoid this by adding
92 ## dummy dependencies for each header file. Too bad gcc doesn't do
93 ## this for us directly.
96 ## Some versions of gcc put a space before the `:'. On the theory
97 ## that the space means something, we add a space to the output as
99 ## Some versions of the HPUX 10.20 sed can't process this invocation
100 ## correctly. Breaking it into two sed invocations is a workaround.
101 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
106 # This case exists only to let depend.m4 do its work. It works by
107 # looking at the text of this script. This case will never be run,
108 # since it is checked for above.
113 if test "$libtool" = yes; then
114 "$@" "-Wp,-MDupdate,$tmpdepfile"
116 "$@" -MDupdate "$tmpdepfile"
119 if test $stat -eq 0; then :
126 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
127 echo "$object : \\" > "$depfile"
129 # Clip off the initial element (the dependent). Don't try to be
130 # clever and replace this with sed code, as IRIX sed won't handle
131 # lines with more than a fixed number of characters (4096 in
132 # IRIX 6.2 sed, 8192 in IRIX 6.5).
134 ' < "$tmpdepfile" | sed 's/^[^\.]*\.o://' | tr '
138 ' < "$tmpdepfile" | \
139 ## Some versions of the HPUX 10.20 sed can't process this invocation
140 ## correctly. Breaking it into two sed invocations is a workaround.
141 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
143 # The sourcefile does not contain any dependencies, so just
144 # store a dummy comment line, to avoid errors with the Makefile
145 # "include basename.Plo" scheme.
146 echo "#dummy" > "$depfile"
152 # The C for AIX Compiler uses -M and outputs the dependencies
154 tmpdepfile=`echo "$object" | sed 's/\(.*\)\..*$/\1.u/'`
155 if test "$libtool" = yes; then
162 if test $stat -eq 0; then :
168 if test -f "$tmpdepfile"; then
169 echo "$object : \\" > "$depfile"
171 # Clip off the initial element (the dependent). Don't try to be
172 # clever and replace this with sed code, as IRIX sed won't handle
173 # lines with more than a fixed number of characters (4096 in
174 # IRIX 6.2 sed, 8192 in IRIX 6.5).
176 ' < "$tmpdepfile" | sed 's/^[^\.]*\.o://' | tr '
180 ' < "$tmpdepfile" | \
181 ## Some versions of the HPUX 10.20 sed can't process this invocation
182 ## correctly. Breaking it into two sed invocations is a workaround.
183 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
185 # The sourcefile does not contain any dependencies, so just
186 # store a dummy comment line, to avoid errors with the Makefile
187 # "include basename.Plo" scheme.
188 echo "#dummy" > "$depfile"
194 # This comment above is used by automake to tell side-effect
195 # dependency tracking mechanisms from slower ones.
198 # Important note: in order to support this mode, a compiler *must*
199 # always write the proprocessed file to stdout, regardless of -o,
200 # because we must use -o when running libtool.
201 test -z "$dashmflag" && dashmflag=-M
204 *" --mode=compile "*) # this is libtool, let us make it quiet
206 do # cycle over the arguments
209 # insert --quiet before "--mode=compile"
210 set fnord "$@" --quiet
214 set fnord "$@" "$arg"
220 "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
226 if test "$stat" != 0; then exit $stat; fi
228 cat < "$tmpdepfile" > "$depfile"
230 ' < "$tmpdepfile" | \
231 ## Some versions of the HPUX 10.20 sed can't process this invocation
232 ## correctly. Breaking it into two sed invocations is a workaround.
233 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
238 # This case only exists to satisfy depend.m4. It is never actually
239 # run, as this mode is specially recognized in the preamble.
255 set fnord "$@" "$arg"; shift;;
259 set fnord "$@" "$arg"; shift;;
262 obj_suffix="`echo $object | sed 's/^.*\././'`"
264 ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
270 if test "$stat" != 0; then exit $stat; fi
272 cat < "$tmpdepfile" > "$depfile"
273 tail +3 "$tmpdepfile" | tr ' ' '
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"
278 rm -f "$tmpdepfile" "$tmpdepfile".bak
282 # Important note: in order to support this mode, a compiler *must*
283 # always write the proprocessed file to stdout, regardless of -o,
284 # because we must use -o when running libtool.
287 *" --mode=compile "*)
289 do # cycle over the arguments
292 # insert --quiet before "--mode=compile"
293 set fnord "$@" --quiet
297 set fnord "$@" "$arg"
304 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
305 sed '$ s: \\$::' > "$tmpdepfile"
311 if test "$stat" != 0; then exit $stat; fi
313 echo "$object : \\" > "$depfile"
314 cat < "$tmpdepfile" >> "$depfile"
315 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
320 # Important note: in order to support this mode, a compiler *must*
321 # always write the proprocessed file to stdout, regardless of -o,
322 # because we must use -o when running libtool.
325 *" --mode=compile "*)
327 do # cycle over the arguments
330 # insert --quiet before "--mode=compile"
331 set fnord "$@" --quiet
335 set fnord "$@" "$arg"
342 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
348 if test "$stat" != 0; then exit $stat; fi
350 echo "$object : \\" > "$depfile"
351 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
352 echo " " >> "$depfile"
353 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
362 echo "Unknown depmode $depmode" 1>&2