1357f1050SThomas Veerman#! /bin/sh 2357f1050SThomas Veerman# depcomp - compile a program generating dependencies as side-effects 3357f1050SThomas Veerman 4*0a6a1f1dSLionel Sambucscriptversion=2012-03-27.16; # UTC 5357f1050SThomas Veerman 6*0a6a1f1dSLionel Sambuc# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 7*0a6a1f1dSLionel Sambuc# 2011, 2012 Free Software Foundation, Inc. 8357f1050SThomas Veerman 9357f1050SThomas Veerman# This program is free software; you can redistribute it and/or modify 10357f1050SThomas Veerman# it under the terms of the GNU General Public License as published by 11357f1050SThomas Veerman# the Free Software Foundation; either version 2, or (at your option) 12357f1050SThomas Veerman# any later version. 13357f1050SThomas Veerman 14357f1050SThomas Veerman# This program is distributed in the hope that it will be useful, 15357f1050SThomas Veerman# but WITHOUT ANY WARRANTY; without even the implied warranty of 16357f1050SThomas Veerman# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17357f1050SThomas Veerman# GNU General Public License for more details. 18357f1050SThomas Veerman 19357f1050SThomas Veerman# You should have received a copy of the GNU General Public License 2084d9c625SLionel Sambuc# along with this program. If not, see <http://www.gnu.org/licenses/>. 21357f1050SThomas Veerman 22357f1050SThomas Veerman# As a special exception to the GNU General Public License, if you 23357f1050SThomas Veerman# distribute this file as part of a program that contains a 24357f1050SThomas Veerman# configuration script generated by Autoconf, you may include it under 25357f1050SThomas Veerman# the same distribution terms that you use for the rest of that program. 26357f1050SThomas Veerman 27357f1050SThomas Veerman# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 28357f1050SThomas Veerman 29357f1050SThomas Veermancase $1 in 30357f1050SThomas Veerman '') 31*0a6a1f1dSLionel Sambuc echo "$0: No command. Try '$0 --help' for more information." 1>&2 32357f1050SThomas Veerman exit 1; 33357f1050SThomas Veerman ;; 34357f1050SThomas Veerman -h | --h*) 35357f1050SThomas Veerman cat <<\EOF 36357f1050SThomas VeermanUsage: depcomp [--help] [--version] PROGRAM [ARGS] 37357f1050SThomas Veerman 38357f1050SThomas VeermanRun PROGRAMS ARGS to compile a file, generating dependencies 39357f1050SThomas Veermanas side-effects. 40357f1050SThomas Veerman 41357f1050SThomas VeermanEnvironment variables: 42357f1050SThomas Veerman depmode Dependency tracking mode. 43*0a6a1f1dSLionel Sambuc source Source file read by 'PROGRAMS ARGS'. 44*0a6a1f1dSLionel Sambuc object Object file output by 'PROGRAMS ARGS'. 45357f1050SThomas Veerman DEPDIR directory where to store dependencies. 46357f1050SThomas Veerman depfile Dependency file to output. 47*0a6a1f1dSLionel Sambuc tmpdepfile Temporary file to use when outputting dependencies. 48357f1050SThomas Veerman libtool Whether libtool is used (yes/no). 49357f1050SThomas Veerman 50357f1050SThomas VeermanReport bugs to <bug-automake@gnu.org>. 51357f1050SThomas VeermanEOF 52357f1050SThomas Veerman exit $? 53357f1050SThomas Veerman ;; 54357f1050SThomas Veerman -v | --v*) 55357f1050SThomas Veerman echo "depcomp $scriptversion" 56357f1050SThomas Veerman exit $? 57357f1050SThomas Veerman ;; 58357f1050SThomas Veermanesac 59357f1050SThomas Veerman 60*0a6a1f1dSLionel Sambuc# A tabulation character. 61*0a6a1f1dSLionel Sambuctab=' ' 62*0a6a1f1dSLionel Sambuc# A newline character. 63*0a6a1f1dSLionel Sambucnl=' 64*0a6a1f1dSLionel Sambuc' 65*0a6a1f1dSLionel Sambuc 66357f1050SThomas Veermanif test -z "$depmode" || test -z "$source" || test -z "$object"; then 67357f1050SThomas Veerman echo "depcomp: Variables source, object and depmode must be set" 1>&2 68357f1050SThomas Veerman exit 1 69357f1050SThomas Veermanfi 70357f1050SThomas Veerman 71357f1050SThomas Veerman# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 72357f1050SThomas Veermandepfile=${depfile-`echo "$object" | 73357f1050SThomas Veerman sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 74357f1050SThomas Veermantmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 75357f1050SThomas Veerman 76357f1050SThomas Veermanrm -f "$tmpdepfile" 77357f1050SThomas Veerman 78357f1050SThomas Veerman# Some modes work just like other modes, but use different flags. We 79357f1050SThomas Veerman# parameterize here, but still list the modes in the big case below, 80357f1050SThomas Veerman# to make depend.m4 easier to write. Note that we *cannot* use a case 81357f1050SThomas Veerman# here, because this file can only contain one case statement. 82357f1050SThomas Veermanif test "$depmode" = hp; then 83357f1050SThomas Veerman # HP compiler uses -M and no extra arg. 84357f1050SThomas Veerman gccflag=-M 85357f1050SThomas Veerman depmode=gcc 86357f1050SThomas Veermanfi 87357f1050SThomas Veerman 88357f1050SThomas Veermanif test "$depmode" = dashXmstdout; then 89357f1050SThomas Veerman # This is just like dashmstdout with a different argument. 90357f1050SThomas Veerman dashmflag=-xM 91357f1050SThomas Veerman depmode=dashmstdout 92357f1050SThomas Veermanfi 93357f1050SThomas Veerman 9484d9c625SLionel Sambuccygpath_u="cygpath -u -f -" 9584d9c625SLionel Sambucif test "$depmode" = msvcmsys; then 9684d9c625SLionel Sambuc # This is just like msvisualcpp but w/o cygpath translation. 9784d9c625SLionel Sambuc # Just convert the backslash-escaped backslashes to single forward 9884d9c625SLionel Sambuc # slashes to satisfy depend.m4 99*0a6a1f1dSLionel Sambuc cygpath_u='sed s,\\\\,/,g' 10084d9c625SLionel Sambuc depmode=msvisualcpp 10184d9c625SLionel Sambucfi 10284d9c625SLionel Sambuc 103*0a6a1f1dSLionel Sambucif test "$depmode" = msvc7msys; then 104*0a6a1f1dSLionel Sambuc # This is just like msvc7 but w/o cygpath translation. 105*0a6a1f1dSLionel Sambuc # Just convert the backslash-escaped backslashes to single forward 106*0a6a1f1dSLionel Sambuc # slashes to satisfy depend.m4 107*0a6a1f1dSLionel Sambuc cygpath_u='sed s,\\\\,/,g' 108*0a6a1f1dSLionel Sambuc depmode=msvc7 109*0a6a1f1dSLionel Sambucfi 110*0a6a1f1dSLionel Sambuc 111*0a6a1f1dSLionel Sambucif test "$depmode" = xlc; then 112*0a6a1f1dSLionel Sambuc # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations. 113*0a6a1f1dSLionel Sambuc gccflag=-qmakedep=gcc,-MF 114*0a6a1f1dSLionel Sambuc depmode=gcc 115*0a6a1f1dSLionel Sambucfi 116*0a6a1f1dSLionel Sambuc 117357f1050SThomas Veermancase "$depmode" in 118357f1050SThomas Veermangcc3) 119357f1050SThomas Veerman## gcc 3 implements dependency tracking that does exactly what 120357f1050SThomas Veerman## we want. Yay! Note: for some reason libtool 1.4 doesn't like 121357f1050SThomas Veerman## it if -MD -MP comes after the -MF stuff. Hmm. 12284d9c625SLionel Sambuc## Unfortunately, FreeBSD c89 acceptance of flags depends upon 12384d9c625SLionel Sambuc## the command line argument order; so add the flags where they 12484d9c625SLionel Sambuc## appear in depend2.am. Note that the slowdown incurred here 12584d9c625SLionel Sambuc## affects only configure: in makefiles, %FASTDEP% shortcuts this. 12684d9c625SLionel Sambuc for arg 12784d9c625SLionel Sambuc do 12884d9c625SLionel Sambuc case $arg in 12984d9c625SLionel Sambuc -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 13084d9c625SLionel Sambuc *) set fnord "$@" "$arg" ;; 13184d9c625SLionel Sambuc esac 13284d9c625SLionel Sambuc shift # fnord 13384d9c625SLionel Sambuc shift # $arg 13484d9c625SLionel Sambuc done 13584d9c625SLionel Sambuc "$@" 136357f1050SThomas Veerman stat=$? 137357f1050SThomas Veerman if test $stat -eq 0; then : 138357f1050SThomas Veerman else 139357f1050SThomas Veerman rm -f "$tmpdepfile" 140357f1050SThomas Veerman exit $stat 141357f1050SThomas Veerman fi 142357f1050SThomas Veerman mv "$tmpdepfile" "$depfile" 143357f1050SThomas Veerman ;; 144357f1050SThomas Veerman 145357f1050SThomas Veermangcc) 146357f1050SThomas Veerman## There are various ways to get dependency output from gcc. Here's 147357f1050SThomas Veerman## why we pick this rather obscure method: 148357f1050SThomas Veerman## - Don't want to use -MD because we'd like the dependencies to end 149357f1050SThomas Veerman## up in a subdir. Having to rename by hand is ugly. 150357f1050SThomas Veerman## (We might end up doing this anyway to support other compilers.) 151357f1050SThomas Veerman## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 152357f1050SThomas Veerman## -MM, not -M (despite what the docs say). 153357f1050SThomas Veerman## - Using -M directly means running the compiler twice (even worse 154357f1050SThomas Veerman## than renaming). 155357f1050SThomas Veerman if test -z "$gccflag"; then 156357f1050SThomas Veerman gccflag=-MD, 157357f1050SThomas Veerman fi 158357f1050SThomas Veerman "$@" -Wp,"$gccflag$tmpdepfile" 159357f1050SThomas Veerman stat=$? 160357f1050SThomas Veerman if test $stat -eq 0; then : 161357f1050SThomas Veerman else 162357f1050SThomas Veerman rm -f "$tmpdepfile" 163357f1050SThomas Veerman exit $stat 164357f1050SThomas Veerman fi 165357f1050SThomas Veerman rm -f "$depfile" 166357f1050SThomas Veerman echo "$object : \\" > "$depfile" 167357f1050SThomas Veerman alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 168357f1050SThomas Veerman## The second -e expression handles DOS-style file names with drive letters. 169357f1050SThomas Veerman sed -e 's/^[^:]*: / /' \ 170357f1050SThomas Veerman -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 171*0a6a1f1dSLionel Sambuc## This next piece of magic avoids the "deleted header file" problem. 172357f1050SThomas Veerman## The problem is that when a header file which appears in a .P file 173357f1050SThomas Veerman## is deleted, the dependency causes make to die (because there is 174357f1050SThomas Veerman## typically no way to rebuild the header). We avoid this by adding 175357f1050SThomas Veerman## dummy dependencies for each header file. Too bad gcc doesn't do 176357f1050SThomas Veerman## this for us directly. 177*0a6a1f1dSLionel Sambuc tr ' ' "$nl" < "$tmpdepfile" | 178*0a6a1f1dSLionel Sambuc## Some versions of gcc put a space before the ':'. On the theory 179357f1050SThomas Veerman## that the space means something, we add a space to the output as 180*0a6a1f1dSLionel Sambuc## well. hp depmode also adds that space, but also prefixes the VPATH 181*0a6a1f1dSLionel Sambuc## to the object. Take care to not repeat it in the output. 182357f1050SThomas Veerman## Some versions of the HPUX 10.20 sed can't process this invocation 183357f1050SThomas Veerman## correctly. Breaking it into two sed invocations is a workaround. 184*0a6a1f1dSLionel Sambuc sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 185*0a6a1f1dSLionel Sambuc | sed -e 's/$/ :/' >> "$depfile" 186357f1050SThomas Veerman rm -f "$tmpdepfile" 187357f1050SThomas Veerman ;; 188357f1050SThomas Veerman 189357f1050SThomas Veermanhp) 190357f1050SThomas Veerman # This case exists only to let depend.m4 do its work. It works by 191357f1050SThomas Veerman # looking at the text of this script. This case will never be run, 192357f1050SThomas Veerman # since it is checked for above. 193357f1050SThomas Veerman exit 1 194357f1050SThomas Veerman ;; 195357f1050SThomas Veerman 196357f1050SThomas Veermansgi) 197357f1050SThomas Veerman if test "$libtool" = yes; then 198357f1050SThomas Veerman "$@" "-Wp,-MDupdate,$tmpdepfile" 199357f1050SThomas Veerman else 200357f1050SThomas Veerman "$@" -MDupdate "$tmpdepfile" 201357f1050SThomas Veerman fi 202357f1050SThomas Veerman stat=$? 203357f1050SThomas Veerman if test $stat -eq 0; then : 204357f1050SThomas Veerman else 205357f1050SThomas Veerman rm -f "$tmpdepfile" 206357f1050SThomas Veerman exit $stat 207357f1050SThomas Veerman fi 208357f1050SThomas Veerman rm -f "$depfile" 209357f1050SThomas Veerman 210357f1050SThomas Veerman if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 211357f1050SThomas Veerman echo "$object : \\" > "$depfile" 212357f1050SThomas Veerman 213357f1050SThomas Veerman # Clip off the initial element (the dependent). Don't try to be 214357f1050SThomas Veerman # clever and replace this with sed code, as IRIX sed won't handle 215357f1050SThomas Veerman # lines with more than a fixed number of characters (4096 in 216357f1050SThomas Veerman # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 217*0a6a1f1dSLionel Sambuc # the IRIX cc adds comments like '#:fec' to the end of the 218357f1050SThomas Veerman # dependency line. 219*0a6a1f1dSLionel Sambuc tr ' ' "$nl" < "$tmpdepfile" \ 220357f1050SThomas Veerman | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ 221*0a6a1f1dSLionel Sambuc tr "$nl" ' ' >> "$depfile" 22284d9c625SLionel Sambuc echo >> "$depfile" 223357f1050SThomas Veerman 224357f1050SThomas Veerman # The second pass generates a dummy entry for each header file. 225*0a6a1f1dSLionel Sambuc tr ' ' "$nl" < "$tmpdepfile" \ 226357f1050SThomas Veerman | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 22784d9c625SLionel Sambuc >> "$depfile" 228357f1050SThomas Veerman else 229357f1050SThomas Veerman # The sourcefile does not contain any dependencies, so just 230357f1050SThomas Veerman # store a dummy comment line, to avoid errors with the Makefile 231357f1050SThomas Veerman # "include basename.Plo" scheme. 232357f1050SThomas Veerman echo "#dummy" > "$depfile" 233357f1050SThomas Veerman fi 234357f1050SThomas Veerman rm -f "$tmpdepfile" 235357f1050SThomas Veerman ;; 236357f1050SThomas Veerman 237*0a6a1f1dSLionel Sambucxlc) 238*0a6a1f1dSLionel Sambuc # This case exists only to let depend.m4 do its work. It works by 239*0a6a1f1dSLionel Sambuc # looking at the text of this script. This case will never be run, 240*0a6a1f1dSLionel Sambuc # since it is checked for above. 241*0a6a1f1dSLionel Sambuc exit 1 242*0a6a1f1dSLionel Sambuc ;; 243*0a6a1f1dSLionel Sambuc 244357f1050SThomas Veermanaix) 245357f1050SThomas Veerman # The C for AIX Compiler uses -M and outputs the dependencies 246357f1050SThomas Veerman # in a .u file. In older versions, this file always lives in the 247*0a6a1f1dSLionel Sambuc # current directory. Also, the AIX compiler puts '$object:' at the 248357f1050SThomas Veerman # start of each line; $object doesn't have directory information. 249357f1050SThomas Veerman # Version 6 uses the directory in both cases. 25084d9c625SLionel Sambuc dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 25184d9c625SLionel Sambuc test "x$dir" = "x$object" && dir= 25284d9c625SLionel Sambuc base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 253357f1050SThomas Veerman if test "$libtool" = yes; then 25484d9c625SLionel Sambuc tmpdepfile1=$dir$base.u 25584d9c625SLionel Sambuc tmpdepfile2=$base.u 25684d9c625SLionel Sambuc tmpdepfile3=$dir.libs/$base.u 257357f1050SThomas Veerman "$@" -Wc,-M 258357f1050SThomas Veerman else 25984d9c625SLionel Sambuc tmpdepfile1=$dir$base.u 26084d9c625SLionel Sambuc tmpdepfile2=$dir$base.u 26184d9c625SLionel Sambuc tmpdepfile3=$dir$base.u 262357f1050SThomas Veerman "$@" -M 263357f1050SThomas Veerman fi 264357f1050SThomas Veerman stat=$? 265357f1050SThomas Veerman 266357f1050SThomas Veerman if test $stat -eq 0; then : 267357f1050SThomas Veerman else 26884d9c625SLionel Sambuc rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 269357f1050SThomas Veerman exit $stat 270357f1050SThomas Veerman fi 271357f1050SThomas Veerman 27284d9c625SLionel Sambuc for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 27384d9c625SLionel Sambuc do 27484d9c625SLionel Sambuc test -f "$tmpdepfile" && break 27584d9c625SLionel Sambuc done 276357f1050SThomas Veerman if test -f "$tmpdepfile"; then 277*0a6a1f1dSLionel Sambuc # Each line is of the form 'foo.o: dependent.h'. 278357f1050SThomas Veerman # Do two passes, one to just change these to 279*0a6a1f1dSLionel Sambuc # '$object: dependent.h' and one to simply 'dependent.h:'. 28084d9c625SLionel Sambuc sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 281*0a6a1f1dSLionel Sambuc sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 282357f1050SThomas Veerman else 283357f1050SThomas Veerman # The sourcefile does not contain any dependencies, so just 284357f1050SThomas Veerman # store a dummy comment line, to avoid errors with the Makefile 285357f1050SThomas Veerman # "include basename.Plo" scheme. 286357f1050SThomas Veerman echo "#dummy" > "$depfile" 287357f1050SThomas Veerman fi 288357f1050SThomas Veerman rm -f "$tmpdepfile" 289357f1050SThomas Veerman ;; 290357f1050SThomas Veerman 291357f1050SThomas Veermanicc) 292*0a6a1f1dSLionel Sambuc # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'. 293*0a6a1f1dSLionel Sambuc # However on 294*0a6a1f1dSLionel Sambuc # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c 295357f1050SThomas Veerman # ICC 7.0 will fill foo.d with something like 296357f1050SThomas Veerman # foo.o: sub/foo.c 297357f1050SThomas Veerman # foo.o: sub/foo.h 298*0a6a1f1dSLionel Sambuc # which is wrong. We want 299357f1050SThomas Veerman # sub/foo.o: sub/foo.c 300357f1050SThomas Veerman # sub/foo.o: sub/foo.h 301357f1050SThomas Veerman # sub/foo.c: 302357f1050SThomas Veerman # sub/foo.h: 303357f1050SThomas Veerman # ICC 7.1 will output 304357f1050SThomas Veerman # foo.o: sub/foo.c sub/foo.h 305*0a6a1f1dSLionel Sambuc # and will wrap long lines using '\': 306357f1050SThomas Veerman # foo.o: sub/foo.c ... \ 307357f1050SThomas Veerman # sub/foo.h ... \ 308357f1050SThomas Veerman # ... 309*0a6a1f1dSLionel Sambuc # tcc 0.9.26 (FIXME still under development at the moment of writing) 310*0a6a1f1dSLionel Sambuc # will emit a similar output, but also prepend the continuation lines 311*0a6a1f1dSLionel Sambuc # with horizontal tabulation characters. 312357f1050SThomas Veerman "$@" -MD -MF "$tmpdepfile" 313357f1050SThomas Veerman stat=$? 314357f1050SThomas Veerman if test $stat -eq 0; then : 315357f1050SThomas Veerman else 316357f1050SThomas Veerman rm -f "$tmpdepfile" 317357f1050SThomas Veerman exit $stat 318357f1050SThomas Veerman fi 319357f1050SThomas Veerman rm -f "$depfile" 320*0a6a1f1dSLionel Sambuc # Each line is of the form 'foo.o: dependent.h', 321*0a6a1f1dSLionel Sambuc # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'. 322357f1050SThomas Veerman # Do two passes, one to just change these to 323*0a6a1f1dSLionel Sambuc # '$object: dependent.h' and one to simply 'dependent.h:'. 324*0a6a1f1dSLionel Sambuc sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \ 325*0a6a1f1dSLionel Sambuc < "$tmpdepfile" > "$depfile" 326*0a6a1f1dSLionel Sambuc sed ' 327*0a6a1f1dSLionel Sambuc s/[ '"$tab"'][ '"$tab"']*/ /g 328*0a6a1f1dSLionel Sambuc s/^ *// 329*0a6a1f1dSLionel Sambuc s/ *\\*$// 330*0a6a1f1dSLionel Sambuc s/^[^:]*: *// 331*0a6a1f1dSLionel Sambuc /^$/d 332*0a6a1f1dSLionel Sambuc /:$/d 333*0a6a1f1dSLionel Sambuc s/$/ :/ 334*0a6a1f1dSLionel Sambuc ' < "$tmpdepfile" >> "$depfile" 335357f1050SThomas Veerman rm -f "$tmpdepfile" 336357f1050SThomas Veerman ;; 337357f1050SThomas Veerman 33884d9c625SLionel Sambuchp2) 33984d9c625SLionel Sambuc # The "hp" stanza above does not work with aCC (C++) and HP's ia64 34084d9c625SLionel Sambuc # compilers, which have integrated preprocessors. The correct option 34184d9c625SLionel Sambuc # to use with these is +Maked; it writes dependencies to a file named 34284d9c625SLionel Sambuc # 'foo.d', which lands next to the object file, wherever that 34384d9c625SLionel Sambuc # happens to be. 34484d9c625SLionel Sambuc # Much of this is similar to the tru64 case; see comments there. 34584d9c625SLionel Sambuc dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 34684d9c625SLionel Sambuc test "x$dir" = "x$object" && dir= 34784d9c625SLionel Sambuc base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 34884d9c625SLionel Sambuc if test "$libtool" = yes; then 34984d9c625SLionel Sambuc tmpdepfile1=$dir$base.d 35084d9c625SLionel Sambuc tmpdepfile2=$dir.libs/$base.d 35184d9c625SLionel Sambuc "$@" -Wc,+Maked 35284d9c625SLionel Sambuc else 35384d9c625SLionel Sambuc tmpdepfile1=$dir$base.d 35484d9c625SLionel Sambuc tmpdepfile2=$dir$base.d 35584d9c625SLionel Sambuc "$@" +Maked 35684d9c625SLionel Sambuc fi 35784d9c625SLionel Sambuc stat=$? 35884d9c625SLionel Sambuc if test $stat -eq 0; then : 35984d9c625SLionel Sambuc else 36084d9c625SLionel Sambuc rm -f "$tmpdepfile1" "$tmpdepfile2" 36184d9c625SLionel Sambuc exit $stat 36284d9c625SLionel Sambuc fi 36384d9c625SLionel Sambuc 36484d9c625SLionel Sambuc for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 36584d9c625SLionel Sambuc do 36684d9c625SLionel Sambuc test -f "$tmpdepfile" && break 36784d9c625SLionel Sambuc done 36884d9c625SLionel Sambuc if test -f "$tmpdepfile"; then 36984d9c625SLionel Sambuc sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile" 370*0a6a1f1dSLionel Sambuc # Add 'dependent.h:' lines. 37184d9c625SLionel Sambuc sed -ne '2,${ 37284d9c625SLionel Sambuc s/^ *// 37384d9c625SLionel Sambuc s/ \\*$// 37484d9c625SLionel Sambuc s/$/:/ 37584d9c625SLionel Sambuc p 37684d9c625SLionel Sambuc }' "$tmpdepfile" >> "$depfile" 37784d9c625SLionel Sambuc else 37884d9c625SLionel Sambuc echo "#dummy" > "$depfile" 37984d9c625SLionel Sambuc fi 38084d9c625SLionel Sambuc rm -f "$tmpdepfile" "$tmpdepfile2" 38184d9c625SLionel Sambuc ;; 38284d9c625SLionel Sambuc 383357f1050SThomas Veermantru64) 384357f1050SThomas Veerman # The Tru64 compiler uses -MD to generate dependencies as a side 385*0a6a1f1dSLionel Sambuc # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 386357f1050SThomas Veerman # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 387*0a6a1f1dSLionel Sambuc # dependencies in 'foo.d' instead, so we check for that too. 388357f1050SThomas Veerman # Subdirectories are respected. 389357f1050SThomas Veerman dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 390357f1050SThomas Veerman test "x$dir" = "x$object" && dir= 391357f1050SThomas Veerman base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 392357f1050SThomas Veerman 393357f1050SThomas Veerman if test "$libtool" = yes; then 394357f1050SThomas Veerman # With Tru64 cc, shared objects can also be used to make a 39584d9c625SLionel Sambuc # static library. This mechanism is used in libtool 1.4 series to 396357f1050SThomas Veerman # handle both shared and static libraries in a single compilation. 397357f1050SThomas Veerman # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. 398357f1050SThomas Veerman # 399357f1050SThomas Veerman # With libtool 1.5 this exception was removed, and libtool now 400357f1050SThomas Veerman # generates 2 separate objects for the 2 libraries. These two 40184d9c625SLionel Sambuc # compilations output dependencies in $dir.libs/$base.o.d and 402357f1050SThomas Veerman # in $dir$base.o.d. We have to check for both files, because 403357f1050SThomas Veerman # one of the two compilations can be disabled. We should prefer 404357f1050SThomas Veerman # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 405357f1050SThomas Veerman # automatically cleaned when .libs/ is deleted, while ignoring 406357f1050SThomas Veerman # the former would cause a distcleancheck panic. 407357f1050SThomas Veerman tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 408357f1050SThomas Veerman tmpdepfile2=$dir$base.o.d # libtool 1.5 409357f1050SThomas Veerman tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 410357f1050SThomas Veerman tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 411357f1050SThomas Veerman "$@" -Wc,-MD 412357f1050SThomas Veerman else 413357f1050SThomas Veerman tmpdepfile1=$dir$base.o.d 414357f1050SThomas Veerman tmpdepfile2=$dir$base.d 415357f1050SThomas Veerman tmpdepfile3=$dir$base.d 416357f1050SThomas Veerman tmpdepfile4=$dir$base.d 417357f1050SThomas Veerman "$@" -MD 418357f1050SThomas Veerman fi 419357f1050SThomas Veerman 420357f1050SThomas Veerman stat=$? 421357f1050SThomas Veerman if test $stat -eq 0; then : 422357f1050SThomas Veerman else 423357f1050SThomas Veerman rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 424357f1050SThomas Veerman exit $stat 425357f1050SThomas Veerman fi 426357f1050SThomas Veerman 427357f1050SThomas Veerman for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 428357f1050SThomas Veerman do 429357f1050SThomas Veerman test -f "$tmpdepfile" && break 430357f1050SThomas Veerman done 431357f1050SThomas Veerman if test -f "$tmpdepfile"; then 432357f1050SThomas Veerman sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 433*0a6a1f1dSLionel Sambuc sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 434357f1050SThomas Veerman else 435357f1050SThomas Veerman echo "#dummy" > "$depfile" 436357f1050SThomas Veerman fi 437357f1050SThomas Veerman rm -f "$tmpdepfile" 438357f1050SThomas Veerman ;; 439357f1050SThomas Veerman 440*0a6a1f1dSLionel Sambucmsvc7) 441*0a6a1f1dSLionel Sambuc if test "$libtool" = yes; then 442*0a6a1f1dSLionel Sambuc showIncludes=-Wc,-showIncludes 443*0a6a1f1dSLionel Sambuc else 444*0a6a1f1dSLionel Sambuc showIncludes=-showIncludes 445*0a6a1f1dSLionel Sambuc fi 446*0a6a1f1dSLionel Sambuc "$@" $showIncludes > "$tmpdepfile" 447*0a6a1f1dSLionel Sambuc stat=$? 448*0a6a1f1dSLionel Sambuc grep -v '^Note: including file: ' "$tmpdepfile" 449*0a6a1f1dSLionel Sambuc if test "$stat" = 0; then : 450*0a6a1f1dSLionel Sambuc else 451*0a6a1f1dSLionel Sambuc rm -f "$tmpdepfile" 452*0a6a1f1dSLionel Sambuc exit $stat 453*0a6a1f1dSLionel Sambuc fi 454*0a6a1f1dSLionel Sambuc rm -f "$depfile" 455*0a6a1f1dSLionel Sambuc echo "$object : \\" > "$depfile" 456*0a6a1f1dSLionel Sambuc # The first sed program below extracts the file names and escapes 457*0a6a1f1dSLionel Sambuc # backslashes for cygpath. The second sed program outputs the file 458*0a6a1f1dSLionel Sambuc # name when reading, but also accumulates all include files in the 459*0a6a1f1dSLionel Sambuc # hold buffer in order to output them again at the end. This only 460*0a6a1f1dSLionel Sambuc # works with sed implementations that can handle large buffers. 461*0a6a1f1dSLionel Sambuc sed < "$tmpdepfile" -n ' 462*0a6a1f1dSLionel Sambuc/^Note: including file: *\(.*\)/ { 463*0a6a1f1dSLionel Sambuc s//\1/ 464*0a6a1f1dSLionel Sambuc s/\\/\\\\/g 465*0a6a1f1dSLionel Sambuc p 466*0a6a1f1dSLionel Sambuc}' | $cygpath_u | sort -u | sed -n ' 467*0a6a1f1dSLionel Sambucs/ /\\ /g 468*0a6a1f1dSLionel Sambucs/\(.*\)/'"$tab"'\1 \\/p 469*0a6a1f1dSLionel Sambucs/.\(.*\) \\/\1:/ 470*0a6a1f1dSLionel SambucH 471*0a6a1f1dSLionel Sambuc$ { 472*0a6a1f1dSLionel Sambuc s/.*/'"$tab"'/ 473*0a6a1f1dSLionel Sambuc G 474*0a6a1f1dSLionel Sambuc p 475*0a6a1f1dSLionel Sambuc}' >> "$depfile" 476*0a6a1f1dSLionel Sambuc rm -f "$tmpdepfile" 477*0a6a1f1dSLionel Sambuc ;; 478*0a6a1f1dSLionel Sambuc 479*0a6a1f1dSLionel Sambucmsvc7msys) 480*0a6a1f1dSLionel Sambuc # This case exists only to let depend.m4 do its work. It works by 481*0a6a1f1dSLionel Sambuc # looking at the text of this script. This case will never be run, 482*0a6a1f1dSLionel Sambuc # since it is checked for above. 483*0a6a1f1dSLionel Sambuc exit 1 484*0a6a1f1dSLionel Sambuc ;; 485*0a6a1f1dSLionel Sambuc 486357f1050SThomas Veerman#nosideeffect) 487357f1050SThomas Veerman # This comment above is used by automake to tell side-effect 488357f1050SThomas Veerman # dependency tracking mechanisms from slower ones. 489357f1050SThomas Veerman 490357f1050SThomas Veermandashmstdout) 491357f1050SThomas Veerman # Important note: in order to support this mode, a compiler *must* 492357f1050SThomas Veerman # always write the preprocessed file to stdout, regardless of -o. 493357f1050SThomas Veerman "$@" || exit $? 494357f1050SThomas Veerman 495357f1050SThomas Veerman # Remove the call to Libtool. 496357f1050SThomas Veerman if test "$libtool" = yes; then 49784d9c625SLionel Sambuc while test "X$1" != 'X--mode=compile'; do 498357f1050SThomas Veerman shift 499357f1050SThomas Veerman done 500357f1050SThomas Veerman shift 501357f1050SThomas Veerman fi 502357f1050SThomas Veerman 503*0a6a1f1dSLionel Sambuc # Remove '-o $object'. 504357f1050SThomas Veerman IFS=" " 505357f1050SThomas Veerman for arg 506357f1050SThomas Veerman do 507357f1050SThomas Veerman case $arg in 508357f1050SThomas Veerman -o) 509357f1050SThomas Veerman shift 510357f1050SThomas Veerman ;; 511357f1050SThomas Veerman $object) 512357f1050SThomas Veerman shift 513357f1050SThomas Veerman ;; 514357f1050SThomas Veerman *) 515357f1050SThomas Veerman set fnord "$@" "$arg" 516357f1050SThomas Veerman shift # fnord 517357f1050SThomas Veerman shift # $arg 518357f1050SThomas Veerman ;; 519357f1050SThomas Veerman esac 520357f1050SThomas Veerman done 521357f1050SThomas Veerman 522357f1050SThomas Veerman test -z "$dashmflag" && dashmflag=-M 523*0a6a1f1dSLionel Sambuc # Require at least two characters before searching for ':' 524357f1050SThomas Veerman # in the target name. This is to cope with DOS-style filenames: 525*0a6a1f1dSLionel Sambuc # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 526357f1050SThomas Veerman "$@" $dashmflag | 527*0a6a1f1dSLionel Sambuc sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile" 528357f1050SThomas Veerman rm -f "$depfile" 529357f1050SThomas Veerman cat < "$tmpdepfile" > "$depfile" 530*0a6a1f1dSLionel Sambuc tr ' ' "$nl" < "$tmpdepfile" | \ 531357f1050SThomas Veerman## Some versions of the HPUX 10.20 sed can't process this invocation 532357f1050SThomas Veerman## correctly. Breaking it into two sed invocations is a workaround. 533357f1050SThomas Veerman sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 534357f1050SThomas Veerman rm -f "$tmpdepfile" 535357f1050SThomas Veerman ;; 536357f1050SThomas Veerman 537357f1050SThomas VeermandashXmstdout) 538357f1050SThomas Veerman # This case only exists to satisfy depend.m4. It is never actually 539357f1050SThomas Veerman # run, as this mode is specially recognized in the preamble. 540357f1050SThomas Veerman exit 1 541357f1050SThomas Veerman ;; 542357f1050SThomas Veerman 543357f1050SThomas Veermanmakedepend) 544357f1050SThomas Veerman "$@" || exit $? 545357f1050SThomas Veerman # Remove any Libtool call 546357f1050SThomas Veerman if test "$libtool" = yes; then 54784d9c625SLionel Sambuc while test "X$1" != 'X--mode=compile'; do 548357f1050SThomas Veerman shift 549357f1050SThomas Veerman done 550357f1050SThomas Veerman shift 551357f1050SThomas Veerman fi 552357f1050SThomas Veerman # X makedepend 553357f1050SThomas Veerman shift 55484d9c625SLionel Sambuc cleared=no eat=no 55584d9c625SLionel Sambuc for arg 55684d9c625SLionel Sambuc do 557357f1050SThomas Veerman case $cleared in 558357f1050SThomas Veerman no) 559357f1050SThomas Veerman set ""; shift 560357f1050SThomas Veerman cleared=yes ;; 561357f1050SThomas Veerman esac 56284d9c625SLionel Sambuc if test $eat = yes; then 56384d9c625SLionel Sambuc eat=no 56484d9c625SLionel Sambuc continue 56584d9c625SLionel Sambuc fi 566357f1050SThomas Veerman case "$arg" in 567357f1050SThomas Veerman -D*|-I*) 568357f1050SThomas Veerman set fnord "$@" "$arg"; shift ;; 569357f1050SThomas Veerman # Strip any option that makedepend may not understand. Remove 570357f1050SThomas Veerman # the object too, otherwise makedepend will parse it as a source file. 57184d9c625SLionel Sambuc -arch) 57284d9c625SLionel Sambuc eat=yes ;; 573357f1050SThomas Veerman -*|$object) 574357f1050SThomas Veerman ;; 575357f1050SThomas Veerman *) 576357f1050SThomas Veerman set fnord "$@" "$arg"; shift ;; 577357f1050SThomas Veerman esac 578357f1050SThomas Veerman done 57984d9c625SLionel Sambuc obj_suffix=`echo "$object" | sed 's/^.*\././'` 580357f1050SThomas Veerman touch "$tmpdepfile" 581357f1050SThomas Veerman ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 582357f1050SThomas Veerman rm -f "$depfile" 583*0a6a1f1dSLionel Sambuc # makedepend may prepend the VPATH from the source file name to the object. 584*0a6a1f1dSLionel Sambuc # No need to regex-escape $object, excess matching of '.' is harmless. 585*0a6a1f1dSLionel Sambuc sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 586*0a6a1f1dSLionel Sambuc sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \ 587357f1050SThomas Veerman## Some versions of the HPUX 10.20 sed can't process this invocation 588357f1050SThomas Veerman## correctly. Breaking it into two sed invocations is a workaround. 589357f1050SThomas Veerman sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 590357f1050SThomas Veerman rm -f "$tmpdepfile" "$tmpdepfile".bak 591357f1050SThomas Veerman ;; 592357f1050SThomas Veerman 593357f1050SThomas Veermancpp) 594357f1050SThomas Veerman # Important note: in order to support this mode, a compiler *must* 595357f1050SThomas Veerman # always write the preprocessed file to stdout. 596357f1050SThomas Veerman "$@" || exit $? 597357f1050SThomas Veerman 598357f1050SThomas Veerman # Remove the call to Libtool. 599357f1050SThomas Veerman if test "$libtool" = yes; then 60084d9c625SLionel Sambuc while test "X$1" != 'X--mode=compile'; do 601357f1050SThomas Veerman shift 602357f1050SThomas Veerman done 603357f1050SThomas Veerman shift 604357f1050SThomas Veerman fi 605357f1050SThomas Veerman 606*0a6a1f1dSLionel Sambuc # Remove '-o $object'. 607357f1050SThomas Veerman IFS=" " 608357f1050SThomas Veerman for arg 609357f1050SThomas Veerman do 610357f1050SThomas Veerman case $arg in 611357f1050SThomas Veerman -o) 612357f1050SThomas Veerman shift 613357f1050SThomas Veerman ;; 614357f1050SThomas Veerman $object) 615357f1050SThomas Veerman shift 616357f1050SThomas Veerman ;; 617357f1050SThomas Veerman *) 618357f1050SThomas Veerman set fnord "$@" "$arg" 619357f1050SThomas Veerman shift # fnord 620357f1050SThomas Veerman shift # $arg 621357f1050SThomas Veerman ;; 622357f1050SThomas Veerman esac 623357f1050SThomas Veerman done 624357f1050SThomas Veerman 625357f1050SThomas Veerman "$@" -E | 626357f1050SThomas Veerman sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 627357f1050SThomas Veerman -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | 628357f1050SThomas Veerman sed '$ s: \\$::' > "$tmpdepfile" 629357f1050SThomas Veerman rm -f "$depfile" 630357f1050SThomas Veerman echo "$object : \\" > "$depfile" 631357f1050SThomas Veerman cat < "$tmpdepfile" >> "$depfile" 632357f1050SThomas Veerman sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 633357f1050SThomas Veerman rm -f "$tmpdepfile" 634357f1050SThomas Veerman ;; 635357f1050SThomas Veerman 636357f1050SThomas Veermanmsvisualcpp) 637357f1050SThomas Veerman # Important note: in order to support this mode, a compiler *must* 63884d9c625SLionel Sambuc # always write the preprocessed file to stdout. 639357f1050SThomas Veerman "$@" || exit $? 64084d9c625SLionel Sambuc 64184d9c625SLionel Sambuc # Remove the call to Libtool. 64284d9c625SLionel Sambuc if test "$libtool" = yes; then 64384d9c625SLionel Sambuc while test "X$1" != 'X--mode=compile'; do 64484d9c625SLionel Sambuc shift 64584d9c625SLionel Sambuc done 64684d9c625SLionel Sambuc shift 64784d9c625SLionel Sambuc fi 64884d9c625SLionel Sambuc 649357f1050SThomas Veerman IFS=" " 650357f1050SThomas Veerman for arg 651357f1050SThomas Veerman do 652357f1050SThomas Veerman case "$arg" in 65384d9c625SLionel Sambuc -o) 65484d9c625SLionel Sambuc shift 65584d9c625SLionel Sambuc ;; 65684d9c625SLionel Sambuc $object) 65784d9c625SLionel Sambuc shift 65884d9c625SLionel Sambuc ;; 659357f1050SThomas Veerman "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 660357f1050SThomas Veerman set fnord "$@" 661357f1050SThomas Veerman shift 662357f1050SThomas Veerman shift 663357f1050SThomas Veerman ;; 664357f1050SThomas Veerman *) 665357f1050SThomas Veerman set fnord "$@" "$arg" 666357f1050SThomas Veerman shift 667357f1050SThomas Veerman shift 668357f1050SThomas Veerman ;; 669357f1050SThomas Veerman esac 670357f1050SThomas Veerman done 67184d9c625SLionel Sambuc "$@" -E 2>/dev/null | 67284d9c625SLionel Sambuc sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 673357f1050SThomas Veerman rm -f "$depfile" 674357f1050SThomas Veerman echo "$object : \\" > "$depfile" 675*0a6a1f1dSLionel Sambuc sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 676*0a6a1f1dSLionel Sambuc echo "$tab" >> "$depfile" 67784d9c625SLionel Sambuc sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 678357f1050SThomas Veerman rm -f "$tmpdepfile" 679357f1050SThomas Veerman ;; 680357f1050SThomas Veerman 68184d9c625SLionel Sambucmsvcmsys) 68284d9c625SLionel Sambuc # This case exists only to let depend.m4 do its work. It works by 68384d9c625SLionel Sambuc # looking at the text of this script. This case will never be run, 68484d9c625SLionel Sambuc # since it is checked for above. 68584d9c625SLionel Sambuc exit 1 68684d9c625SLionel Sambuc ;; 68784d9c625SLionel Sambuc 688357f1050SThomas Veermannone) 689357f1050SThomas Veerman exec "$@" 690357f1050SThomas Veerman ;; 691357f1050SThomas Veerman 692357f1050SThomas Veerman*) 693357f1050SThomas Veerman echo "Unknown depmode $depmode" 1>&2 694357f1050SThomas Veerman exit 1 695357f1050SThomas Veerman ;; 696357f1050SThomas Veermanesac 697357f1050SThomas Veerman 698357f1050SThomas Veermanexit 0 699357f1050SThomas Veerman 700357f1050SThomas Veerman# Local Variables: 701357f1050SThomas Veerman# mode: shell-script 702357f1050SThomas Veerman# sh-indentation: 2 703357f1050SThomas Veerman# eval: (add-hook 'write-file-hooks 'time-stamp) 704357f1050SThomas Veerman# time-stamp-start: "scriptversion=" 705357f1050SThomas Veerman# time-stamp-format: "%:y-%02m-%02d.%02H" 70684d9c625SLionel Sambuc# time-stamp-time-zone: "UTC" 70784d9c625SLionel Sambuc# time-stamp-end: "; # UTC" 708357f1050SThomas Veerman# End: 709