1a1d141d5Smrg#! /bin/sh 2a1d141d5Smrg# depcomp - compile a program generating dependencies as side-effects 32ddb6cf1Smrg 426df5c7cSmrgscriptversion=2018-03-07.03; # UTC 52ddb6cf1Smrg 626df5c7cSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7a1d141d5Smrg 8a1d141d5Smrg# This program is free software; you can redistribute it and/or modify 9a1d141d5Smrg# it under the terms of the GNU General Public License as published by 10a1d141d5Smrg# the Free Software Foundation; either version 2, or (at your option) 11a1d141d5Smrg# any later version. 12a1d141d5Smrg 13a1d141d5Smrg# This program is distributed in the hope that it will be useful, 14a1d141d5Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15a1d141d5Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a1d141d5Smrg# GNU General Public License for more details. 17a1d141d5Smrg 18a1d141d5Smrg# You should have received a copy of the GNU General Public License 1926df5c7cSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20a1d141d5Smrg 21a1d141d5Smrg# As a special exception to the GNU General Public License, if you 22a1d141d5Smrg# distribute this file as part of a program that contains a 23a1d141d5Smrg# configuration script generated by Autoconf, you may include it under 24a1d141d5Smrg# the same distribution terms that you use for the rest of that program. 25a1d141d5Smrg 26a1d141d5Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27a1d141d5Smrg 282ddb6cf1Smrgcase $1 in 292ddb6cf1Smrg '') 30054b3d00Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31054b3d00Smrg exit 1; 32054b3d00Smrg ;; 332ddb6cf1Smrg -h | --h*) 342ddb6cf1Smrg cat <<\EOF 352ddb6cf1SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 362ddb6cf1Smrg 372ddb6cf1SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 382ddb6cf1Smrgas side-effects. 392ddb6cf1Smrg 402ddb6cf1SmrgEnvironment variables: 412ddb6cf1Smrg depmode Dependency tracking mode. 42054b3d00Smrg source Source file read by 'PROGRAMS ARGS'. 43054b3d00Smrg object Object file output by 'PROGRAMS ARGS'. 442ddb6cf1Smrg DEPDIR directory where to store dependencies. 452ddb6cf1Smrg depfile Dependency file to output. 46054b3d00Smrg tmpdepfile Temporary file to use when outputting dependencies. 472ddb6cf1Smrg libtool Whether libtool is used (yes/no). 482ddb6cf1Smrg 492ddb6cf1SmrgReport bugs to <bug-automake@gnu.org>. 502ddb6cf1SmrgEOF 512ddb6cf1Smrg exit $? 522ddb6cf1Smrg ;; 532ddb6cf1Smrg -v | --v*) 542ddb6cf1Smrg echo "depcomp $scriptversion" 552ddb6cf1Smrg exit $? 562ddb6cf1Smrg ;; 572ddb6cf1Smrgesac 582ddb6cf1Smrg 59054b3d00Smrg# Get the directory component of the given path, and save it in the 60054b3d00Smrg# global variables '$dir'. Note that this directory component will 61054b3d00Smrg# be either empty or ending with a '/' character. This is deliberate. 62054b3d00Smrgset_dir_from () 63054b3d00Smrg{ 64054b3d00Smrg case $1 in 65054b3d00Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66054b3d00Smrg *) dir=;; 67054b3d00Smrg esac 68054b3d00Smrg} 69054b3d00Smrg 70054b3d00Smrg# Get the suffix-stripped basename of the given path, and save it the 71054b3d00Smrg# global variable '$base'. 72054b3d00Smrgset_base_from () 73054b3d00Smrg{ 74054b3d00Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75054b3d00Smrg} 76054b3d00Smrg 77054b3d00Smrg# If no dependency file was actually created by the compiler invocation, 78054b3d00Smrg# we still have to create a dummy depfile, to avoid errors with the 79054b3d00Smrg# Makefile "include basename.Plo" scheme. 80054b3d00Smrgmake_dummy_depfile () 81054b3d00Smrg{ 82054b3d00Smrg echo "#dummy" > "$depfile" 83054b3d00Smrg} 84054b3d00Smrg 85054b3d00Smrg# Factor out some common post-processing of the generated depfile. 86054b3d00Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87054b3d00Smrgaix_post_process_depfile () 88054b3d00Smrg{ 89054b3d00Smrg # If the compiler actually managed to produce a dependency file, 90054b3d00Smrg # post-process it. 91054b3d00Smrg if test -f "$tmpdepfile"; then 92054b3d00Smrg # Each line is of the form 'foo.o: dependency.h'. 93054b3d00Smrg # Do two passes, one to just change these to 94054b3d00Smrg # $object: dependency.h 95054b3d00Smrg # and one to simply output 96054b3d00Smrg # dependency.h: 97054b3d00Smrg # which is needed to avoid the deleted-header problem. 98054b3d00Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99054b3d00Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100054b3d00Smrg } > "$depfile" 101054b3d00Smrg rm -f "$tmpdepfile" 102054b3d00Smrg else 103054b3d00Smrg make_dummy_depfile 104054b3d00Smrg fi 105054b3d00Smrg} 106054b3d00Smrg 107054b3d00Smrg# A tabulation character. 108054b3d00Smrgtab=' ' 109054b3d00Smrg# A newline character. 110054b3d00Smrgnl=' 111054b3d00Smrg' 112054b3d00Smrg# Character ranges might be problematic outside the C locale. 113054b3d00Smrg# These definitions help. 114054b3d00Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115054b3d00Smrglower=abcdefghijklmnopqrstuvwxyz 116054b3d00Smrgdigits=0123456789 117054b3d00Smrgalpha=${upper}${lower} 118054b3d00Smrg 119a1d141d5Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120a1d141d5Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121a1d141d5Smrg exit 1 122a1d141d5Smrgfi 123a1d141d5Smrg 1242ddb6cf1Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1252ddb6cf1Smrgdepfile=${depfile-`echo "$object" | 1262ddb6cf1Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127a1d141d5Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128a1d141d5Smrg 129a1d141d5Smrgrm -f "$tmpdepfile" 130a1d141d5Smrg 131054b3d00Smrg# Avoid interferences from the environment. 132054b3d00Smrggccflag= dashmflag= 133054b3d00Smrg 134a1d141d5Smrg# Some modes work just like other modes, but use different flags. We 135a1d141d5Smrg# parameterize here, but still list the modes in the big case below, 136a1d141d5Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137a1d141d5Smrg# here, because this file can only contain one case statement. 138a1d141d5Smrgif test "$depmode" = hp; then 139a1d141d5Smrg # HP compiler uses -M and no extra arg. 140a1d141d5Smrg gccflag=-M 141a1d141d5Smrg depmode=gcc 142a1d141d5Smrgfi 143a1d141d5Smrg 144a1d141d5Smrgif test "$depmode" = dashXmstdout; then 145054b3d00Smrg # This is just like dashmstdout with a different argument. 146054b3d00Smrg dashmflag=-xM 147054b3d00Smrg depmode=dashmstdout 148a1d141d5Smrgfi 149a1d141d5Smrg 1502ddb6cf1Smrgcygpath_u="cygpath -u -f -" 1512ddb6cf1Smrgif test "$depmode" = msvcmsys; then 152054b3d00Smrg # This is just like msvisualcpp but w/o cygpath translation. 153054b3d00Smrg # Just convert the backslash-escaped backslashes to single forward 154054b3d00Smrg # slashes to satisfy depend.m4 155054b3d00Smrg cygpath_u='sed s,\\\\,/,g' 156054b3d00Smrg depmode=msvisualcpp 157054b3d00Smrgfi 158054b3d00Smrg 159054b3d00Smrgif test "$depmode" = msvc7msys; then 160054b3d00Smrg # This is just like msvc7 but w/o cygpath translation. 161054b3d00Smrg # Just convert the backslash-escaped backslashes to single forward 162054b3d00Smrg # slashes to satisfy depend.m4 163054b3d00Smrg cygpath_u='sed s,\\\\,/,g' 164054b3d00Smrg depmode=msvc7 165054b3d00Smrgfi 166054b3d00Smrg 167054b3d00Smrgif test "$depmode" = xlc; then 168054b3d00Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169054b3d00Smrg gccflag=-qmakedep=gcc,-MF 170054b3d00Smrg depmode=gcc 1712ddb6cf1Smrgfi 1722ddb6cf1Smrg 173a1d141d5Smrgcase "$depmode" in 174a1d141d5Smrggcc3) 175a1d141d5Smrg## gcc 3 implements dependency tracking that does exactly what 176a1d141d5Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177a1d141d5Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1782ddb6cf1Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1792ddb6cf1Smrg## the command line argument order; so add the flags where they 1802ddb6cf1Smrg## appear in depend2.am. Note that the slowdown incurred here 1812ddb6cf1Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1822ddb6cf1Smrg for arg 1832ddb6cf1Smrg do 1842ddb6cf1Smrg case $arg in 1852ddb6cf1Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1862ddb6cf1Smrg *) set fnord "$@" "$arg" ;; 1872ddb6cf1Smrg esac 1882ddb6cf1Smrg shift # fnord 1892ddb6cf1Smrg shift # $arg 1902ddb6cf1Smrg done 1912ddb6cf1Smrg "$@" 192a1d141d5Smrg stat=$? 193054b3d00Smrg if test $stat -ne 0; then 194a1d141d5Smrg rm -f "$tmpdepfile" 195a1d141d5Smrg exit $stat 196a1d141d5Smrg fi 197a1d141d5Smrg mv "$tmpdepfile" "$depfile" 198a1d141d5Smrg ;; 199a1d141d5Smrg 200a1d141d5Smrggcc) 201054b3d00Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202054b3d00Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203054b3d00Smrg## (see the conditional assignment to $gccflag above). 204a1d141d5Smrg## There are various ways to get dependency output from gcc. Here's 205a1d141d5Smrg## why we pick this rather obscure method: 206a1d141d5Smrg## - Don't want to use -MD because we'd like the dependencies to end 207a1d141d5Smrg## up in a subdir. Having to rename by hand is ugly. 208a1d141d5Smrg## (We might end up doing this anyway to support other compilers.) 209a1d141d5Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210054b3d00Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211054b3d00Smrg## supported by the other compilers which use the 'gcc' depmode. 212a1d141d5Smrg## - Using -M directly means running the compiler twice (even worse 213a1d141d5Smrg## than renaming). 214a1d141d5Smrg if test -z "$gccflag"; then 215a1d141d5Smrg gccflag=-MD, 216a1d141d5Smrg fi 217a1d141d5Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218a1d141d5Smrg stat=$? 219054b3d00Smrg if test $stat -ne 0; then 220a1d141d5Smrg rm -f "$tmpdepfile" 221a1d141d5Smrg exit $stat 222a1d141d5Smrg fi 223a1d141d5Smrg rm -f "$depfile" 224a1d141d5Smrg echo "$object : \\" > "$depfile" 225054b3d00Smrg # The second -e expression handles DOS-style file names with drive 226054b3d00Smrg # letters. 227a1d141d5Smrg sed -e 's/^[^:]*: / /' \ 228a1d141d5Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229054b3d00Smrg## This next piece of magic avoids the "deleted header file" problem. 230a1d141d5Smrg## The problem is that when a header file which appears in a .P file 231a1d141d5Smrg## is deleted, the dependency causes make to die (because there is 232a1d141d5Smrg## typically no way to rebuild the header). We avoid this by adding 233a1d141d5Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234a1d141d5Smrg## this for us directly. 235054b3d00Smrg## Some versions of gcc put a space before the ':'. On the theory 236a1d141d5Smrg## that the space means something, we add a space to the output as 237054b3d00Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238054b3d00Smrg## to the object. Take care to not repeat it in the output. 239a1d141d5Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240a1d141d5Smrg## correctly. Breaking it into two sed invocations is a workaround. 241054b3d00Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242054b3d00Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243054b3d00Smrg | sed -e 's/$/ :/' >> "$depfile" 244a1d141d5Smrg rm -f "$tmpdepfile" 245a1d141d5Smrg ;; 246a1d141d5Smrg 247a1d141d5Smrghp) 248a1d141d5Smrg # This case exists only to let depend.m4 do its work. It works by 249a1d141d5Smrg # looking at the text of this script. This case will never be run, 250a1d141d5Smrg # since it is checked for above. 251a1d141d5Smrg exit 1 252a1d141d5Smrg ;; 253a1d141d5Smrg 254a1d141d5Smrgsgi) 255a1d141d5Smrg if test "$libtool" = yes; then 256a1d141d5Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257a1d141d5Smrg else 258a1d141d5Smrg "$@" -MDupdate "$tmpdepfile" 259a1d141d5Smrg fi 260a1d141d5Smrg stat=$? 261054b3d00Smrg if test $stat -ne 0; then 262a1d141d5Smrg rm -f "$tmpdepfile" 263a1d141d5Smrg exit $stat 264a1d141d5Smrg fi 265a1d141d5Smrg rm -f "$depfile" 266a1d141d5Smrg 267a1d141d5Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268a1d141d5Smrg echo "$object : \\" > "$depfile" 269a1d141d5Smrg # Clip off the initial element (the dependent). Don't try to be 270a1d141d5Smrg # clever and replace this with sed code, as IRIX sed won't handle 271a1d141d5Smrg # lines with more than a fixed number of characters (4096 in 272a1d141d5Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273054b3d00Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274a1d141d5Smrg # dependency line. 275054b3d00Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276054b3d00Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277054b3d00Smrg | tr "$nl" ' ' >> "$depfile" 2782ddb6cf1Smrg echo >> "$depfile" 279a1d141d5Smrg # The second pass generates a dummy entry for each header file. 280054b3d00Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281054b3d00Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282054b3d00Smrg >> "$depfile" 283a1d141d5Smrg else 284054b3d00Smrg make_dummy_depfile 285a1d141d5Smrg fi 286a1d141d5Smrg rm -f "$tmpdepfile" 287a1d141d5Smrg ;; 288a1d141d5Smrg 289054b3d00Smrgxlc) 290054b3d00Smrg # This case exists only to let depend.m4 do its work. It works by 291054b3d00Smrg # looking at the text of this script. This case will never be run, 292054b3d00Smrg # since it is checked for above. 293054b3d00Smrg exit 1 294054b3d00Smrg ;; 295054b3d00Smrg 296a1d141d5Smrgaix) 297a1d141d5Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298a1d141d5Smrg # in a .u file. In older versions, this file always lives in the 299054b3d00Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300a1d141d5Smrg # start of each line; $object doesn't have directory information. 301a1d141d5Smrg # Version 6 uses the directory in both cases. 302054b3d00Smrg set_dir_from "$object" 303054b3d00Smrg set_base_from "$object" 304a1d141d5Smrg if test "$libtool" = yes; then 3052ddb6cf1Smrg tmpdepfile1=$dir$base.u 3062ddb6cf1Smrg tmpdepfile2=$base.u 3072ddb6cf1Smrg tmpdepfile3=$dir.libs/$base.u 308a1d141d5Smrg "$@" -Wc,-M 309a1d141d5Smrg else 3102ddb6cf1Smrg tmpdepfile1=$dir$base.u 3112ddb6cf1Smrg tmpdepfile2=$dir$base.u 3122ddb6cf1Smrg tmpdepfile3=$dir$base.u 313a1d141d5Smrg "$@" -M 314a1d141d5Smrg fi 315a1d141d5Smrg stat=$? 316054b3d00Smrg if test $stat -ne 0; then 3172ddb6cf1Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318a1d141d5Smrg exit $stat 319a1d141d5Smrg fi 320a1d141d5Smrg 3212ddb6cf1Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3222ddb6cf1Smrg do 3232ddb6cf1Smrg test -f "$tmpdepfile" && break 3242ddb6cf1Smrg done 325054b3d00Smrg aix_post_process_depfile 326054b3d00Smrg ;; 327054b3d00Smrg 328054b3d00Smrgtcc) 329054b3d00Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330054b3d00Smrg # FIXME: That version still under development at the moment of writing. 331054b3d00Smrg # Make that this statement remains true also for stable, released 332054b3d00Smrg # versions. 333054b3d00Smrg # It will wrap lines (doesn't matter whether long or short) with a 334054b3d00Smrg # trailing '\', as in: 335054b3d00Smrg # 336054b3d00Smrg # foo.o : \ 337054b3d00Smrg # foo.c \ 338054b3d00Smrg # foo.h \ 339054b3d00Smrg # 340054b3d00Smrg # It will put a trailing '\' even on the last line, and will use leading 341054b3d00Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342054b3d00Smrg # "Emit spaces for -MD"). 343054b3d00Smrg "$@" -MD -MF "$tmpdepfile" 344054b3d00Smrg stat=$? 345054b3d00Smrg if test $stat -ne 0; then 346054b3d00Smrg rm -f "$tmpdepfile" 347054b3d00Smrg exit $stat 348a1d141d5Smrg fi 349054b3d00Smrg rm -f "$depfile" 350054b3d00Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351054b3d00Smrg # We have to change lines of the first kind to '$object: \'. 352054b3d00Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353054b3d00Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354054b3d00Smrg # dummy dependency, to avoid the deleted-header problem. 355054b3d00Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356a1d141d5Smrg rm -f "$tmpdepfile" 357a1d141d5Smrg ;; 358a1d141d5Smrg 359054b3d00Smrg## The order of this option in the case statement is important, since the 360054b3d00Smrg## shell code in configure will try each of these formats in the order 361054b3d00Smrg## listed in this file. A plain '-MD' option would be understood by many 362054b3d00Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363054b3d00Smrgpgcc) 364054b3d00Smrg # Portland's C compiler understands '-MD'. 365054b3d00Smrg # Will always output deps to 'file.d' where file is the root name of the 366054b3d00Smrg # source file under compilation, even if file resides in a subdirectory. 367054b3d00Smrg # The object file name does not affect the name of the '.d' file. 368054b3d00Smrg # pgcc 10.2 will output 369a1d141d5Smrg # foo.o: sub/foo.c sub/foo.h 370054b3d00Smrg # and will wrap long lines using '\' : 371a1d141d5Smrg # foo.o: sub/foo.c ... \ 372a1d141d5Smrg # sub/foo.h ... \ 373a1d141d5Smrg # ... 374054b3d00Smrg set_dir_from "$object" 375054b3d00Smrg # Use the source, not the object, to determine the base name, since 376054b3d00Smrg # that's sadly what pgcc will do too. 377054b3d00Smrg set_base_from "$source" 378054b3d00Smrg tmpdepfile=$base.d 379054b3d00Smrg 380054b3d00Smrg # For projects that build the same source file twice into different object 381054b3d00Smrg # files, the pgcc approach of using the *source* file root name can cause 382054b3d00Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383054b3d00Smrg # the same $tmpdepfile. 384054b3d00Smrg lockdir=$base.d-lock 385054b3d00Smrg trap " 386054b3d00Smrg echo '$0: caught signal, cleaning up...' >&2 387054b3d00Smrg rmdir '$lockdir' 388054b3d00Smrg exit 1 389054b3d00Smrg " 1 2 13 15 390054b3d00Smrg numtries=100 391054b3d00Smrg i=$numtries 392054b3d00Smrg while test $i -gt 0; do 393054b3d00Smrg # mkdir is a portable test-and-set. 394054b3d00Smrg if mkdir "$lockdir" 2>/dev/null; then 395054b3d00Smrg # This process acquired the lock. 396054b3d00Smrg "$@" -MD 397054b3d00Smrg stat=$? 398054b3d00Smrg # Release the lock. 399054b3d00Smrg rmdir "$lockdir" 400054b3d00Smrg break 401054b3d00Smrg else 402054b3d00Smrg # If the lock is being held by a different process, wait 403054b3d00Smrg # until the winning process is done or we timeout. 404054b3d00Smrg while test -d "$lockdir" && test $i -gt 0; do 405054b3d00Smrg sleep 1 406054b3d00Smrg i=`expr $i - 1` 407054b3d00Smrg done 408054b3d00Smrg fi 409054b3d00Smrg i=`expr $i - 1` 410054b3d00Smrg done 411054b3d00Smrg trap - 1 2 13 15 412054b3d00Smrg if test $i -le 0; then 413054b3d00Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414054b3d00Smrg echo "$0: check lockdir '$lockdir'" >&2 415054b3d00Smrg exit 1 416054b3d00Smrg fi 417a1d141d5Smrg 418054b3d00Smrg if test $stat -ne 0; then 419a1d141d5Smrg rm -f "$tmpdepfile" 420a1d141d5Smrg exit $stat 421a1d141d5Smrg fi 422a1d141d5Smrg rm -f "$depfile" 423a1d141d5Smrg # Each line is of the form `foo.o: dependent.h', 424a1d141d5Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425a1d141d5Smrg # Do two passes, one to just change these to 426a1d141d5Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427a1d141d5Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428a1d141d5Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429a1d141d5Smrg # correctly. Breaking it into two sed invocations is a workaround. 430054b3d00Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431054b3d00Smrg | sed -e 's/$/ :/' >> "$depfile" 432a1d141d5Smrg rm -f "$tmpdepfile" 433a1d141d5Smrg ;; 434a1d141d5Smrg 4352ddb6cf1Smrghp2) 4362ddb6cf1Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4372ddb6cf1Smrg # compilers, which have integrated preprocessors. The correct option 4382ddb6cf1Smrg # to use with these is +Maked; it writes dependencies to a file named 4392ddb6cf1Smrg # 'foo.d', which lands next to the object file, wherever that 4402ddb6cf1Smrg # happens to be. 4412ddb6cf1Smrg # Much of this is similar to the tru64 case; see comments there. 442054b3d00Smrg set_dir_from "$object" 443054b3d00Smrg set_base_from "$object" 4442ddb6cf1Smrg if test "$libtool" = yes; then 4452ddb6cf1Smrg tmpdepfile1=$dir$base.d 4462ddb6cf1Smrg tmpdepfile2=$dir.libs/$base.d 4472ddb6cf1Smrg "$@" -Wc,+Maked 4482ddb6cf1Smrg else 4492ddb6cf1Smrg tmpdepfile1=$dir$base.d 4502ddb6cf1Smrg tmpdepfile2=$dir$base.d 4512ddb6cf1Smrg "$@" +Maked 4522ddb6cf1Smrg fi 4532ddb6cf1Smrg stat=$? 454054b3d00Smrg if test $stat -ne 0; then 4552ddb6cf1Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4562ddb6cf1Smrg exit $stat 4572ddb6cf1Smrg fi 4582ddb6cf1Smrg 4592ddb6cf1Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4602ddb6cf1Smrg do 4612ddb6cf1Smrg test -f "$tmpdepfile" && break 4622ddb6cf1Smrg done 4632ddb6cf1Smrg if test -f "$tmpdepfile"; then 464054b3d00Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465054b3d00Smrg # Add 'dependent.h:' lines. 4662ddb6cf1Smrg sed -ne '2,${ 467054b3d00Smrg s/^ *// 468054b3d00Smrg s/ \\*$// 469054b3d00Smrg s/$/:/ 470054b3d00Smrg p 471054b3d00Smrg }' "$tmpdepfile" >> "$depfile" 4722ddb6cf1Smrg else 473054b3d00Smrg make_dummy_depfile 4742ddb6cf1Smrg fi 4752ddb6cf1Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4762ddb6cf1Smrg ;; 4772ddb6cf1Smrg 478a1d141d5Smrgtru64) 479054b3d00Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480054b3d00Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481054b3d00Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482054b3d00Smrg # dependencies in 'foo.d' instead, so we check for that too. 483054b3d00Smrg # Subdirectories are respected. 484054b3d00Smrg set_dir_from "$object" 485054b3d00Smrg set_base_from "$object" 486054b3d00Smrg 487054b3d00Smrg if test "$libtool" = yes; then 488054b3d00Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489054b3d00Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490054b3d00Smrg # in $dir$base.o.d. We have to check for both files, because 491054b3d00Smrg # one of the two compilations can be disabled. We should prefer 492054b3d00Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493054b3d00Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494054b3d00Smrg # the former would cause a distcleancheck panic. 495054b3d00Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496054b3d00Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497054b3d00Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498054b3d00Smrg "$@" -Wc,-MD 499054b3d00Smrg else 500054b3d00Smrg tmpdepfile1=$dir$base.d 501054b3d00Smrg tmpdepfile2=$dir$base.d 502054b3d00Smrg tmpdepfile3=$dir$base.d 503054b3d00Smrg "$@" -MD 504054b3d00Smrg fi 505054b3d00Smrg 506054b3d00Smrg stat=$? 507054b3d00Smrg if test $stat -ne 0; then 508054b3d00Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509054b3d00Smrg exit $stat 510054b3d00Smrg fi 511054b3d00Smrg 512054b3d00Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513054b3d00Smrg do 514054b3d00Smrg test -f "$tmpdepfile" && break 515054b3d00Smrg done 516054b3d00Smrg # Same post-processing that is required for AIX mode. 517054b3d00Smrg aix_post_process_depfile 518054b3d00Smrg ;; 519054b3d00Smrg 520054b3d00Smrgmsvc7) 521054b3d00Smrg if test "$libtool" = yes; then 522054b3d00Smrg showIncludes=-Wc,-showIncludes 523054b3d00Smrg else 524054b3d00Smrg showIncludes=-showIncludes 525054b3d00Smrg fi 526054b3d00Smrg "$@" $showIncludes > "$tmpdepfile" 527054b3d00Smrg stat=$? 528054b3d00Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529054b3d00Smrg if test $stat -ne 0; then 530054b3d00Smrg rm -f "$tmpdepfile" 531054b3d00Smrg exit $stat 532054b3d00Smrg fi 533054b3d00Smrg rm -f "$depfile" 534054b3d00Smrg echo "$object : \\" > "$depfile" 535054b3d00Smrg # The first sed program below extracts the file names and escapes 536054b3d00Smrg # backslashes for cygpath. The second sed program outputs the file 537054b3d00Smrg # name when reading, but also accumulates all include files in the 538054b3d00Smrg # hold buffer in order to output them again at the end. This only 539054b3d00Smrg # works with sed implementations that can handle large buffers. 540054b3d00Smrg sed < "$tmpdepfile" -n ' 541054b3d00Smrg/^Note: including file: *\(.*\)/ { 542054b3d00Smrg s//\1/ 543054b3d00Smrg s/\\/\\\\/g 544054b3d00Smrg p 545054b3d00Smrg}' | $cygpath_u | sort -u | sed -n ' 546054b3d00Smrgs/ /\\ /g 547054b3d00Smrgs/\(.*\)/'"$tab"'\1 \\/p 548054b3d00Smrgs/.\(.*\) \\/\1:/ 549054b3d00SmrgH 550054b3d00Smrg$ { 551054b3d00Smrg s/.*/'"$tab"'/ 552054b3d00Smrg G 553054b3d00Smrg p 554054b3d00Smrg}' >> "$depfile" 555054b3d00Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556054b3d00Smrg rm -f "$tmpdepfile" 557054b3d00Smrg ;; 558054b3d00Smrg 559054b3d00Smrgmsvc7msys) 560054b3d00Smrg # This case exists only to let depend.m4 do its work. It works by 561054b3d00Smrg # looking at the text of this script. This case will never be run, 562054b3d00Smrg # since it is checked for above. 563054b3d00Smrg exit 1 564054b3d00Smrg ;; 565a1d141d5Smrg 566a1d141d5Smrg#nosideeffect) 567a1d141d5Smrg # This comment above is used by automake to tell side-effect 568a1d141d5Smrg # dependency tracking mechanisms from slower ones. 569a1d141d5Smrg 570a1d141d5Smrgdashmstdout) 571a1d141d5Smrg # Important note: in order to support this mode, a compiler *must* 572a1d141d5Smrg # always write the preprocessed file to stdout, regardless of -o. 573a1d141d5Smrg "$@" || exit $? 574a1d141d5Smrg 575a1d141d5Smrg # Remove the call to Libtool. 576a1d141d5Smrg if test "$libtool" = yes; then 5772ddb6cf1Smrg while test "X$1" != 'X--mode=compile'; do 578a1d141d5Smrg shift 579a1d141d5Smrg done 580a1d141d5Smrg shift 581a1d141d5Smrg fi 582a1d141d5Smrg 583054b3d00Smrg # Remove '-o $object'. 584a1d141d5Smrg IFS=" " 585a1d141d5Smrg for arg 586a1d141d5Smrg do 587a1d141d5Smrg case $arg in 588a1d141d5Smrg -o) 589a1d141d5Smrg shift 590a1d141d5Smrg ;; 591a1d141d5Smrg $object) 592a1d141d5Smrg shift 593a1d141d5Smrg ;; 594a1d141d5Smrg *) 595a1d141d5Smrg set fnord "$@" "$arg" 596a1d141d5Smrg shift # fnord 597a1d141d5Smrg shift # $arg 598a1d141d5Smrg ;; 599a1d141d5Smrg esac 600a1d141d5Smrg done 601a1d141d5Smrg 602a1d141d5Smrg test -z "$dashmflag" && dashmflag=-M 603054b3d00Smrg # Require at least two characters before searching for ':' 604a1d141d5Smrg # in the target name. This is to cope with DOS-style filenames: 605054b3d00Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606a1d141d5Smrg "$@" $dashmflag | 607054b3d00Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608a1d141d5Smrg rm -f "$depfile" 609a1d141d5Smrg cat < "$tmpdepfile" > "$depfile" 610054b3d00Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611054b3d00Smrg # correctly. Breaking it into two sed invocations is a workaround. 612054b3d00Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613054b3d00Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614054b3d00Smrg | sed -e 's/$/ :/' >> "$depfile" 615a1d141d5Smrg rm -f "$tmpdepfile" 616a1d141d5Smrg ;; 617a1d141d5Smrg 618a1d141d5SmrgdashXmstdout) 619a1d141d5Smrg # This case only exists to satisfy depend.m4. It is never actually 620a1d141d5Smrg # run, as this mode is specially recognized in the preamble. 621a1d141d5Smrg exit 1 622a1d141d5Smrg ;; 623a1d141d5Smrg 624a1d141d5Smrgmakedepend) 625a1d141d5Smrg "$@" || exit $? 626a1d141d5Smrg # Remove any Libtool call 627a1d141d5Smrg if test "$libtool" = yes; then 6282ddb6cf1Smrg while test "X$1" != 'X--mode=compile'; do 629a1d141d5Smrg shift 630a1d141d5Smrg done 631a1d141d5Smrg shift 632a1d141d5Smrg fi 633a1d141d5Smrg # X makedepend 634a1d141d5Smrg shift 6352ddb6cf1Smrg cleared=no eat=no 6362ddb6cf1Smrg for arg 6372ddb6cf1Smrg do 638a1d141d5Smrg case $cleared in 639a1d141d5Smrg no) 640a1d141d5Smrg set ""; shift 641a1d141d5Smrg cleared=yes ;; 642a1d141d5Smrg esac 6432ddb6cf1Smrg if test $eat = yes; then 6442ddb6cf1Smrg eat=no 6452ddb6cf1Smrg continue 6462ddb6cf1Smrg fi 647a1d141d5Smrg case "$arg" in 648a1d141d5Smrg -D*|-I*) 649a1d141d5Smrg set fnord "$@" "$arg"; shift ;; 650a1d141d5Smrg # Strip any option that makedepend may not understand. Remove 651a1d141d5Smrg # the object too, otherwise makedepend will parse it as a source file. 6522ddb6cf1Smrg -arch) 6532ddb6cf1Smrg eat=yes ;; 654a1d141d5Smrg -*|$object) 655a1d141d5Smrg ;; 656a1d141d5Smrg *) 657a1d141d5Smrg set fnord "$@" "$arg"; shift ;; 658a1d141d5Smrg esac 659a1d141d5Smrg done 6602ddb6cf1Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661a1d141d5Smrg touch "$tmpdepfile" 662a1d141d5Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663a1d141d5Smrg rm -f "$depfile" 664054b3d00Smrg # makedepend may prepend the VPATH from the source file name to the object. 665054b3d00Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666054b3d00Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667054b3d00Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668054b3d00Smrg # correctly. Breaking it into two sed invocations is a workaround. 669054b3d00Smrg sed '1,2d' "$tmpdepfile" \ 670054b3d00Smrg | tr ' ' "$nl" \ 671054b3d00Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672054b3d00Smrg | sed -e 's/$/ :/' >> "$depfile" 673a1d141d5Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674a1d141d5Smrg ;; 675a1d141d5Smrg 676a1d141d5Smrgcpp) 677a1d141d5Smrg # Important note: in order to support this mode, a compiler *must* 678a1d141d5Smrg # always write the preprocessed file to stdout. 679a1d141d5Smrg "$@" || exit $? 680a1d141d5Smrg 681a1d141d5Smrg # Remove the call to Libtool. 682a1d141d5Smrg if test "$libtool" = yes; then 6832ddb6cf1Smrg while test "X$1" != 'X--mode=compile'; do 684a1d141d5Smrg shift 685a1d141d5Smrg done 686a1d141d5Smrg shift 687a1d141d5Smrg fi 688a1d141d5Smrg 689054b3d00Smrg # Remove '-o $object'. 690a1d141d5Smrg IFS=" " 691a1d141d5Smrg for arg 692a1d141d5Smrg do 693a1d141d5Smrg case $arg in 694a1d141d5Smrg -o) 695a1d141d5Smrg shift 696a1d141d5Smrg ;; 697a1d141d5Smrg $object) 698a1d141d5Smrg shift 699a1d141d5Smrg ;; 700a1d141d5Smrg *) 701a1d141d5Smrg set fnord "$@" "$arg" 702a1d141d5Smrg shift # fnord 703a1d141d5Smrg shift # $arg 704a1d141d5Smrg ;; 705a1d141d5Smrg esac 706a1d141d5Smrg done 707a1d141d5Smrg 708054b3d00Smrg "$@" -E \ 709054b3d00Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710054b3d00Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711054b3d00Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712a1d141d5Smrg rm -f "$depfile" 713a1d141d5Smrg echo "$object : \\" > "$depfile" 714a1d141d5Smrg cat < "$tmpdepfile" >> "$depfile" 715a1d141d5Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716a1d141d5Smrg rm -f "$tmpdepfile" 717a1d141d5Smrg ;; 718a1d141d5Smrg 719a1d141d5Smrgmsvisualcpp) 720a1d141d5Smrg # Important note: in order to support this mode, a compiler *must* 7212ddb6cf1Smrg # always write the preprocessed file to stdout. 722a1d141d5Smrg "$@" || exit $? 7232ddb6cf1Smrg 7242ddb6cf1Smrg # Remove the call to Libtool. 7252ddb6cf1Smrg if test "$libtool" = yes; then 7262ddb6cf1Smrg while test "X$1" != 'X--mode=compile'; do 7272ddb6cf1Smrg shift 7282ddb6cf1Smrg done 7292ddb6cf1Smrg shift 7302ddb6cf1Smrg fi 7312ddb6cf1Smrg 732a1d141d5Smrg IFS=" " 733a1d141d5Smrg for arg 734a1d141d5Smrg do 735a1d141d5Smrg case "$arg" in 7362ddb6cf1Smrg -o) 7372ddb6cf1Smrg shift 7382ddb6cf1Smrg ;; 7392ddb6cf1Smrg $object) 7402ddb6cf1Smrg shift 7412ddb6cf1Smrg ;; 742a1d141d5Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743054b3d00Smrg set fnord "$@" 744054b3d00Smrg shift 745054b3d00Smrg shift 746054b3d00Smrg ;; 747a1d141d5Smrg *) 748054b3d00Smrg set fnord "$@" "$arg" 749054b3d00Smrg shift 750054b3d00Smrg shift 751054b3d00Smrg ;; 752a1d141d5Smrg esac 753a1d141d5Smrg done 7542ddb6cf1Smrg "$@" -E 2>/dev/null | 7552ddb6cf1Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756a1d141d5Smrg rm -f "$depfile" 757a1d141d5Smrg echo "$object : \\" > "$depfile" 758054b3d00Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759054b3d00Smrg echo "$tab" >> "$depfile" 7602ddb6cf1Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761a1d141d5Smrg rm -f "$tmpdepfile" 762a1d141d5Smrg ;; 763a1d141d5Smrg 7642ddb6cf1Smrgmsvcmsys) 7652ddb6cf1Smrg # This case exists only to let depend.m4 do its work. It works by 7662ddb6cf1Smrg # looking at the text of this script. This case will never be run, 7672ddb6cf1Smrg # since it is checked for above. 7682ddb6cf1Smrg exit 1 7692ddb6cf1Smrg ;; 7702ddb6cf1Smrg 771a1d141d5Smrgnone) 772a1d141d5Smrg exec "$@" 773a1d141d5Smrg ;; 774a1d141d5Smrg 775a1d141d5Smrg*) 776a1d141d5Smrg echo "Unknown depmode $depmode" 1>&2 777a1d141d5Smrg exit 1 778a1d141d5Smrg ;; 779a1d141d5Smrgesac 780a1d141d5Smrg 781a1d141d5Smrgexit 0 7822ddb6cf1Smrg 7832ddb6cf1Smrg# Local Variables: 7842ddb6cf1Smrg# mode: shell-script 7852ddb6cf1Smrg# sh-indentation: 2 78626df5c7cSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7872ddb6cf1Smrg# time-stamp-start: "scriptversion=" 7882ddb6cf1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78926df5c7cSmrg# time-stamp-time-zone: "UTC0" 7902ddb6cf1Smrg# time-stamp-end: "; # UTC" 7912ddb6cf1Smrg# End: 792