1e6232409Smrg#! /bin/sh 2e6232409Smrg# depcomp - compile a program generating dependencies as side-effects 3e6232409Smrg 46d1874b2Smrgscriptversion=2018-03-07.03; # UTC 5e6232409Smrg 66d1874b2Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7e6232409Smrg 8e6232409Smrg# This program is free software; you can redistribute it and/or modify 9e6232409Smrg# it under the terms of the GNU General Public License as published by 10e6232409Smrg# the Free Software Foundation; either version 2, or (at your option) 11e6232409Smrg# any later version. 12e6232409Smrg 13e6232409Smrg# This program is distributed in the hope that it will be useful, 14e6232409Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15e6232409Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16e6232409Smrg# GNU General Public License for more details. 17e6232409Smrg 18e6232409Smrg# You should have received a copy of the GNU General Public License 196d1874b2Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20e6232409Smrg 21e6232409Smrg# As a special exception to the GNU General Public License, if you 22e6232409Smrg# distribute this file as part of a program that contains a 23e6232409Smrg# configuration script generated by Autoconf, you may include it under 24e6232409Smrg# the same distribution terms that you use for the rest of that program. 25e6232409Smrg 26e6232409Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27e6232409Smrg 28e6232409Smrgcase $1 in 29e6232409Smrg '') 306a45684fSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 316a45684fSmrg exit 1; 326a45684fSmrg ;; 33e6232409Smrg -h | --h*) 34e6232409Smrg cat <<\EOF 35e6232409SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36e6232409Smrg 37e6232409SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38e6232409Smrgas side-effects. 39e6232409Smrg 40e6232409SmrgEnvironment variables: 41e6232409Smrg depmode Dependency tracking mode. 426a45684fSmrg source Source file read by 'PROGRAMS ARGS'. 436a45684fSmrg object Object file output by 'PROGRAMS ARGS'. 44e6232409Smrg DEPDIR directory where to store dependencies. 45e6232409Smrg depfile Dependency file to output. 4694a251fdSmrg tmpdepfile Temporary file to use when outputting dependencies. 47e6232409Smrg libtool Whether libtool is used (yes/no). 48e6232409Smrg 49e6232409SmrgReport bugs to <bug-automake@gnu.org>. 50e6232409SmrgEOF 51e6232409Smrg exit $? 52e6232409Smrg ;; 53e6232409Smrg -v | --v*) 54e6232409Smrg echo "depcomp $scriptversion" 55e6232409Smrg exit $? 56e6232409Smrg ;; 57e6232409Smrgesac 58e6232409Smrg 596a45684fSmrg# Get the directory component of the given path, and save it in the 606a45684fSmrg# global variables '$dir'. Note that this directory component will 616a45684fSmrg# be either empty or ending with a '/' character. This is deliberate. 626a45684fSmrgset_dir_from () 636a45684fSmrg{ 646a45684fSmrg case $1 in 656a45684fSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 666a45684fSmrg *) dir=;; 676a45684fSmrg esac 686a45684fSmrg} 696a45684fSmrg 706a45684fSmrg# Get the suffix-stripped basename of the given path, and save it the 716a45684fSmrg# global variable '$base'. 726a45684fSmrgset_base_from () 736a45684fSmrg{ 746a45684fSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 756a45684fSmrg} 766a45684fSmrg 776a45684fSmrg# If no dependency file was actually created by the compiler invocation, 786a45684fSmrg# we still have to create a dummy depfile, to avoid errors with the 796a45684fSmrg# Makefile "include basename.Plo" scheme. 806a45684fSmrgmake_dummy_depfile () 816a45684fSmrg{ 826a45684fSmrg echo "#dummy" > "$depfile" 836a45684fSmrg} 846a45684fSmrg 856a45684fSmrg# Factor out some common post-processing of the generated depfile. 866a45684fSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 876a45684fSmrgaix_post_process_depfile () 886a45684fSmrg{ 896a45684fSmrg # If the compiler actually managed to produce a dependency file, 906a45684fSmrg # post-process it. 916a45684fSmrg if test -f "$tmpdepfile"; then 926a45684fSmrg # Each line is of the form 'foo.o: dependency.h'. 936a45684fSmrg # Do two passes, one to just change these to 946a45684fSmrg # $object: dependency.h 956a45684fSmrg # and one to simply output 966a45684fSmrg # dependency.h: 976a45684fSmrg # which is needed to avoid the deleted-header problem. 986a45684fSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 996a45684fSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1006a45684fSmrg } > "$depfile" 1016a45684fSmrg rm -f "$tmpdepfile" 1026a45684fSmrg else 1036a45684fSmrg make_dummy_depfile 1046a45684fSmrg fi 1056a45684fSmrg} 1066a45684fSmrg 1076a45684fSmrg# A tabulation character. 1086a45684fSmrgtab=' ' 1096a45684fSmrg# A newline character. 1106a45684fSmrgnl=' 1116a45684fSmrg' 1126a45684fSmrg# Character ranges might be problematic outside the C locale. 1136a45684fSmrg# These definitions help. 1146a45684fSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1156a45684fSmrglower=abcdefghijklmnopqrstuvwxyz 1166a45684fSmrgdigits=0123456789 1176a45684fSmrgalpha=${upper}${lower} 1186a45684fSmrg 119e6232409Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120e6232409Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121e6232409Smrg exit 1 122e6232409Smrgfi 123e6232409Smrg 124e6232409Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125e6232409Smrgdepfile=${depfile-`echo "$object" | 126e6232409Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127e6232409Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128e6232409Smrg 129e6232409Smrgrm -f "$tmpdepfile" 130e6232409Smrg 1316a45684fSmrg# Avoid interferences from the environment. 1326a45684fSmrggccflag= dashmflag= 1336a45684fSmrg 134e6232409Smrg# Some modes work just like other modes, but use different flags. We 135e6232409Smrg# parameterize here, but still list the modes in the big case below, 136e6232409Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137e6232409Smrg# here, because this file can only contain one case statement. 138e6232409Smrgif test "$depmode" = hp; then 139e6232409Smrg # HP compiler uses -M and no extra arg. 140e6232409Smrg gccflag=-M 141e6232409Smrg depmode=gcc 142e6232409Smrgfi 143e6232409Smrg 144e6232409Smrgif test "$depmode" = dashXmstdout; then 1456a45684fSmrg # This is just like dashmstdout with a different argument. 1466a45684fSmrg dashmflag=-xM 1476a45684fSmrg depmode=dashmstdout 148e6232409Smrgfi 149e6232409Smrg 1508fff3f40Smrgcygpath_u="cygpath -u -f -" 1518fff3f40Smrgif test "$depmode" = msvcmsys; then 1526a45684fSmrg # This is just like msvisualcpp but w/o cygpath translation. 1536a45684fSmrg # Just convert the backslash-escaped backslashes to single forward 1546a45684fSmrg # slashes to satisfy depend.m4 1556a45684fSmrg cygpath_u='sed s,\\\\,/,g' 1566a45684fSmrg depmode=msvisualcpp 1578fff3f40Smrgfi 1588fff3f40Smrg 15994a251fdSmrgif test "$depmode" = msvc7msys; then 1606a45684fSmrg # This is just like msvc7 but w/o cygpath translation. 1616a45684fSmrg # Just convert the backslash-escaped backslashes to single forward 1626a45684fSmrg # slashes to satisfy depend.m4 1636a45684fSmrg cygpath_u='sed s,\\\\,/,g' 1646a45684fSmrg depmode=msvc7 1656a45684fSmrgfi 1666a45684fSmrg 1676a45684fSmrgif test "$depmode" = xlc; then 1686a45684fSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1696a45684fSmrg gccflag=-qmakedep=gcc,-MF 1706a45684fSmrg depmode=gcc 17194a251fdSmrgfi 17294a251fdSmrg 173e6232409Smrgcase "$depmode" in 174e6232409Smrggcc3) 175e6232409Smrg## gcc 3 implements dependency tracking that does exactly what 176e6232409Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177e6232409Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1788fff3f40Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1798fff3f40Smrg## the command line argument order; so add the flags where they 1808fff3f40Smrg## appear in depend2.am. Note that the slowdown incurred here 1818fff3f40Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1828fff3f40Smrg for arg 1838fff3f40Smrg do 1848fff3f40Smrg case $arg in 1858fff3f40Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1868fff3f40Smrg *) set fnord "$@" "$arg" ;; 1878fff3f40Smrg esac 1888fff3f40Smrg shift # fnord 1898fff3f40Smrg shift # $arg 1908fff3f40Smrg done 1918fff3f40Smrg "$@" 192e6232409Smrg stat=$? 1936a45684fSmrg if test $stat -ne 0; then 194e6232409Smrg rm -f "$tmpdepfile" 195e6232409Smrg exit $stat 196e6232409Smrg fi 197e6232409Smrg mv "$tmpdepfile" "$depfile" 198e6232409Smrg ;; 199e6232409Smrg 200e6232409Smrggcc) 2016a45684fSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2026a45684fSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2036a45684fSmrg## (see the conditional assignment to $gccflag above). 204e6232409Smrg## There are various ways to get dependency output from gcc. Here's 205e6232409Smrg## why we pick this rather obscure method: 206e6232409Smrg## - Don't want to use -MD because we'd like the dependencies to end 207e6232409Smrg## up in a subdir. Having to rename by hand is ugly. 208e6232409Smrg## (We might end up doing this anyway to support other compilers.) 209e6232409Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2106a45684fSmrg## -MM, not -M (despite what the docs say). Also, it might not be 2116a45684fSmrg## supported by the other compilers which use the 'gcc' depmode. 212e6232409Smrg## - Using -M directly means running the compiler twice (even worse 213e6232409Smrg## than renaming). 214e6232409Smrg if test -z "$gccflag"; then 215e6232409Smrg gccflag=-MD, 216e6232409Smrg fi 217e6232409Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218e6232409Smrg stat=$? 2196a45684fSmrg if test $stat -ne 0; then 220e6232409Smrg rm -f "$tmpdepfile" 221e6232409Smrg exit $stat 222e6232409Smrg fi 223e6232409Smrg rm -f "$depfile" 224e6232409Smrg echo "$object : \\" > "$depfile" 2256a45684fSmrg # The second -e expression handles DOS-style file names with drive 2266a45684fSmrg # letters. 227e6232409Smrg sed -e 's/^[^:]*: / /' \ 228e6232409Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2296a45684fSmrg## This next piece of magic avoids the "deleted header file" problem. 230e6232409Smrg## The problem is that when a header file which appears in a .P file 231e6232409Smrg## is deleted, the dependency causes make to die (because there is 232e6232409Smrg## typically no way to rebuild the header). We avoid this by adding 233e6232409Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234e6232409Smrg## this for us directly. 2356a45684fSmrg## Some versions of gcc put a space before the ':'. On the theory 236e6232409Smrg## that the space means something, we add a space to the output as 23794a251fdSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 23894a251fdSmrg## to the object. Take care to not repeat it in the output. 239e6232409Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240e6232409Smrg## correctly. Breaking it into two sed invocations is a workaround. 2416a45684fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2426a45684fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2436a45684fSmrg | sed -e 's/$/ :/' >> "$depfile" 244e6232409Smrg rm -f "$tmpdepfile" 245e6232409Smrg ;; 246e6232409Smrg 247e6232409Smrghp) 248e6232409Smrg # This case exists only to let depend.m4 do its work. It works by 249e6232409Smrg # looking at the text of this script. This case will never be run, 250e6232409Smrg # since it is checked for above. 251e6232409Smrg exit 1 252e6232409Smrg ;; 253e6232409Smrg 254e6232409Smrgsgi) 255e6232409Smrg if test "$libtool" = yes; then 256e6232409Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257e6232409Smrg else 258e6232409Smrg "$@" -MDupdate "$tmpdepfile" 259e6232409Smrg fi 260e6232409Smrg stat=$? 2616a45684fSmrg if test $stat -ne 0; then 262e6232409Smrg rm -f "$tmpdepfile" 263e6232409Smrg exit $stat 264e6232409Smrg fi 265e6232409Smrg rm -f "$depfile" 266e6232409Smrg 267e6232409Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268e6232409Smrg echo "$object : \\" > "$depfile" 269e6232409Smrg # Clip off the initial element (the dependent). Don't try to be 270e6232409Smrg # clever and replace this with sed code, as IRIX sed won't handle 271e6232409Smrg # lines with more than a fixed number of characters (4096 in 272e6232409Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2736a45684fSmrg # the IRIX cc adds comments like '#:fec' to the end of the 274e6232409Smrg # dependency line. 2756a45684fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2766a45684fSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2776a45684fSmrg | tr "$nl" ' ' >> "$depfile" 2788fff3f40Smrg echo >> "$depfile" 279e6232409Smrg # The second pass generates a dummy entry for each header file. 2806a45684fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2816a45684fSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2826a45684fSmrg >> "$depfile" 283e6232409Smrg else 2846a45684fSmrg make_dummy_depfile 285e6232409Smrg fi 286e6232409Smrg rm -f "$tmpdepfile" 287e6232409Smrg ;; 288e6232409Smrg 2896a45684fSmrgxlc) 2906a45684fSmrg # This case exists only to let depend.m4 do its work. It works by 2916a45684fSmrg # looking at the text of this script. This case will never be run, 2926a45684fSmrg # since it is checked for above. 2936a45684fSmrg exit 1 2946a45684fSmrg ;; 2956a45684fSmrg 296e6232409Smrgaix) 297e6232409Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298e6232409Smrg # in a .u file. In older versions, this file always lives in the 2996a45684fSmrg # current directory. Also, the AIX compiler puts '$object:' at the 300e6232409Smrg # start of each line; $object doesn't have directory information. 301e6232409Smrg # Version 6 uses the directory in both cases. 3026a45684fSmrg set_dir_from "$object" 3036a45684fSmrg set_base_from "$object" 304e6232409Smrg if test "$libtool" = yes; then 3058fff3f40Smrg tmpdepfile1=$dir$base.u 3068fff3f40Smrg tmpdepfile2=$base.u 3078fff3f40Smrg tmpdepfile3=$dir.libs/$base.u 308e6232409Smrg "$@" -Wc,-M 309e6232409Smrg else 3108fff3f40Smrg tmpdepfile1=$dir$base.u 3118fff3f40Smrg tmpdepfile2=$dir$base.u 3128fff3f40Smrg tmpdepfile3=$dir$base.u 313e6232409Smrg "$@" -M 314e6232409Smrg fi 315e6232409Smrg stat=$? 3166a45684fSmrg if test $stat -ne 0; then 3178fff3f40Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318e6232409Smrg exit $stat 319e6232409Smrg fi 320e6232409Smrg 3218fff3f40Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3228fff3f40Smrg do 3238fff3f40Smrg test -f "$tmpdepfile" && break 3248fff3f40Smrg done 3256a45684fSmrg aix_post_process_depfile 3266a45684fSmrg ;; 3276a45684fSmrg 3286a45684fSmrgtcc) 3296a45684fSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3306a45684fSmrg # FIXME: That version still under development at the moment of writing. 3316a45684fSmrg # Make that this statement remains true also for stable, released 3326a45684fSmrg # versions. 3336a45684fSmrg # It will wrap lines (doesn't matter whether long or short) with a 3346a45684fSmrg # trailing '\', as in: 3356a45684fSmrg # 3366a45684fSmrg # foo.o : \ 3376a45684fSmrg # foo.c \ 3386a45684fSmrg # foo.h \ 3396a45684fSmrg # 3406a45684fSmrg # It will put a trailing '\' even on the last line, and will use leading 3416a45684fSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 3426a45684fSmrg # "Emit spaces for -MD"). 3436a45684fSmrg "$@" -MD -MF "$tmpdepfile" 3446a45684fSmrg stat=$? 3456a45684fSmrg if test $stat -ne 0; then 3466a45684fSmrg rm -f "$tmpdepfile" 3476a45684fSmrg exit $stat 348e6232409Smrg fi 3496a45684fSmrg rm -f "$depfile" 3506a45684fSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3516a45684fSmrg # We have to change lines of the first kind to '$object: \'. 3526a45684fSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3536a45684fSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 3546a45684fSmrg # dummy dependency, to avoid the deleted-header problem. 3556a45684fSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356e6232409Smrg rm -f "$tmpdepfile" 357e6232409Smrg ;; 358e6232409Smrg 3596a45684fSmrg## The order of this option in the case statement is important, since the 3606a45684fSmrg## shell code in configure will try each of these formats in the order 3616a45684fSmrg## listed in this file. A plain '-MD' option would be understood by many 3626a45684fSmrg## compilers, so we must ensure this comes after the gcc and icc options. 3636a45684fSmrgpgcc) 3646a45684fSmrg # Portland's C compiler understands '-MD'. 3656a45684fSmrg # Will always output deps to 'file.d' where file is the root name of the 3666a45684fSmrg # source file under compilation, even if file resides in a subdirectory. 3676a45684fSmrg # The object file name does not affect the name of the '.d' file. 3686a45684fSmrg # pgcc 10.2 will output 369e6232409Smrg # foo.o: sub/foo.c sub/foo.h 3706a45684fSmrg # and will wrap long lines using '\' : 371e6232409Smrg # foo.o: sub/foo.c ... \ 372e6232409Smrg # sub/foo.h ... \ 373e6232409Smrg # ... 3746a45684fSmrg set_dir_from "$object" 3756a45684fSmrg # Use the source, not the object, to determine the base name, since 3766a45684fSmrg # that's sadly what pgcc will do too. 3776a45684fSmrg set_base_from "$source" 3786a45684fSmrg tmpdepfile=$base.d 3796a45684fSmrg 3806a45684fSmrg # For projects that build the same source file twice into different object 3816a45684fSmrg # files, the pgcc approach of using the *source* file root name can cause 3826a45684fSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3836a45684fSmrg # the same $tmpdepfile. 3846a45684fSmrg lockdir=$base.d-lock 3856a45684fSmrg trap " 3866a45684fSmrg echo '$0: caught signal, cleaning up...' >&2 3876a45684fSmrg rmdir '$lockdir' 3886a45684fSmrg exit 1 3896a45684fSmrg " 1 2 13 15 3906a45684fSmrg numtries=100 3916a45684fSmrg i=$numtries 3926a45684fSmrg while test $i -gt 0; do 3936a45684fSmrg # mkdir is a portable test-and-set. 3946a45684fSmrg if mkdir "$lockdir" 2>/dev/null; then 3956a45684fSmrg # This process acquired the lock. 3966a45684fSmrg "$@" -MD 3976a45684fSmrg stat=$? 3986a45684fSmrg # Release the lock. 3996a45684fSmrg rmdir "$lockdir" 4006a45684fSmrg break 4016a45684fSmrg else 4026a45684fSmrg # If the lock is being held by a different process, wait 4036a45684fSmrg # until the winning process is done or we timeout. 4046a45684fSmrg while test -d "$lockdir" && test $i -gt 0; do 4056a45684fSmrg sleep 1 4066a45684fSmrg i=`expr $i - 1` 4076a45684fSmrg done 4086a45684fSmrg fi 4096a45684fSmrg i=`expr $i - 1` 4106a45684fSmrg done 4116a45684fSmrg trap - 1 2 13 15 4126a45684fSmrg if test $i -le 0; then 4136a45684fSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4146a45684fSmrg echo "$0: check lockdir '$lockdir'" >&2 4156a45684fSmrg exit 1 4166a45684fSmrg fi 417e6232409Smrg 4186a45684fSmrg if test $stat -ne 0; then 419e6232409Smrg rm -f "$tmpdepfile" 420e6232409Smrg exit $stat 421e6232409Smrg fi 422e6232409Smrg rm -f "$depfile" 423e6232409Smrg # Each line is of the form `foo.o: dependent.h', 424e6232409Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425e6232409Smrg # Do two passes, one to just change these to 426e6232409Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427e6232409Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428e6232409Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429e6232409Smrg # correctly. Breaking it into two sed invocations is a workaround. 4306a45684fSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4316a45684fSmrg | sed -e 's/$/ :/' >> "$depfile" 432e6232409Smrg rm -f "$tmpdepfile" 433e6232409Smrg ;; 434e6232409Smrg 4358fff3f40Smrghp2) 4368fff3f40Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4378fff3f40Smrg # compilers, which have integrated preprocessors. The correct option 4388fff3f40Smrg # to use with these is +Maked; it writes dependencies to a file named 4398fff3f40Smrg # 'foo.d', which lands next to the object file, wherever that 4408fff3f40Smrg # happens to be. 4418fff3f40Smrg # Much of this is similar to the tru64 case; see comments there. 4426a45684fSmrg set_dir_from "$object" 4436a45684fSmrg set_base_from "$object" 4448fff3f40Smrg if test "$libtool" = yes; then 4458fff3f40Smrg tmpdepfile1=$dir$base.d 4468fff3f40Smrg tmpdepfile2=$dir.libs/$base.d 4478fff3f40Smrg "$@" -Wc,+Maked 4488fff3f40Smrg else 4498fff3f40Smrg tmpdepfile1=$dir$base.d 4508fff3f40Smrg tmpdepfile2=$dir$base.d 4518fff3f40Smrg "$@" +Maked 4528fff3f40Smrg fi 4538fff3f40Smrg stat=$? 4546a45684fSmrg if test $stat -ne 0; then 4558fff3f40Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4568fff3f40Smrg exit $stat 4578fff3f40Smrg fi 4588fff3f40Smrg 4598fff3f40Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4608fff3f40Smrg do 4618fff3f40Smrg test -f "$tmpdepfile" && break 4628fff3f40Smrg done 4638fff3f40Smrg if test -f "$tmpdepfile"; then 4646a45684fSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4656a45684fSmrg # Add 'dependent.h:' lines. 4668fff3f40Smrg sed -ne '2,${ 4676a45684fSmrg s/^ *// 4686a45684fSmrg s/ \\*$// 4696a45684fSmrg s/$/:/ 4706a45684fSmrg p 4716a45684fSmrg }' "$tmpdepfile" >> "$depfile" 4728fff3f40Smrg else 4736a45684fSmrg make_dummy_depfile 4748fff3f40Smrg fi 4758fff3f40Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4768fff3f40Smrg ;; 4778fff3f40Smrg 478e6232409Smrgtru64) 4796a45684fSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 4806a45684fSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4816a45684fSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4826a45684fSmrg # dependencies in 'foo.d' instead, so we check for that too. 4836a45684fSmrg # Subdirectories are respected. 4846a45684fSmrg set_dir_from "$object" 4856a45684fSmrg set_base_from "$object" 4866a45684fSmrg 4876a45684fSmrg if test "$libtool" = yes; then 4886a45684fSmrg # Libtool generates 2 separate objects for the 2 libraries. These 4896a45684fSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 4906a45684fSmrg # in $dir$base.o.d. We have to check for both files, because 4916a45684fSmrg # one of the two compilations can be disabled. We should prefer 4926a45684fSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4936a45684fSmrg # automatically cleaned when .libs/ is deleted, while ignoring 4946a45684fSmrg # the former would cause a distcleancheck panic. 4956a45684fSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4966a45684fSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4976a45684fSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4986a45684fSmrg "$@" -Wc,-MD 4996a45684fSmrg else 5006a45684fSmrg tmpdepfile1=$dir$base.d 5016a45684fSmrg tmpdepfile2=$dir$base.d 5026a45684fSmrg tmpdepfile3=$dir$base.d 5036a45684fSmrg "$@" -MD 5046a45684fSmrg fi 5056a45684fSmrg 5066a45684fSmrg stat=$? 5076a45684fSmrg if test $stat -ne 0; then 5086a45684fSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5096a45684fSmrg exit $stat 5106a45684fSmrg fi 5116a45684fSmrg 5126a45684fSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5136a45684fSmrg do 5146a45684fSmrg test -f "$tmpdepfile" && break 5156a45684fSmrg done 5166a45684fSmrg # Same post-processing that is required for AIX mode. 5176a45684fSmrg aix_post_process_depfile 5186a45684fSmrg ;; 519e6232409Smrg 52094a251fdSmrgmsvc7) 52194a251fdSmrg if test "$libtool" = yes; then 52294a251fdSmrg showIncludes=-Wc,-showIncludes 52394a251fdSmrg else 52494a251fdSmrg showIncludes=-showIncludes 52594a251fdSmrg fi 52694a251fdSmrg "$@" $showIncludes > "$tmpdepfile" 52794a251fdSmrg stat=$? 52894a251fdSmrg grep -v '^Note: including file: ' "$tmpdepfile" 5296a45684fSmrg if test $stat -ne 0; then 53094a251fdSmrg rm -f "$tmpdepfile" 53194a251fdSmrg exit $stat 53294a251fdSmrg fi 53394a251fdSmrg rm -f "$depfile" 53494a251fdSmrg echo "$object : \\" > "$depfile" 53594a251fdSmrg # The first sed program below extracts the file names and escapes 53694a251fdSmrg # backslashes for cygpath. The second sed program outputs the file 53794a251fdSmrg # name when reading, but also accumulates all include files in the 53894a251fdSmrg # hold buffer in order to output them again at the end. This only 53994a251fdSmrg # works with sed implementations that can handle large buffers. 54094a251fdSmrg sed < "$tmpdepfile" -n ' 54194a251fdSmrg/^Note: including file: *\(.*\)/ { 54294a251fdSmrg s//\1/ 54394a251fdSmrg s/\\/\\\\/g 54494a251fdSmrg p 54594a251fdSmrg}' | $cygpath_u | sort -u | sed -n ' 54694a251fdSmrgs/ /\\ /g 5476a45684fSmrgs/\(.*\)/'"$tab"'\1 \\/p 54894a251fdSmrgs/.\(.*\) \\/\1:/ 54994a251fdSmrgH 55094a251fdSmrg$ { 5516a45684fSmrg s/.*/'"$tab"'/ 55294a251fdSmrg G 55394a251fdSmrg p 55494a251fdSmrg}' >> "$depfile" 5556a45684fSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55694a251fdSmrg rm -f "$tmpdepfile" 55794a251fdSmrg ;; 55894a251fdSmrg 55994a251fdSmrgmsvc7msys) 56094a251fdSmrg # This case exists only to let depend.m4 do its work. It works by 56194a251fdSmrg # looking at the text of this script. This case will never be run, 56294a251fdSmrg # since it is checked for above. 56394a251fdSmrg exit 1 56494a251fdSmrg ;; 56594a251fdSmrg 566e6232409Smrg#nosideeffect) 567e6232409Smrg # This comment above is used by automake to tell side-effect 568e6232409Smrg # dependency tracking mechanisms from slower ones. 569e6232409Smrg 570e6232409Smrgdashmstdout) 571e6232409Smrg # Important note: in order to support this mode, a compiler *must* 572e6232409Smrg # always write the preprocessed file to stdout, regardless of -o. 573e6232409Smrg "$@" || exit $? 574e6232409Smrg 575e6232409Smrg # Remove the call to Libtool. 576e6232409Smrg if test "$libtool" = yes; then 5778fff3f40Smrg while test "X$1" != 'X--mode=compile'; do 578e6232409Smrg shift 579e6232409Smrg done 580e6232409Smrg shift 581e6232409Smrg fi 582e6232409Smrg 5836a45684fSmrg # Remove '-o $object'. 584e6232409Smrg IFS=" " 585e6232409Smrg for arg 586e6232409Smrg do 587e6232409Smrg case $arg in 588e6232409Smrg -o) 589e6232409Smrg shift 590e6232409Smrg ;; 591e6232409Smrg $object) 592e6232409Smrg shift 593e6232409Smrg ;; 594e6232409Smrg *) 595e6232409Smrg set fnord "$@" "$arg" 596e6232409Smrg shift # fnord 597e6232409Smrg shift # $arg 598e6232409Smrg ;; 599e6232409Smrg esac 600e6232409Smrg done 601e6232409Smrg 602e6232409Smrg test -z "$dashmflag" && dashmflag=-M 6036a45684fSmrg # Require at least two characters before searching for ':' 604e6232409Smrg # in the target name. This is to cope with DOS-style filenames: 6056a45684fSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606e6232409Smrg "$@" $dashmflag | 6076a45684fSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608e6232409Smrg rm -f "$depfile" 609e6232409Smrg cat < "$tmpdepfile" > "$depfile" 6106a45684fSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6116a45684fSmrg # correctly. Breaking it into two sed invocations is a workaround. 6126a45684fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 6136a45684fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6146a45684fSmrg | sed -e 's/$/ :/' >> "$depfile" 615e6232409Smrg rm -f "$tmpdepfile" 616e6232409Smrg ;; 617e6232409Smrg 618e6232409SmrgdashXmstdout) 619e6232409Smrg # This case only exists to satisfy depend.m4. It is never actually 620e6232409Smrg # run, as this mode is specially recognized in the preamble. 621e6232409Smrg exit 1 622e6232409Smrg ;; 623e6232409Smrg 624e6232409Smrgmakedepend) 625e6232409Smrg "$@" || exit $? 626e6232409Smrg # Remove any Libtool call 627e6232409Smrg if test "$libtool" = yes; then 6288fff3f40Smrg while test "X$1" != 'X--mode=compile'; do 629e6232409Smrg shift 630e6232409Smrg done 631e6232409Smrg shift 632e6232409Smrg fi 633e6232409Smrg # X makedepend 634e6232409Smrg shift 6358fff3f40Smrg cleared=no eat=no 6368fff3f40Smrg for arg 6378fff3f40Smrg do 638e6232409Smrg case $cleared in 639e6232409Smrg no) 640e6232409Smrg set ""; shift 641e6232409Smrg cleared=yes ;; 642e6232409Smrg esac 6438fff3f40Smrg if test $eat = yes; then 6448fff3f40Smrg eat=no 6458fff3f40Smrg continue 6468fff3f40Smrg fi 647e6232409Smrg case "$arg" in 648e6232409Smrg -D*|-I*) 649e6232409Smrg set fnord "$@" "$arg"; shift ;; 650e6232409Smrg # Strip any option that makedepend may not understand. Remove 651e6232409Smrg # the object too, otherwise makedepend will parse it as a source file. 6528fff3f40Smrg -arch) 6538fff3f40Smrg eat=yes ;; 654e6232409Smrg -*|$object) 655e6232409Smrg ;; 656e6232409Smrg *) 657e6232409Smrg set fnord "$@" "$arg"; shift ;; 658e6232409Smrg esac 659e6232409Smrg done 6608fff3f40Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661e6232409Smrg touch "$tmpdepfile" 662e6232409Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663e6232409Smrg rm -f "$depfile" 66494a251fdSmrg # makedepend may prepend the VPATH from the source file name to the object. 66594a251fdSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 66694a251fdSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6676a45684fSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6686a45684fSmrg # correctly. Breaking it into two sed invocations is a workaround. 6696a45684fSmrg sed '1,2d' "$tmpdepfile" \ 6706a45684fSmrg | tr ' ' "$nl" \ 6716a45684fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6726a45684fSmrg | sed -e 's/$/ :/' >> "$depfile" 673e6232409Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674e6232409Smrg ;; 675e6232409Smrg 676e6232409Smrgcpp) 677e6232409Smrg # Important note: in order to support this mode, a compiler *must* 678e6232409Smrg # always write the preprocessed file to stdout. 679e6232409Smrg "$@" || exit $? 680e6232409Smrg 681e6232409Smrg # Remove the call to Libtool. 682e6232409Smrg if test "$libtool" = yes; then 6838fff3f40Smrg while test "X$1" != 'X--mode=compile'; do 684e6232409Smrg shift 685e6232409Smrg done 686e6232409Smrg shift 687e6232409Smrg fi 688e6232409Smrg 6896a45684fSmrg # Remove '-o $object'. 690e6232409Smrg IFS=" " 691e6232409Smrg for arg 692e6232409Smrg do 693e6232409Smrg case $arg in 694e6232409Smrg -o) 695e6232409Smrg shift 696e6232409Smrg ;; 697e6232409Smrg $object) 698e6232409Smrg shift 699e6232409Smrg ;; 700e6232409Smrg *) 701e6232409Smrg set fnord "$@" "$arg" 702e6232409Smrg shift # fnord 703e6232409Smrg shift # $arg 704e6232409Smrg ;; 705e6232409Smrg esac 706e6232409Smrg done 707e6232409Smrg 7086a45684fSmrg "$@" -E \ 7096a45684fSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7106a45684fSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7116a45684fSmrg | sed '$ s: \\$::' > "$tmpdepfile" 712e6232409Smrg rm -f "$depfile" 713e6232409Smrg echo "$object : \\" > "$depfile" 714e6232409Smrg cat < "$tmpdepfile" >> "$depfile" 715e6232409Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716e6232409Smrg rm -f "$tmpdepfile" 717e6232409Smrg ;; 718e6232409Smrg 719e6232409Smrgmsvisualcpp) 720e6232409Smrg # Important note: in order to support this mode, a compiler *must* 7218fff3f40Smrg # always write the preprocessed file to stdout. 722e6232409Smrg "$@" || exit $? 7238fff3f40Smrg 7248fff3f40Smrg # Remove the call to Libtool. 7258fff3f40Smrg if test "$libtool" = yes; then 7268fff3f40Smrg while test "X$1" != 'X--mode=compile'; do 7278fff3f40Smrg shift 7288fff3f40Smrg done 7298fff3f40Smrg shift 7308fff3f40Smrg fi 7318fff3f40Smrg 732e6232409Smrg IFS=" " 733e6232409Smrg for arg 734e6232409Smrg do 735e6232409Smrg case "$arg" in 7368fff3f40Smrg -o) 7378fff3f40Smrg shift 7388fff3f40Smrg ;; 7398fff3f40Smrg $object) 7408fff3f40Smrg shift 7418fff3f40Smrg ;; 742e6232409Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7436a45684fSmrg set fnord "$@" 7446a45684fSmrg shift 7456a45684fSmrg shift 7466a45684fSmrg ;; 747e6232409Smrg *) 7486a45684fSmrg set fnord "$@" "$arg" 7496a45684fSmrg shift 7506a45684fSmrg shift 7516a45684fSmrg ;; 752e6232409Smrg esac 753e6232409Smrg done 7548fff3f40Smrg "$@" -E 2>/dev/null | 7558fff3f40Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756e6232409Smrg rm -f "$depfile" 757e6232409Smrg echo "$object : \\" > "$depfile" 7586a45684fSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7596a45684fSmrg echo "$tab" >> "$depfile" 7608fff3f40Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761e6232409Smrg rm -f "$tmpdepfile" 762e6232409Smrg ;; 763e6232409Smrg 7648fff3f40Smrgmsvcmsys) 7658fff3f40Smrg # This case exists only to let depend.m4 do its work. It works by 7668fff3f40Smrg # looking at the text of this script. This case will never be run, 7678fff3f40Smrg # since it is checked for above. 7688fff3f40Smrg exit 1 7698fff3f40Smrg ;; 7708fff3f40Smrg 771e6232409Smrgnone) 772e6232409Smrg exec "$@" 773e6232409Smrg ;; 774e6232409Smrg 775e6232409Smrg*) 776e6232409Smrg echo "Unknown depmode $depmode" 1>&2 777e6232409Smrg exit 1 778e6232409Smrg ;; 779e6232409Smrgesac 780e6232409Smrg 781e6232409Smrgexit 0 782e6232409Smrg 783e6232409Smrg# Local Variables: 784e6232409Smrg# mode: shell-script 785e6232409Smrg# sh-indentation: 2 7866d1874b2Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 787e6232409Smrg# time-stamp-start: "scriptversion=" 788e6232409Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7896d1874b2Smrg# time-stamp-time-zone: "UTC0" 7908fff3f40Smrg# time-stamp-end: "; # UTC" 791e6232409Smrg# End: 792