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