1a0195d5fSmrg#! /bin/sh 2a0195d5fSmrg# depcomp - compile a program generating dependencies as side-effects 3a0195d5fSmrg 40f5b81e5Smrgscriptversion=2018-03-07.03; # UTC 5a0195d5fSmrg 60f5b81e5Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7a0195d5fSmrg 8a0195d5fSmrg# This program is free software; you can redistribute it and/or modify 9a0195d5fSmrg# it under the terms of the GNU General Public License as published by 10a0195d5fSmrg# the Free Software Foundation; either version 2, or (at your option) 11a0195d5fSmrg# any later version. 12a0195d5fSmrg 13a0195d5fSmrg# This program is distributed in the hope that it will be useful, 14a0195d5fSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15a0195d5fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a0195d5fSmrg# GNU General Public License for more details. 17a0195d5fSmrg 18a0195d5fSmrg# You should have received a copy of the GNU General Public License 190f5b81e5Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20a0195d5fSmrg 21a0195d5fSmrg# As a special exception to the GNU General Public License, if you 22a0195d5fSmrg# distribute this file as part of a program that contains a 23a0195d5fSmrg# configuration script generated by Autoconf, you may include it under 24a0195d5fSmrg# the same distribution terms that you use for the rest of that program. 25a0195d5fSmrg 26a0195d5fSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27a0195d5fSmrg 28a0195d5fSmrgcase $1 in 29a0195d5fSmrg '') 3040a76396Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3140a76396Smrg exit 1; 3240a76396Smrg ;; 33a0195d5fSmrg -h | --h*) 34a0195d5fSmrg cat <<\EOF 35a0195d5fSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36a0195d5fSmrg 37a0195d5fSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38a0195d5fSmrgas side-effects. 39a0195d5fSmrg 40a0195d5fSmrgEnvironment variables: 41a0195d5fSmrg depmode Dependency tracking mode. 4240a76396Smrg source Source file read by 'PROGRAMS ARGS'. 4340a76396Smrg object Object file output by 'PROGRAMS ARGS'. 44a0195d5fSmrg DEPDIR directory where to store dependencies. 45a0195d5fSmrg depfile Dependency file to output. 4640a76396Smrg tmpdepfile Temporary file to use when outputting dependencies. 47a0195d5fSmrg libtool Whether libtool is used (yes/no). 48a0195d5fSmrg 49a0195d5fSmrgReport bugs to <bug-automake@gnu.org>. 50a0195d5fSmrgEOF 51a0195d5fSmrg exit $? 52a0195d5fSmrg ;; 53a0195d5fSmrg -v | --v*) 54a0195d5fSmrg echo "depcomp $scriptversion" 55a0195d5fSmrg exit $? 56a0195d5fSmrg ;; 57a0195d5fSmrgesac 58a0195d5fSmrg 5940a76396Smrg# Get the directory component of the given path, and save it in the 6040a76396Smrg# global variables '$dir'. Note that this directory component will 6140a76396Smrg# be either empty or ending with a '/' character. This is deliberate. 6240a76396Smrgset_dir_from () 6340a76396Smrg{ 6440a76396Smrg case $1 in 6540a76396Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6640a76396Smrg *) dir=;; 6740a76396Smrg esac 6840a76396Smrg} 6940a76396Smrg 7040a76396Smrg# Get the suffix-stripped basename of the given path, and save it the 7140a76396Smrg# global variable '$base'. 7240a76396Smrgset_base_from () 7340a76396Smrg{ 7440a76396Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7540a76396Smrg} 7640a76396Smrg 7740a76396Smrg# If no dependency file was actually created by the compiler invocation, 7840a76396Smrg# we still have to create a dummy depfile, to avoid errors with the 7940a76396Smrg# Makefile "include basename.Plo" scheme. 8040a76396Smrgmake_dummy_depfile () 8140a76396Smrg{ 8240a76396Smrg echo "#dummy" > "$depfile" 8340a76396Smrg} 8440a76396Smrg 8540a76396Smrg# Factor out some common post-processing of the generated depfile. 8640a76396Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8740a76396Smrgaix_post_process_depfile () 8840a76396Smrg{ 8940a76396Smrg # If the compiler actually managed to produce a dependency file, 9040a76396Smrg # post-process it. 9140a76396Smrg if test -f "$tmpdepfile"; then 9240a76396Smrg # Each line is of the form 'foo.o: dependency.h'. 9340a76396Smrg # Do two passes, one to just change these to 9440a76396Smrg # $object: dependency.h 9540a76396Smrg # and one to simply output 9640a76396Smrg # dependency.h: 9740a76396Smrg # which is needed to avoid the deleted-header problem. 9840a76396Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9940a76396Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10040a76396Smrg } > "$depfile" 10140a76396Smrg rm -f "$tmpdepfile" 10240a76396Smrg else 10340a76396Smrg make_dummy_depfile 10440a76396Smrg fi 10540a76396Smrg} 10640a76396Smrg 10740a76396Smrg# A tabulation character. 10840a76396Smrgtab=' ' 10940a76396Smrg# A newline character. 11040a76396Smrgnl=' 11140a76396Smrg' 11240a76396Smrg# Character ranges might be problematic outside the C locale. 11340a76396Smrg# These definitions help. 11440a76396Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11540a76396Smrglower=abcdefghijklmnopqrstuvwxyz 11640a76396Smrgdigits=0123456789 11740a76396Smrgalpha=${upper}${lower} 11840a76396Smrg 119a0195d5fSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120a0195d5fSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121a0195d5fSmrg exit 1 122a0195d5fSmrgfi 123a0195d5fSmrg 124a0195d5fSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125a0195d5fSmrgdepfile=${depfile-`echo "$object" | 126a0195d5fSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127a0195d5fSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128a0195d5fSmrg 129a0195d5fSmrgrm -f "$tmpdepfile" 130a0195d5fSmrg 13140a76396Smrg# Avoid interferences from the environment. 13240a76396Smrggccflag= dashmflag= 13340a76396Smrg 134a0195d5fSmrg# Some modes work just like other modes, but use different flags. We 135a0195d5fSmrg# parameterize here, but still list the modes in the big case below, 136a0195d5fSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137a0195d5fSmrg# here, because this file can only contain one case statement. 138a0195d5fSmrgif test "$depmode" = hp; then 139a0195d5fSmrg # HP compiler uses -M and no extra arg. 140a0195d5fSmrg gccflag=-M 141a0195d5fSmrg depmode=gcc 142a0195d5fSmrgfi 143a0195d5fSmrg 144a0195d5fSmrgif test "$depmode" = dashXmstdout; then 14540a76396Smrg # This is just like dashmstdout with a different argument. 14640a76396Smrg dashmflag=-xM 14740a76396Smrg depmode=dashmstdout 148a0195d5fSmrgfi 149a0195d5fSmrg 1506600fe5bSmrgcygpath_u="cygpath -u -f -" 1516600fe5bSmrgif test "$depmode" = msvcmsys; then 15240a76396Smrg # This is just like msvisualcpp but w/o cygpath translation. 15340a76396Smrg # Just convert the backslash-escaped backslashes to single forward 15440a76396Smrg # slashes to satisfy depend.m4 15540a76396Smrg cygpath_u='sed s,\\\\,/,g' 15640a76396Smrg depmode=msvisualcpp 15740a76396Smrgfi 15840a76396Smrg 15940a76396Smrgif test "$depmode" = msvc7msys; then 16040a76396Smrg # This is just like msvc7 but w/o cygpath translation. 16140a76396Smrg # Just convert the backslash-escaped backslashes to single forward 16240a76396Smrg # slashes to satisfy depend.m4 16340a76396Smrg cygpath_u='sed s,\\\\,/,g' 16440a76396Smrg depmode=msvc7 16540a76396Smrgfi 16640a76396Smrg 16740a76396Smrgif test "$depmode" = xlc; then 16840a76396Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16940a76396Smrg gccflag=-qmakedep=gcc,-MF 17040a76396Smrg depmode=gcc 1716600fe5bSmrgfi 1726600fe5bSmrg 173a0195d5fSmrgcase "$depmode" in 174a0195d5fSmrggcc3) 175a0195d5fSmrg## gcc 3 implements dependency tracking that does exactly what 176a0195d5fSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177a0195d5fSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 178a0195d5fSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179a0195d5fSmrg## the command line argument order; so add the flags where they 180a0195d5fSmrg## appear in depend2.am. Note that the slowdown incurred here 181a0195d5fSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182a0195d5fSmrg for arg 183a0195d5fSmrg do 184a0195d5fSmrg case $arg in 185a0195d5fSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186a0195d5fSmrg *) set fnord "$@" "$arg" ;; 187a0195d5fSmrg esac 188a0195d5fSmrg shift # fnord 189a0195d5fSmrg shift # $arg 190a0195d5fSmrg done 191a0195d5fSmrg "$@" 192a0195d5fSmrg stat=$? 19340a76396Smrg if test $stat -ne 0; then 194a0195d5fSmrg rm -f "$tmpdepfile" 195a0195d5fSmrg exit $stat 196a0195d5fSmrg fi 197a0195d5fSmrg mv "$tmpdepfile" "$depfile" 198a0195d5fSmrg ;; 199a0195d5fSmrg 200a0195d5fSmrggcc) 20140a76396Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20240a76396Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20340a76396Smrg## (see the conditional assignment to $gccflag above). 204a0195d5fSmrg## There are various ways to get dependency output from gcc. Here's 205a0195d5fSmrg## why we pick this rather obscure method: 206a0195d5fSmrg## - Don't want to use -MD because we'd like the dependencies to end 207a0195d5fSmrg## up in a subdir. Having to rename by hand is ugly. 208a0195d5fSmrg## (We might end up doing this anyway to support other compilers.) 209a0195d5fSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21040a76396Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21140a76396Smrg## supported by the other compilers which use the 'gcc' depmode. 212a0195d5fSmrg## - Using -M directly means running the compiler twice (even worse 213a0195d5fSmrg## than renaming). 214a0195d5fSmrg if test -z "$gccflag"; then 215a0195d5fSmrg gccflag=-MD, 216a0195d5fSmrg fi 217a0195d5fSmrg "$@" -Wp,"$gccflag$tmpdepfile" 218a0195d5fSmrg stat=$? 21940a76396Smrg if test $stat -ne 0; then 220a0195d5fSmrg rm -f "$tmpdepfile" 221a0195d5fSmrg exit $stat 222a0195d5fSmrg fi 223a0195d5fSmrg rm -f "$depfile" 224a0195d5fSmrg echo "$object : \\" > "$depfile" 22540a76396Smrg # The second -e expression handles DOS-style file names with drive 22640a76396Smrg # letters. 227a0195d5fSmrg sed -e 's/^[^:]*: / /' \ 228a0195d5fSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22940a76396Smrg## This next piece of magic avoids the "deleted header file" problem. 230a0195d5fSmrg## The problem is that when a header file which appears in a .P file 231a0195d5fSmrg## is deleted, the dependency causes make to die (because there is 232a0195d5fSmrg## typically no way to rebuild the header). We avoid this by adding 233a0195d5fSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 234a0195d5fSmrg## this for us directly. 23540a76396Smrg## Some versions of gcc put a space before the ':'. On the theory 236a0195d5fSmrg## that the space means something, we add a space to the output as 23740a76396Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23840a76396Smrg## to the object. Take care to not repeat it in the output. 239a0195d5fSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 240a0195d5fSmrg## correctly. Breaking it into two sed invocations is a workaround. 24140a76396Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24240a76396Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24340a76396Smrg | sed -e 's/$/ :/' >> "$depfile" 244a0195d5fSmrg rm -f "$tmpdepfile" 245a0195d5fSmrg ;; 246a0195d5fSmrg 247a0195d5fSmrghp) 248a0195d5fSmrg # This case exists only to let depend.m4 do its work. It works by 249a0195d5fSmrg # looking at the text of this script. This case will never be run, 250a0195d5fSmrg # since it is checked for above. 251a0195d5fSmrg exit 1 252a0195d5fSmrg ;; 253a0195d5fSmrg 254a0195d5fSmrgsgi) 255a0195d5fSmrg if test "$libtool" = yes; then 256a0195d5fSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257a0195d5fSmrg else 258a0195d5fSmrg "$@" -MDupdate "$tmpdepfile" 259a0195d5fSmrg fi 260a0195d5fSmrg stat=$? 26140a76396Smrg if test $stat -ne 0; then 262a0195d5fSmrg rm -f "$tmpdepfile" 263a0195d5fSmrg exit $stat 264a0195d5fSmrg fi 265a0195d5fSmrg rm -f "$depfile" 266a0195d5fSmrg 267a0195d5fSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268a0195d5fSmrg echo "$object : \\" > "$depfile" 269a0195d5fSmrg # Clip off the initial element (the dependent). Don't try to be 270a0195d5fSmrg # clever and replace this with sed code, as IRIX sed won't handle 271a0195d5fSmrg # lines with more than a fixed number of characters (4096 in 272a0195d5fSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27340a76396Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274a0195d5fSmrg # dependency line. 27540a76396Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27640a76396Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27740a76396Smrg | tr "$nl" ' ' >> "$depfile" 2786600fe5bSmrg echo >> "$depfile" 279a0195d5fSmrg # The second pass generates a dummy entry for each header file. 28040a76396Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28140a76396Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28240a76396Smrg >> "$depfile" 283a0195d5fSmrg else 28440a76396Smrg make_dummy_depfile 285a0195d5fSmrg fi 286a0195d5fSmrg rm -f "$tmpdepfile" 287a0195d5fSmrg ;; 288a0195d5fSmrg 28940a76396Smrgxlc) 29040a76396Smrg # This case exists only to let depend.m4 do its work. It works by 29140a76396Smrg # looking at the text of this script. This case will never be run, 29240a76396Smrg # since it is checked for above. 29340a76396Smrg exit 1 29440a76396Smrg ;; 29540a76396Smrg 296a0195d5fSmrgaix) 297a0195d5fSmrg # The C for AIX Compiler uses -M and outputs the dependencies 298a0195d5fSmrg # in a .u file. In older versions, this file always lives in the 29940a76396Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300a0195d5fSmrg # start of each line; $object doesn't have directory information. 301a0195d5fSmrg # Version 6 uses the directory in both cases. 30240a76396Smrg set_dir_from "$object" 30340a76396Smrg set_base_from "$object" 304a0195d5fSmrg if test "$libtool" = yes; then 305a0195d5fSmrg tmpdepfile1=$dir$base.u 306a0195d5fSmrg tmpdepfile2=$base.u 307a0195d5fSmrg tmpdepfile3=$dir.libs/$base.u 308a0195d5fSmrg "$@" -Wc,-M 309a0195d5fSmrg else 310a0195d5fSmrg tmpdepfile1=$dir$base.u 311a0195d5fSmrg tmpdepfile2=$dir$base.u 312a0195d5fSmrg tmpdepfile3=$dir$base.u 313a0195d5fSmrg "$@" -M 314a0195d5fSmrg fi 315a0195d5fSmrg stat=$? 31640a76396Smrg if test $stat -ne 0; then 317a0195d5fSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318a0195d5fSmrg exit $stat 319a0195d5fSmrg fi 320a0195d5fSmrg 321a0195d5fSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322a0195d5fSmrg do 323a0195d5fSmrg test -f "$tmpdepfile" && break 324a0195d5fSmrg done 32540a76396Smrg aix_post_process_depfile 32640a76396Smrg ;; 32740a76396Smrg 32840a76396Smrgtcc) 32940a76396Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33040a76396Smrg # FIXME: That version still under development at the moment of writing. 33140a76396Smrg # Make that this statement remains true also for stable, released 33240a76396Smrg # versions. 33340a76396Smrg # It will wrap lines (doesn't matter whether long or short) with a 33440a76396Smrg # trailing '\', as in: 33540a76396Smrg # 33640a76396Smrg # foo.o : \ 33740a76396Smrg # foo.c \ 33840a76396Smrg # foo.h \ 33940a76396Smrg # 34040a76396Smrg # It will put a trailing '\' even on the last line, and will use leading 34140a76396Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34240a76396Smrg # "Emit spaces for -MD"). 34340a76396Smrg "$@" -MD -MF "$tmpdepfile" 34440a76396Smrg stat=$? 34540a76396Smrg if test $stat -ne 0; then 34640a76396Smrg rm -f "$tmpdepfile" 34740a76396Smrg exit $stat 348a0195d5fSmrg fi 34940a76396Smrg rm -f "$depfile" 35040a76396Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35140a76396Smrg # We have to change lines of the first kind to '$object: \'. 35240a76396Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35340a76396Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35440a76396Smrg # dummy dependency, to avoid the deleted-header problem. 35540a76396Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356a0195d5fSmrg rm -f "$tmpdepfile" 357a0195d5fSmrg ;; 358a0195d5fSmrg 35940a76396Smrg## The order of this option in the case statement is important, since the 36040a76396Smrg## shell code in configure will try each of these formats in the order 36140a76396Smrg## listed in this file. A plain '-MD' option would be understood by many 36240a76396Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36340a76396Smrgpgcc) 36440a76396Smrg # Portland's C compiler understands '-MD'. 36540a76396Smrg # Will always output deps to 'file.d' where file is the root name of the 36640a76396Smrg # source file under compilation, even if file resides in a subdirectory. 36740a76396Smrg # The object file name does not affect the name of the '.d' file. 36840a76396Smrg # pgcc 10.2 will output 369a0195d5fSmrg # foo.o: sub/foo.c sub/foo.h 37040a76396Smrg # and will wrap long lines using '\' : 371a0195d5fSmrg # foo.o: sub/foo.c ... \ 372a0195d5fSmrg # sub/foo.h ... \ 373a0195d5fSmrg # ... 37440a76396Smrg set_dir_from "$object" 37540a76396Smrg # Use the source, not the object, to determine the base name, since 37640a76396Smrg # that's sadly what pgcc will do too. 37740a76396Smrg set_base_from "$source" 37840a76396Smrg tmpdepfile=$base.d 37940a76396Smrg 38040a76396Smrg # For projects that build the same source file twice into different object 38140a76396Smrg # files, the pgcc approach of using the *source* file root name can cause 38240a76396Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38340a76396Smrg # the same $tmpdepfile. 38440a76396Smrg lockdir=$base.d-lock 38540a76396Smrg trap " 38640a76396Smrg echo '$0: caught signal, cleaning up...' >&2 38740a76396Smrg rmdir '$lockdir' 38840a76396Smrg exit 1 38940a76396Smrg " 1 2 13 15 39040a76396Smrg numtries=100 39140a76396Smrg i=$numtries 39240a76396Smrg while test $i -gt 0; do 39340a76396Smrg # mkdir is a portable test-and-set. 39440a76396Smrg if mkdir "$lockdir" 2>/dev/null; then 39540a76396Smrg # This process acquired the lock. 39640a76396Smrg "$@" -MD 39740a76396Smrg stat=$? 39840a76396Smrg # Release the lock. 39940a76396Smrg rmdir "$lockdir" 40040a76396Smrg break 40140a76396Smrg else 40240a76396Smrg # If the lock is being held by a different process, wait 40340a76396Smrg # until the winning process is done or we timeout. 40440a76396Smrg while test -d "$lockdir" && test $i -gt 0; do 40540a76396Smrg sleep 1 40640a76396Smrg i=`expr $i - 1` 40740a76396Smrg done 40840a76396Smrg fi 40940a76396Smrg i=`expr $i - 1` 41040a76396Smrg done 41140a76396Smrg trap - 1 2 13 15 41240a76396Smrg if test $i -le 0; then 41340a76396Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41440a76396Smrg echo "$0: check lockdir '$lockdir'" >&2 41540a76396Smrg exit 1 41640a76396Smrg fi 417a0195d5fSmrg 41840a76396Smrg if test $stat -ne 0; then 419a0195d5fSmrg rm -f "$tmpdepfile" 420a0195d5fSmrg exit $stat 421a0195d5fSmrg fi 422a0195d5fSmrg rm -f "$depfile" 423a0195d5fSmrg # Each line is of the form `foo.o: dependent.h', 424a0195d5fSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425a0195d5fSmrg # Do two passes, one to just change these to 426a0195d5fSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427a0195d5fSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428a0195d5fSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429a0195d5fSmrg # correctly. Breaking it into two sed invocations is a workaround. 43040a76396Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43140a76396Smrg | sed -e 's/$/ :/' >> "$depfile" 432a0195d5fSmrg rm -f "$tmpdepfile" 433a0195d5fSmrg ;; 434a0195d5fSmrg 435a0195d5fSmrghp2) 436a0195d5fSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437a0195d5fSmrg # compilers, which have integrated preprocessors. The correct option 438a0195d5fSmrg # to use with these is +Maked; it writes dependencies to a file named 439a0195d5fSmrg # 'foo.d', which lands next to the object file, wherever that 440a0195d5fSmrg # happens to be. 441a0195d5fSmrg # Much of this is similar to the tru64 case; see comments there. 44240a76396Smrg set_dir_from "$object" 44340a76396Smrg set_base_from "$object" 444a0195d5fSmrg if test "$libtool" = yes; then 445a0195d5fSmrg tmpdepfile1=$dir$base.d 446a0195d5fSmrg tmpdepfile2=$dir.libs/$base.d 447a0195d5fSmrg "$@" -Wc,+Maked 448a0195d5fSmrg else 449a0195d5fSmrg tmpdepfile1=$dir$base.d 450a0195d5fSmrg tmpdepfile2=$dir$base.d 451a0195d5fSmrg "$@" +Maked 452a0195d5fSmrg fi 453a0195d5fSmrg stat=$? 45440a76396Smrg if test $stat -ne 0; then 455a0195d5fSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456a0195d5fSmrg exit $stat 457a0195d5fSmrg fi 458a0195d5fSmrg 459a0195d5fSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460a0195d5fSmrg do 461a0195d5fSmrg test -f "$tmpdepfile" && break 462a0195d5fSmrg done 463a0195d5fSmrg if test -f "$tmpdepfile"; then 46440a76396Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46540a76396Smrg # Add 'dependent.h:' lines. 4666600fe5bSmrg sed -ne '2,${ 46740a76396Smrg s/^ *// 46840a76396Smrg s/ \\*$// 46940a76396Smrg s/$/:/ 47040a76396Smrg p 47140a76396Smrg }' "$tmpdepfile" >> "$depfile" 472a0195d5fSmrg else 47340a76396Smrg make_dummy_depfile 474a0195d5fSmrg fi 475a0195d5fSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 476a0195d5fSmrg ;; 477a0195d5fSmrg 478a0195d5fSmrgtru64) 47940a76396Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48040a76396Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48140a76396Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48240a76396Smrg # dependencies in 'foo.d' instead, so we check for that too. 48340a76396Smrg # Subdirectories are respected. 48440a76396Smrg set_dir_from "$object" 48540a76396Smrg set_base_from "$object" 48640a76396Smrg 48740a76396Smrg if test "$libtool" = yes; then 48840a76396Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48940a76396Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49040a76396Smrg # in $dir$base.o.d. We have to check for both files, because 49140a76396Smrg # one of the two compilations can be disabled. We should prefer 49240a76396Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49340a76396Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49440a76396Smrg # the former would cause a distcleancheck panic. 49540a76396Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49640a76396Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49740a76396Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49840a76396Smrg "$@" -Wc,-MD 49940a76396Smrg else 50040a76396Smrg tmpdepfile1=$dir$base.d 50140a76396Smrg tmpdepfile2=$dir$base.d 50240a76396Smrg tmpdepfile3=$dir$base.d 50340a76396Smrg "$@" -MD 50440a76396Smrg fi 50540a76396Smrg 50640a76396Smrg stat=$? 50740a76396Smrg if test $stat -ne 0; then 50840a76396Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50940a76396Smrg exit $stat 51040a76396Smrg fi 51140a76396Smrg 51240a76396Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51340a76396Smrg do 51440a76396Smrg test -f "$tmpdepfile" && break 51540a76396Smrg done 51640a76396Smrg # Same post-processing that is required for AIX mode. 51740a76396Smrg aix_post_process_depfile 51840a76396Smrg ;; 51940a76396Smrg 52040a76396Smrgmsvc7) 52140a76396Smrg if test "$libtool" = yes; then 52240a76396Smrg showIncludes=-Wc,-showIncludes 52340a76396Smrg else 52440a76396Smrg showIncludes=-showIncludes 52540a76396Smrg fi 52640a76396Smrg "$@" $showIncludes > "$tmpdepfile" 52740a76396Smrg stat=$? 52840a76396Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52940a76396Smrg if test $stat -ne 0; then 53040a76396Smrg rm -f "$tmpdepfile" 53140a76396Smrg exit $stat 53240a76396Smrg fi 53340a76396Smrg rm -f "$depfile" 53440a76396Smrg echo "$object : \\" > "$depfile" 53540a76396Smrg # The first sed program below extracts the file names and escapes 53640a76396Smrg # backslashes for cygpath. The second sed program outputs the file 53740a76396Smrg # name when reading, but also accumulates all include files in the 53840a76396Smrg # hold buffer in order to output them again at the end. This only 53940a76396Smrg # works with sed implementations that can handle large buffers. 54040a76396Smrg sed < "$tmpdepfile" -n ' 54140a76396Smrg/^Note: including file: *\(.*\)/ { 54240a76396Smrg s//\1/ 54340a76396Smrg s/\\/\\\\/g 54440a76396Smrg p 54540a76396Smrg}' | $cygpath_u | sort -u | sed -n ' 54640a76396Smrgs/ /\\ /g 54740a76396Smrgs/\(.*\)/'"$tab"'\1 \\/p 54840a76396Smrgs/.\(.*\) \\/\1:/ 54940a76396SmrgH 55040a76396Smrg$ { 55140a76396Smrg s/.*/'"$tab"'/ 55240a76396Smrg G 55340a76396Smrg p 55440a76396Smrg}' >> "$depfile" 55540a76396Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55640a76396Smrg rm -f "$tmpdepfile" 55740a76396Smrg ;; 55840a76396Smrg 55940a76396Smrgmsvc7msys) 56040a76396Smrg # This case exists only to let depend.m4 do its work. It works by 56140a76396Smrg # looking at the text of this script. This case will never be run, 56240a76396Smrg # since it is checked for above. 56340a76396Smrg exit 1 56440a76396Smrg ;; 565a0195d5fSmrg 566a0195d5fSmrg#nosideeffect) 567a0195d5fSmrg # This comment above is used by automake to tell side-effect 568a0195d5fSmrg # dependency tracking mechanisms from slower ones. 569a0195d5fSmrg 570a0195d5fSmrgdashmstdout) 571a0195d5fSmrg # Important note: in order to support this mode, a compiler *must* 572a0195d5fSmrg # always write the preprocessed file to stdout, regardless of -o. 573a0195d5fSmrg "$@" || exit $? 574a0195d5fSmrg 575a0195d5fSmrg # Remove the call to Libtool. 576a0195d5fSmrg if test "$libtool" = yes; then 5776600fe5bSmrg while test "X$1" != 'X--mode=compile'; do 578a0195d5fSmrg shift 579a0195d5fSmrg done 580a0195d5fSmrg shift 581a0195d5fSmrg fi 582a0195d5fSmrg 58340a76396Smrg # Remove '-o $object'. 584a0195d5fSmrg IFS=" " 585a0195d5fSmrg for arg 586a0195d5fSmrg do 587a0195d5fSmrg case $arg in 588a0195d5fSmrg -o) 589a0195d5fSmrg shift 590a0195d5fSmrg ;; 591a0195d5fSmrg $object) 592a0195d5fSmrg shift 593a0195d5fSmrg ;; 594a0195d5fSmrg *) 595a0195d5fSmrg set fnord "$@" "$arg" 596a0195d5fSmrg shift # fnord 597a0195d5fSmrg shift # $arg 598a0195d5fSmrg ;; 599a0195d5fSmrg esac 600a0195d5fSmrg done 601a0195d5fSmrg 602a0195d5fSmrg test -z "$dashmflag" && dashmflag=-M 60340a76396Smrg # Require at least two characters before searching for ':' 604a0195d5fSmrg # in the target name. This is to cope with DOS-style filenames: 60540a76396Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606a0195d5fSmrg "$@" $dashmflag | 60740a76396Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608a0195d5fSmrg rm -f "$depfile" 609a0195d5fSmrg cat < "$tmpdepfile" > "$depfile" 61040a76396Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61140a76396Smrg # correctly. Breaking it into two sed invocations is a workaround. 61240a76396Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61340a76396Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61440a76396Smrg | sed -e 's/$/ :/' >> "$depfile" 615a0195d5fSmrg rm -f "$tmpdepfile" 616a0195d5fSmrg ;; 617a0195d5fSmrg 618a0195d5fSmrgdashXmstdout) 619a0195d5fSmrg # This case only exists to satisfy depend.m4. It is never actually 620a0195d5fSmrg # run, as this mode is specially recognized in the preamble. 621a0195d5fSmrg exit 1 622a0195d5fSmrg ;; 623a0195d5fSmrg 624a0195d5fSmrgmakedepend) 625a0195d5fSmrg "$@" || exit $? 626a0195d5fSmrg # Remove any Libtool call 627a0195d5fSmrg if test "$libtool" = yes; then 6286600fe5bSmrg while test "X$1" != 'X--mode=compile'; do 629a0195d5fSmrg shift 630a0195d5fSmrg done 631a0195d5fSmrg shift 632a0195d5fSmrg fi 633a0195d5fSmrg # X makedepend 634a0195d5fSmrg shift 6356600fe5bSmrg cleared=no eat=no 6366600fe5bSmrg for arg 6376600fe5bSmrg do 638a0195d5fSmrg case $cleared in 639a0195d5fSmrg no) 640a0195d5fSmrg set ""; shift 641a0195d5fSmrg cleared=yes ;; 642a0195d5fSmrg esac 6436600fe5bSmrg if test $eat = yes; then 6446600fe5bSmrg eat=no 6456600fe5bSmrg continue 6466600fe5bSmrg fi 647a0195d5fSmrg case "$arg" in 648a0195d5fSmrg -D*|-I*) 649a0195d5fSmrg set fnord "$@" "$arg"; shift ;; 650a0195d5fSmrg # Strip any option that makedepend may not understand. Remove 651a0195d5fSmrg # the object too, otherwise makedepend will parse it as a source file. 6526600fe5bSmrg -arch) 6536600fe5bSmrg eat=yes ;; 654a0195d5fSmrg -*|$object) 655a0195d5fSmrg ;; 656a0195d5fSmrg *) 657a0195d5fSmrg set fnord "$@" "$arg"; shift ;; 658a0195d5fSmrg esac 659a0195d5fSmrg done 6606600fe5bSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661a0195d5fSmrg touch "$tmpdepfile" 662a0195d5fSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663a0195d5fSmrg rm -f "$depfile" 66440a76396Smrg # makedepend may prepend the VPATH from the source file name to the object. 66540a76396Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66640a76396Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66740a76396Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66840a76396Smrg # correctly. Breaking it into two sed invocations is a workaround. 66940a76396Smrg sed '1,2d' "$tmpdepfile" \ 67040a76396Smrg | tr ' ' "$nl" \ 67140a76396Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67240a76396Smrg | sed -e 's/$/ :/' >> "$depfile" 673a0195d5fSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674a0195d5fSmrg ;; 675a0195d5fSmrg 676a0195d5fSmrgcpp) 677a0195d5fSmrg # Important note: in order to support this mode, a compiler *must* 678a0195d5fSmrg # always write the preprocessed file to stdout. 679a0195d5fSmrg "$@" || exit $? 680a0195d5fSmrg 681a0195d5fSmrg # Remove the call to Libtool. 682a0195d5fSmrg if test "$libtool" = yes; then 6836600fe5bSmrg while test "X$1" != 'X--mode=compile'; do 684a0195d5fSmrg shift 685a0195d5fSmrg done 686a0195d5fSmrg shift 687a0195d5fSmrg fi 688a0195d5fSmrg 68940a76396Smrg # Remove '-o $object'. 690a0195d5fSmrg IFS=" " 691a0195d5fSmrg for arg 692a0195d5fSmrg do 693a0195d5fSmrg case $arg in 694a0195d5fSmrg -o) 695a0195d5fSmrg shift 696a0195d5fSmrg ;; 697a0195d5fSmrg $object) 698a0195d5fSmrg shift 699a0195d5fSmrg ;; 700a0195d5fSmrg *) 701a0195d5fSmrg set fnord "$@" "$arg" 702a0195d5fSmrg shift # fnord 703a0195d5fSmrg shift # $arg 704a0195d5fSmrg ;; 705a0195d5fSmrg esac 706a0195d5fSmrg done 707a0195d5fSmrg 70840a76396Smrg "$@" -E \ 70940a76396Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71040a76396Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71140a76396Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712a0195d5fSmrg rm -f "$depfile" 713a0195d5fSmrg echo "$object : \\" > "$depfile" 714a0195d5fSmrg cat < "$tmpdepfile" >> "$depfile" 715a0195d5fSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716a0195d5fSmrg rm -f "$tmpdepfile" 717a0195d5fSmrg ;; 718a0195d5fSmrg 719a0195d5fSmrgmsvisualcpp) 720a0195d5fSmrg # Important note: in order to support this mode, a compiler *must* 7216600fe5bSmrg # always write the preprocessed file to stdout. 722a0195d5fSmrg "$@" || exit $? 7236600fe5bSmrg 7246600fe5bSmrg # Remove the call to Libtool. 7256600fe5bSmrg if test "$libtool" = yes; then 7266600fe5bSmrg while test "X$1" != 'X--mode=compile'; do 7276600fe5bSmrg shift 7286600fe5bSmrg done 7296600fe5bSmrg shift 7306600fe5bSmrg fi 7316600fe5bSmrg 732a0195d5fSmrg IFS=" " 733a0195d5fSmrg for arg 734a0195d5fSmrg do 735a0195d5fSmrg case "$arg" in 7366600fe5bSmrg -o) 7376600fe5bSmrg shift 7386600fe5bSmrg ;; 7396600fe5bSmrg $object) 7406600fe5bSmrg shift 7416600fe5bSmrg ;; 742a0195d5fSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74340a76396Smrg set fnord "$@" 74440a76396Smrg shift 74540a76396Smrg shift 74640a76396Smrg ;; 747a0195d5fSmrg *) 74840a76396Smrg set fnord "$@" "$arg" 74940a76396Smrg shift 75040a76396Smrg shift 75140a76396Smrg ;; 752a0195d5fSmrg esac 753a0195d5fSmrg done 7546600fe5bSmrg "$@" -E 2>/dev/null | 7556600fe5bSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756a0195d5fSmrg rm -f "$depfile" 757a0195d5fSmrg echo "$object : \\" > "$depfile" 75840a76396Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75940a76396Smrg echo "$tab" >> "$depfile" 7606600fe5bSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761a0195d5fSmrg rm -f "$tmpdepfile" 762a0195d5fSmrg ;; 763a0195d5fSmrg 7646600fe5bSmrgmsvcmsys) 7656600fe5bSmrg # This case exists only to let depend.m4 do its work. It works by 7666600fe5bSmrg # looking at the text of this script. This case will never be run, 7676600fe5bSmrg # since it is checked for above. 7686600fe5bSmrg exit 1 7696600fe5bSmrg ;; 7706600fe5bSmrg 771a0195d5fSmrgnone) 772a0195d5fSmrg exec "$@" 773a0195d5fSmrg ;; 774a0195d5fSmrg 775a0195d5fSmrg*) 776a0195d5fSmrg echo "Unknown depmode $depmode" 1>&2 777a0195d5fSmrg exit 1 778a0195d5fSmrg ;; 779a0195d5fSmrgesac 780a0195d5fSmrg 781a0195d5fSmrgexit 0 782a0195d5fSmrg 783a0195d5fSmrg# Local Variables: 784a0195d5fSmrg# mode: shell-script 785a0195d5fSmrg# sh-indentation: 2 7860f5b81e5Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 787a0195d5fSmrg# time-stamp-start: "scriptversion=" 788a0195d5fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7890f5b81e5Smrg# time-stamp-time-zone: "UTC0" 7906600fe5bSmrg# time-stamp-end: "; # UTC" 791a0195d5fSmrg# End: 792