1b3307321Smrg#! /bin/sh 2b3307321Smrg# depcomp - compile a program generating dependencies as side-effects 3afe13c8eSmrg 474b97a6cSmrgscriptversion=2018-03-07.03; # UTC 5afe13c8eSmrg 674b97a6cSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7b3307321Smrg 8b3307321Smrg# This program is free software; you can redistribute it and/or modify 9b3307321Smrg# it under the terms of the GNU General Public License as published by 10b3307321Smrg# the Free Software Foundation; either version 2, or (at your option) 11b3307321Smrg# any later version. 12b3307321Smrg 13b3307321Smrg# This program is distributed in the hope that it will be useful, 14b3307321Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15b3307321Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16b3307321Smrg# GNU General Public License for more details. 17b3307321Smrg 18b3307321Smrg# You should have received a copy of the GNU General Public License 1974b97a6cSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20b3307321Smrg 21b3307321Smrg# As a special exception to the GNU General Public License, if you 22b3307321Smrg# distribute this file as part of a program that contains a 23b3307321Smrg# configuration script generated by Autoconf, you may include it under 24b3307321Smrg# the same distribution terms that you use for the rest of that program. 25b3307321Smrg 26b3307321Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27b3307321Smrg 28afe13c8eSmrgcase $1 in 29afe13c8eSmrg '') 3074a3f230Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3174a3f230Smrg exit 1; 3274a3f230Smrg ;; 33afe13c8eSmrg -h | --h*) 34afe13c8eSmrg cat <<\EOF 35afe13c8eSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36afe13c8eSmrg 37afe13c8eSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38afe13c8eSmrgas side-effects. 39afe13c8eSmrg 40afe13c8eSmrgEnvironment variables: 41afe13c8eSmrg depmode Dependency tracking mode. 4274a3f230Smrg source Source file read by 'PROGRAMS ARGS'. 4374a3f230Smrg object Object file output by 'PROGRAMS ARGS'. 44afe13c8eSmrg DEPDIR directory where to store dependencies. 45afe13c8eSmrg depfile Dependency file to output. 4674a3f230Smrg tmpdepfile Temporary file to use when outputting dependencies. 47afe13c8eSmrg libtool Whether libtool is used (yes/no). 48afe13c8eSmrg 49afe13c8eSmrgReport bugs to <bug-automake@gnu.org>. 50afe13c8eSmrgEOF 51afe13c8eSmrg exit $? 52afe13c8eSmrg ;; 53afe13c8eSmrg -v | --v*) 54afe13c8eSmrg echo "depcomp $scriptversion" 55afe13c8eSmrg exit $? 56afe13c8eSmrg ;; 57afe13c8eSmrgesac 58afe13c8eSmrg 5974a3f230Smrg# Get the directory component of the given path, and save it in the 6074a3f230Smrg# global variables '$dir'. Note that this directory component will 6174a3f230Smrg# be either empty or ending with a '/' character. This is deliberate. 6274a3f230Smrgset_dir_from () 6374a3f230Smrg{ 6474a3f230Smrg case $1 in 6574a3f230Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6674a3f230Smrg *) dir=;; 6774a3f230Smrg esac 6874a3f230Smrg} 6974a3f230Smrg 7074a3f230Smrg# Get the suffix-stripped basename of the given path, and save it the 7174a3f230Smrg# global variable '$base'. 7274a3f230Smrgset_base_from () 7374a3f230Smrg{ 7474a3f230Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7574a3f230Smrg} 7674a3f230Smrg 7774a3f230Smrg# If no dependency file was actually created by the compiler invocation, 7874a3f230Smrg# we still have to create a dummy depfile, to avoid errors with the 7974a3f230Smrg# Makefile "include basename.Plo" scheme. 8074a3f230Smrgmake_dummy_depfile () 8174a3f230Smrg{ 8274a3f230Smrg echo "#dummy" > "$depfile" 8374a3f230Smrg} 8474a3f230Smrg 8574a3f230Smrg# Factor out some common post-processing of the generated depfile. 8674a3f230Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8774a3f230Smrgaix_post_process_depfile () 8874a3f230Smrg{ 8974a3f230Smrg # If the compiler actually managed to produce a dependency file, 9074a3f230Smrg # post-process it. 9174a3f230Smrg if test -f "$tmpdepfile"; then 9274a3f230Smrg # Each line is of the form 'foo.o: dependency.h'. 9374a3f230Smrg # Do two passes, one to just change these to 9474a3f230Smrg # $object: dependency.h 9574a3f230Smrg # and one to simply output 9674a3f230Smrg # dependency.h: 9774a3f230Smrg # which is needed to avoid the deleted-header problem. 9874a3f230Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9974a3f230Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10074a3f230Smrg } > "$depfile" 10174a3f230Smrg rm -f "$tmpdepfile" 10274a3f230Smrg else 10374a3f230Smrg make_dummy_depfile 10474a3f230Smrg fi 10574a3f230Smrg} 10674a3f230Smrg 10774a3f230Smrg# A tabulation character. 10874a3f230Smrgtab=' ' 10974a3f230Smrg# A newline character. 11074a3f230Smrgnl=' 11174a3f230Smrg' 11274a3f230Smrg# Character ranges might be problematic outside the C locale. 11374a3f230Smrg# These definitions help. 11474a3f230Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11574a3f230Smrglower=abcdefghijklmnopqrstuvwxyz 11674a3f230Smrgdigits=0123456789 11774a3f230Smrgalpha=${upper}${lower} 11874a3f230Smrg 119b3307321Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120b3307321Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121b3307321Smrg exit 1 122b3307321Smrgfi 123b3307321Smrg 124afe13c8eSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125afe13c8eSmrgdepfile=${depfile-`echo "$object" | 126afe13c8eSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127b3307321Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128b3307321Smrg 129b3307321Smrgrm -f "$tmpdepfile" 130b3307321Smrg 13174a3f230Smrg# Avoid interferences from the environment. 13274a3f230Smrggccflag= dashmflag= 13374a3f230Smrg 134b3307321Smrg# Some modes work just like other modes, but use different flags. We 135b3307321Smrg# parameterize here, but still list the modes in the big case below, 136b3307321Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137b3307321Smrg# here, because this file can only contain one case statement. 138b3307321Smrgif test "$depmode" = hp; then 139b3307321Smrg # HP compiler uses -M and no extra arg. 140b3307321Smrg gccflag=-M 141b3307321Smrg depmode=gcc 142b3307321Smrgfi 143b3307321Smrg 144b3307321Smrgif test "$depmode" = dashXmstdout; then 14574a3f230Smrg # This is just like dashmstdout with a different argument. 14674a3f230Smrg dashmflag=-xM 14774a3f230Smrg depmode=dashmstdout 148b3307321Smrgfi 149b3307321Smrg 1505e358ecaSmrgcygpath_u="cygpath -u -f -" 1515e358ecaSmrgif test "$depmode" = msvcmsys; then 15274a3f230Smrg # This is just like msvisualcpp but w/o cygpath translation. 15374a3f230Smrg # Just convert the backslash-escaped backslashes to single forward 15474a3f230Smrg # slashes to satisfy depend.m4 15574a3f230Smrg cygpath_u='sed s,\\\\,/,g' 15674a3f230Smrg depmode=msvisualcpp 15774a3f230Smrgfi 15874a3f230Smrg 15974a3f230Smrgif test "$depmode" = msvc7msys; then 16074a3f230Smrg # This is just like msvc7 but w/o cygpath translation. 16174a3f230Smrg # Just convert the backslash-escaped backslashes to single forward 16274a3f230Smrg # slashes to satisfy depend.m4 16374a3f230Smrg cygpath_u='sed s,\\\\,/,g' 16474a3f230Smrg depmode=msvc7 16574a3f230Smrgfi 16674a3f230Smrg 16774a3f230Smrgif test "$depmode" = xlc; then 16874a3f230Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16974a3f230Smrg gccflag=-qmakedep=gcc,-MF 17074a3f230Smrg depmode=gcc 1715e358ecaSmrgfi 1725e358ecaSmrg 173b3307321Smrgcase "$depmode" in 174b3307321Smrggcc3) 175b3307321Smrg## gcc 3 implements dependency tracking that does exactly what 176b3307321Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177b3307321Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178afe13c8eSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179afe13c8eSmrg## the command line argument order; so add the flags where they 180afe13c8eSmrg## appear in depend2.am. Note that the slowdown incurred here 181afe13c8eSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182afe13c8eSmrg for arg 183afe13c8eSmrg do 184afe13c8eSmrg case $arg in 185afe13c8eSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186afe13c8eSmrg *) set fnord "$@" "$arg" ;; 187afe13c8eSmrg esac 188afe13c8eSmrg shift # fnord 189afe13c8eSmrg shift # $arg 190afe13c8eSmrg done 191afe13c8eSmrg "$@" 192b3307321Smrg stat=$? 19374a3f230Smrg if test $stat -ne 0; then 194b3307321Smrg rm -f "$tmpdepfile" 195b3307321Smrg exit $stat 196b3307321Smrg fi 197b3307321Smrg mv "$tmpdepfile" "$depfile" 198b3307321Smrg ;; 199b3307321Smrg 200b3307321Smrggcc) 20174a3f230Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20274a3f230Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20374a3f230Smrg## (see the conditional assignment to $gccflag above). 204b3307321Smrg## There are various ways to get dependency output from gcc. Here's 205b3307321Smrg## why we pick this rather obscure method: 206b3307321Smrg## - Don't want to use -MD because we'd like the dependencies to end 207b3307321Smrg## up in a subdir. Having to rename by hand is ugly. 208b3307321Smrg## (We might end up doing this anyway to support other compilers.) 209b3307321Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21074a3f230Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21174a3f230Smrg## supported by the other compilers which use the 'gcc' depmode. 212b3307321Smrg## - Using -M directly means running the compiler twice (even worse 213b3307321Smrg## than renaming). 214b3307321Smrg if test -z "$gccflag"; then 215b3307321Smrg gccflag=-MD, 216b3307321Smrg fi 217b3307321Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218b3307321Smrg stat=$? 21974a3f230Smrg if test $stat -ne 0; then 220b3307321Smrg rm -f "$tmpdepfile" 221b3307321Smrg exit $stat 222b3307321Smrg fi 223b3307321Smrg rm -f "$depfile" 224b3307321Smrg echo "$object : \\" > "$depfile" 22574a3f230Smrg # The second -e expression handles DOS-style file names with drive 22674a3f230Smrg # letters. 227b3307321Smrg sed -e 's/^[^:]*: / /' \ 228b3307321Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22974a3f230Smrg## This next piece of magic avoids the "deleted header file" problem. 230b3307321Smrg## The problem is that when a header file which appears in a .P file 231b3307321Smrg## is deleted, the dependency causes make to die (because there is 232b3307321Smrg## typically no way to rebuild the header). We avoid this by adding 233b3307321Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234b3307321Smrg## this for us directly. 23574a3f230Smrg## Some versions of gcc put a space before the ':'. On the theory 236b3307321Smrg## that the space means something, we add a space to the output as 23774a3f230Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23874a3f230Smrg## to the object. Take care to not repeat it in the output. 239b3307321Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240b3307321Smrg## correctly. Breaking it into two sed invocations is a workaround. 24174a3f230Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24274a3f230Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24374a3f230Smrg | sed -e 's/$/ :/' >> "$depfile" 244b3307321Smrg rm -f "$tmpdepfile" 245b3307321Smrg ;; 246b3307321Smrg 247b3307321Smrghp) 248b3307321Smrg # This case exists only to let depend.m4 do its work. It works by 249b3307321Smrg # looking at the text of this script. This case will never be run, 250b3307321Smrg # since it is checked for above. 251b3307321Smrg exit 1 252b3307321Smrg ;; 253b3307321Smrg 254b3307321Smrgsgi) 255b3307321Smrg if test "$libtool" = yes; then 256b3307321Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257b3307321Smrg else 258b3307321Smrg "$@" -MDupdate "$tmpdepfile" 259b3307321Smrg fi 260b3307321Smrg stat=$? 26174a3f230Smrg if test $stat -ne 0; then 262b3307321Smrg rm -f "$tmpdepfile" 263b3307321Smrg exit $stat 264b3307321Smrg fi 265b3307321Smrg rm -f "$depfile" 266b3307321Smrg 267b3307321Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268b3307321Smrg echo "$object : \\" > "$depfile" 269b3307321Smrg # Clip off the initial element (the dependent). Don't try to be 270b3307321Smrg # clever and replace this with sed code, as IRIX sed won't handle 271b3307321Smrg # lines with more than a fixed number of characters (4096 in 272b3307321Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27374a3f230Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274b3307321Smrg # dependency line. 27574a3f230Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27674a3f230Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27774a3f230Smrg | tr "$nl" ' ' >> "$depfile" 2785e358ecaSmrg echo >> "$depfile" 279b3307321Smrg # The second pass generates a dummy entry for each header file. 28074a3f230Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28174a3f230Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28274a3f230Smrg >> "$depfile" 283b3307321Smrg else 28474a3f230Smrg make_dummy_depfile 285b3307321Smrg fi 286b3307321Smrg rm -f "$tmpdepfile" 287b3307321Smrg ;; 288b3307321Smrg 28974a3f230Smrgxlc) 29074a3f230Smrg # This case exists only to let depend.m4 do its work. It works by 29174a3f230Smrg # looking at the text of this script. This case will never be run, 29274a3f230Smrg # since it is checked for above. 29374a3f230Smrg exit 1 29474a3f230Smrg ;; 29574a3f230Smrg 296b3307321Smrgaix) 297b3307321Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298b3307321Smrg # in a .u file. In older versions, this file always lives in the 29974a3f230Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300b3307321Smrg # start of each line; $object doesn't have directory information. 301b3307321Smrg # Version 6 uses the directory in both cases. 30274a3f230Smrg set_dir_from "$object" 30374a3f230Smrg set_base_from "$object" 304b3307321Smrg if test "$libtool" = yes; then 305afe13c8eSmrg tmpdepfile1=$dir$base.u 306afe13c8eSmrg tmpdepfile2=$base.u 307afe13c8eSmrg tmpdepfile3=$dir.libs/$base.u 308b3307321Smrg "$@" -Wc,-M 309b3307321Smrg else 310afe13c8eSmrg tmpdepfile1=$dir$base.u 311afe13c8eSmrg tmpdepfile2=$dir$base.u 312afe13c8eSmrg tmpdepfile3=$dir$base.u 313b3307321Smrg "$@" -M 314b3307321Smrg fi 315b3307321Smrg stat=$? 31674a3f230Smrg if test $stat -ne 0; then 317afe13c8eSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318b3307321Smrg exit $stat 319b3307321Smrg fi 320b3307321Smrg 321afe13c8eSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322afe13c8eSmrg do 323afe13c8eSmrg test -f "$tmpdepfile" && break 324afe13c8eSmrg done 32574a3f230Smrg aix_post_process_depfile 32674a3f230Smrg ;; 32774a3f230Smrg 32874a3f230Smrgtcc) 32974a3f230Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33074a3f230Smrg # FIXME: That version still under development at the moment of writing. 33174a3f230Smrg # Make that this statement remains true also for stable, released 33274a3f230Smrg # versions. 33374a3f230Smrg # It will wrap lines (doesn't matter whether long or short) with a 33474a3f230Smrg # trailing '\', as in: 33574a3f230Smrg # 33674a3f230Smrg # foo.o : \ 33774a3f230Smrg # foo.c \ 33874a3f230Smrg # foo.h \ 33974a3f230Smrg # 34074a3f230Smrg # It will put a trailing '\' even on the last line, and will use leading 34174a3f230Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34274a3f230Smrg # "Emit spaces for -MD"). 34374a3f230Smrg "$@" -MD -MF "$tmpdepfile" 34474a3f230Smrg stat=$? 34574a3f230Smrg if test $stat -ne 0; then 34674a3f230Smrg rm -f "$tmpdepfile" 34774a3f230Smrg exit $stat 348b3307321Smrg fi 34974a3f230Smrg rm -f "$depfile" 35074a3f230Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35174a3f230Smrg # We have to change lines of the first kind to '$object: \'. 35274a3f230Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35374a3f230Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35474a3f230Smrg # dummy dependency, to avoid the deleted-header problem. 35574a3f230Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356b3307321Smrg rm -f "$tmpdepfile" 357b3307321Smrg ;; 358b3307321Smrg 35974a3f230Smrg## The order of this option in the case statement is important, since the 36074a3f230Smrg## shell code in configure will try each of these formats in the order 36174a3f230Smrg## listed in this file. A plain '-MD' option would be understood by many 36274a3f230Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36374a3f230Smrgpgcc) 36474a3f230Smrg # Portland's C compiler understands '-MD'. 36574a3f230Smrg # Will always output deps to 'file.d' where file is the root name of the 36674a3f230Smrg # source file under compilation, even if file resides in a subdirectory. 36774a3f230Smrg # The object file name does not affect the name of the '.d' file. 36874a3f230Smrg # pgcc 10.2 will output 369b3307321Smrg # foo.o: sub/foo.c sub/foo.h 37074a3f230Smrg # and will wrap long lines using '\' : 371b3307321Smrg # foo.o: sub/foo.c ... \ 372b3307321Smrg # sub/foo.h ... \ 373b3307321Smrg # ... 37474a3f230Smrg set_dir_from "$object" 37574a3f230Smrg # Use the source, not the object, to determine the base name, since 37674a3f230Smrg # that's sadly what pgcc will do too. 37774a3f230Smrg set_base_from "$source" 37874a3f230Smrg tmpdepfile=$base.d 37974a3f230Smrg 38074a3f230Smrg # For projects that build the same source file twice into different object 38174a3f230Smrg # files, the pgcc approach of using the *source* file root name can cause 38274a3f230Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38374a3f230Smrg # the same $tmpdepfile. 38474a3f230Smrg lockdir=$base.d-lock 38574a3f230Smrg trap " 38674a3f230Smrg echo '$0: caught signal, cleaning up...' >&2 38774a3f230Smrg rmdir '$lockdir' 38874a3f230Smrg exit 1 38974a3f230Smrg " 1 2 13 15 39074a3f230Smrg numtries=100 39174a3f230Smrg i=$numtries 39274a3f230Smrg while test $i -gt 0; do 39374a3f230Smrg # mkdir is a portable test-and-set. 39474a3f230Smrg if mkdir "$lockdir" 2>/dev/null; then 39574a3f230Smrg # This process acquired the lock. 39674a3f230Smrg "$@" -MD 39774a3f230Smrg stat=$? 39874a3f230Smrg # Release the lock. 39974a3f230Smrg rmdir "$lockdir" 40074a3f230Smrg break 40174a3f230Smrg else 40274a3f230Smrg # If the lock is being held by a different process, wait 40374a3f230Smrg # until the winning process is done or we timeout. 40474a3f230Smrg while test -d "$lockdir" && test $i -gt 0; do 40574a3f230Smrg sleep 1 40674a3f230Smrg i=`expr $i - 1` 40774a3f230Smrg done 40874a3f230Smrg fi 40974a3f230Smrg i=`expr $i - 1` 41074a3f230Smrg done 41174a3f230Smrg trap - 1 2 13 15 41274a3f230Smrg if test $i -le 0; then 41374a3f230Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41474a3f230Smrg echo "$0: check lockdir '$lockdir'" >&2 41574a3f230Smrg exit 1 41674a3f230Smrg fi 417b3307321Smrg 41874a3f230Smrg if test $stat -ne 0; then 419b3307321Smrg rm -f "$tmpdepfile" 420b3307321Smrg exit $stat 421b3307321Smrg fi 422b3307321Smrg rm -f "$depfile" 423b3307321Smrg # Each line is of the form `foo.o: dependent.h', 424b3307321Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425b3307321Smrg # Do two passes, one to just change these to 426b3307321Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427b3307321Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428b3307321Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429b3307321Smrg # correctly. Breaking it into two sed invocations is a workaround. 43074a3f230Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43174a3f230Smrg | sed -e 's/$/ :/' >> "$depfile" 432b3307321Smrg rm -f "$tmpdepfile" 433b3307321Smrg ;; 434b3307321Smrg 435afe13c8eSmrghp2) 436afe13c8eSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437afe13c8eSmrg # compilers, which have integrated preprocessors. The correct option 438afe13c8eSmrg # to use with these is +Maked; it writes dependencies to a file named 439afe13c8eSmrg # 'foo.d', which lands next to the object file, wherever that 440afe13c8eSmrg # happens to be. 441afe13c8eSmrg # Much of this is similar to the tru64 case; see comments there. 44274a3f230Smrg set_dir_from "$object" 44374a3f230Smrg set_base_from "$object" 444afe13c8eSmrg if test "$libtool" = yes; then 445afe13c8eSmrg tmpdepfile1=$dir$base.d 446afe13c8eSmrg tmpdepfile2=$dir.libs/$base.d 447afe13c8eSmrg "$@" -Wc,+Maked 448afe13c8eSmrg else 449afe13c8eSmrg tmpdepfile1=$dir$base.d 450afe13c8eSmrg tmpdepfile2=$dir$base.d 451afe13c8eSmrg "$@" +Maked 452afe13c8eSmrg fi 453afe13c8eSmrg stat=$? 45474a3f230Smrg if test $stat -ne 0; then 455afe13c8eSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456afe13c8eSmrg exit $stat 457afe13c8eSmrg fi 458afe13c8eSmrg 459afe13c8eSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460afe13c8eSmrg do 461afe13c8eSmrg test -f "$tmpdepfile" && break 462afe13c8eSmrg done 463afe13c8eSmrg if test -f "$tmpdepfile"; then 46474a3f230Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46574a3f230Smrg # Add 'dependent.h:' lines. 4665e358ecaSmrg sed -ne '2,${ 46774a3f230Smrg s/^ *// 46874a3f230Smrg s/ \\*$// 46974a3f230Smrg s/$/:/ 47074a3f230Smrg p 47174a3f230Smrg }' "$tmpdepfile" >> "$depfile" 472afe13c8eSmrg else 47374a3f230Smrg make_dummy_depfile 474afe13c8eSmrg fi 475afe13c8eSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 476afe13c8eSmrg ;; 477afe13c8eSmrg 478b3307321Smrgtru64) 47974a3f230Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48074a3f230Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48174a3f230Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48274a3f230Smrg # dependencies in 'foo.d' instead, so we check for that too. 48374a3f230Smrg # Subdirectories are respected. 48474a3f230Smrg set_dir_from "$object" 48574a3f230Smrg set_base_from "$object" 48674a3f230Smrg 48774a3f230Smrg if test "$libtool" = yes; then 48874a3f230Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48974a3f230Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49074a3f230Smrg # in $dir$base.o.d. We have to check for both files, because 49174a3f230Smrg # one of the two compilations can be disabled. We should prefer 49274a3f230Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49374a3f230Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49474a3f230Smrg # the former would cause a distcleancheck panic. 49574a3f230Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49674a3f230Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49774a3f230Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49874a3f230Smrg "$@" -Wc,-MD 49974a3f230Smrg else 50074a3f230Smrg tmpdepfile1=$dir$base.d 50174a3f230Smrg tmpdepfile2=$dir$base.d 50274a3f230Smrg tmpdepfile3=$dir$base.d 50374a3f230Smrg "$@" -MD 50474a3f230Smrg fi 50574a3f230Smrg 50674a3f230Smrg stat=$? 50774a3f230Smrg if test $stat -ne 0; then 50874a3f230Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50974a3f230Smrg exit $stat 51074a3f230Smrg fi 51174a3f230Smrg 51274a3f230Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51374a3f230Smrg do 51474a3f230Smrg test -f "$tmpdepfile" && break 51574a3f230Smrg done 51674a3f230Smrg # Same post-processing that is required for AIX mode. 51774a3f230Smrg aix_post_process_depfile 51874a3f230Smrg ;; 51974a3f230Smrg 52074a3f230Smrgmsvc7) 52174a3f230Smrg if test "$libtool" = yes; then 52274a3f230Smrg showIncludes=-Wc,-showIncludes 52374a3f230Smrg else 52474a3f230Smrg showIncludes=-showIncludes 52574a3f230Smrg fi 52674a3f230Smrg "$@" $showIncludes > "$tmpdepfile" 52774a3f230Smrg stat=$? 52874a3f230Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52974a3f230Smrg if test $stat -ne 0; then 53074a3f230Smrg rm -f "$tmpdepfile" 53174a3f230Smrg exit $stat 53274a3f230Smrg fi 53374a3f230Smrg rm -f "$depfile" 53474a3f230Smrg echo "$object : \\" > "$depfile" 53574a3f230Smrg # The first sed program below extracts the file names and escapes 53674a3f230Smrg # backslashes for cygpath. The second sed program outputs the file 53774a3f230Smrg # name when reading, but also accumulates all include files in the 53874a3f230Smrg # hold buffer in order to output them again at the end. This only 53974a3f230Smrg # works with sed implementations that can handle large buffers. 54074a3f230Smrg sed < "$tmpdepfile" -n ' 54174a3f230Smrg/^Note: including file: *\(.*\)/ { 54274a3f230Smrg s//\1/ 54374a3f230Smrg s/\\/\\\\/g 54474a3f230Smrg p 54574a3f230Smrg}' | $cygpath_u | sort -u | sed -n ' 54674a3f230Smrgs/ /\\ /g 54774a3f230Smrgs/\(.*\)/'"$tab"'\1 \\/p 54874a3f230Smrgs/.\(.*\) \\/\1:/ 54974a3f230SmrgH 55074a3f230Smrg$ { 55174a3f230Smrg s/.*/'"$tab"'/ 55274a3f230Smrg G 55374a3f230Smrg p 55474a3f230Smrg}' >> "$depfile" 55574a3f230Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55674a3f230Smrg rm -f "$tmpdepfile" 55774a3f230Smrg ;; 55874a3f230Smrg 55974a3f230Smrgmsvc7msys) 56074a3f230Smrg # This case exists only to let depend.m4 do its work. It works by 56174a3f230Smrg # looking at the text of this script. This case will never be run, 56274a3f230Smrg # since it is checked for above. 56374a3f230Smrg exit 1 56474a3f230Smrg ;; 565b3307321Smrg 566b3307321Smrg#nosideeffect) 567b3307321Smrg # This comment above is used by automake to tell side-effect 568b3307321Smrg # dependency tracking mechanisms from slower ones. 569b3307321Smrg 570b3307321Smrgdashmstdout) 571b3307321Smrg # Important note: in order to support this mode, a compiler *must* 572b3307321Smrg # always write the preprocessed file to stdout, regardless of -o. 573b3307321Smrg "$@" || exit $? 574b3307321Smrg 575b3307321Smrg # Remove the call to Libtool. 576b3307321Smrg if test "$libtool" = yes; then 5775e358ecaSmrg while test "X$1" != 'X--mode=compile'; do 578b3307321Smrg shift 579b3307321Smrg done 580b3307321Smrg shift 581b3307321Smrg fi 582b3307321Smrg 58374a3f230Smrg # Remove '-o $object'. 584b3307321Smrg IFS=" " 585b3307321Smrg for arg 586b3307321Smrg do 587b3307321Smrg case $arg in 588b3307321Smrg -o) 589b3307321Smrg shift 590b3307321Smrg ;; 591b3307321Smrg $object) 592b3307321Smrg shift 593b3307321Smrg ;; 594b3307321Smrg *) 595b3307321Smrg set fnord "$@" "$arg" 596b3307321Smrg shift # fnord 597b3307321Smrg shift # $arg 598b3307321Smrg ;; 599b3307321Smrg esac 600b3307321Smrg done 601b3307321Smrg 602b3307321Smrg test -z "$dashmflag" && dashmflag=-M 60374a3f230Smrg # Require at least two characters before searching for ':' 604b3307321Smrg # in the target name. This is to cope with DOS-style filenames: 60574a3f230Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606b3307321Smrg "$@" $dashmflag | 60774a3f230Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608b3307321Smrg rm -f "$depfile" 609b3307321Smrg cat < "$tmpdepfile" > "$depfile" 61074a3f230Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61174a3f230Smrg # correctly. Breaking it into two sed invocations is a workaround. 61274a3f230Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61374a3f230Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61474a3f230Smrg | sed -e 's/$/ :/' >> "$depfile" 615b3307321Smrg rm -f "$tmpdepfile" 616b3307321Smrg ;; 617b3307321Smrg 618b3307321SmrgdashXmstdout) 619b3307321Smrg # This case only exists to satisfy depend.m4. It is never actually 620b3307321Smrg # run, as this mode is specially recognized in the preamble. 621b3307321Smrg exit 1 622b3307321Smrg ;; 623b3307321Smrg 624b3307321Smrgmakedepend) 625b3307321Smrg "$@" || exit $? 626b3307321Smrg # Remove any Libtool call 627b3307321Smrg if test "$libtool" = yes; then 6285e358ecaSmrg while test "X$1" != 'X--mode=compile'; do 629b3307321Smrg shift 630b3307321Smrg done 631b3307321Smrg shift 632b3307321Smrg fi 633b3307321Smrg # X makedepend 634b3307321Smrg shift 6355e358ecaSmrg cleared=no eat=no 6365e358ecaSmrg for arg 6375e358ecaSmrg do 638b3307321Smrg case $cleared in 639b3307321Smrg no) 640b3307321Smrg set ""; shift 641b3307321Smrg cleared=yes ;; 642b3307321Smrg esac 6435e358ecaSmrg if test $eat = yes; then 6445e358ecaSmrg eat=no 6455e358ecaSmrg continue 6465e358ecaSmrg fi 647b3307321Smrg case "$arg" in 648b3307321Smrg -D*|-I*) 649b3307321Smrg set fnord "$@" "$arg"; shift ;; 650b3307321Smrg # Strip any option that makedepend may not understand. Remove 651b3307321Smrg # the object too, otherwise makedepend will parse it as a source file. 6525e358ecaSmrg -arch) 6535e358ecaSmrg eat=yes ;; 654b3307321Smrg -*|$object) 655b3307321Smrg ;; 656b3307321Smrg *) 657b3307321Smrg set fnord "$@" "$arg"; shift ;; 658b3307321Smrg esac 659b3307321Smrg done 6605e358ecaSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661b3307321Smrg touch "$tmpdepfile" 662b3307321Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663b3307321Smrg rm -f "$depfile" 66474a3f230Smrg # makedepend may prepend the VPATH from the source file name to the object. 66574a3f230Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66674a3f230Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66774a3f230Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66874a3f230Smrg # correctly. Breaking it into two sed invocations is a workaround. 66974a3f230Smrg sed '1,2d' "$tmpdepfile" \ 67074a3f230Smrg | tr ' ' "$nl" \ 67174a3f230Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67274a3f230Smrg | sed -e 's/$/ :/' >> "$depfile" 673b3307321Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674b3307321Smrg ;; 675b3307321Smrg 676b3307321Smrgcpp) 677b3307321Smrg # Important note: in order to support this mode, a compiler *must* 678b3307321Smrg # always write the preprocessed file to stdout. 679b3307321Smrg "$@" || exit $? 680b3307321Smrg 681b3307321Smrg # Remove the call to Libtool. 682b3307321Smrg if test "$libtool" = yes; then 6835e358ecaSmrg while test "X$1" != 'X--mode=compile'; do 684b3307321Smrg shift 685b3307321Smrg done 686b3307321Smrg shift 687b3307321Smrg fi 688b3307321Smrg 68974a3f230Smrg # Remove '-o $object'. 690b3307321Smrg IFS=" " 691b3307321Smrg for arg 692b3307321Smrg do 693b3307321Smrg case $arg in 694b3307321Smrg -o) 695b3307321Smrg shift 696b3307321Smrg ;; 697b3307321Smrg $object) 698b3307321Smrg shift 699b3307321Smrg ;; 700b3307321Smrg *) 701b3307321Smrg set fnord "$@" "$arg" 702b3307321Smrg shift # fnord 703b3307321Smrg shift # $arg 704b3307321Smrg ;; 705b3307321Smrg esac 706b3307321Smrg done 707b3307321Smrg 70874a3f230Smrg "$@" -E \ 70974a3f230Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71074a3f230Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71174a3f230Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712b3307321Smrg rm -f "$depfile" 713b3307321Smrg echo "$object : \\" > "$depfile" 714b3307321Smrg cat < "$tmpdepfile" >> "$depfile" 715b3307321Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716b3307321Smrg rm -f "$tmpdepfile" 717b3307321Smrg ;; 718b3307321Smrg 719b3307321Smrgmsvisualcpp) 720b3307321Smrg # Important note: in order to support this mode, a compiler *must* 7215e358ecaSmrg # always write the preprocessed file to stdout. 722b3307321Smrg "$@" || exit $? 7235e358ecaSmrg 7245e358ecaSmrg # Remove the call to Libtool. 7255e358ecaSmrg if test "$libtool" = yes; then 7265e358ecaSmrg while test "X$1" != 'X--mode=compile'; do 7275e358ecaSmrg shift 7285e358ecaSmrg done 7295e358ecaSmrg shift 7305e358ecaSmrg fi 7315e358ecaSmrg 732b3307321Smrg IFS=" " 733b3307321Smrg for arg 734b3307321Smrg do 735b3307321Smrg case "$arg" in 7365e358ecaSmrg -o) 7375e358ecaSmrg shift 7385e358ecaSmrg ;; 7395e358ecaSmrg $object) 7405e358ecaSmrg shift 7415e358ecaSmrg ;; 742b3307321Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74374a3f230Smrg set fnord "$@" 74474a3f230Smrg shift 74574a3f230Smrg shift 74674a3f230Smrg ;; 747b3307321Smrg *) 74874a3f230Smrg set fnord "$@" "$arg" 74974a3f230Smrg shift 75074a3f230Smrg shift 75174a3f230Smrg ;; 752b3307321Smrg esac 753b3307321Smrg done 7545e358ecaSmrg "$@" -E 2>/dev/null | 7555e358ecaSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756b3307321Smrg rm -f "$depfile" 757b3307321Smrg echo "$object : \\" > "$depfile" 75874a3f230Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75974a3f230Smrg echo "$tab" >> "$depfile" 7605e358ecaSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761b3307321Smrg rm -f "$tmpdepfile" 762b3307321Smrg ;; 763b3307321Smrg 7645e358ecaSmrgmsvcmsys) 7655e358ecaSmrg # This case exists only to let depend.m4 do its work. It works by 7665e358ecaSmrg # looking at the text of this script. This case will never be run, 7675e358ecaSmrg # since it is checked for above. 7685e358ecaSmrg exit 1 7695e358ecaSmrg ;; 7705e358ecaSmrg 771b3307321Smrgnone) 772b3307321Smrg exec "$@" 773b3307321Smrg ;; 774b3307321Smrg 775b3307321Smrg*) 776b3307321Smrg echo "Unknown depmode $depmode" 1>&2 777b3307321Smrg exit 1 778b3307321Smrg ;; 779b3307321Smrgesac 780b3307321Smrg 781b3307321Smrgexit 0 782afe13c8eSmrg 783afe13c8eSmrg# Local Variables: 784afe13c8eSmrg# mode: shell-script 785afe13c8eSmrg# sh-indentation: 2 78674b97a6cSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 787afe13c8eSmrg# time-stamp-start: "scriptversion=" 788afe13c8eSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78974b97a6cSmrg# time-stamp-time-zone: "UTC0" 7905e358ecaSmrg# time-stamp-end: "; # UTC" 791afe13c8eSmrg# End: 792