depcomp revision 1.5 1 1.1 mrg #! /bin/sh
2 1.1 mrg # depcomp - compile a program generating dependencies as side-effects
3 1.1 mrg
4 1.5 mrg scriptversion=2013-05-30.07; # UTC
5 1.1 mrg
6 1.5 mrg # Copyright (C) 1999-2014 Free Software Foundation, Inc.
7 1.1 mrg
8 1.1 mrg # This program is free software; you can redistribute it and/or modify
9 1.1 mrg # it under the terms of the GNU General Public License as published by
10 1.1 mrg # the Free Software Foundation; either version 2, or (at your option)
11 1.1 mrg # any later version.
12 1.1 mrg
13 1.1 mrg # This program is distributed in the hope that it will be useful,
14 1.1 mrg # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 1.1 mrg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 1.1 mrg # GNU General Public License for more details.
17 1.1 mrg
18 1.1 mrg # You should have received a copy of the GNU General Public License
19 1.1 mrg # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 1.1 mrg
21 1.1 mrg # As a special exception to the GNU General Public License, if you
22 1.1 mrg # distribute this file as part of a program that contains a
23 1.1 mrg # configuration script generated by Autoconf, you may include it under
24 1.1 mrg # the same distribution terms that you use for the rest of that program.
25 1.1 mrg
26 1.1 mrg # Originally written by Alexandre Oliva <oliva (at] dcc.unicamp.br>.
27 1.1 mrg
28 1.1 mrg case $1 in
29 1.1 mrg '')
30 1.5 mrg echo "$0: No command. Try '$0 --help' for more information." 1>&2
31 1.5 mrg exit 1;
32 1.5 mrg ;;
33 1.1 mrg -h | --h*)
34 1.1 mrg cat <<\EOF
35 1.1 mrg Usage: depcomp [--help] [--version] PROGRAM [ARGS]
36 1.1 mrg
37 1.1 mrg Run PROGRAMS ARGS to compile a file, generating dependencies
38 1.1 mrg as side-effects.
39 1.1 mrg
40 1.1 mrg Environment variables:
41 1.1 mrg depmode Dependency tracking mode.
42 1.5 mrg source Source file read by 'PROGRAMS ARGS'.
43 1.5 mrg object Object file output by 'PROGRAMS ARGS'.
44 1.1 mrg DEPDIR directory where to store dependencies.
45 1.1 mrg depfile Dependency file to output.
46 1.5 mrg tmpdepfile Temporary file to use when outputting dependencies.
47 1.1 mrg libtool Whether libtool is used (yes/no).
48 1.1 mrg
49 1.1 mrg Report bugs to <bug-automake@gnu.org>.
50 1.1 mrg EOF
51 1.1 mrg exit $?
52 1.1 mrg ;;
53 1.1 mrg -v | --v*)
54 1.1 mrg echo "depcomp $scriptversion"
55 1.1 mrg exit $?
56 1.1 mrg ;;
57 1.1 mrg esac
58 1.1 mrg
59 1.5 mrg # Get the directory component of the given path, and save it in the
60 1.5 mrg # global variables '$dir'. Note that this directory component will
61 1.5 mrg # be either empty or ending with a '/' character. This is deliberate.
62 1.5 mrg set_dir_from ()
63 1.5 mrg {
64 1.5 mrg case $1 in
65 1.5 mrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66 1.5 mrg *) dir=;;
67 1.5 mrg esac
68 1.5 mrg }
69 1.5 mrg
70 1.5 mrg # Get the suffix-stripped basename of the given path, and save it the
71 1.5 mrg # global variable '$base'.
72 1.5 mrg set_base_from ()
73 1.5 mrg {
74 1.5 mrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75 1.5 mrg }
76 1.5 mrg
77 1.5 mrg # If no dependency file was actually created by the compiler invocation,
78 1.5 mrg # we still have to create a dummy depfile, to avoid errors with the
79 1.5 mrg # Makefile "include basename.Plo" scheme.
80 1.5 mrg make_dummy_depfile ()
81 1.5 mrg {
82 1.5 mrg echo "#dummy" > "$depfile"
83 1.5 mrg }
84 1.5 mrg
85 1.5 mrg # Factor out some common post-processing of the generated depfile.
86 1.5 mrg # Requires the auxiliary global variable '$tmpdepfile' to be set.
87 1.5 mrg aix_post_process_depfile ()
88 1.5 mrg {
89 1.5 mrg # If the compiler actually managed to produce a dependency file,
90 1.5 mrg # post-process it.
91 1.5 mrg if test -f "$tmpdepfile"; then
92 1.5 mrg # Each line is of the form 'foo.o: dependency.h'.
93 1.5 mrg # Do two passes, one to just change these to
94 1.5 mrg # $object: dependency.h
95 1.5 mrg # and one to simply output
96 1.5 mrg # dependency.h:
97 1.5 mrg # which is needed to avoid the deleted-header problem.
98 1.5 mrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99 1.5 mrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100 1.5 mrg } > "$depfile"
101 1.5 mrg rm -f "$tmpdepfile"
102 1.5 mrg else
103 1.5 mrg make_dummy_depfile
104 1.5 mrg fi
105 1.5 mrg }
106 1.5 mrg
107 1.5 mrg # A tabulation character.
108 1.5 mrg tab=' '
109 1.5 mrg # A newline character.
110 1.5 mrg nl='
111 1.5 mrg '
112 1.5 mrg # Character ranges might be problematic outside the C locale.
113 1.5 mrg # These definitions help.
114 1.5 mrg upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115 1.5 mrg lower=abcdefghijklmnopqrstuvwxyz
116 1.5 mrg digits=0123456789
117 1.5 mrg alpha=${upper}${lower}
118 1.5 mrg
119 1.1 mrg if test -z "$depmode" || test -z "$source" || test -z "$object"; then
120 1.1 mrg echo "depcomp: Variables source, object and depmode must be set" 1>&2
121 1.1 mrg exit 1
122 1.1 mrg fi
123 1.1 mrg
124 1.1 mrg # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125 1.1 mrg depfile=${depfile-`echo "$object" |
126 1.1 mrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127 1.1 mrg tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128 1.1 mrg
129 1.1 mrg rm -f "$tmpdepfile"
130 1.1 mrg
131 1.5 mrg # Avoid interferences from the environment.
132 1.5 mrg gccflag= dashmflag=
133 1.5 mrg
134 1.1 mrg # Some modes work just like other modes, but use different flags. We
135 1.1 mrg # parameterize here, but still list the modes in the big case below,
136 1.1 mrg # to make depend.m4 easier to write. Note that we *cannot* use a case
137 1.1 mrg # here, because this file can only contain one case statement.
138 1.1 mrg if test "$depmode" = hp; then
139 1.1 mrg # HP compiler uses -M and no extra arg.
140 1.1 mrg gccflag=-M
141 1.1 mrg depmode=gcc
142 1.1 mrg fi
143 1.1 mrg
144 1.1 mrg if test "$depmode" = dashXmstdout; then
145 1.5 mrg # This is just like dashmstdout with a different argument.
146 1.5 mrg dashmflag=-xM
147 1.5 mrg depmode=dashmstdout
148 1.1 mrg fi
149 1.1 mrg
150 1.1 mrg cygpath_u="cygpath -u -f -"
151 1.1 mrg if test "$depmode" = msvcmsys; then
152 1.5 mrg # This is just like msvisualcpp but w/o cygpath translation.
153 1.5 mrg # Just convert the backslash-escaped backslashes to single forward
154 1.5 mrg # slashes to satisfy depend.m4
155 1.5 mrg cygpath_u='sed s,\\\\,/,g'
156 1.5 mrg depmode=msvisualcpp
157 1.5 mrg fi
158 1.5 mrg
159 1.5 mrg if test "$depmode" = msvc7msys; then
160 1.5 mrg # This is just like msvc7 but w/o cygpath translation.
161 1.5 mrg # Just convert the backslash-escaped backslashes to single forward
162 1.5 mrg # slashes to satisfy depend.m4
163 1.5 mrg cygpath_u='sed s,\\\\,/,g'
164 1.5 mrg depmode=msvc7
165 1.5 mrg fi
166 1.5 mrg
167 1.5 mrg if test "$depmode" = xlc; then
168 1.5 mrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169 1.5 mrg gccflag=-qmakedep=gcc,-MF
170 1.5 mrg depmode=gcc
171 1.1 mrg fi
172 1.1 mrg
173 1.1 mrg case "$depmode" in
174 1.1 mrg gcc3)
175 1.1 mrg ## gcc 3 implements dependency tracking that does exactly what
176 1.1 mrg ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
177 1.1 mrg ## it if -MD -MP comes after the -MF stuff. Hmm.
178 1.1 mrg ## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179 1.1 mrg ## the command line argument order; so add the flags where they
180 1.1 mrg ## appear in depend2.am. Note that the slowdown incurred here
181 1.1 mrg ## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182 1.1 mrg for arg
183 1.1 mrg do
184 1.1 mrg case $arg in
185 1.1 mrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186 1.1 mrg *) set fnord "$@" "$arg" ;;
187 1.1 mrg esac
188 1.1 mrg shift # fnord
189 1.1 mrg shift # $arg
190 1.1 mrg done
191 1.1 mrg "$@"
192 1.1 mrg stat=$?
193 1.5 mrg if test $stat -ne 0; then
194 1.1 mrg rm -f "$tmpdepfile"
195 1.1 mrg exit $stat
196 1.1 mrg fi
197 1.1 mrg mv "$tmpdepfile" "$depfile"
198 1.1 mrg ;;
199 1.1 mrg
200 1.1 mrg gcc)
201 1.5 mrg ## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202 1.5 mrg ## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203 1.5 mrg ## (see the conditional assignment to $gccflag above).
204 1.1 mrg ## There are various ways to get dependency output from gcc. Here's
205 1.1 mrg ## why we pick this rather obscure method:
206 1.1 mrg ## - Don't want to use -MD because we'd like the dependencies to end
207 1.1 mrg ## up in a subdir. Having to rename by hand is ugly.
208 1.1 mrg ## (We might end up doing this anyway to support other compilers.)
209 1.1 mrg ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210 1.5 mrg ## -MM, not -M (despite what the docs say). Also, it might not be
211 1.5 mrg ## supported by the other compilers which use the 'gcc' depmode.
212 1.1 mrg ## - Using -M directly means running the compiler twice (even worse
213 1.1 mrg ## than renaming).
214 1.1 mrg if test -z "$gccflag"; then
215 1.1 mrg gccflag=-MD,
216 1.1 mrg fi
217 1.1 mrg "$@" -Wp,"$gccflag$tmpdepfile"
218 1.1 mrg stat=$?
219 1.5 mrg if test $stat -ne 0; then
220 1.1 mrg rm -f "$tmpdepfile"
221 1.1 mrg exit $stat
222 1.1 mrg fi
223 1.1 mrg rm -f "$depfile"
224 1.1 mrg echo "$object : \\" > "$depfile"
225 1.5 mrg # The second -e expression handles DOS-style file names with drive
226 1.5 mrg # letters.
227 1.1 mrg sed -e 's/^[^:]*: / /' \
228 1.1 mrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229 1.5 mrg ## This next piece of magic avoids the "deleted header file" problem.
230 1.1 mrg ## The problem is that when a header file which appears in a .P file
231 1.1 mrg ## is deleted, the dependency causes make to die (because there is
232 1.1 mrg ## typically no way to rebuild the header). We avoid this by adding
233 1.1 mrg ## dummy dependencies for each header file. Too bad gcc doesn't do
234 1.1 mrg ## this for us directly.
235 1.5 mrg ## Some versions of gcc put a space before the ':'. On the theory
236 1.1 mrg ## that the space means something, we add a space to the output as
237 1.5 mrg ## well. hp depmode also adds that space, but also prefixes the VPATH
238 1.5 mrg ## to the object. Take care to not repeat it in the output.
239 1.1 mrg ## Some versions of the HPUX 10.20 sed can't process this invocation
240 1.1 mrg ## correctly. Breaking it into two sed invocations is a workaround.
241 1.5 mrg tr ' ' "$nl" < "$tmpdepfile" \
242 1.5 mrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243 1.5 mrg | sed -e 's/$/ :/' >> "$depfile"
244 1.1 mrg rm -f "$tmpdepfile"
245 1.1 mrg ;;
246 1.1 mrg
247 1.1 mrg hp)
248 1.1 mrg # This case exists only to let depend.m4 do its work. It works by
249 1.1 mrg # looking at the text of this script. This case will never be run,
250 1.1 mrg # since it is checked for above.
251 1.1 mrg exit 1
252 1.1 mrg ;;
253 1.1 mrg
254 1.5 mrg xlc)
255 1.5 mrg # This case exists only to let depend.m4 do its work. It works by
256 1.5 mrg # looking at the text of this script. This case will never be run,
257 1.5 mrg # since it is checked for above.
258 1.5 mrg exit 1
259 1.1 mrg ;;
260 1.1 mrg
261 1.1 mrg aix)
262 1.1 mrg # The C for AIX Compiler uses -M and outputs the dependencies
263 1.1 mrg # in a .u file. In older versions, this file always lives in the
264 1.5 mrg # current directory. Also, the AIX compiler puts '$object:' at the
265 1.1 mrg # start of each line; $object doesn't have directory information.
266 1.1 mrg # Version 6 uses the directory in both cases.
267 1.5 mrg set_dir_from "$object"
268 1.5 mrg set_base_from "$object"
269 1.1 mrg if test "$libtool" = yes; then
270 1.1 mrg tmpdepfile1=$dir$base.u
271 1.1 mrg tmpdepfile2=$base.u
272 1.1 mrg tmpdepfile3=$dir.libs/$base.u
273 1.1 mrg "$@" -Wc,-M
274 1.1 mrg else
275 1.1 mrg tmpdepfile1=$dir$base.u
276 1.1 mrg tmpdepfile2=$dir$base.u
277 1.1 mrg tmpdepfile3=$dir$base.u
278 1.1 mrg "$@" -M
279 1.1 mrg fi
280 1.1 mrg stat=$?
281 1.5 mrg if test $stat -ne 0; then
282 1.1 mrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
283 1.1 mrg exit $stat
284 1.1 mrg fi
285 1.1 mrg
286 1.1 mrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
287 1.1 mrg do
288 1.1 mrg test -f "$tmpdepfile" && break
289 1.1 mrg done
290 1.5 mrg aix_post_process_depfile
291 1.5 mrg ;;
292 1.5 mrg
293 1.5 mrg tcc)
294 1.5 mrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
295 1.5 mrg # FIXME: That version still under development at the moment of writing.
296 1.5 mrg # Make that this statement remains true also for stable, released
297 1.5 mrg # versions.
298 1.5 mrg # It will wrap lines (doesn't matter whether long or short) with a
299 1.5 mrg # trailing '\', as in:
300 1.5 mrg #
301 1.5 mrg # foo.o : \
302 1.5 mrg # foo.c \
303 1.5 mrg # foo.h \
304 1.5 mrg #
305 1.5 mrg # It will put a trailing '\' even on the last line, and will use leading
306 1.5 mrg # spaces rather than leading tabs (at least since its commit 0394caf7
307 1.5 mrg # "Emit spaces for -MD").
308 1.5 mrg "$@" -MD -MF "$tmpdepfile"
309 1.5 mrg stat=$?
310 1.5 mrg if test $stat -ne 0; then
311 1.5 mrg rm -f "$tmpdepfile"
312 1.5 mrg exit $stat
313 1.1 mrg fi
314 1.5 mrg rm -f "$depfile"
315 1.5 mrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
316 1.5 mrg # We have to change lines of the first kind to '$object: \'.
317 1.5 mrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
318 1.5 mrg # And for each line of the second kind, we have to emit a 'dep.h:'
319 1.5 mrg # dummy dependency, to avoid the deleted-header problem.
320 1.5 mrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
321 1.1 mrg rm -f "$tmpdepfile"
322 1.1 mrg ;;
323 1.1 mrg
324 1.5 mrg ## The order of this option in the case statement is important, since the
325 1.5 mrg ## shell code in configure will try each of these formats in the order
326 1.5 mrg ## listed in this file. A plain '-MD' option would be understood by many
327 1.5 mrg ## compilers, so we must ensure this comes after the gcc and icc options.
328 1.5 mrg pgcc)
329 1.5 mrg # Portland's C compiler understands '-MD'.
330 1.5 mrg # Will always output deps to 'file.d' where file is the root name of the
331 1.5 mrg # source file under compilation, even if file resides in a subdirectory.
332 1.5 mrg # The object file name does not affect the name of the '.d' file.
333 1.5 mrg # pgcc 10.2 will output
334 1.1 mrg # foo.o: sub/foo.c sub/foo.h
335 1.5 mrg # and will wrap long lines using '\' :
336 1.1 mrg # foo.o: sub/foo.c ... \
337 1.1 mrg # sub/foo.h ... \
338 1.1 mrg # ...
339 1.5 mrg set_dir_from "$object"
340 1.5 mrg # Use the source, not the object, to determine the base name, since
341 1.5 mrg # that's sadly what pgcc will do too.
342 1.5 mrg set_base_from "$source"
343 1.5 mrg tmpdepfile=$base.d
344 1.5 mrg
345 1.5 mrg # For projects that build the same source file twice into different object
346 1.5 mrg # files, the pgcc approach of using the *source* file root name can cause
347 1.5 mrg # problems in parallel builds. Use a locking strategy to avoid stomping on
348 1.5 mrg # the same $tmpdepfile.
349 1.5 mrg lockdir=$base.d-lock
350 1.5 mrg trap "
351 1.5 mrg echo '$0: caught signal, cleaning up...' >&2
352 1.5 mrg rmdir '$lockdir'
353 1.5 mrg exit 1
354 1.5 mrg " 1 2 13 15
355 1.5 mrg numtries=100
356 1.5 mrg i=$numtries
357 1.5 mrg while test $i -gt 0; do
358 1.5 mrg # mkdir is a portable test-and-set.
359 1.5 mrg if mkdir "$lockdir" 2>/dev/null; then
360 1.5 mrg # This process acquired the lock.
361 1.5 mrg "$@" -MD
362 1.5 mrg stat=$?
363 1.5 mrg # Release the lock.
364 1.5 mrg rmdir "$lockdir"
365 1.5 mrg break
366 1.5 mrg else
367 1.5 mrg # If the lock is being held by a different process, wait
368 1.5 mrg # until the winning process is done or we timeout.
369 1.5 mrg while test -d "$lockdir" && test $i -gt 0; do
370 1.5 mrg sleep 1
371 1.5 mrg i=`expr $i - 1`
372 1.5 mrg done
373 1.5 mrg fi
374 1.5 mrg i=`expr $i - 1`
375 1.5 mrg done
376 1.5 mrg trap - 1 2 13 15
377 1.5 mrg if test $i -le 0; then
378 1.5 mrg echo "$0: failed to acquire lock after $numtries attempts" >&2
379 1.5 mrg echo "$0: check lockdir '$lockdir'" >&2
380 1.5 mrg exit 1
381 1.5 mrg fi
382 1.1 mrg
383 1.5 mrg if test $stat -ne 0; then
384 1.1 mrg rm -f "$tmpdepfile"
385 1.1 mrg exit $stat
386 1.1 mrg fi
387 1.1 mrg rm -f "$depfile"
388 1.1 mrg # Each line is of the form `foo.o: dependent.h',
389 1.1 mrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
390 1.1 mrg # Do two passes, one to just change these to
391 1.1 mrg # `$object: dependent.h' and one to simply `dependent.h:'.
392 1.1 mrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
393 1.1 mrg # Some versions of the HPUX 10.20 sed can't process this invocation
394 1.1 mrg # correctly. Breaking it into two sed invocations is a workaround.
395 1.5 mrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
396 1.5 mrg | sed -e 's/$/ :/' >> "$depfile"
397 1.1 mrg rm -f "$tmpdepfile"
398 1.1 mrg ;;
399 1.1 mrg
400 1.1 mrg hp2)
401 1.1 mrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64
402 1.1 mrg # compilers, which have integrated preprocessors. The correct option
403 1.1 mrg # to use with these is +Maked; it writes dependencies to a file named
404 1.1 mrg # 'foo.d', which lands next to the object file, wherever that
405 1.1 mrg # happens to be.
406 1.1 mrg # Much of this is similar to the tru64 case; see comments there.
407 1.5 mrg set_dir_from "$object"
408 1.5 mrg set_base_from "$object"
409 1.1 mrg if test "$libtool" = yes; then
410 1.1 mrg tmpdepfile1=$dir$base.d
411 1.1 mrg tmpdepfile2=$dir.libs/$base.d
412 1.1 mrg "$@" -Wc,+Maked
413 1.1 mrg else
414 1.1 mrg tmpdepfile1=$dir$base.d
415 1.1 mrg tmpdepfile2=$dir$base.d
416 1.1 mrg "$@" +Maked
417 1.1 mrg fi
418 1.1 mrg stat=$?
419 1.5 mrg if test $stat -ne 0; then
420 1.1 mrg rm -f "$tmpdepfile1" "$tmpdepfile2"
421 1.1 mrg exit $stat
422 1.1 mrg fi
423 1.1 mrg
424 1.1 mrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
425 1.1 mrg do
426 1.1 mrg test -f "$tmpdepfile" && break
427 1.1 mrg done
428 1.1 mrg if test -f "$tmpdepfile"; then
429 1.5 mrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
430 1.5 mrg # Add 'dependent.h:' lines.
431 1.1 mrg sed -ne '2,${
432 1.5 mrg s/^ *//
433 1.5 mrg s/ \\*$//
434 1.5 mrg s/$/:/
435 1.5 mrg p
436 1.5 mrg }' "$tmpdepfile" >> "$depfile"
437 1.1 mrg else
438 1.5 mrg make_dummy_depfile
439 1.1 mrg fi
440 1.1 mrg rm -f "$tmpdepfile" "$tmpdepfile2"
441 1.1 mrg ;;
442 1.1 mrg
443 1.1 mrg tru64)
444 1.5 mrg # The Tru64 compiler uses -MD to generate dependencies as a side
445 1.5 mrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
446 1.5 mrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
447 1.5 mrg # dependencies in 'foo.d' instead, so we check for that too.
448 1.5 mrg # Subdirectories are respected.
449 1.5 mrg set_dir_from "$object"
450 1.5 mrg set_base_from "$object"
451 1.5 mrg
452 1.5 mrg if test "$libtool" = yes; then
453 1.5 mrg # Libtool generates 2 separate objects for the 2 libraries. These
454 1.5 mrg # two compilations output dependencies in $dir.libs/$base.o.d and
455 1.5 mrg # in $dir$base.o.d. We have to check for both files, because
456 1.5 mrg # one of the two compilations can be disabled. We should prefer
457 1.5 mrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
458 1.5 mrg # automatically cleaned when .libs/ is deleted, while ignoring
459 1.5 mrg # the former would cause a distcleancheck panic.
460 1.5 mrg tmpdepfile1=$dir$base.o.d # libtool 1.5
461 1.5 mrg tmpdepfile2=$dir.libs/$base.o.d # Likewise.
462 1.5 mrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504
463 1.5 mrg "$@" -Wc,-MD
464 1.5 mrg else
465 1.5 mrg tmpdepfile1=$dir$base.d
466 1.5 mrg tmpdepfile2=$dir$base.d
467 1.5 mrg tmpdepfile3=$dir$base.d
468 1.5 mrg "$@" -MD
469 1.5 mrg fi
470 1.5 mrg
471 1.5 mrg stat=$?
472 1.5 mrg if test $stat -ne 0; then
473 1.5 mrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
474 1.5 mrg exit $stat
475 1.5 mrg fi
476 1.5 mrg
477 1.5 mrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
478 1.5 mrg do
479 1.5 mrg test -f "$tmpdepfile" && break
480 1.5 mrg done
481 1.5 mrg # Same post-processing that is required for AIX mode.
482 1.5 mrg aix_post_process_depfile
483 1.5 mrg ;;
484 1.5 mrg
485 1.5 mrg msvc7)
486 1.5 mrg if test "$libtool" = yes; then
487 1.5 mrg showIncludes=-Wc,-showIncludes
488 1.5 mrg else
489 1.5 mrg showIncludes=-showIncludes
490 1.5 mrg fi
491 1.5 mrg "$@" $showIncludes > "$tmpdepfile"
492 1.5 mrg stat=$?
493 1.5 mrg grep -v '^Note: including file: ' "$tmpdepfile"
494 1.5 mrg if test $stat -ne 0; then
495 1.5 mrg rm -f "$tmpdepfile"
496 1.5 mrg exit $stat
497 1.5 mrg fi
498 1.5 mrg rm -f "$depfile"
499 1.5 mrg echo "$object : \\" > "$depfile"
500 1.5 mrg # The first sed program below extracts the file names and escapes
501 1.5 mrg # backslashes for cygpath. The second sed program outputs the file
502 1.5 mrg # name when reading, but also accumulates all include files in the
503 1.5 mrg # hold buffer in order to output them again at the end. This only
504 1.5 mrg # works with sed implementations that can handle large buffers.
505 1.5 mrg sed < "$tmpdepfile" -n '
506 1.5 mrg /^Note: including file: *\(.*\)/ {
507 1.5 mrg s//\1/
508 1.5 mrg s/\\/\\\\/g
509 1.5 mrg p
510 1.5 mrg }' | $cygpath_u | sort -u | sed -n '
511 1.5 mrg s/ /\\ /g
512 1.5 mrg s/\(.*\)/'"$tab"'\1 \\/p
513 1.5 mrg s/.\(.*\) \\/\1:/
514 1.5 mrg H
515 1.5 mrg $ {
516 1.5 mrg s/.*/'"$tab"'/
517 1.5 mrg G
518 1.5 mrg p
519 1.5 mrg }' >> "$depfile"
520 1.5 mrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash
521 1.5 mrg rm -f "$tmpdepfile"
522 1.5 mrg ;;
523 1.1 mrg
524 1.5 mrg msvc7msys)
525 1.5 mrg # This case exists only to let depend.m4 do its work. It works by
526 1.5 mrg # looking at the text of this script. This case will never be run,
527 1.5 mrg # since it is checked for above.
528 1.5 mrg exit 1
529 1.5 mrg ;;
530 1.1 mrg
531 1.1 mrg #nosideeffect)
532 1.1 mrg # This comment above is used by automake to tell side-effect
533 1.1 mrg # dependency tracking mechanisms from slower ones.
534 1.1 mrg
535 1.1 mrg dashmstdout)
536 1.1 mrg # Important note: in order to support this mode, a compiler *must*
537 1.1 mrg # always write the preprocessed file to stdout, regardless of -o.
538 1.1 mrg "$@" || exit $?
539 1.1 mrg
540 1.1 mrg # Remove the call to Libtool.
541 1.1 mrg if test "$libtool" = yes; then
542 1.1 mrg while test "X$1" != 'X--mode=compile'; do
543 1.1 mrg shift
544 1.1 mrg done
545 1.1 mrg shift
546 1.1 mrg fi
547 1.1 mrg
548 1.5 mrg # Remove '-o $object'.
549 1.1 mrg IFS=" "
550 1.1 mrg for arg
551 1.1 mrg do
552 1.1 mrg case $arg in
553 1.1 mrg -o)
554 1.1 mrg shift
555 1.1 mrg ;;
556 1.1 mrg $object)
557 1.1 mrg shift
558 1.1 mrg ;;
559 1.1 mrg *)
560 1.1 mrg set fnord "$@" "$arg"
561 1.1 mrg shift # fnord
562 1.1 mrg shift # $arg
563 1.1 mrg ;;
564 1.1 mrg esac
565 1.1 mrg done
566 1.1 mrg
567 1.1 mrg test -z "$dashmflag" && dashmflag=-M
568 1.5 mrg # Require at least two characters before searching for ':'
569 1.1 mrg # in the target name. This is to cope with DOS-style filenames:
570 1.5 mrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
571 1.1 mrg "$@" $dashmflag |
572 1.5 mrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
573 1.1 mrg rm -f "$depfile"
574 1.1 mrg cat < "$tmpdepfile" > "$depfile"
575 1.5 mrg # Some versions of the HPUX 10.20 sed can't process this sed invocation
576 1.5 mrg # correctly. Breaking it into two sed invocations is a workaround.
577 1.5 mrg tr ' ' "$nl" < "$tmpdepfile" \
578 1.5 mrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
579 1.5 mrg | sed -e 's/$/ :/' >> "$depfile"
580 1.1 mrg rm -f "$tmpdepfile"
581 1.1 mrg ;;
582 1.1 mrg
583 1.1 mrg dashXmstdout)
584 1.1 mrg # This case only exists to satisfy depend.m4. It is never actually
585 1.1 mrg # run, as this mode is specially recognized in the preamble.
586 1.1 mrg exit 1
587 1.1 mrg ;;
588 1.1 mrg
589 1.1 mrg makedepend)
590 1.1 mrg "$@" || exit $?
591 1.1 mrg # Remove any Libtool call
592 1.1 mrg if test "$libtool" = yes; then
593 1.1 mrg while test "X$1" != 'X--mode=compile'; do
594 1.1 mrg shift
595 1.1 mrg done
596 1.1 mrg shift
597 1.1 mrg fi
598 1.1 mrg # X makedepend
599 1.1 mrg shift
600 1.1 mrg cleared=no eat=no
601 1.1 mrg for arg
602 1.1 mrg do
603 1.1 mrg case $cleared in
604 1.1 mrg no)
605 1.1 mrg set ""; shift
606 1.1 mrg cleared=yes ;;
607 1.1 mrg esac
608 1.1 mrg if test $eat = yes; then
609 1.1 mrg eat=no
610 1.1 mrg continue
611 1.1 mrg fi
612 1.1 mrg case "$arg" in
613 1.1 mrg -D*|-I*)
614 1.1 mrg set fnord "$@" "$arg"; shift ;;
615 1.1 mrg # Strip any option that makedepend may not understand. Remove
616 1.1 mrg # the object too, otherwise makedepend will parse it as a source file.
617 1.1 mrg -arch)
618 1.1 mrg eat=yes ;;
619 1.1 mrg -*|$object)
620 1.1 mrg ;;
621 1.1 mrg *)
622 1.1 mrg set fnord "$@" "$arg"; shift ;;
623 1.1 mrg esac
624 1.1 mrg done
625 1.1 mrg obj_suffix=`echo "$object" | sed 's/^.*\././'`
626 1.1 mrg touch "$tmpdepfile"
627 1.1 mrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
628 1.1 mrg rm -f "$depfile"
629 1.5 mrg # makedepend may prepend the VPATH from the source file name to the object.
630 1.5 mrg # No need to regex-escape $object, excess matching of '.' is harmless.
631 1.5 mrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
632 1.5 mrg # Some versions of the HPUX 10.20 sed can't process the last invocation
633 1.5 mrg # correctly. Breaking it into two sed invocations is a workaround.
634 1.5 mrg sed '1,2d' "$tmpdepfile" \
635 1.5 mrg | tr ' ' "$nl" \
636 1.5 mrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
637 1.5 mrg | sed -e 's/$/ :/' >> "$depfile"
638 1.1 mrg rm -f "$tmpdepfile" "$tmpdepfile".bak
639 1.1 mrg ;;
640 1.1 mrg
641 1.1 mrg cpp)
642 1.1 mrg # Important note: in order to support this mode, a compiler *must*
643 1.1 mrg # always write the preprocessed file to stdout.
644 1.1 mrg "$@" || exit $?
645 1.1 mrg
646 1.1 mrg # Remove the call to Libtool.
647 1.1 mrg if test "$libtool" = yes; then
648 1.1 mrg while test "X$1" != 'X--mode=compile'; do
649 1.1 mrg shift
650 1.1 mrg done
651 1.1 mrg shift
652 1.1 mrg fi
653 1.1 mrg
654 1.5 mrg # Remove '-o $object'.
655 1.1 mrg IFS=" "
656 1.1 mrg for arg
657 1.1 mrg do
658 1.1 mrg case $arg in
659 1.1 mrg -o)
660 1.1 mrg shift
661 1.1 mrg ;;
662 1.1 mrg $object)
663 1.1 mrg shift
664 1.1 mrg ;;
665 1.1 mrg *)
666 1.1 mrg set fnord "$@" "$arg"
667 1.1 mrg shift # fnord
668 1.1 mrg shift # $arg
669 1.1 mrg ;;
670 1.1 mrg esac
671 1.1 mrg done
672 1.1 mrg
673 1.5 mrg "$@" -E \
674 1.5 mrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
675 1.5 mrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
676 1.5 mrg | sed '$ s: \\$::' > "$tmpdepfile"
677 1.1 mrg rm -f "$depfile"
678 1.1 mrg echo "$object : \\" > "$depfile"
679 1.1 mrg cat < "$tmpdepfile" >> "$depfile"
680 1.1 mrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
681 1.1 mrg rm -f "$tmpdepfile"
682 1.1 mrg ;;
683 1.1 mrg
684 1.1 mrg msvisualcpp)
685 1.1 mrg # Important note: in order to support this mode, a compiler *must*
686 1.1 mrg # always write the preprocessed file to stdout.
687 1.1 mrg "$@" || exit $?
688 1.1 mrg
689 1.1 mrg # Remove the call to Libtool.
690 1.1 mrg if test "$libtool" = yes; then
691 1.1 mrg while test "X$1" != 'X--mode=compile'; do
692 1.1 mrg shift
693 1.1 mrg done
694 1.1 mrg shift
695 1.1 mrg fi
696 1.1 mrg
697 1.1 mrg IFS=" "
698 1.1 mrg for arg
699 1.1 mrg do
700 1.1 mrg case "$arg" in
701 1.1 mrg -o)
702 1.1 mrg shift
703 1.1 mrg ;;
704 1.1 mrg $object)
705 1.1 mrg shift
706 1.1 mrg ;;
707 1.1 mrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
708 1.5 mrg set fnord "$@"
709 1.5 mrg shift
710 1.5 mrg shift
711 1.5 mrg ;;
712 1.1 mrg *)
713 1.5 mrg set fnord "$@" "$arg"
714 1.5 mrg shift
715 1.5 mrg shift
716 1.5 mrg ;;
717 1.1 mrg esac
718 1.1 mrg done
719 1.1 mrg "$@" -E 2>/dev/null |
720 1.1 mrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
721 1.1 mrg rm -f "$depfile"
722 1.1 mrg echo "$object : \\" > "$depfile"
723 1.5 mrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
724 1.5 mrg echo "$tab" >> "$depfile"
725 1.1 mrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
726 1.1 mrg rm -f "$tmpdepfile"
727 1.1 mrg ;;
728 1.1 mrg
729 1.1 mrg msvcmsys)
730 1.1 mrg # This case exists only to let depend.m4 do its work. It works by
731 1.1 mrg # looking at the text of this script. This case will never be run,
732 1.1 mrg # since it is checked for above.
733 1.1 mrg exit 1
734 1.1 mrg ;;
735 1.1 mrg
736 1.1 mrg none)
737 1.1 mrg exec "$@"
738 1.1 mrg ;;
739 1.1 mrg
740 1.1 mrg *)
741 1.1 mrg echo "Unknown depmode $depmode" 1>&2
742 1.1 mrg exit 1
743 1.1 mrg ;;
744 1.1 mrg esac
745 1.1 mrg
746 1.1 mrg exit 0
747 1.1 mrg
748 1.1 mrg # Local Variables:
749 1.1 mrg # mode: shell-script
750 1.1 mrg # sh-indentation: 2
751 1.1 mrg # eval: (add-hook 'write-file-hooks 'time-stamp)
752 1.1 mrg # time-stamp-start: "scriptversion="
753 1.1 mrg # time-stamp-format: "%:y-%02m-%02d.%02H"
754 1.1 mrg # time-stamp-time-zone: "UTC"
755 1.1 mrg # time-stamp-end: "; # UTC"
756 1.1 mrg # End:
757