depcomp revision 54b44505
14a041c5bSmacallan#! /bin/sh 24a041c5bSmacallan# depcomp - compile a program generating dependencies as side-effects 34a041c5bSmacallan 454b44505Smrgscriptversion=2012-07-12.20; # UTC 54a041c5bSmacallan 654b44505Smrg# Copyright (C) 1999-2012 Free Software Foundation, Inc. 74a041c5bSmacallan 84a041c5bSmacallan# This program is free software; you can redistribute it and/or modify 94a041c5bSmacallan# it under the terms of the GNU General Public License as published by 104a041c5bSmacallan# the Free Software Foundation; either version 2, or (at your option) 114a041c5bSmacallan# any later version. 124a041c5bSmacallan 134a041c5bSmacallan# This program is distributed in the hope that it will be useful, 144a041c5bSmacallan# but WITHOUT ANY WARRANTY; without even the implied warranty of 154a041c5bSmacallan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 164a041c5bSmacallan# GNU General Public License for more details. 174a041c5bSmacallan 184a041c5bSmacallan# You should have received a copy of the GNU General Public License 1954b44505Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 204a041c5bSmacallan 214a041c5bSmacallan# As a special exception to the GNU General Public License, if you 224a041c5bSmacallan# distribute this file as part of a program that contains a 234a041c5bSmacallan# configuration script generated by Autoconf, you may include it under 244a041c5bSmacallan# the same distribution terms that you use for the rest of that program. 254a041c5bSmacallan 264a041c5bSmacallan# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 274a041c5bSmacallan 284a041c5bSmacallancase $1 in 294a041c5bSmacallan '') 3054b44505Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 314a041c5bSmacallan exit 1; 324a041c5bSmacallan ;; 334a041c5bSmacallan -h | --h*) 344a041c5bSmacallan cat <<\EOF 354a041c5bSmacallanUsage: depcomp [--help] [--version] PROGRAM [ARGS] 364a041c5bSmacallan 374a041c5bSmacallanRun PROGRAMS ARGS to compile a file, generating dependencies 384a041c5bSmacallanas side-effects. 394a041c5bSmacallan 404a041c5bSmacallanEnvironment variables: 414a041c5bSmacallan depmode Dependency tracking mode. 4254b44505Smrg source Source file read by 'PROGRAMS ARGS'. 4354b44505Smrg object Object file output by 'PROGRAMS ARGS'. 444a041c5bSmacallan DEPDIR directory where to store dependencies. 454a041c5bSmacallan depfile Dependency file to output. 4654b44505Smrg tmpdepfile Temporary file to use when outputting dependencies. 474a041c5bSmacallan libtool Whether libtool is used (yes/no). 484a041c5bSmacallan 494a041c5bSmacallanReport bugs to <bug-automake@gnu.org>. 504a041c5bSmacallanEOF 514a041c5bSmacallan exit $? 524a041c5bSmacallan ;; 534a041c5bSmacallan -v | --v*) 544a041c5bSmacallan echo "depcomp $scriptversion" 554a041c5bSmacallan exit $? 564a041c5bSmacallan ;; 574a041c5bSmacallanesac 584a041c5bSmacallan 5954b44505Smrg# A tabulation character. 6054b44505Smrgtab=' ' 6154b44505Smrg# A newline character. 6254b44505Smrgnl=' 6354b44505Smrg' 6454b44505Smrg 654a041c5bSmacallanif test -z "$depmode" || test -z "$source" || test -z "$object"; then 664a041c5bSmacallan echo "depcomp: Variables source, object and depmode must be set" 1>&2 674a041c5bSmacallan exit 1 684a041c5bSmacallanfi 694a041c5bSmacallan 704a041c5bSmacallan# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 714a041c5bSmacallandepfile=${depfile-`echo "$object" | 724a041c5bSmacallan sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 734a041c5bSmacallantmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 744a041c5bSmacallan 754a041c5bSmacallanrm -f "$tmpdepfile" 764a041c5bSmacallan 7754b44505Smrg# Avoid interferences from the environment. 7854b44505Smrggccflag= dashmflag= 7954b44505Smrg 804a041c5bSmacallan# Some modes work just like other modes, but use different flags. We 814a041c5bSmacallan# parameterize here, but still list the modes in the big case below, 824a041c5bSmacallan# to make depend.m4 easier to write. Note that we *cannot* use a case 834a041c5bSmacallan# here, because this file can only contain one case statement. 844a041c5bSmacallanif test "$depmode" = hp; then 854a041c5bSmacallan # HP compiler uses -M and no extra arg. 864a041c5bSmacallan gccflag=-M 874a041c5bSmacallan depmode=gcc 884a041c5bSmacallanfi 894a041c5bSmacallan 904a041c5bSmacallanif test "$depmode" = dashXmstdout; then 914a041c5bSmacallan # This is just like dashmstdout with a different argument. 924a041c5bSmacallan dashmflag=-xM 934a041c5bSmacallan depmode=dashmstdout 944a041c5bSmacallanfi 954a041c5bSmacallan 9654b44505Smrgcygpath_u="cygpath -u -f -" 9754b44505Smrgif test "$depmode" = msvcmsys; then 9854b44505Smrg # This is just like msvisualcpp but w/o cygpath translation. 9954b44505Smrg # Just convert the backslash-escaped backslashes to single forward 10054b44505Smrg # slashes to satisfy depend.m4 10154b44505Smrg cygpath_u='sed s,\\\\,/,g' 10254b44505Smrg depmode=msvisualcpp 10354b44505Smrgfi 10454b44505Smrg 10554b44505Smrgif test "$depmode" = msvc7msys; then 10654b44505Smrg # This is just like msvc7 but w/o cygpath translation. 10754b44505Smrg # Just convert the backslash-escaped backslashes to single forward 10854b44505Smrg # slashes to satisfy depend.m4 10954b44505Smrg cygpath_u='sed s,\\\\,/,g' 11054b44505Smrg depmode=msvc7 11154b44505Smrgfi 11254b44505Smrg 11354b44505Smrgif test "$depmode" = xlc; then 11454b44505Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 11554b44505Smrg gccflag=-qmakedep=gcc,-MF 11654b44505Smrg depmode=gcc 11754b44505Smrgfi 11854b44505Smrg 1194a041c5bSmacallancase "$depmode" in 1204a041c5bSmacallangcc3) 1214a041c5bSmacallan## gcc 3 implements dependency tracking that does exactly what 1224a041c5bSmacallan## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1234a041c5bSmacallan## it if -MD -MP comes after the -MF stuff. Hmm. 1244a041c5bSmacallan## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1254a041c5bSmacallan## the command line argument order; so add the flags where they 1264a041c5bSmacallan## appear in depend2.am. Note that the slowdown incurred here 1274a041c5bSmacallan## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1284a041c5bSmacallan for arg 1294a041c5bSmacallan do 1304a041c5bSmacallan case $arg in 1314a041c5bSmacallan -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1324a041c5bSmacallan *) set fnord "$@" "$arg" ;; 1334a041c5bSmacallan esac 1344a041c5bSmacallan shift # fnord 1354a041c5bSmacallan shift # $arg 1364a041c5bSmacallan done 1374a041c5bSmacallan "$@" 1384a041c5bSmacallan stat=$? 1394a041c5bSmacallan if test $stat -eq 0; then : 1404a041c5bSmacallan else 1414a041c5bSmacallan rm -f "$tmpdepfile" 1424a041c5bSmacallan exit $stat 1434a041c5bSmacallan fi 1444a041c5bSmacallan mv "$tmpdepfile" "$depfile" 1454a041c5bSmacallan ;; 1464a041c5bSmacallan 1474a041c5bSmacallangcc) 14854b44505Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 14954b44505Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 15054b44505Smrg## (see the conditional assignment to $gccflag above). 1514a041c5bSmacallan## There are various ways to get dependency output from gcc. Here's 1524a041c5bSmacallan## why we pick this rather obscure method: 1534a041c5bSmacallan## - Don't want to use -MD because we'd like the dependencies to end 1544a041c5bSmacallan## up in a subdir. Having to rename by hand is ugly. 1554a041c5bSmacallan## (We might end up doing this anyway to support other compilers.) 1564a041c5bSmacallan## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 15754b44505Smrg## -MM, not -M (despite what the docs say). Also, it might not be 15854b44505Smrg## supported by the other compilers which use the 'gcc' depmode. 1594a041c5bSmacallan## - Using -M directly means running the compiler twice (even worse 1604a041c5bSmacallan## than renaming). 1614a041c5bSmacallan if test -z "$gccflag"; then 1624a041c5bSmacallan gccflag=-MD, 1634a041c5bSmacallan fi 1644a041c5bSmacallan "$@" -Wp,"$gccflag$tmpdepfile" 1654a041c5bSmacallan stat=$? 1664a041c5bSmacallan if test $stat -eq 0; then : 1674a041c5bSmacallan else 1684a041c5bSmacallan rm -f "$tmpdepfile" 1694a041c5bSmacallan exit $stat 1704a041c5bSmacallan fi 1714a041c5bSmacallan rm -f "$depfile" 1724a041c5bSmacallan echo "$object : \\" > "$depfile" 1734a041c5bSmacallan alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 1744a041c5bSmacallan## The second -e expression handles DOS-style file names with drive letters. 1754a041c5bSmacallan sed -e 's/^[^:]*: / /' \ 1764a041c5bSmacallan -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 17754b44505Smrg## This next piece of magic avoids the "deleted header file" problem. 1784a041c5bSmacallan## The problem is that when a header file which appears in a .P file 1794a041c5bSmacallan## is deleted, the dependency causes make to die (because there is 1804a041c5bSmacallan## typically no way to rebuild the header). We avoid this by adding 1814a041c5bSmacallan## dummy dependencies for each header file. Too bad gcc doesn't do 1824a041c5bSmacallan## this for us directly. 18354b44505Smrg tr ' ' "$nl" < "$tmpdepfile" | 18454b44505Smrg## Some versions of gcc put a space before the ':'. On the theory 1854a041c5bSmacallan## that the space means something, we add a space to the output as 18654b44505Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 18754b44505Smrg## to the object. Take care to not repeat it in the output. 1884a041c5bSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 1894a041c5bSmacallan## correctly. Breaking it into two sed invocations is a workaround. 19054b44505Smrg sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 19154b44505Smrg | sed -e 's/$/ :/' >> "$depfile" 1924a041c5bSmacallan rm -f "$tmpdepfile" 1934a041c5bSmacallan ;; 1944a041c5bSmacallan 1954a041c5bSmacallanhp) 1964a041c5bSmacallan # This case exists only to let depend.m4 do its work. It works by 1974a041c5bSmacallan # looking at the text of this script. This case will never be run, 1984a041c5bSmacallan # since it is checked for above. 1994a041c5bSmacallan exit 1 2004a041c5bSmacallan ;; 2014a041c5bSmacallan 2024a041c5bSmacallansgi) 2034a041c5bSmacallan if test "$libtool" = yes; then 2044a041c5bSmacallan "$@" "-Wp,-MDupdate,$tmpdepfile" 2054a041c5bSmacallan else 2064a041c5bSmacallan "$@" -MDupdate "$tmpdepfile" 2074a041c5bSmacallan fi 2084a041c5bSmacallan stat=$? 2094a041c5bSmacallan if test $stat -eq 0; then : 2104a041c5bSmacallan else 2114a041c5bSmacallan rm -f "$tmpdepfile" 2124a041c5bSmacallan exit $stat 2134a041c5bSmacallan fi 2144a041c5bSmacallan rm -f "$depfile" 2154a041c5bSmacallan 2164a041c5bSmacallan if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2174a041c5bSmacallan echo "$object : \\" > "$depfile" 2184a041c5bSmacallan 2194a041c5bSmacallan # Clip off the initial element (the dependent). Don't try to be 2204a041c5bSmacallan # clever and replace this with sed code, as IRIX sed won't handle 2214a041c5bSmacallan # lines with more than a fixed number of characters (4096 in 2224a041c5bSmacallan # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 22354b44505Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2244a041c5bSmacallan # dependency line. 22554b44505Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2264a041c5bSmacallan | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ 22754b44505Smrg tr "$nl" ' ' >> "$depfile" 22854b44505Smrg echo >> "$depfile" 2294a041c5bSmacallan 2304a041c5bSmacallan # The second pass generates a dummy entry for each header file. 23154b44505Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2324a041c5bSmacallan | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 23354b44505Smrg >> "$depfile" 2344a041c5bSmacallan else 2354a041c5bSmacallan # The sourcefile does not contain any dependencies, so just 2364a041c5bSmacallan # store a dummy comment line, to avoid errors with the Makefile 2374a041c5bSmacallan # "include basename.Plo" scheme. 2384a041c5bSmacallan echo "#dummy" > "$depfile" 2394a041c5bSmacallan fi 2404a041c5bSmacallan rm -f "$tmpdepfile" 2414a041c5bSmacallan ;; 2424a041c5bSmacallan 24354b44505Smrgxlc) 24454b44505Smrg # This case exists only to let depend.m4 do its work. It works by 24554b44505Smrg # looking at the text of this script. This case will never be run, 24654b44505Smrg # since it is checked for above. 24754b44505Smrg exit 1 24854b44505Smrg ;; 24954b44505Smrg 2504a041c5bSmacallanaix) 2514a041c5bSmacallan # The C for AIX Compiler uses -M and outputs the dependencies 2524a041c5bSmacallan # in a .u file. In older versions, this file always lives in the 25354b44505Smrg # current directory. Also, the AIX compiler puts '$object:' at the 2544a041c5bSmacallan # start of each line; $object doesn't have directory information. 2554a041c5bSmacallan # Version 6 uses the directory in both cases. 2564a041c5bSmacallan dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 2574a041c5bSmacallan test "x$dir" = "x$object" && dir= 2584a041c5bSmacallan base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 2594a041c5bSmacallan if test "$libtool" = yes; then 2604a041c5bSmacallan tmpdepfile1=$dir$base.u 2614a041c5bSmacallan tmpdepfile2=$base.u 2624a041c5bSmacallan tmpdepfile3=$dir.libs/$base.u 2634a041c5bSmacallan "$@" -Wc,-M 2644a041c5bSmacallan else 2654a041c5bSmacallan tmpdepfile1=$dir$base.u 2664a041c5bSmacallan tmpdepfile2=$dir$base.u 2674a041c5bSmacallan tmpdepfile3=$dir$base.u 2684a041c5bSmacallan "$@" -M 2694a041c5bSmacallan fi 2704a041c5bSmacallan stat=$? 2714a041c5bSmacallan 2724a041c5bSmacallan if test $stat -eq 0; then : 2734a041c5bSmacallan else 2744a041c5bSmacallan rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 2754a041c5bSmacallan exit $stat 2764a041c5bSmacallan fi 2774a041c5bSmacallan 2784a041c5bSmacallan for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 2794a041c5bSmacallan do 2804a041c5bSmacallan test -f "$tmpdepfile" && break 2814a041c5bSmacallan done 2824a041c5bSmacallan if test -f "$tmpdepfile"; then 28354b44505Smrg # Each line is of the form 'foo.o: dependent.h'. 2844a041c5bSmacallan # Do two passes, one to just change these to 28554b44505Smrg # '$object: dependent.h' and one to simply 'dependent.h:'. 2864a041c5bSmacallan sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 28754b44505Smrg sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 2884a041c5bSmacallan else 2894a041c5bSmacallan # The sourcefile does not contain any dependencies, so just 2904a041c5bSmacallan # store a dummy comment line, to avoid errors with the Makefile 2914a041c5bSmacallan # "include basename.Plo" scheme. 2924a041c5bSmacallan echo "#dummy" > "$depfile" 2934a041c5bSmacallan fi 2944a041c5bSmacallan rm -f "$tmpdepfile" 2954a041c5bSmacallan ;; 2964a041c5bSmacallan 2974a041c5bSmacallanicc) 29854b44505Smrg # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'. 29954b44505Smrg # However on 30054b44505Smrg # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c 3014a041c5bSmacallan # ICC 7.0 will fill foo.d with something like 3024a041c5bSmacallan # foo.o: sub/foo.c 3034a041c5bSmacallan # foo.o: sub/foo.h 30454b44505Smrg # which is wrong. We want 3054a041c5bSmacallan # sub/foo.o: sub/foo.c 3064a041c5bSmacallan # sub/foo.o: sub/foo.h 3074a041c5bSmacallan # sub/foo.c: 3084a041c5bSmacallan # sub/foo.h: 3094a041c5bSmacallan # ICC 7.1 will output 3104a041c5bSmacallan # foo.o: sub/foo.c sub/foo.h 31154b44505Smrg # and will wrap long lines using '\': 3124a041c5bSmacallan # foo.o: sub/foo.c ... \ 3134a041c5bSmacallan # sub/foo.h ... \ 3144a041c5bSmacallan # ... 31554b44505Smrg # tcc 0.9.26 (FIXME still under development at the moment of writing) 31654b44505Smrg # will emit a similar output, but also prepend the continuation lines 31754b44505Smrg # with horizontal tabulation characters. 3184a041c5bSmacallan "$@" -MD -MF "$tmpdepfile" 3194a041c5bSmacallan stat=$? 3204a041c5bSmacallan if test $stat -eq 0; then : 3214a041c5bSmacallan else 3224a041c5bSmacallan rm -f "$tmpdepfile" 3234a041c5bSmacallan exit $stat 3244a041c5bSmacallan fi 3254a041c5bSmacallan rm -f "$depfile" 32654b44505Smrg # Each line is of the form 'foo.o: dependent.h', 32754b44505Smrg # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'. 32854b44505Smrg # Do two passes, one to just change these to 32954b44505Smrg # '$object: dependent.h' and one to simply 'dependent.h:'. 33054b44505Smrg sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \ 33154b44505Smrg < "$tmpdepfile" > "$depfile" 33254b44505Smrg sed ' 33354b44505Smrg s/[ '"$tab"'][ '"$tab"']*/ /g 33454b44505Smrg s/^ *// 33554b44505Smrg s/ *\\*$// 33654b44505Smrg s/^[^:]*: *// 33754b44505Smrg /^$/d 33854b44505Smrg /:$/d 33954b44505Smrg s/$/ :/ 34054b44505Smrg ' < "$tmpdepfile" >> "$depfile" 34154b44505Smrg rm -f "$tmpdepfile" 34254b44505Smrg ;; 34354b44505Smrg 34454b44505Smrg## The order of this option in the case statement is important, since the 34554b44505Smrg## shell code in configure will try each of these formats in the order 34654b44505Smrg## listed in this file. A plain '-MD' option would be understood by many 34754b44505Smrg## compilers, so we must ensure this comes after the gcc and icc options. 34854b44505Smrgpgcc) 34954b44505Smrg # Portland's C compiler understands '-MD'. 35054b44505Smrg # Will always output deps to 'file.d' where file is the root name of the 35154b44505Smrg # source file under compilation, even if file resides in a subdirectory. 35254b44505Smrg # The object file name does not affect the name of the '.d' file. 35354b44505Smrg # pgcc 10.2 will output 35454b44505Smrg # foo.o: sub/foo.c sub/foo.h 35554b44505Smrg # and will wrap long lines using '\' : 35654b44505Smrg # foo.o: sub/foo.c ... \ 35754b44505Smrg # sub/foo.h ... \ 35854b44505Smrg # ... 35954b44505Smrg dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 36054b44505Smrg test "x$dir" = "x$object" && dir= 36154b44505Smrg # Use the source, not the object, to determine the base name, since 36254b44505Smrg # that's sadly what pgcc will do too. 36354b44505Smrg base=`echo "$source" | sed -e 's|^.*/||' -e 's/\.[-_a-zA-Z0-9]*$//'` 36454b44505Smrg tmpdepfile="$base.d" 36554b44505Smrg 36654b44505Smrg # For projects that build the same source file twice into different object 36754b44505Smrg # files, the pgcc approach of using the *source* file root name can cause 36854b44505Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 36954b44505Smrg # the same $tmpdepfile. 37054b44505Smrg lockdir="$base.d-lock" 37154b44505Smrg trap "echo '$0: caught signal, cleaning up...' >&2; rm -rf $lockdir" 1 2 13 15 37254b44505Smrg numtries=100 37354b44505Smrg i=$numtries 37454b44505Smrg while test $i -gt 0 ; do 37554b44505Smrg # mkdir is a portable test-and-set. 37654b44505Smrg if mkdir $lockdir 2>/dev/null; then 37754b44505Smrg # This process acquired the lock. 37854b44505Smrg "$@" -MD 37954b44505Smrg stat=$? 38054b44505Smrg # Release the lock. 38154b44505Smrg rm -rf $lockdir 38254b44505Smrg break 38354b44505Smrg else 38454b44505Smrg ## the lock is being held by a different process, 38554b44505Smrg ## wait until the winning process is done or we timeout 38654b44505Smrg while test -d $lockdir && test $i -gt 0; do 38754b44505Smrg sleep 1 38854b44505Smrg i=`expr $i - 1` 38954b44505Smrg done 39054b44505Smrg fi 39154b44505Smrg i=`expr $i - 1` 39254b44505Smrg done 39354b44505Smrg trap - 1 2 13 15 39454b44505Smrg if test $i -le 0; then 39554b44505Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 39654b44505Smrg echo "$0: check lockdir '$lockdir'" >&2 39754b44505Smrg exit 1 39854b44505Smrg fi 39954b44505Smrg 40054b44505Smrg if test $stat -ne 0; then 40154b44505Smrg rm -f "$tmpdepfile" 40254b44505Smrg exit $stat 40354b44505Smrg fi 40454b44505Smrg rm -f "$depfile" 4054a041c5bSmacallan # Each line is of the form `foo.o: dependent.h', 4064a041c5bSmacallan # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4074a041c5bSmacallan # Do two passes, one to just change these to 4084a041c5bSmacallan # `$object: dependent.h' and one to simply `dependent.h:'. 4094a041c5bSmacallan sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4104a041c5bSmacallan # Some versions of the HPUX 10.20 sed can't process this invocation 4114a041c5bSmacallan # correctly. Breaking it into two sed invocations is a workaround. 4124a041c5bSmacallan sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" | 4134a041c5bSmacallan sed -e 's/$/ :/' >> "$depfile" 4144a041c5bSmacallan rm -f "$tmpdepfile" 4154a041c5bSmacallan ;; 4164a041c5bSmacallan 4174a041c5bSmacallanhp2) 4184a041c5bSmacallan # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4194a041c5bSmacallan # compilers, which have integrated preprocessors. The correct option 4204a041c5bSmacallan # to use with these is +Maked; it writes dependencies to a file named 4214a041c5bSmacallan # 'foo.d', which lands next to the object file, wherever that 4224a041c5bSmacallan # happens to be. 4234a041c5bSmacallan # Much of this is similar to the tru64 case; see comments there. 4244a041c5bSmacallan dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 4254a041c5bSmacallan test "x$dir" = "x$object" && dir= 4264a041c5bSmacallan base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 4274a041c5bSmacallan if test "$libtool" = yes; then 4284a041c5bSmacallan tmpdepfile1=$dir$base.d 4294a041c5bSmacallan tmpdepfile2=$dir.libs/$base.d 4304a041c5bSmacallan "$@" -Wc,+Maked 4314a041c5bSmacallan else 4324a041c5bSmacallan tmpdepfile1=$dir$base.d 4334a041c5bSmacallan tmpdepfile2=$dir$base.d 4344a041c5bSmacallan "$@" +Maked 4354a041c5bSmacallan fi 4364a041c5bSmacallan stat=$? 4374a041c5bSmacallan if test $stat -eq 0; then : 4384a041c5bSmacallan else 4394a041c5bSmacallan rm -f "$tmpdepfile1" "$tmpdepfile2" 4404a041c5bSmacallan exit $stat 4414a041c5bSmacallan fi 4424a041c5bSmacallan 4434a041c5bSmacallan for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4444a041c5bSmacallan do 4454a041c5bSmacallan test -f "$tmpdepfile" && break 4464a041c5bSmacallan done 4474a041c5bSmacallan if test -f "$tmpdepfile"; then 4484a041c5bSmacallan sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile" 44954b44505Smrg # Add 'dependent.h:' lines. 45054b44505Smrg sed -ne '2,${ 45154b44505Smrg s/^ *// 45254b44505Smrg s/ \\*$// 45354b44505Smrg s/$/:/ 45454b44505Smrg p 45554b44505Smrg }' "$tmpdepfile" >> "$depfile" 4564a041c5bSmacallan else 4574a041c5bSmacallan echo "#dummy" > "$depfile" 4584a041c5bSmacallan fi 4594a041c5bSmacallan rm -f "$tmpdepfile" "$tmpdepfile2" 4604a041c5bSmacallan ;; 4614a041c5bSmacallan 4624a041c5bSmacallantru64) 4634a041c5bSmacallan # The Tru64 compiler uses -MD to generate dependencies as a side 46454b44505Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4654a041c5bSmacallan # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 46654b44505Smrg # dependencies in 'foo.d' instead, so we check for that too. 4674a041c5bSmacallan # Subdirectories are respected. 4684a041c5bSmacallan dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 4694a041c5bSmacallan test "x$dir" = "x$object" && dir= 4704a041c5bSmacallan base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 4714a041c5bSmacallan 4724a041c5bSmacallan if test "$libtool" = yes; then 4734a041c5bSmacallan # With Tru64 cc, shared objects can also be used to make a 4744a041c5bSmacallan # static library. This mechanism is used in libtool 1.4 series to 4754a041c5bSmacallan # handle both shared and static libraries in a single compilation. 4764a041c5bSmacallan # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. 4774a041c5bSmacallan # 4784a041c5bSmacallan # With libtool 1.5 this exception was removed, and libtool now 4794a041c5bSmacallan # generates 2 separate objects for the 2 libraries. These two 4804a041c5bSmacallan # compilations output dependencies in $dir.libs/$base.o.d and 4814a041c5bSmacallan # in $dir$base.o.d. We have to check for both files, because 4824a041c5bSmacallan # one of the two compilations can be disabled. We should prefer 4834a041c5bSmacallan # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4844a041c5bSmacallan # automatically cleaned when .libs/ is deleted, while ignoring 4854a041c5bSmacallan # the former would cause a distcleancheck panic. 4864a041c5bSmacallan tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 4874a041c5bSmacallan tmpdepfile2=$dir$base.o.d # libtool 1.5 4884a041c5bSmacallan tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 4894a041c5bSmacallan tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 4904a041c5bSmacallan "$@" -Wc,-MD 4914a041c5bSmacallan else 4924a041c5bSmacallan tmpdepfile1=$dir$base.o.d 4934a041c5bSmacallan tmpdepfile2=$dir$base.d 4944a041c5bSmacallan tmpdepfile3=$dir$base.d 4954a041c5bSmacallan tmpdepfile4=$dir$base.d 4964a041c5bSmacallan "$@" -MD 4974a041c5bSmacallan fi 4984a041c5bSmacallan 4994a041c5bSmacallan stat=$? 5004a041c5bSmacallan if test $stat -eq 0; then : 5014a041c5bSmacallan else 5024a041c5bSmacallan rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 5034a041c5bSmacallan exit $stat 5044a041c5bSmacallan fi 5054a041c5bSmacallan 5064a041c5bSmacallan for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 5074a041c5bSmacallan do 5084a041c5bSmacallan test -f "$tmpdepfile" && break 5094a041c5bSmacallan done 5104a041c5bSmacallan if test -f "$tmpdepfile"; then 5114a041c5bSmacallan sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 51254b44505Smrg sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 5134a041c5bSmacallan else 5144a041c5bSmacallan echo "#dummy" > "$depfile" 5154a041c5bSmacallan fi 5164a041c5bSmacallan rm -f "$tmpdepfile" 5174a041c5bSmacallan ;; 5184a041c5bSmacallan 51954b44505Smrgmsvc7) 52054b44505Smrg if test "$libtool" = yes; then 52154b44505Smrg showIncludes=-Wc,-showIncludes 52254b44505Smrg else 52354b44505Smrg showIncludes=-showIncludes 52454b44505Smrg fi 52554b44505Smrg "$@" $showIncludes > "$tmpdepfile" 52654b44505Smrg stat=$? 52754b44505Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52854b44505Smrg if test "$stat" = 0; then : 52954b44505Smrg else 53054b44505Smrg rm -f "$tmpdepfile" 53154b44505Smrg exit $stat 53254b44505Smrg fi 53354b44505Smrg rm -f "$depfile" 53454b44505Smrg echo "$object : \\" > "$depfile" 53554b44505Smrg # The first sed program below extracts the file names and escapes 53654b44505Smrg # backslashes for cygpath. The second sed program outputs the file 53754b44505Smrg # name when reading, but also accumulates all include files in the 53854b44505Smrg # hold buffer in order to output them again at the end. This only 53954b44505Smrg # works with sed implementations that can handle large buffers. 54054b44505Smrg sed < "$tmpdepfile" -n ' 54154b44505Smrg/^Note: including file: *\(.*\)/ { 54254b44505Smrg s//\1/ 54354b44505Smrg s/\\/\\\\/g 54454b44505Smrg p 54554b44505Smrg}' | $cygpath_u | sort -u | sed -n ' 54654b44505Smrgs/ /\\ /g 54754b44505Smrgs/\(.*\)/'"$tab"'\1 \\/p 54854b44505Smrgs/.\(.*\) \\/\1:/ 54954b44505SmrgH 55054b44505Smrg$ { 55154b44505Smrg s/.*/'"$tab"'/ 55254b44505Smrg G 55354b44505Smrg p 55454b44505Smrg}' >> "$depfile" 55554b44505Smrg rm -f "$tmpdepfile" 55654b44505Smrg ;; 55754b44505Smrg 55854b44505Smrgmsvc7msys) 55954b44505Smrg # This case exists only to let depend.m4 do its work. It works by 56054b44505Smrg # looking at the text of this script. This case will never be run, 56154b44505Smrg # since it is checked for above. 56254b44505Smrg exit 1 56354b44505Smrg ;; 56454b44505Smrg 5654a041c5bSmacallan#nosideeffect) 5664a041c5bSmacallan # This comment above is used by automake to tell side-effect 5674a041c5bSmacallan # dependency tracking mechanisms from slower ones. 5684a041c5bSmacallan 5694a041c5bSmacallandashmstdout) 5704a041c5bSmacallan # Important note: in order to support this mode, a compiler *must* 5714a041c5bSmacallan # always write the preprocessed file to stdout, regardless of -o. 5724a041c5bSmacallan "$@" || exit $? 5734a041c5bSmacallan 5744a041c5bSmacallan # Remove the call to Libtool. 5754a041c5bSmacallan if test "$libtool" = yes; then 57654b44505Smrg while test "X$1" != 'X--mode=compile'; do 5774a041c5bSmacallan shift 5784a041c5bSmacallan done 5794a041c5bSmacallan shift 5804a041c5bSmacallan fi 5814a041c5bSmacallan 58254b44505Smrg # Remove '-o $object'. 5834a041c5bSmacallan IFS=" " 5844a041c5bSmacallan for arg 5854a041c5bSmacallan do 5864a041c5bSmacallan case $arg in 5874a041c5bSmacallan -o) 5884a041c5bSmacallan shift 5894a041c5bSmacallan ;; 5904a041c5bSmacallan $object) 5914a041c5bSmacallan shift 5924a041c5bSmacallan ;; 5934a041c5bSmacallan *) 5944a041c5bSmacallan set fnord "$@" "$arg" 5954a041c5bSmacallan shift # fnord 5964a041c5bSmacallan shift # $arg 5974a041c5bSmacallan ;; 5984a041c5bSmacallan esac 5994a041c5bSmacallan done 6004a041c5bSmacallan 6014a041c5bSmacallan test -z "$dashmflag" && dashmflag=-M 60254b44505Smrg # Require at least two characters before searching for ':' 6034a041c5bSmacallan # in the target name. This is to cope with DOS-style filenames: 60454b44505Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6054a041c5bSmacallan "$@" $dashmflag | 60654b44505Smrg sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile" 6074a041c5bSmacallan rm -f "$depfile" 6084a041c5bSmacallan cat < "$tmpdepfile" > "$depfile" 60954b44505Smrg tr ' ' "$nl" < "$tmpdepfile" | \ 6104a041c5bSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 6114a041c5bSmacallan## correctly. Breaking it into two sed invocations is a workaround. 6124a041c5bSmacallan sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 6134a041c5bSmacallan rm -f "$tmpdepfile" 6144a041c5bSmacallan ;; 6154a041c5bSmacallan 6164a041c5bSmacallandashXmstdout) 6174a041c5bSmacallan # This case only exists to satisfy depend.m4. It is never actually 6184a041c5bSmacallan # run, as this mode is specially recognized in the preamble. 6194a041c5bSmacallan exit 1 6204a041c5bSmacallan ;; 6214a041c5bSmacallan 6224a041c5bSmacallanmakedepend) 6234a041c5bSmacallan "$@" || exit $? 6244a041c5bSmacallan # Remove any Libtool call 6254a041c5bSmacallan if test "$libtool" = yes; then 62654b44505Smrg while test "X$1" != 'X--mode=compile'; do 6274a041c5bSmacallan shift 6284a041c5bSmacallan done 6294a041c5bSmacallan shift 6304a041c5bSmacallan fi 6314a041c5bSmacallan # X makedepend 6324a041c5bSmacallan shift 63354b44505Smrg cleared=no eat=no 63454b44505Smrg for arg 63554b44505Smrg do 6364a041c5bSmacallan case $cleared in 6374a041c5bSmacallan no) 6384a041c5bSmacallan set ""; shift 6394a041c5bSmacallan cleared=yes ;; 6404a041c5bSmacallan esac 64154b44505Smrg if test $eat = yes; then 64254b44505Smrg eat=no 64354b44505Smrg continue 64454b44505Smrg fi 6454a041c5bSmacallan case "$arg" in 6464a041c5bSmacallan -D*|-I*) 6474a041c5bSmacallan set fnord "$@" "$arg"; shift ;; 6484a041c5bSmacallan # Strip any option that makedepend may not understand. Remove 6494a041c5bSmacallan # the object too, otherwise makedepend will parse it as a source file. 65054b44505Smrg -arch) 65154b44505Smrg eat=yes ;; 6524a041c5bSmacallan -*|$object) 6534a041c5bSmacallan ;; 6544a041c5bSmacallan *) 6554a041c5bSmacallan set fnord "$@" "$arg"; shift ;; 6564a041c5bSmacallan esac 6574a041c5bSmacallan done 65854b44505Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6594a041c5bSmacallan touch "$tmpdepfile" 6604a041c5bSmacallan ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6614a041c5bSmacallan rm -f "$depfile" 66254b44505Smrg # makedepend may prepend the VPATH from the source file name to the object. 66354b44505Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66454b44505Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66554b44505Smrg sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \ 6664a041c5bSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 6674a041c5bSmacallan## correctly. Breaking it into two sed invocations is a workaround. 6684a041c5bSmacallan sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 6694a041c5bSmacallan rm -f "$tmpdepfile" "$tmpdepfile".bak 6704a041c5bSmacallan ;; 6714a041c5bSmacallan 6724a041c5bSmacallancpp) 6734a041c5bSmacallan # Important note: in order to support this mode, a compiler *must* 6744a041c5bSmacallan # always write the preprocessed file to stdout. 6754a041c5bSmacallan "$@" || exit $? 6764a041c5bSmacallan 6774a041c5bSmacallan # Remove the call to Libtool. 6784a041c5bSmacallan if test "$libtool" = yes; then 67954b44505Smrg while test "X$1" != 'X--mode=compile'; do 6804a041c5bSmacallan shift 6814a041c5bSmacallan done 6824a041c5bSmacallan shift 6834a041c5bSmacallan fi 6844a041c5bSmacallan 68554b44505Smrg # Remove '-o $object'. 6864a041c5bSmacallan IFS=" " 6874a041c5bSmacallan for arg 6884a041c5bSmacallan do 6894a041c5bSmacallan case $arg in 6904a041c5bSmacallan -o) 6914a041c5bSmacallan shift 6924a041c5bSmacallan ;; 6934a041c5bSmacallan $object) 6944a041c5bSmacallan shift 6954a041c5bSmacallan ;; 6964a041c5bSmacallan *) 6974a041c5bSmacallan set fnord "$@" "$arg" 6984a041c5bSmacallan shift # fnord 6994a041c5bSmacallan shift # $arg 7004a041c5bSmacallan ;; 7014a041c5bSmacallan esac 7024a041c5bSmacallan done 7034a041c5bSmacallan 7044a041c5bSmacallan "$@" -E | 7054a041c5bSmacallan sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7064a041c5bSmacallan -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | 7074a041c5bSmacallan sed '$ s: \\$::' > "$tmpdepfile" 7084a041c5bSmacallan rm -f "$depfile" 7094a041c5bSmacallan echo "$object : \\" > "$depfile" 7104a041c5bSmacallan cat < "$tmpdepfile" >> "$depfile" 7114a041c5bSmacallan sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7124a041c5bSmacallan rm -f "$tmpdepfile" 7134a041c5bSmacallan ;; 7144a041c5bSmacallan 7154a041c5bSmacallanmsvisualcpp) 7164a041c5bSmacallan # Important note: in order to support this mode, a compiler *must* 71754b44505Smrg # always write the preprocessed file to stdout. 7184a041c5bSmacallan "$@" || exit $? 71954b44505Smrg 72054b44505Smrg # Remove the call to Libtool. 72154b44505Smrg if test "$libtool" = yes; then 72254b44505Smrg while test "X$1" != 'X--mode=compile'; do 72354b44505Smrg shift 72454b44505Smrg done 72554b44505Smrg shift 72654b44505Smrg fi 72754b44505Smrg 7284a041c5bSmacallan IFS=" " 7294a041c5bSmacallan for arg 7304a041c5bSmacallan do 7314a041c5bSmacallan case "$arg" in 73254b44505Smrg -o) 73354b44505Smrg shift 73454b44505Smrg ;; 73554b44505Smrg $object) 73654b44505Smrg shift 73754b44505Smrg ;; 7384a041c5bSmacallan "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7394a041c5bSmacallan set fnord "$@" 7404a041c5bSmacallan shift 7414a041c5bSmacallan shift 7424a041c5bSmacallan ;; 7434a041c5bSmacallan *) 7444a041c5bSmacallan set fnord "$@" "$arg" 7454a041c5bSmacallan shift 7464a041c5bSmacallan shift 7474a041c5bSmacallan ;; 7484a041c5bSmacallan esac 7494a041c5bSmacallan done 75054b44505Smrg "$@" -E 2>/dev/null | 75154b44505Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7524a041c5bSmacallan rm -f "$depfile" 7534a041c5bSmacallan echo "$object : \\" > "$depfile" 75454b44505Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75554b44505Smrg echo "$tab" >> "$depfile" 75654b44505Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7574a041c5bSmacallan rm -f "$tmpdepfile" 7584a041c5bSmacallan ;; 7594a041c5bSmacallan 76054b44505Smrgmsvcmsys) 76154b44505Smrg # This case exists only to let depend.m4 do its work. It works by 76254b44505Smrg # looking at the text of this script. This case will never be run, 76354b44505Smrg # since it is checked for above. 76454b44505Smrg exit 1 76554b44505Smrg ;; 76654b44505Smrg 7674a041c5bSmacallannone) 7684a041c5bSmacallan exec "$@" 7694a041c5bSmacallan ;; 7704a041c5bSmacallan 7714a041c5bSmacallan*) 7724a041c5bSmacallan echo "Unknown depmode $depmode" 1>&2 7734a041c5bSmacallan exit 1 7744a041c5bSmacallan ;; 7754a041c5bSmacallanesac 7764a041c5bSmacallan 7774a041c5bSmacallanexit 0 7784a041c5bSmacallan 7794a041c5bSmacallan# Local Variables: 7804a041c5bSmacallan# mode: shell-script 7814a041c5bSmacallan# sh-indentation: 2 7824a041c5bSmacallan# eval: (add-hook 'write-file-hooks 'time-stamp) 7834a041c5bSmacallan# time-stamp-start: "scriptversion=" 7844a041c5bSmacallan# time-stamp-format: "%:y-%02m-%02d.%02H" 78554b44505Smrg# time-stamp-time-zone: "UTC" 78654b44505Smrg# time-stamp-end: "; # UTC" 7874a041c5bSmacallan# End: 788