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