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