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