annotate kdiff3/admin/depcomp @ 14:415083d043f3

KDiff3 version 0.9.70
author joachim99
date Mon, 06 Oct 2003 19:19:11 +0000
parents 53b8ecbce0cb
children 8febbfb1148c
rev   line source
joachim99@2 1 #! /bin/sh
joachim99@2 2
joachim99@2 3 # depcomp - compile a program generating dependencies as side-effects
joachim99@2 4 # Copyright 1999, 2000 Free Software Foundation, Inc.
joachim99@2 5
joachim99@2 6 # This program is free software; you can redistribute it and/or modify
joachim99@2 7 # it under the terms of the GNU General Public License as published by
joachim99@2 8 # the Free Software Foundation; either version 2, or (at your option)
joachim99@2 9 # any later version.
joachim99@2 10
joachim99@2 11 # This program is distributed in the hope that it will be useful,
joachim99@2 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
joachim99@2 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
joachim99@2 14 # GNU General Public License for more details.
joachim99@2 15
joachim99@2 16 # You should have received a copy of the GNU General Public License
joachim99@2 17 # along with this program; if not, write to the Free Software
joachim99@2 18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
joachim99@2 19 # 02111-1307, USA.
joachim99@2 20
joachim99@14 21 # As a special exception to the GNU General Public License, if you
joachim99@14 22 # distribute this file as part of a program that contains a
joachim99@14 23 # configuration script generated by Autoconf, you may include it under
joachim99@14 24 # the same distribution terms that you use for the rest of that program.
joachim99@14 25
joachim99@2 26 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
joachim99@2 27
joachim99@2 28 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
joachim99@2 29 echo "depcomp: Variables source, object and depmode must be set" 1>&2
joachim99@2 30 exit 1
joachim99@2 31 fi
joachim99@2 32 # `libtool' can also be set to `yes' or `no'.
joachim99@2 33
joachim99@2 34 depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
joachim99@2 35 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
joachim99@2 36
joachim99@2 37 rm -f "$tmpdepfile"
joachim99@2 38
joachim99@2 39 # Some modes work just like other modes, but use different flags. We
joachim99@2 40 # parameterize here, but still list the modes in the big case below,
joachim99@2 41 # to make depend.m4 easier to write. Note that we *cannot* use a case
joachim99@2 42 # here, because this file can only contain one case statement.
joachim99@2 43 if test "$depmode" = hp; then
joachim99@2 44 # HP compiler uses -M and no extra arg.
joachim99@2 45 gccflag=-M
joachim99@2 46 depmode=gcc
joachim99@2 47 fi
joachim99@2 48
joachim99@2 49 if test "$depmode" = dashXmstdout; then
joachim99@2 50 # This is just like dashmstdout with a different argument.
joachim99@2 51 dashmflag=-xM
joachim99@2 52 depmode=dashmstdout
joachim99@2 53 fi
joachim99@2 54
joachim99@2 55 case "$depmode" in
joachim99@2 56 gcc3)
joachim99@2 57 ## gcc 3 implements dependency tracking that does exactly what
joachim99@14 58 ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
joachim99@14 59 ## it if -MD -MP comes after the -MF stuff. Hmm.
joachim99@14 60 "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
joachim99@14 61 stat=$?
joachim99@14 62 if test $stat -eq 0; then :
joachim99@2 63 else
joachim99@2 64 rm -f "$tmpdepfile"
joachim99@2 65 exit $stat
joachim99@2 66 fi
joachim99@2 67 mv "$tmpdepfile" "$depfile"
joachim99@2 68 ;;
joachim99@2 69
joachim99@2 70 gcc)
joachim99@2 71 ## There are various ways to get dependency output from gcc. Here's
joachim99@2 72 ## why we pick this rather obscure method:
joachim99@2 73 ## - Don't want to use -MD because we'd like the dependencies to end
joachim99@2 74 ## up in a subdir. Having to rename by hand is ugly.
joachim99@2 75 ## (We might end up doing this anyway to support other compilers.)
joachim99@2 76 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
joachim99@2 77 ## -MM, not -M (despite what the docs say).
joachim99@2 78 ## - Using -M directly means running the compiler twice (even worse
joachim99@2 79 ## than renaming).
joachim99@2 80 if test -z "$gccflag"; then
joachim99@2 81 gccflag=-MD,
joachim99@2 82 fi
joachim99@14 83 "$@" -Wp,"$gccflag$tmpdepfile"
joachim99@14 84 stat=$?
joachim99@14 85 if test $stat -eq 0; then :
joachim99@2 86 else
joachim99@2 87 rm -f "$tmpdepfile"
joachim99@2 88 exit $stat
joachim99@2 89 fi
joachim99@2 90 rm -f "$depfile"
joachim99@2 91 echo "$object : \\" > "$depfile"
joachim99@2 92 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
joachim99@2 93 ## The second -e expression handles DOS-style file names with drive letters.
joachim99@2 94 sed -e 's/^[^:]*: / /' \
joachim99@2 95 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
joachim99@2 96 ## This next piece of magic avoids the `deleted header file' problem.
joachim99@2 97 ## The problem is that when a header file which appears in a .P file
joachim99@2 98 ## is deleted, the dependency causes make to die (because there is
joachim99@2 99 ## typically no way to rebuild the header). We avoid this by adding
joachim99@2 100 ## dummy dependencies for each header file. Too bad gcc doesn't do
joachim99@2 101 ## this for us directly.
joachim99@2 102 tr ' ' '
joachim99@2 103 ' < "$tmpdepfile" |
joachim99@2 104 ## Some versions of gcc put a space before the `:'. On the theory
joachim99@2 105 ## that the space means something, we add a space to the output as
joachim99@2 106 ## well.
joachim99@2 107 ## Some versions of the HPUX 10.20 sed can't process this invocation
joachim99@2 108 ## correctly. Breaking it into two sed invocations is a workaround.
joachim99@2 109 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
joachim99@2 110 rm -f "$tmpdepfile"
joachim99@2 111 ;;
joachim99@2 112
joachim99@2 113 hp)
joachim99@2 114 # This case exists only to let depend.m4 do its work. It works by
joachim99@2 115 # looking at the text of this script. This case will never be run,
joachim99@2 116 # since it is checked for above.
joachim99@2 117 exit 1
joachim99@2 118 ;;
joachim99@2 119
joachim99@2 120 sgi)
joachim99@2 121 if test "$libtool" = yes; then
joachim99@2 122 "$@" "-Wp,-MDupdate,$tmpdepfile"
joachim99@2 123 else
joachim99@2 124 "$@" -MDupdate "$tmpdepfile"
joachim99@2 125 fi
joachim99@2 126 stat=$?
joachim99@2 127 if test $stat -eq 0; then :
joachim99@2 128 else
joachim99@2 129 rm -f "$tmpdepfile"
joachim99@2 130 exit $stat
joachim99@2 131 fi
joachim99@2 132 rm -f "$depfile"
joachim99@2 133
joachim99@2 134 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
joachim99@2 135 echo "$object : \\" > "$depfile"
joachim99@2 136
joachim99@14 137 # Clip off the initial element (the dependent). Don't try to be
joachim99@2 138 # clever and replace this with sed code, as IRIX sed won't handle
joachim99@2 139 # lines with more than a fixed number of characters (4096 in
joachim99@14 140 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
joachim99@14 141 # the IRIX cc adds comments like `#:fec' to the end of the
joachim99@14 142 # dependency line.
joachim99@2 143 tr ' ' '
joachim99@14 144 ' < "$tmpdepfile" \
joachim99@14 145 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
joachim99@14 146 tr '
joachim99@2 147 ' ' ' >> $depfile
joachim99@14 148 echo >> $depfile
joachim99@2 149
joachim99@14 150 # The second pass generates a dummy entry for each header file.
joachim99@2 151 tr ' ' '
joachim99@14 152 ' < "$tmpdepfile" \
joachim99@14 153 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
joachim99@14 154 >> $depfile
joachim99@2 155 else
joachim99@2 156 # The sourcefile does not contain any dependencies, so just
joachim99@2 157 # store a dummy comment line, to avoid errors with the Makefile
joachim99@2 158 # "include basename.Plo" scheme.
joachim99@2 159 echo "#dummy" > "$depfile"
joachim99@2 160 fi
joachim99@2 161 rm -f "$tmpdepfile"
joachim99@2 162 ;;
joachim99@2 163
joachim99@2 164 aix)
joachim99@2 165 # The C for AIX Compiler uses -M and outputs the dependencies
joachim99@14 166 # in a .u file. This file always lives in the current directory.
joachim99@14 167 # Also, the AIX compiler puts `$object:' at the start of each line;
joachim99@14 168 # $object doesn't have directory information.
joachim99@14 169 stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
joachim99@14 170 tmpdepfile="$stripped.u"
joachim99@14 171 outname="$stripped.o"
joachim99@2 172 if test "$libtool" = yes; then
joachim99@2 173 "$@" -Wc,-M
joachim99@2 174 else
joachim99@2 175 "$@" -M
joachim99@2 176 fi
joachim99@2 177
joachim99@2 178 stat=$?
joachim99@2 179 if test $stat -eq 0; then :
joachim99@2 180 else
joachim99@2 181 rm -f "$tmpdepfile"
joachim99@2 182 exit $stat
joachim99@2 183 fi
joachim99@2 184
joachim99@2 185 if test -f "$tmpdepfile"; then
joachim99@14 186 # Each line is of the form `foo.o: dependent.h'.
joachim99@14 187 # Do two passes, one to just change these to
joachim99@14 188 # `$object: dependent.h' and one to simply `dependent.h:'.
joachim99@14 189 sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
joachim99@14 190 sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
joachim99@2 191 else
joachim99@2 192 # The sourcefile does not contain any dependencies, so just
joachim99@2 193 # store a dummy comment line, to avoid errors with the Makefile
joachim99@2 194 # "include basename.Plo" scheme.
joachim99@2 195 echo "#dummy" > "$depfile"
joachim99@2 196 fi
joachim99@2 197 rm -f "$tmpdepfile"
joachim99@2 198 ;;
joachim99@2 199
joachim99@14 200 icc)
joachim99@14 201 # Must come before tru64.
joachim99@14 202
joachim99@14 203 # Intel's C compiler understands `-MD -MF file'. However
joachim99@14 204 # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
joachim99@14 205 # will fill foo.d with something like
joachim99@14 206 # foo.o: sub/foo.c
joachim99@14 207 # foo.o: sub/foo.h
joachim99@14 208 # which is wrong. We want:
joachim99@14 209 # sub/foo.o: sub/foo.c
joachim99@14 210 # sub/foo.o: sub/foo.h
joachim99@14 211 # sub/foo.c:
joachim99@14 212 # sub/foo.h:
joachim99@14 213
joachim99@14 214 "$@" -MD -MF "$tmpdepfile"
joachim99@14 215 stat=$?
joachim99@14 216 if test $stat -eq 0; then :
joachim99@14 217 else
joachim99@14 218 rm -f "$tmpdepfile"
joachim99@14 219 exit $stat
joachim99@14 220 fi
joachim99@14 221 rm -f "$depfile"
joachim99@14 222 # Each line is of the form `foo.o: dependent.h'.
joachim99@14 223 # Do two passes, one to just change these to
joachim99@14 224 # `$object: dependent.h' and one to simply `dependent.h:'.
joachim99@14 225 sed -e "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
joachim99@14 226 sed -e "s,^[^:]*: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
joachim99@14 227 rm -f "$tmpdepfile"
joachim99@14 228 ;;
joachim99@14 229
joachim99@14 230 tru64)
joachim99@14 231 # The Tru64 AIX compiler uses -MD to generate dependencies as a side
joachim99@14 232 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
joachim99@14 233 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
joachim99@14 234 # dependencies in `foo.d' instead, so we check for that too.
joachim99@14 235 # Subdirectories are respected.
joachim99@14 236
joachim99@14 237 tmpdepfile1="$object.d"
joachim99@14 238 tmpdepfile2=`echo "$object" | sed -e 's/.o$/.d/'`
joachim99@14 239 if test "$libtool" = yes; then
joachim99@14 240 "$@" -Wc,-MD
joachim99@14 241 else
joachim99@14 242 "$@" -MD
joachim99@14 243 fi
joachim99@14 244
joachim99@14 245 stat=$?
joachim99@14 246 if test $stat -eq 0; then :
joachim99@14 247 else
joachim99@14 248 rm -f "$tmpdepfile1" "$tmpdepfile2"
joachim99@14 249 exit $stat
joachim99@14 250 fi
joachim99@14 251
joachim99@14 252 if test -f "$tmpdepfile1"; then
joachim99@14 253 tmpdepfile="$tmpdepfile1"
joachim99@14 254 else
joachim99@14 255 tmpdepfile="$tmpdepfile2"
joachim99@14 256 fi
joachim99@14 257 if test -f "$tmpdepfile"; then
joachim99@14 258 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
joachim99@14 259 # That's a space and a tab in the [].
joachim99@14 260 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
joachim99@14 261 else
joachim99@14 262 echo "#dummy" > "$depfile"
joachim99@14 263 fi
joachim99@14 264 rm -f "$tmpdepfile"
joachim99@14 265 ;;
joachim99@14 266
joachim99@2 267 #nosideeffect)
joachim99@2 268 # This comment above is used by automake to tell side-effect
joachim99@2 269 # dependency tracking mechanisms from slower ones.
joachim99@2 270
joachim99@2 271 dashmstdout)
joachim99@2 272 # Important note: in order to support this mode, a compiler *must*
joachim99@2 273 # always write the proprocessed file to stdout, regardless of -o,
joachim99@2 274 # because we must use -o when running libtool.
joachim99@2 275 test -z "$dashmflag" && dashmflag=-M
joachim99@2 276 ( IFS=" "
joachim99@2 277 case " $* " in
joachim99@2 278 *" --mode=compile "*) # this is libtool, let us make it quiet
joachim99@2 279 for arg
joachim99@2 280 do # cycle over the arguments
joachim99@2 281 case "$arg" in
joachim99@2 282 "--mode=compile")
joachim99@2 283 # insert --quiet before "--mode=compile"
joachim99@2 284 set fnord "$@" --quiet
joachim99@2 285 shift # fnord
joachim99@2 286 ;;
joachim99@2 287 esac
joachim99@2 288 set fnord "$@" "$arg"
joachim99@2 289 shift # fnord
joachim99@2 290 shift # "$arg"
joachim99@2 291 done
joachim99@2 292 ;;
joachim99@2 293 esac
joachim99@2 294 "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
joachim99@2 295 ) &
joachim99@2 296 proc=$!
joachim99@2 297 "$@"
joachim99@2 298 stat=$?
joachim99@2 299 wait "$proc"
joachim99@2 300 if test "$stat" != 0; then exit $stat; fi
joachim99@2 301 rm -f "$depfile"
joachim99@2 302 cat < "$tmpdepfile" > "$depfile"
joachim99@2 303 tr ' ' '
joachim99@2 304 ' < "$tmpdepfile" | \
joachim99@2 305 ## Some versions of the HPUX 10.20 sed can't process this invocation
joachim99@2 306 ## correctly. Breaking it into two sed invocations is a workaround.
joachim99@2 307 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
joachim99@2 308 rm -f "$tmpdepfile"
joachim99@2 309 ;;
joachim99@2 310
joachim99@2 311 dashXmstdout)
joachim99@2 312 # This case only exists to satisfy depend.m4. It is never actually
joachim99@2 313 # run, as this mode is specially recognized in the preamble.
joachim99@2 314 exit 1
joachim99@2 315 ;;
joachim99@2 316
joachim99@2 317 makedepend)
joachim99@2 318 # X makedepend
joachim99@2 319 (
joachim99@2 320 shift
joachim99@2 321 cleared=no
joachim99@2 322 for arg in "$@"; do
joachim99@2 323 case $cleared in no)
joachim99@2 324 set ""; shift
joachim99@2 325 cleared=yes
joachim99@2 326 esac
joachim99@2 327 case "$arg" in
joachim99@2 328 -D*|-I*)
joachim99@2 329 set fnord "$@" "$arg"; shift;;
joachim99@2 330 -*)
joachim99@2 331 ;;
joachim99@2 332 *)
joachim99@2 333 set fnord "$@" "$arg"; shift;;
joachim99@2 334 esac
joachim99@2 335 done
joachim99@2 336 obj_suffix="`echo $object | sed 's/^.*\././'`"
joachim99@2 337 touch "$tmpdepfile"
joachim99@2 338 ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
joachim99@2 339 ) &
joachim99@2 340 proc=$!
joachim99@2 341 "$@"
joachim99@2 342 stat=$?
joachim99@2 343 wait "$proc"
joachim99@2 344 if test "$stat" != 0; then exit $stat; fi
joachim99@2 345 rm -f "$depfile"
joachim99@2 346 cat < "$tmpdepfile" > "$depfile"
joachim99@2 347 tail +3 "$tmpdepfile" | tr ' ' '
joachim99@2 348 ' | \
joachim99@2 349 ## Some versions of the HPUX 10.20 sed can't process this invocation
joachim99@2 350 ## correctly. Breaking it into two sed invocations is a workaround.
joachim99@2 351 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
joachim99@2 352 rm -f "$tmpdepfile" "$tmpdepfile".bak
joachim99@2 353 ;;
joachim99@2 354
joachim99@2 355 cpp)
joachim99@2 356 # Important note: in order to support this mode, a compiler *must*
joachim99@2 357 # always write the proprocessed file to stdout, regardless of -o,
joachim99@2 358 # because we must use -o when running libtool.
joachim99@2 359 ( IFS=" "
joachim99@2 360 case " $* " in
joachim99@2 361 *" --mode=compile "*)
joachim99@2 362 for arg
joachim99@2 363 do # cycle over the arguments
joachim99@2 364 case $arg in
joachim99@2 365 "--mode=compile")
joachim99@2 366 # insert --quiet before "--mode=compile"
joachim99@2 367 set fnord "$@" --quiet
joachim99@2 368 shift # fnord
joachim99@2 369 ;;
joachim99@2 370 esac
joachim99@2 371 set fnord "$@" "$arg"
joachim99@2 372 shift # fnord
joachim99@2 373 shift # "$arg"
joachim99@2 374 done
joachim99@2 375 ;;
joachim99@2 376 esac
joachim99@2 377 "$@" -E |
joachim99@2 378 sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
joachim99@2 379 sed '$ s: \\$::' > "$tmpdepfile"
joachim99@2 380 ) &
joachim99@2 381 proc=$!
joachim99@2 382 "$@"
joachim99@2 383 stat=$?
joachim99@2 384 wait "$proc"
joachim99@2 385 if test "$stat" != 0; then exit $stat; fi
joachim99@2 386 rm -f "$depfile"
joachim99@2 387 echo "$object : \\" > "$depfile"
joachim99@2 388 cat < "$tmpdepfile" >> "$depfile"
joachim99@2 389 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
joachim99@2 390 rm -f "$tmpdepfile"
joachim99@2 391 ;;
joachim99@2 392
joachim99@2 393 msvisualcpp)
joachim99@2 394 # Important note: in order to support this mode, a compiler *must*
joachim99@2 395 # always write the proprocessed file to stdout, regardless of -o,
joachim99@2 396 # because we must use -o when running libtool.
joachim99@2 397 ( IFS=" "
joachim99@2 398 case " $* " in
joachim99@2 399 *" --mode=compile "*)
joachim99@2 400 for arg
joachim99@2 401 do # cycle over the arguments
joachim99@2 402 case $arg in
joachim99@2 403 "--mode=compile")
joachim99@2 404 # insert --quiet before "--mode=compile"
joachim99@2 405 set fnord "$@" --quiet
joachim99@2 406 shift # fnord
joachim99@2 407 ;;
joachim99@2 408 esac
joachim99@2 409 set fnord "$@" "$arg"
joachim99@2 410 shift # fnord
joachim99@2 411 shift # "$arg"
joachim99@2 412 done
joachim99@2 413 ;;
joachim99@2 414 esac
joachim99@2 415 "$@" -E |
joachim99@2 416 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
joachim99@2 417 ) &
joachim99@2 418 proc=$!
joachim99@2 419 "$@"
joachim99@2 420 stat=$?
joachim99@2 421 wait "$proc"
joachim99@2 422 if test "$stat" != 0; then exit $stat; fi
joachim99@2 423 rm -f "$depfile"
joachim99@2 424 echo "$object : \\" > "$depfile"
joachim99@2 425 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
joachim99@2 426 echo " " >> "$depfile"
joachim99@2 427 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
joachim99@2 428 rm -f "$tmpdepfile"
joachim99@2 429 ;;
joachim99@2 430
joachim99@2 431 none)
joachim99@2 432 exec "$@"
joachim99@2 433 ;;
joachim99@2 434
joachim99@2 435 *)
joachim99@2 436 echo "Unknown depmode $depmode" 1>&2
joachim99@2 437 exit 1
joachim99@2 438 ;;
joachim99@2 439 esac
joachim99@2 440
joachim99@2 441 exit 0