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