* confh4.test: Corrected final test.
[automake.git] / depcomp
blobeb42e39501f908aa9c0fc8889ef26ebd96ffc3c7
1 #! /bin/sh
3 # depcomp - compile a program generating dependencies as side-effects
4 # Copyright (C) 1999 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
28 depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
29 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
31 rm -f "$tmpdepfile"
33 if test "$depmode" = hp; then
34 # HP compiler uses -M and no extra arg.
35 gccflag=-M
36 depmode=gcc
39 case "$depmode" in
40 hp)
41 # This case exists only to let depend.m4 do its work. It works by
42 # looking at the text of this script. This case will never be run,
43 # since it is checked for above.
44 exit 1
47 gcc)
48 ## There are various ways to get dependency output from gcc. Here's
49 ## why we pick this rather obscure method:
50 ## - Don't want to use -MD because we'd like the dependencies to end
51 ## up in a subdir. Having to rename by hand is ugly.
52 ## (We might end up doing this anyway to support other compilers.)
53 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
54 ## -MM, not -M (despite what the docs say).
55 ## - Using -M directly means running the compiler twice (even worse
56 ## than renaming).
57 if test -z "$gccflag"; then
58 gccflag=-MD,
60 if "$@" -Wp,"$gccflag$tmpdepfile"; then :
61 else
62 stat=$?
63 rm -f "$tmpdepfile"
64 exit $stat
66 rm -f "$depfile"
67 echo "$object : \\" > "$depfile"
68 sed 's/^[^:]*: / /' < "$tmpdepfile" >> "$depfile"
69 ## This next piece of magic avoids the `deleted header file' problem.
70 ## The problem is that when a header file which appears in a .P file
71 ## is deleted, the dependency causes make to die (because there is
72 ## typically no way to rebuild the header). We avoid this by adding
73 ## dummy dependencies for each header file. Too bad gcc doesn't do
74 ## this for us directly.
75 tr ' ' '
76 ' < "$tmpdepfile" |
77 ## Some versions of gcc put a space before the `:'. On the theory
78 ## that the space means something, we add a space to the output as
79 ## well.
80 ## Some versions of the HPUX 10.20 sed can't process this invocation
81 ## correctly. Breaking it into two sed invocations is a workaround.
82 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
83 rm -f "$tmpdepfile"
86 dashmd)
87 # The Java front end to gcc doesn't run cpp, so we can't use the -Wp
88 # trick. Instead we must use -M and then rename the resulting .d
89 # file. This is also the case for older versions of gcc, which
90 # don't implement -Wp.
91 if "$@" -MD; then :
92 else
93 stat=$?
94 rm -f FIXME
95 exit $stat
97 FIXME: rewrite the file
100 sgi)
101 if "$@" -MDupdate "$tmpdepfile"; then :
102 else
103 stat=$?
104 rm -f "$tmpdepfile"
105 exit $stat
107 rm -f "$depfile"
108 echo "$object : \\" > "$depfile"
109 sed 's/^[^:]*: / /' < "$tmpdepfile" >> "$depfile"
110 tr ' ' '
111 ' < "$tmpdepfile" | \
112 ## Some versions of the HPUX 10.20 sed can't process this invocation
113 ## correctly. Breaking it into two sed invocations is a workaround.
114 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
115 rm -f "$tmpdepfile"
118 #nosideeffect)
119 # This comment above is used by automake to tell side-effect
120 # dependency tracking mechanisms from slower ones.
122 dashmstdout)
123 # Important note: in order to support this mode, a compiler *must*
124 # always write the proprocessed file to stdout, regardless of -o,
125 # because we must use -o when running libtool.
126 ( IFS=" "
127 case " $* " in
128 *" --mode=compile "*) # this is libtool, let us make it quiet
129 for arg
130 do # cycle over the arguments
131 case "$arg" in
132 "--mode=compile")
133 # insert --quiet before "--mode=compile"
134 set fnord "$@" --quiet
135 shift # fnord
137 esac
138 set fnord "$@" "$arg"
139 shift # fnord
140 shift # "$arg"
141 done
143 esac
144 "$@" -M | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
146 proc=$!
147 "$@"
148 stat=$?
149 wait "$proc"
150 if test "$stat" != 0; then exit $stat; fi
151 rm -f "$depfile"
152 cat < "$tmpdepfile" > "$depfile"
153 tr ' ' '
154 ' < "$tmpdepfile" | \
155 ## Some versions of the HPUX 10.20 sed can't process this invocation
156 ## correctly. Breaking it into two sed invocations is a workaround.
157 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
158 rm -f "$tmpdepfile"
161 dashXmstdout)
162 # Important note: in order to support this mode, a compiler *must*
163 # always write the proprocessed file to stdout, regardless of -o,
164 # because we must use -o when running libtool.
165 ( IFS=" "
166 case " $* " in
167 *" --mode=compile "*) # this is libtool, let us make it quiet
168 for arg
169 do # cycle over the arguments
170 case "$arg" in
171 "--mode=compile")
172 # insert --quiet before "--mode=compile"
173 set fnord "$@" --quiet
174 shift # fnord
176 esac
177 set fnord "$@" "$arg"
178 shift # fnord
179 shift # "$arg"
180 done
182 esac
183 "$@" -xM | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
185 proc=$!
186 "$@"
187 stat=$?
188 wait "$proc"
189 if test "$stat" != 0; then exit $stat; fi
190 rm -f "$depfile"
191 cat < "$tmpdepfile" > "$depfile"
192 tr ' ' '
193 ' < "$tmpdepfile" | \
194 ## Some versions of the HPUX 10.20 sed can't process this invocation
195 ## correctly. Breaking it into two sed invocations is a workaround.
196 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
197 rm -f "$tmpdepfile"
200 makedepend)
201 # X makedepend
203 shift
204 cleared=no
205 for arg in "$@"; do
206 case $cleared in no)
207 set ""; shift
208 cleared=yes
209 esac
210 case "$arg" in
211 -D*|-I*)
212 set fnord "$@" "$arg"; shift;;
216 set fnord "$@" "$arg"; shift;;
217 esac
218 done
219 obj_suffix="`echo $object | sed 's/^.*\././'`"
220 touch "$tmpdepfile"
221 ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
223 proc=$!
224 "$@"
225 stat=$?
226 wait "$proc"
227 if test "$stat" != 0; then exit $stat; fi
228 rm -f "$depfile"
229 cat < "$tmpdepfile" > "$depfile"
230 tail +3 "$tmpdepfile" | tr ' ' '
231 ' | \
232 ## Some versions of the HPUX 10.20 sed can't process this invocation
233 ## correctly. Breaking it into two sed invocations is a workaround.
234 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
235 rm -f "$tmpdepfile" "$tmpdepfile".bak
238 cpp)
239 # Important note: in order to support this mode, a compiler *must*
240 # always write the proprocessed file to stdout, regardless of -o,
241 # because we must use -o when running libtool.
242 ( IFS=" "
243 case " $* " in
244 *" --mode=compile "*)
245 for arg
246 do # cycle over the arguments
247 case "$arg" in
248 "--mode=compile")
249 # insert --quiet before "--mode=compile"
250 set fnord "$@" --quiet
251 shift # fnord
253 esac
254 set fnord "$@" "$arg"
255 shift # fnord
256 shift # "$arg"
257 done
259 esac
260 "$@" -E |
261 sed -n '/^# [0-9][0-9]* "\([^"]*\)"/ s::'"$object"'\: \1:p' > "$tmpdepfile"
263 proc=$!
264 "$@"
265 stat=$?
266 wait "$proc"
267 if test "$stat" != 0; then exit $stat; fi
268 rm -f "$depfile"
269 cat < "$tmpdepfile" > "$depfile"
270 sed < "$tmpdepfile" -e 's/^[^:]*: //' -e 's/$/ :/' >> "$depfile"
271 rm -f "$tmpdepfile"
274 none)
275 exec "$@"
279 echo "Unknown depmode $depmode" 1>&2
280 exit 1
282 esac
284 exit 0