1#! /bin/sh 2# $MirOS: src/gnu/share/depcomp,v 1.3 2008/05/03 22:26:44 tg Exp $ 3# $miros: contrib/gnu/automake/lib/depcomp,v 1.4 2008/05/02 23:31:52 tg Exp $ 4#- 5# depcomp - compile a program generating dependencies as side-effects 6 7scriptversion=2007-03-29.01 8 9# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007 Free Software 10# Foundation, Inc. 11 12# This program is free software; you can redistribute it and/or modify 13# it under the terms of the GNU General Public License as published by 14# the Free Software Foundation; either version 2, or (at your option) 15# any later version. 16 17# This program is distributed in the hope that it will be useful, 18# but WITHOUT ANY WARRANTY; without even the implied warranty of 19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20# GNU General Public License for more details. 21 22# You should have received a copy of the GNU General Public License 23# along with this program; if not, write to the Free Software 24# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 25# 02110-1301, USA. 26 27# As a special exception to the GNU General Public License, if you 28# distribute this file as part of a program that contains a 29# configuration script generated by Autoconf, you may include it under 30# the same distribution terms that you use for the rest of that program. 31 32# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 33 34case $1 in 35 '') 36 echo "$0: No command. Try \`$0 --help' for more information." 1>&2 37 exit 1; 38 ;; 39 -h | --h*) 40 cat <<\EOF 41Usage: depcomp [--help] [--version] PROGRAM [ARGS] 42 43Run PROGRAMS ARGS to compile a file, generating dependencies 44as side-effects. 45 46Environment variables: 47 depmode Dependency tracking mode. 48 source Source file read by `PROGRAMS ARGS'. 49 object Object file output by `PROGRAMS ARGS'. 50 DEPDIR directory where to store dependencies. 51 depfile Dependency file to output. 52 tmpdepfile Temporary file to use when outputing dependencies. 53 libtool Whether libtool is used (yes/no). 54 55Report bugs to <bug-automake@gnu.org>. 56EOF 57 exit $? 58 ;; 59 -v | --v*) 60 echo "depcomp $scriptversion" 61 exit $? 62 ;; 63esac 64 65if test -z "$depmode" || test -z "$source" || test -z "$object"; then 66 echo "depcomp: Variables source, object and depmode must be set" 1>&2 67 exit 1 68fi 69 70# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 71depfile=${depfile-`echo "$object" | 72 sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 73tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 74 75rm -f "$tmpdepfile" 76 77# Some modes work just like other modes, but use different flags. We 78# parameterize here, but still list the modes in the big case below, 79# to make depend.m4 easier to write. Note that we *cannot* use a case 80# here, because this file can only contain one case statement. 81if test "$depmode" = hp; then 82 # HP compiler uses -M and no extra arg. 83 gccflag=-M 84 depmode=gcc 85fi 86 87if test "$depmode" = dashXmstdout; then 88 # This is just like dashmstdout with a different argument. 89 dashmflag=-xM 90 depmode=dashmstdout 91fi 92 93case "$depmode" in 94gcc3) 95## gcc 3 implements dependency tracking that does exactly what 96## we want. Yay! Note: for some reason libtool 1.4 doesn't like 97## it if -MD -MP comes after the -MF stuff. Hmm. 98## Unfortunately, FreeBSD c89 acceptance of flags depends upon 99## the command line argument order; so add the flags where they 100## appear in depend2.am. Note that the slowdown incurred here 101## affects only configure: in makefiles, %FASTDEP% shortcuts this. 102 for arg 103 do 104 case $arg in 105 -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 106 *) set fnord "$@" "$arg" ;; 107 esac 108 shift # fnord 109 shift # $arg 110 done 111 "$@" 112 stat=$? 113 if test $stat -eq 0; then : 114 else 115 rm -f "$tmpdepfile" 116 exit $stat 117 fi 118 mv "$tmpdepfile" "$depfile" 119 ;; 120 121gcc) 122## There are various ways to get dependency output from gcc. Here's 123## why we pick this rather obscure method: 124## - Don't want to use -MD because we'd like the dependencies to end 125## up in a subdir. Having to rename by hand is ugly. 126## (We might end up doing this anyway to support other compilers.) 127## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 128## -MM, not -M (despite what the docs say). 129## - Using -M directly means running the compiler twice (even worse 130## than renaming). 131 if test -z "$gccflag"; then 132 gccflag=-MD, 133 fi 134 "$@" -Wp,"$gccflag$tmpdepfile" 135 stat=$? 136 if test $stat -eq 0; then : 137 else 138 rm -f "$tmpdepfile" 139 exit $stat 140 fi 141 rm -f "$depfile" 142 echo "$object : \\" > "$depfile" 143 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 144## The second -e expression handles DOS-style file names with drive letters. 145 sed -e 's/^[^:]*: / /' \ 146 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 147## This next piece of magic avoids the `deleted header file' problem. 148## The problem is that when a header file which appears in a .P file 149## is deleted, the dependency causes make to die (because there is 150## typically no way to rebuild the header). We avoid this by adding 151## dummy dependencies for each header file. Too bad gcc doesn't do 152## this for us directly. 153 tr ' ' ' 154' < "$tmpdepfile" | 155## Some versions of gcc put a space before the `:'. On the theory 156## that the space means something, we add a space to the output as 157## well. 158## Some versions of the HPUX 10.20 sed can't process this invocation 159## correctly. Breaking it into two sed invocations is a workaround. 160 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 161 rm -f "$tmpdepfile" 162 ;; 163 164hp) 165 # This case exists only to let depend.m4 do its work. It works by 166 # looking at the text of this script. This case will never be run, 167 # since it is checked for above. 168 exit 1 169 ;; 170 171sgi) 172 if test "$libtool" = yes; then 173 "$@" "-Wp,-MDupdate,$tmpdepfile" 174 else 175 "$@" -MDupdate "$tmpdepfile" 176 fi 177 stat=$? 178 if test $stat -eq 0; then : 179 else 180 rm -f "$tmpdepfile" 181 exit $stat 182 fi 183 rm -f "$depfile" 184 185 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 186 echo "$object : \\" > "$depfile" 187 188 # Clip off the initial element (the dependent). Don't try to be 189 # clever and replace this with sed code, as IRIX sed won't handle 190 # lines with more than a fixed number of characters (4096 in 191 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 192 # the IRIX cc adds comments like `#:fec' to the end of the 193 # dependency line. 194 tr ' ' ' 195' < "$tmpdepfile" \ 196 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ 197 tr ' 198' ' ' >> $depfile 199 echo >> $depfile 200 201 # The second pass generates a dummy entry for each header file. 202 tr ' ' ' 203' < "$tmpdepfile" \ 204 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 205 >> $depfile 206 else 207 # The sourcefile does not contain any dependencies, so just 208 # store a dummy comment line, to avoid errors with the Makefile 209 # "include basename.Plo" scheme. 210 echo "#dummy" > "$depfile" 211 fi 212 rm -f "$tmpdepfile" 213 ;; 214 215aix) 216 # The C for AIX Compiler uses -M and outputs the dependencies 217 # in a .u file. In older versions, this file always lives in the 218 # current directory. Also, the AIX compiler puts `$object:' at the 219 # start of each line; $object doesn't have directory information. 220 # Version 6 uses the directory in both cases. 221 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 222 test "x$dir" = "x$object" && dir= 223 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 224 if test "$libtool" = yes; then 225 tmpdepfile1=$dir$base.u 226 tmpdepfile2=$base.u 227 tmpdepfile3=$dir.libs/$base.u 228 "$@" -Wc,-M 229 else 230 tmpdepfile1=$dir$base.u 231 tmpdepfile2=$dir$base.u 232 tmpdepfile3=$dir$base.u 233 "$@" -M 234 fi 235 stat=$? 236 237 if test $stat -eq 0; then : 238 else 239 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 240 exit $stat 241 fi 242 243 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 244 do 245 test -f "$tmpdepfile" && break 246 done 247 if test -f "$tmpdepfile"; then 248 # Each line is of the form `foo.o: dependent.h'. 249 # Do two passes, one to just change these to 250 # `$object: dependent.h' and one to simply `dependent.h:'. 251 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 252 # That's a tab and a space in the []. 253 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 254 else 255 # The sourcefile does not contain any dependencies, so just 256 # store a dummy comment line, to avoid errors with the Makefile 257 # "include basename.Plo" scheme. 258 echo "#dummy" > "$depfile" 259 fi 260 rm -f "$tmpdepfile" 261 ;; 262 263icc) 264 # Intel's C compiler understands `-MD -MF file'. However on 265 # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c 266 # ICC 7.0 will fill foo.d with something like 267 # foo.o: sub/foo.c 268 # foo.o: sub/foo.h 269 # which is wrong. We want: 270 # sub/foo.o: sub/foo.c 271 # sub/foo.o: sub/foo.h 272 # sub/foo.c: 273 # sub/foo.h: 274 # ICC 7.1 will output 275 # foo.o: sub/foo.c sub/foo.h 276 # and will wrap long lines using \ : 277 # foo.o: sub/foo.c ... \ 278 # sub/foo.h ... \ 279 # ... 280 281 "$@" -MD -MF "$tmpdepfile" 282 stat=$? 283 if test $stat -eq 0; then : 284 else 285 rm -f "$tmpdepfile" 286 exit $stat 287 fi 288 rm -f "$depfile" 289 # Each line is of the form `foo.o: dependent.h', 290 # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 291 # Do two passes, one to just change these to 292 # `$object: dependent.h' and one to simply `dependent.h:'. 293 sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 294 # Some versions of the HPUX 10.20 sed can't process this invocation 295 # correctly. Breaking it into two sed invocations is a workaround. 296 sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" | 297 sed -e 's/$/ :/' >> "$depfile" 298 rm -f "$tmpdepfile" 299 ;; 300 301hp2) 302 # The "hp" stanza above does not work with aCC (C++) and HP's ia64 303 # compilers, which have integrated preprocessors. The correct option 304 # to use with these is +Maked; it writes dependencies to a file named 305 # 'foo.d', which lands next to the object file, wherever that 306 # happens to be. 307 # Much of this is similar to the tru64 case; see comments there. 308 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 309 test "x$dir" = "x$object" && dir= 310 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 311 if test "$libtool" = yes; then 312 tmpdepfile1=$dir$base.d 313 tmpdepfile2=$dir.libs/$base.d 314 "$@" -Wc,+Maked 315 else 316 tmpdepfile1=$dir$base.d 317 tmpdepfile2=$dir$base.d 318 "$@" +Maked 319 fi 320 stat=$? 321 if test $stat -eq 0; then : 322 else 323 rm -f "$tmpdepfile1" "$tmpdepfile2" 324 exit $stat 325 fi 326 327 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 328 do 329 test -f "$tmpdepfile" && break 330 done 331 if test -f "$tmpdepfile"; then 332 sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile" 333 # Add `dependent.h:' lines. 334 sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile" 335 else 336 echo "#dummy" > "$depfile" 337 fi 338 rm -f "$tmpdepfile" "$tmpdepfile2" 339 ;; 340 341tru64) 342 # The Tru64 compiler uses -MD to generate dependencies as a side 343 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. 344 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 345 # dependencies in `foo.d' instead, so we check for that too. 346 # Subdirectories are respected. 347 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 348 test "x$dir" = "x$object" && dir= 349 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 350 351 if test "$libtool" = yes; then 352 # With Tru64 cc, shared objects can also be used to make a 353 # static library. This mechanism is used in libtool 1.4 series to 354 # handle both shared and static libraries in a single compilation. 355 # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. 356 # 357 # With libtool 1.5 this exception was removed, and libtool now 358 # generates 2 separate objects for the 2 libraries. These two 359 # compilations output dependencies in $dir.libs/$base.o.d and 360 # in $dir$base.o.d. We have to check for both files, because 361 # one of the two compilations can be disabled. We should prefer 362 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 363 # automatically cleaned when .libs/ is deleted, while ignoring 364 # the former would cause a distcleancheck panic. 365 tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 366 tmpdepfile2=$dir$base.o.d # libtool 1.5 367 tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 368 tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 369 "$@" -Wc,-MD 370 else 371 tmpdepfile1=$dir$base.o.d 372 tmpdepfile2=$dir$base.d 373 tmpdepfile3=$dir$base.d 374 tmpdepfile4=$dir$base.d 375 "$@" -MD 376 fi 377 378 stat=$? 379 if test $stat -eq 0; then : 380 else 381 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 382 exit $stat 383 fi 384 385 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 386 do 387 test -f "$tmpdepfile" && break 388 done 389 if test -f "$tmpdepfile"; then 390 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 391 # That's a tab and a space in the []. 392 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 393 else 394 echo "#dummy" > "$depfile" 395 fi 396 rm -f "$tmpdepfile" 397 ;; 398 399#nosideeffect) 400 # This comment above is used by automake to tell side-effect 401 # dependency tracking mechanisms from slower ones. 402 403dashmstdout) 404 # Important note: in order to support this mode, a compiler *must* 405 # always write the preprocessed file to stdout, regardless of -o. 406 "$@" || exit $? 407 408 # Remove the call to Libtool. 409 if test "$libtool" = yes; then 410 while test $1 != '--mode=compile'; do 411 shift 412 done 413 shift 414 fi 415 416 # Remove `-o $object'. 417 IFS=" " 418 for arg 419 do 420 case $arg in 421 -o) 422 shift 423 ;; 424 $object) 425 shift 426 ;; 427 *) 428 set fnord "$@" "$arg" 429 shift # fnord 430 shift # $arg 431 ;; 432 esac 433 done 434 435 test -z "$dashmflag" && dashmflag=-M 436 # Require at least two characters before searching for `:' 437 # in the target name. This is to cope with DOS-style filenames: 438 # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise. 439 "$@" $dashmflag | 440 sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" 441 rm -f "$depfile" 442 cat < "$tmpdepfile" > "$depfile" 443 tr ' ' ' 444' < "$tmpdepfile" | \ 445## Some versions of the HPUX 10.20 sed can't process this invocation 446## correctly. Breaking it into two sed invocations is a workaround. 447 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 448 rm -f "$tmpdepfile" 449 ;; 450 451dashXmstdout) 452 # This case only exists to satisfy depend.m4. It is never actually 453 # run, as this mode is specially recognized in the preamble. 454 exit 1 455 ;; 456 457makedepend) 458 "$@" || exit $? 459 # Remove any Libtool call 460 if test "$libtool" = yes; then 461 while test $1 != '--mode=compile'; do 462 shift 463 done 464 shift 465 fi 466 # X makedepend 467 shift 468 cleared=no 469 for arg in "$@"; do 470 case $cleared in 471 no) 472 set ""; shift 473 cleared=yes ;; 474 esac 475 case "$arg" in 476 -D*|-I*) 477 set fnord "$@" "$arg"; shift ;; 478 # Strip any option that makedepend may not understand. Remove 479 # the object too, otherwise makedepend will parse it as a source file. 480 -*|$object) 481 ;; 482 *) 483 set fnord "$@" "$arg"; shift ;; 484 esac 485 done 486 obj_suffix="`echo $object | sed 's/^.*\././'`" 487 touch "$tmpdepfile" 488 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 489 rm -f "$depfile" 490 cat < "$tmpdepfile" > "$depfile" 491 sed '1,2d' "$tmpdepfile" | tr ' ' ' 492' | \ 493## Some versions of the HPUX 10.20 sed can't process this invocation 494## correctly. Breaking it into two sed invocations is a workaround. 495 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 496 rm -f "$tmpdepfile" "$tmpdepfile".bak 497 ;; 498 499cpp) 500 # Important note: in order to support this mode, a compiler *must* 501 # always write the preprocessed file to stdout. 502 "$@" || exit $? 503 504 # Remove the call to Libtool. 505 if test "$libtool" = yes; then 506 while test $1 != '--mode=compile'; do 507 shift 508 done 509 shift 510 fi 511 512 # Remove `-o $object'. 513 IFS=" " 514 for arg 515 do 516 case $arg in 517 -o) 518 shift 519 ;; 520 $object) 521 shift 522 ;; 523 *) 524 set fnord "$@" "$arg" 525 shift # fnord 526 shift # $arg 527 ;; 528 esac 529 done 530 531 "$@" -E | 532 sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 533 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | 534 sed '$ s: \\$::' > "$tmpdepfile" 535 rm -f "$depfile" 536 echo "$object : \\" > "$depfile" 537 cat < "$tmpdepfile" >> "$depfile" 538 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 539 rm -f "$tmpdepfile" 540 ;; 541 542msvisualcpp) 543 # Important note: in order to support this mode, a compiler *must* 544 # always write the preprocessed file to stdout, regardless of -o, 545 # because we must use -o when running libtool. 546 "$@" || exit $? 547 IFS=" " 548 for arg 549 do 550 case "$arg" in 551 "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 552 set fnord "$@" 553 shift 554 shift 555 ;; 556 *) 557 set fnord "$@" "$arg" 558 shift 559 shift 560 ;; 561 esac 562 done 563 "$@" -E | 564 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" 565 rm -f "$depfile" 566 echo "$object : \\" > "$depfile" 567 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" 568 echo " " >> "$depfile" 569 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" 570 rm -f "$tmpdepfile" 571 ;; 572 573none) 574 exec "$@" 575 ;; 576 577*) 578 echo "Unknown depmode $depmode" 1>&2 579 exit 1 580 ;; 581esac 582 583exit 0 584 585# Local Variables: 586# mode: shell-script 587# sh-indentation: 2 588# eval: (add-hook 'write-file-hooks 'time-stamp) 589# time-stamp-start: "scriptversion=" 590# time-stamp-format: "%:y-%02m-%02d.%02H" 591# time-stamp-end: "$" 592# End: 593