2 # depcomp - compile a program generating dependencies as side-effects
4 scriptversion
=2006-07-09.11
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 "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
97 if test $stat -eq 0; then :
102 mv "$tmpdepfile" "$depfile"
106 ## There are various ways to get dependency output from gcc. Here's
107 ## why we pick this rather obscure method:
108 ## - Don't want to use -MD because we'd like the dependencies to end
109 ## up in a subdir. Having to rename by hand is ugly.
110 ## (We might end up doing this anyway to support other compilers.)
111 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
112 ## -MM, not -M (despite what the docs say).
113 ## - Using -M directly means running the compiler twice (even worse
115 if test -z "$gccflag"; then
118 "$@" -Wp,"$gccflag$tmpdepfile"
120 if test $stat -eq 0; then :
126 echo "$object : \\" > "$depfile"
127 alpha
=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
128 ## The second -e expression handles DOS-style file names with drive letters.
129 sed -e 's/^[^:]*: / /' \
130 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
131 ## This next piece of magic avoids the `deleted header file' problem.
132 ## The problem is that when a header file which appears in a .P file
133 ## is deleted, the dependency causes make to die (because there is
134 ## typically no way to rebuild the header). We avoid this by adding
135 ## dummy dependencies for each header file. Too bad gcc doesn't do
136 ## this for us directly.
139 ## Some versions of gcc put a space before the `:'. On the theory
140 ## that the space means something, we add a space to the output as
142 ## Some versions of the HPUX 10.20 sed can't process this invocation
143 ## correctly. Breaking it into two sed invocations is a workaround.
144 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
149 # This case exists only to let depend.m4 do its work. It works by
150 # looking at the text of this script. This case will never be run,
151 # since it is checked for above.
156 if test "$libtool" = yes; then
157 "$@" "-Wp,-MDupdate,$tmpdepfile"
159 "$@" -MDupdate "$tmpdepfile"
162 if test $stat -eq 0; then :
169 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
170 echo "$object : \\" > "$depfile"
172 # Clip off the initial element (the dependent). Don't try to be
173 # clever and replace this with sed code, as IRIX sed won't handle
174 # lines with more than a fixed number of characters (4096 in
175 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
176 # the IRIX cc adds comments like `#:fec' to the end of the
180 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
185 # The second pass generates a dummy entry for each header file.
188 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
191 # The sourcefile does not contain any dependencies, so just
192 # store a dummy comment line, to avoid errors with the Makefile
193 # "include basename.Plo" scheme.
194 echo "#dummy" > "$depfile"
200 # The C for AIX Compiler uses -M and outputs the dependencies
201 # in a .u file. In older versions, this file always lives in the
202 # current directory. Also, the AIX compiler puts `$object:' at the
203 # start of each line; $object doesn't have directory information.
204 # Version 6 uses the directory in both cases.
205 stripped
=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
206 tmpdepfile
="$stripped.u"
207 if test "$libtool" = yes; then
214 if test -f "$tmpdepfile"; then :
216 stripped
=`echo "$stripped" | sed 's,^.*/,,'`
217 tmpdepfile
="$stripped.u"
220 if test $stat -eq 0; then :
226 if test -f "$tmpdepfile"; then
227 outname
="$stripped.o"
228 # Each line is of the form `foo.o: dependent.h'.
229 # Do two passes, one to just change these to
230 # `$object: dependent.h' and one to simply `dependent.h:'.
231 sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
232 sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
234 # The sourcefile does not contain any dependencies, so just
235 # store a dummy comment line, to avoid errors with the Makefile
236 # "include basename.Plo" scheme.
237 echo "#dummy" > "$depfile"
243 # Intel's C compiler understands `-MD -MF file'. However on
244 # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
245 # ICC 7.0 will fill foo.d with something like
248 # which is wrong. We want:
249 # sub/foo.o: sub/foo.c
250 # sub/foo.o: sub/foo.h
253 # ICC 7.1 will output
254 # foo.o: sub/foo.c sub/foo.h
255 # and will wrap long lines using \ :
256 # foo.o: sub/foo.c ... \
260 "$@" -MD -MF "$tmpdepfile"
262 if test $stat -eq 0; then :
268 # Each line is of the form `foo.o: dependent.h',
269 # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
270 # Do two passes, one to just change these to
271 # `$object: dependent.h' and one to simply `dependent.h:'.
272 sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
273 # Some versions of the HPUX 10.20 sed can't process this invocation
274 # correctly. Breaking it into two sed invocations is a workaround.
275 sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
276 sed -e 's/$/ :/' >> "$depfile"
281 # The "hp" stanza above does not work with aCC (C++) and HP's ia64
282 # compilers, which have integrated preprocessors. The correct option
283 # to use with these is +Maked; it writes dependencies to a file named
284 # 'foo.d', which lands next to the object file, wherever that
286 # Much of this is similar to the tru64 case; see comments there.
287 dir
=`echo "$object" | sed -e 's|/[^/]*$|/|'`
288 test "x$dir" = "x$object" && dir
=
289 base
=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
290 if test "$libtool" = yes; then
291 tmpdepfile1
=$dir$base.d
292 tmpdepfile2
=$dir.libs
/$base.d
295 tmpdepfile1
=$dir$base.d
296 tmpdepfile2
=$dir$base.d
300 if test $stat -eq 0; then :
302 rm -f "$tmpdepfile1" "$tmpdepfile2"
306 for tmpdepfile
in "$tmpdepfile1" "$tmpdepfile2"
308 test -f "$tmpdepfile" && break
310 if test -f "$tmpdepfile"; then
311 sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
312 # Add `dependent.h:' lines.
313 sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
315 echo "#dummy" > "$depfile"
317 rm -f "$tmpdepfile" "$tmpdepfile2"
321 # The Tru64 compiler uses -MD to generate dependencies as a side
322 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
323 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
324 # dependencies in `foo.d' instead, so we check for that too.
325 # Subdirectories are respected.
326 dir
=`echo "$object" | sed -e 's|/[^/]*$|/|'`
327 test "x$dir" = "x$object" && dir
=
328 base
=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
330 if test "$libtool" = yes; then
331 # With Tru64 cc, shared objects can also be used to make a
332 # static library. This mechanism is used in libtool 1.4 series to
333 # handle both shared and static libraries in a single compilation.
334 # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
336 # With libtool 1.5 this exception was removed, and libtool now
337 # generates 2 separate objects for the 2 libraries. These two
338 # compilations output dependencies in $dir.libs/$base.o.d and
339 # in $dir$base.o.d. We have to check for both files, because
340 # one of the two compilations can be disabled. We should prefer
341 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
342 # automatically cleaned when .libs/ is deleted, while ignoring
343 # the former would cause a distcleancheck panic.
344 tmpdepfile1
=$dir.libs
/$base.lo.d
# libtool 1.4
345 tmpdepfile2
=$dir$base.o.d
# libtool 1.5
346 tmpdepfile3
=$dir.libs
/$base.o.d
# libtool 1.5
347 tmpdepfile4
=$dir.libs
/$base.d
# Compaq CCC V6.2-504
350 tmpdepfile1
=$dir$base.o.d
351 tmpdepfile2
=$dir$base.d
352 tmpdepfile3
=$dir$base.d
353 tmpdepfile4
=$dir$base.d
358 if test $stat -eq 0; then :
360 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
364 for tmpdepfile
in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
366 test -f "$tmpdepfile" && break
368 if test -f "$tmpdepfile"; then
369 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
370 # That's a tab and a space in the [].
371 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
373 echo "#dummy" > "$depfile"
379 # This comment above is used by automake to tell side-effect
380 # dependency tracking mechanisms from slower ones.
383 # Important note: in order to support this mode, a compiler *must*
384 # always write the preprocessed file to stdout, regardless of -o.
387 # Remove the call to Libtool.
388 if test "$libtool" = yes; then
389 while test $1 != '--mode=compile'; do
395 # Remove `-o $object'.
407 set fnord
"$@" "$arg"
414 test -z "$dashmflag" && dashmflag
=-M
415 # Require at least two characters before searching for `:'
416 # in the target name. This is to cope with DOS-style filenames:
417 # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
419 sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
421 cat < "$tmpdepfile" > "$depfile"
423 ' < "$tmpdepfile" | \
424 ## Some versions of the HPUX 10.20 sed can't process this invocation
425 ## correctly. Breaking it into two sed invocations is a workaround.
426 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
431 # This case only exists to satisfy depend.m4. It is never actually
432 # run, as this mode is specially recognized in the preamble.
438 # Remove any Libtool call
439 if test "$libtool" = yes; then
440 while test $1 != '--mode=compile'; do
456 set fnord
"$@" "$arg"; shift ;;
457 # Strip any option that makedepend may not understand. Remove
458 # the object too, otherwise makedepend will parse it as a source file.
462 set fnord
"$@" "$arg"; shift ;;
465 obj_suffix
="`echo $object | sed 's/^.*\././'`"
467 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
469 cat < "$tmpdepfile" > "$depfile"
470 sed '1,2d' "$tmpdepfile" |
tr ' ' '
472 ## Some versions of the HPUX 10.20 sed can't process this invocation
473 ## correctly. Breaking it into two sed invocations is a workaround.
474 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
475 rm -f "$tmpdepfile" "$tmpdepfile".bak
479 # Important note: in order to support this mode, a compiler *must*
480 # always write the preprocessed file to stdout.
483 # Remove the call to Libtool.
484 if test "$libtool" = yes; then
485 while test $1 != '--mode=compile'; do
491 # Remove `-o $object'.
503 set fnord
"$@" "$arg"
511 sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
512 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
513 sed '$ s: \\$::' > "$tmpdepfile"
515 echo "$object : \\" > "$depfile"
516 cat < "$tmpdepfile" >> "$depfile"
517 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
522 # Important note: in order to support this mode, a compiler *must*
523 # always write the preprocessed file to stdout, regardless of -o,
524 # because we must use -o when running libtool.
530 "-Gm"|
"/Gm"|
"-Gi"|
"/Gi"|
"-ZI"|
"/ZI")
536 set fnord
"$@" "$arg"
543 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' |
sort |
uniq > "$tmpdepfile"
545 echo "$object : \\" > "$depfile"
546 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
547 echo " " >> "$depfile"
548 .
"$tmpdepfile" |
sed 's% %\\ %g' |
sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
557 echo "Unknown depmode $depmode" 1>&2
567 # eval: (add-hook 'write-file-hooks 'time-stamp)
568 # time-stamp-start: "scriptversion="
569 # time-stamp-format: "%:y-%02m-%02d.%02H"
570 # time-stamp-end: "$"