1af7c02bdSmrg#! /bin/sh 2af7c02bdSmrg# depcomp - compile a program generating dependencies as side-effects 3af7c02bdSmrg 46c9573adSmrgscriptversion=2018-03-07.03; # UTC 5af7c02bdSmrg 66c9573adSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7af7c02bdSmrg 8af7c02bdSmrg# This program is free software; you can redistribute it and/or modify 9af7c02bdSmrg# it under the terms of the GNU General Public License as published by 10af7c02bdSmrg# the Free Software Foundation; either version 2, or (at your option) 11af7c02bdSmrg# any later version. 12af7c02bdSmrg 13af7c02bdSmrg# This program is distributed in the hope that it will be useful, 14af7c02bdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15af7c02bdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16af7c02bdSmrg# GNU General Public License for more details. 17af7c02bdSmrg 18af7c02bdSmrg# You should have received a copy of the GNU General Public License 196c9573adSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20af7c02bdSmrg 21af7c02bdSmrg# As a special exception to the GNU General Public License, if you 22af7c02bdSmrg# distribute this file as part of a program that contains a 23af7c02bdSmrg# configuration script generated by Autoconf, you may include it under 24af7c02bdSmrg# the same distribution terms that you use for the rest of that program. 25af7c02bdSmrg 26af7c02bdSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27af7c02bdSmrg 28af7c02bdSmrgcase $1 in 29af7c02bdSmrg '') 306c9573adSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 316c9573adSmrg exit 1; 326c9573adSmrg ;; 33af7c02bdSmrg -h | --h*) 34af7c02bdSmrg cat <<\EOF 35af7c02bdSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36af7c02bdSmrg 37af7c02bdSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38af7c02bdSmrgas side-effects. 39af7c02bdSmrg 40af7c02bdSmrgEnvironment variables: 41af7c02bdSmrg depmode Dependency tracking mode. 426c9573adSmrg source Source file read by 'PROGRAMS ARGS'. 436c9573adSmrg object Object file output by 'PROGRAMS ARGS'. 44af7c02bdSmrg DEPDIR directory where to store dependencies. 45af7c02bdSmrg depfile Dependency file to output. 466dda92f9Smrg tmpdepfile Temporary file to use when outputting dependencies. 47af7c02bdSmrg libtool Whether libtool is used (yes/no). 48af7c02bdSmrg 49af7c02bdSmrgReport bugs to <bug-automake@gnu.org>. 50af7c02bdSmrgEOF 51af7c02bdSmrg exit $? 52af7c02bdSmrg ;; 53af7c02bdSmrg -v | --v*) 54af7c02bdSmrg echo "depcomp $scriptversion" 55af7c02bdSmrg exit $? 56af7c02bdSmrg ;; 57af7c02bdSmrgesac 58af7c02bdSmrg 596c9573adSmrg# Get the directory component of the given path, and save it in the 606c9573adSmrg# global variables '$dir'. Note that this directory component will 616c9573adSmrg# be either empty or ending with a '/' character. This is deliberate. 626c9573adSmrgset_dir_from () 636c9573adSmrg{ 646c9573adSmrg case $1 in 656c9573adSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 666c9573adSmrg *) dir=;; 676c9573adSmrg esac 686c9573adSmrg} 696c9573adSmrg 706c9573adSmrg# Get the suffix-stripped basename of the given path, and save it the 716c9573adSmrg# global variable '$base'. 726c9573adSmrgset_base_from () 736c9573adSmrg{ 746c9573adSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 756c9573adSmrg} 766c9573adSmrg 776c9573adSmrg# If no dependency file was actually created by the compiler invocation, 786c9573adSmrg# we still have to create a dummy depfile, to avoid errors with the 796c9573adSmrg# Makefile "include basename.Plo" scheme. 806c9573adSmrgmake_dummy_depfile () 816c9573adSmrg{ 826c9573adSmrg echo "#dummy" > "$depfile" 836c9573adSmrg} 846c9573adSmrg 856c9573adSmrg# Factor out some common post-processing of the generated depfile. 866c9573adSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 876c9573adSmrgaix_post_process_depfile () 886c9573adSmrg{ 896c9573adSmrg # If the compiler actually managed to produce a dependency file, 906c9573adSmrg # post-process it. 916c9573adSmrg if test -f "$tmpdepfile"; then 926c9573adSmrg # Each line is of the form 'foo.o: dependency.h'. 936c9573adSmrg # Do two passes, one to just change these to 946c9573adSmrg # $object: dependency.h 956c9573adSmrg # and one to simply output 966c9573adSmrg # dependency.h: 976c9573adSmrg # which is needed to avoid the deleted-header problem. 986c9573adSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 996c9573adSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1006c9573adSmrg } > "$depfile" 1016c9573adSmrg rm -f "$tmpdepfile" 1026c9573adSmrg else 1036c9573adSmrg make_dummy_depfile 1046c9573adSmrg fi 1056c9573adSmrg} 1066c9573adSmrg 1076c9573adSmrg# A tabulation character. 1086c9573adSmrgtab=' ' 1096c9573adSmrg# A newline character. 1106c9573adSmrgnl=' 1116c9573adSmrg' 1126c9573adSmrg# Character ranges might be problematic outside the C locale. 1136c9573adSmrg# These definitions help. 1146c9573adSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1156c9573adSmrglower=abcdefghijklmnopqrstuvwxyz 1166c9573adSmrgdigits=0123456789 1176c9573adSmrgalpha=${upper}${lower} 1186c9573adSmrg 119af7c02bdSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120af7c02bdSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121af7c02bdSmrg exit 1 122af7c02bdSmrgfi 123af7c02bdSmrg 124af7c02bdSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125af7c02bdSmrgdepfile=${depfile-`echo "$object" | 126af7c02bdSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127af7c02bdSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128af7c02bdSmrg 129af7c02bdSmrgrm -f "$tmpdepfile" 130af7c02bdSmrg 1316c9573adSmrg# Avoid interferences from the environment. 1326c9573adSmrggccflag= dashmflag= 1336c9573adSmrg 134af7c02bdSmrg# Some modes work just like other modes, but use different flags. We 135af7c02bdSmrg# parameterize here, but still list the modes in the big case below, 136af7c02bdSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137af7c02bdSmrg# here, because this file can only contain one case statement. 138af7c02bdSmrgif test "$depmode" = hp; then 139af7c02bdSmrg # HP compiler uses -M and no extra arg. 140af7c02bdSmrg gccflag=-M 141af7c02bdSmrg depmode=gcc 142af7c02bdSmrgfi 143af7c02bdSmrg 144af7c02bdSmrgif test "$depmode" = dashXmstdout; then 1456c9573adSmrg # This is just like dashmstdout with a different argument. 1466c9573adSmrg dashmflag=-xM 1476c9573adSmrg depmode=dashmstdout 148af7c02bdSmrgfi 149af7c02bdSmrg 15081c81b28Smrgcygpath_u="cygpath -u -f -" 15181c81b28Smrgif test "$depmode" = msvcmsys; then 1526c9573adSmrg # This is just like msvisualcpp but w/o cygpath translation. 1536c9573adSmrg # Just convert the backslash-escaped backslashes to single forward 1546c9573adSmrg # slashes to satisfy depend.m4 1556c9573adSmrg cygpath_u='sed s,\\\\,/,g' 1566c9573adSmrg depmode=msvisualcpp 15781c81b28Smrgfi 15881c81b28Smrg 1596dda92f9Smrgif test "$depmode" = msvc7msys; then 1606c9573adSmrg # This is just like msvc7 but w/o cygpath translation. 1616c9573adSmrg # Just convert the backslash-escaped backslashes to single forward 1626c9573adSmrg # slashes to satisfy depend.m4 1636c9573adSmrg cygpath_u='sed s,\\\\,/,g' 1646c9573adSmrg depmode=msvc7 1656c9573adSmrgfi 1666c9573adSmrg 1676c9573adSmrgif test "$depmode" = xlc; then 1686c9573adSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1696c9573adSmrg gccflag=-qmakedep=gcc,-MF 1706c9573adSmrg depmode=gcc 1716dda92f9Smrgfi 1726dda92f9Smrg 173af7c02bdSmrgcase "$depmode" in 174af7c02bdSmrggcc3) 175af7c02bdSmrg## gcc 3 implements dependency tracking that does exactly what 176af7c02bdSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177af7c02bdSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 17881c81b28Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 17981c81b28Smrg## the command line argument order; so add the flags where they 18081c81b28Smrg## appear in depend2.am. Note that the slowdown incurred here 18181c81b28Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 18281c81b28Smrg for arg 18381c81b28Smrg do 18481c81b28Smrg case $arg in 18581c81b28Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 18681c81b28Smrg *) set fnord "$@" "$arg" ;; 18781c81b28Smrg esac 18881c81b28Smrg shift # fnord 18981c81b28Smrg shift # $arg 19081c81b28Smrg done 19181c81b28Smrg "$@" 192af7c02bdSmrg stat=$? 1936c9573adSmrg if test $stat -ne 0; then 194af7c02bdSmrg rm -f "$tmpdepfile" 195af7c02bdSmrg exit $stat 196af7c02bdSmrg fi 197af7c02bdSmrg mv "$tmpdepfile" "$depfile" 198af7c02bdSmrg ;; 199af7c02bdSmrg 200af7c02bdSmrggcc) 2016c9573adSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2026c9573adSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2036c9573adSmrg## (see the conditional assignment to $gccflag above). 204af7c02bdSmrg## There are various ways to get dependency output from gcc. Here's 205af7c02bdSmrg## why we pick this rather obscure method: 206af7c02bdSmrg## - Don't want to use -MD because we'd like the dependencies to end 207af7c02bdSmrg## up in a subdir. Having to rename by hand is ugly. 208af7c02bdSmrg## (We might end up doing this anyway to support other compilers.) 209af7c02bdSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2106c9573adSmrg## -MM, not -M (despite what the docs say). Also, it might not be 2116c9573adSmrg## supported by the other compilers which use the 'gcc' depmode. 212af7c02bdSmrg## - Using -M directly means running the compiler twice (even worse 213af7c02bdSmrg## than renaming). 214af7c02bdSmrg if test -z "$gccflag"; then 215af7c02bdSmrg gccflag=-MD, 216af7c02bdSmrg fi 217af7c02bdSmrg "$@" -Wp,"$gccflag$tmpdepfile" 218af7c02bdSmrg stat=$? 2196c9573adSmrg if test $stat -ne 0; then 220af7c02bdSmrg rm -f "$tmpdepfile" 221af7c02bdSmrg exit $stat 222af7c02bdSmrg fi 223af7c02bdSmrg rm -f "$depfile" 224af7c02bdSmrg echo "$object : \\" > "$depfile" 2256c9573adSmrg # The second -e expression handles DOS-style file names with drive 2266c9573adSmrg # letters. 227af7c02bdSmrg sed -e 's/^[^:]*: / /' \ 228af7c02bdSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2296c9573adSmrg## This next piece of magic avoids the "deleted header file" problem. 230af7c02bdSmrg## The problem is that when a header file which appears in a .P file 231af7c02bdSmrg## is deleted, the dependency causes make to die (because there is 232af7c02bdSmrg## typically no way to rebuild the header). We avoid this by adding 233af7c02bdSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 234af7c02bdSmrg## this for us directly. 2356c9573adSmrg## Some versions of gcc put a space before the ':'. On the theory 236af7c02bdSmrg## that the space means something, we add a space to the output as 2376dda92f9Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 2386dda92f9Smrg## to the object. Take care to not repeat it in the output. 239af7c02bdSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 240af7c02bdSmrg## correctly. Breaking it into two sed invocations is a workaround. 2416c9573adSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2426c9573adSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2436c9573adSmrg | sed -e 's/$/ :/' >> "$depfile" 244af7c02bdSmrg rm -f "$tmpdepfile" 245af7c02bdSmrg ;; 246af7c02bdSmrg 247af7c02bdSmrghp) 248af7c02bdSmrg # This case exists only to let depend.m4 do its work. It works by 249af7c02bdSmrg # looking at the text of this script. This case will never be run, 250af7c02bdSmrg # since it is checked for above. 251af7c02bdSmrg exit 1 252af7c02bdSmrg ;; 253af7c02bdSmrg 254af7c02bdSmrgsgi) 255af7c02bdSmrg if test "$libtool" = yes; then 256af7c02bdSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257af7c02bdSmrg else 258af7c02bdSmrg "$@" -MDupdate "$tmpdepfile" 259af7c02bdSmrg fi 260af7c02bdSmrg stat=$? 2616c9573adSmrg if test $stat -ne 0; then 262af7c02bdSmrg rm -f "$tmpdepfile" 263af7c02bdSmrg exit $stat 264af7c02bdSmrg fi 265af7c02bdSmrg rm -f "$depfile" 266af7c02bdSmrg 267af7c02bdSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268af7c02bdSmrg echo "$object : \\" > "$depfile" 269af7c02bdSmrg # Clip off the initial element (the dependent). Don't try to be 270af7c02bdSmrg # clever and replace this with sed code, as IRIX sed won't handle 271af7c02bdSmrg # lines with more than a fixed number of characters (4096 in 272af7c02bdSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2736c9573adSmrg # the IRIX cc adds comments like '#:fec' to the end of the 274af7c02bdSmrg # dependency line. 2756c9573adSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2766c9573adSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2776c9573adSmrg | tr "$nl" ' ' >> "$depfile" 27881c81b28Smrg echo >> "$depfile" 279af7c02bdSmrg # The second pass generates a dummy entry for each header file. 2806c9573adSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2816c9573adSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2826c9573adSmrg >> "$depfile" 283af7c02bdSmrg else 2846c9573adSmrg make_dummy_depfile 285af7c02bdSmrg fi 286af7c02bdSmrg rm -f "$tmpdepfile" 287af7c02bdSmrg ;; 288af7c02bdSmrg 2896c9573adSmrgxlc) 2906c9573adSmrg # This case exists only to let depend.m4 do its work. It works by 2916c9573adSmrg # looking at the text of this script. This case will never be run, 2926c9573adSmrg # since it is checked for above. 2936c9573adSmrg exit 1 2946c9573adSmrg ;; 2956c9573adSmrg 296af7c02bdSmrgaix) 297af7c02bdSmrg # The C for AIX Compiler uses -M and outputs the dependencies 298af7c02bdSmrg # in a .u file. In older versions, this file always lives in the 2996c9573adSmrg # current directory. Also, the AIX compiler puts '$object:' at the 300af7c02bdSmrg # start of each line; $object doesn't have directory information. 301af7c02bdSmrg # Version 6 uses the directory in both cases. 3026c9573adSmrg set_dir_from "$object" 3036c9573adSmrg set_base_from "$object" 304af7c02bdSmrg if test "$libtool" = yes; then 30581c81b28Smrg tmpdepfile1=$dir$base.u 30681c81b28Smrg tmpdepfile2=$base.u 30781c81b28Smrg tmpdepfile3=$dir.libs/$base.u 308af7c02bdSmrg "$@" -Wc,-M 309af7c02bdSmrg else 31081c81b28Smrg tmpdepfile1=$dir$base.u 31181c81b28Smrg tmpdepfile2=$dir$base.u 31281c81b28Smrg tmpdepfile3=$dir$base.u 313af7c02bdSmrg "$@" -M 314af7c02bdSmrg fi 315af7c02bdSmrg stat=$? 3166c9573adSmrg if test $stat -ne 0; then 31781c81b28Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318af7c02bdSmrg exit $stat 319af7c02bdSmrg fi 320af7c02bdSmrg 32181c81b28Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32281c81b28Smrg do 32381c81b28Smrg test -f "$tmpdepfile" && break 32481c81b28Smrg done 3256c9573adSmrg aix_post_process_depfile 3266c9573adSmrg ;; 3276c9573adSmrg 3286c9573adSmrgtcc) 3296c9573adSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3306c9573adSmrg # FIXME: That version still under development at the moment of writing. 3316c9573adSmrg # Make that this statement remains true also for stable, released 3326c9573adSmrg # versions. 3336c9573adSmrg # It will wrap lines (doesn't matter whether long or short) with a 3346c9573adSmrg # trailing '\', as in: 3356c9573adSmrg # 3366c9573adSmrg # foo.o : \ 3376c9573adSmrg # foo.c \ 3386c9573adSmrg # foo.h \ 3396c9573adSmrg # 3406c9573adSmrg # It will put a trailing '\' even on the last line, and will use leading 3416c9573adSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 3426c9573adSmrg # "Emit spaces for -MD"). 3436c9573adSmrg "$@" -MD -MF "$tmpdepfile" 3446c9573adSmrg stat=$? 3456c9573adSmrg if test $stat -ne 0; then 3466c9573adSmrg rm -f "$tmpdepfile" 3476c9573adSmrg exit $stat 348af7c02bdSmrg fi 3496c9573adSmrg rm -f "$depfile" 3506c9573adSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3516c9573adSmrg # We have to change lines of the first kind to '$object: \'. 3526c9573adSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3536c9573adSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 3546c9573adSmrg # dummy dependency, to avoid the deleted-header problem. 3556c9573adSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356af7c02bdSmrg rm -f "$tmpdepfile" 357af7c02bdSmrg ;; 358af7c02bdSmrg 3596c9573adSmrg## The order of this option in the case statement is important, since the 3606c9573adSmrg## shell code in configure will try each of these formats in the order 3616c9573adSmrg## listed in this file. A plain '-MD' option would be understood by many 3626c9573adSmrg## compilers, so we must ensure this comes after the gcc and icc options. 3636c9573adSmrgpgcc) 3646c9573adSmrg # Portland's C compiler understands '-MD'. 3656c9573adSmrg # Will always output deps to 'file.d' where file is the root name of the 3666c9573adSmrg # source file under compilation, even if file resides in a subdirectory. 3676c9573adSmrg # The object file name does not affect the name of the '.d' file. 3686c9573adSmrg # pgcc 10.2 will output 369af7c02bdSmrg # foo.o: sub/foo.c sub/foo.h 3706c9573adSmrg # and will wrap long lines using '\' : 371af7c02bdSmrg # foo.o: sub/foo.c ... \ 372af7c02bdSmrg # sub/foo.h ... \ 373af7c02bdSmrg # ... 3746c9573adSmrg set_dir_from "$object" 3756c9573adSmrg # Use the source, not the object, to determine the base name, since 3766c9573adSmrg # that's sadly what pgcc will do too. 3776c9573adSmrg set_base_from "$source" 3786c9573adSmrg tmpdepfile=$base.d 3796c9573adSmrg 3806c9573adSmrg # For projects that build the same source file twice into different object 3816c9573adSmrg # files, the pgcc approach of using the *source* file root name can cause 3826c9573adSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3836c9573adSmrg # the same $tmpdepfile. 3846c9573adSmrg lockdir=$base.d-lock 3856c9573adSmrg trap " 3866c9573adSmrg echo '$0: caught signal, cleaning up...' >&2 3876c9573adSmrg rmdir '$lockdir' 3886c9573adSmrg exit 1 3896c9573adSmrg " 1 2 13 15 3906c9573adSmrg numtries=100 3916c9573adSmrg i=$numtries 3926c9573adSmrg while test $i -gt 0; do 3936c9573adSmrg # mkdir is a portable test-and-set. 3946c9573adSmrg if mkdir "$lockdir" 2>/dev/null; then 3956c9573adSmrg # This process acquired the lock. 3966c9573adSmrg "$@" -MD 3976c9573adSmrg stat=$? 3986c9573adSmrg # Release the lock. 3996c9573adSmrg rmdir "$lockdir" 4006c9573adSmrg break 4016c9573adSmrg else 4026c9573adSmrg # If the lock is being held by a different process, wait 4036c9573adSmrg # until the winning process is done or we timeout. 4046c9573adSmrg while test -d "$lockdir" && test $i -gt 0; do 4056c9573adSmrg sleep 1 4066c9573adSmrg i=`expr $i - 1` 4076c9573adSmrg done 4086c9573adSmrg fi 4096c9573adSmrg i=`expr $i - 1` 4106c9573adSmrg done 4116c9573adSmrg trap - 1 2 13 15 4126c9573adSmrg if test $i -le 0; then 4136c9573adSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4146c9573adSmrg echo "$0: check lockdir '$lockdir'" >&2 4156c9573adSmrg exit 1 4166c9573adSmrg fi 417af7c02bdSmrg 4186c9573adSmrg if test $stat -ne 0; then 419af7c02bdSmrg rm -f "$tmpdepfile" 420af7c02bdSmrg exit $stat 421af7c02bdSmrg fi 422af7c02bdSmrg rm -f "$depfile" 423af7c02bdSmrg # Each line is of the form `foo.o: dependent.h', 424af7c02bdSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425af7c02bdSmrg # Do two passes, one to just change these to 426af7c02bdSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427af7c02bdSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428af7c02bdSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429af7c02bdSmrg # correctly. Breaking it into two sed invocations is a workaround. 4306c9573adSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4316c9573adSmrg | sed -e 's/$/ :/' >> "$depfile" 432af7c02bdSmrg rm -f "$tmpdepfile" 433af7c02bdSmrg ;; 434af7c02bdSmrg 43581c81b28Smrghp2) 43681c81b28Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 43781c81b28Smrg # compilers, which have integrated preprocessors. The correct option 43881c81b28Smrg # to use with these is +Maked; it writes dependencies to a file named 43981c81b28Smrg # 'foo.d', which lands next to the object file, wherever that 44081c81b28Smrg # happens to be. 44181c81b28Smrg # Much of this is similar to the tru64 case; see comments there. 4426c9573adSmrg set_dir_from "$object" 4436c9573adSmrg set_base_from "$object" 44481c81b28Smrg if test "$libtool" = yes; then 44581c81b28Smrg tmpdepfile1=$dir$base.d 44681c81b28Smrg tmpdepfile2=$dir.libs/$base.d 44781c81b28Smrg "$@" -Wc,+Maked 44881c81b28Smrg else 44981c81b28Smrg tmpdepfile1=$dir$base.d 45081c81b28Smrg tmpdepfile2=$dir$base.d 45181c81b28Smrg "$@" +Maked 45281c81b28Smrg fi 45381c81b28Smrg stat=$? 4546c9573adSmrg if test $stat -ne 0; then 45581c81b28Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 45681c81b28Smrg exit $stat 45781c81b28Smrg fi 45881c81b28Smrg 45981c81b28Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 46081c81b28Smrg do 46181c81b28Smrg test -f "$tmpdepfile" && break 46281c81b28Smrg done 46381c81b28Smrg if test -f "$tmpdepfile"; then 4646c9573adSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4656c9573adSmrg # Add 'dependent.h:' lines. 46681c81b28Smrg sed -ne '2,${ 4676c9573adSmrg s/^ *// 4686c9573adSmrg s/ \\*$// 4696c9573adSmrg s/$/:/ 4706c9573adSmrg p 4716c9573adSmrg }' "$tmpdepfile" >> "$depfile" 47281c81b28Smrg else 4736c9573adSmrg make_dummy_depfile 47481c81b28Smrg fi 47581c81b28Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 47681c81b28Smrg ;; 47781c81b28Smrg 478af7c02bdSmrgtru64) 4796c9573adSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 4806c9573adSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4816c9573adSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4826c9573adSmrg # dependencies in 'foo.d' instead, so we check for that too. 4836c9573adSmrg # Subdirectories are respected. 4846c9573adSmrg set_dir_from "$object" 4856c9573adSmrg set_base_from "$object" 4866c9573adSmrg 4876c9573adSmrg if test "$libtool" = yes; then 4886c9573adSmrg # Libtool generates 2 separate objects for the 2 libraries. These 4896c9573adSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 4906c9573adSmrg # in $dir$base.o.d. We have to check for both files, because 4916c9573adSmrg # one of the two compilations can be disabled. We should prefer 4926c9573adSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4936c9573adSmrg # automatically cleaned when .libs/ is deleted, while ignoring 4946c9573adSmrg # the former would cause a distcleancheck panic. 4956c9573adSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4966c9573adSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4976c9573adSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4986c9573adSmrg "$@" -Wc,-MD 4996c9573adSmrg else 5006c9573adSmrg tmpdepfile1=$dir$base.d 5016c9573adSmrg tmpdepfile2=$dir$base.d 5026c9573adSmrg tmpdepfile3=$dir$base.d 5036c9573adSmrg "$@" -MD 5046c9573adSmrg fi 5056c9573adSmrg 5066c9573adSmrg stat=$? 5076c9573adSmrg if test $stat -ne 0; then 5086c9573adSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5096c9573adSmrg exit $stat 5106c9573adSmrg fi 5116c9573adSmrg 5126c9573adSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5136c9573adSmrg do 5146c9573adSmrg test -f "$tmpdepfile" && break 5156c9573adSmrg done 5166c9573adSmrg # Same post-processing that is required for AIX mode. 5176c9573adSmrg aix_post_process_depfile 5186c9573adSmrg ;; 519af7c02bdSmrg 5206dda92f9Smrgmsvc7) 5216dda92f9Smrg if test "$libtool" = yes; then 5226dda92f9Smrg showIncludes=-Wc,-showIncludes 5236dda92f9Smrg else 5246dda92f9Smrg showIncludes=-showIncludes 5256dda92f9Smrg fi 5266dda92f9Smrg "$@" $showIncludes > "$tmpdepfile" 5276dda92f9Smrg stat=$? 5286dda92f9Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5296c9573adSmrg if test $stat -ne 0; then 5306dda92f9Smrg rm -f "$tmpdepfile" 5316dda92f9Smrg exit $stat 5326dda92f9Smrg fi 5336dda92f9Smrg rm -f "$depfile" 5346dda92f9Smrg echo "$object : \\" > "$depfile" 5356dda92f9Smrg # The first sed program below extracts the file names and escapes 5366dda92f9Smrg # backslashes for cygpath. The second sed program outputs the file 5376dda92f9Smrg # name when reading, but also accumulates all include files in the 5386dda92f9Smrg # hold buffer in order to output them again at the end. This only 5396dda92f9Smrg # works with sed implementations that can handle large buffers. 5406dda92f9Smrg sed < "$tmpdepfile" -n ' 5416dda92f9Smrg/^Note: including file: *\(.*\)/ { 5426dda92f9Smrg s//\1/ 5436dda92f9Smrg s/\\/\\\\/g 5446dda92f9Smrg p 5456dda92f9Smrg}' | $cygpath_u | sort -u | sed -n ' 5466dda92f9Smrgs/ /\\ /g 5476c9573adSmrgs/\(.*\)/'"$tab"'\1 \\/p 5486dda92f9Smrgs/.\(.*\) \\/\1:/ 5496dda92f9SmrgH 5506dda92f9Smrg$ { 5516c9573adSmrg s/.*/'"$tab"'/ 5526dda92f9Smrg G 5536dda92f9Smrg p 5546dda92f9Smrg}' >> "$depfile" 5556c9573adSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5566dda92f9Smrg rm -f "$tmpdepfile" 5576dda92f9Smrg ;; 5586dda92f9Smrg 5596dda92f9Smrgmsvc7msys) 5606dda92f9Smrg # This case exists only to let depend.m4 do its work. It works by 5616dda92f9Smrg # looking at the text of this script. This case will never be run, 5626dda92f9Smrg # since it is checked for above. 5636dda92f9Smrg exit 1 5646dda92f9Smrg ;; 5656dda92f9Smrg 566af7c02bdSmrg#nosideeffect) 567af7c02bdSmrg # This comment above is used by automake to tell side-effect 568af7c02bdSmrg # dependency tracking mechanisms from slower ones. 569af7c02bdSmrg 570af7c02bdSmrgdashmstdout) 571af7c02bdSmrg # Important note: in order to support this mode, a compiler *must* 572af7c02bdSmrg # always write the preprocessed file to stdout, regardless of -o. 573af7c02bdSmrg "$@" || exit $? 574af7c02bdSmrg 575af7c02bdSmrg # Remove the call to Libtool. 576af7c02bdSmrg if test "$libtool" = yes; then 57781c81b28Smrg while test "X$1" != 'X--mode=compile'; do 578af7c02bdSmrg shift 579af7c02bdSmrg done 580af7c02bdSmrg shift 581af7c02bdSmrg fi 582af7c02bdSmrg 5836c9573adSmrg # Remove '-o $object'. 584af7c02bdSmrg IFS=" " 585af7c02bdSmrg for arg 586af7c02bdSmrg do 587af7c02bdSmrg case $arg in 588af7c02bdSmrg -o) 589af7c02bdSmrg shift 590af7c02bdSmrg ;; 591af7c02bdSmrg $object) 592af7c02bdSmrg shift 593af7c02bdSmrg ;; 594af7c02bdSmrg *) 595af7c02bdSmrg set fnord "$@" "$arg" 596af7c02bdSmrg shift # fnord 597af7c02bdSmrg shift # $arg 598af7c02bdSmrg ;; 599af7c02bdSmrg esac 600af7c02bdSmrg done 601af7c02bdSmrg 602af7c02bdSmrg test -z "$dashmflag" && dashmflag=-M 6036c9573adSmrg # Require at least two characters before searching for ':' 604af7c02bdSmrg # in the target name. This is to cope with DOS-style filenames: 6056c9573adSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606af7c02bdSmrg "$@" $dashmflag | 6076c9573adSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608af7c02bdSmrg rm -f "$depfile" 609af7c02bdSmrg cat < "$tmpdepfile" > "$depfile" 6106c9573adSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6116c9573adSmrg # correctly. Breaking it into two sed invocations is a workaround. 6126c9573adSmrg tr ' ' "$nl" < "$tmpdepfile" \ 6136c9573adSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6146c9573adSmrg | sed -e 's/$/ :/' >> "$depfile" 615af7c02bdSmrg rm -f "$tmpdepfile" 616af7c02bdSmrg ;; 617af7c02bdSmrg 618af7c02bdSmrgdashXmstdout) 619af7c02bdSmrg # This case only exists to satisfy depend.m4. It is never actually 620af7c02bdSmrg # run, as this mode is specially recognized in the preamble. 621af7c02bdSmrg exit 1 622af7c02bdSmrg ;; 623af7c02bdSmrg 624af7c02bdSmrgmakedepend) 625af7c02bdSmrg "$@" || exit $? 626af7c02bdSmrg # Remove any Libtool call 627af7c02bdSmrg if test "$libtool" = yes; then 62881c81b28Smrg while test "X$1" != 'X--mode=compile'; do 629af7c02bdSmrg shift 630af7c02bdSmrg done 631af7c02bdSmrg shift 632af7c02bdSmrg fi 633af7c02bdSmrg # X makedepend 634af7c02bdSmrg shift 63581c81b28Smrg cleared=no eat=no 63681c81b28Smrg for arg 63781c81b28Smrg do 638af7c02bdSmrg case $cleared in 639af7c02bdSmrg no) 640af7c02bdSmrg set ""; shift 641af7c02bdSmrg cleared=yes ;; 642af7c02bdSmrg esac 64381c81b28Smrg if test $eat = yes; then 64481c81b28Smrg eat=no 64581c81b28Smrg continue 64681c81b28Smrg fi 647af7c02bdSmrg case "$arg" in 648af7c02bdSmrg -D*|-I*) 649af7c02bdSmrg set fnord "$@" "$arg"; shift ;; 650af7c02bdSmrg # Strip any option that makedepend may not understand. Remove 651af7c02bdSmrg # the object too, otherwise makedepend will parse it as a source file. 65281c81b28Smrg -arch) 65381c81b28Smrg eat=yes ;; 654af7c02bdSmrg -*|$object) 655af7c02bdSmrg ;; 656af7c02bdSmrg *) 657af7c02bdSmrg set fnord "$@" "$arg"; shift ;; 658af7c02bdSmrg esac 659af7c02bdSmrg done 66081c81b28Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661af7c02bdSmrg touch "$tmpdepfile" 662af7c02bdSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663af7c02bdSmrg rm -f "$depfile" 6646dda92f9Smrg # makedepend may prepend the VPATH from the source file name to the object. 6656dda92f9Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 6666dda92f9Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6676c9573adSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6686c9573adSmrg # correctly. Breaking it into two sed invocations is a workaround. 6696c9573adSmrg sed '1,2d' "$tmpdepfile" \ 6706c9573adSmrg | tr ' ' "$nl" \ 6716c9573adSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6726c9573adSmrg | sed -e 's/$/ :/' >> "$depfile" 673af7c02bdSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674af7c02bdSmrg ;; 675af7c02bdSmrg 676af7c02bdSmrgcpp) 677af7c02bdSmrg # Important note: in order to support this mode, a compiler *must* 678af7c02bdSmrg # always write the preprocessed file to stdout. 679af7c02bdSmrg "$@" || exit $? 680af7c02bdSmrg 681af7c02bdSmrg # Remove the call to Libtool. 682af7c02bdSmrg if test "$libtool" = yes; then 68381c81b28Smrg while test "X$1" != 'X--mode=compile'; do 684af7c02bdSmrg shift 685af7c02bdSmrg done 686af7c02bdSmrg shift 687af7c02bdSmrg fi 688af7c02bdSmrg 6896c9573adSmrg # Remove '-o $object'. 690af7c02bdSmrg IFS=" " 691af7c02bdSmrg for arg 692af7c02bdSmrg do 693af7c02bdSmrg case $arg in 694af7c02bdSmrg -o) 695af7c02bdSmrg shift 696af7c02bdSmrg ;; 697af7c02bdSmrg $object) 698af7c02bdSmrg shift 699af7c02bdSmrg ;; 700af7c02bdSmrg *) 701af7c02bdSmrg set fnord "$@" "$arg" 702af7c02bdSmrg shift # fnord 703af7c02bdSmrg shift # $arg 704af7c02bdSmrg ;; 705af7c02bdSmrg esac 706af7c02bdSmrg done 707af7c02bdSmrg 7086c9573adSmrg "$@" -E \ 7096c9573adSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7106c9573adSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7116c9573adSmrg | sed '$ s: \\$::' > "$tmpdepfile" 712af7c02bdSmrg rm -f "$depfile" 713af7c02bdSmrg echo "$object : \\" > "$depfile" 714af7c02bdSmrg cat < "$tmpdepfile" >> "$depfile" 715af7c02bdSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716af7c02bdSmrg rm -f "$tmpdepfile" 717af7c02bdSmrg ;; 718af7c02bdSmrg 719af7c02bdSmrgmsvisualcpp) 720af7c02bdSmrg # Important note: in order to support this mode, a compiler *must* 72181c81b28Smrg # always write the preprocessed file to stdout. 722af7c02bdSmrg "$@" || exit $? 72381c81b28Smrg 72481c81b28Smrg # Remove the call to Libtool. 72581c81b28Smrg if test "$libtool" = yes; then 72681c81b28Smrg while test "X$1" != 'X--mode=compile'; do 72781c81b28Smrg shift 72881c81b28Smrg done 72981c81b28Smrg shift 73081c81b28Smrg fi 73181c81b28Smrg 732af7c02bdSmrg IFS=" " 733af7c02bdSmrg for arg 734af7c02bdSmrg do 735af7c02bdSmrg case "$arg" in 73681c81b28Smrg -o) 73781c81b28Smrg shift 73881c81b28Smrg ;; 73981c81b28Smrg $object) 74081c81b28Smrg shift 74181c81b28Smrg ;; 742af7c02bdSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7436c9573adSmrg set fnord "$@" 7446c9573adSmrg shift 7456c9573adSmrg shift 7466c9573adSmrg ;; 747af7c02bdSmrg *) 7486c9573adSmrg set fnord "$@" "$arg" 7496c9573adSmrg shift 7506c9573adSmrg shift 7516c9573adSmrg ;; 752af7c02bdSmrg esac 753af7c02bdSmrg done 75481c81b28Smrg "$@" -E 2>/dev/null | 75581c81b28Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756af7c02bdSmrg rm -f "$depfile" 757af7c02bdSmrg echo "$object : \\" > "$depfile" 7586c9573adSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7596c9573adSmrg echo "$tab" >> "$depfile" 76081c81b28Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761af7c02bdSmrg rm -f "$tmpdepfile" 762af7c02bdSmrg ;; 763af7c02bdSmrg 76481c81b28Smrgmsvcmsys) 76581c81b28Smrg # This case exists only to let depend.m4 do its work. It works by 76681c81b28Smrg # looking at the text of this script. This case will never be run, 76781c81b28Smrg # since it is checked for above. 76881c81b28Smrg exit 1 76981c81b28Smrg ;; 77081c81b28Smrg 771af7c02bdSmrgnone) 772af7c02bdSmrg exec "$@" 773af7c02bdSmrg ;; 774af7c02bdSmrg 775af7c02bdSmrg*) 776af7c02bdSmrg echo "Unknown depmode $depmode" 1>&2 777af7c02bdSmrg exit 1 778af7c02bdSmrg ;; 779af7c02bdSmrgesac 780af7c02bdSmrg 781af7c02bdSmrgexit 0 782af7c02bdSmrg 783af7c02bdSmrg# Local Variables: 784af7c02bdSmrg# mode: shell-script 785af7c02bdSmrg# sh-indentation: 2 7866c9573adSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 787af7c02bdSmrg# time-stamp-start: "scriptversion=" 788af7c02bdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7896c9573adSmrg# time-stamp-time-zone: "UTC0" 79081c81b28Smrg# time-stamp-end: "; # UTC" 791af7c02bdSmrg# End: 792