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