depcomp revision 60da515c
1a96d7823Smrg#! /bin/sh 2a96d7823Smrg# depcomp - compile a program generating dependencies as side-effects 3a96d7823Smrg 460da515cSmrgscriptversion=2018-03-07.03; # UTC 5a96d7823Smrg 660da515cSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7a96d7823Smrg 8a96d7823Smrg# This program is free software; you can redistribute it and/or modify 9a96d7823Smrg# it under the terms of the GNU General Public License as published by 10a96d7823Smrg# the Free Software Foundation; either version 2, or (at your option) 11a96d7823Smrg# any later version. 12a96d7823Smrg 13a96d7823Smrg# This program is distributed in the hope that it will be useful, 14a96d7823Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15a96d7823Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a96d7823Smrg# GNU General Public License for more details. 17a96d7823Smrg 18a96d7823Smrg# You should have received a copy of the GNU General Public License 1960da515cSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20a96d7823Smrg 21a96d7823Smrg# As a special exception to the GNU General Public License, if you 22a96d7823Smrg# distribute this file as part of a program that contains a 23a96d7823Smrg# configuration script generated by Autoconf, you may include it under 24a96d7823Smrg# the same distribution terms that you use for the rest of that program. 25a96d7823Smrg 26a96d7823Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27a96d7823Smrg 28a96d7823Smrgcase $1 in 29a96d7823Smrg '') 30a96d7823Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31a96d7823Smrg exit 1; 32a96d7823Smrg ;; 33a96d7823Smrg -h | --h*) 34a96d7823Smrg cat <<\EOF 35a96d7823SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36a96d7823Smrg 37a96d7823SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38a96d7823Smrgas side-effects. 39a96d7823Smrg 40a96d7823SmrgEnvironment variables: 41a96d7823Smrg depmode Dependency tracking mode. 42a96d7823Smrg source Source file read by 'PROGRAMS ARGS'. 43a96d7823Smrg object Object file output by 'PROGRAMS ARGS'. 44a96d7823Smrg DEPDIR directory where to store dependencies. 45a96d7823Smrg depfile Dependency file to output. 46a96d7823Smrg tmpdepfile Temporary file to use when outputting dependencies. 47a96d7823Smrg libtool Whether libtool is used (yes/no). 48a96d7823Smrg 49a96d7823SmrgReport bugs to <bug-automake@gnu.org>. 50a96d7823SmrgEOF 51a96d7823Smrg exit $? 52a96d7823Smrg ;; 53a96d7823Smrg -v | --v*) 54a96d7823Smrg echo "depcomp $scriptversion" 55a96d7823Smrg exit $? 56a96d7823Smrg ;; 57a96d7823Smrgesac 58a96d7823Smrg 59a96d7823Smrg# Get the directory component of the given path, and save it in the 60a96d7823Smrg# global variables '$dir'. Note that this directory component will 61a96d7823Smrg# be either empty or ending with a '/' character. This is deliberate. 62a96d7823Smrgset_dir_from () 63a96d7823Smrg{ 64a96d7823Smrg case $1 in 65a96d7823Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66a96d7823Smrg *) dir=;; 67a96d7823Smrg esac 68a96d7823Smrg} 69a96d7823Smrg 70a96d7823Smrg# Get the suffix-stripped basename of the given path, and save it the 71a96d7823Smrg# global variable '$base'. 72a96d7823Smrgset_base_from () 73a96d7823Smrg{ 74a96d7823Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75a96d7823Smrg} 76a96d7823Smrg 77a96d7823Smrg# If no dependency file was actually created by the compiler invocation, 78a96d7823Smrg# we still have to create a dummy depfile, to avoid errors with the 79a96d7823Smrg# Makefile "include basename.Plo" scheme. 80a96d7823Smrgmake_dummy_depfile () 81a96d7823Smrg{ 82a96d7823Smrg echo "#dummy" > "$depfile" 83a96d7823Smrg} 84a96d7823Smrg 85a96d7823Smrg# Factor out some common post-processing of the generated depfile. 86a96d7823Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87a96d7823Smrgaix_post_process_depfile () 88a96d7823Smrg{ 89a96d7823Smrg # If the compiler actually managed to produce a dependency file, 90a96d7823Smrg # post-process it. 91a96d7823Smrg if test -f "$tmpdepfile"; then 92a96d7823Smrg # Each line is of the form 'foo.o: dependency.h'. 93a96d7823Smrg # Do two passes, one to just change these to 94a96d7823Smrg # $object: dependency.h 95a96d7823Smrg # and one to simply output 96a96d7823Smrg # dependency.h: 97a96d7823Smrg # which is needed to avoid the deleted-header problem. 98a96d7823Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99a96d7823Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100a96d7823Smrg } > "$depfile" 101a96d7823Smrg rm -f "$tmpdepfile" 102a96d7823Smrg else 103a96d7823Smrg make_dummy_depfile 104a96d7823Smrg fi 105a96d7823Smrg} 106a96d7823Smrg 107a96d7823Smrg# A tabulation character. 108a96d7823Smrgtab=' ' 109a96d7823Smrg# A newline character. 110a96d7823Smrgnl=' 111a96d7823Smrg' 112a96d7823Smrg# Character ranges might be problematic outside the C locale. 113a96d7823Smrg# These definitions help. 114a96d7823Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115a96d7823Smrglower=abcdefghijklmnopqrstuvwxyz 116a96d7823Smrgdigits=0123456789 117a96d7823Smrgalpha=${upper}${lower} 118a96d7823Smrg 119a96d7823Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120a96d7823Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121a96d7823Smrg exit 1 122a96d7823Smrgfi 123a96d7823Smrg 124a96d7823Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125a96d7823Smrgdepfile=${depfile-`echo "$object" | 126a96d7823Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127a96d7823Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128a96d7823Smrg 129a96d7823Smrgrm -f "$tmpdepfile" 130a96d7823Smrg 131a96d7823Smrg# Avoid interferences from the environment. 132a96d7823Smrggccflag= dashmflag= 133a96d7823Smrg 134a96d7823Smrg# Some modes work just like other modes, but use different flags. We 135a96d7823Smrg# parameterize here, but still list the modes in the big case below, 136a96d7823Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137a96d7823Smrg# here, because this file can only contain one case statement. 138a96d7823Smrgif test "$depmode" = hp; then 139a96d7823Smrg # HP compiler uses -M and no extra arg. 140a96d7823Smrg gccflag=-M 141a96d7823Smrg depmode=gcc 142a96d7823Smrgfi 143a96d7823Smrg 144a96d7823Smrgif test "$depmode" = dashXmstdout; then 145a96d7823Smrg # This is just like dashmstdout with a different argument. 146a96d7823Smrg dashmflag=-xM 147a96d7823Smrg depmode=dashmstdout 148a96d7823Smrgfi 149a96d7823Smrg 150a96d7823Smrgcygpath_u="cygpath -u -f -" 151a96d7823Smrgif test "$depmode" = msvcmsys; then 152a96d7823Smrg # This is just like msvisualcpp but w/o cygpath translation. 153a96d7823Smrg # Just convert the backslash-escaped backslashes to single forward 154a96d7823Smrg # slashes to satisfy depend.m4 155a96d7823Smrg cygpath_u='sed s,\\\\,/,g' 156a96d7823Smrg depmode=msvisualcpp 157a96d7823Smrgfi 158a96d7823Smrg 159a96d7823Smrgif test "$depmode" = msvc7msys; then 160a96d7823Smrg # This is just like msvc7 but w/o cygpath translation. 161a96d7823Smrg # Just convert the backslash-escaped backslashes to single forward 162a96d7823Smrg # slashes to satisfy depend.m4 163a96d7823Smrg cygpath_u='sed s,\\\\,/,g' 164a96d7823Smrg depmode=msvc7 165a96d7823Smrgfi 166a96d7823Smrg 167a96d7823Smrgif test "$depmode" = xlc; then 168a96d7823Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169a96d7823Smrg gccflag=-qmakedep=gcc,-MF 170a96d7823Smrg depmode=gcc 171a96d7823Smrgfi 172a96d7823Smrg 173a96d7823Smrgcase "$depmode" in 174a96d7823Smrggcc3) 175a96d7823Smrg## gcc 3 implements dependency tracking that does exactly what 176a96d7823Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177a96d7823Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178a96d7823Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179a96d7823Smrg## the command line argument order; so add the flags where they 180a96d7823Smrg## appear in depend2.am. Note that the slowdown incurred here 181a96d7823Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182a96d7823Smrg for arg 183a96d7823Smrg do 184a96d7823Smrg case $arg in 185a96d7823Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186a96d7823Smrg *) set fnord "$@" "$arg" ;; 187a96d7823Smrg esac 188a96d7823Smrg shift # fnord 189a96d7823Smrg shift # $arg 190a96d7823Smrg done 191a96d7823Smrg "$@" 192a96d7823Smrg stat=$? 193a96d7823Smrg if test $stat -ne 0; then 194a96d7823Smrg rm -f "$tmpdepfile" 195a96d7823Smrg exit $stat 196a96d7823Smrg fi 197a96d7823Smrg mv "$tmpdepfile" "$depfile" 198a96d7823Smrg ;; 199a96d7823Smrg 200a96d7823Smrggcc) 201a96d7823Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202a96d7823Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203a96d7823Smrg## (see the conditional assignment to $gccflag above). 204a96d7823Smrg## There are various ways to get dependency output from gcc. Here's 205a96d7823Smrg## why we pick this rather obscure method: 206a96d7823Smrg## - Don't want to use -MD because we'd like the dependencies to end 207a96d7823Smrg## up in a subdir. Having to rename by hand is ugly. 208a96d7823Smrg## (We might end up doing this anyway to support other compilers.) 209a96d7823Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210a96d7823Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211a96d7823Smrg## supported by the other compilers which use the 'gcc' depmode. 212a96d7823Smrg## - Using -M directly means running the compiler twice (even worse 213a96d7823Smrg## than renaming). 214a96d7823Smrg if test -z "$gccflag"; then 215a96d7823Smrg gccflag=-MD, 216a96d7823Smrg fi 217a96d7823Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218a96d7823Smrg stat=$? 219a96d7823Smrg if test $stat -ne 0; then 220a96d7823Smrg rm -f "$tmpdepfile" 221a96d7823Smrg exit $stat 222a96d7823Smrg fi 223a96d7823Smrg rm -f "$depfile" 224a96d7823Smrg echo "$object : \\" > "$depfile" 225a96d7823Smrg # The second -e expression handles DOS-style file names with drive 226a96d7823Smrg # letters. 227a96d7823Smrg sed -e 's/^[^:]*: / /' \ 228a96d7823Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229a96d7823Smrg## This next piece of magic avoids the "deleted header file" problem. 230a96d7823Smrg## The problem is that when a header file which appears in a .P file 231a96d7823Smrg## is deleted, the dependency causes make to die (because there is 232a96d7823Smrg## typically no way to rebuild the header). We avoid this by adding 233a96d7823Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234a96d7823Smrg## this for us directly. 235a96d7823Smrg## Some versions of gcc put a space before the ':'. On the theory 236a96d7823Smrg## that the space means something, we add a space to the output as 237a96d7823Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238a96d7823Smrg## to the object. Take care to not repeat it in the output. 239a96d7823Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240a96d7823Smrg## correctly. Breaking it into two sed invocations is a workaround. 241a96d7823Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242a96d7823Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243a96d7823Smrg | sed -e 's/$/ :/' >> "$depfile" 244a96d7823Smrg rm -f "$tmpdepfile" 245a96d7823Smrg ;; 246a96d7823Smrg 247a96d7823Smrghp) 248a96d7823Smrg # This case exists only to let depend.m4 do its work. It works by 249a96d7823Smrg # looking at the text of this script. This case will never be run, 250a96d7823Smrg # since it is checked for above. 251a96d7823Smrg exit 1 252a96d7823Smrg ;; 253a96d7823Smrg 254a96d7823Smrgsgi) 255a96d7823Smrg if test "$libtool" = yes; then 256a96d7823Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257a96d7823Smrg else 258a96d7823Smrg "$@" -MDupdate "$tmpdepfile" 259a96d7823Smrg fi 260a96d7823Smrg stat=$? 261a96d7823Smrg if test $stat -ne 0; then 262a96d7823Smrg rm -f "$tmpdepfile" 263a96d7823Smrg exit $stat 264a96d7823Smrg fi 265a96d7823Smrg rm -f "$depfile" 266a96d7823Smrg 267a96d7823Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268a96d7823Smrg echo "$object : \\" > "$depfile" 269a96d7823Smrg # Clip off the initial element (the dependent). Don't try to be 270a96d7823Smrg # clever and replace this with sed code, as IRIX sed won't handle 271a96d7823Smrg # lines with more than a fixed number of characters (4096 in 272a96d7823Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273a96d7823Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274a96d7823Smrg # dependency line. 275a96d7823Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276a96d7823Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277a96d7823Smrg | tr "$nl" ' ' >> "$depfile" 278a96d7823Smrg echo >> "$depfile" 279a96d7823Smrg # The second pass generates a dummy entry for each header file. 280a96d7823Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281a96d7823Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282a96d7823Smrg >> "$depfile" 283a96d7823Smrg else 284a96d7823Smrg make_dummy_depfile 285a96d7823Smrg fi 286a96d7823Smrg rm -f "$tmpdepfile" 287a96d7823Smrg ;; 288a96d7823Smrg 289a96d7823Smrgxlc) 290a96d7823Smrg # This case exists only to let depend.m4 do its work. It works by 291a96d7823Smrg # looking at the text of this script. This case will never be run, 292a96d7823Smrg # since it is checked for above. 293a96d7823Smrg exit 1 294a96d7823Smrg ;; 295a96d7823Smrg 296a96d7823Smrgaix) 297a96d7823Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298a96d7823Smrg # in a .u file. In older versions, this file always lives in the 299a96d7823Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300a96d7823Smrg # start of each line; $object doesn't have directory information. 301a96d7823Smrg # Version 6 uses the directory in both cases. 302a96d7823Smrg set_dir_from "$object" 303a96d7823Smrg set_base_from "$object" 304a96d7823Smrg if test "$libtool" = yes; then 305a96d7823Smrg tmpdepfile1=$dir$base.u 306a96d7823Smrg tmpdepfile2=$base.u 307a96d7823Smrg tmpdepfile3=$dir.libs/$base.u 308a96d7823Smrg "$@" -Wc,-M 309a96d7823Smrg else 310a96d7823Smrg tmpdepfile1=$dir$base.u 311a96d7823Smrg tmpdepfile2=$dir$base.u 312a96d7823Smrg tmpdepfile3=$dir$base.u 313a96d7823Smrg "$@" -M 314a96d7823Smrg fi 315a96d7823Smrg stat=$? 316a96d7823Smrg if test $stat -ne 0; then 317a96d7823Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318a96d7823Smrg exit $stat 319a96d7823Smrg fi 320a96d7823Smrg 321a96d7823Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322a96d7823Smrg do 323a96d7823Smrg test -f "$tmpdepfile" && break 324a96d7823Smrg done 325a96d7823Smrg aix_post_process_depfile 326a96d7823Smrg ;; 327a96d7823Smrg 328a96d7823Smrgtcc) 329a96d7823Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330a96d7823Smrg # FIXME: That version still under development at the moment of writing. 331a96d7823Smrg # Make that this statement remains true also for stable, released 332a96d7823Smrg # versions. 333a96d7823Smrg # It will wrap lines (doesn't matter whether long or short) with a 334a96d7823Smrg # trailing '\', as in: 335a96d7823Smrg # 336a96d7823Smrg # foo.o : \ 337a96d7823Smrg # foo.c \ 338a96d7823Smrg # foo.h \ 339a96d7823Smrg # 340a96d7823Smrg # It will put a trailing '\' even on the last line, and will use leading 341a96d7823Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342a96d7823Smrg # "Emit spaces for -MD"). 343a96d7823Smrg "$@" -MD -MF "$tmpdepfile" 344a96d7823Smrg stat=$? 345a96d7823Smrg if test $stat -ne 0; then 346a96d7823Smrg rm -f "$tmpdepfile" 347a96d7823Smrg exit $stat 348a96d7823Smrg fi 349a96d7823Smrg rm -f "$depfile" 350a96d7823Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351a96d7823Smrg # We have to change lines of the first kind to '$object: \'. 352a96d7823Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353a96d7823Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354a96d7823Smrg # dummy dependency, to avoid the deleted-header problem. 355a96d7823Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356a96d7823Smrg rm -f "$tmpdepfile" 357a96d7823Smrg ;; 358a96d7823Smrg 359a96d7823Smrg## The order of this option in the case statement is important, since the 360a96d7823Smrg## shell code in configure will try each of these formats in the order 361a96d7823Smrg## listed in this file. A plain '-MD' option would be understood by many 362a96d7823Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363a96d7823Smrgpgcc) 364a96d7823Smrg # Portland's C compiler understands '-MD'. 365a96d7823Smrg # Will always output deps to 'file.d' where file is the root name of the 366a96d7823Smrg # source file under compilation, even if file resides in a subdirectory. 367a96d7823Smrg # The object file name does not affect the name of the '.d' file. 368a96d7823Smrg # pgcc 10.2 will output 369a96d7823Smrg # foo.o: sub/foo.c sub/foo.h 370a96d7823Smrg # and will wrap long lines using '\' : 371a96d7823Smrg # foo.o: sub/foo.c ... \ 372a96d7823Smrg # sub/foo.h ... \ 373a96d7823Smrg # ... 374a96d7823Smrg set_dir_from "$object" 375a96d7823Smrg # Use the source, not the object, to determine the base name, since 376a96d7823Smrg # that's sadly what pgcc will do too. 377a96d7823Smrg set_base_from "$source" 378a96d7823Smrg tmpdepfile=$base.d 379a96d7823Smrg 380a96d7823Smrg # For projects that build the same source file twice into different object 381a96d7823Smrg # files, the pgcc approach of using the *source* file root name can cause 382a96d7823Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383a96d7823Smrg # the same $tmpdepfile. 384a96d7823Smrg lockdir=$base.d-lock 385a96d7823Smrg trap " 386a96d7823Smrg echo '$0: caught signal, cleaning up...' >&2 387a96d7823Smrg rmdir '$lockdir' 388a96d7823Smrg exit 1 389a96d7823Smrg " 1 2 13 15 390a96d7823Smrg numtries=100 391a96d7823Smrg i=$numtries 392a96d7823Smrg while test $i -gt 0; do 393a96d7823Smrg # mkdir is a portable test-and-set. 394a96d7823Smrg if mkdir "$lockdir" 2>/dev/null; then 395a96d7823Smrg # This process acquired the lock. 396a96d7823Smrg "$@" -MD 397a96d7823Smrg stat=$? 398a96d7823Smrg # Release the lock. 399a96d7823Smrg rmdir "$lockdir" 400a96d7823Smrg break 401a96d7823Smrg else 402a96d7823Smrg # If the lock is being held by a different process, wait 403a96d7823Smrg # until the winning process is done or we timeout. 404a96d7823Smrg while test -d "$lockdir" && test $i -gt 0; do 405a96d7823Smrg sleep 1 406a96d7823Smrg i=`expr $i - 1` 407a96d7823Smrg done 408a96d7823Smrg fi 409a96d7823Smrg i=`expr $i - 1` 410a96d7823Smrg done 411a96d7823Smrg trap - 1 2 13 15 412a96d7823Smrg if test $i -le 0; then 413a96d7823Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414a96d7823Smrg echo "$0: check lockdir '$lockdir'" >&2 415a96d7823Smrg exit 1 416a96d7823Smrg fi 417a96d7823Smrg 418a96d7823Smrg if test $stat -ne 0; then 419a96d7823Smrg rm -f "$tmpdepfile" 420a96d7823Smrg exit $stat 421a96d7823Smrg fi 422a96d7823Smrg rm -f "$depfile" 423a96d7823Smrg # Each line is of the form `foo.o: dependent.h', 424a96d7823Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425a96d7823Smrg # Do two passes, one to just change these to 426a96d7823Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427a96d7823Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428a96d7823Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429a96d7823Smrg # correctly. Breaking it into two sed invocations is a workaround. 430a96d7823Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431a96d7823Smrg | sed -e 's/$/ :/' >> "$depfile" 432a96d7823Smrg rm -f "$tmpdepfile" 433a96d7823Smrg ;; 434a96d7823Smrg 435a96d7823Smrghp2) 436a96d7823Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437a96d7823Smrg # compilers, which have integrated preprocessors. The correct option 438a96d7823Smrg # to use with these is +Maked; it writes dependencies to a file named 439a96d7823Smrg # 'foo.d', which lands next to the object file, wherever that 440a96d7823Smrg # happens to be. 441a96d7823Smrg # Much of this is similar to the tru64 case; see comments there. 442a96d7823Smrg set_dir_from "$object" 443a96d7823Smrg set_base_from "$object" 444a96d7823Smrg if test "$libtool" = yes; then 445a96d7823Smrg tmpdepfile1=$dir$base.d 446a96d7823Smrg tmpdepfile2=$dir.libs/$base.d 447a96d7823Smrg "$@" -Wc,+Maked 448a96d7823Smrg else 449a96d7823Smrg tmpdepfile1=$dir$base.d 450a96d7823Smrg tmpdepfile2=$dir$base.d 451a96d7823Smrg "$@" +Maked 452a96d7823Smrg fi 453a96d7823Smrg stat=$? 454a96d7823Smrg if test $stat -ne 0; then 455a96d7823Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456a96d7823Smrg exit $stat 457a96d7823Smrg fi 458a96d7823Smrg 459a96d7823Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460a96d7823Smrg do 461a96d7823Smrg test -f "$tmpdepfile" && break 462a96d7823Smrg done 463a96d7823Smrg if test -f "$tmpdepfile"; then 464a96d7823Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465a96d7823Smrg # Add 'dependent.h:' lines. 466a96d7823Smrg sed -ne '2,${ 467a96d7823Smrg s/^ *// 468a96d7823Smrg s/ \\*$// 469a96d7823Smrg s/$/:/ 470a96d7823Smrg p 471a96d7823Smrg }' "$tmpdepfile" >> "$depfile" 472a96d7823Smrg else 473a96d7823Smrg make_dummy_depfile 474a96d7823Smrg fi 475a96d7823Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 476a96d7823Smrg ;; 477a96d7823Smrg 478a96d7823Smrgtru64) 479a96d7823Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480a96d7823Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481a96d7823Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482a96d7823Smrg # dependencies in 'foo.d' instead, so we check for that too. 483a96d7823Smrg # Subdirectories are respected. 484a96d7823Smrg set_dir_from "$object" 485a96d7823Smrg set_base_from "$object" 486a96d7823Smrg 487a96d7823Smrg if test "$libtool" = yes; then 488a96d7823Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489a96d7823Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490a96d7823Smrg # in $dir$base.o.d. We have to check for both files, because 491a96d7823Smrg # one of the two compilations can be disabled. We should prefer 492a96d7823Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493a96d7823Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494a96d7823Smrg # the former would cause a distcleancheck panic. 495a96d7823Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496a96d7823Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497a96d7823Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498a96d7823Smrg "$@" -Wc,-MD 499a96d7823Smrg else 500a96d7823Smrg tmpdepfile1=$dir$base.d 501a96d7823Smrg tmpdepfile2=$dir$base.d 502a96d7823Smrg tmpdepfile3=$dir$base.d 503a96d7823Smrg "$@" -MD 504a96d7823Smrg fi 505a96d7823Smrg 506a96d7823Smrg stat=$? 507a96d7823Smrg if test $stat -ne 0; then 508a96d7823Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509a96d7823Smrg exit $stat 510a96d7823Smrg fi 511a96d7823Smrg 512a96d7823Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513a96d7823Smrg do 514a96d7823Smrg test -f "$tmpdepfile" && break 515a96d7823Smrg done 516a96d7823Smrg # Same post-processing that is required for AIX mode. 517a96d7823Smrg aix_post_process_depfile 518a96d7823Smrg ;; 519a96d7823Smrg 520a96d7823Smrgmsvc7) 521a96d7823Smrg if test "$libtool" = yes; then 522a96d7823Smrg showIncludes=-Wc,-showIncludes 523a96d7823Smrg else 524a96d7823Smrg showIncludes=-showIncludes 525a96d7823Smrg fi 526a96d7823Smrg "$@" $showIncludes > "$tmpdepfile" 527a96d7823Smrg stat=$? 528a96d7823Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529a96d7823Smrg if test $stat -ne 0; then 530a96d7823Smrg rm -f "$tmpdepfile" 531a96d7823Smrg exit $stat 532a96d7823Smrg fi 533a96d7823Smrg rm -f "$depfile" 534a96d7823Smrg echo "$object : \\" > "$depfile" 535a96d7823Smrg # The first sed program below extracts the file names and escapes 536a96d7823Smrg # backslashes for cygpath. The second sed program outputs the file 537a96d7823Smrg # name when reading, but also accumulates all include files in the 538a96d7823Smrg # hold buffer in order to output them again at the end. This only 539a96d7823Smrg # works with sed implementations that can handle large buffers. 540a96d7823Smrg sed < "$tmpdepfile" -n ' 541a96d7823Smrg/^Note: including file: *\(.*\)/ { 542a96d7823Smrg s//\1/ 543a96d7823Smrg s/\\/\\\\/g 544a96d7823Smrg p 545a96d7823Smrg}' | $cygpath_u | sort -u | sed -n ' 546a96d7823Smrgs/ /\\ /g 547a96d7823Smrgs/\(.*\)/'"$tab"'\1 \\/p 548a96d7823Smrgs/.\(.*\) \\/\1:/ 549a96d7823SmrgH 550a96d7823Smrg$ { 551a96d7823Smrg s/.*/'"$tab"'/ 552a96d7823Smrg G 553a96d7823Smrg p 554a96d7823Smrg}' >> "$depfile" 555a96d7823Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556a96d7823Smrg rm -f "$tmpdepfile" 557a96d7823Smrg ;; 558a96d7823Smrg 559a96d7823Smrgmsvc7msys) 560a96d7823Smrg # This case exists only to let depend.m4 do its work. It works by 561a96d7823Smrg # looking at the text of this script. This case will never be run, 562a96d7823Smrg # since it is checked for above. 563a96d7823Smrg exit 1 564a96d7823Smrg ;; 565a96d7823Smrg 566a96d7823Smrg#nosideeffect) 567a96d7823Smrg # This comment above is used by automake to tell side-effect 568a96d7823Smrg # dependency tracking mechanisms from slower ones. 569a96d7823Smrg 570a96d7823Smrgdashmstdout) 571a96d7823Smrg # Important note: in order to support this mode, a compiler *must* 572a96d7823Smrg # always write the preprocessed file to stdout, regardless of -o. 573a96d7823Smrg "$@" || exit $? 574a96d7823Smrg 575a96d7823Smrg # Remove the call to Libtool. 576a96d7823Smrg if test "$libtool" = yes; then 577a96d7823Smrg while test "X$1" != 'X--mode=compile'; do 578a96d7823Smrg shift 579a96d7823Smrg done 580a96d7823Smrg shift 581a96d7823Smrg fi 582a96d7823Smrg 583a96d7823Smrg # Remove '-o $object'. 584a96d7823Smrg IFS=" " 585a96d7823Smrg for arg 586a96d7823Smrg do 587a96d7823Smrg case $arg in 588a96d7823Smrg -o) 589a96d7823Smrg shift 590a96d7823Smrg ;; 591a96d7823Smrg $object) 592a96d7823Smrg shift 593a96d7823Smrg ;; 594a96d7823Smrg *) 595a96d7823Smrg set fnord "$@" "$arg" 596a96d7823Smrg shift # fnord 597a96d7823Smrg shift # $arg 598a96d7823Smrg ;; 599a96d7823Smrg esac 600a96d7823Smrg done 601a96d7823Smrg 602a96d7823Smrg test -z "$dashmflag" && dashmflag=-M 603a96d7823Smrg # Require at least two characters before searching for ':' 604a96d7823Smrg # in the target name. This is to cope with DOS-style filenames: 605a96d7823Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606a96d7823Smrg "$@" $dashmflag | 607a96d7823Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608a96d7823Smrg rm -f "$depfile" 609a96d7823Smrg cat < "$tmpdepfile" > "$depfile" 610a96d7823Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611a96d7823Smrg # correctly. Breaking it into two sed invocations is a workaround. 612a96d7823Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613a96d7823Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614a96d7823Smrg | sed -e 's/$/ :/' >> "$depfile" 615a96d7823Smrg rm -f "$tmpdepfile" 616a96d7823Smrg ;; 617a96d7823Smrg 618a96d7823SmrgdashXmstdout) 619a96d7823Smrg # This case only exists to satisfy depend.m4. It is never actually 620a96d7823Smrg # run, as this mode is specially recognized in the preamble. 621a96d7823Smrg exit 1 622a96d7823Smrg ;; 623a96d7823Smrg 624a96d7823Smrgmakedepend) 625a96d7823Smrg "$@" || exit $? 626a96d7823Smrg # Remove any Libtool call 627a96d7823Smrg if test "$libtool" = yes; then 628a96d7823Smrg while test "X$1" != 'X--mode=compile'; do 629a96d7823Smrg shift 630a96d7823Smrg done 631a96d7823Smrg shift 632a96d7823Smrg fi 633a96d7823Smrg # X makedepend 634a96d7823Smrg shift 635a96d7823Smrg cleared=no eat=no 636a96d7823Smrg for arg 637a96d7823Smrg do 638a96d7823Smrg case $cleared in 639a96d7823Smrg no) 640a96d7823Smrg set ""; shift 641a96d7823Smrg cleared=yes ;; 642a96d7823Smrg esac 643a96d7823Smrg if test $eat = yes; then 644a96d7823Smrg eat=no 645a96d7823Smrg continue 646a96d7823Smrg fi 647a96d7823Smrg case "$arg" in 648a96d7823Smrg -D*|-I*) 649a96d7823Smrg set fnord "$@" "$arg"; shift ;; 650a96d7823Smrg # Strip any option that makedepend may not understand. Remove 651a96d7823Smrg # the object too, otherwise makedepend will parse it as a source file. 652a96d7823Smrg -arch) 653a96d7823Smrg eat=yes ;; 654a96d7823Smrg -*|$object) 655a96d7823Smrg ;; 656a96d7823Smrg *) 657a96d7823Smrg set fnord "$@" "$arg"; shift ;; 658a96d7823Smrg esac 659a96d7823Smrg done 660a96d7823Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661a96d7823Smrg touch "$tmpdepfile" 662a96d7823Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663a96d7823Smrg rm -f "$depfile" 664a96d7823Smrg # makedepend may prepend the VPATH from the source file name to the object. 665a96d7823Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666a96d7823Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667a96d7823Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668a96d7823Smrg # correctly. Breaking it into two sed invocations is a workaround. 669a96d7823Smrg sed '1,2d' "$tmpdepfile" \ 670a96d7823Smrg | tr ' ' "$nl" \ 671a96d7823Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672a96d7823Smrg | sed -e 's/$/ :/' >> "$depfile" 673a96d7823Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674a96d7823Smrg ;; 675a96d7823Smrg 676a96d7823Smrgcpp) 677a96d7823Smrg # Important note: in order to support this mode, a compiler *must* 678a96d7823Smrg # always write the preprocessed file to stdout. 679a96d7823Smrg "$@" || exit $? 680a96d7823Smrg 681a96d7823Smrg # Remove the call to Libtool. 682a96d7823Smrg if test "$libtool" = yes; then 683a96d7823Smrg while test "X$1" != 'X--mode=compile'; do 684a96d7823Smrg shift 685a96d7823Smrg done 686a96d7823Smrg shift 687a96d7823Smrg fi 688a96d7823Smrg 689a96d7823Smrg # Remove '-o $object'. 690a96d7823Smrg IFS=" " 691a96d7823Smrg for arg 692a96d7823Smrg do 693a96d7823Smrg case $arg in 694a96d7823Smrg -o) 695a96d7823Smrg shift 696a96d7823Smrg ;; 697a96d7823Smrg $object) 698a96d7823Smrg shift 699a96d7823Smrg ;; 700a96d7823Smrg *) 701a96d7823Smrg set fnord "$@" "$arg" 702a96d7823Smrg shift # fnord 703a96d7823Smrg shift # $arg 704a96d7823Smrg ;; 705a96d7823Smrg esac 706a96d7823Smrg done 707a96d7823Smrg 708a96d7823Smrg "$@" -E \ 709a96d7823Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710a96d7823Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711a96d7823Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712a96d7823Smrg rm -f "$depfile" 713a96d7823Smrg echo "$object : \\" > "$depfile" 714a96d7823Smrg cat < "$tmpdepfile" >> "$depfile" 715a96d7823Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716a96d7823Smrg rm -f "$tmpdepfile" 717a96d7823Smrg ;; 718a96d7823Smrg 719a96d7823Smrgmsvisualcpp) 720a96d7823Smrg # Important note: in order to support this mode, a compiler *must* 721a96d7823Smrg # always write the preprocessed file to stdout. 722a96d7823Smrg "$@" || exit $? 723a96d7823Smrg 724a96d7823Smrg # Remove the call to Libtool. 725a96d7823Smrg if test "$libtool" = yes; then 726a96d7823Smrg while test "X$1" != 'X--mode=compile'; do 727a96d7823Smrg shift 728a96d7823Smrg done 729a96d7823Smrg shift 730a96d7823Smrg fi 731a96d7823Smrg 732a96d7823Smrg IFS=" " 733a96d7823Smrg for arg 734a96d7823Smrg do 735a96d7823Smrg case "$arg" in 736a96d7823Smrg -o) 737a96d7823Smrg shift 738a96d7823Smrg ;; 739a96d7823Smrg $object) 740a96d7823Smrg shift 741a96d7823Smrg ;; 742a96d7823Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743a96d7823Smrg set fnord "$@" 744a96d7823Smrg shift 745a96d7823Smrg shift 746a96d7823Smrg ;; 747a96d7823Smrg *) 748a96d7823Smrg set fnord "$@" "$arg" 749a96d7823Smrg shift 750a96d7823Smrg shift 751a96d7823Smrg ;; 752a96d7823Smrg esac 753a96d7823Smrg done 754a96d7823Smrg "$@" -E 2>/dev/null | 755a96d7823Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756a96d7823Smrg rm -f "$depfile" 757a96d7823Smrg echo "$object : \\" > "$depfile" 758a96d7823Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759a96d7823Smrg echo "$tab" >> "$depfile" 760a96d7823Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761a96d7823Smrg rm -f "$tmpdepfile" 762a96d7823Smrg ;; 763a96d7823Smrg 764a96d7823Smrgmsvcmsys) 765a96d7823Smrg # This case exists only to let depend.m4 do its work. It works by 766a96d7823Smrg # looking at the text of this script. This case will never be run, 767a96d7823Smrg # since it is checked for above. 768a96d7823Smrg exit 1 769a96d7823Smrg ;; 770a96d7823Smrg 771a96d7823Smrgnone) 772a96d7823Smrg exec "$@" 773a96d7823Smrg ;; 774a96d7823Smrg 775a96d7823Smrg*) 776a96d7823Smrg echo "Unknown depmode $depmode" 1>&2 777a96d7823Smrg exit 1 778a96d7823Smrg ;; 779a96d7823Smrgesac 780a96d7823Smrg 781a96d7823Smrgexit 0 782a96d7823Smrg 783a96d7823Smrg# Local Variables: 784a96d7823Smrg# mode: shell-script 785a96d7823Smrg# sh-indentation: 2 78660da515cSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 787a96d7823Smrg# time-stamp-start: "scriptversion=" 788a96d7823Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78960da515cSmrg# time-stamp-time-zone: "UTC0" 790a96d7823Smrg# time-stamp-end: "; # UTC" 791a96d7823Smrg# End: 792