depcomp revision 70728a38
18c9fbc29Smrg#! /bin/sh 28c9fbc29Smrg# depcomp - compile a program generating dependencies as side-effects 38c9fbc29Smrg 470728a38Smrgscriptversion=2013-05-30.07; # UTC 58c9fbc29Smrg 670728a38Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc. 78c9fbc29Smrg 88c9fbc29Smrg# This program is free software; you can redistribute it and/or modify 98c9fbc29Smrg# it under the terms of the GNU General Public License as published by 108c9fbc29Smrg# the Free Software Foundation; either version 2, or (at your option) 118c9fbc29Smrg# any later version. 128c9fbc29Smrg 138c9fbc29Smrg# This program is distributed in the hope that it will be useful, 148c9fbc29Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 158c9fbc29Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 168c9fbc29Smrg# GNU General Public License for more details. 178c9fbc29Smrg 188c9fbc29Smrg# You should have received a copy of the GNU General Public License 194e411241Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 208c9fbc29Smrg 218c9fbc29Smrg# As a special exception to the GNU General Public License, if you 228c9fbc29Smrg# distribute this file as part of a program that contains a 238c9fbc29Smrg# configuration script generated by Autoconf, you may include it under 248c9fbc29Smrg# the same distribution terms that you use for the rest of that program. 258c9fbc29Smrg 268c9fbc29Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 278c9fbc29Smrg 288c9fbc29Smrgcase $1 in 298c9fbc29Smrg '') 3070728a38Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3170728a38Smrg exit 1; 3270728a38Smrg ;; 338c9fbc29Smrg -h | --h*) 348c9fbc29Smrg cat <<\EOF 358c9fbc29SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 368c9fbc29Smrg 378c9fbc29SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 388c9fbc29Smrgas side-effects. 398c9fbc29Smrg 408c9fbc29SmrgEnvironment variables: 418c9fbc29Smrg depmode Dependency tracking mode. 4270728a38Smrg source Source file read by 'PROGRAMS ARGS'. 4370728a38Smrg object Object file output by 'PROGRAMS ARGS'. 448c9fbc29Smrg DEPDIR directory where to store dependencies. 458c9fbc29Smrg depfile Dependency file to output. 4670728a38Smrg tmpdepfile Temporary file to use when outputting dependencies. 478c9fbc29Smrg libtool Whether libtool is used (yes/no). 488c9fbc29Smrg 498c9fbc29SmrgReport bugs to <bug-automake@gnu.org>. 508c9fbc29SmrgEOF 518c9fbc29Smrg exit $? 528c9fbc29Smrg ;; 538c9fbc29Smrg -v | --v*) 548c9fbc29Smrg echo "depcomp $scriptversion" 558c9fbc29Smrg exit $? 568c9fbc29Smrg ;; 578c9fbc29Smrgesac 588c9fbc29Smrg 5970728a38Smrg# Get the directory component of the given path, and save it in the 6070728a38Smrg# global variables '$dir'. Note that this directory component will 6170728a38Smrg# be either empty or ending with a '/' character. This is deliberate. 6270728a38Smrgset_dir_from () 6370728a38Smrg{ 6470728a38Smrg case $1 in 6570728a38Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6670728a38Smrg *) dir=;; 6770728a38Smrg esac 6870728a38Smrg} 6970728a38Smrg 7070728a38Smrg# Get the suffix-stripped basename of the given path, and save it the 7170728a38Smrg# global variable '$base'. 7270728a38Smrgset_base_from () 7370728a38Smrg{ 7470728a38Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7570728a38Smrg} 7670728a38Smrg 7770728a38Smrg# If no dependency file was actually created by the compiler invocation, 7870728a38Smrg# we still have to create a dummy depfile, to avoid errors with the 7970728a38Smrg# Makefile "include basename.Plo" scheme. 8070728a38Smrgmake_dummy_depfile () 8170728a38Smrg{ 8270728a38Smrg echo "#dummy" > "$depfile" 8370728a38Smrg} 8470728a38Smrg 8570728a38Smrg# Factor out some common post-processing of the generated depfile. 8670728a38Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8770728a38Smrgaix_post_process_depfile () 8870728a38Smrg{ 8970728a38Smrg # If the compiler actually managed to produce a dependency file, 9070728a38Smrg # post-process it. 9170728a38Smrg if test -f "$tmpdepfile"; then 9270728a38Smrg # Each line is of the form 'foo.o: dependency.h'. 9370728a38Smrg # Do two passes, one to just change these to 9470728a38Smrg # $object: dependency.h 9570728a38Smrg # and one to simply output 9670728a38Smrg # dependency.h: 9770728a38Smrg # which is needed to avoid the deleted-header problem. 9870728a38Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9970728a38Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10070728a38Smrg } > "$depfile" 10170728a38Smrg rm -f "$tmpdepfile" 10270728a38Smrg else 10370728a38Smrg make_dummy_depfile 10470728a38Smrg fi 10570728a38Smrg} 10670728a38Smrg 10770728a38Smrg# A tabulation character. 10870728a38Smrgtab=' ' 10970728a38Smrg# A newline character. 11070728a38Smrgnl=' 11170728a38Smrg' 11270728a38Smrg# Character ranges might be problematic outside the C locale. 11370728a38Smrg# These definitions help. 11470728a38Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11570728a38Smrglower=abcdefghijklmnopqrstuvwxyz 11670728a38Smrgdigits=0123456789 11770728a38Smrgalpha=${upper}${lower} 11870728a38Smrg 1198c9fbc29Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1208c9fbc29Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1218c9fbc29Smrg exit 1 1228c9fbc29Smrgfi 1238c9fbc29Smrg 1248c9fbc29Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1258c9fbc29Smrgdepfile=${depfile-`echo "$object" | 1268c9fbc29Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1278c9fbc29Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1288c9fbc29Smrg 1298c9fbc29Smrgrm -f "$tmpdepfile" 1308c9fbc29Smrg 13170728a38Smrg# Avoid interferences from the environment. 13270728a38Smrggccflag= dashmflag= 13370728a38Smrg 1348c9fbc29Smrg# Some modes work just like other modes, but use different flags. We 1358c9fbc29Smrg# parameterize here, but still list the modes in the big case below, 1368c9fbc29Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1378c9fbc29Smrg# here, because this file can only contain one case statement. 1388c9fbc29Smrgif test "$depmode" = hp; then 1398c9fbc29Smrg # HP compiler uses -M and no extra arg. 1408c9fbc29Smrg gccflag=-M 1418c9fbc29Smrg depmode=gcc 1428c9fbc29Smrgfi 1438c9fbc29Smrg 1448c9fbc29Smrgif test "$depmode" = dashXmstdout; then 14570728a38Smrg # This is just like dashmstdout with a different argument. 14670728a38Smrg dashmflag=-xM 14770728a38Smrg depmode=dashmstdout 1488c9fbc29Smrgfi 1498c9fbc29Smrg 1504e411241Smrgcygpath_u="cygpath -u -f -" 1514e411241Smrgif test "$depmode" = msvcmsys; then 15270728a38Smrg # This is just like msvisualcpp but w/o cygpath translation. 15370728a38Smrg # Just convert the backslash-escaped backslashes to single forward 15470728a38Smrg # slashes to satisfy depend.m4 15570728a38Smrg cygpath_u='sed s,\\\\,/,g' 15670728a38Smrg depmode=msvisualcpp 15770728a38Smrgfi 15870728a38Smrg 15970728a38Smrgif test "$depmode" = msvc7msys; then 16070728a38Smrg # This is just like msvc7 but w/o cygpath translation. 16170728a38Smrg # Just convert the backslash-escaped backslashes to single forward 16270728a38Smrg # slashes to satisfy depend.m4 16370728a38Smrg cygpath_u='sed s,\\\\,/,g' 16470728a38Smrg depmode=msvc7 16570728a38Smrgfi 16670728a38Smrg 16770728a38Smrgif test "$depmode" = xlc; then 16870728a38Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16970728a38Smrg gccflag=-qmakedep=gcc,-MF 17070728a38Smrg depmode=gcc 1714e411241Smrgfi 1724e411241Smrg 1738c9fbc29Smrgcase "$depmode" in 1748c9fbc29Smrggcc3) 1758c9fbc29Smrg## gcc 3 implements dependency tracking that does exactly what 1768c9fbc29Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1778c9fbc29Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1788c9fbc29Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1798c9fbc29Smrg## the command line argument order; so add the flags where they 1808c9fbc29Smrg## appear in depend2.am. Note that the slowdown incurred here 1818c9fbc29Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1828c9fbc29Smrg for arg 1838c9fbc29Smrg do 1848c9fbc29Smrg case $arg in 1858c9fbc29Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1868c9fbc29Smrg *) set fnord "$@" "$arg" ;; 1878c9fbc29Smrg esac 1888c9fbc29Smrg shift # fnord 1898c9fbc29Smrg shift # $arg 1908c9fbc29Smrg done 1918c9fbc29Smrg "$@" 1928c9fbc29Smrg stat=$? 19370728a38Smrg if test $stat -ne 0; then 1948c9fbc29Smrg rm -f "$tmpdepfile" 1958c9fbc29Smrg exit $stat 1968c9fbc29Smrg fi 1978c9fbc29Smrg mv "$tmpdepfile" "$depfile" 1988c9fbc29Smrg ;; 1998c9fbc29Smrg 2008c9fbc29Smrggcc) 20170728a38Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20270728a38Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20370728a38Smrg## (see the conditional assignment to $gccflag above). 2048c9fbc29Smrg## There are various ways to get dependency output from gcc. Here's 2058c9fbc29Smrg## why we pick this rather obscure method: 2068c9fbc29Smrg## - Don't want to use -MD because we'd like the dependencies to end 2078c9fbc29Smrg## up in a subdir. Having to rename by hand is ugly. 2088c9fbc29Smrg## (We might end up doing this anyway to support other compilers.) 2098c9fbc29Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21070728a38Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21170728a38Smrg## supported by the other compilers which use the 'gcc' depmode. 2128c9fbc29Smrg## - Using -M directly means running the compiler twice (even worse 2138c9fbc29Smrg## than renaming). 2148c9fbc29Smrg if test -z "$gccflag"; then 2158c9fbc29Smrg gccflag=-MD, 2168c9fbc29Smrg fi 2178c9fbc29Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2188c9fbc29Smrg stat=$? 21970728a38Smrg if test $stat -ne 0; then 2208c9fbc29Smrg rm -f "$tmpdepfile" 2218c9fbc29Smrg exit $stat 2228c9fbc29Smrg fi 2238c9fbc29Smrg rm -f "$depfile" 2248c9fbc29Smrg echo "$object : \\" > "$depfile" 22570728a38Smrg # The second -e expression handles DOS-style file names with drive 22670728a38Smrg # letters. 2278c9fbc29Smrg sed -e 's/^[^:]*: / /' \ 2288c9fbc29Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22970728a38Smrg## This next piece of magic avoids the "deleted header file" problem. 2308c9fbc29Smrg## The problem is that when a header file which appears in a .P file 2318c9fbc29Smrg## is deleted, the dependency causes make to die (because there is 2328c9fbc29Smrg## typically no way to rebuild the header). We avoid this by adding 2338c9fbc29Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2348c9fbc29Smrg## this for us directly. 23570728a38Smrg## Some versions of gcc put a space before the ':'. On the theory 2368c9fbc29Smrg## that the space means something, we add a space to the output as 23770728a38Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23870728a38Smrg## to the object. Take care to not repeat it in the output. 2398c9fbc29Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2408c9fbc29Smrg## correctly. Breaking it into two sed invocations is a workaround. 24170728a38Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24270728a38Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24370728a38Smrg | sed -e 's/$/ :/' >> "$depfile" 2448c9fbc29Smrg rm -f "$tmpdepfile" 2458c9fbc29Smrg ;; 2468c9fbc29Smrg 2478c9fbc29Smrghp) 2488c9fbc29Smrg # This case exists only to let depend.m4 do its work. It works by 2498c9fbc29Smrg # looking at the text of this script. This case will never be run, 2508c9fbc29Smrg # since it is checked for above. 2518c9fbc29Smrg exit 1 2528c9fbc29Smrg ;; 2538c9fbc29Smrg 2548c9fbc29Smrgsgi) 2558c9fbc29Smrg if test "$libtool" = yes; then 2568c9fbc29Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2578c9fbc29Smrg else 2588c9fbc29Smrg "$@" -MDupdate "$tmpdepfile" 2598c9fbc29Smrg fi 2608c9fbc29Smrg stat=$? 26170728a38Smrg if test $stat -ne 0; then 2628c9fbc29Smrg rm -f "$tmpdepfile" 2638c9fbc29Smrg exit $stat 2648c9fbc29Smrg fi 2658c9fbc29Smrg rm -f "$depfile" 2668c9fbc29Smrg 2678c9fbc29Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2688c9fbc29Smrg echo "$object : \\" > "$depfile" 2698c9fbc29Smrg # Clip off the initial element (the dependent). Don't try to be 2708c9fbc29Smrg # clever and replace this with sed code, as IRIX sed won't handle 2718c9fbc29Smrg # lines with more than a fixed number of characters (4096 in 2728c9fbc29Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27370728a38Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2748c9fbc29Smrg # dependency line. 27570728a38Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27670728a38Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27770728a38Smrg | tr "$nl" ' ' >> "$depfile" 2784e411241Smrg echo >> "$depfile" 2798c9fbc29Smrg # The second pass generates a dummy entry for each header file. 28070728a38Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28170728a38Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28270728a38Smrg >> "$depfile" 2838c9fbc29Smrg else 28470728a38Smrg make_dummy_depfile 2858c9fbc29Smrg fi 2868c9fbc29Smrg rm -f "$tmpdepfile" 2878c9fbc29Smrg ;; 2888c9fbc29Smrg 28970728a38Smrgxlc) 29070728a38Smrg # This case exists only to let depend.m4 do its work. It works by 29170728a38Smrg # looking at the text of this script. This case will never be run, 29270728a38Smrg # since it is checked for above. 29370728a38Smrg exit 1 29470728a38Smrg ;; 29570728a38Smrg 2968c9fbc29Smrgaix) 2978c9fbc29Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2988c9fbc29Smrg # in a .u file. In older versions, this file always lives in the 29970728a38Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3008c9fbc29Smrg # start of each line; $object doesn't have directory information. 3018c9fbc29Smrg # Version 6 uses the directory in both cases. 30270728a38Smrg set_dir_from "$object" 30370728a38Smrg set_base_from "$object" 3048c9fbc29Smrg if test "$libtool" = yes; then 3054e411241Smrg tmpdepfile1=$dir$base.u 3064e411241Smrg tmpdepfile2=$base.u 3074e411241Smrg tmpdepfile3=$dir.libs/$base.u 3088c9fbc29Smrg "$@" -Wc,-M 3098c9fbc29Smrg else 3104e411241Smrg tmpdepfile1=$dir$base.u 3114e411241Smrg tmpdepfile2=$dir$base.u 3124e411241Smrg tmpdepfile3=$dir$base.u 3138c9fbc29Smrg "$@" -M 3148c9fbc29Smrg fi 3158c9fbc29Smrg stat=$? 31670728a38Smrg if test $stat -ne 0; then 3174e411241Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3188c9fbc29Smrg exit $stat 3198c9fbc29Smrg fi 3208c9fbc29Smrg 3214e411241Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3224e411241Smrg do 3234e411241Smrg test -f "$tmpdepfile" && break 3244e411241Smrg done 32570728a38Smrg aix_post_process_depfile 32670728a38Smrg ;; 32770728a38Smrg 32870728a38Smrgtcc) 32970728a38Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33070728a38Smrg # FIXME: That version still under development at the moment of writing. 33170728a38Smrg # Make that this statement remains true also for stable, released 33270728a38Smrg # versions. 33370728a38Smrg # It will wrap lines (doesn't matter whether long or short) with a 33470728a38Smrg # trailing '\', as in: 33570728a38Smrg # 33670728a38Smrg # foo.o : \ 33770728a38Smrg # foo.c \ 33870728a38Smrg # foo.h \ 33970728a38Smrg # 34070728a38Smrg # It will put a trailing '\' even on the last line, and will use leading 34170728a38Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34270728a38Smrg # "Emit spaces for -MD"). 34370728a38Smrg "$@" -MD -MF "$tmpdepfile" 34470728a38Smrg stat=$? 34570728a38Smrg if test $stat -ne 0; then 34670728a38Smrg rm -f "$tmpdepfile" 34770728a38Smrg exit $stat 3488c9fbc29Smrg fi 34970728a38Smrg rm -f "$depfile" 35070728a38Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35170728a38Smrg # We have to change lines of the first kind to '$object: \'. 35270728a38Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35370728a38Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35470728a38Smrg # dummy dependency, to avoid the deleted-header problem. 35570728a38Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3568c9fbc29Smrg rm -f "$tmpdepfile" 3578c9fbc29Smrg ;; 3588c9fbc29Smrg 35970728a38Smrg## The order of this option in the case statement is important, since the 36070728a38Smrg## shell code in configure will try each of these formats in the order 36170728a38Smrg## listed in this file. A plain '-MD' option would be understood by many 36270728a38Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36370728a38Smrgpgcc) 36470728a38Smrg # Portland's C compiler understands '-MD'. 36570728a38Smrg # Will always output deps to 'file.d' where file is the root name of the 36670728a38Smrg # source file under compilation, even if file resides in a subdirectory. 36770728a38Smrg # The object file name does not affect the name of the '.d' file. 36870728a38Smrg # pgcc 10.2 will output 3698c9fbc29Smrg # foo.o: sub/foo.c sub/foo.h 37070728a38Smrg # and will wrap long lines using '\' : 3718c9fbc29Smrg # foo.o: sub/foo.c ... \ 3728c9fbc29Smrg # sub/foo.h ... \ 3738c9fbc29Smrg # ... 37470728a38Smrg set_dir_from "$object" 37570728a38Smrg # Use the source, not the object, to determine the base name, since 37670728a38Smrg # that's sadly what pgcc will do too. 37770728a38Smrg set_base_from "$source" 37870728a38Smrg tmpdepfile=$base.d 37970728a38Smrg 38070728a38Smrg # For projects that build the same source file twice into different object 38170728a38Smrg # files, the pgcc approach of using the *source* file root name can cause 38270728a38Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38370728a38Smrg # the same $tmpdepfile. 38470728a38Smrg lockdir=$base.d-lock 38570728a38Smrg trap " 38670728a38Smrg echo '$0: caught signal, cleaning up...' >&2 38770728a38Smrg rmdir '$lockdir' 38870728a38Smrg exit 1 38970728a38Smrg " 1 2 13 15 39070728a38Smrg numtries=100 39170728a38Smrg i=$numtries 39270728a38Smrg while test $i -gt 0; do 39370728a38Smrg # mkdir is a portable test-and-set. 39470728a38Smrg if mkdir "$lockdir" 2>/dev/null; then 39570728a38Smrg # This process acquired the lock. 39670728a38Smrg "$@" -MD 39770728a38Smrg stat=$? 39870728a38Smrg # Release the lock. 39970728a38Smrg rmdir "$lockdir" 40070728a38Smrg break 40170728a38Smrg else 40270728a38Smrg # If the lock is being held by a different process, wait 40370728a38Smrg # until the winning process is done or we timeout. 40470728a38Smrg while test -d "$lockdir" && test $i -gt 0; do 40570728a38Smrg sleep 1 40670728a38Smrg i=`expr $i - 1` 40770728a38Smrg done 40870728a38Smrg fi 40970728a38Smrg i=`expr $i - 1` 41070728a38Smrg done 41170728a38Smrg trap - 1 2 13 15 41270728a38Smrg if test $i -le 0; then 41370728a38Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41470728a38Smrg echo "$0: check lockdir '$lockdir'" >&2 41570728a38Smrg exit 1 41670728a38Smrg fi 4178c9fbc29Smrg 41870728a38Smrg if test $stat -ne 0; then 4198c9fbc29Smrg rm -f "$tmpdepfile" 4208c9fbc29Smrg exit $stat 4218c9fbc29Smrg fi 4228c9fbc29Smrg rm -f "$depfile" 4238c9fbc29Smrg # Each line is of the form `foo.o: dependent.h', 4248c9fbc29Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4258c9fbc29Smrg # Do two passes, one to just change these to 4268c9fbc29Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4278c9fbc29Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4288c9fbc29Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4298c9fbc29Smrg # correctly. Breaking it into two sed invocations is a workaround. 43070728a38Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43170728a38Smrg | sed -e 's/$/ :/' >> "$depfile" 4328c9fbc29Smrg rm -f "$tmpdepfile" 4338c9fbc29Smrg ;; 4348c9fbc29Smrg 4358c9fbc29Smrghp2) 4368c9fbc29Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4378c9fbc29Smrg # compilers, which have integrated preprocessors. The correct option 4388c9fbc29Smrg # to use with these is +Maked; it writes dependencies to a file named 4398c9fbc29Smrg # 'foo.d', which lands next to the object file, wherever that 4408c9fbc29Smrg # happens to be. 4418c9fbc29Smrg # Much of this is similar to the tru64 case; see comments there. 44270728a38Smrg set_dir_from "$object" 44370728a38Smrg set_base_from "$object" 4448c9fbc29Smrg if test "$libtool" = yes; then 4458c9fbc29Smrg tmpdepfile1=$dir$base.d 4468c9fbc29Smrg tmpdepfile2=$dir.libs/$base.d 4478c9fbc29Smrg "$@" -Wc,+Maked 4488c9fbc29Smrg else 4498c9fbc29Smrg tmpdepfile1=$dir$base.d 4508c9fbc29Smrg tmpdepfile2=$dir$base.d 4518c9fbc29Smrg "$@" +Maked 4528c9fbc29Smrg fi 4538c9fbc29Smrg stat=$? 45470728a38Smrg if test $stat -ne 0; then 4558c9fbc29Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4568c9fbc29Smrg exit $stat 4578c9fbc29Smrg fi 4588c9fbc29Smrg 4598c9fbc29Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4608c9fbc29Smrg do 4618c9fbc29Smrg test -f "$tmpdepfile" && break 4628c9fbc29Smrg done 4638c9fbc29Smrg if test -f "$tmpdepfile"; then 46470728a38Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46570728a38Smrg # Add 'dependent.h:' lines. 4664e411241Smrg sed -ne '2,${ 46770728a38Smrg s/^ *// 46870728a38Smrg s/ \\*$// 46970728a38Smrg s/$/:/ 47070728a38Smrg p 47170728a38Smrg }' "$tmpdepfile" >> "$depfile" 4728c9fbc29Smrg else 47370728a38Smrg make_dummy_depfile 4748c9fbc29Smrg fi 4758c9fbc29Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4768c9fbc29Smrg ;; 4778c9fbc29Smrg 4788c9fbc29Smrgtru64) 47970728a38Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48070728a38Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48170728a38Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48270728a38Smrg # dependencies in 'foo.d' instead, so we check for that too. 48370728a38Smrg # Subdirectories are respected. 48470728a38Smrg set_dir_from "$object" 48570728a38Smrg set_base_from "$object" 48670728a38Smrg 48770728a38Smrg if test "$libtool" = yes; then 48870728a38Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48970728a38Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49070728a38Smrg # in $dir$base.o.d. We have to check for both files, because 49170728a38Smrg # one of the two compilations can be disabled. We should prefer 49270728a38Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49370728a38Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49470728a38Smrg # the former would cause a distcleancheck panic. 49570728a38Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49670728a38Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49770728a38Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49870728a38Smrg "$@" -Wc,-MD 49970728a38Smrg else 50070728a38Smrg tmpdepfile1=$dir$base.d 50170728a38Smrg tmpdepfile2=$dir$base.d 50270728a38Smrg tmpdepfile3=$dir$base.d 50370728a38Smrg "$@" -MD 50470728a38Smrg fi 50570728a38Smrg 50670728a38Smrg stat=$? 50770728a38Smrg if test $stat -ne 0; then 50870728a38Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50970728a38Smrg exit $stat 51070728a38Smrg fi 51170728a38Smrg 51270728a38Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51370728a38Smrg do 51470728a38Smrg test -f "$tmpdepfile" && break 51570728a38Smrg done 51670728a38Smrg # Same post-processing that is required for AIX mode. 51770728a38Smrg aix_post_process_depfile 51870728a38Smrg ;; 51970728a38Smrg 52070728a38Smrgmsvc7) 52170728a38Smrg if test "$libtool" = yes; then 52270728a38Smrg showIncludes=-Wc,-showIncludes 52370728a38Smrg else 52470728a38Smrg showIncludes=-showIncludes 52570728a38Smrg fi 52670728a38Smrg "$@" $showIncludes > "$tmpdepfile" 52770728a38Smrg stat=$? 52870728a38Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52970728a38Smrg if test $stat -ne 0; then 53070728a38Smrg rm -f "$tmpdepfile" 53170728a38Smrg exit $stat 53270728a38Smrg fi 53370728a38Smrg rm -f "$depfile" 53470728a38Smrg echo "$object : \\" > "$depfile" 53570728a38Smrg # The first sed program below extracts the file names and escapes 53670728a38Smrg # backslashes for cygpath. The second sed program outputs the file 53770728a38Smrg # name when reading, but also accumulates all include files in the 53870728a38Smrg # hold buffer in order to output them again at the end. This only 53970728a38Smrg # works with sed implementations that can handle large buffers. 54070728a38Smrg sed < "$tmpdepfile" -n ' 54170728a38Smrg/^Note: including file: *\(.*\)/ { 54270728a38Smrg s//\1/ 54370728a38Smrg s/\\/\\\\/g 54470728a38Smrg p 54570728a38Smrg}' | $cygpath_u | sort -u | sed -n ' 54670728a38Smrgs/ /\\ /g 54770728a38Smrgs/\(.*\)/'"$tab"'\1 \\/p 54870728a38Smrgs/.\(.*\) \\/\1:/ 54970728a38SmrgH 55070728a38Smrg$ { 55170728a38Smrg s/.*/'"$tab"'/ 55270728a38Smrg G 55370728a38Smrg p 55470728a38Smrg}' >> "$depfile" 55570728a38Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55670728a38Smrg rm -f "$tmpdepfile" 55770728a38Smrg ;; 55870728a38Smrg 55970728a38Smrgmsvc7msys) 56070728a38Smrg # This case exists only to let depend.m4 do its work. It works by 56170728a38Smrg # looking at the text of this script. This case will never be run, 56270728a38Smrg # since it is checked for above. 56370728a38Smrg exit 1 56470728a38Smrg ;; 5658c9fbc29Smrg 5668c9fbc29Smrg#nosideeffect) 5678c9fbc29Smrg # This comment above is used by automake to tell side-effect 5688c9fbc29Smrg # dependency tracking mechanisms from slower ones. 5698c9fbc29Smrg 5708c9fbc29Smrgdashmstdout) 5718c9fbc29Smrg # Important note: in order to support this mode, a compiler *must* 5728c9fbc29Smrg # always write the preprocessed file to stdout, regardless of -o. 5738c9fbc29Smrg "$@" || exit $? 5748c9fbc29Smrg 5758c9fbc29Smrg # Remove the call to Libtool. 5768c9fbc29Smrg if test "$libtool" = yes; then 5774e411241Smrg while test "X$1" != 'X--mode=compile'; do 5788c9fbc29Smrg shift 5798c9fbc29Smrg done 5808c9fbc29Smrg shift 5818c9fbc29Smrg fi 5828c9fbc29Smrg 58370728a38Smrg # Remove '-o $object'. 5848c9fbc29Smrg IFS=" " 5858c9fbc29Smrg for arg 5868c9fbc29Smrg do 5878c9fbc29Smrg case $arg in 5888c9fbc29Smrg -o) 5898c9fbc29Smrg shift 5908c9fbc29Smrg ;; 5918c9fbc29Smrg $object) 5928c9fbc29Smrg shift 5938c9fbc29Smrg ;; 5948c9fbc29Smrg *) 5958c9fbc29Smrg set fnord "$@" "$arg" 5968c9fbc29Smrg shift # fnord 5978c9fbc29Smrg shift # $arg 5988c9fbc29Smrg ;; 5998c9fbc29Smrg esac 6008c9fbc29Smrg done 6018c9fbc29Smrg 6028c9fbc29Smrg test -z "$dashmflag" && dashmflag=-M 60370728a38Smrg # Require at least two characters before searching for ':' 6048c9fbc29Smrg # in the target name. This is to cope with DOS-style filenames: 60570728a38Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6068c9fbc29Smrg "$@" $dashmflag | 60770728a38Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6088c9fbc29Smrg rm -f "$depfile" 6098c9fbc29Smrg cat < "$tmpdepfile" > "$depfile" 61070728a38Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61170728a38Smrg # correctly. Breaking it into two sed invocations is a workaround. 61270728a38Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61370728a38Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61470728a38Smrg | sed -e 's/$/ :/' >> "$depfile" 6158c9fbc29Smrg rm -f "$tmpdepfile" 6168c9fbc29Smrg ;; 6178c9fbc29Smrg 6188c9fbc29SmrgdashXmstdout) 6198c9fbc29Smrg # This case only exists to satisfy depend.m4. It is never actually 6208c9fbc29Smrg # run, as this mode is specially recognized in the preamble. 6218c9fbc29Smrg exit 1 6228c9fbc29Smrg ;; 6238c9fbc29Smrg 6248c9fbc29Smrgmakedepend) 6258c9fbc29Smrg "$@" || exit $? 6268c9fbc29Smrg # Remove any Libtool call 6278c9fbc29Smrg if test "$libtool" = yes; then 6284e411241Smrg while test "X$1" != 'X--mode=compile'; do 6298c9fbc29Smrg shift 6308c9fbc29Smrg done 6318c9fbc29Smrg shift 6328c9fbc29Smrg fi 6338c9fbc29Smrg # X makedepend 6348c9fbc29Smrg shift 6354e411241Smrg cleared=no eat=no 6364e411241Smrg for arg 6374e411241Smrg do 6388c9fbc29Smrg case $cleared in 6398c9fbc29Smrg no) 6408c9fbc29Smrg set ""; shift 6418c9fbc29Smrg cleared=yes ;; 6428c9fbc29Smrg esac 6434e411241Smrg if test $eat = yes; then 6444e411241Smrg eat=no 6454e411241Smrg continue 6464e411241Smrg fi 6478c9fbc29Smrg case "$arg" in 6488c9fbc29Smrg -D*|-I*) 6498c9fbc29Smrg set fnord "$@" "$arg"; shift ;; 6508c9fbc29Smrg # Strip any option that makedepend may not understand. Remove 6518c9fbc29Smrg # the object too, otherwise makedepend will parse it as a source file. 6524e411241Smrg -arch) 6534e411241Smrg eat=yes ;; 6548c9fbc29Smrg -*|$object) 6558c9fbc29Smrg ;; 6568c9fbc29Smrg *) 6578c9fbc29Smrg set fnord "$@" "$arg"; shift ;; 6588c9fbc29Smrg esac 6598c9fbc29Smrg done 6604e411241Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6618c9fbc29Smrg touch "$tmpdepfile" 6628c9fbc29Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6638c9fbc29Smrg rm -f "$depfile" 66470728a38Smrg # makedepend may prepend the VPATH from the source file name to the object. 66570728a38Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66670728a38Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66770728a38Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66870728a38Smrg # correctly. Breaking it into two sed invocations is a workaround. 66970728a38Smrg sed '1,2d' "$tmpdepfile" \ 67070728a38Smrg | tr ' ' "$nl" \ 67170728a38Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67270728a38Smrg | sed -e 's/$/ :/' >> "$depfile" 6738c9fbc29Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6748c9fbc29Smrg ;; 6758c9fbc29Smrg 6768c9fbc29Smrgcpp) 6778c9fbc29Smrg # Important note: in order to support this mode, a compiler *must* 6788c9fbc29Smrg # always write the preprocessed file to stdout. 6798c9fbc29Smrg "$@" || exit $? 6808c9fbc29Smrg 6818c9fbc29Smrg # Remove the call to Libtool. 6828c9fbc29Smrg if test "$libtool" = yes; then 6834e411241Smrg while test "X$1" != 'X--mode=compile'; do 6848c9fbc29Smrg shift 6858c9fbc29Smrg done 6868c9fbc29Smrg shift 6878c9fbc29Smrg fi 6888c9fbc29Smrg 68970728a38Smrg # Remove '-o $object'. 6908c9fbc29Smrg IFS=" " 6918c9fbc29Smrg for arg 6928c9fbc29Smrg do 6938c9fbc29Smrg case $arg in 6948c9fbc29Smrg -o) 6958c9fbc29Smrg shift 6968c9fbc29Smrg ;; 6978c9fbc29Smrg $object) 6988c9fbc29Smrg shift 6998c9fbc29Smrg ;; 7008c9fbc29Smrg *) 7018c9fbc29Smrg set fnord "$@" "$arg" 7028c9fbc29Smrg shift # fnord 7038c9fbc29Smrg shift # $arg 7048c9fbc29Smrg ;; 7058c9fbc29Smrg esac 7068c9fbc29Smrg done 7078c9fbc29Smrg 70870728a38Smrg "$@" -E \ 70970728a38Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71070728a38Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71170728a38Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7128c9fbc29Smrg rm -f "$depfile" 7138c9fbc29Smrg echo "$object : \\" > "$depfile" 7148c9fbc29Smrg cat < "$tmpdepfile" >> "$depfile" 7158c9fbc29Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7168c9fbc29Smrg rm -f "$tmpdepfile" 7178c9fbc29Smrg ;; 7188c9fbc29Smrg 7198c9fbc29Smrgmsvisualcpp) 7208c9fbc29Smrg # Important note: in order to support this mode, a compiler *must* 7214e411241Smrg # always write the preprocessed file to stdout. 7228c9fbc29Smrg "$@" || exit $? 7234e411241Smrg 7244e411241Smrg # Remove the call to Libtool. 7254e411241Smrg if test "$libtool" = yes; then 7264e411241Smrg while test "X$1" != 'X--mode=compile'; do 7274e411241Smrg shift 7284e411241Smrg done 7294e411241Smrg shift 7304e411241Smrg fi 7314e411241Smrg 7328c9fbc29Smrg IFS=" " 7338c9fbc29Smrg for arg 7348c9fbc29Smrg do 7358c9fbc29Smrg case "$arg" in 7364e411241Smrg -o) 7374e411241Smrg shift 7384e411241Smrg ;; 7394e411241Smrg $object) 7404e411241Smrg shift 7414e411241Smrg ;; 7428c9fbc29Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74370728a38Smrg set fnord "$@" 74470728a38Smrg shift 74570728a38Smrg shift 74670728a38Smrg ;; 7478c9fbc29Smrg *) 74870728a38Smrg set fnord "$@" "$arg" 74970728a38Smrg shift 75070728a38Smrg shift 75170728a38Smrg ;; 7528c9fbc29Smrg esac 7538c9fbc29Smrg done 7544e411241Smrg "$@" -E 2>/dev/null | 7554e411241Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7568c9fbc29Smrg rm -f "$depfile" 7578c9fbc29Smrg echo "$object : \\" > "$depfile" 75870728a38Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75970728a38Smrg echo "$tab" >> "$depfile" 7604e411241Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7618c9fbc29Smrg rm -f "$tmpdepfile" 7628c9fbc29Smrg ;; 7638c9fbc29Smrg 7644e411241Smrgmsvcmsys) 7654e411241Smrg # This case exists only to let depend.m4 do its work. It works by 7664e411241Smrg # looking at the text of this script. This case will never be run, 7674e411241Smrg # since it is checked for above. 7684e411241Smrg exit 1 7694e411241Smrg ;; 7704e411241Smrg 7718c9fbc29Smrgnone) 7728c9fbc29Smrg exec "$@" 7738c9fbc29Smrg ;; 7748c9fbc29Smrg 7758c9fbc29Smrg*) 7768c9fbc29Smrg echo "Unknown depmode $depmode" 1>&2 7778c9fbc29Smrg exit 1 7788c9fbc29Smrg ;; 7798c9fbc29Smrgesac 7808c9fbc29Smrg 7818c9fbc29Smrgexit 0 7828c9fbc29Smrg 7838c9fbc29Smrg# Local Variables: 7848c9fbc29Smrg# mode: shell-script 7858c9fbc29Smrg# sh-indentation: 2 7868c9fbc29Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 7878c9fbc29Smrg# time-stamp-start: "scriptversion=" 7888c9fbc29Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7894e411241Smrg# time-stamp-time-zone: "UTC" 7904e411241Smrg# time-stamp-end: "; # UTC" 7918c9fbc29Smrg# End: 792