]> jfr.im git - irc/evilnet/x3.git/blame - rx/depcomp
Couple of srvx updates.
[irc/evilnet/x3.git] / rx / depcomp
CommitLineData
d76ed9a9 1#! /bin/sh
2
3# depcomp - compile a program generating dependencies as side-effects
4# Copyright 1999, 2000 Free Software Foundation, Inc.
5
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.
10
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.
15
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.
20
21# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
22
23if 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
26fi
27# `libtool' can also be set to `yes' or `no'.
28
29depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
30tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
31
32rm -f "$tmpdepfile"
33
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.
38if test "$depmode" = hp; then
39 # HP compiler uses -M and no extra arg.
40 gccflag=-M
41 depmode=gcc
42fi
43
44if test "$depmode" = dashXmstdout; then
45 # This is just like dashmstdout with a different argument.
46 dashmflag=-xM
47 depmode=dashmstdout
48fi
49
50case "$depmode" in
51gcc3)
52## gcc 3 implements dependency tracking that does exactly what
53## we want. Yay!
54 if "$@" -MT "$object" -MF "$depfile" -MD -MP; then
55 exit $?
56 fi
57 ;;
58
59gcc)
60## There are various ways to get dependency output from gcc. Here's
61## why we pick this rather obscure method:
62## - Don't want to use -MD because we'd like the dependencies to end
63## up in a subdir. Having to rename by hand is ugly.
64## (We might end up doing this anyway to support other compilers.)
65## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
66## -MM, not -M (despite what the docs say).
67## - Using -M directly means running the compiler twice (even worse
68## than renaming).
69 if test -z "$gccflag"; then
70 gccflag=-MD,
71 fi
72 if "$@" -Wp,"$gccflag$tmpdepfile"; then :
73 else
74 stat=$?
75 rm -f "$tmpdepfile"
76 exit $stat
77 fi
78 rm -f "$depfile"
79 echo "$object : \\" > "$depfile"
80 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
81## The second -e expression handles DOS-style file names with drive letters.
82 sed -e 's/^[^:]*: / /' \
83 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
84## This next piece of magic avoids the `deleted header file' problem.
85## The problem is that when a header file which appears in a .P file
86## is deleted, the dependency causes make to die (because there is
87## typically no way to rebuild the header). We avoid this by adding
88## dummy dependencies for each header file. Too bad gcc doesn't do
89## this for us directly.
90 tr ' ' '
91' < "$tmpdepfile" |
92## Some versions of gcc put a space before the `:'. On the theory
93## that the space means something, we add a space to the output as
94## well.
95## Some versions of the HPUX 10.20 sed can't process this invocation
96## correctly. Breaking it into two sed invocations is a workaround.
97 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
98 rm -f "$tmpdepfile"
99 ;;
100
101hp)
102 # This case exists only to let depend.m4 do its work. It works by
103 # looking at the text of this script. This case will never be run,
104 # since it is checked for above.
105 exit 1
106 ;;
107
108dashmd)
109 # The Java front end to gcc doesn't run cpp, so we can't use the -Wp
110 # trick. Instead we must use -M and then rename the resulting .d
111 # file. This is also the case for older versions of gcc, which
112 # don't implement -Wp.
113 if "$@" -MD; then :
114 else
115 stat=$?
116 rm -f FIXME
117 exit $stat
118 fi
119 FIXME: rewrite the file
120 ;;
121
122sgi)
123 if test "$libtool" = yes; then
124 "$@" "-Wp,-MDupdate,$tmpdepfile"
125 else
126 "$@" -MDupdate "$tmpdepfile"
127 fi
128 stat=$?
129 if test $stat -eq 0; then :
130 else
131 stat=$?
132 rm -f "$tmpdepfile"
133 exit $stat
134 fi
135 rm -f "$depfile"
136
137 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
138 echo "$object : \\" > "$depfile"
139
140 # Clip off the initial element (the dependent). Don't try to be
141 # clever and replace this with sed code, as IRIX sed won't handle
142 # lines with more than a fixed number of characters (4096 in
143 # IRIX 6.2 sed, 8192 in IRIX 6.5).
144 tr ' ' '
145' < "$tmpdepfile" | sed 's/^[^\.]*\.o://' | tr '
146' ' ' >> $depfile
147
148 tr ' ' '
149' < "$tmpdepfile" | \
150## Some versions of the HPUX 10.20 sed can't process this invocation
151## correctly. Breaking it into two sed invocations is a workaround.
152 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
153 else
154 # The sourcefile does not contain any dependencies, so just
155 # store a dummy comment line, to avoid errors with the Makefile
156 # "include basename.Plo" scheme.
157 echo "#dummy" > "$depfile"
158 fi
159 rm -f "$tmpdepfile"
160 ;;
161
162#nosideeffect)
163 # This comment above is used by automake to tell side-effect
164 # dependency tracking mechanisms from slower ones.
165
166dashmstdout)
167 # Important note: in order to support this mode, a compiler *must*
168 # always write the proprocessed file to stdout, regardless of -o,
169 # because we must use -o when running libtool.
170 test -z "$dashmflag" && dashmflag=-M
171 ( IFS=" "
172 case " $* " in
173 *" --mode=compile "*) # this is libtool, let us make it quiet
174 for arg
175 do # cycle over the arguments
176 case "$arg" in
177 "--mode=compile")
178 # insert --quiet before "--mode=compile"
179 set fnord "$@" --quiet
180 shift # fnord
181 ;;
182 esac
183 set fnord "$@" "$arg"
184 shift # fnord
185 shift # "$arg"
186 done
187 ;;
188 esac
189 "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
190 ) &
191 proc=$!
192 "$@"
193 stat=$?
194 wait "$proc"
195 if test "$stat" != 0; then exit $stat; fi
196 rm -f "$depfile"
197 cat < "$tmpdepfile" > "$depfile"
198 tr ' ' '
199' < "$tmpdepfile" | \
200## Some versions of the HPUX 10.20 sed can't process this invocation
201## correctly. Breaking it into two sed invocations is a workaround.
202 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
203 rm -f "$tmpdepfile"
204 ;;
205
206dashXmstdout)
207 # This case only exists to satisfy depend.m4. It is never actually
208 # run, as this mode is specially recognized in the preamble.
209 exit 1
210 ;;
211
212makedepend)
213 # X makedepend
214 (
215 shift
216 cleared=no
217 for arg in "$@"; do
218 case $cleared in no)
219 set ""; shift
220 cleared=yes
221 esac
222 case "$arg" in
223 -D*|-I*)
224 set fnord "$@" "$arg"; shift;;
225 -*)
226 ;;
227 *)
228 set fnord "$@" "$arg"; shift;;
229 esac
230 done
231 obj_suffix="`echo $object | sed 's/^.*\././'`"
232 touch "$tmpdepfile"
233 ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
234 ) &
235 proc=$!
236 "$@"
237 stat=$?
238 wait "$proc"
239 if test "$stat" != 0; then exit $stat; fi
240 rm -f "$depfile"
241 cat < "$tmpdepfile" > "$depfile"
242 tail +3 "$tmpdepfile" | tr ' ' '
243' | \
244## Some versions of the HPUX 10.20 sed can't process this invocation
245## correctly. Breaking it into two sed invocations is a workaround.
246 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
247 rm -f "$tmpdepfile" "$tmpdepfile".bak
248 ;;
249
250cpp)
251 # Important note: in order to support this mode, a compiler *must*
252 # always write the proprocessed file to stdout, regardless of -o,
253 # because we must use -o when running libtool.
254 ( IFS=" "
255 case " $* " in
256 *" --mode=compile "*)
257 for arg
258 do # cycle over the arguments
259 case $arg in
260 "--mode=compile")
261 # insert --quiet before "--mode=compile"
262 set fnord "$@" --quiet
263 shift # fnord
264 ;;
265 esac
266 set fnord "$@" "$arg"
267 shift # fnord
268 shift # "$arg"
269 done
270 ;;
271 esac
272 "$@" -E |
273 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
274 sed '$ s: \\$::' > "$tmpdepfile"
275 ) &
276 proc=$!
277 "$@"
278 stat=$?
279 wait "$proc"
280 if test "$stat" != 0; then exit $stat; fi
281 rm -f "$depfile"
282 echo "$object : \\" > "$depfile"
283 cat < "$tmpdepfile" >> "$depfile"
284 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
285 rm -f "$tmpdepfile"
286 ;;
287
288msvisualcpp)
289 # Important note: in order to support this mode, a compiler *must*
290 # always write the proprocessed file to stdout, regardless of -o,
291 # because we must use -o when running libtool.
292 ( IFS=" "
293 case " $* " in
294 *" --mode=compile "*)
295 for arg
296 do # cycle over the arguments
297 case $arg in
298 "--mode=compile")
299 # insert --quiet before "--mode=compile"
300 set fnord "$@" --quiet
301 shift # fnord
302 ;;
303 esac
304 set fnord "$@" "$arg"
305 shift # fnord
306 shift # "$arg"
307 done
308 ;;
309 esac
310 "$@" -E |
311 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
312 ) &
313 proc=$!
314 "$@"
315 stat=$?
316 wait "$proc"
317 if test "$stat" != 0; then exit $stat; fi
318 rm -f "$depfile"
319 echo "$object : \\" > "$depfile"
320 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
321 echo " " >> "$depfile"
322 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
323 rm -f "$tmpdepfile"
324 ;;
325
326none)
327 exec "$@"
328 ;;
329
330*)
331 echo "Unknown depmode $depmode" 1>&2
332 exit 1
333 ;;
334esac
335
336exit 0