1943345d3Smrg#! /bin/sh 2943345d3Smrg# depcomp - compile a program generating dependencies as side-effects 3943345d3Smrg 415ffece8Smrgscriptversion=2018-03-07.03; # UTC 5943345d3Smrg 615ffece8Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7943345d3Smrg 8943345d3Smrg# This program is free software; you can redistribute it and/or modify 9943345d3Smrg# it under the terms of the GNU General Public License as published by 10943345d3Smrg# the Free Software Foundation; either version 2, or (at your option) 11943345d3Smrg# any later version. 12943345d3Smrg 13943345d3Smrg# This program is distributed in the hope that it will be useful, 14943345d3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15943345d3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16943345d3Smrg# GNU General Public License for more details. 17943345d3Smrg 18943345d3Smrg# You should have received a copy of the GNU General Public License 1915ffece8Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20943345d3Smrg 21943345d3Smrg# As a special exception to the GNU General Public License, if you 22943345d3Smrg# distribute this file as part of a program that contains a 23943345d3Smrg# configuration script generated by Autoconf, you may include it under 24943345d3Smrg# the same distribution terms that you use for the rest of that program. 25943345d3Smrg 26943345d3Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27943345d3Smrg 28943345d3Smrgcase $1 in 29943345d3Smrg '') 3015ffece8Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3115ffece8Smrg exit 1; 3215ffece8Smrg ;; 33943345d3Smrg -h | --h*) 34943345d3Smrg cat <<\EOF 35943345d3SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36943345d3Smrg 37943345d3SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38943345d3Smrgas side-effects. 39943345d3Smrg 40943345d3SmrgEnvironment variables: 41943345d3Smrg depmode Dependency tracking mode. 4215ffece8Smrg source Source file read by 'PROGRAMS ARGS'. 4315ffece8Smrg object Object file output by 'PROGRAMS ARGS'. 44943345d3Smrg DEPDIR directory where to store dependencies. 45943345d3Smrg depfile Dependency file to output. 463e51e026Smrg tmpdepfile Temporary file to use when outputting dependencies. 47943345d3Smrg libtool Whether libtool is used (yes/no). 48943345d3Smrg 49943345d3SmrgReport bugs to <bug-automake@gnu.org>. 50943345d3SmrgEOF 51943345d3Smrg exit $? 52943345d3Smrg ;; 53943345d3Smrg -v | --v*) 54943345d3Smrg echo "depcomp $scriptversion" 55943345d3Smrg exit $? 56943345d3Smrg ;; 57943345d3Smrgesac 58943345d3Smrg 5915ffece8Smrg# Get the directory component of the given path, and save it in the 6015ffece8Smrg# global variables '$dir'. Note that this directory component will 6115ffece8Smrg# be either empty or ending with a '/' character. This is deliberate. 6215ffece8Smrgset_dir_from () 6315ffece8Smrg{ 6415ffece8Smrg case $1 in 6515ffece8Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6615ffece8Smrg *) dir=;; 6715ffece8Smrg esac 6815ffece8Smrg} 6915ffece8Smrg 7015ffece8Smrg# Get the suffix-stripped basename of the given path, and save it the 7115ffece8Smrg# global variable '$base'. 7215ffece8Smrgset_base_from () 7315ffece8Smrg{ 7415ffece8Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7515ffece8Smrg} 7615ffece8Smrg 7715ffece8Smrg# If no dependency file was actually created by the compiler invocation, 7815ffece8Smrg# we still have to create a dummy depfile, to avoid errors with the 7915ffece8Smrg# Makefile "include basename.Plo" scheme. 8015ffece8Smrgmake_dummy_depfile () 8115ffece8Smrg{ 8215ffece8Smrg echo "#dummy" > "$depfile" 8315ffece8Smrg} 8415ffece8Smrg 8515ffece8Smrg# Factor out some common post-processing of the generated depfile. 8615ffece8Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8715ffece8Smrgaix_post_process_depfile () 8815ffece8Smrg{ 8915ffece8Smrg # If the compiler actually managed to produce a dependency file, 9015ffece8Smrg # post-process it. 9115ffece8Smrg if test -f "$tmpdepfile"; then 9215ffece8Smrg # Each line is of the form 'foo.o: dependency.h'. 9315ffece8Smrg # Do two passes, one to just change these to 9415ffece8Smrg # $object: dependency.h 9515ffece8Smrg # and one to simply output 9615ffece8Smrg # dependency.h: 9715ffece8Smrg # which is needed to avoid the deleted-header problem. 9815ffece8Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9915ffece8Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10015ffece8Smrg } > "$depfile" 10115ffece8Smrg rm -f "$tmpdepfile" 10215ffece8Smrg else 10315ffece8Smrg make_dummy_depfile 10415ffece8Smrg fi 10515ffece8Smrg} 10615ffece8Smrg 10715ffece8Smrg# A tabulation character. 10815ffece8Smrgtab=' ' 10915ffece8Smrg# A newline character. 11015ffece8Smrgnl=' 11115ffece8Smrg' 11215ffece8Smrg# Character ranges might be problematic outside the C locale. 11315ffece8Smrg# These definitions help. 11415ffece8Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11515ffece8Smrglower=abcdefghijklmnopqrstuvwxyz 11615ffece8Smrgdigits=0123456789 11715ffece8Smrgalpha=${upper}${lower} 11815ffece8Smrg 119943345d3Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120943345d3Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121943345d3Smrg exit 1 122943345d3Smrgfi 123943345d3Smrg 124943345d3Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125943345d3Smrgdepfile=${depfile-`echo "$object" | 126943345d3Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127943345d3Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128943345d3Smrg 129943345d3Smrgrm -f "$tmpdepfile" 130943345d3Smrg 13115ffece8Smrg# Avoid interferences from the environment. 13215ffece8Smrggccflag= dashmflag= 13315ffece8Smrg 134943345d3Smrg# Some modes work just like other modes, but use different flags. We 135943345d3Smrg# parameterize here, but still list the modes in the big case below, 136943345d3Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137943345d3Smrg# here, because this file can only contain one case statement. 138943345d3Smrgif test "$depmode" = hp; then 139943345d3Smrg # HP compiler uses -M and no extra arg. 140943345d3Smrg gccflag=-M 141943345d3Smrg depmode=gcc 142943345d3Smrgfi 143943345d3Smrg 144943345d3Smrgif test "$depmode" = dashXmstdout; then 14515ffece8Smrg # This is just like dashmstdout with a different argument. 14615ffece8Smrg dashmflag=-xM 14715ffece8Smrg depmode=dashmstdout 148943345d3Smrgfi 149943345d3Smrg 1505e695a52Smrgcygpath_u="cygpath -u -f -" 1515e695a52Smrgif test "$depmode" = msvcmsys; then 15215ffece8Smrg # This is just like msvisualcpp but w/o cygpath translation. 15315ffece8Smrg # Just convert the backslash-escaped backslashes to single forward 15415ffece8Smrg # slashes to satisfy depend.m4 15515ffece8Smrg cygpath_u='sed s,\\\\,/,g' 15615ffece8Smrg depmode=msvisualcpp 1575e695a52Smrgfi 1585e695a52Smrg 1593e51e026Smrgif test "$depmode" = msvc7msys; then 16015ffece8Smrg # This is just like msvc7 but w/o cygpath translation. 16115ffece8Smrg # Just convert the backslash-escaped backslashes to single forward 16215ffece8Smrg # slashes to satisfy depend.m4 16315ffece8Smrg cygpath_u='sed s,\\\\,/,g' 16415ffece8Smrg depmode=msvc7 16515ffece8Smrgfi 16615ffece8Smrg 16715ffece8Smrgif test "$depmode" = xlc; then 16815ffece8Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16915ffece8Smrg gccflag=-qmakedep=gcc,-MF 17015ffece8Smrg depmode=gcc 1713e51e026Smrgfi 1723e51e026Smrg 173943345d3Smrgcase "$depmode" in 174943345d3Smrggcc3) 175943345d3Smrg## gcc 3 implements dependency tracking that does exactly what 176943345d3Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177943345d3Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178f67b85aaSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179f67b85aaSmrg## the command line argument order; so add the flags where they 180f67b85aaSmrg## appear in depend2.am. Note that the slowdown incurred here 181f67b85aaSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182f67b85aaSmrg for arg 183f67b85aaSmrg do 184f67b85aaSmrg case $arg in 185f67b85aaSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186f67b85aaSmrg *) set fnord "$@" "$arg" ;; 187f67b85aaSmrg esac 188f67b85aaSmrg shift # fnord 189f67b85aaSmrg shift # $arg 190f67b85aaSmrg done 191f67b85aaSmrg "$@" 192943345d3Smrg stat=$? 19315ffece8Smrg if test $stat -ne 0; then 194943345d3Smrg rm -f "$tmpdepfile" 195943345d3Smrg exit $stat 196943345d3Smrg fi 197943345d3Smrg mv "$tmpdepfile" "$depfile" 198943345d3Smrg ;; 199943345d3Smrg 200943345d3Smrggcc) 20115ffece8Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20215ffece8Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20315ffece8Smrg## (see the conditional assignment to $gccflag above). 204943345d3Smrg## There are various ways to get dependency output from gcc. Here's 205943345d3Smrg## why we pick this rather obscure method: 206943345d3Smrg## - Don't want to use -MD because we'd like the dependencies to end 207943345d3Smrg## up in a subdir. Having to rename by hand is ugly. 208943345d3Smrg## (We might end up doing this anyway to support other compilers.) 209943345d3Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21015ffece8Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21115ffece8Smrg## supported by the other compilers which use the 'gcc' depmode. 212943345d3Smrg## - Using -M directly means running the compiler twice (even worse 213943345d3Smrg## than renaming). 214943345d3Smrg if test -z "$gccflag"; then 215943345d3Smrg gccflag=-MD, 216943345d3Smrg fi 217943345d3Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218943345d3Smrg stat=$? 21915ffece8Smrg if test $stat -ne 0; then 220943345d3Smrg rm -f "$tmpdepfile" 221943345d3Smrg exit $stat 222943345d3Smrg fi 223943345d3Smrg rm -f "$depfile" 224943345d3Smrg echo "$object : \\" > "$depfile" 22515ffece8Smrg # The second -e expression handles DOS-style file names with drive 22615ffece8Smrg # letters. 227943345d3Smrg sed -e 's/^[^:]*: / /' \ 228943345d3Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22915ffece8Smrg## This next piece of magic avoids the "deleted header file" problem. 230943345d3Smrg## The problem is that when a header file which appears in a .P file 231943345d3Smrg## is deleted, the dependency causes make to die (because there is 232943345d3Smrg## typically no way to rebuild the header). We avoid this by adding 233943345d3Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234943345d3Smrg## this for us directly. 23515ffece8Smrg## Some versions of gcc put a space before the ':'. On the theory 236943345d3Smrg## that the space means something, we add a space to the output as 2373e51e026Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 2383e51e026Smrg## to the object. Take care to not repeat it in the output. 239943345d3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240943345d3Smrg## correctly. Breaking it into two sed invocations is a workaround. 24115ffece8Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24215ffece8Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24315ffece8Smrg | sed -e 's/$/ :/' >> "$depfile" 244943345d3Smrg rm -f "$tmpdepfile" 245943345d3Smrg ;; 246943345d3Smrg 247943345d3Smrghp) 248943345d3Smrg # This case exists only to let depend.m4 do its work. It works by 249943345d3Smrg # looking at the text of this script. This case will never be run, 250943345d3Smrg # since it is checked for above. 251943345d3Smrg exit 1 252943345d3Smrg ;; 253943345d3Smrg 254943345d3Smrgsgi) 255943345d3Smrg if test "$libtool" = yes; then 256943345d3Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257943345d3Smrg else 258943345d3Smrg "$@" -MDupdate "$tmpdepfile" 259943345d3Smrg fi 260943345d3Smrg stat=$? 26115ffece8Smrg if test $stat -ne 0; then 262943345d3Smrg rm -f "$tmpdepfile" 263943345d3Smrg exit $stat 264943345d3Smrg fi 265943345d3Smrg rm -f "$depfile" 266943345d3Smrg 267943345d3Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268943345d3Smrg echo "$object : \\" > "$depfile" 269943345d3Smrg # Clip off the initial element (the dependent). Don't try to be 270943345d3Smrg # clever and replace this with sed code, as IRIX sed won't handle 271943345d3Smrg # lines with more than a fixed number of characters (4096 in 272943345d3Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27315ffece8Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274943345d3Smrg # dependency line. 27515ffece8Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27615ffece8Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27715ffece8Smrg | tr "$nl" ' ' >> "$depfile" 2785e695a52Smrg echo >> "$depfile" 279943345d3Smrg # The second pass generates a dummy entry for each header file. 28015ffece8Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28115ffece8Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28215ffece8Smrg >> "$depfile" 283943345d3Smrg else 28415ffece8Smrg make_dummy_depfile 285943345d3Smrg fi 286943345d3Smrg rm -f "$tmpdepfile" 287943345d3Smrg ;; 288943345d3Smrg 28915ffece8Smrgxlc) 29015ffece8Smrg # This case exists only to let depend.m4 do its work. It works by 29115ffece8Smrg # looking at the text of this script. This case will never be run, 29215ffece8Smrg # since it is checked for above. 29315ffece8Smrg exit 1 29415ffece8Smrg ;; 29515ffece8Smrg 296943345d3Smrgaix) 297943345d3Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298943345d3Smrg # in a .u file. In older versions, this file always lives in the 29915ffece8Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300943345d3Smrg # start of each line; $object doesn't have directory information. 301943345d3Smrg # Version 6 uses the directory in both cases. 30215ffece8Smrg set_dir_from "$object" 30315ffece8Smrg set_base_from "$object" 304943345d3Smrg if test "$libtool" = yes; then 3055e695a52Smrg tmpdepfile1=$dir$base.u 3065e695a52Smrg tmpdepfile2=$base.u 3075e695a52Smrg tmpdepfile3=$dir.libs/$base.u 308943345d3Smrg "$@" -Wc,-M 309943345d3Smrg else 3105e695a52Smrg tmpdepfile1=$dir$base.u 3115e695a52Smrg tmpdepfile2=$dir$base.u 3125e695a52Smrg tmpdepfile3=$dir$base.u 313943345d3Smrg "$@" -M 314943345d3Smrg fi 315943345d3Smrg stat=$? 31615ffece8Smrg if test $stat -ne 0; then 3175e695a52Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318943345d3Smrg exit $stat 319943345d3Smrg fi 320943345d3Smrg 3215e695a52Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3225e695a52Smrg do 3235e695a52Smrg test -f "$tmpdepfile" && break 3245e695a52Smrg done 32515ffece8Smrg aix_post_process_depfile 32615ffece8Smrg ;; 32715ffece8Smrg 32815ffece8Smrgtcc) 32915ffece8Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33015ffece8Smrg # FIXME: That version still under development at the moment of writing. 33115ffece8Smrg # Make that this statement remains true also for stable, released 33215ffece8Smrg # versions. 33315ffece8Smrg # It will wrap lines (doesn't matter whether long or short) with a 33415ffece8Smrg # trailing '\', as in: 33515ffece8Smrg # 33615ffece8Smrg # foo.o : \ 33715ffece8Smrg # foo.c \ 33815ffece8Smrg # foo.h \ 33915ffece8Smrg # 34015ffece8Smrg # It will put a trailing '\' even on the last line, and will use leading 34115ffece8Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34215ffece8Smrg # "Emit spaces for -MD"). 34315ffece8Smrg "$@" -MD -MF "$tmpdepfile" 34415ffece8Smrg stat=$? 34515ffece8Smrg if test $stat -ne 0; then 34615ffece8Smrg rm -f "$tmpdepfile" 34715ffece8Smrg exit $stat 348943345d3Smrg fi 34915ffece8Smrg rm -f "$depfile" 35015ffece8Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35115ffece8Smrg # We have to change lines of the first kind to '$object: \'. 35215ffece8Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35315ffece8Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35415ffece8Smrg # dummy dependency, to avoid the deleted-header problem. 35515ffece8Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356943345d3Smrg rm -f "$tmpdepfile" 357943345d3Smrg ;; 358943345d3Smrg 35915ffece8Smrg## The order of this option in the case statement is important, since the 36015ffece8Smrg## shell code in configure will try each of these formats in the order 36115ffece8Smrg## listed in this file. A plain '-MD' option would be understood by many 36215ffece8Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36315ffece8Smrgpgcc) 36415ffece8Smrg # Portland's C compiler understands '-MD'. 36515ffece8Smrg # Will always output deps to 'file.d' where file is the root name of the 36615ffece8Smrg # source file under compilation, even if file resides in a subdirectory. 36715ffece8Smrg # The object file name does not affect the name of the '.d' file. 36815ffece8Smrg # pgcc 10.2 will output 369943345d3Smrg # foo.o: sub/foo.c sub/foo.h 37015ffece8Smrg # and will wrap long lines using '\' : 371943345d3Smrg # foo.o: sub/foo.c ... \ 372943345d3Smrg # sub/foo.h ... \ 373943345d3Smrg # ... 37415ffece8Smrg set_dir_from "$object" 37515ffece8Smrg # Use the source, not the object, to determine the base name, since 37615ffece8Smrg # that's sadly what pgcc will do too. 37715ffece8Smrg set_base_from "$source" 37815ffece8Smrg tmpdepfile=$base.d 37915ffece8Smrg 38015ffece8Smrg # For projects that build the same source file twice into different object 38115ffece8Smrg # files, the pgcc approach of using the *source* file root name can cause 38215ffece8Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38315ffece8Smrg # the same $tmpdepfile. 38415ffece8Smrg lockdir=$base.d-lock 38515ffece8Smrg trap " 38615ffece8Smrg echo '$0: caught signal, cleaning up...' >&2 38715ffece8Smrg rmdir '$lockdir' 38815ffece8Smrg exit 1 38915ffece8Smrg " 1 2 13 15 39015ffece8Smrg numtries=100 39115ffece8Smrg i=$numtries 39215ffece8Smrg while test $i -gt 0; do 39315ffece8Smrg # mkdir is a portable test-and-set. 39415ffece8Smrg if mkdir "$lockdir" 2>/dev/null; then 39515ffece8Smrg # This process acquired the lock. 39615ffece8Smrg "$@" -MD 39715ffece8Smrg stat=$? 39815ffece8Smrg # Release the lock. 39915ffece8Smrg rmdir "$lockdir" 40015ffece8Smrg break 40115ffece8Smrg else 40215ffece8Smrg # If the lock is being held by a different process, wait 40315ffece8Smrg # until the winning process is done or we timeout. 40415ffece8Smrg while test -d "$lockdir" && test $i -gt 0; do 40515ffece8Smrg sleep 1 40615ffece8Smrg i=`expr $i - 1` 40715ffece8Smrg done 40815ffece8Smrg fi 40915ffece8Smrg i=`expr $i - 1` 41015ffece8Smrg done 41115ffece8Smrg trap - 1 2 13 15 41215ffece8Smrg if test $i -le 0; then 41315ffece8Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41415ffece8Smrg echo "$0: check lockdir '$lockdir'" >&2 41515ffece8Smrg exit 1 41615ffece8Smrg fi 417943345d3Smrg 41815ffece8Smrg if test $stat -ne 0; then 419943345d3Smrg rm -f "$tmpdepfile" 420943345d3Smrg exit $stat 421943345d3Smrg fi 422943345d3Smrg rm -f "$depfile" 423943345d3Smrg # Each line is of the form `foo.o: dependent.h', 424943345d3Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425943345d3Smrg # Do two passes, one to just change these to 426943345d3Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427943345d3Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428943345d3Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429943345d3Smrg # correctly. Breaking it into two sed invocations is a workaround. 43015ffece8Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43115ffece8Smrg | sed -e 's/$/ :/' >> "$depfile" 432943345d3Smrg rm -f "$tmpdepfile" 433943345d3Smrg ;; 434943345d3Smrg 435f67b85aaSmrghp2) 436f67b85aaSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437f67b85aaSmrg # compilers, which have integrated preprocessors. The correct option 438f67b85aaSmrg # to use with these is +Maked; it writes dependencies to a file named 439f67b85aaSmrg # 'foo.d', which lands next to the object file, wherever that 440f67b85aaSmrg # happens to be. 441f67b85aaSmrg # Much of this is similar to the tru64 case; see comments there. 44215ffece8Smrg set_dir_from "$object" 44315ffece8Smrg set_base_from "$object" 444f67b85aaSmrg if test "$libtool" = yes; then 445f67b85aaSmrg tmpdepfile1=$dir$base.d 446f67b85aaSmrg tmpdepfile2=$dir.libs/$base.d 447f67b85aaSmrg "$@" -Wc,+Maked 448f67b85aaSmrg else 449f67b85aaSmrg tmpdepfile1=$dir$base.d 450f67b85aaSmrg tmpdepfile2=$dir$base.d 451f67b85aaSmrg "$@" +Maked 452f67b85aaSmrg fi 453f67b85aaSmrg stat=$? 45415ffece8Smrg if test $stat -ne 0; then 455f67b85aaSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456f67b85aaSmrg exit $stat 457f67b85aaSmrg fi 458f67b85aaSmrg 459f67b85aaSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460f67b85aaSmrg do 461f67b85aaSmrg test -f "$tmpdepfile" && break 462f67b85aaSmrg done 463f67b85aaSmrg if test -f "$tmpdepfile"; then 46415ffece8Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46515ffece8Smrg # Add 'dependent.h:' lines. 4665e695a52Smrg sed -ne '2,${ 46715ffece8Smrg s/^ *// 46815ffece8Smrg s/ \\*$// 46915ffece8Smrg s/$/:/ 47015ffece8Smrg p 47115ffece8Smrg }' "$tmpdepfile" >> "$depfile" 472f67b85aaSmrg else 47315ffece8Smrg make_dummy_depfile 474f67b85aaSmrg fi 475f67b85aaSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 476f67b85aaSmrg ;; 477f67b85aaSmrg 478943345d3Smrgtru64) 47915ffece8Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48015ffece8Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48115ffece8Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48215ffece8Smrg # dependencies in 'foo.d' instead, so we check for that too. 48315ffece8Smrg # Subdirectories are respected. 48415ffece8Smrg set_dir_from "$object" 48515ffece8Smrg set_base_from "$object" 48615ffece8Smrg 48715ffece8Smrg if test "$libtool" = yes; then 48815ffece8Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48915ffece8Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49015ffece8Smrg # in $dir$base.o.d. We have to check for both files, because 49115ffece8Smrg # one of the two compilations can be disabled. We should prefer 49215ffece8Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49315ffece8Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49415ffece8Smrg # the former would cause a distcleancheck panic. 49515ffece8Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49615ffece8Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49715ffece8Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49815ffece8Smrg "$@" -Wc,-MD 49915ffece8Smrg else 50015ffece8Smrg tmpdepfile1=$dir$base.d 50115ffece8Smrg tmpdepfile2=$dir$base.d 50215ffece8Smrg tmpdepfile3=$dir$base.d 50315ffece8Smrg "$@" -MD 50415ffece8Smrg fi 50515ffece8Smrg 50615ffece8Smrg stat=$? 50715ffece8Smrg if test $stat -ne 0; then 50815ffece8Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50915ffece8Smrg exit $stat 51015ffece8Smrg fi 51115ffece8Smrg 51215ffece8Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51315ffece8Smrg do 51415ffece8Smrg test -f "$tmpdepfile" && break 51515ffece8Smrg done 51615ffece8Smrg # Same post-processing that is required for AIX mode. 51715ffece8Smrg aix_post_process_depfile 51815ffece8Smrg ;; 519943345d3Smrg 5203e51e026Smrgmsvc7) 5213e51e026Smrg if test "$libtool" = yes; then 5223e51e026Smrg showIncludes=-Wc,-showIncludes 5233e51e026Smrg else 5243e51e026Smrg showIncludes=-showIncludes 5253e51e026Smrg fi 5263e51e026Smrg "$@" $showIncludes > "$tmpdepfile" 5273e51e026Smrg stat=$? 5283e51e026Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52915ffece8Smrg if test $stat -ne 0; then 5303e51e026Smrg rm -f "$tmpdepfile" 5313e51e026Smrg exit $stat 5323e51e026Smrg fi 5333e51e026Smrg rm -f "$depfile" 5343e51e026Smrg echo "$object : \\" > "$depfile" 5353e51e026Smrg # The first sed program below extracts the file names and escapes 5363e51e026Smrg # backslashes for cygpath. The second sed program outputs the file 5373e51e026Smrg # name when reading, but also accumulates all include files in the 5383e51e026Smrg # hold buffer in order to output them again at the end. This only 5393e51e026Smrg # works with sed implementations that can handle large buffers. 5403e51e026Smrg sed < "$tmpdepfile" -n ' 5413e51e026Smrg/^Note: including file: *\(.*\)/ { 5423e51e026Smrg s//\1/ 5433e51e026Smrg s/\\/\\\\/g 5443e51e026Smrg p 5453e51e026Smrg}' | $cygpath_u | sort -u | sed -n ' 5463e51e026Smrgs/ /\\ /g 54715ffece8Smrgs/\(.*\)/'"$tab"'\1 \\/p 5483e51e026Smrgs/.\(.*\) \\/\1:/ 5493e51e026SmrgH 5503e51e026Smrg$ { 55115ffece8Smrg s/.*/'"$tab"'/ 5523e51e026Smrg G 5533e51e026Smrg p 5543e51e026Smrg}' >> "$depfile" 55515ffece8Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5563e51e026Smrg rm -f "$tmpdepfile" 5573e51e026Smrg ;; 5583e51e026Smrg 5593e51e026Smrgmsvc7msys) 5603e51e026Smrg # This case exists only to let depend.m4 do its work. It works by 5613e51e026Smrg # looking at the text of this script. This case will never be run, 5623e51e026Smrg # since it is checked for above. 5633e51e026Smrg exit 1 5643e51e026Smrg ;; 5653e51e026Smrg 566943345d3Smrg#nosideeffect) 567943345d3Smrg # This comment above is used by automake to tell side-effect 568943345d3Smrg # dependency tracking mechanisms from slower ones. 569943345d3Smrg 570943345d3Smrgdashmstdout) 571943345d3Smrg # Important note: in order to support this mode, a compiler *must* 572943345d3Smrg # always write the preprocessed file to stdout, regardless of -o. 573943345d3Smrg "$@" || exit $? 574943345d3Smrg 575943345d3Smrg # Remove the call to Libtool. 576943345d3Smrg if test "$libtool" = yes; then 5775e695a52Smrg while test "X$1" != 'X--mode=compile'; do 578943345d3Smrg shift 579943345d3Smrg done 580943345d3Smrg shift 581943345d3Smrg fi 582943345d3Smrg 58315ffece8Smrg # Remove '-o $object'. 584943345d3Smrg IFS=" " 585943345d3Smrg for arg 586943345d3Smrg do 587943345d3Smrg case $arg in 588943345d3Smrg -o) 589943345d3Smrg shift 590943345d3Smrg ;; 591943345d3Smrg $object) 592943345d3Smrg shift 593943345d3Smrg ;; 594943345d3Smrg *) 595943345d3Smrg set fnord "$@" "$arg" 596943345d3Smrg shift # fnord 597943345d3Smrg shift # $arg 598943345d3Smrg ;; 599943345d3Smrg esac 600943345d3Smrg done 601943345d3Smrg 602943345d3Smrg test -z "$dashmflag" && dashmflag=-M 60315ffece8Smrg # Require at least two characters before searching for ':' 604943345d3Smrg # in the target name. This is to cope with DOS-style filenames: 60515ffece8Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606943345d3Smrg "$@" $dashmflag | 60715ffece8Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608943345d3Smrg rm -f "$depfile" 609943345d3Smrg cat < "$tmpdepfile" > "$depfile" 61015ffece8Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61115ffece8Smrg # correctly. Breaking it into two sed invocations is a workaround. 61215ffece8Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61315ffece8Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61415ffece8Smrg | sed -e 's/$/ :/' >> "$depfile" 615943345d3Smrg rm -f "$tmpdepfile" 616943345d3Smrg ;; 617943345d3Smrg 618943345d3SmrgdashXmstdout) 619943345d3Smrg # This case only exists to satisfy depend.m4. It is never actually 620943345d3Smrg # run, as this mode is specially recognized in the preamble. 621943345d3Smrg exit 1 622943345d3Smrg ;; 623943345d3Smrg 624943345d3Smrgmakedepend) 625943345d3Smrg "$@" || exit $? 626943345d3Smrg # Remove any Libtool call 627943345d3Smrg if test "$libtool" = yes; then 6285e695a52Smrg while test "X$1" != 'X--mode=compile'; do 629943345d3Smrg shift 630943345d3Smrg done 631943345d3Smrg shift 632943345d3Smrg fi 633943345d3Smrg # X makedepend 634943345d3Smrg shift 6355e695a52Smrg cleared=no eat=no 6365e695a52Smrg for arg 6375e695a52Smrg do 638943345d3Smrg case $cleared in 639943345d3Smrg no) 640943345d3Smrg set ""; shift 641943345d3Smrg cleared=yes ;; 642943345d3Smrg esac 6435e695a52Smrg if test $eat = yes; then 6445e695a52Smrg eat=no 6455e695a52Smrg continue 6465e695a52Smrg fi 647943345d3Smrg case "$arg" in 648943345d3Smrg -D*|-I*) 649943345d3Smrg set fnord "$@" "$arg"; shift ;; 650943345d3Smrg # Strip any option that makedepend may not understand. Remove 651943345d3Smrg # the object too, otherwise makedepend will parse it as a source file. 6525e695a52Smrg -arch) 6535e695a52Smrg eat=yes ;; 654943345d3Smrg -*|$object) 655943345d3Smrg ;; 656943345d3Smrg *) 657943345d3Smrg set fnord "$@" "$arg"; shift ;; 658943345d3Smrg esac 659943345d3Smrg done 6605e695a52Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661943345d3Smrg touch "$tmpdepfile" 662943345d3Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663943345d3Smrg rm -f "$depfile" 6643e51e026Smrg # makedepend may prepend the VPATH from the source file name to the object. 6653e51e026Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 6663e51e026Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66715ffece8Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66815ffece8Smrg # correctly. Breaking it into two sed invocations is a workaround. 66915ffece8Smrg sed '1,2d' "$tmpdepfile" \ 67015ffece8Smrg | tr ' ' "$nl" \ 67115ffece8Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67215ffece8Smrg | sed -e 's/$/ :/' >> "$depfile" 673943345d3Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674943345d3Smrg ;; 675943345d3Smrg 676943345d3Smrgcpp) 677943345d3Smrg # Important note: in order to support this mode, a compiler *must* 678943345d3Smrg # always write the preprocessed file to stdout. 679943345d3Smrg "$@" || exit $? 680943345d3Smrg 681943345d3Smrg # Remove the call to Libtool. 682943345d3Smrg if test "$libtool" = yes; then 6835e695a52Smrg while test "X$1" != 'X--mode=compile'; do 684943345d3Smrg shift 685943345d3Smrg done 686943345d3Smrg shift 687943345d3Smrg fi 688943345d3Smrg 68915ffece8Smrg # Remove '-o $object'. 690943345d3Smrg IFS=" " 691943345d3Smrg for arg 692943345d3Smrg do 693943345d3Smrg case $arg in 694943345d3Smrg -o) 695943345d3Smrg shift 696943345d3Smrg ;; 697943345d3Smrg $object) 698943345d3Smrg shift 699943345d3Smrg ;; 700943345d3Smrg *) 701943345d3Smrg set fnord "$@" "$arg" 702943345d3Smrg shift # fnord 703943345d3Smrg shift # $arg 704943345d3Smrg ;; 705943345d3Smrg esac 706943345d3Smrg done 707943345d3Smrg 70815ffece8Smrg "$@" -E \ 70915ffece8Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71015ffece8Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71115ffece8Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712943345d3Smrg rm -f "$depfile" 713943345d3Smrg echo "$object : \\" > "$depfile" 714943345d3Smrg cat < "$tmpdepfile" >> "$depfile" 715943345d3Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716943345d3Smrg rm -f "$tmpdepfile" 717943345d3Smrg ;; 718943345d3Smrg 719943345d3Smrgmsvisualcpp) 720943345d3Smrg # Important note: in order to support this mode, a compiler *must* 7215e695a52Smrg # always write the preprocessed file to stdout. 722943345d3Smrg "$@" || exit $? 7235e695a52Smrg 7245e695a52Smrg # Remove the call to Libtool. 7255e695a52Smrg if test "$libtool" = yes; then 7265e695a52Smrg while test "X$1" != 'X--mode=compile'; do 7275e695a52Smrg shift 7285e695a52Smrg done 7295e695a52Smrg shift 7305e695a52Smrg fi 7315e695a52Smrg 732943345d3Smrg IFS=" " 733943345d3Smrg for arg 734943345d3Smrg do 735943345d3Smrg case "$arg" in 7365e695a52Smrg -o) 7375e695a52Smrg shift 7385e695a52Smrg ;; 7395e695a52Smrg $object) 7405e695a52Smrg shift 7415e695a52Smrg ;; 742943345d3Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74315ffece8Smrg set fnord "$@" 74415ffece8Smrg shift 74515ffece8Smrg shift 74615ffece8Smrg ;; 747943345d3Smrg *) 74815ffece8Smrg set fnord "$@" "$arg" 74915ffece8Smrg shift 75015ffece8Smrg shift 75115ffece8Smrg ;; 752943345d3Smrg esac 753943345d3Smrg done 7545e695a52Smrg "$@" -E 2>/dev/null | 7555e695a52Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756943345d3Smrg rm -f "$depfile" 757943345d3Smrg echo "$object : \\" > "$depfile" 75815ffece8Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75915ffece8Smrg echo "$tab" >> "$depfile" 7605e695a52Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761943345d3Smrg rm -f "$tmpdepfile" 762943345d3Smrg ;; 763943345d3Smrg 7645e695a52Smrgmsvcmsys) 7655e695a52Smrg # This case exists only to let depend.m4 do its work. It works by 7665e695a52Smrg # looking at the text of this script. This case will never be run, 7675e695a52Smrg # since it is checked for above. 7685e695a52Smrg exit 1 7695e695a52Smrg ;; 7705e695a52Smrg 771943345d3Smrgnone) 772943345d3Smrg exec "$@" 773943345d3Smrg ;; 774943345d3Smrg 775943345d3Smrg*) 776943345d3Smrg echo "Unknown depmode $depmode" 1>&2 777943345d3Smrg exit 1 778943345d3Smrg ;; 779943345d3Smrgesac 780943345d3Smrg 781943345d3Smrgexit 0 782943345d3Smrg 783943345d3Smrg# Local Variables: 784943345d3Smrg# mode: shell-script 785943345d3Smrg# sh-indentation: 2 78615ffece8Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 787943345d3Smrg# time-stamp-start: "scriptversion=" 788943345d3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78915ffece8Smrg# time-stamp-time-zone: "UTC0" 7905e695a52Smrg# time-stamp-end: "; # UTC" 791943345d3Smrg# End: 792