* Makefile.am (TESTS): Added aclocali1.test.
[automake.git] / depcomp
blob0a92302ec9790cbb8243d55b4f190a159a07f2d6
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 gcc)
52 ## There are various ways to get dependency output from gcc. Here's
53 ## why we pick this rather obscure method:
54 ## - Don't want to use -MD because we'd like the dependencies to end
55 ## up in a subdir. Having to rename by hand is ugly.
56 ## (We might end up doing this anyway to support other compilers.)
57 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
58 ## -MM, not -M (despite what the docs say).
59 ## - Using -M directly means running the compiler twice (even worse
60 ## than renaming).
61 if test -z "$gccflag"; then
62 gccflag=-MD,
64 if "$@" -Wp,"$gccflag$tmpdepfile"; then :
65 else
66 stat=$?
67 rm -f "$tmpdepfile"
68 exit $stat
70 rm -f "$depfile"
71 echo "$object : \\" > "$depfile"
72 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
73 ## The second -e expression handles DOS-style file names with drive letters.
74 sed -e 's/^[^:]*: / /' \
75 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
76 ## This next piece of magic avoids the `deleted header file' problem.
77 ## The problem is that when a header file which appears in a .P file
78 ## is deleted, the dependency causes make to die (because there is
79 ## typically no way to rebuild the header). We avoid this by adding
80 ## dummy dependencies for each header file. Too bad gcc doesn't do
81 ## this for us directly.
82 tr ' ' '
83 ' < "$tmpdepfile" |
84 ## Some versions of gcc put a space before the `:'. On the theory
85 ## that the space means something, we add a space to the output as
86 ## well.
87 ## Some versions of the HPUX 10.20 sed can't process this invocation
88 ## correctly. Breaking it into two sed invocations is a workaround.
89 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
90 rm -f "$tmpdepfile"
93 hp)
94 # This case exists only to let depend.m4 do its work. It works by
95 # looking at the text of this script. This case will never be run,
96 # since it is checked for above.
97 exit 1
100 dashmd)
101 # The Java front end to gcc doesn't run cpp, so we can't use the -Wp
102 # trick. Instead we must use -M and then rename the resulting .d
103 # file. This is also the case for older versions of gcc, which
104 # don't implement -Wp.
105 if "$@" -MD; then :
106 else
107 stat=$?
108 rm -f FIXME
109 exit $stat
111 FIXME: rewrite the file
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 stat=$?
124 rm -f "$tmpdepfile"
125 exit $stat
127 rm -f "$depfile"
129 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
130 echo "$object : \\" > "$depfile"
132 # Clip off the initial element (the dependent). Don't try to be
133 # clever and replace this with sed code, as IRIX sed won't handle
134 # lines with more than a fixed number of characters (4096 in
135 # IRIX 6.2 sed, 8192 in IRIX 6.5).
136 tr ' ' '
137 ' < "$tmpdepfile" | sed 's/^[^\.]*\.o://' | tr '
138 ' ' ' >> $depfile
140 tr ' ' '
141 ' < "$tmpdepfile" | \
142 ## Some versions of the HPUX 10.20 sed can't process this invocation
143 ## correctly. Breaking it into two sed invocations is a workaround.
144 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
145 else
146 # The sourcefile does not contain any dependencies, so just
147 # store a dummy comment line, to avoid errors with the Makefile
148 # "include basename.Plo" scheme.
149 echo "#dummy" > "$depfile"
151 rm -f "$tmpdepfile"
154 #nosideeffect)
155 # This comment above is used by automake to tell side-effect
156 # dependency tracking mechanisms from slower ones.
158 dashmstdout)
159 # Important note: in order to support this mode, a compiler *must*
160 # always write the proprocessed file to stdout, regardless of -o,
161 # because we must use -o when running libtool.
162 test -z "$dashmflag" && dashmflag=-M
163 ( IFS=" "
164 case " $* " in
165 *" --mode=compile "*) # this is libtool, let us make it quiet
166 for arg
167 do # cycle over the arguments
168 case "$arg" in
169 "--mode=compile")
170 # insert --quiet before "--mode=compile"
171 set fnord "$@" --quiet
172 shift # fnord
174 esac
175 set fnord "$@" "$arg"
176 shift # fnord
177 shift # "$arg"
178 done
180 esac
181 "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
183 proc=$!
184 "$@"
185 stat=$?
186 wait "$proc"
187 if test "$stat" != 0; then exit $stat; fi
188 rm -f "$depfile"
189 cat < "$tmpdepfile" > "$depfile"
190 tr ' ' '
191 ' < "$tmpdepfile" | \
192 ## Some versions of the HPUX 10.20 sed can't process this invocation
193 ## correctly. Breaking it into two sed invocations is a workaround.
194 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
195 rm -f "$tmpdepfile"
198 dashXmstdout)
199 # This case only exists to satisfy depend.m4. It is never actually
200 # run, as this mode is specially recognized in the preamble.
201 exit 1
204 makedepend)
205 # X makedepend
207 shift
208 cleared=no
209 for arg in "$@"; do
210 case $cleared in no)
211 set ""; shift
212 cleared=yes
213 esac
214 case "$arg" in
215 -D*|-I*)
216 set fnord "$@" "$arg"; shift;;
220 set fnord "$@" "$arg"; shift;;
221 esac
222 done
223 obj_suffix="`echo $object | sed 's/^.*\././'`"
224 touch "$tmpdepfile"
225 ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
227 proc=$!
228 "$@"
229 stat=$?
230 wait "$proc"
231 if test "$stat" != 0; then exit $stat; fi
232 rm -f "$depfile"
233 cat < "$tmpdepfile" > "$depfile"
234 tail +3 "$tmpdepfile" | tr ' ' '
235 ' | \
236 ## Some versions of the HPUX 10.20 sed can't process this invocation
237 ## correctly. Breaking it into two sed invocations is a workaround.
238 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
239 rm -f "$tmpdepfile" "$tmpdepfile".bak
242 cpp)
243 # Important note: in order to support this mode, a compiler *must*
244 # always write the proprocessed file to stdout, regardless of -o,
245 # because we must use -o when running libtool.
246 ( IFS=" "
247 case " $* " in
248 *" --mode=compile "*)
249 for arg
250 do # cycle over the arguments
251 case $arg in
252 "--mode=compile")
253 # insert --quiet before "--mode=compile"
254 set fnord "$@" --quiet
255 shift # fnord
257 esac
258 set fnord "$@" "$arg"
259 shift # fnord
260 shift # "$arg"
261 done
263 esac
264 "$@" -E |
265 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
266 sed '$ s: \\$::' > "$tmpdepfile"
268 proc=$!
269 "$@"
270 stat=$?
271 wait "$proc"
272 if test "$stat" != 0; then exit $stat; fi
273 rm -f "$depfile"
274 echo "$object : \\" > "$depfile"
275 cat < "$tmpdepfile" >> "$depfile"
276 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
277 rm -f "$tmpdepfile"
280 msvisualcpp)
281 # Important note: in order to support this mode, a compiler *must*
282 # always write the proprocessed file to stdout, regardless of -o,
283 # because we must use -o when running libtool.
284 ( IFS=" "
285 case " $* " in
286 *" --mode=compile "*)
287 for arg
288 do # cycle over the arguments
289 case $arg in
290 "--mode=compile")
291 # insert --quiet before "--mode=compile"
292 set fnord "$@" --quiet
293 shift # fnord
295 esac
296 set fnord "$@" "$arg"
297 shift # fnord
298 shift # "$arg"
299 done
301 esac
302 "$@" -E |
303 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
305 proc=$!
306 "$@"
307 stat=$?
308 wait "$proc"
309 if test "$stat" != 0; then exit $stat; fi
310 rm -f "$depfile"
311 echo "$object : \\" > "$depfile"
312 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
313 echo " " >> "$depfile"
314 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
315 rm -f "$tmpdepfile"
318 none)
319 exec "$@"
323 echo "Unknown depmode $depmode" 1>&2
324 exit 1
326 esac
328 exit 0