Support nanosecond timestamps and time arguments with fractional parts
[findutils.git] / depcomp
blobffe5461bdead5741ab8de333fb015a950d090a0d
1 #! /bin/sh
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
7 # Foundation, Inc.
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)
12 # any later version.
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
22 # 02110-1301, USA.
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>.
31 case $1 in
32 '')
33 echo "$0: No command. Try \`$0 --help' for more information." 1>&2
34 exit 1;
36 -h | --h*)
37 cat <<\EOF
38 Usage: depcomp [--help] [--version] PROGRAM [ARGS]
40 Run PROGRAMS ARGS to compile a file, generating dependencies
41 as side-effects.
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>.
53 EOF
54 exit $?
56 -v | --v*)
57 echo "depcomp $scriptversion"
58 exit $?
60 esac
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
64 exit 1
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/'`}
72 rm -f "$tmpdepfile"
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.
80 gccflag=-M
81 depmode=gcc
84 if test "$depmode" = dashXmstdout; then
85 # This is just like dashmstdout with a different argument.
86 dashmflag=-xM
87 depmode=dashmstdout
90 case "$depmode" in
91 gcc3)
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"
96 stat=$?
97 if test $stat -eq 0; then :
98 else
99 rm -f "$tmpdepfile"
100 exit $stat
102 mv "$tmpdepfile" "$depfile"
105 gcc)
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
114 ## than renaming).
115 if test -z "$gccflag"; then
116 gccflag=-MD,
118 "$@" -Wp,"$gccflag$tmpdepfile"
119 stat=$?
120 if test $stat -eq 0; then :
121 else
122 rm -f "$tmpdepfile"
123 exit $stat
125 rm -f "$depfile"
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.
137 tr ' ' '
138 ' < "$tmpdepfile" |
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
141 ## well.
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"
145 rm -f "$tmpdepfile"
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.
152 exit 1
155 sgi)
156 if test "$libtool" = yes; then
157 "$@" "-Wp,-MDupdate,$tmpdepfile"
158 else
159 "$@" -MDupdate "$tmpdepfile"
161 stat=$?
162 if test $stat -eq 0; then :
163 else
164 rm -f "$tmpdepfile"
165 exit $stat
167 rm -f "$depfile"
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
177 # dependency line.
178 tr ' ' '
179 ' < "$tmpdepfile" \
180 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
181 tr '
182 ' ' ' >> $depfile
183 echo >> $depfile
185 # The second pass generates a dummy entry for each header file.
186 tr ' ' '
187 ' < "$tmpdepfile" \
188 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
189 >> $depfile
190 else
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"
196 rm -f "$tmpdepfile"
199 aix)
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
208 "$@" -Wc,-M
209 else
210 "$@" -M
212 stat=$?
214 if test -f "$tmpdepfile"; then :
215 else
216 stripped=`echo "$stripped" | sed 's,^.*/,,'`
217 tmpdepfile="$stripped.u"
220 if test $stat -eq 0; then :
221 else
222 rm -f "$tmpdepfile"
223 exit $stat
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"
233 else
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"
239 rm -f "$tmpdepfile"
242 icc)
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
246 # foo.o: sub/foo.c
247 # foo.o: sub/foo.h
248 # which is wrong. We want:
249 # sub/foo.o: sub/foo.c
250 # sub/foo.o: sub/foo.h
251 # sub/foo.c:
252 # 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 ... \
257 # sub/foo.h ... \
258 # ...
260 "$@" -MD -MF "$tmpdepfile"
261 stat=$?
262 if test $stat -eq 0; then :
263 else
264 rm -f "$tmpdepfile"
265 exit $stat
267 rm -f "$depfile"
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"
277 rm -f "$tmpdepfile"
280 hp2)
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
285 # happens to be.
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
293 "$@" -Wc,+Maked
294 else
295 tmpdepfile1=$dir$base.d
296 tmpdepfile2=$dir$base.d
297 "$@" +Maked
299 stat=$?
300 if test $stat -eq 0; then :
301 else
302 rm -f "$tmpdepfile1" "$tmpdepfile2"
303 exit $stat
306 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
308 test -f "$tmpdepfile" && break
309 done
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"
314 else
315 echo "#dummy" > "$depfile"
317 rm -f "$tmpdepfile" "$tmpdepfile2"
320 tru64)
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
348 "$@" -Wc,-MD
349 else
350 tmpdepfile1=$dir$base.o.d
351 tmpdepfile2=$dir$base.d
352 tmpdepfile3=$dir$base.d
353 tmpdepfile4=$dir$base.d
354 "$@" -MD
357 stat=$?
358 if test $stat -eq 0; then :
359 else
360 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
361 exit $stat
364 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
366 test -f "$tmpdepfile" && break
367 done
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"
372 else
373 echo "#dummy" > "$depfile"
375 rm -f "$tmpdepfile"
378 #nosideeffect)
379 # This comment above is used by automake to tell side-effect
380 # dependency tracking mechanisms from slower ones.
382 dashmstdout)
383 # Important note: in order to support this mode, a compiler *must*
384 # always write the preprocessed file to stdout, regardless of -o.
385 "$@" || exit $?
387 # Remove the call to Libtool.
388 if test "$libtool" = yes; then
389 while test $1 != '--mode=compile'; do
390 shift
391 done
392 shift
395 # Remove `-o $object'.
396 IFS=" "
397 for arg
399 case $arg in
401 shift
403 $object)
404 shift
407 set fnord "$@" "$arg"
408 shift # fnord
409 shift # $arg
411 esac
412 done
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.
418 "$@" $dashmflag |
419 sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
420 rm -f "$depfile"
421 cat < "$tmpdepfile" > "$depfile"
422 tr ' ' '
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"
427 rm -f "$tmpdepfile"
430 dashXmstdout)
431 # This case only exists to satisfy depend.m4. It is never actually
432 # run, as this mode is specially recognized in the preamble.
433 exit 1
436 makedepend)
437 "$@" || exit $?
438 # Remove any Libtool call
439 if test "$libtool" = yes; then
440 while test $1 != '--mode=compile'; do
441 shift
442 done
443 shift
445 # X makedepend
446 shift
447 cleared=no
448 for arg in "$@"; do
449 case $cleared in
451 set ""; shift
452 cleared=yes ;;
453 esac
454 case "$arg" in
455 -D*|-I*)
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.
459 -*|$object)
462 set fnord "$@" "$arg"; shift ;;
463 esac
464 done
465 obj_suffix="`echo $object | sed 's/^.*\././'`"
466 touch "$tmpdepfile"
467 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
468 rm -f "$depfile"
469 cat < "$tmpdepfile" > "$depfile"
470 sed '1,2d' "$tmpdepfile" | tr ' ' '
471 ' | \
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
478 cpp)
479 # Important note: in order to support this mode, a compiler *must*
480 # always write the preprocessed file to stdout.
481 "$@" || exit $?
483 # Remove the call to Libtool.
484 if test "$libtool" = yes; then
485 while test $1 != '--mode=compile'; do
486 shift
487 done
488 shift
491 # Remove `-o $object'.
492 IFS=" "
493 for arg
495 case $arg in
497 shift
499 $object)
500 shift
503 set fnord "$@" "$arg"
504 shift # fnord
505 shift # $arg
507 esac
508 done
510 "$@" -E |
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"
514 rm -f "$depfile"
515 echo "$object : \\" > "$depfile"
516 cat < "$tmpdepfile" >> "$depfile"
517 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
518 rm -f "$tmpdepfile"
521 msvisualcpp)
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.
525 "$@" || exit $?
526 IFS=" "
527 for arg
529 case "$arg" in
530 "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
531 set fnord "$@"
532 shift
533 shift
536 set fnord "$@" "$arg"
537 shift
538 shift
540 esac
541 done
542 "$@" -E |
543 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
544 rm -f "$depfile"
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"
549 rm -f "$tmpdepfile"
552 none)
553 exec "$@"
557 echo "Unknown depmode $depmode" 1>&2
558 exit 1
560 esac
562 exit 0
564 # Local Variables:
565 # mode: shell-script
566 # sh-indentation: 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: "$"
571 # End: