2 # depcomp - compile a program generating dependencies as side-effects
4 scriptversion
=2012-10-18.11
; # UTC
6 # Copyright (C) 1999-2012 Free Software Foundation, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # As a special exception to the GNU General Public License, if you
22 # distribute this file as part of a program that contains a
23 # configuration script generated by Autoconf, you may include it under
24 # the same distribution terms that you use for the rest of that program.
26 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
30 echo "$0: No command. Try '$0 --help' for more information." 1>&2
35 Usage
: depcomp
[--help] [--version] PROGRAM
[ARGS
]
37 Run PROGRAMS ARGS to compile a
file, generating dependencies
40 Environment variables
:
41 depmode Dependency tracking mode.
42 source Source
file read by
'PROGRAMS ARGS'.
43 object Object
file output by
'PROGRAMS ARGS'.
44 DEPDIR directory where to store dependencies.
45 depfile Dependency
file to output.
46 tmpdepfile Temporary
file to use when outputting dependencies.
47 libtool Whether libtool is used
(yes
/no
).
49 Report bugs to
<bug-automake@gnu.org
>.
54 echo "depcomp $scriptversion"
59 # Get the directory component of the given path, and save it in the
60 # global variables '$dir'. Note that this directory component will
61 # be either empty or ending with a '/' character. This is deliberate.
65 */*) dir
=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
70 # Get the suffix-stripped basename of the given path, and save it the
71 # global variable '$base'.
74 base
=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
77 # Factor out some common post-processing of the generated depfile.
78 # Requires the auxiliary global variable '$tmpdepfile' to be set.
79 aix_post_process_depfile
()
81 # If the compiler actually managed to produce a dependency file,
83 if test -f "$tmpdepfile"; then
84 # Each line is of the form 'foo.o: dependency.h'.
85 # Do two passes, one to just change these to
86 # $object: dependency.h
87 # and one to simply output
89 # which is needed to avoid the deleted-header problem.
90 { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
91 sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
95 # No dependency file was actually created by the compiler invocation.
96 # No real dependency information will be available.
97 echo "#dummy" > "$depfile"
101 # A tabulation character.
103 # A newline character.
106 # Character ranges might be problematic outside the C locale.
107 # These definitions help.
108 upper
=ABCDEFGHIJKLMNOPQRSTUVWXYZ
109 lower
=abcdefghijklmnopqrstuvwxyz
111 alpha
=${upper}${lower}
112 alnum
=${alpha}${digits}
114 if test -z "$depmode" ||
test -z "$source" ||
test -z "$object"; then
115 echo "depcomp: Variables source, object and depmode must be set" 1>&2
119 # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
120 depfile
=$
{depfile-
`echo "$object" |
121 sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
122 tmpdepfile
=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
126 # Avoid interferences from the environment.
129 # Some modes work just like other modes, but use different flags. We
130 # parameterize here, but still list the modes in the big case below,
131 # to make depend.m4 easier to write. Note that we *cannot* use a case
132 # here, because this file can only contain one case statement.
133 if test "$depmode" = hp
; then
134 # HP compiler uses -M and no extra arg.
139 if test "$depmode" = dashXmstdout
; then
140 # This is just like dashmstdout with a different argument.
145 cygpath_u
="cygpath -u -f -"
146 if test "$depmode" = msvcmsys
; then
147 # This is just like msvisualcpp but w/o cygpath translation.
148 # Just convert the backslash-escaped backslashes to single forward
149 # slashes to satisfy depend.m4
150 cygpath_u
='sed s,\\\\,/,g'
154 if test "$depmode" = msvc7msys
; then
155 # This is just like msvc7 but w/o cygpath translation.
156 # Just convert the backslash-escaped backslashes to single forward
157 # slashes to satisfy depend.m4
158 cygpath_u
='sed s,\\\\,/,g'
162 if test "$depmode" = xlc
; then
163 # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
164 gccflag
=-qmakedep=gcc
,-MF
170 ## gcc 3 implements dependency tracking that does exactly what
171 ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
172 ## it if -MD -MP comes after the -MF stuff. Hmm.
173 ## Unfortunately, FreeBSD c89 acceptance of flags depends upon
174 ## the command line argument order; so add the flags where they
175 ## appear in depend2.am. Note that the slowdown incurred here
176 ## affects only configure: in makefiles, %FASTDEP% shortcuts this.
180 -c) set fnord
"$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
181 *) set fnord
"$@" "$arg" ;;
188 if test $stat -ne 0; then
192 mv "$tmpdepfile" "$depfile"
196 ## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
197 ## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
198 ## (see the conditional assignment to $gccflag above).
199 ## There are various ways to get dependency output from gcc. Here's
200 ## why we pick this rather obscure method:
201 ## - Don't want to use -MD because we'd like the dependencies to end
202 ## up in a subdir. Having to rename by hand is ugly.
203 ## (We might end up doing this anyway to support other compilers.)
204 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
205 ## -MM, not -M (despite what the docs say). Also, it might not be
206 ## supported by the other compilers which use the 'gcc' depmode.
207 ## - Using -M directly means running the compiler twice (even worse
209 if test -z "$gccflag"; then
212 "$@" -Wp,"$gccflag$tmpdepfile"
214 if test $stat -ne 0; then
219 echo "$object : \\" > "$depfile"
220 ## The second -e expression handles DOS-style file names with drive letters.
221 sed -e 's/^[^:]*: / /' \
222 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
223 ## This next piece of magic avoids the "deleted header file" problem.
224 ## The problem is that when a header file which appears in a .P file
225 ## is deleted, the dependency causes make to die (because there is
226 ## typically no way to rebuild the header). We avoid this by adding
227 ## dummy dependencies for each header file. Too bad gcc doesn't do
228 ## this for us directly.
229 tr ' ' "$nl" < "$tmpdepfile" |
230 ## Some versions of gcc put a space before the ':'. On the theory
231 ## that the space means something, we add a space to the output as
232 ## well. hp depmode also adds that space, but also prefixes the VPATH
233 ## to the object. Take care to not repeat it in the output.
234 ## Some versions of the HPUX 10.20 sed can't process this invocation
235 ## correctly. Breaking it into two sed invocations is a workaround.
236 sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
237 |
sed -e 's/$/ :/' >> "$depfile"
242 # This case exists only to let depend.m4 do its work. It works by
243 # looking at the text of this script. This case will never be run,
244 # since it is checked for above.
249 if test "$libtool" = yes; then
250 "$@" "-Wp,-MDupdate,$tmpdepfile"
252 "$@" -MDupdate "$tmpdepfile"
255 if test $stat -ne 0; then
261 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
262 echo "$object : \\" > "$depfile"
264 # Clip off the initial element (the dependent). Don't try to be
265 # clever and replace this with sed code, as IRIX sed won't handle
266 # lines with more than a fixed number of characters (4096 in
267 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
268 # the IRIX cc adds comments like '#:fec' to the end of the
270 tr ' ' "$nl" < "$tmpdepfile" \
271 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
272 tr "$nl" ' ' >> "$depfile"
275 # The second pass generates a dummy entry for each header file.
276 tr ' ' "$nl" < "$tmpdepfile" \
277 |
sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
280 # The sourcefile does not contain any dependencies, so just
281 # store a dummy comment line, to avoid errors with the Makefile
282 # "include basename.Plo" scheme.
283 echo "#dummy" > "$depfile"
289 # This case exists only to let depend.m4 do its work. It works by
290 # looking at the text of this script. This case will never be run,
291 # since it is checked for above.
296 # The C for AIX Compiler uses -M and outputs the dependencies
297 # in a .u file. In older versions, this file always lives in the
298 # current directory. Also, the AIX compiler puts '$object:' at the
299 # start of each line; $object doesn't have directory information.
300 # Version 6 uses the directory in both cases.
301 set_dir_from
"$object"
302 set_base_from
"$object"
303 if test "$libtool" = yes; then
304 tmpdepfile1
=$dir$base.u
306 tmpdepfile3
=$dir.libs
/$base.u
309 tmpdepfile1
=$dir$base.u
310 tmpdepfile2
=$dir$base.u
311 tmpdepfile3
=$dir$base.u
316 if test $stat -ne 0; then
317 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
321 for tmpdepfile
in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
323 test -f "$tmpdepfile" && break
325 aix_post_process_depfile
329 # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.
331 # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c
332 # ICC 7.0 will fill foo.d with something like
335 # which is wrong. We want
336 # sub/foo.o: sub/foo.c
337 # sub/foo.o: sub/foo.h
340 # ICC 7.1 will output
341 # foo.o: sub/foo.c sub/foo.h
342 # and will wrap long lines using '\':
343 # foo.o: sub/foo.c ... \
346 # tcc 0.9.26 (FIXME still under development at the moment of writing)
347 # will emit a similar output, but also prepend the continuation lines
348 # with horizontal tabulation characters.
349 "$@" -MD -MF "$tmpdepfile"
351 if test $stat -ne 0; then
356 # Each line is of the form 'foo.o: dependent.h',
357 # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.
358 # Do two passes, one to just change these to
359 # '$object: dependent.h' and one to simply 'dependent.h:'.
360 sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \
361 < "$tmpdepfile" > "$depfile"
363 s/[ '"$tab"'][ '"$tab"']*/ /g
370 ' < "$tmpdepfile" >> "$depfile"
374 ## The order of this option in the case statement is important, since the
375 ## shell code in configure will try each of these formats in the order
376 ## listed in this file. A plain '-MD' option would be understood by many
377 ## compilers, so we must ensure this comes after the gcc and icc options.
379 # Portland's C compiler understands '-MD'.
380 # Will always output deps to 'file.d' where file is the root name of the
381 # source file under compilation, even if file resides in a subdirectory.
382 # The object file name does not affect the name of the '.d' file.
383 # pgcc 10.2 will output
384 # foo.o: sub/foo.c sub/foo.h
385 # and will wrap long lines using '\' :
386 # foo.o: sub/foo.c ... \
389 set_dir_from
"$object"
390 # Use the source, not the object, to determine the base name, since
391 # that's sadly what pgcc will do too.
392 set_base_from
"$source"
395 # For projects that build the same source file twice into different object
396 # files, the pgcc approach of using the *source* file root name can cause
397 # problems in parallel builds. Use a locking strategy to avoid stomping on
398 # the same $tmpdepfile.
401 echo '$0: caught signal, cleaning up...' >&2
407 while test $i -gt 0 ; do
408 # mkdir is a portable test-and-set.
409 if mkdir
"$lockdir" 2>/dev
/null
; then
410 # This process acquired the lock.
417 ## If the lock is being held by a different process, wait
418 ## until the winning process is done or we timeout.
419 while test -d "$lockdir" && test $i -gt 0; do
427 if test $i -le 0; then
428 echo "$0: failed to acquire lock after $numtries attempts" >&2
429 echo "$0: check lockdir '$lockdir'" >&2
433 if test $stat -ne 0; then
438 # Each line is of the form `foo.o: dependent.h',
439 # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
440 # Do two passes, one to just change these to
441 # `$object: dependent.h' and one to simply `dependent.h:'.
442 sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
443 # Some versions of the HPUX 10.20 sed can't process this invocation
444 # correctly. Breaking it into two sed invocations is a workaround.
445 sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
446 sed -e 's/$/ :/' >> "$depfile"
451 # The "hp" stanza above does not work with aCC (C++) and HP's ia64
452 # compilers, which have integrated preprocessors. The correct option
453 # to use with these is +Maked; it writes dependencies to a file named
454 # 'foo.d', which lands next to the object file, wherever that
456 # Much of this is similar to the tru64 case; see comments there.
457 set_dir_from
"$object"
458 set_base_from
"$object"
459 if test "$libtool" = yes; then
460 tmpdepfile1
=$dir$base.d
461 tmpdepfile2
=$dir.libs
/$base.d
464 tmpdepfile1
=$dir$base.d
465 tmpdepfile2
=$dir$base.d
469 if test $stat -ne 0; then
470 rm -f "$tmpdepfile1" "$tmpdepfile2"
474 for tmpdepfile
in "$tmpdepfile1" "$tmpdepfile2"
476 test -f "$tmpdepfile" && break
478 if test -f "$tmpdepfile"; then
479 sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
480 # Add 'dependent.h:' lines.
486 }' "$tmpdepfile" >> "$depfile"
488 echo "#dummy" > "$depfile"
490 rm -f "$tmpdepfile" "$tmpdepfile2"
494 # The Tru64 compiler uses -MD to generate dependencies as a side
495 # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
496 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
497 # dependencies in 'foo.d' instead, so we check for that too.
498 # Subdirectories are respected.
499 set_dir_from
"$object"
500 set_base_from
"$object"
502 if test "$libtool" = yes; then
503 # With Tru64 cc, shared objects can also be used to make a
504 # static library. This mechanism is used in libtool 1.4 series to
505 # handle both shared and static libraries in a single compilation.
506 # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
508 # With libtool 1.5 this exception was removed, and libtool now
509 # generates 2 separate objects for the 2 libraries. These two
510 # compilations output dependencies in $dir.libs/$base.o.d and
511 # in $dir$base.o.d. We have to check for both files, because
512 # one of the two compilations can be disabled. We should prefer
513 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
514 # automatically cleaned when .libs/ is deleted, while ignoring
515 # the former would cause a distcleancheck panic.
516 tmpdepfile1
=$dir.libs
/$base.lo.d
# libtool 1.4
517 tmpdepfile2
=$dir$base.o.d
# libtool 1.5
518 tmpdepfile3
=$dir.libs
/$base.o.d
# libtool 1.5
519 tmpdepfile4
=$dir.libs
/$base.d
# Compaq CCC V6.2-504
522 tmpdepfile1
=$dir$base.o.d
523 tmpdepfile2
=$dir$base.d
524 tmpdepfile3
=$dir$base.d
525 tmpdepfile4
=$dir$base.d
530 if test $stat -ne 0; then
531 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
535 for tmpdepfile
in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
537 test -f "$tmpdepfile" && break
539 # Same post-processing that is required for AIX mode.
540 aix_post_process_depfile
544 if test "$libtool" = yes; then
545 showIncludes
=-Wc,-showIncludes
547 showIncludes
=-showIncludes
549 "$@" $showIncludes > "$tmpdepfile"
551 grep -v '^Note: including file: ' "$tmpdepfile"
552 if test $stat -ne 0; then
557 echo "$object : \\" > "$depfile"
558 # The first sed program below extracts the file names and escapes
559 # backslashes for cygpath. The second sed program outputs the file
560 # name when reading, but also accumulates all include files in the
561 # hold buffer in order to output them again at the end. This only
562 # works with sed implementations that can handle large buffers.
563 sed < "$tmpdepfile" -n '
564 /^Note: including file: *\(.*\)/ {
568 }' |
$cygpath_u |
sort -u |
sed -n '
570 s/\(.*\)/'"$tab"'\1 \\/p
582 # This case exists only to let depend.m4 do its work. It works by
583 # looking at the text of this script. This case will never be run,
584 # since it is checked for above.
589 # This comment above is used by automake to tell side-effect
590 # dependency tracking mechanisms from slower ones.
593 # Important note: in order to support this mode, a compiler *must*
594 # always write the preprocessed file to stdout, regardless of -o.
597 # Remove the call to Libtool.
598 if test "$libtool" = yes; then
599 while test "X$1" != 'X--mode=compile'; do
605 # Remove '-o $object'.
617 set fnord
"$@" "$arg"
624 test -z "$dashmflag" && dashmflag
=-M
625 # Require at least two characters before searching for ':'
626 # in the target name. This is to cope with DOS-style filenames:
627 # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
629 sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"
631 cat < "$tmpdepfile" > "$depfile"
632 tr ' ' "$nl" < "$tmpdepfile" | \
633 ## Some versions of the HPUX 10.20 sed can't process this invocation
634 ## correctly. Breaking it into two sed invocations is a workaround.
635 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
640 # This case only exists to satisfy depend.m4. It is never actually
641 # run, as this mode is specially recognized in the preamble.
647 # Remove any Libtool call
648 if test "$libtool" = yes; then
649 while test "X$1" != 'X--mode=compile'; do
664 if test $eat = yes; then
670 set fnord
"$@" "$arg"; shift ;;
671 # Strip any option that makedepend may not understand. Remove
672 # the object too, otherwise makedepend will parse it as a source file.
678 set fnord
"$@" "$arg"; shift ;;
681 obj_suffix
=`echo "$object" | sed 's/^.*\././'`
683 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
685 # makedepend may prepend the VPATH from the source file name to the object.
686 # No need to regex-escape $object, excess matching of '.' is harmless.
687 sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
688 sed '1,2d' "$tmpdepfile" |
tr ' ' "$nl" | \
689 ## Some versions of the HPUX 10.20 sed can't process this invocation
690 ## correctly. Breaking it into two sed invocations is a workaround.
691 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' |
sed -e 's/$/ :/' >> "$depfile"
692 rm -f "$tmpdepfile" "$tmpdepfile".bak
696 # Important note: in order to support this mode, a compiler *must*
697 # always write the preprocessed file to stdout.
700 # Remove the call to Libtool.
701 if test "$libtool" = yes; then
702 while test "X$1" != 'X--mode=compile'; do
708 # Remove '-o $object'.
720 set fnord
"$@" "$arg"
728 sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
729 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
730 sed '$ s: \\$::' > "$tmpdepfile"
732 echo "$object : \\" > "$depfile"
733 cat < "$tmpdepfile" >> "$depfile"
734 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
739 # Important note: in order to support this mode, a compiler *must*
740 # always write the preprocessed file to stdout.
743 # Remove the call to Libtool.
744 if test "$libtool" = yes; then
745 while test "X$1" != 'X--mode=compile'; do
761 "-Gm"|
"/Gm"|
"-Gi"|
"/Gi"|
"-ZI"|
"/ZI")
767 set fnord
"$@" "$arg"
773 "$@" -E 2>/dev
/null |
774 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' |
$cygpath_u |
sort -u > "$tmpdepfile"
776 echo "$object : \\" > "$depfile"
777 sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
778 echo "$tab" >> "$depfile"
779 sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
784 # This case exists only to let depend.m4 do its work. It works by
785 # looking at the text of this script. This case will never be run,
786 # since it is checked for above.
795 echo "Unknown depmode $depmode" 1>&2
805 # eval: (add-hook 'write-file-hooks 'time-stamp)
806 # time-stamp-start: "scriptversion="
807 # time-stamp-format: "%:y-%02m-%02d.%02H"
808 # time-stamp-time-zone: "UTC"
809 # time-stamp-end: "; # UTC"