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