depcomp revision 9511053f
1a850946eSmrg#! /bin/sh 2a850946eSmrg# depcomp - compile a program generating dependencies as side-effects 370f7c90cSmrg 49511053fSmrgscriptversion=2013-05-30.07; # UTC 570f7c90cSmrg 69511053fSmrg# Copyright (C) 1999-2013 Free Software Foundation, Inc. 7a850946eSmrg 8a850946eSmrg# This program is free software; you can redistribute it and/or modify 9a850946eSmrg# it under the terms of the GNU General Public License as published by 10a850946eSmrg# the Free Software Foundation; either version 2, or (at your option) 11a850946eSmrg# any later version. 12a850946eSmrg 13a850946eSmrg# This program is distributed in the hope that it will be useful, 14a850946eSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15a850946eSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a850946eSmrg# GNU General Public License for more details. 17a850946eSmrg 18a850946eSmrg# You should have received a copy of the GNU General Public License 1970f7c90cSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20a850946eSmrg 21a850946eSmrg# As a special exception to the GNU General Public License, if you 22a850946eSmrg# distribute this file as part of a program that contains a 23a850946eSmrg# configuration script generated by Autoconf, you may include it under 24a850946eSmrg# the same distribution terms that you use for the rest of that program. 25a850946eSmrg 26a850946eSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27a850946eSmrg 2870f7c90cSmrgcase $1 in 2970f7c90cSmrg '') 309511053fSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 319511053fSmrg exit 1; 329511053fSmrg ;; 3370f7c90cSmrg -h | --h*) 3470f7c90cSmrg cat <<\EOF 3570f7c90cSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3670f7c90cSmrg 3770f7c90cSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3870f7c90cSmrgas side-effects. 3970f7c90cSmrg 4070f7c90cSmrgEnvironment variables: 4170f7c90cSmrg depmode Dependency tracking mode. 429511053fSmrg source Source file read by 'PROGRAMS ARGS'. 439511053fSmrg object Object file output by 'PROGRAMS ARGS'. 4470f7c90cSmrg DEPDIR directory where to store dependencies. 4570f7c90cSmrg depfile Dependency file to output. 469511053fSmrg tmpdepfile Temporary file to use when outputting dependencies. 4770f7c90cSmrg libtool Whether libtool is used (yes/no). 4870f7c90cSmrg 4970f7c90cSmrgReport bugs to <bug-automake@gnu.org>. 5070f7c90cSmrgEOF 5170f7c90cSmrg exit $? 5270f7c90cSmrg ;; 5370f7c90cSmrg -v | --v*) 5470f7c90cSmrg echo "depcomp $scriptversion" 5570f7c90cSmrg exit $? 5670f7c90cSmrg ;; 5770f7c90cSmrgesac 5870f7c90cSmrg 599511053fSmrg# Get the directory component of the given path, and save it in the 609511053fSmrg# global variables '$dir'. Note that this directory component will 619511053fSmrg# be either empty or ending with a '/' character. This is deliberate. 629511053fSmrgset_dir_from () 639511053fSmrg{ 649511053fSmrg case $1 in 659511053fSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 669511053fSmrg *) dir=;; 679511053fSmrg esac 689511053fSmrg} 699511053fSmrg 709511053fSmrg# Get the suffix-stripped basename of the given path, and save it the 719511053fSmrg# global variable '$base'. 729511053fSmrgset_base_from () 739511053fSmrg{ 749511053fSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 759511053fSmrg} 769511053fSmrg 779511053fSmrg# If no dependency file was actually created by the compiler invocation, 789511053fSmrg# we still have to create a dummy depfile, to avoid errors with the 799511053fSmrg# Makefile "include basename.Plo" scheme. 809511053fSmrgmake_dummy_depfile () 819511053fSmrg{ 829511053fSmrg echo "#dummy" > "$depfile" 839511053fSmrg} 849511053fSmrg 859511053fSmrg# Factor out some common post-processing of the generated depfile. 869511053fSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 879511053fSmrgaix_post_process_depfile () 889511053fSmrg{ 899511053fSmrg # If the compiler actually managed to produce a dependency file, 909511053fSmrg # post-process it. 919511053fSmrg if test -f "$tmpdepfile"; then 929511053fSmrg # Each line is of the form 'foo.o: dependency.h'. 939511053fSmrg # Do two passes, one to just change these to 949511053fSmrg # $object: dependency.h 959511053fSmrg # and one to simply output 969511053fSmrg # dependency.h: 979511053fSmrg # which is needed to avoid the deleted-header problem. 989511053fSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 999511053fSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1009511053fSmrg } > "$depfile" 1019511053fSmrg rm -f "$tmpdepfile" 1029511053fSmrg else 1039511053fSmrg make_dummy_depfile 1049511053fSmrg fi 1059511053fSmrg} 1069511053fSmrg 1079511053fSmrg# A tabulation character. 1089511053fSmrgtab=' ' 1099511053fSmrg# A newline character. 1109511053fSmrgnl=' 1119511053fSmrg' 1129511053fSmrg# Character ranges might be problematic outside the C locale. 1139511053fSmrg# These definitions help. 1149511053fSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1159511053fSmrglower=abcdefghijklmnopqrstuvwxyz 1169511053fSmrgdigits=0123456789 1179511053fSmrgalpha=${upper}${lower} 1189511053fSmrg 119a850946eSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120a850946eSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121a850946eSmrg exit 1 122a850946eSmrgfi 123a850946eSmrg 12470f7c90cSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12570f7c90cSmrgdepfile=${depfile-`echo "$object" | 12670f7c90cSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127a850946eSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128a850946eSmrg 129a850946eSmrgrm -f "$tmpdepfile" 130a850946eSmrg 1319511053fSmrg# Avoid interferences from the environment. 1329511053fSmrggccflag= dashmflag= 1339511053fSmrg 134a850946eSmrg# Some modes work just like other modes, but use different flags. We 135a850946eSmrg# parameterize here, but still list the modes in the big case below, 136a850946eSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137a850946eSmrg# here, because this file can only contain one case statement. 138a850946eSmrgif test "$depmode" = hp; then 139a850946eSmrg # HP compiler uses -M and no extra arg. 140a850946eSmrg gccflag=-M 141a850946eSmrg depmode=gcc 142a850946eSmrgfi 143a850946eSmrg 144a850946eSmrgif test "$depmode" = dashXmstdout; then 1459511053fSmrg # This is just like dashmstdout with a different argument. 1469511053fSmrg dashmflag=-xM 1479511053fSmrg depmode=dashmstdout 148a850946eSmrgfi 149a850946eSmrg 15070f7c90cSmrgcygpath_u="cygpath -u -f -" 15170f7c90cSmrgif test "$depmode" = msvcmsys; then 1529511053fSmrg # This is just like msvisualcpp but w/o cygpath translation. 1539511053fSmrg # Just convert the backslash-escaped backslashes to single forward 1549511053fSmrg # slashes to satisfy depend.m4 1559511053fSmrg cygpath_u='sed s,\\\\,/,g' 1569511053fSmrg depmode=msvisualcpp 1579511053fSmrgfi 1589511053fSmrg 1599511053fSmrgif test "$depmode" = msvc7msys; then 1609511053fSmrg # This is just like msvc7 but w/o cygpath translation. 1619511053fSmrg # Just convert the backslash-escaped backslashes to single forward 1629511053fSmrg # slashes to satisfy depend.m4 1639511053fSmrg cygpath_u='sed s,\\\\,/,g' 1649511053fSmrg depmode=msvc7 1659511053fSmrgfi 1669511053fSmrg 1679511053fSmrgif test "$depmode" = xlc; then 1689511053fSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1699511053fSmrg gccflag=-qmakedep=gcc,-MF 1709511053fSmrg depmode=gcc 17170f7c90cSmrgfi 17270f7c90cSmrg 173a850946eSmrgcase "$depmode" in 174a850946eSmrggcc3) 175a850946eSmrg## gcc 3 implements dependency tracking that does exactly what 176a850946eSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177a850946eSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 17870f7c90cSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 17970f7c90cSmrg## the command line argument order; so add the flags where they 18070f7c90cSmrg## appear in depend2.am. Note that the slowdown incurred here 18170f7c90cSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 18270f7c90cSmrg for arg 18370f7c90cSmrg do 18470f7c90cSmrg case $arg in 18570f7c90cSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 18670f7c90cSmrg *) set fnord "$@" "$arg" ;; 18770f7c90cSmrg esac 18870f7c90cSmrg shift # fnord 18970f7c90cSmrg shift # $arg 19070f7c90cSmrg done 19170f7c90cSmrg "$@" 192a850946eSmrg stat=$? 1939511053fSmrg if test $stat -ne 0; then 194a850946eSmrg rm -f "$tmpdepfile" 195a850946eSmrg exit $stat 196a850946eSmrg fi 197a850946eSmrg mv "$tmpdepfile" "$depfile" 198a850946eSmrg ;; 199a850946eSmrg 200a850946eSmrggcc) 2019511053fSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2029511053fSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2039511053fSmrg## (see the conditional assignment to $gccflag above). 204a850946eSmrg## There are various ways to get dependency output from gcc. Here's 205a850946eSmrg## why we pick this rather obscure method: 206a850946eSmrg## - Don't want to use -MD because we'd like the dependencies to end 207a850946eSmrg## up in a subdir. Having to rename by hand is ugly. 208a850946eSmrg## (We might end up doing this anyway to support other compilers.) 209a850946eSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2109511053fSmrg## -MM, not -M (despite what the docs say). Also, it might not be 2119511053fSmrg## supported by the other compilers which use the 'gcc' depmode. 212a850946eSmrg## - Using -M directly means running the compiler twice (even worse 213a850946eSmrg## than renaming). 214a850946eSmrg if test -z "$gccflag"; then 215a850946eSmrg gccflag=-MD, 216a850946eSmrg fi 217a850946eSmrg "$@" -Wp,"$gccflag$tmpdepfile" 218a850946eSmrg stat=$? 2199511053fSmrg if test $stat -ne 0; then 220a850946eSmrg rm -f "$tmpdepfile" 221a850946eSmrg exit $stat 222a850946eSmrg fi 223a850946eSmrg rm -f "$depfile" 224a850946eSmrg echo "$object : \\" > "$depfile" 2259511053fSmrg # The second -e expression handles DOS-style file names with drive 2269511053fSmrg # letters. 227a850946eSmrg sed -e 's/^[^:]*: / /' \ 228a850946eSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2299511053fSmrg## This next piece of magic avoids the "deleted header file" problem. 230a850946eSmrg## The problem is that when a header file which appears in a .P file 231a850946eSmrg## is deleted, the dependency causes make to die (because there is 232a850946eSmrg## typically no way to rebuild the header). We avoid this by adding 233a850946eSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 234a850946eSmrg## this for us directly. 2359511053fSmrg## Some versions of gcc put a space before the ':'. On the theory 236a850946eSmrg## that the space means something, we add a space to the output as 2379511053fSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 2389511053fSmrg## to the object. Take care to not repeat it in the output. 239a850946eSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 240a850946eSmrg## correctly. Breaking it into two sed invocations is a workaround. 2419511053fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2429511053fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2439511053fSmrg | sed -e 's/$/ :/' >> "$depfile" 244a850946eSmrg rm -f "$tmpdepfile" 245a850946eSmrg ;; 246a850946eSmrg 247a850946eSmrghp) 248a850946eSmrg # This case exists only to let depend.m4 do its work. It works by 249a850946eSmrg # looking at the text of this script. This case will never be run, 250a850946eSmrg # since it is checked for above. 251a850946eSmrg exit 1 252a850946eSmrg ;; 253a850946eSmrg 254a850946eSmrgsgi) 255a850946eSmrg if test "$libtool" = yes; then 256a850946eSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257a850946eSmrg else 258a850946eSmrg "$@" -MDupdate "$tmpdepfile" 259a850946eSmrg fi 260a850946eSmrg stat=$? 2619511053fSmrg if test $stat -ne 0; then 262a850946eSmrg rm -f "$tmpdepfile" 263a850946eSmrg exit $stat 264a850946eSmrg fi 265a850946eSmrg rm -f "$depfile" 266a850946eSmrg 267a850946eSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268a850946eSmrg echo "$object : \\" > "$depfile" 269a850946eSmrg # Clip off the initial element (the dependent). Don't try to be 270a850946eSmrg # clever and replace this with sed code, as IRIX sed won't handle 271a850946eSmrg # lines with more than a fixed number of characters (4096 in 272a850946eSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2739511053fSmrg # the IRIX cc adds comments like '#:fec' to the end of the 274a850946eSmrg # dependency line. 2759511053fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2769511053fSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2779511053fSmrg | tr "$nl" ' ' >> "$depfile" 27870f7c90cSmrg echo >> "$depfile" 279a850946eSmrg # The second pass generates a dummy entry for each header file. 2809511053fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2819511053fSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2829511053fSmrg >> "$depfile" 283a850946eSmrg else 2849511053fSmrg make_dummy_depfile 285a850946eSmrg fi 286a850946eSmrg rm -f "$tmpdepfile" 287a850946eSmrg ;; 288a850946eSmrg 2899511053fSmrgxlc) 2909511053fSmrg # This case exists only to let depend.m4 do its work. It works by 2919511053fSmrg # looking at the text of this script. This case will never be run, 2929511053fSmrg # since it is checked for above. 2939511053fSmrg exit 1 2949511053fSmrg ;; 2959511053fSmrg 296a850946eSmrgaix) 297a850946eSmrg # The C for AIX Compiler uses -M and outputs the dependencies 298a850946eSmrg # in a .u file. In older versions, this file always lives in the 2999511053fSmrg # current directory. Also, the AIX compiler puts '$object:' at the 300a850946eSmrg # start of each line; $object doesn't have directory information. 301a850946eSmrg # Version 6 uses the directory in both cases. 3029511053fSmrg set_dir_from "$object" 3039511053fSmrg set_base_from "$object" 304a850946eSmrg if test "$libtool" = yes; then 30570f7c90cSmrg tmpdepfile1=$dir$base.u 30670f7c90cSmrg tmpdepfile2=$base.u 30770f7c90cSmrg tmpdepfile3=$dir.libs/$base.u 308a850946eSmrg "$@" -Wc,-M 309a850946eSmrg else 31070f7c90cSmrg tmpdepfile1=$dir$base.u 31170f7c90cSmrg tmpdepfile2=$dir$base.u 31270f7c90cSmrg tmpdepfile3=$dir$base.u 313a850946eSmrg "$@" -M 314a850946eSmrg fi 315a850946eSmrg stat=$? 3169511053fSmrg if test $stat -ne 0; then 31770f7c90cSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318a850946eSmrg exit $stat 319a850946eSmrg fi 320a850946eSmrg 32170f7c90cSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32270f7c90cSmrg do 32370f7c90cSmrg test -f "$tmpdepfile" && break 32470f7c90cSmrg done 3259511053fSmrg aix_post_process_depfile 3269511053fSmrg ;; 3279511053fSmrg 3289511053fSmrgtcc) 3299511053fSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3309511053fSmrg # FIXME: That version still under development at the moment of writing. 3319511053fSmrg # Make that this statement remains true also for stable, released 3329511053fSmrg # versions. 3339511053fSmrg # It will wrap lines (doesn't matter whether long or short) with a 3349511053fSmrg # trailing '\', as in: 3359511053fSmrg # 3369511053fSmrg # foo.o : \ 3379511053fSmrg # foo.c \ 3389511053fSmrg # foo.h \ 3399511053fSmrg # 3409511053fSmrg # It will put a trailing '\' even on the last line, and will use leading 3419511053fSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 3429511053fSmrg # "Emit spaces for -MD"). 3439511053fSmrg "$@" -MD -MF "$tmpdepfile" 3449511053fSmrg stat=$? 3459511053fSmrg if test $stat -ne 0; then 3469511053fSmrg rm -f "$tmpdepfile" 3479511053fSmrg exit $stat 348a850946eSmrg fi 3499511053fSmrg rm -f "$depfile" 3509511053fSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3519511053fSmrg # We have to change lines of the first kind to '$object: \'. 3529511053fSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3539511053fSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 3549511053fSmrg # dummy dependency, to avoid the deleted-header problem. 3559511053fSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356a850946eSmrg rm -f "$tmpdepfile" 357a850946eSmrg ;; 358a850946eSmrg 3599511053fSmrg## The order of this option in the case statement is important, since the 3609511053fSmrg## shell code in configure will try each of these formats in the order 3619511053fSmrg## listed in this file. A plain '-MD' option would be understood by many 3629511053fSmrg## compilers, so we must ensure this comes after the gcc and icc options. 3639511053fSmrgpgcc) 3649511053fSmrg # Portland's C compiler understands '-MD'. 3659511053fSmrg # Will always output deps to 'file.d' where file is the root name of the 3669511053fSmrg # source file under compilation, even if file resides in a subdirectory. 3679511053fSmrg # The object file name does not affect the name of the '.d' file. 3689511053fSmrg # pgcc 10.2 will output 369a850946eSmrg # foo.o: sub/foo.c sub/foo.h 3709511053fSmrg # and will wrap long lines using '\' : 371a850946eSmrg # foo.o: sub/foo.c ... \ 372a850946eSmrg # sub/foo.h ... \ 373a850946eSmrg # ... 3749511053fSmrg set_dir_from "$object" 3759511053fSmrg # Use the source, not the object, to determine the base name, since 3769511053fSmrg # that's sadly what pgcc will do too. 3779511053fSmrg set_base_from "$source" 3789511053fSmrg tmpdepfile=$base.d 3799511053fSmrg 3809511053fSmrg # For projects that build the same source file twice into different object 3819511053fSmrg # files, the pgcc approach of using the *source* file root name can cause 3829511053fSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3839511053fSmrg # the same $tmpdepfile. 3849511053fSmrg lockdir=$base.d-lock 3859511053fSmrg trap " 3869511053fSmrg echo '$0: caught signal, cleaning up...' >&2 3879511053fSmrg rmdir '$lockdir' 3889511053fSmrg exit 1 3899511053fSmrg " 1 2 13 15 3909511053fSmrg numtries=100 3919511053fSmrg i=$numtries 3929511053fSmrg while test $i -gt 0; do 3939511053fSmrg # mkdir is a portable test-and-set. 3949511053fSmrg if mkdir "$lockdir" 2>/dev/null; then 3959511053fSmrg # This process acquired the lock. 3969511053fSmrg "$@" -MD 3979511053fSmrg stat=$? 3989511053fSmrg # Release the lock. 3999511053fSmrg rmdir "$lockdir" 4009511053fSmrg break 4019511053fSmrg else 4029511053fSmrg # If the lock is being held by a different process, wait 4039511053fSmrg # until the winning process is done or we timeout. 4049511053fSmrg while test -d "$lockdir" && test $i -gt 0; do 4059511053fSmrg sleep 1 4069511053fSmrg i=`expr $i - 1` 4079511053fSmrg done 4089511053fSmrg fi 4099511053fSmrg i=`expr $i - 1` 4109511053fSmrg done 4119511053fSmrg trap - 1 2 13 15 4129511053fSmrg if test $i -le 0; then 4139511053fSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4149511053fSmrg echo "$0: check lockdir '$lockdir'" >&2 4159511053fSmrg exit 1 4169511053fSmrg fi 417a850946eSmrg 4189511053fSmrg if test $stat -ne 0; then 419a850946eSmrg rm -f "$tmpdepfile" 420a850946eSmrg exit $stat 421a850946eSmrg fi 422a850946eSmrg rm -f "$depfile" 423a850946eSmrg # Each line is of the form `foo.o: dependent.h', 424a850946eSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425a850946eSmrg # Do two passes, one to just change these to 426a850946eSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427a850946eSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428a850946eSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429a850946eSmrg # correctly. Breaking it into two sed invocations is a workaround. 4309511053fSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4319511053fSmrg | sed -e 's/$/ :/' >> "$depfile" 432a850946eSmrg rm -f "$tmpdepfile" 433a850946eSmrg ;; 434a850946eSmrg 43570f7c90cSmrghp2) 43670f7c90cSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 43770f7c90cSmrg # compilers, which have integrated preprocessors. The correct option 43870f7c90cSmrg # to use with these is +Maked; it writes dependencies to a file named 43970f7c90cSmrg # 'foo.d', which lands next to the object file, wherever that 44070f7c90cSmrg # happens to be. 44170f7c90cSmrg # Much of this is similar to the tru64 case; see comments there. 4429511053fSmrg set_dir_from "$object" 4439511053fSmrg set_base_from "$object" 44470f7c90cSmrg if test "$libtool" = yes; then 44570f7c90cSmrg tmpdepfile1=$dir$base.d 44670f7c90cSmrg tmpdepfile2=$dir.libs/$base.d 44770f7c90cSmrg "$@" -Wc,+Maked 44870f7c90cSmrg else 44970f7c90cSmrg tmpdepfile1=$dir$base.d 45070f7c90cSmrg tmpdepfile2=$dir$base.d 45170f7c90cSmrg "$@" +Maked 45270f7c90cSmrg fi 45370f7c90cSmrg stat=$? 4549511053fSmrg if test $stat -ne 0; then 45570f7c90cSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 45670f7c90cSmrg exit $stat 45770f7c90cSmrg fi 45870f7c90cSmrg 45970f7c90cSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 46070f7c90cSmrg do 46170f7c90cSmrg test -f "$tmpdepfile" && break 46270f7c90cSmrg done 46370f7c90cSmrg if test -f "$tmpdepfile"; then 4649511053fSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4659511053fSmrg # Add 'dependent.h:' lines. 46670f7c90cSmrg sed -ne '2,${ 4679511053fSmrg s/^ *// 4689511053fSmrg s/ \\*$// 4699511053fSmrg s/$/:/ 4709511053fSmrg p 4719511053fSmrg }' "$tmpdepfile" >> "$depfile" 47270f7c90cSmrg else 4739511053fSmrg make_dummy_depfile 47470f7c90cSmrg fi 47570f7c90cSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 47670f7c90cSmrg ;; 47770f7c90cSmrg 478a850946eSmrgtru64) 4799511053fSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 4809511053fSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4819511053fSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4829511053fSmrg # dependencies in 'foo.d' instead, so we check for that too. 4839511053fSmrg # Subdirectories are respected. 4849511053fSmrg set_dir_from "$object" 4859511053fSmrg set_base_from "$object" 4869511053fSmrg 4879511053fSmrg if test "$libtool" = yes; then 4889511053fSmrg # Libtool generates 2 separate objects for the 2 libraries. These 4899511053fSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 4909511053fSmrg # in $dir$base.o.d. We have to check for both files, because 4919511053fSmrg # one of the two compilations can be disabled. We should prefer 4929511053fSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4939511053fSmrg # automatically cleaned when .libs/ is deleted, while ignoring 4949511053fSmrg # the former would cause a distcleancheck panic. 4959511053fSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4969511053fSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4979511053fSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4989511053fSmrg "$@" -Wc,-MD 4999511053fSmrg else 5009511053fSmrg tmpdepfile1=$dir$base.d 5019511053fSmrg tmpdepfile2=$dir$base.d 5029511053fSmrg tmpdepfile3=$dir$base.d 5039511053fSmrg "$@" -MD 5049511053fSmrg fi 5059511053fSmrg 5069511053fSmrg stat=$? 5079511053fSmrg if test $stat -ne 0; then 5089511053fSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5099511053fSmrg exit $stat 5109511053fSmrg fi 5119511053fSmrg 5129511053fSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5139511053fSmrg do 5149511053fSmrg test -f "$tmpdepfile" && break 5159511053fSmrg done 5169511053fSmrg # Same post-processing that is required for AIX mode. 5179511053fSmrg aix_post_process_depfile 5189511053fSmrg ;; 5199511053fSmrg 5209511053fSmrgmsvc7) 5219511053fSmrg if test "$libtool" = yes; then 5229511053fSmrg showIncludes=-Wc,-showIncludes 5239511053fSmrg else 5249511053fSmrg showIncludes=-showIncludes 5259511053fSmrg fi 5269511053fSmrg "$@" $showIncludes > "$tmpdepfile" 5279511053fSmrg stat=$? 5289511053fSmrg grep -v '^Note: including file: ' "$tmpdepfile" 5299511053fSmrg if test $stat -ne 0; then 5309511053fSmrg rm -f "$tmpdepfile" 5319511053fSmrg exit $stat 5329511053fSmrg fi 5339511053fSmrg rm -f "$depfile" 5349511053fSmrg echo "$object : \\" > "$depfile" 5359511053fSmrg # The first sed program below extracts the file names and escapes 5369511053fSmrg # backslashes for cygpath. The second sed program outputs the file 5379511053fSmrg # name when reading, but also accumulates all include files in the 5389511053fSmrg # hold buffer in order to output them again at the end. This only 5399511053fSmrg # works with sed implementations that can handle large buffers. 5409511053fSmrg sed < "$tmpdepfile" -n ' 5419511053fSmrg/^Note: including file: *\(.*\)/ { 5429511053fSmrg s//\1/ 5439511053fSmrg s/\\/\\\\/g 5449511053fSmrg p 5459511053fSmrg}' | $cygpath_u | sort -u | sed -n ' 5469511053fSmrgs/ /\\ /g 5479511053fSmrgs/\(.*\)/'"$tab"'\1 \\/p 5489511053fSmrgs/.\(.*\) \\/\1:/ 5499511053fSmrgH 5509511053fSmrg$ { 5519511053fSmrg s/.*/'"$tab"'/ 5529511053fSmrg G 5539511053fSmrg p 5549511053fSmrg}' >> "$depfile" 5559511053fSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5569511053fSmrg rm -f "$tmpdepfile" 5579511053fSmrg ;; 5589511053fSmrg 5599511053fSmrgmsvc7msys) 5609511053fSmrg # This case exists only to let depend.m4 do its work. It works by 5619511053fSmrg # looking at the text of this script. This case will never be run, 5629511053fSmrg # since it is checked for above. 5639511053fSmrg exit 1 5649511053fSmrg ;; 565a850946eSmrg 566a850946eSmrg#nosideeffect) 567a850946eSmrg # This comment above is used by automake to tell side-effect 568a850946eSmrg # dependency tracking mechanisms from slower ones. 569a850946eSmrg 570a850946eSmrgdashmstdout) 571a850946eSmrg # Important note: in order to support this mode, a compiler *must* 572a850946eSmrg # always write the preprocessed file to stdout, regardless of -o. 573a850946eSmrg "$@" || exit $? 574a850946eSmrg 575a850946eSmrg # Remove the call to Libtool. 576a850946eSmrg if test "$libtool" = yes; then 57770f7c90cSmrg while test "X$1" != 'X--mode=compile'; do 578a850946eSmrg shift 579a850946eSmrg done 580a850946eSmrg shift 581a850946eSmrg fi 582a850946eSmrg 5839511053fSmrg # Remove '-o $object'. 584a850946eSmrg IFS=" " 585a850946eSmrg for arg 586a850946eSmrg do 587a850946eSmrg case $arg in 588a850946eSmrg -o) 589a850946eSmrg shift 590a850946eSmrg ;; 591a850946eSmrg $object) 592a850946eSmrg shift 593a850946eSmrg ;; 594a850946eSmrg *) 595a850946eSmrg set fnord "$@" "$arg" 596a850946eSmrg shift # fnord 597a850946eSmrg shift # $arg 598a850946eSmrg ;; 599a850946eSmrg esac 600a850946eSmrg done 601a850946eSmrg 602a850946eSmrg test -z "$dashmflag" && dashmflag=-M 6039511053fSmrg # Require at least two characters before searching for ':' 604a850946eSmrg # in the target name. This is to cope with DOS-style filenames: 6059511053fSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606a850946eSmrg "$@" $dashmflag | 6079511053fSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608a850946eSmrg rm -f "$depfile" 609a850946eSmrg cat < "$tmpdepfile" > "$depfile" 6109511053fSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6119511053fSmrg # correctly. Breaking it into two sed invocations is a workaround. 6129511053fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 6139511053fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6149511053fSmrg | sed -e 's/$/ :/' >> "$depfile" 615a850946eSmrg rm -f "$tmpdepfile" 616a850946eSmrg ;; 617a850946eSmrg 618a850946eSmrgdashXmstdout) 619a850946eSmrg # This case only exists to satisfy depend.m4. It is never actually 620a850946eSmrg # run, as this mode is specially recognized in the preamble. 621a850946eSmrg exit 1 622a850946eSmrg ;; 623a850946eSmrg 624a850946eSmrgmakedepend) 625a850946eSmrg "$@" || exit $? 626a850946eSmrg # Remove any Libtool call 627a850946eSmrg if test "$libtool" = yes; then 62870f7c90cSmrg while test "X$1" != 'X--mode=compile'; do 629a850946eSmrg shift 630a850946eSmrg done 631a850946eSmrg shift 632a850946eSmrg fi 633a850946eSmrg # X makedepend 634a850946eSmrg shift 63570f7c90cSmrg cleared=no eat=no 63670f7c90cSmrg for arg 63770f7c90cSmrg do 638a850946eSmrg case $cleared in 639a850946eSmrg no) 640a850946eSmrg set ""; shift 641a850946eSmrg cleared=yes ;; 642a850946eSmrg esac 64370f7c90cSmrg if test $eat = yes; then 64470f7c90cSmrg eat=no 64570f7c90cSmrg continue 64670f7c90cSmrg fi 647a850946eSmrg case "$arg" in 648a850946eSmrg -D*|-I*) 649a850946eSmrg set fnord "$@" "$arg"; shift ;; 650a850946eSmrg # Strip any option that makedepend may not understand. Remove 651a850946eSmrg # the object too, otherwise makedepend will parse it as a source file. 65270f7c90cSmrg -arch) 65370f7c90cSmrg eat=yes ;; 654a850946eSmrg -*|$object) 655a850946eSmrg ;; 656a850946eSmrg *) 657a850946eSmrg set fnord "$@" "$arg"; shift ;; 658a850946eSmrg esac 659a850946eSmrg done 66070f7c90cSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661a850946eSmrg touch "$tmpdepfile" 662a850946eSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663a850946eSmrg rm -f "$depfile" 6649511053fSmrg # makedepend may prepend the VPATH from the source file name to the object. 6659511053fSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 6669511053fSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6679511053fSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6689511053fSmrg # correctly. Breaking it into two sed invocations is a workaround. 6699511053fSmrg sed '1,2d' "$tmpdepfile" \ 6709511053fSmrg | tr ' ' "$nl" \ 6719511053fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6729511053fSmrg | sed -e 's/$/ :/' >> "$depfile" 673a850946eSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674a850946eSmrg ;; 675a850946eSmrg 676a850946eSmrgcpp) 677a850946eSmrg # Important note: in order to support this mode, a compiler *must* 678a850946eSmrg # always write the preprocessed file to stdout. 679a850946eSmrg "$@" || exit $? 680a850946eSmrg 681a850946eSmrg # Remove the call to Libtool. 682a850946eSmrg if test "$libtool" = yes; then 68370f7c90cSmrg while test "X$1" != 'X--mode=compile'; do 684a850946eSmrg shift 685a850946eSmrg done 686a850946eSmrg shift 687a850946eSmrg fi 688a850946eSmrg 6899511053fSmrg # Remove '-o $object'. 690a850946eSmrg IFS=" " 691a850946eSmrg for arg 692a850946eSmrg do 693a850946eSmrg case $arg in 694a850946eSmrg -o) 695a850946eSmrg shift 696a850946eSmrg ;; 697a850946eSmrg $object) 698a850946eSmrg shift 699a850946eSmrg ;; 700a850946eSmrg *) 701a850946eSmrg set fnord "$@" "$arg" 702a850946eSmrg shift # fnord 703a850946eSmrg shift # $arg 704a850946eSmrg ;; 705a850946eSmrg esac 706a850946eSmrg done 707a850946eSmrg 7089511053fSmrg "$@" -E \ 7099511053fSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7109511053fSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7119511053fSmrg | sed '$ s: \\$::' > "$tmpdepfile" 712a850946eSmrg rm -f "$depfile" 713a850946eSmrg echo "$object : \\" > "$depfile" 714a850946eSmrg cat < "$tmpdepfile" >> "$depfile" 715a850946eSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716a850946eSmrg rm -f "$tmpdepfile" 717a850946eSmrg ;; 718a850946eSmrg 719a850946eSmrgmsvisualcpp) 720a850946eSmrg # Important note: in order to support this mode, a compiler *must* 72170f7c90cSmrg # always write the preprocessed file to stdout. 722a850946eSmrg "$@" || exit $? 72370f7c90cSmrg 72470f7c90cSmrg # Remove the call to Libtool. 72570f7c90cSmrg if test "$libtool" = yes; then 72670f7c90cSmrg while test "X$1" != 'X--mode=compile'; do 72770f7c90cSmrg shift 72870f7c90cSmrg done 72970f7c90cSmrg shift 73070f7c90cSmrg fi 73170f7c90cSmrg 732a850946eSmrg IFS=" " 733a850946eSmrg for arg 734a850946eSmrg do 735a850946eSmrg case "$arg" in 73670f7c90cSmrg -o) 73770f7c90cSmrg shift 73870f7c90cSmrg ;; 73970f7c90cSmrg $object) 74070f7c90cSmrg shift 74170f7c90cSmrg ;; 742a850946eSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7439511053fSmrg set fnord "$@" 7449511053fSmrg shift 7459511053fSmrg shift 7469511053fSmrg ;; 747a850946eSmrg *) 7489511053fSmrg set fnord "$@" "$arg" 7499511053fSmrg shift 7509511053fSmrg shift 7519511053fSmrg ;; 752a850946eSmrg esac 753a850946eSmrg done 75470f7c90cSmrg "$@" -E 2>/dev/null | 75570f7c90cSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756a850946eSmrg rm -f "$depfile" 757a850946eSmrg echo "$object : \\" > "$depfile" 7589511053fSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7599511053fSmrg echo "$tab" >> "$depfile" 76070f7c90cSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761a850946eSmrg rm -f "$tmpdepfile" 762a850946eSmrg ;; 763a850946eSmrg 76470f7c90cSmrgmsvcmsys) 76570f7c90cSmrg # This case exists only to let depend.m4 do its work. It works by 76670f7c90cSmrg # looking at the text of this script. This case will never be run, 76770f7c90cSmrg # since it is checked for above. 76870f7c90cSmrg exit 1 76970f7c90cSmrg ;; 77070f7c90cSmrg 771a850946eSmrgnone) 772a850946eSmrg exec "$@" 773a850946eSmrg ;; 774a850946eSmrg 775a850946eSmrg*) 776a850946eSmrg echo "Unknown depmode $depmode" 1>&2 777a850946eSmrg exit 1 778a850946eSmrg ;; 779a850946eSmrgesac 780a850946eSmrg 781a850946eSmrgexit 0 78270f7c90cSmrg 78370f7c90cSmrg# Local Variables: 78470f7c90cSmrg# mode: shell-script 78570f7c90cSmrg# sh-indentation: 2 78670f7c90cSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 78770f7c90cSmrg# time-stamp-start: "scriptversion=" 78870f7c90cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78970f7c90cSmrg# time-stamp-time-zone: "UTC" 79070f7c90cSmrg# time-stamp-end: "; # UTC" 79170f7c90cSmrg# End: 792