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