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