* automake.in (read_am_file): Removed debugging code.
[automake.git] / depcomp
blob71e0ec059044f367623589c9b27ad19fc695cdbd
1 #! /bin/sh
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)
9 # any later version.
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
19 # 02111-1307, USA.
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
25 exit 1
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/'`}
32 rm -f "$tmpdepfile"
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.
40 gccflag=-M
41 depmode=gcc
44 if test "$depmode" = dashXmstdout; then
45 # This is just like dashmstdout with a different argument.
46 dashmflag=-xM
47 depmode=dashmstdout
50 case "$depmode" in
51 gcc3)
52 ## gcc 3 implements dependency tracking that does exactly what
53 ## we want. Yay!
54 "$@" -MT "$object" -MF "$tmpdepfile" -MD -MP
55 stat=$?
56 if test $stat -eq 0; then :
57 else
58 rm -f "$tmpdepfile"
59 exit $stat
61 mv "$tmpdepfile" "$depfile"
64 gcc)
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
73 ## than renaming).
74 if test -z "$gccflag"; then
75 gccflag=-MD,
77 "$@" -Wp,"$gccflag$tmpdepfile"
78 stat=$?
79 if test $stat -eq 0; then :
80 else
81 rm -f "$tmpdepfile"
82 exit $stat
84 rm -f "$depfile"
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.
96 tr ' ' '
97 ' < "$tmpdepfile" |
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
100 ## well.
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"
104 rm -f "$tmpdepfile"
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.
111 exit 1
114 sgi)
115 if test "$libtool" = yes; then
116 "$@" "-Wp,-MDupdate,$tmpdepfile"
117 else
118 "$@" -MDupdate "$tmpdepfile"
120 stat=$?
121 if test $stat -eq 0; then :
122 else
123 rm -f "$tmpdepfile"
124 exit $stat
126 rm -f "$depfile"
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).
135 tr ' ' '
136 ' < "$tmpdepfile" | sed 's/^.*\.o://' | tr '
137 ' ' ' >> $depfile
139 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"
144 else
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"
150 rm -f "$tmpdepfile"
153 aix)
154 # The C for AIX Compiler uses -M and outputs the dependencies
155 # in a .u file.
156 tmpdepfile=`echo "$object" | sed 's/\(.*\)\..*$/\1.u/'`
157 if test "$libtool" = yes; then
158 "$@" -Wc,-M
159 else
160 "$@" -M
163 stat=$?
164 if test $stat -eq 0; then :
165 else
166 rm -f "$tmpdepfile"
167 exit $stat
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).
177 tr ' ' '
178 ' < "$tmpdepfile" | sed 's/^[^\.]*\.o://' | tr '
179 ' ' ' >> $depfile
181 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"
186 else
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"
192 rm -f "$tmpdepfile"
195 #nosideeffect)
196 # This comment above is used by automake to tell side-effect
197 # dependency tracking mechanisms from slower ones.
199 dashmstdout)
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
204 ( IFS=" "
205 case " $* " in
206 *" --mode=compile "*) # this is libtool, let us make it quiet
207 for arg
208 do # cycle over the arguments
209 case "$arg" in
210 "--mode=compile")
211 # insert --quiet before "--mode=compile"
212 set fnord "$@" --quiet
213 shift # fnord
215 esac
216 set fnord "$@" "$arg"
217 shift # fnord
218 shift # "$arg"
219 done
221 esac
222 "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
224 proc=$!
225 "$@"
226 stat=$?
227 wait "$proc"
228 if test "$stat" != 0; then exit $stat; fi
229 rm -f "$depfile"
230 cat < "$tmpdepfile" > "$depfile"
231 tr ' ' '
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"
236 rm -f "$tmpdepfile"
239 dashXmstdout)
240 # This case only exists to satisfy depend.m4. It is never actually
241 # run, as this mode is specially recognized in the preamble.
242 exit 1
245 makedepend)
246 # X makedepend
248 shift
249 cleared=no
250 for arg in "$@"; do
251 case $cleared in no)
252 set ""; shift
253 cleared=yes
254 esac
255 case "$arg" in
256 -D*|-I*)
257 set fnord "$@" "$arg"; shift;;
261 set fnord "$@" "$arg"; shift;;
262 esac
263 done
264 obj_suffix="`echo $object | sed 's/^.*\././'`"
265 touch "$tmpdepfile"
266 ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
268 proc=$!
269 "$@"
270 stat=$?
271 wait "$proc"
272 if test "$stat" != 0; then exit $stat; fi
273 rm -f "$depfile"
274 cat < "$tmpdepfile" > "$depfile"
275 tail +3 "$tmpdepfile" | tr ' ' '
276 ' | \
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
283 cpp)
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.
287 ( IFS=" "
288 case " $* " in
289 *" --mode=compile "*)
290 for arg
291 do # cycle over the arguments
292 case $arg in
293 "--mode=compile")
294 # insert --quiet before "--mode=compile"
295 set fnord "$@" --quiet
296 shift # fnord
298 esac
299 set fnord "$@" "$arg"
300 shift # fnord
301 shift # "$arg"
302 done
304 esac
305 "$@" -E |
306 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
307 sed '$ s: \\$::' > "$tmpdepfile"
309 proc=$!
310 "$@"
311 stat=$?
312 wait "$proc"
313 if test "$stat" != 0; then exit $stat; fi
314 rm -f "$depfile"
315 echo "$object : \\" > "$depfile"
316 cat < "$tmpdepfile" >> "$depfile"
317 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
318 rm -f "$tmpdepfile"
321 msvisualcpp)
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.
325 ( IFS=" "
326 case " $* " in
327 *" --mode=compile "*)
328 for arg
329 do # cycle over the arguments
330 case $arg in
331 "--mode=compile")
332 # insert --quiet before "--mode=compile"
333 set fnord "$@" --quiet
334 shift # fnord
336 esac
337 set fnord "$@" "$arg"
338 shift # fnord
339 shift # "$arg"
340 done
342 esac
343 "$@" -E |
344 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
346 proc=$!
347 "$@"
348 stat=$?
349 wait "$proc"
350 if test "$stat" != 0; then exit $stat; fi
351 rm -f "$depfile"
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"
356 rm -f "$tmpdepfile"
359 none)
360 exec "$@"
364 echo "Unknown depmode $depmode" 1>&2
365 exit 1
367 esac
369 exit 0