2 # depcomp - compile a program generating dependencies as side-effects
\r
4 scriptversion=2005-07-09.11
\r
6 # Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
\r
8 # This program is free software; you can redistribute it and/or modify
\r
9 # it under the terms of the GNU General Public License as published by
\r
10 # the Free Software Foundation; either version 2, or (at your option)
\r
11 # any later version.
\r
13 # This program is distributed in the hope that it will be useful,
\r
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 # GNU General Public License for more details.
\r
18 # You should have received a copy of the GNU General Public License
\r
19 # along with this program; if not, write to the Free Software
\r
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
\r
23 # As a special exception to the GNU General Public License, if you
\r
24 # distribute this file as part of a program that contains a
\r
25 # configuration script generated by Autoconf, you may include it under
\r
26 # the same distribution terms that you use for the rest of that program.
\r
28 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
\r
32 echo "$0: No command. Try \`$0 --help' for more information." 1>&2
\r
37 Usage: depcomp [--help] [--version] PROGRAM [ARGS]
\r
39 Run PROGRAMS ARGS to compile a file, generating dependencies
\r
42 Environment variables:
\r
43 depmode Dependency tracking mode.
\r
44 source Source file read by `PROGRAMS ARGS'.
\r
45 object Object file output by `PROGRAMS ARGS'.
\r
46 DEPDIR directory where to store dependencies.
\r
47 depfile Dependency file to output.
\r
48 tmpdepfile Temporary file to use when outputing dependencies.
\r
49 libtool Whether libtool is used (yes/no).
\r
51 Report bugs to <bug-automake@gnu.org>.
\r
56 echo "depcomp $scriptversion"
\r
61 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
\r
62 echo "depcomp: Variables source, object and depmode must be set" 1>&2
\r
66 # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
\r
67 depfile=${depfile-`echo "$object" |
\r
68 sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
\r
69 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
\r
73 # Some modes work just like other modes, but use different flags. We
\r
74 # parameterize here, but still list the modes in the big case below,
\r
75 # to make depend.m4 easier to write. Note that we *cannot* use a case
\r
76 # here, because this file can only contain one case statement.
\r
77 if test "$depmode" = hp; then
\r
78 # HP compiler uses -M and no extra arg.
\r
83 if test "$depmode" = dashXmstdout; then
\r
84 # This is just like dashmstdout with a different argument.
\r
91 ## gcc 3 implements dependency tracking that does exactly what
\r
92 ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
\r
93 ## it if -MD -MP comes after the -MF stuff. Hmm.
\r
94 "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
\r
96 if test $stat -eq 0; then :
\r
101 mv "$tmpdepfile" "$depfile"
\r
105 ## There are various ways to get dependency output from gcc. Here's
\r
106 ## why we pick this rather obscure method:
\r
107 ## - Don't want to use -MD because we'd like the dependencies to end
\r
108 ## up in a subdir. Having to rename by hand is ugly.
\r
109 ## (We might end up doing this anyway to support other compilers.)
\r
110 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
\r
111 ## -MM, not -M (despite what the docs say).
\r
112 ## - Using -M directly means running the compiler twice (even worse
\r
114 if test -z "$gccflag"; then
\r
117 "$@" -Wp,"$gccflag$tmpdepfile"
\r
119 if test $stat -eq 0; then :
\r
121 rm -f "$tmpdepfile"
\r
125 echo "$object : \\" > "$depfile"
\r
126 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
\r
127 ## The second -e expression handles DOS-style file names with drive letters.
\r
128 sed -e 's/^[^:]*: / /' \
\r
129 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
\r
130 ## This next piece of magic avoids the `deleted header file' problem.
\r
131 ## The problem is that when a header file which appears in a .P file
\r
132 ## is deleted, the dependency causes make to die (because there is
\r
133 ## typically no way to rebuild the header). We avoid this by adding
\r
134 ## dummy dependencies for each header file. Too bad gcc doesn't do
\r
135 ## this for us directly.
\r
137 ' < "$tmpdepfile" |
\r
138 ## Some versions of gcc put a space before the `:'. On the theory
\r
139 ## that the space means something, we add a space to the output as
\r
141 ## Some versions of the HPUX 10.20 sed can't process this invocation
\r
142 ## correctly. Breaking it into two sed invocations is a workaround.
\r
143 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
\r
144 rm -f "$tmpdepfile"
\r
148 # This case exists only to let depend.m4 do its work. It works by
\r
149 # looking at the text of this script. This case will never be run,
\r
150 # since it is checked for above.
\r
155 if test "$libtool" = yes; then
\r
156 "$@" "-Wp,-MDupdate,$tmpdepfile"
\r
158 "$@" -MDupdate "$tmpdepfile"
\r
161 if test $stat -eq 0; then :
\r
163 rm -f "$tmpdepfile"
\r
168 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
\r
169 echo "$object : \\" > "$depfile"
\r
171 # Clip off the initial element (the dependent). Don't try to be
\r
172 # clever and replace this with sed code, as IRIX sed won't handle
\r
173 # lines with more than a fixed number of characters (4096 in
\r
174 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
\r
175 # the IRIX cc adds comments like `#:fec' to the end of the
\r
178 ' < "$tmpdepfile" \
\r
179 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
\r
184 # The second pass generates a dummy entry for each header file.
\r
186 ' < "$tmpdepfile" \
\r
187 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
\r
190 # The sourcefile does not contain any dependencies, so just
\r
191 # store a dummy comment line, to avoid errors with the Makefile
\r
192 # "include basename.Plo" scheme.
\r
193 echo "#dummy" > "$depfile"
\r
195 rm -f "$tmpdepfile"
\r
199 # The C for AIX Compiler uses -M and outputs the dependencies
\r
200 # in a .u file. In older versions, this file always lives in the
\r
201 # current directory. Also, the AIX compiler puts `$object:' at the
\r
202 # start of each line; $object doesn't have directory information.
\r
203 # Version 6 uses the directory in both cases.
\r
204 stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
\r
205 tmpdepfile="$stripped.u"
\r
206 if test "$libtool" = yes; then
\r
213 if test -f "$tmpdepfile"; then :
\r
215 stripped=`echo "$stripped" | sed 's,^.*/,,'`
\r
216 tmpdepfile="$stripped.u"
\r
219 if test $stat -eq 0; then :
\r
221 rm -f "$tmpdepfile"
\r
225 if test -f "$tmpdepfile"; then
\r
226 outname="$stripped.o"
\r
227 # Each line is of the form `foo.o: dependent.h'.
\r
228 # Do two passes, one to just change these to
\r
229 # `$object: dependent.h' and one to simply `dependent.h:'.
\r
230 sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
\r
231 sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
\r
233 # The sourcefile does not contain any dependencies, so just
\r
234 # store a dummy comment line, to avoid errors with the Makefile
\r
235 # "include basename.Plo" scheme.
\r
236 echo "#dummy" > "$depfile"
\r
238 rm -f "$tmpdepfile"
\r
242 # Intel's C compiler understands `-MD -MF file'. However on
\r
243 # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
\r
244 # ICC 7.0 will fill foo.d with something like
\r
247 # which is wrong. We want:
\r
248 # sub/foo.o: sub/foo.c
\r
249 # sub/foo.o: sub/foo.h
\r
252 # ICC 7.1 will output
\r
253 # foo.o: sub/foo.c sub/foo.h
\r
254 # and will wrap long lines using \ :
\r
255 # foo.o: sub/foo.c ... \
\r
259 "$@" -MD -MF "$tmpdepfile"
\r
261 if test $stat -eq 0; then :
\r
263 rm -f "$tmpdepfile"
\r
267 # Each line is of the form `foo.o: dependent.h',
\r
268 # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
\r
269 # Do two passes, one to just change these to
\r
270 # `$object: dependent.h' and one to simply `dependent.h:'.
\r
271 sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
\r
272 # Some versions of the HPUX 10.20 sed can't process this invocation
\r
273 # correctly. Breaking it into two sed invocations is a workaround.
\r
274 sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
\r
275 sed -e 's/$/ :/' >> "$depfile"
\r
276 rm -f "$tmpdepfile"
\r
280 # The Tru64 compiler uses -MD to generate dependencies as a side
\r
281 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
\r
282 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
\r
283 # dependencies in `foo.d' instead, so we check for that too.
\r
284 # Subdirectories are respected.
\r
285 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
\r
286 test "x$dir" = "x$object" && dir=
\r
287 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
\r
289 if test "$libtool" = yes; then
\r
290 # With Tru64 cc, shared objects can also be used to make a
\r
291 # static library. This mecanism is used in libtool 1.4 series to
\r
292 # handle both shared and static libraries in a single compilation.
\r
293 # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
\r
295 # With libtool 1.5 this exception was removed, and libtool now
\r
296 # generates 2 separate objects for the 2 libraries. These two
\r
297 # compilations output dependencies in in $dir.libs/$base.o.d and
\r
298 # in $dir$base.o.d. We have to check for both files, because
\r
299 # one of the two compilations can be disabled. We should prefer
\r
300 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
\r
301 # automatically cleaned when .libs/ is deleted, while ignoring
\r
302 # the former would cause a distcleancheck panic.
\r
303 tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
\r
304 tmpdepfile2=$dir$base.o.d # libtool 1.5
\r
305 tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
\r
306 tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
\r
309 tmpdepfile1=$dir$base.o.d
\r
310 tmpdepfile2=$dir$base.d
\r
311 tmpdepfile3=$dir$base.d
\r
312 tmpdepfile4=$dir$base.d
\r
317 if test $stat -eq 0; then :
\r
319 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
\r
323 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
\r
325 test -f "$tmpdepfile" && break
\r
327 if test -f "$tmpdepfile"; then
\r
328 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
\r
329 # That's a tab and a space in the [].
\r
330 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
\r
332 echo "#dummy" > "$depfile"
\r
334 rm -f "$tmpdepfile"
\r
338 # This comment above is used by automake to tell side-effect
\r
339 # dependency tracking mechanisms from slower ones.
\r
342 # Important note: in order to support this mode, a compiler *must*
\r
343 # always write the preprocessed file to stdout, regardless of -o.
\r
346 # Remove the call to Libtool.
\r
347 if test "$libtool" = yes; then
\r
348 while test $1 != '--mode=compile'; do
\r
354 # Remove `-o $object'.
\r
366 set fnord "$@" "$arg"
\r
373 test -z "$dashmflag" && dashmflag=-M
\r
374 # Require at least two characters before searching for `:'
\r
375 # in the target name. This is to cope with DOS-style filenames:
\r
376 # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
\r
378 sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
\r
380 cat < "$tmpdepfile" > "$depfile"
\r
382 ' < "$tmpdepfile" | \
\r
383 ## Some versions of the HPUX 10.20 sed can't process this invocation
\r
384 ## correctly. Breaking it into two sed invocations is a workaround.
\r
385 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
\r
386 rm -f "$tmpdepfile"
\r
390 # This case only exists to satisfy depend.m4. It is never actually
\r
391 # run, as this mode is specially recognized in the preamble.
\r
397 # Remove any Libtool call
\r
398 if test "$libtool" = yes; then
\r
399 while test $1 != '--mode=compile'; do
\r
407 for arg in "$@"; do
\r
415 set fnord "$@" "$arg"; shift ;;
\r
416 # Strip any option that makedepend may not understand. Remove
\r
417 # the object too, otherwise makedepend will parse it as a source file.
\r
421 set fnord "$@" "$arg"; shift ;;
\r
424 obj_suffix="`echo $object | sed 's/^.*\././'`"
\r
425 touch "$tmpdepfile"
\r
426 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
\r
428 cat < "$tmpdepfile" > "$depfile"
\r
429 sed '1,2d' "$tmpdepfile" | tr ' ' '
\r
431 ## Some versions of the HPUX 10.20 sed can't process this invocation
\r
432 ## correctly. Breaking it into two sed invocations is a workaround.
\r
433 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
\r
434 rm -f "$tmpdepfile" "$tmpdepfile".bak
\r
438 # Important note: in order to support this mode, a compiler *must*
\r
439 # always write the preprocessed file to stdout.
\r
442 # Remove the call to Libtool.
\r
443 if test "$libtool" = yes; then
\r
444 while test $1 != '--mode=compile'; do
\r
450 # Remove `-o $object'.
\r
462 set fnord "$@" "$arg"
\r
470 sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
\r
471 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
\r
472 sed '$ s: \\$::' > "$tmpdepfile"
\r
474 echo "$object : \\" > "$depfile"
\r
475 cat < "$tmpdepfile" >> "$depfile"
\r
476 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
\r
477 rm -f "$tmpdepfile"
\r
481 # Important note: in order to support this mode, a compiler *must*
\r
482 # always write the preprocessed file to stdout, regardless of -o,
\r
483 # because we must use -o when running libtool.
\r
489 "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
\r
495 set fnord "$@" "$arg"
\r
502 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
\r
504 echo "$object : \\" > "$depfile"
\r
505 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
\r
506 echo " " >> "$depfile"
\r
507 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
\r
508 rm -f "$tmpdepfile"
\r
516 echo "Unknown depmode $depmode" 1>&2
\r
524 # mode: shell-script
\r
525 # sh-indentation: 2
\r
526 # eval: (add-hook 'write-file-hooks 'time-stamp)
\r
527 # time-stamp-start: "scriptversion="
\r
528 # time-stamp-format: "%:y-%02m-%02d.%02H"
\r
529 # time-stamp-end: "$"
\r