18dd3e0eeSmrg#! /bin/sh 28dd3e0eeSmrg# depcomp - compile a program generating dependencies as side-effects 38dd3e0eeSmrg 427485fbcSmrgscriptversion=2018-03-07.03; # UTC 58dd3e0eeSmrg 627485fbcSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 78dd3e0eeSmrg 88dd3e0eeSmrg# This program is free software; you can redistribute it and/or modify 98dd3e0eeSmrg# it under the terms of the GNU General Public License as published by 108dd3e0eeSmrg# the Free Software Foundation; either version 2, or (at your option) 118dd3e0eeSmrg# any later version. 128dd3e0eeSmrg 138dd3e0eeSmrg# This program is distributed in the hope that it will be useful, 148dd3e0eeSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 158dd3e0eeSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 168dd3e0eeSmrg# GNU General Public License for more details. 178dd3e0eeSmrg 188dd3e0eeSmrg# You should have received a copy of the GNU General Public License 1927485fbcSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 208dd3e0eeSmrg 218dd3e0eeSmrg# As a special exception to the GNU General Public License, if you 228dd3e0eeSmrg# distribute this file as part of a program that contains a 238dd3e0eeSmrg# configuration script generated by Autoconf, you may include it under 248dd3e0eeSmrg# the same distribution terms that you use for the rest of that program. 258dd3e0eeSmrg 268dd3e0eeSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 278dd3e0eeSmrg 288dd3e0eeSmrgcase $1 in 298dd3e0eeSmrg '') 30d5a688bcSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31d5a688bcSmrg exit 1; 32d5a688bcSmrg ;; 338dd3e0eeSmrg -h | --h*) 348dd3e0eeSmrg cat <<\EOF 358dd3e0eeSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 368dd3e0eeSmrg 378dd3e0eeSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 388dd3e0eeSmrgas side-effects. 398dd3e0eeSmrg 408dd3e0eeSmrgEnvironment variables: 418dd3e0eeSmrg depmode Dependency tracking mode. 42d5a688bcSmrg source Source file read by 'PROGRAMS ARGS'. 43d5a688bcSmrg object Object file output by 'PROGRAMS ARGS'. 448dd3e0eeSmrg DEPDIR directory where to store dependencies. 458dd3e0eeSmrg depfile Dependency file to output. 46d5a688bcSmrg tmpdepfile Temporary file to use when outputting dependencies. 478dd3e0eeSmrg libtool Whether libtool is used (yes/no). 488dd3e0eeSmrg 498dd3e0eeSmrgReport bugs to <bug-automake@gnu.org>. 508dd3e0eeSmrgEOF 518dd3e0eeSmrg exit $? 528dd3e0eeSmrg ;; 538dd3e0eeSmrg -v | --v*) 548dd3e0eeSmrg echo "depcomp $scriptversion" 558dd3e0eeSmrg exit $? 568dd3e0eeSmrg ;; 578dd3e0eeSmrgesac 588dd3e0eeSmrg 59d5a688bcSmrg# Get the directory component of the given path, and save it in the 60d5a688bcSmrg# global variables '$dir'. Note that this directory component will 61d5a688bcSmrg# be either empty or ending with a '/' character. This is deliberate. 62d5a688bcSmrgset_dir_from () 63d5a688bcSmrg{ 64d5a688bcSmrg case $1 in 65d5a688bcSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66d5a688bcSmrg *) dir=;; 67d5a688bcSmrg esac 68d5a688bcSmrg} 69d5a688bcSmrg 70d5a688bcSmrg# Get the suffix-stripped basename of the given path, and save it the 71d5a688bcSmrg# global variable '$base'. 72d5a688bcSmrgset_base_from () 73d5a688bcSmrg{ 74d5a688bcSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75d5a688bcSmrg} 76d5a688bcSmrg 77d5a688bcSmrg# If no dependency file was actually created by the compiler invocation, 78d5a688bcSmrg# we still have to create a dummy depfile, to avoid errors with the 79d5a688bcSmrg# Makefile "include basename.Plo" scheme. 80d5a688bcSmrgmake_dummy_depfile () 81d5a688bcSmrg{ 82d5a688bcSmrg echo "#dummy" > "$depfile" 83d5a688bcSmrg} 84d5a688bcSmrg 85d5a688bcSmrg# Factor out some common post-processing of the generated depfile. 86d5a688bcSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87d5a688bcSmrgaix_post_process_depfile () 88d5a688bcSmrg{ 89d5a688bcSmrg # If the compiler actually managed to produce a dependency file, 90d5a688bcSmrg # post-process it. 91d5a688bcSmrg if test -f "$tmpdepfile"; then 92d5a688bcSmrg # Each line is of the form 'foo.o: dependency.h'. 93d5a688bcSmrg # Do two passes, one to just change these to 94d5a688bcSmrg # $object: dependency.h 95d5a688bcSmrg # and one to simply output 96d5a688bcSmrg # dependency.h: 97d5a688bcSmrg # which is needed to avoid the deleted-header problem. 98d5a688bcSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99d5a688bcSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100d5a688bcSmrg } > "$depfile" 101d5a688bcSmrg rm -f "$tmpdepfile" 102d5a688bcSmrg else 103d5a688bcSmrg make_dummy_depfile 104d5a688bcSmrg fi 105d5a688bcSmrg} 106d5a688bcSmrg 107d5a688bcSmrg# A tabulation character. 108d5a688bcSmrgtab=' ' 109d5a688bcSmrg# A newline character. 110d5a688bcSmrgnl=' 111d5a688bcSmrg' 112d5a688bcSmrg# Character ranges might be problematic outside the C locale. 113d5a688bcSmrg# These definitions help. 114d5a688bcSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115d5a688bcSmrglower=abcdefghijklmnopqrstuvwxyz 116d5a688bcSmrgdigits=0123456789 117d5a688bcSmrgalpha=${upper}${lower} 118d5a688bcSmrg 1198dd3e0eeSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1208dd3e0eeSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1218dd3e0eeSmrg exit 1 1228dd3e0eeSmrgfi 1238dd3e0eeSmrg 1248dd3e0eeSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1258dd3e0eeSmrgdepfile=${depfile-`echo "$object" | 1268dd3e0eeSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1278dd3e0eeSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1288dd3e0eeSmrg 1298dd3e0eeSmrgrm -f "$tmpdepfile" 1308dd3e0eeSmrg 131d5a688bcSmrg# Avoid interferences from the environment. 132d5a688bcSmrggccflag= dashmflag= 133d5a688bcSmrg 1348dd3e0eeSmrg# Some modes work just like other modes, but use different flags. We 1358dd3e0eeSmrg# parameterize here, but still list the modes in the big case below, 1368dd3e0eeSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1378dd3e0eeSmrg# here, because this file can only contain one case statement. 1388dd3e0eeSmrgif test "$depmode" = hp; then 1398dd3e0eeSmrg # HP compiler uses -M and no extra arg. 1408dd3e0eeSmrg gccflag=-M 1418dd3e0eeSmrg depmode=gcc 1428dd3e0eeSmrgfi 1438dd3e0eeSmrg 1448dd3e0eeSmrgif test "$depmode" = dashXmstdout; then 145d5a688bcSmrg # This is just like dashmstdout with a different argument. 146d5a688bcSmrg dashmflag=-xM 147d5a688bcSmrg depmode=dashmstdout 1488dd3e0eeSmrgfi 1498dd3e0eeSmrg 150329fdfe9Smrgcygpath_u="cygpath -u -f -" 151329fdfe9Smrgif test "$depmode" = msvcmsys; then 152d5a688bcSmrg # This is just like msvisualcpp but w/o cygpath translation. 153d5a688bcSmrg # Just convert the backslash-escaped backslashes to single forward 154d5a688bcSmrg # slashes to satisfy depend.m4 155d5a688bcSmrg cygpath_u='sed s,\\\\,/,g' 156d5a688bcSmrg depmode=msvisualcpp 157d5a688bcSmrgfi 158d5a688bcSmrg 159d5a688bcSmrgif test "$depmode" = msvc7msys; then 160d5a688bcSmrg # This is just like msvc7 but w/o cygpath translation. 161d5a688bcSmrg # Just convert the backslash-escaped backslashes to single forward 162d5a688bcSmrg # slashes to satisfy depend.m4 163d5a688bcSmrg cygpath_u='sed s,\\\\,/,g' 164d5a688bcSmrg depmode=msvc7 165d5a688bcSmrgfi 166d5a688bcSmrg 167d5a688bcSmrgif test "$depmode" = xlc; then 168d5a688bcSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169d5a688bcSmrg gccflag=-qmakedep=gcc,-MF 170d5a688bcSmrg depmode=gcc 171329fdfe9Smrgfi 172329fdfe9Smrg 1738dd3e0eeSmrgcase "$depmode" in 1748dd3e0eeSmrggcc3) 1758dd3e0eeSmrg## gcc 3 implements dependency tracking that does exactly what 1768dd3e0eeSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1778dd3e0eeSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 1788dd3e0eeSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1798dd3e0eeSmrg## the command line argument order; so add the flags where they 1808dd3e0eeSmrg## appear in depend2.am. Note that the slowdown incurred here 1818dd3e0eeSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1828dd3e0eeSmrg for arg 1838dd3e0eeSmrg do 1848dd3e0eeSmrg case $arg in 1858dd3e0eeSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1868dd3e0eeSmrg *) set fnord "$@" "$arg" ;; 1878dd3e0eeSmrg esac 1888dd3e0eeSmrg shift # fnord 1898dd3e0eeSmrg shift # $arg 1908dd3e0eeSmrg done 1918dd3e0eeSmrg "$@" 1928dd3e0eeSmrg stat=$? 193d5a688bcSmrg if test $stat -ne 0; then 1948dd3e0eeSmrg rm -f "$tmpdepfile" 1958dd3e0eeSmrg exit $stat 1968dd3e0eeSmrg fi 1978dd3e0eeSmrg mv "$tmpdepfile" "$depfile" 1988dd3e0eeSmrg ;; 1998dd3e0eeSmrg 2008dd3e0eeSmrggcc) 201d5a688bcSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202d5a688bcSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203d5a688bcSmrg## (see the conditional assignment to $gccflag above). 2048dd3e0eeSmrg## There are various ways to get dependency output from gcc. Here's 2058dd3e0eeSmrg## why we pick this rather obscure method: 2068dd3e0eeSmrg## - Don't want to use -MD because we'd like the dependencies to end 2078dd3e0eeSmrg## up in a subdir. Having to rename by hand is ugly. 2088dd3e0eeSmrg## (We might end up doing this anyway to support other compilers.) 2098dd3e0eeSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210d5a688bcSmrg## -MM, not -M (despite what the docs say). Also, it might not be 211d5a688bcSmrg## supported by the other compilers which use the 'gcc' depmode. 2128dd3e0eeSmrg## - Using -M directly means running the compiler twice (even worse 2138dd3e0eeSmrg## than renaming). 2148dd3e0eeSmrg if test -z "$gccflag"; then 2158dd3e0eeSmrg gccflag=-MD, 2168dd3e0eeSmrg fi 2178dd3e0eeSmrg "$@" -Wp,"$gccflag$tmpdepfile" 2188dd3e0eeSmrg stat=$? 219d5a688bcSmrg if test $stat -ne 0; then 2208dd3e0eeSmrg rm -f "$tmpdepfile" 2218dd3e0eeSmrg exit $stat 2228dd3e0eeSmrg fi 2238dd3e0eeSmrg rm -f "$depfile" 2248dd3e0eeSmrg echo "$object : \\" > "$depfile" 225d5a688bcSmrg # The second -e expression handles DOS-style file names with drive 226d5a688bcSmrg # letters. 2278dd3e0eeSmrg sed -e 's/^[^:]*: / /' \ 2288dd3e0eeSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229d5a688bcSmrg## This next piece of magic avoids the "deleted header file" problem. 2308dd3e0eeSmrg## The problem is that when a header file which appears in a .P file 2318dd3e0eeSmrg## is deleted, the dependency causes make to die (because there is 2328dd3e0eeSmrg## typically no way to rebuild the header). We avoid this by adding 2338dd3e0eeSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 2348dd3e0eeSmrg## this for us directly. 235d5a688bcSmrg## Some versions of gcc put a space before the ':'. On the theory 2368dd3e0eeSmrg## that the space means something, we add a space to the output as 237d5a688bcSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 238d5a688bcSmrg## to the object. Take care to not repeat it in the output. 2398dd3e0eeSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 2408dd3e0eeSmrg## correctly. Breaking it into two sed invocations is a workaround. 241d5a688bcSmrg tr ' ' "$nl" < "$tmpdepfile" \ 242d5a688bcSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243d5a688bcSmrg | sed -e 's/$/ :/' >> "$depfile" 2448dd3e0eeSmrg rm -f "$tmpdepfile" 2458dd3e0eeSmrg ;; 2468dd3e0eeSmrg 2478dd3e0eeSmrghp) 2488dd3e0eeSmrg # This case exists only to let depend.m4 do its work. It works by 2498dd3e0eeSmrg # looking at the text of this script. This case will never be run, 2508dd3e0eeSmrg # since it is checked for above. 2518dd3e0eeSmrg exit 1 2528dd3e0eeSmrg ;; 2538dd3e0eeSmrg 2548dd3e0eeSmrgsgi) 2558dd3e0eeSmrg if test "$libtool" = yes; then 2568dd3e0eeSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2578dd3e0eeSmrg else 2588dd3e0eeSmrg "$@" -MDupdate "$tmpdepfile" 2598dd3e0eeSmrg fi 2608dd3e0eeSmrg stat=$? 261d5a688bcSmrg if test $stat -ne 0; then 2628dd3e0eeSmrg rm -f "$tmpdepfile" 2638dd3e0eeSmrg exit $stat 2648dd3e0eeSmrg fi 2658dd3e0eeSmrg rm -f "$depfile" 2668dd3e0eeSmrg 2678dd3e0eeSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2688dd3e0eeSmrg echo "$object : \\" > "$depfile" 2698dd3e0eeSmrg # Clip off the initial element (the dependent). Don't try to be 2708dd3e0eeSmrg # clever and replace this with sed code, as IRIX sed won't handle 2718dd3e0eeSmrg # lines with more than a fixed number of characters (4096 in 2728dd3e0eeSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273d5a688bcSmrg # the IRIX cc adds comments like '#:fec' to the end of the 2748dd3e0eeSmrg # dependency line. 275d5a688bcSmrg tr ' ' "$nl" < "$tmpdepfile" \ 276d5a688bcSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277d5a688bcSmrg | tr "$nl" ' ' >> "$depfile" 278329fdfe9Smrg echo >> "$depfile" 2798dd3e0eeSmrg # The second pass generates a dummy entry for each header file. 280d5a688bcSmrg tr ' ' "$nl" < "$tmpdepfile" \ 281d5a688bcSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282d5a688bcSmrg >> "$depfile" 2838dd3e0eeSmrg else 284d5a688bcSmrg make_dummy_depfile 2858dd3e0eeSmrg fi 2868dd3e0eeSmrg rm -f "$tmpdepfile" 2878dd3e0eeSmrg ;; 2888dd3e0eeSmrg 289d5a688bcSmrgxlc) 290d5a688bcSmrg # This case exists only to let depend.m4 do its work. It works by 291d5a688bcSmrg # looking at the text of this script. This case will never be run, 292d5a688bcSmrg # since it is checked for above. 293d5a688bcSmrg exit 1 294d5a688bcSmrg ;; 295d5a688bcSmrg 2968dd3e0eeSmrgaix) 2978dd3e0eeSmrg # The C for AIX Compiler uses -M and outputs the dependencies 2988dd3e0eeSmrg # in a .u file. In older versions, this file always lives in the 299d5a688bcSmrg # current directory. Also, the AIX compiler puts '$object:' at the 3008dd3e0eeSmrg # start of each line; $object doesn't have directory information. 3018dd3e0eeSmrg # Version 6 uses the directory in both cases. 302d5a688bcSmrg set_dir_from "$object" 303d5a688bcSmrg set_base_from "$object" 3048dd3e0eeSmrg if test "$libtool" = yes; then 305329fdfe9Smrg tmpdepfile1=$dir$base.u 306329fdfe9Smrg tmpdepfile2=$base.u 307329fdfe9Smrg tmpdepfile3=$dir.libs/$base.u 3088dd3e0eeSmrg "$@" -Wc,-M 3098dd3e0eeSmrg else 310329fdfe9Smrg tmpdepfile1=$dir$base.u 311329fdfe9Smrg tmpdepfile2=$dir$base.u 312329fdfe9Smrg tmpdepfile3=$dir$base.u 3138dd3e0eeSmrg "$@" -M 3148dd3e0eeSmrg fi 3158dd3e0eeSmrg stat=$? 316d5a688bcSmrg if test $stat -ne 0; then 317329fdfe9Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3188dd3e0eeSmrg exit $stat 3198dd3e0eeSmrg fi 3208dd3e0eeSmrg 321329fdfe9Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322329fdfe9Smrg do 323329fdfe9Smrg test -f "$tmpdepfile" && break 324329fdfe9Smrg done 325d5a688bcSmrg aix_post_process_depfile 326d5a688bcSmrg ;; 327d5a688bcSmrg 328d5a688bcSmrgtcc) 329d5a688bcSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330d5a688bcSmrg # FIXME: That version still under development at the moment of writing. 331d5a688bcSmrg # Make that this statement remains true also for stable, released 332d5a688bcSmrg # versions. 333d5a688bcSmrg # It will wrap lines (doesn't matter whether long or short) with a 334d5a688bcSmrg # trailing '\', as in: 335d5a688bcSmrg # 336d5a688bcSmrg # foo.o : \ 337d5a688bcSmrg # foo.c \ 338d5a688bcSmrg # foo.h \ 339d5a688bcSmrg # 340d5a688bcSmrg # It will put a trailing '\' even on the last line, and will use leading 341d5a688bcSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 342d5a688bcSmrg # "Emit spaces for -MD"). 343d5a688bcSmrg "$@" -MD -MF "$tmpdepfile" 344d5a688bcSmrg stat=$? 345d5a688bcSmrg if test $stat -ne 0; then 346d5a688bcSmrg rm -f "$tmpdepfile" 347d5a688bcSmrg exit $stat 3488dd3e0eeSmrg fi 349d5a688bcSmrg rm -f "$depfile" 350d5a688bcSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351d5a688bcSmrg # We have to change lines of the first kind to '$object: \'. 352d5a688bcSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353d5a688bcSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 354d5a688bcSmrg # dummy dependency, to avoid the deleted-header problem. 355d5a688bcSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3568dd3e0eeSmrg rm -f "$tmpdepfile" 3578dd3e0eeSmrg ;; 3588dd3e0eeSmrg 359d5a688bcSmrg## The order of this option in the case statement is important, since the 360d5a688bcSmrg## shell code in configure will try each of these formats in the order 361d5a688bcSmrg## listed in this file. A plain '-MD' option would be understood by many 362d5a688bcSmrg## compilers, so we must ensure this comes after the gcc and icc options. 363d5a688bcSmrgpgcc) 364d5a688bcSmrg # Portland's C compiler understands '-MD'. 365d5a688bcSmrg # Will always output deps to 'file.d' where file is the root name of the 366d5a688bcSmrg # source file under compilation, even if file resides in a subdirectory. 367d5a688bcSmrg # The object file name does not affect the name of the '.d' file. 368d5a688bcSmrg # pgcc 10.2 will output 3698dd3e0eeSmrg # foo.o: sub/foo.c sub/foo.h 370d5a688bcSmrg # and will wrap long lines using '\' : 3718dd3e0eeSmrg # foo.o: sub/foo.c ... \ 3728dd3e0eeSmrg # sub/foo.h ... \ 3738dd3e0eeSmrg # ... 374d5a688bcSmrg set_dir_from "$object" 375d5a688bcSmrg # Use the source, not the object, to determine the base name, since 376d5a688bcSmrg # that's sadly what pgcc will do too. 377d5a688bcSmrg set_base_from "$source" 378d5a688bcSmrg tmpdepfile=$base.d 379d5a688bcSmrg 380d5a688bcSmrg # For projects that build the same source file twice into different object 381d5a688bcSmrg # files, the pgcc approach of using the *source* file root name can cause 382d5a688bcSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383d5a688bcSmrg # the same $tmpdepfile. 384d5a688bcSmrg lockdir=$base.d-lock 385d5a688bcSmrg trap " 386d5a688bcSmrg echo '$0: caught signal, cleaning up...' >&2 387d5a688bcSmrg rmdir '$lockdir' 388d5a688bcSmrg exit 1 389d5a688bcSmrg " 1 2 13 15 390d5a688bcSmrg numtries=100 391d5a688bcSmrg i=$numtries 392d5a688bcSmrg while test $i -gt 0; do 393d5a688bcSmrg # mkdir is a portable test-and-set. 394d5a688bcSmrg if mkdir "$lockdir" 2>/dev/null; then 395d5a688bcSmrg # This process acquired the lock. 396d5a688bcSmrg "$@" -MD 397d5a688bcSmrg stat=$? 398d5a688bcSmrg # Release the lock. 399d5a688bcSmrg rmdir "$lockdir" 400d5a688bcSmrg break 401d5a688bcSmrg else 402d5a688bcSmrg # If the lock is being held by a different process, wait 403d5a688bcSmrg # until the winning process is done or we timeout. 404d5a688bcSmrg while test -d "$lockdir" && test $i -gt 0; do 405d5a688bcSmrg sleep 1 406d5a688bcSmrg i=`expr $i - 1` 407d5a688bcSmrg done 408d5a688bcSmrg fi 409d5a688bcSmrg i=`expr $i - 1` 410d5a688bcSmrg done 411d5a688bcSmrg trap - 1 2 13 15 412d5a688bcSmrg if test $i -le 0; then 413d5a688bcSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414d5a688bcSmrg echo "$0: check lockdir '$lockdir'" >&2 415d5a688bcSmrg exit 1 416d5a688bcSmrg fi 4178dd3e0eeSmrg 418d5a688bcSmrg if test $stat -ne 0; then 4198dd3e0eeSmrg rm -f "$tmpdepfile" 4208dd3e0eeSmrg exit $stat 4218dd3e0eeSmrg fi 4228dd3e0eeSmrg rm -f "$depfile" 4238dd3e0eeSmrg # Each line is of the form `foo.o: dependent.h', 4248dd3e0eeSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4258dd3e0eeSmrg # Do two passes, one to just change these to 4268dd3e0eeSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 4278dd3e0eeSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4288dd3e0eeSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 4298dd3e0eeSmrg # correctly. Breaking it into two sed invocations is a workaround. 430d5a688bcSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431d5a688bcSmrg | sed -e 's/$/ :/' >> "$depfile" 4328dd3e0eeSmrg rm -f "$tmpdepfile" 4338dd3e0eeSmrg ;; 4348dd3e0eeSmrg 4358dd3e0eeSmrghp2) 4368dd3e0eeSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4378dd3e0eeSmrg # compilers, which have integrated preprocessors. The correct option 4388dd3e0eeSmrg # to use with these is +Maked; it writes dependencies to a file named 4398dd3e0eeSmrg # 'foo.d', which lands next to the object file, wherever that 4408dd3e0eeSmrg # happens to be. 4418dd3e0eeSmrg # Much of this is similar to the tru64 case; see comments there. 442d5a688bcSmrg set_dir_from "$object" 443d5a688bcSmrg set_base_from "$object" 4448dd3e0eeSmrg if test "$libtool" = yes; then 4458dd3e0eeSmrg tmpdepfile1=$dir$base.d 4468dd3e0eeSmrg tmpdepfile2=$dir.libs/$base.d 4478dd3e0eeSmrg "$@" -Wc,+Maked 4488dd3e0eeSmrg else 4498dd3e0eeSmrg tmpdepfile1=$dir$base.d 4508dd3e0eeSmrg tmpdepfile2=$dir$base.d 4518dd3e0eeSmrg "$@" +Maked 4528dd3e0eeSmrg fi 4538dd3e0eeSmrg stat=$? 454d5a688bcSmrg if test $stat -ne 0; then 4558dd3e0eeSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4568dd3e0eeSmrg exit $stat 4578dd3e0eeSmrg fi 4588dd3e0eeSmrg 4598dd3e0eeSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4608dd3e0eeSmrg do 4618dd3e0eeSmrg test -f "$tmpdepfile" && break 4628dd3e0eeSmrg done 4638dd3e0eeSmrg if test -f "$tmpdepfile"; then 464d5a688bcSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465d5a688bcSmrg # Add 'dependent.h:' lines. 466329fdfe9Smrg sed -ne '2,${ 467d5a688bcSmrg s/^ *// 468d5a688bcSmrg s/ \\*$// 469d5a688bcSmrg s/$/:/ 470d5a688bcSmrg p 471d5a688bcSmrg }' "$tmpdepfile" >> "$depfile" 4728dd3e0eeSmrg else 473d5a688bcSmrg make_dummy_depfile 4748dd3e0eeSmrg fi 4758dd3e0eeSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 4768dd3e0eeSmrg ;; 4778dd3e0eeSmrg 4788dd3e0eeSmrgtru64) 479d5a688bcSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 480d5a688bcSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481d5a688bcSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482d5a688bcSmrg # dependencies in 'foo.d' instead, so we check for that too. 483d5a688bcSmrg # Subdirectories are respected. 484d5a688bcSmrg set_dir_from "$object" 485d5a688bcSmrg set_base_from "$object" 486d5a688bcSmrg 487d5a688bcSmrg if test "$libtool" = yes; then 488d5a688bcSmrg # Libtool generates 2 separate objects for the 2 libraries. These 489d5a688bcSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 490d5a688bcSmrg # in $dir$base.o.d. We have to check for both files, because 491d5a688bcSmrg # one of the two compilations can be disabled. We should prefer 492d5a688bcSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493d5a688bcSmrg # automatically cleaned when .libs/ is deleted, while ignoring 494d5a688bcSmrg # the former would cause a distcleancheck panic. 495d5a688bcSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496d5a688bcSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497d5a688bcSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498d5a688bcSmrg "$@" -Wc,-MD 499d5a688bcSmrg else 500d5a688bcSmrg tmpdepfile1=$dir$base.d 501d5a688bcSmrg tmpdepfile2=$dir$base.d 502d5a688bcSmrg tmpdepfile3=$dir$base.d 503d5a688bcSmrg "$@" -MD 504d5a688bcSmrg fi 505d5a688bcSmrg 506d5a688bcSmrg stat=$? 507d5a688bcSmrg if test $stat -ne 0; then 508d5a688bcSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509d5a688bcSmrg exit $stat 510d5a688bcSmrg fi 511d5a688bcSmrg 512d5a688bcSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513d5a688bcSmrg do 514d5a688bcSmrg test -f "$tmpdepfile" && break 515d5a688bcSmrg done 516d5a688bcSmrg # Same post-processing that is required for AIX mode. 517d5a688bcSmrg aix_post_process_depfile 518d5a688bcSmrg ;; 519d5a688bcSmrg 520d5a688bcSmrgmsvc7) 521d5a688bcSmrg if test "$libtool" = yes; then 522d5a688bcSmrg showIncludes=-Wc,-showIncludes 523d5a688bcSmrg else 524d5a688bcSmrg showIncludes=-showIncludes 525d5a688bcSmrg fi 526d5a688bcSmrg "$@" $showIncludes > "$tmpdepfile" 527d5a688bcSmrg stat=$? 528d5a688bcSmrg grep -v '^Note: including file: ' "$tmpdepfile" 529d5a688bcSmrg if test $stat -ne 0; then 530d5a688bcSmrg rm -f "$tmpdepfile" 531d5a688bcSmrg exit $stat 532d5a688bcSmrg fi 533d5a688bcSmrg rm -f "$depfile" 534d5a688bcSmrg echo "$object : \\" > "$depfile" 535d5a688bcSmrg # The first sed program below extracts the file names and escapes 536d5a688bcSmrg # backslashes for cygpath. The second sed program outputs the file 537d5a688bcSmrg # name when reading, but also accumulates all include files in the 538d5a688bcSmrg # hold buffer in order to output them again at the end. This only 539d5a688bcSmrg # works with sed implementations that can handle large buffers. 540d5a688bcSmrg sed < "$tmpdepfile" -n ' 541d5a688bcSmrg/^Note: including file: *\(.*\)/ { 542d5a688bcSmrg s//\1/ 543d5a688bcSmrg s/\\/\\\\/g 544d5a688bcSmrg p 545d5a688bcSmrg}' | $cygpath_u | sort -u | sed -n ' 546d5a688bcSmrgs/ /\\ /g 547d5a688bcSmrgs/\(.*\)/'"$tab"'\1 \\/p 548d5a688bcSmrgs/.\(.*\) \\/\1:/ 549d5a688bcSmrgH 550d5a688bcSmrg$ { 551d5a688bcSmrg s/.*/'"$tab"'/ 552d5a688bcSmrg G 553d5a688bcSmrg p 554d5a688bcSmrg}' >> "$depfile" 555c1d6e445Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556d5a688bcSmrg rm -f "$tmpdepfile" 557d5a688bcSmrg ;; 558d5a688bcSmrg 559d5a688bcSmrgmsvc7msys) 560d5a688bcSmrg # This case exists only to let depend.m4 do its work. It works by 561d5a688bcSmrg # looking at the text of this script. This case will never be run, 562d5a688bcSmrg # since it is checked for above. 563d5a688bcSmrg exit 1 564d5a688bcSmrg ;; 5658dd3e0eeSmrg 5668dd3e0eeSmrg#nosideeffect) 5678dd3e0eeSmrg # This comment above is used by automake to tell side-effect 5688dd3e0eeSmrg # dependency tracking mechanisms from slower ones. 5698dd3e0eeSmrg 5708dd3e0eeSmrgdashmstdout) 5718dd3e0eeSmrg # Important note: in order to support this mode, a compiler *must* 5728dd3e0eeSmrg # always write the preprocessed file to stdout, regardless of -o. 5738dd3e0eeSmrg "$@" || exit $? 5748dd3e0eeSmrg 5758dd3e0eeSmrg # Remove the call to Libtool. 5768dd3e0eeSmrg if test "$libtool" = yes; then 577329fdfe9Smrg while test "X$1" != 'X--mode=compile'; do 5788dd3e0eeSmrg shift 5798dd3e0eeSmrg done 5808dd3e0eeSmrg shift 5818dd3e0eeSmrg fi 5828dd3e0eeSmrg 583d5a688bcSmrg # Remove '-o $object'. 5848dd3e0eeSmrg IFS=" " 5858dd3e0eeSmrg for arg 5868dd3e0eeSmrg do 5878dd3e0eeSmrg case $arg in 5888dd3e0eeSmrg -o) 5898dd3e0eeSmrg shift 5908dd3e0eeSmrg ;; 5918dd3e0eeSmrg $object) 5928dd3e0eeSmrg shift 5938dd3e0eeSmrg ;; 5948dd3e0eeSmrg *) 5958dd3e0eeSmrg set fnord "$@" "$arg" 5968dd3e0eeSmrg shift # fnord 5978dd3e0eeSmrg shift # $arg 5988dd3e0eeSmrg ;; 5998dd3e0eeSmrg esac 6008dd3e0eeSmrg done 6018dd3e0eeSmrg 6028dd3e0eeSmrg test -z "$dashmflag" && dashmflag=-M 603d5a688bcSmrg # Require at least two characters before searching for ':' 6048dd3e0eeSmrg # in the target name. This is to cope with DOS-style filenames: 605d5a688bcSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6068dd3e0eeSmrg "$@" $dashmflag | 607d5a688bcSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6088dd3e0eeSmrg rm -f "$depfile" 6098dd3e0eeSmrg cat < "$tmpdepfile" > "$depfile" 610d5a688bcSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611d5a688bcSmrg # correctly. Breaking it into two sed invocations is a workaround. 612d5a688bcSmrg tr ' ' "$nl" < "$tmpdepfile" \ 613d5a688bcSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614d5a688bcSmrg | sed -e 's/$/ :/' >> "$depfile" 6158dd3e0eeSmrg rm -f "$tmpdepfile" 6168dd3e0eeSmrg ;; 6178dd3e0eeSmrg 6188dd3e0eeSmrgdashXmstdout) 6198dd3e0eeSmrg # This case only exists to satisfy depend.m4. It is never actually 6208dd3e0eeSmrg # run, as this mode is specially recognized in the preamble. 6218dd3e0eeSmrg exit 1 6228dd3e0eeSmrg ;; 6238dd3e0eeSmrg 6248dd3e0eeSmrgmakedepend) 6258dd3e0eeSmrg "$@" || exit $? 6268dd3e0eeSmrg # Remove any Libtool call 6278dd3e0eeSmrg if test "$libtool" = yes; then 628329fdfe9Smrg while test "X$1" != 'X--mode=compile'; do 6298dd3e0eeSmrg shift 6308dd3e0eeSmrg done 6318dd3e0eeSmrg shift 6328dd3e0eeSmrg fi 6338dd3e0eeSmrg # X makedepend 6348dd3e0eeSmrg shift 635329fdfe9Smrg cleared=no eat=no 636329fdfe9Smrg for arg 637329fdfe9Smrg do 6388dd3e0eeSmrg case $cleared in 6398dd3e0eeSmrg no) 6408dd3e0eeSmrg set ""; shift 6418dd3e0eeSmrg cleared=yes ;; 6428dd3e0eeSmrg esac 643329fdfe9Smrg if test $eat = yes; then 644329fdfe9Smrg eat=no 645329fdfe9Smrg continue 646329fdfe9Smrg fi 6478dd3e0eeSmrg case "$arg" in 6488dd3e0eeSmrg -D*|-I*) 6498dd3e0eeSmrg set fnord "$@" "$arg"; shift ;; 6508dd3e0eeSmrg # Strip any option that makedepend may not understand. Remove 6518dd3e0eeSmrg # the object too, otherwise makedepend will parse it as a source file. 652329fdfe9Smrg -arch) 653329fdfe9Smrg eat=yes ;; 6548dd3e0eeSmrg -*|$object) 6558dd3e0eeSmrg ;; 6568dd3e0eeSmrg *) 6578dd3e0eeSmrg set fnord "$@" "$arg"; shift ;; 6588dd3e0eeSmrg esac 6598dd3e0eeSmrg done 660329fdfe9Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6618dd3e0eeSmrg touch "$tmpdepfile" 6628dd3e0eeSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6638dd3e0eeSmrg rm -f "$depfile" 664d5a688bcSmrg # makedepend may prepend the VPATH from the source file name to the object. 665d5a688bcSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 666d5a688bcSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667d5a688bcSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668d5a688bcSmrg # correctly. Breaking it into two sed invocations is a workaround. 669d5a688bcSmrg sed '1,2d' "$tmpdepfile" \ 670d5a688bcSmrg | tr ' ' "$nl" \ 671d5a688bcSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672d5a688bcSmrg | sed -e 's/$/ :/' >> "$depfile" 6738dd3e0eeSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6748dd3e0eeSmrg ;; 6758dd3e0eeSmrg 6768dd3e0eeSmrgcpp) 6778dd3e0eeSmrg # Important note: in order to support this mode, a compiler *must* 6788dd3e0eeSmrg # always write the preprocessed file to stdout. 6798dd3e0eeSmrg "$@" || exit $? 6808dd3e0eeSmrg 6818dd3e0eeSmrg # Remove the call to Libtool. 6828dd3e0eeSmrg if test "$libtool" = yes; then 683329fdfe9Smrg while test "X$1" != 'X--mode=compile'; do 6848dd3e0eeSmrg shift 6858dd3e0eeSmrg done 6868dd3e0eeSmrg shift 6878dd3e0eeSmrg fi 6888dd3e0eeSmrg 689d5a688bcSmrg # Remove '-o $object'. 6908dd3e0eeSmrg IFS=" " 6918dd3e0eeSmrg for arg 6928dd3e0eeSmrg do 6938dd3e0eeSmrg case $arg in 6948dd3e0eeSmrg -o) 6958dd3e0eeSmrg shift 6968dd3e0eeSmrg ;; 6978dd3e0eeSmrg $object) 6988dd3e0eeSmrg shift 6998dd3e0eeSmrg ;; 7008dd3e0eeSmrg *) 7018dd3e0eeSmrg set fnord "$@" "$arg" 7028dd3e0eeSmrg shift # fnord 7038dd3e0eeSmrg shift # $arg 7048dd3e0eeSmrg ;; 7058dd3e0eeSmrg esac 7068dd3e0eeSmrg done 7078dd3e0eeSmrg 708d5a688bcSmrg "$@" -E \ 709d5a688bcSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710d5a688bcSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711d5a688bcSmrg | sed '$ s: \\$::' > "$tmpdepfile" 7128dd3e0eeSmrg rm -f "$depfile" 7138dd3e0eeSmrg echo "$object : \\" > "$depfile" 7148dd3e0eeSmrg cat < "$tmpdepfile" >> "$depfile" 7158dd3e0eeSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7168dd3e0eeSmrg rm -f "$tmpdepfile" 7178dd3e0eeSmrg ;; 7188dd3e0eeSmrg 7198dd3e0eeSmrgmsvisualcpp) 7208dd3e0eeSmrg # Important note: in order to support this mode, a compiler *must* 721329fdfe9Smrg # always write the preprocessed file to stdout. 7228dd3e0eeSmrg "$@" || exit $? 723329fdfe9Smrg 724329fdfe9Smrg # Remove the call to Libtool. 725329fdfe9Smrg if test "$libtool" = yes; then 726329fdfe9Smrg while test "X$1" != 'X--mode=compile'; do 727329fdfe9Smrg shift 728329fdfe9Smrg done 729329fdfe9Smrg shift 730329fdfe9Smrg fi 731329fdfe9Smrg 7328dd3e0eeSmrg IFS=" " 7338dd3e0eeSmrg for arg 7348dd3e0eeSmrg do 7358dd3e0eeSmrg case "$arg" in 736329fdfe9Smrg -o) 737329fdfe9Smrg shift 738329fdfe9Smrg ;; 739329fdfe9Smrg $object) 740329fdfe9Smrg shift 741329fdfe9Smrg ;; 7428dd3e0eeSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743d5a688bcSmrg set fnord "$@" 744d5a688bcSmrg shift 745d5a688bcSmrg shift 746d5a688bcSmrg ;; 7478dd3e0eeSmrg *) 748d5a688bcSmrg set fnord "$@" "$arg" 749d5a688bcSmrg shift 750d5a688bcSmrg shift 751d5a688bcSmrg ;; 7528dd3e0eeSmrg esac 7538dd3e0eeSmrg done 754329fdfe9Smrg "$@" -E 2>/dev/null | 755329fdfe9Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7568dd3e0eeSmrg rm -f "$depfile" 7578dd3e0eeSmrg echo "$object : \\" > "$depfile" 758d5a688bcSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759d5a688bcSmrg echo "$tab" >> "$depfile" 760329fdfe9Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7618dd3e0eeSmrg rm -f "$tmpdepfile" 7628dd3e0eeSmrg ;; 7638dd3e0eeSmrg 764329fdfe9Smrgmsvcmsys) 765329fdfe9Smrg # This case exists only to let depend.m4 do its work. It works by 766329fdfe9Smrg # looking at the text of this script. This case will never be run, 767329fdfe9Smrg # since it is checked for above. 768329fdfe9Smrg exit 1 769329fdfe9Smrg ;; 770329fdfe9Smrg 7718dd3e0eeSmrgnone) 7728dd3e0eeSmrg exec "$@" 7738dd3e0eeSmrg ;; 7748dd3e0eeSmrg 7758dd3e0eeSmrg*) 7768dd3e0eeSmrg echo "Unknown depmode $depmode" 1>&2 7778dd3e0eeSmrg exit 1 7788dd3e0eeSmrg ;; 7798dd3e0eeSmrgesac 7808dd3e0eeSmrg 7818dd3e0eeSmrgexit 0 7828dd3e0eeSmrg 7838dd3e0eeSmrg# Local Variables: 7848dd3e0eeSmrg# mode: shell-script 7858dd3e0eeSmrg# sh-indentation: 2 78627485fbcSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7878dd3e0eeSmrg# time-stamp-start: "scriptversion=" 7888dd3e0eeSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78927485fbcSmrg# time-stamp-time-zone: "UTC0" 790329fdfe9Smrg# time-stamp-end: "; # UTC" 7918dd3e0eeSmrg# End: 792