2 # depcomp - compile a program generating dependencies as side-effects
4 scriptversion
=2006-10-15.18
6 # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 # As a special exception to the GNU General Public License, if you
25 # distribute this file as part of a program that contains a
26 # configuration script generated by Autoconf, you may include it under
27 # the same distribution terms that you use for the rest of that program.
29 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
33 echo "$0: No command. Try \`$0 --help' for more information." 1>&2
38 Usage
: depcomp
[--help] [--version] PROGRAM
[ARGS
]
40 Run PROGRAMS ARGS to compile a
file, generating dependencies
43 Environment variables
:
44 depmode Dependency tracking mode.
45 source Source
file read by
`PROGRAMS ARGS'.
46 object Object file output by `PROGRAMS ARGS
'.
47 DEPDIR directory where to store dependencies.
48 depfile Dependency file to output.
49 tmpdepfile Temporary file to use when outputing dependencies.
50 libtool Whether libtool is used (yes/no).
52 Report bugs to <bug-automake@gnu.org>.
57 echo "depcomp $scriptversion"
62 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
63 echo "depcomp: Variables source, object and depmode must be set" 1>&2
67 # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
68 depfile=${depfile-`echo "$object" |
69 sed 's
|[^
\\/]*$
|'${DEPDIR-.deps}'/&|;s
|\.\
([^.
]*\
)$
|.P\
1|;s
|Pobj$
|Po
|'`}
70 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
74 # Some modes work just like other modes, but use different flags. We
75 # parameterize here, but still list the modes in the big case below,
76 # to make depend.m4 easier to write. Note that we *cannot* use a case
77 # here, because this file can only contain one case statement.
78 if test "$depmode" = hp; then
79 # HP compiler uses -M and no extra arg.
84 if test "$depmode" = dashXmstdout; then
85 # This is just like dashmstdout with a different argument.
92 ## gcc 3 implements dependency tracking that does exactly what
93 ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
94 ## it if -MD -MP comes after the -MF stuff. Hmm.
95 ## Unfortunately, FreeBSD c89 acceptance of flags depends upon
96 ## the command line argument order; so add the flags where they
97 ## appear in depend2.am. Note that the slowdown incurred here
98 ## affects only configure: in makefiles, %FASTDEP% shortcuts this.
102 -c) set fnord
"$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
103 *) set fnord
"$@" "$arg" ;;
110 if test $stat -eq 0; then :
115 mv "$tmpdepfile" "$depfile"
119 ## There are various ways to get dependency output from gcc. Here's
120 ## why we pick this rather obscure method:
121 ## - Don't want to use -MD because we'd like the dependencies to end
122 ## up in a subdir. Having to rename by hand is ugly.
123 ## (We might end up doing this anyway to support other compilers.)
124 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
125 ## -MM, not -M (despite what the docs say).
126 ## - Using -M directly means running the compiler twice (even worse
128 if test -z "$gccflag"; then
131 "$@" -Wp,"$gccflag$tmpdepfile"
133 if test $stat -eq 0; then :
139 echo "$object : \\" > "$depfile"
140 alpha
=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
141 ## The second -e expression handles DOS-style file names with drive letters.
142 sed -e 's/^[^:]*: / /' \
143 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
144 ## This next piece of magic avoids the `deleted header file' problem.
145 ## The problem is that when a header file which appears in a .P file
146 ## is deleted, the dependency causes make to die (because there is
147 ## typically no way to rebuild the header). We avoid this by adding
148 ## dummy dependencies for each header file. Too bad gcc doesn't do
149 ## this for us directly.
152 ## Some versions of gcc put a space before the `:'. On the theory
153 ## that the space means something, we add a space to the output as
155 ## Some versions of the HPUX 10.20 sed can't process this invocation
156 ## correctly. Breaking it into two sed invocations is a workaround.
157 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
162 # This case exists only to let depend.m4 do its work. It works by
163 # looking at the text of this script. This case will never be run,
164 # since it is checked for above.
169 if test "$libtool" = yes; then
170 "$@" "-Wp,-MDupdate,$tmpdepfile"
172 "$@" -MDupdate "$tmpdepfile"
175 if test $stat -eq 0; then :
182 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
183 echo "$object : \\" > "$depfile"
185 # Clip off the initial element (the dependent). Don't try to be
186 # clever and replace this with sed code, as IRIX sed won't handle
187 # lines with more than a fixed number of characters (4096 in
188 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
189 # the IRIX cc adds comments like `#:fec' to the end of the
193 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
198 # The second pass generates a dummy entry for each header file.
201 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
204 # The sourcefile does not contain any dependencies, so just
205 # store a dummy comment line, to avoid errors with the Makefile
206 # "include basename.Plo" scheme.
207 echo "#dummy" > "$depfile"
213 # The C for AIX Compiler uses -M and outputs the dependencies
214 # in a .u file. In older versions, this file always lives in the
215 # current directory. Also, the AIX compiler puts `$object:' at the
216 # start of each line; $object doesn't have directory information.
217 # Version 6 uses the directory in both cases.
218 stripped
=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
219 tmpdepfile
="$stripped.u"
220 if test "$libtool" = yes; then
227 if test -f "$tmpdepfile"; then :
229 stripped
=`echo "$stripped" | sed 's,^.*/,,'`
230 tmpdepfile
="$stripped.u"
233 if test $stat -eq 0; then :
239 if test -f "$tmpdepfile"; then
240 outname
="$stripped.o"
241 # Each line is of the form `foo.o: dependent.h'.
242 # Do two passes, one to just change these to
243 # `$object: dependent.h' and one to simply `dependent.h:'.
244 sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
245 sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
247 # The sourcefile does not contain any dependencies, so just
248 # store a dummy comment line, to avoid errors with the Makefile
249 # "include basename.Plo" scheme.
250 echo "#dummy" > "$depfile"
256 # Intel's C compiler understands `-MD -MF file'. However on
257 # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
258 # ICC 7.0 will fill foo.d with something like
261 # which is wrong. We want:
262 # sub/foo.o: sub/foo.c
263 # sub/foo.o: sub/foo.h
266 # ICC 7.1 will output
267 # foo.o: sub/foo.c sub/foo.h
268 # and will wrap long lines using \ :
269 # foo.o: sub/foo.c ... \
273 "$@" -MD -MF "$tmpdepfile"
275 if test $stat -eq 0; then :
281 # Each line is of the form `foo.o: dependent.h',
282 # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
283 # Do two passes, one to just change these to
284 # `$object: dependent.h' and one to simply `dependent.h:'.
285 sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
286 # Some versions of the HPUX 10.20 sed can't process this invocation
287 # correctly. Breaking it into two sed invocations is a workaround.
288 sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
289 sed -e 's/$/ :/' >> "$depfile"
294 # The "hp" stanza above does not work with aCC (C++) and HP's ia64
295 # compilers, which have integrated preprocessors. The correct option
296 # to use with these is +Maked; it writes dependencies to a file named
297 # 'foo.d', which lands next to the object file, wherever that
299 # Much of this is similar to the tru64 case; see comments there.
300 dir
=`echo "$object" | sed -e 's|/[^/]*$|/|'`
301 test "x$dir" = "x$object" && dir
=
302 base
=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
303 if test "$libtool" = yes; then
304 tmpdepfile1
=$dir$base.d
305 tmpdepfile2
=$dir.libs
/$base.d
308 tmpdepfile1
=$dir$base.d
309 tmpdepfile2
=$dir$base.d
313 if test $stat -eq 0; then :
315 rm -f "$tmpdepfile1" "$tmpdepfile2"
319 for tmpdepfile
in "$tmpdepfile1" "$tmpdepfile2"
321 test -f "$tmpdepfile" && break
323 if test -f "$tmpdepfile"; then
324 sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
325 # Add `dependent.h:' lines.
326 sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
328 echo "#dummy" > "$depfile"
330 rm -f "$tmpdepfile" "$tmpdepfile2"
334 # The Tru64 compiler uses -MD to generate dependencies as a side
335 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
336 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
337 # dependencies in `foo.d' instead, so we check for that too.
338 # Subdirectories are respected.
339 dir
=`echo "$object" | sed -e 's|/[^/]*$|/|'`
340 test "x$dir" = "x$object" && dir
=
341 base
=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
343 if test "$libtool" = yes; then
344 # With Tru64 cc, shared objects can also be used to make a
345 # static library. This mechanism is used in libtool 1.4 series to
346 # handle both shared and static libraries in a single compilation.
347 # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
349 # With libtool 1.5 this exception was removed, and libtool now
350 # generates 2 separate objects for the 2 libraries. These two
351 # compilations output dependencies in $dir.libs/$base.o.d and
352 # in $dir$base.o.d. We have to check for both files, because
353 # one of the two compilations can be disabled. We should prefer
354 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
355 # automatically cleaned when .libs/ is deleted, while ignoring
356 # the former would cause a distcleancheck panic.
357 tmpdepfile1
=$dir.libs
/$base.lo.d
# libtool 1.4
358 tmpdepfile2
=$dir$base.o.d
# libtool 1.5
359 tmpdepfile3
=$dir.libs
/$base.o.d
# libtool 1.5
360 tmpdepfile4
=$dir.libs
/$base.d
# Compaq CCC V6.2-504
363 tmpdepfile1
=$dir$base.o.d
364 tmpdepfile2
=$dir$base.d
365 tmpdepfile3
=$dir$base.d
366 tmpdepfile4
=$dir$base.d
371 if test $stat -eq 0; then :
373 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
377 for tmpdepfile
in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
379 test -f "$tmpdepfile" && break
381 if test -f "$tmpdepfile"; then
382 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
383 # That's a tab and a space in the [].
384 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
386 echo "#dummy" > "$depfile"
392 # This comment above is used by automake to tell side-effect
393 # dependency tracking mechanisms from slower ones.
396 # Important note: in order to support this mode, a compiler *must*
397 # always write the preprocessed file to stdout, regardless of -o.
400 # Remove the call to Libtool.
401 if test "$libtool" = yes; then
402 while test $1 != '--mode=compile'; do
408 # Remove `-o $object'.
420 set fnord
"$@" "$arg"
427 test -z "$dashmflag" && dashmflag
=-M
428 # Require at least two characters before searching for `:'
429 # in the target name. This is to cope with DOS-style filenames:
430 # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
432 sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\
: :' > "$tmpdepfile"
434 cat < "$tmpdepfile" > "$depfile"
436 ' < "$tmpdepfile" | \
437 ## Some versions of the HPUX 10.20 sed can't process this invocation
438 ## correctly. Breaking it into two sed invocations is a workaround.
439 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
444 # This case only exists to satisfy depend.m4. It is never actually
445 # run, as this mode is specially recognized in the preamble.
451 # Remove any Libtool call
452 if test "$libtool" = yes; then
453 while test $1 != '--mode=compile'; do
469 set fnord
"$@" "$arg"; shift ;;
470 # Strip any option that makedepend may not understand. Remove
471 # the object too, otherwise makedepend will parse it as a source file.
475 set fnord
"$@" "$arg"; shift ;;
478 obj_suffix
="`echo $object | sed 's/^.*\././'`"
480 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
482 cat < "$tmpdepfile" > "$depfile"
483 sed '1,2d' "$tmpdepfile" | tr ' ' '
485 ## Some versions of the HPUX 10.20 sed can't process this invocation
486 ## correctly. Breaking it into two sed invocations is a workaround.
487 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
488 rm -f "$tmpdepfile" "$tmpdepfile".bak
492 # Important note: in order to support this mode, a compiler *must*
493 # always write the preprocessed file to stdout.
496 # Remove the call to Libtool.
497 if test "$libtool" = yes; then
498 while test $1 != '--mode=compile'; do
504 # Remove `-o $object'.
516 set fnord
"$@" "$arg"
524 sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
525 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
526 sed '$ s: \\$::' > "$tmpdepfile"
528 echo "$object : \\" > "$depfile"
529 cat < "$tmpdepfile" >> "$depfile"
530 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
535 # Important note: in order to support this mode, a compiler *must*
536 # always write the preprocessed file to stdout, regardless of -o,
537 # because we must use -o when running libtool.
543 "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
549 set fnord
"$@" "$arg"
556 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
558 echo "$object : \\" > "$depfile"
559 .
"$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
560 echo " " >> "$depfile"
561 .
"$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
570 echo "Unknown depmode $depmode" 1>&2
580 # eval: (add-hook 'write-file-hooks 'time-stamp)
581 # time-stamp-start: "scriptversion="
582 # time-stamp-format: "%:y-%02m-%02d.%02H"
583 # time-stamp-end: "$"