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, see <http://www.gnu.org/licenses/>.
22 # As a special exception to the GNU General Public License, if you
23 # distribute this file as part of a program that contains a
24 # configuration script generated by Autoconf, you may include it under
25 # the same distribution terms that you use for the rest of that program.
27 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
31 echo "$0: No command. Try \`$0 --help' for more information." 1>&2
36 Usage
: depcomp
[--help] [--version] PROGRAM
[ARGS
]
38 Run PROGRAMS ARGS to compile a
file, generating dependencies
41 Environment variables
:
42 depmode Dependency tracking mode.
43 source Source
file read by
`PROGRAMS ARGS'.
44 object Object file output by `PROGRAMS ARGS
'.
45 DEPDIR directory where to store dependencies.
46 depfile Dependency file to output.
47 tmpdepfile Temporary file to use when outputing dependencies.
48 libtool Whether libtool is used (yes/no).
50 Report bugs to <bug-automake@gnu.org>.
55 echo "depcomp $scriptversion"
60 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
61 echo "depcomp: Variables source, object and depmode must be set" 1>&2
65 # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
66 depfile=${depfile-`echo "$object" |
67 sed 's|
[^
\\/]*$|
'${DEPDIR-.deps}'/&|
;s|\.\
([^.
]*\
)$|.P\
1|
;s|Pobj$|Po|
'`}
68 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
72 # Some modes work just like other modes, but use different flags. We
73 # parameterize here, but still list the modes in the big case below,
74 # to make depend.m4 easier to write. Note that we *cannot* use a case
75 # here, because this file can only contain one case statement.
76 if test "$depmode" = hp; then
77 # HP compiler uses -M and no extra arg.
82 if test "$depmode" = dashXmstdout; then
83 # This is just like dashmstdout with a different argument.
90 ## gcc 3 implements dependency tracking that does exactly what
91 ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
92 ## it if -MD -MP comes after the -MF stuff. Hmm.
93 ## Unfortunately, FreeBSD c89 acceptance of flags depends upon
94 ## the command line argument order; so add the flags where they
95 ## appear in depend2.am. Note that the slowdown incurred here
96 ## affects only configure: in makefiles, %FASTDEP% shortcuts this.
100 -c) set fnord
"$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
101 *) set fnord
"$@" "$arg" ;;
108 if test $stat -eq 0; then :
113 mv "$tmpdepfile" "$depfile"
117 ## There are various ways to get dependency output from gcc. Here's
118 ## why we pick this rather obscure method:
119 ## - Don't want to use -MD because we'd like the dependencies to end
120 ## up in a subdir. Having to rename by hand is ugly.
121 ## (We might end up doing this anyway to support other compilers.)
122 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
123 ## -MM, not -M (despite what the docs say).
124 ## - Using -M directly means running the compiler twice (even worse
126 if test -z "$gccflag"; then
129 "$@" -Wp,"$gccflag$tmpdepfile"
131 if test $stat -eq 0; then :
137 echo "$object : \\" > "$depfile"
138 alpha
=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
139 ## The second -e expression handles DOS-style file names with drive letters.
140 sed -e 's/^[^:]*: / /' \
141 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
142 ## This next piece of magic avoids the `deleted header file' problem.
143 ## The problem is that when a header file which appears in a .P file
144 ## is deleted, the dependency causes make to die (because there is
145 ## typically no way to rebuild the header). We avoid this by adding
146 ## dummy dependencies for each header file. Too bad gcc doesn't do
147 ## this for us directly.
150 ## Some versions of gcc put a space before the `:'. On the theory
151 ## that the space means something, we add a space to the output as
153 ## Some versions of the HPUX 10.20 sed can't process this invocation
154 ## correctly. Breaking it into two sed invocations is a workaround.
155 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
160 # This case exists only to let depend.m4 do its work. It works by
161 # looking at the text of this script. This case will never be run,
162 # since it is checked for above.
167 if test "$libtool" = yes; then
168 "$@" "-Wp,-MDupdate,$tmpdepfile"
170 "$@" -MDupdate "$tmpdepfile"
173 if test $stat -eq 0; then :
180 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
181 echo "$object : \\" > "$depfile"
183 # Clip off the initial element (the dependent). Don't try to be
184 # clever and replace this with sed code, as IRIX sed won't handle
185 # lines with more than a fixed number of characters (4096 in
186 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
187 # the IRIX cc adds comments like `#:fec' to the end of the
191 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
196 # The second pass generates a dummy entry for each header file.
199 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
202 # The sourcefile does not contain any dependencies, so just
203 # store a dummy comment line, to avoid errors with the Makefile
204 # "include basename.Plo" scheme.
205 echo "#dummy" > "$depfile"
211 # The C for AIX Compiler uses -M and outputs the dependencies
212 # in a .u file. In older versions, this file always lives in the
213 # current directory. Also, the AIX compiler puts `$object:' at the
214 # start of each line; $object doesn't have directory information.
215 # Version 6 uses the directory in both cases.
216 stripped
=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
217 tmpdepfile
="$stripped.u"
218 if test "$libtool" = yes; then
225 if test -f "$tmpdepfile"; then :
227 stripped
=`echo "$stripped" | sed 's,^.*/,,'`
228 tmpdepfile
="$stripped.u"
231 if test $stat -eq 0; then :
237 if test -f "$tmpdepfile"; then
238 outname
="$stripped.o"
239 # Each line is of the form `foo.o: dependent.h'.
240 # Do two passes, one to just change these to
241 # `$object: dependent.h' and one to simply `dependent.h:'.
242 sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
243 sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
245 # The sourcefile does not contain any dependencies, so just
246 # store a dummy comment line, to avoid errors with the Makefile
247 # "include basename.Plo" scheme.
248 echo "#dummy" > "$depfile"
254 # Intel's C compiler understands `-MD -MF file'. However on
255 # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
256 # ICC 7.0 will fill foo.d with something like
259 # which is wrong. We want:
260 # sub/foo.o: sub/foo.c
261 # sub/foo.o: sub/foo.h
264 # ICC 7.1 will output
265 # foo.o: sub/foo.c sub/foo.h
266 # and will wrap long lines using \ :
267 # foo.o: sub/foo.c ... \
271 "$@" -MD -MF "$tmpdepfile"
273 if test $stat -eq 0; then :
279 # Each line is of the form `foo.o: dependent.h',
280 # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
281 # Do two passes, one to just change these to
282 # `$object: dependent.h' and one to simply `dependent.h:'.
283 sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
284 # Some versions of the HPUX 10.20 sed can't process this invocation
285 # correctly. Breaking it into two sed invocations is a workaround.
286 sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
287 sed -e 's/$/ :/' >> "$depfile"
292 # The "hp" stanza above does not work with aCC (C++) and HP's ia64
293 # compilers, which have integrated preprocessors. The correct option
294 # to use with these is +Maked; it writes dependencies to a file named
295 # 'foo.d', which lands next to the object file, wherever that
297 # Much of this is similar to the tru64 case; see comments there.
298 dir
=`echo "$object" | sed -e 's|/[^/]*$|/|'`
299 test "x$dir" = "x$object" && dir
=
300 base
=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
301 if test "$libtool" = yes; then
302 tmpdepfile1
=$dir$base.d
303 tmpdepfile2
=$dir.libs
/$base.d
306 tmpdepfile1
=$dir$base.d
307 tmpdepfile2
=$dir$base.d
311 if test $stat -eq 0; then :
313 rm -f "$tmpdepfile1" "$tmpdepfile2"
317 for tmpdepfile
in "$tmpdepfile1" "$tmpdepfile2"
319 test -f "$tmpdepfile" && break
321 if test -f "$tmpdepfile"; then
322 sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
323 # Add `dependent.h:' lines.
324 sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
326 echo "#dummy" > "$depfile"
328 rm -f "$tmpdepfile" "$tmpdepfile2"
332 # The Tru64 compiler uses -MD to generate dependencies as a side
333 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
334 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
335 # dependencies in `foo.d' instead, so we check for that too.
336 # Subdirectories are respected.
337 dir
=`echo "$object" | sed -e 's|/[^/]*$|/|'`
338 test "x$dir" = "x$object" && dir
=
339 base
=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
341 if test "$libtool" = yes; then
342 # With Tru64 cc, shared objects can also be used to make a
343 # static library. This mechanism is used in libtool 1.4 series to
344 # handle both shared and static libraries in a single compilation.
345 # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
347 # With libtool 1.5 this exception was removed, and libtool now
348 # generates 2 separate objects for the 2 libraries. These two
349 # compilations output dependencies in $dir.libs/$base.o.d and
350 # in $dir$base.o.d. We have to check for both files, because
351 # one of the two compilations can be disabled. We should prefer
352 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
353 # automatically cleaned when .libs/ is deleted, while ignoring
354 # the former would cause a distcleancheck panic.
355 tmpdepfile1
=$dir.libs
/$base.lo.d
# libtool 1.4
356 tmpdepfile2
=$dir$base.o.d
# libtool 1.5
357 tmpdepfile3
=$dir.libs
/$base.o.d
# libtool 1.5
358 tmpdepfile4
=$dir.libs
/$base.d
# Compaq CCC V6.2-504
361 tmpdepfile1
=$dir$base.o.d
362 tmpdepfile2
=$dir$base.d
363 tmpdepfile3
=$dir$base.d
364 tmpdepfile4
=$dir$base.d
369 if test $stat -eq 0; then :
371 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
375 for tmpdepfile
in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
377 test -f "$tmpdepfile" && break
379 if test -f "$tmpdepfile"; then
380 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
381 # That's a tab and a space in the [].
382 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
384 echo "#dummy" > "$depfile"
390 # This comment above is used by automake to tell side-effect
391 # dependency tracking mechanisms from slower ones.
394 # Important note: in order to support this mode, a compiler *must*
395 # always write the preprocessed file to stdout, regardless of -o.
398 # Remove the call to Libtool.
399 if test "$libtool" = yes; then
400 while test $1 != '--mode=compile'; do
406 # Remove `-o $object'.
418 set fnord
"$@" "$arg"
425 test -z "$dashmflag" && dashmflag
=-M
426 # Require at least two characters before searching for `:'
427 # in the target name. This is to cope with DOS-style filenames:
428 # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
430 sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
432 cat < "$tmpdepfile" > "$depfile"
434 ' < "$tmpdepfile" | \
435 ## Some versions of the HPUX 10.20 sed can't process this invocation
436 ## correctly. Breaking it into two sed invocations is a workaround.
437 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
442 # This case only exists to satisfy depend.m4. It is never actually
443 # run, as this mode is specially recognized in the preamble.
449 # Remove any Libtool call
450 if test "$libtool" = yes; then
451 while test $1 != '--mode=compile'; do
467 set fnord
"$@" "$arg"; shift ;;
468 # Strip any option that makedepend may not understand. Remove
469 # the object too, otherwise makedepend will parse it as a source file.
473 set fnord
"$@" "$arg"; shift ;;
476 obj_suffix
="`echo $object | sed 's/^.*\././'`"
478 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
480 cat < "$tmpdepfile" > "$depfile"
481 sed '1,2d' "$tmpdepfile" |
tr ' ' '
483 ## Some versions of the HPUX 10.20 sed can't process this invocation
484 ## correctly. Breaking it into two sed invocations is a workaround.
485 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
486 rm -f "$tmpdepfile" "$tmpdepfile".bak
490 # Important note: in order to support this mode, a compiler *must*
491 # always write the preprocessed file to stdout.
494 # Remove the call to Libtool.
495 if test "$libtool" = yes; then
496 while test $1 != '--mode=compile'; do
502 # Remove `-o $object'.
514 set fnord
"$@" "$arg"
522 sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
523 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
524 sed '$ s: \\$::' > "$tmpdepfile"
526 echo "$object : \\" > "$depfile"
527 cat < "$tmpdepfile" >> "$depfile"
528 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
533 # Important note: in order to support this mode, a compiler *must*
534 # always write the preprocessed file to stdout, regardless of -o,
535 # because we must use -o when running libtool.
541 "-Gm"|
"/Gm"|
"-Gi"|
"/Gi"|
"-ZI"|
"/ZI")
547 set fnord
"$@" "$arg"
554 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' |
sort |
uniq > "$tmpdepfile"
556 echo "$object : \\" > "$depfile"
557 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
558 echo " " >> "$depfile"
559 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
568 echo "Unknown depmode $depmode" 1>&2
578 # eval: (add-hook 'write-file-hooks 'time-stamp)
579 # time-stamp-start: "scriptversion="
580 # time-stamp-format: "%:y-%02m-%02d.%02H"
581 # time-stamp-end: "$"