19bd41f2cSmrg#! /bin/sh 29bd41f2cSmrg# depcomp - compile a program generating dependencies as side-effects 39bd41f2cSmrg 4084f91ccSmrgscriptversion=2018-03-07.03; # UTC 59bd41f2cSmrg 6084f91ccSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 79bd41f2cSmrg 89bd41f2cSmrg# This program is free software; you can redistribute it and/or modify 99bd41f2cSmrg# it under the terms of the GNU General Public License as published by 109bd41f2cSmrg# the Free Software Foundation; either version 2, or (at your option) 119bd41f2cSmrg# any later version. 129bd41f2cSmrg 139bd41f2cSmrg# This program is distributed in the hope that it will be useful, 149bd41f2cSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 159bd41f2cSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 169bd41f2cSmrg# GNU General Public License for more details. 179bd41f2cSmrg 189bd41f2cSmrg# You should have received a copy of the GNU General Public License 19084f91ccSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 209bd41f2cSmrg 219bd41f2cSmrg# As a special exception to the GNU General Public License, if you 229bd41f2cSmrg# distribute this file as part of a program that contains a 239bd41f2cSmrg# configuration script generated by Autoconf, you may include it under 249bd41f2cSmrg# the same distribution terms that you use for the rest of that program. 259bd41f2cSmrg 269bd41f2cSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 279bd41f2cSmrg 289bd41f2cSmrgcase $1 in 299bd41f2cSmrg '') 30084f91ccSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31084f91ccSmrg exit 1; 32084f91ccSmrg ;; 339bd41f2cSmrg -h | --h*) 349bd41f2cSmrg cat <<\EOF 359bd41f2cSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 369bd41f2cSmrg 379bd41f2cSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 389bd41f2cSmrgas side-effects. 399bd41f2cSmrg 409bd41f2cSmrgEnvironment variables: 419bd41f2cSmrg depmode Dependency tracking mode. 420da4cdccSmrg source Source file read by 'PROGRAMS ARGS'. 430da4cdccSmrg object Object file output by 'PROGRAMS ARGS'. 449bd41f2cSmrg DEPDIR directory where to store dependencies. 459bd41f2cSmrg depfile Dependency file to output. 460da4cdccSmrg tmpdepfile Temporary file to use when outputting dependencies. 479bd41f2cSmrg libtool Whether libtool is used (yes/no). 489bd41f2cSmrg 499bd41f2cSmrgReport bugs to <bug-automake@gnu.org>. 509bd41f2cSmrgEOF 519bd41f2cSmrg exit $? 529bd41f2cSmrg ;; 539bd41f2cSmrg -v | --v*) 549bd41f2cSmrg echo "depcomp $scriptversion" 559bd41f2cSmrg exit $? 569bd41f2cSmrg ;; 579bd41f2cSmrgesac 589bd41f2cSmrg 59084f91ccSmrg# Get the directory component of the given path, and save it in the 60084f91ccSmrg# global variables '$dir'. Note that this directory component will 61084f91ccSmrg# be either empty or ending with a '/' character. This is deliberate. 62084f91ccSmrgset_dir_from () 63084f91ccSmrg{ 64084f91ccSmrg case $1 in 65084f91ccSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66084f91ccSmrg *) dir=;; 67084f91ccSmrg esac 68084f91ccSmrg} 69084f91ccSmrg 70084f91ccSmrg# Get the suffix-stripped basename of the given path, and save it the 71084f91ccSmrg# global variable '$base'. 72084f91ccSmrgset_base_from () 73084f91ccSmrg{ 74084f91ccSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75084f91ccSmrg} 76084f91ccSmrg 77084f91ccSmrg# If no dependency file was actually created by the compiler invocation, 78084f91ccSmrg# we still have to create a dummy depfile, to avoid errors with the 79084f91ccSmrg# Makefile "include basename.Plo" scheme. 80084f91ccSmrgmake_dummy_depfile () 81084f91ccSmrg{ 82084f91ccSmrg echo "#dummy" > "$depfile" 83084f91ccSmrg} 84084f91ccSmrg 85084f91ccSmrg# Factor out some common post-processing of the generated depfile. 86084f91ccSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87084f91ccSmrgaix_post_process_depfile () 88084f91ccSmrg{ 89084f91ccSmrg # If the compiler actually managed to produce a dependency file, 90084f91ccSmrg # post-process it. 91084f91ccSmrg if test -f "$tmpdepfile"; then 92084f91ccSmrg # Each line is of the form 'foo.o: dependency.h'. 93084f91ccSmrg # Do two passes, one to just change these to 94084f91ccSmrg # $object: dependency.h 95084f91ccSmrg # and one to simply output 96084f91ccSmrg # dependency.h: 97084f91ccSmrg # which is needed to avoid the deleted-header problem. 98084f91ccSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99084f91ccSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100084f91ccSmrg } > "$depfile" 101084f91ccSmrg rm -f "$tmpdepfile" 102084f91ccSmrg else 103084f91ccSmrg make_dummy_depfile 104084f91ccSmrg fi 105084f91ccSmrg} 106084f91ccSmrg 1070da4cdccSmrg# A tabulation character. 1080da4cdccSmrgtab=' ' 1090da4cdccSmrg# A newline character. 1100da4cdccSmrgnl=' 1110da4cdccSmrg' 112084f91ccSmrg# Character ranges might be problematic outside the C locale. 113084f91ccSmrg# These definitions help. 114084f91ccSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115084f91ccSmrglower=abcdefghijklmnopqrstuvwxyz 116084f91ccSmrgdigits=0123456789 117084f91ccSmrgalpha=${upper}${lower} 1180da4cdccSmrg 1199bd41f2cSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1209bd41f2cSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1219bd41f2cSmrg exit 1 1229bd41f2cSmrgfi 1239bd41f2cSmrg 1249bd41f2cSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1259bd41f2cSmrgdepfile=${depfile-`echo "$object" | 1269bd41f2cSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1279bd41f2cSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1289bd41f2cSmrg 1299bd41f2cSmrgrm -f "$tmpdepfile" 1309bd41f2cSmrg 131084f91ccSmrg# Avoid interferences from the environment. 132084f91ccSmrggccflag= dashmflag= 133084f91ccSmrg 1349bd41f2cSmrg# Some modes work just like other modes, but use different flags. We 1359bd41f2cSmrg# parameterize here, but still list the modes in the big case below, 1369bd41f2cSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1379bd41f2cSmrg# here, because this file can only contain one case statement. 1389bd41f2cSmrgif test "$depmode" = hp; then 1399bd41f2cSmrg # HP compiler uses -M and no extra arg. 1409bd41f2cSmrg gccflag=-M 1419bd41f2cSmrg depmode=gcc 1429bd41f2cSmrgfi 1439bd41f2cSmrg 1449bd41f2cSmrgif test "$depmode" = dashXmstdout; then 145084f91ccSmrg # This is just like dashmstdout with a different argument. 146084f91ccSmrg dashmflag=-xM 147084f91ccSmrg depmode=dashmstdout 1489bd41f2cSmrgfi 1499bd41f2cSmrg 1500da4cdccSmrgcygpath_u="cygpath -u -f -" 1510da4cdccSmrgif test "$depmode" = msvcmsys; then 152084f91ccSmrg # This is just like msvisualcpp but w/o cygpath translation. 153084f91ccSmrg # Just convert the backslash-escaped backslashes to single forward 154084f91ccSmrg # slashes to satisfy depend.m4 155084f91ccSmrg cygpath_u='sed s,\\\\,/,g' 156084f91ccSmrg depmode=msvisualcpp 1570da4cdccSmrgfi 1580da4cdccSmrg 1590da4cdccSmrgif test "$depmode" = msvc7msys; then 160084f91ccSmrg # This is just like msvc7 but w/o cygpath translation. 161084f91ccSmrg # Just convert the backslash-escaped backslashes to single forward 162084f91ccSmrg # slashes to satisfy depend.m4 163084f91ccSmrg cygpath_u='sed s,\\\\,/,g' 164084f91ccSmrg depmode=msvc7 1650da4cdccSmrgfi 1660da4cdccSmrg 1670da4cdccSmrgif test "$depmode" = xlc; then 168084f91ccSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169084f91ccSmrg gccflag=-qmakedep=gcc,-MF 170084f91ccSmrg depmode=gcc 1710da4cdccSmrgfi 1720da4cdccSmrg 1739bd41f2cSmrgcase "$depmode" in 1749bd41f2cSmrggcc3) 1759bd41f2cSmrg## gcc 3 implements dependency tracking that does exactly what 1769bd41f2cSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1779bd41f2cSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 1789418810dSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1799418810dSmrg## the command line argument order; so add the flags where they 1809418810dSmrg## appear in depend2.am. Note that the slowdown incurred here 1819418810dSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1829418810dSmrg for arg 1839418810dSmrg do 1849418810dSmrg case $arg in 1859418810dSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1869418810dSmrg *) set fnord "$@" "$arg" ;; 1879418810dSmrg esac 1889418810dSmrg shift # fnord 1899418810dSmrg shift # $arg 1909418810dSmrg done 1919418810dSmrg "$@" 1929bd41f2cSmrg stat=$? 193084f91ccSmrg if test $stat -ne 0; then 1949bd41f2cSmrg rm -f "$tmpdepfile" 1959bd41f2cSmrg exit $stat 1969bd41f2cSmrg fi 1979bd41f2cSmrg mv "$tmpdepfile" "$depfile" 1989bd41f2cSmrg ;; 1999bd41f2cSmrg 2009bd41f2cSmrggcc) 201084f91ccSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202084f91ccSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203084f91ccSmrg## (see the conditional assignment to $gccflag above). 2049bd41f2cSmrg## There are various ways to get dependency output from gcc. Here's 2059bd41f2cSmrg## why we pick this rather obscure method: 2069bd41f2cSmrg## - Don't want to use -MD because we'd like the dependencies to end 2079bd41f2cSmrg## up in a subdir. Having to rename by hand is ugly. 2089bd41f2cSmrg## (We might end up doing this anyway to support other compilers.) 2099bd41f2cSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210084f91ccSmrg## -MM, not -M (despite what the docs say). Also, it might not be 211084f91ccSmrg## supported by the other compilers which use the 'gcc' depmode. 2129bd41f2cSmrg## - Using -M directly means running the compiler twice (even worse 2139bd41f2cSmrg## than renaming). 2149bd41f2cSmrg if test -z "$gccflag"; then 2159bd41f2cSmrg gccflag=-MD, 2169bd41f2cSmrg fi 2179bd41f2cSmrg "$@" -Wp,"$gccflag$tmpdepfile" 2189bd41f2cSmrg stat=$? 219084f91ccSmrg if test $stat -ne 0; then 2209bd41f2cSmrg rm -f "$tmpdepfile" 2219bd41f2cSmrg exit $stat 2229bd41f2cSmrg fi 2239bd41f2cSmrg rm -f "$depfile" 2249bd41f2cSmrg echo "$object : \\" > "$depfile" 225084f91ccSmrg # The second -e expression handles DOS-style file names with drive 226084f91ccSmrg # letters. 2279bd41f2cSmrg sed -e 's/^[^:]*: / /' \ 2289bd41f2cSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2290da4cdccSmrg## This next piece of magic avoids the "deleted header file" problem. 2309bd41f2cSmrg## The problem is that when a header file which appears in a .P file 2319bd41f2cSmrg## is deleted, the dependency causes make to die (because there is 2329bd41f2cSmrg## typically no way to rebuild the header). We avoid this by adding 2339bd41f2cSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 2349bd41f2cSmrg## this for us directly. 2350da4cdccSmrg## Some versions of gcc put a space before the ':'. On the theory 2369bd41f2cSmrg## that the space means something, we add a space to the output as 2370da4cdccSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 2380da4cdccSmrg## to the object. Take care to not repeat it in the output. 2399bd41f2cSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 2409bd41f2cSmrg## correctly. Breaking it into two sed invocations is a workaround. 241084f91ccSmrg tr ' ' "$nl" < "$tmpdepfile" \ 242084f91ccSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243084f91ccSmrg | sed -e 's/$/ :/' >> "$depfile" 2449bd41f2cSmrg rm -f "$tmpdepfile" 2459bd41f2cSmrg ;; 2469bd41f2cSmrg 2479bd41f2cSmrghp) 2489bd41f2cSmrg # This case exists only to let depend.m4 do its work. It works by 2499bd41f2cSmrg # looking at the text of this script. This case will never be run, 2509bd41f2cSmrg # since it is checked for above. 2519bd41f2cSmrg exit 1 2529bd41f2cSmrg ;; 2539bd41f2cSmrg 2549bd41f2cSmrgsgi) 2559bd41f2cSmrg if test "$libtool" = yes; then 2569bd41f2cSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2579bd41f2cSmrg else 2589bd41f2cSmrg "$@" -MDupdate "$tmpdepfile" 2599bd41f2cSmrg fi 2609bd41f2cSmrg stat=$? 261084f91ccSmrg if test $stat -ne 0; then 2629bd41f2cSmrg rm -f "$tmpdepfile" 2639bd41f2cSmrg exit $stat 2649bd41f2cSmrg fi 2659bd41f2cSmrg rm -f "$depfile" 2669bd41f2cSmrg 2679bd41f2cSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2689bd41f2cSmrg echo "$object : \\" > "$depfile" 2699bd41f2cSmrg # Clip off the initial element (the dependent). Don't try to be 2709bd41f2cSmrg # clever and replace this with sed code, as IRIX sed won't handle 2719bd41f2cSmrg # lines with more than a fixed number of characters (4096 in 2729bd41f2cSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2730da4cdccSmrg # the IRIX cc adds comments like '#:fec' to the end of the 2749bd41f2cSmrg # dependency line. 2750da4cdccSmrg tr ' ' "$nl" < "$tmpdepfile" \ 276084f91ccSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277084f91ccSmrg | tr "$nl" ' ' >> "$depfile" 2780da4cdccSmrg echo >> "$depfile" 2799bd41f2cSmrg # The second pass generates a dummy entry for each header file. 2800da4cdccSmrg tr ' ' "$nl" < "$tmpdepfile" \ 281084f91ccSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282084f91ccSmrg >> "$depfile" 2839bd41f2cSmrg else 284084f91ccSmrg make_dummy_depfile 2859bd41f2cSmrg fi 2869bd41f2cSmrg rm -f "$tmpdepfile" 2879bd41f2cSmrg ;; 2889bd41f2cSmrg 2890da4cdccSmrgxlc) 2900da4cdccSmrg # This case exists only to let depend.m4 do its work. It works by 2910da4cdccSmrg # looking at the text of this script. This case will never be run, 2920da4cdccSmrg # since it is checked for above. 2930da4cdccSmrg exit 1 2940da4cdccSmrg ;; 2950da4cdccSmrg 2969bd41f2cSmrgaix) 2979bd41f2cSmrg # The C for AIX Compiler uses -M and outputs the dependencies 2989bd41f2cSmrg # in a .u file. In older versions, this file always lives in the 2990da4cdccSmrg # current directory. Also, the AIX compiler puts '$object:' at the 3009bd41f2cSmrg # start of each line; $object doesn't have directory information. 3019bd41f2cSmrg # Version 6 uses the directory in both cases. 302084f91ccSmrg set_dir_from "$object" 303084f91ccSmrg set_base_from "$object" 3049bd41f2cSmrg if test "$libtool" = yes; then 3059418810dSmrg tmpdepfile1=$dir$base.u 3069418810dSmrg tmpdepfile2=$base.u 3079418810dSmrg tmpdepfile3=$dir.libs/$base.u 3089bd41f2cSmrg "$@" -Wc,-M 3099bd41f2cSmrg else 3109418810dSmrg tmpdepfile1=$dir$base.u 3119418810dSmrg tmpdepfile2=$dir$base.u 3129418810dSmrg tmpdepfile3=$dir$base.u 3139bd41f2cSmrg "$@" -M 3149bd41f2cSmrg fi 3159bd41f2cSmrg stat=$? 316084f91ccSmrg if test $stat -ne 0; then 3179418810dSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3189bd41f2cSmrg exit $stat 3199bd41f2cSmrg fi 3209bd41f2cSmrg 3219418810dSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3229418810dSmrg do 3239418810dSmrg test -f "$tmpdepfile" && break 3249418810dSmrg done 325084f91ccSmrg aix_post_process_depfile 326084f91ccSmrg ;; 327084f91ccSmrg 328084f91ccSmrgtcc) 329084f91ccSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330084f91ccSmrg # FIXME: That version still under development at the moment of writing. 331084f91ccSmrg # Make that this statement remains true also for stable, released 332084f91ccSmrg # versions. 333084f91ccSmrg # It will wrap lines (doesn't matter whether long or short) with a 334084f91ccSmrg # trailing '\', as in: 335084f91ccSmrg # 336084f91ccSmrg # foo.o : \ 337084f91ccSmrg # foo.c \ 338084f91ccSmrg # foo.h \ 339084f91ccSmrg # 340084f91ccSmrg # It will put a trailing '\' even on the last line, and will use leading 341084f91ccSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 342084f91ccSmrg # "Emit spaces for -MD"). 343084f91ccSmrg "$@" -MD -MF "$tmpdepfile" 344084f91ccSmrg stat=$? 345084f91ccSmrg if test $stat -ne 0; then 346084f91ccSmrg rm -f "$tmpdepfile" 347084f91ccSmrg exit $stat 3489bd41f2cSmrg fi 349084f91ccSmrg rm -f "$depfile" 350084f91ccSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351084f91ccSmrg # We have to change lines of the first kind to '$object: \'. 352084f91ccSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353084f91ccSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 354084f91ccSmrg # dummy dependency, to avoid the deleted-header problem. 355084f91ccSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3569bd41f2cSmrg rm -f "$tmpdepfile" 3579bd41f2cSmrg ;; 3589bd41f2cSmrg 359084f91ccSmrg## The order of this option in the case statement is important, since the 360084f91ccSmrg## shell code in configure will try each of these formats in the order 361084f91ccSmrg## listed in this file. A plain '-MD' option would be understood by many 362084f91ccSmrg## compilers, so we must ensure this comes after the gcc and icc options. 363084f91ccSmrgpgcc) 364084f91ccSmrg # Portland's C compiler understands '-MD'. 365084f91ccSmrg # Will always output deps to 'file.d' where file is the root name of the 366084f91ccSmrg # source file under compilation, even if file resides in a subdirectory. 367084f91ccSmrg # The object file name does not affect the name of the '.d' file. 368084f91ccSmrg # pgcc 10.2 will output 3699bd41f2cSmrg # foo.o: sub/foo.c sub/foo.h 370084f91ccSmrg # and will wrap long lines using '\' : 3719bd41f2cSmrg # foo.o: sub/foo.c ... \ 3729bd41f2cSmrg # sub/foo.h ... \ 3739bd41f2cSmrg # ... 374084f91ccSmrg set_dir_from "$object" 375084f91ccSmrg # Use the source, not the object, to determine the base name, since 376084f91ccSmrg # that's sadly what pgcc will do too. 377084f91ccSmrg set_base_from "$source" 378084f91ccSmrg tmpdepfile=$base.d 379084f91ccSmrg 380084f91ccSmrg # For projects that build the same source file twice into different object 381084f91ccSmrg # files, the pgcc approach of using the *source* file root name can cause 382084f91ccSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383084f91ccSmrg # the same $tmpdepfile. 384084f91ccSmrg lockdir=$base.d-lock 385084f91ccSmrg trap " 386084f91ccSmrg echo '$0: caught signal, cleaning up...' >&2 387084f91ccSmrg rmdir '$lockdir' 388084f91ccSmrg exit 1 389084f91ccSmrg " 1 2 13 15 390084f91ccSmrg numtries=100 391084f91ccSmrg i=$numtries 392084f91ccSmrg while test $i -gt 0; do 393084f91ccSmrg # mkdir is a portable test-and-set. 394084f91ccSmrg if mkdir "$lockdir" 2>/dev/null; then 395084f91ccSmrg # This process acquired the lock. 396084f91ccSmrg "$@" -MD 397084f91ccSmrg stat=$? 398084f91ccSmrg # Release the lock. 399084f91ccSmrg rmdir "$lockdir" 400084f91ccSmrg break 401084f91ccSmrg else 402084f91ccSmrg # If the lock is being held by a different process, wait 403084f91ccSmrg # until the winning process is done or we timeout. 404084f91ccSmrg while test -d "$lockdir" && test $i -gt 0; do 405084f91ccSmrg sleep 1 406084f91ccSmrg i=`expr $i - 1` 407084f91ccSmrg done 408084f91ccSmrg fi 409084f91ccSmrg i=`expr $i - 1` 410084f91ccSmrg done 411084f91ccSmrg trap - 1 2 13 15 412084f91ccSmrg if test $i -le 0; then 413084f91ccSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414084f91ccSmrg echo "$0: check lockdir '$lockdir'" >&2 415084f91ccSmrg exit 1 416084f91ccSmrg fi 417084f91ccSmrg 418084f91ccSmrg if test $stat -ne 0; then 4199bd41f2cSmrg rm -f "$tmpdepfile" 4209bd41f2cSmrg exit $stat 4219bd41f2cSmrg fi 4229bd41f2cSmrg rm -f "$depfile" 423084f91ccSmrg # Each line is of the form `foo.o: dependent.h', 424084f91ccSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4259bd41f2cSmrg # Do two passes, one to just change these to 426084f91ccSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427084f91ccSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428084f91ccSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429084f91ccSmrg # correctly. Breaking it into two sed invocations is a workaround. 430084f91ccSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431084f91ccSmrg | sed -e 's/$/ :/' >> "$depfile" 4329bd41f2cSmrg rm -f "$tmpdepfile" 4339bd41f2cSmrg ;; 4349bd41f2cSmrg 4359418810dSmrghp2) 4369418810dSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4379418810dSmrg # compilers, which have integrated preprocessors. The correct option 4389418810dSmrg # to use with these is +Maked; it writes dependencies to a file named 4399418810dSmrg # 'foo.d', which lands next to the object file, wherever that 4409418810dSmrg # happens to be. 4419418810dSmrg # Much of this is similar to the tru64 case; see comments there. 442084f91ccSmrg set_dir_from "$object" 443084f91ccSmrg set_base_from "$object" 4449418810dSmrg if test "$libtool" = yes; then 4459418810dSmrg tmpdepfile1=$dir$base.d 4469418810dSmrg tmpdepfile2=$dir.libs/$base.d 4479418810dSmrg "$@" -Wc,+Maked 4489418810dSmrg else 4499418810dSmrg tmpdepfile1=$dir$base.d 4509418810dSmrg tmpdepfile2=$dir$base.d 4519418810dSmrg "$@" +Maked 4529418810dSmrg fi 4539418810dSmrg stat=$? 454084f91ccSmrg if test $stat -ne 0; then 4559418810dSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4569418810dSmrg exit $stat 4579418810dSmrg fi 4589418810dSmrg 4599418810dSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4609418810dSmrg do 4619418810dSmrg test -f "$tmpdepfile" && break 4629418810dSmrg done 4639418810dSmrg if test -f "$tmpdepfile"; then 464084f91ccSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4650da4cdccSmrg # Add 'dependent.h:' lines. 4660da4cdccSmrg sed -ne '2,${ 467084f91ccSmrg s/^ *// 468084f91ccSmrg s/ \\*$// 469084f91ccSmrg s/$/:/ 470084f91ccSmrg p 471084f91ccSmrg }' "$tmpdepfile" >> "$depfile" 4729418810dSmrg else 473084f91ccSmrg make_dummy_depfile 4749418810dSmrg fi 4759418810dSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 4769418810dSmrg ;; 4779418810dSmrg 4789bd41f2cSmrgtru64) 479084f91ccSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 480084f91ccSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481084f91ccSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482084f91ccSmrg # dependencies in 'foo.d' instead, so we check for that too. 483084f91ccSmrg # Subdirectories are respected. 484084f91ccSmrg set_dir_from "$object" 485084f91ccSmrg set_base_from "$object" 486084f91ccSmrg 487084f91ccSmrg if test "$libtool" = yes; then 488084f91ccSmrg # Libtool generates 2 separate objects for the 2 libraries. These 489084f91ccSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 490084f91ccSmrg # in $dir$base.o.d. We have to check for both files, because 491084f91ccSmrg # one of the two compilations can be disabled. We should prefer 492084f91ccSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493084f91ccSmrg # automatically cleaned when .libs/ is deleted, while ignoring 494084f91ccSmrg # the former would cause a distcleancheck panic. 495084f91ccSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496084f91ccSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497084f91ccSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498084f91ccSmrg "$@" -Wc,-MD 499084f91ccSmrg else 500084f91ccSmrg tmpdepfile1=$dir$base.d 501084f91ccSmrg tmpdepfile2=$dir$base.d 502084f91ccSmrg tmpdepfile3=$dir$base.d 503084f91ccSmrg "$@" -MD 504084f91ccSmrg fi 505084f91ccSmrg 506084f91ccSmrg stat=$? 507084f91ccSmrg if test $stat -ne 0; then 508084f91ccSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509084f91ccSmrg exit $stat 510084f91ccSmrg fi 511084f91ccSmrg 512084f91ccSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513084f91ccSmrg do 514084f91ccSmrg test -f "$tmpdepfile" && break 515084f91ccSmrg done 516084f91ccSmrg # Same post-processing that is required for AIX mode. 517084f91ccSmrg aix_post_process_depfile 518084f91ccSmrg ;; 5199bd41f2cSmrg 5200da4cdccSmrgmsvc7) 5210da4cdccSmrg if test "$libtool" = yes; then 5220da4cdccSmrg showIncludes=-Wc,-showIncludes 5230da4cdccSmrg else 5240da4cdccSmrg showIncludes=-showIncludes 5250da4cdccSmrg fi 5260da4cdccSmrg "$@" $showIncludes > "$tmpdepfile" 5270da4cdccSmrg stat=$? 5280da4cdccSmrg grep -v '^Note: including file: ' "$tmpdepfile" 529084f91ccSmrg if test $stat -ne 0; then 5300da4cdccSmrg rm -f "$tmpdepfile" 5310da4cdccSmrg exit $stat 5320da4cdccSmrg fi 5330da4cdccSmrg rm -f "$depfile" 5340da4cdccSmrg echo "$object : \\" > "$depfile" 5350da4cdccSmrg # The first sed program below extracts the file names and escapes 5360da4cdccSmrg # backslashes for cygpath. The second sed program outputs the file 5370da4cdccSmrg # name when reading, but also accumulates all include files in the 5380da4cdccSmrg # hold buffer in order to output them again at the end. This only 5390da4cdccSmrg # works with sed implementations that can handle large buffers. 5400da4cdccSmrg sed < "$tmpdepfile" -n ' 5410da4cdccSmrg/^Note: including file: *\(.*\)/ { 5420da4cdccSmrg s//\1/ 5430da4cdccSmrg s/\\/\\\\/g 5440da4cdccSmrg p 5450da4cdccSmrg}' | $cygpath_u | sort -u | sed -n ' 5460da4cdccSmrgs/ /\\ /g 5470da4cdccSmrgs/\(.*\)/'"$tab"'\1 \\/p 5480da4cdccSmrgs/.\(.*\) \\/\1:/ 5490da4cdccSmrgH 5500da4cdccSmrg$ { 5510da4cdccSmrg s/.*/'"$tab"'/ 5520da4cdccSmrg G 5530da4cdccSmrg p 5540da4cdccSmrg}' >> "$depfile" 555084f91ccSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5560da4cdccSmrg rm -f "$tmpdepfile" 5570da4cdccSmrg ;; 5580da4cdccSmrg 5590da4cdccSmrgmsvc7msys) 5600da4cdccSmrg # This case exists only to let depend.m4 do its work. It works by 5610da4cdccSmrg # looking at the text of this script. This case will never be run, 5620da4cdccSmrg # since it is checked for above. 5630da4cdccSmrg exit 1 5640da4cdccSmrg ;; 5650da4cdccSmrg 5669bd41f2cSmrg#nosideeffect) 5679bd41f2cSmrg # This comment above is used by automake to tell side-effect 5689bd41f2cSmrg # dependency tracking mechanisms from slower ones. 5699bd41f2cSmrg 5709bd41f2cSmrgdashmstdout) 5719bd41f2cSmrg # Important note: in order to support this mode, a compiler *must* 5729bd41f2cSmrg # always write the preprocessed file to stdout, regardless of -o. 5739bd41f2cSmrg "$@" || exit $? 5749bd41f2cSmrg 5759bd41f2cSmrg # Remove the call to Libtool. 5769bd41f2cSmrg if test "$libtool" = yes; then 5770da4cdccSmrg while test "X$1" != 'X--mode=compile'; do 5789bd41f2cSmrg shift 5799bd41f2cSmrg done 5809bd41f2cSmrg shift 5819bd41f2cSmrg fi 5829bd41f2cSmrg 5830da4cdccSmrg # Remove '-o $object'. 5849bd41f2cSmrg IFS=" " 5859bd41f2cSmrg for arg 5869bd41f2cSmrg do 5879bd41f2cSmrg case $arg in 5889bd41f2cSmrg -o) 5899bd41f2cSmrg shift 5909bd41f2cSmrg ;; 5919bd41f2cSmrg $object) 5929bd41f2cSmrg shift 5939bd41f2cSmrg ;; 5949bd41f2cSmrg *) 5959bd41f2cSmrg set fnord "$@" "$arg" 5969bd41f2cSmrg shift # fnord 5979bd41f2cSmrg shift # $arg 5989bd41f2cSmrg ;; 5999bd41f2cSmrg esac 6009bd41f2cSmrg done 6019bd41f2cSmrg 6029bd41f2cSmrg test -z "$dashmflag" && dashmflag=-M 6030da4cdccSmrg # Require at least two characters before searching for ':' 6049bd41f2cSmrg # in the target name. This is to cope with DOS-style filenames: 6050da4cdccSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6069bd41f2cSmrg "$@" $dashmflag | 607084f91ccSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6089bd41f2cSmrg rm -f "$depfile" 6099bd41f2cSmrg cat < "$tmpdepfile" > "$depfile" 610084f91ccSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611084f91ccSmrg # correctly. Breaking it into two sed invocations is a workaround. 612084f91ccSmrg tr ' ' "$nl" < "$tmpdepfile" \ 613084f91ccSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614084f91ccSmrg | sed -e 's/$/ :/' >> "$depfile" 6159bd41f2cSmrg rm -f "$tmpdepfile" 6169bd41f2cSmrg ;; 6179bd41f2cSmrg 6189bd41f2cSmrgdashXmstdout) 6199bd41f2cSmrg # This case only exists to satisfy depend.m4. It is never actually 6209bd41f2cSmrg # run, as this mode is specially recognized in the preamble. 6219bd41f2cSmrg exit 1 6229bd41f2cSmrg ;; 6239bd41f2cSmrg 6249bd41f2cSmrgmakedepend) 6259bd41f2cSmrg "$@" || exit $? 6269bd41f2cSmrg # Remove any Libtool call 6279bd41f2cSmrg if test "$libtool" = yes; then 6280da4cdccSmrg while test "X$1" != 'X--mode=compile'; do 6299bd41f2cSmrg shift 6309bd41f2cSmrg done 6319bd41f2cSmrg shift 6329bd41f2cSmrg fi 6339bd41f2cSmrg # X makedepend 6349bd41f2cSmrg shift 6350da4cdccSmrg cleared=no eat=no 6360da4cdccSmrg for arg 6370da4cdccSmrg do 6389bd41f2cSmrg case $cleared in 6399bd41f2cSmrg no) 6409bd41f2cSmrg set ""; shift 6419bd41f2cSmrg cleared=yes ;; 6429bd41f2cSmrg esac 6430da4cdccSmrg if test $eat = yes; then 6440da4cdccSmrg eat=no 6450da4cdccSmrg continue 6460da4cdccSmrg fi 6479bd41f2cSmrg case "$arg" in 6489bd41f2cSmrg -D*|-I*) 6499bd41f2cSmrg set fnord "$@" "$arg"; shift ;; 6509bd41f2cSmrg # Strip any option that makedepend may not understand. Remove 6519bd41f2cSmrg # the object too, otherwise makedepend will parse it as a source file. 6520da4cdccSmrg -arch) 6530da4cdccSmrg eat=yes ;; 6549bd41f2cSmrg -*|$object) 6559bd41f2cSmrg ;; 6569bd41f2cSmrg *) 6579bd41f2cSmrg set fnord "$@" "$arg"; shift ;; 6589bd41f2cSmrg esac 6599bd41f2cSmrg done 6600da4cdccSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6619bd41f2cSmrg touch "$tmpdepfile" 6629bd41f2cSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6639bd41f2cSmrg rm -f "$depfile" 6640da4cdccSmrg # makedepend may prepend the VPATH from the source file name to the object. 6650da4cdccSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 6660da4cdccSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667084f91ccSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668084f91ccSmrg # correctly. Breaking it into two sed invocations is a workaround. 669084f91ccSmrg sed '1,2d' "$tmpdepfile" \ 670084f91ccSmrg | tr ' ' "$nl" \ 671084f91ccSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672084f91ccSmrg | sed -e 's/$/ :/' >> "$depfile" 6739bd41f2cSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6749bd41f2cSmrg ;; 6759bd41f2cSmrg 6769bd41f2cSmrgcpp) 6779bd41f2cSmrg # Important note: in order to support this mode, a compiler *must* 6789bd41f2cSmrg # always write the preprocessed file to stdout. 6799bd41f2cSmrg "$@" || exit $? 6809bd41f2cSmrg 6819bd41f2cSmrg # Remove the call to Libtool. 6829bd41f2cSmrg if test "$libtool" = yes; then 6830da4cdccSmrg while test "X$1" != 'X--mode=compile'; do 6849bd41f2cSmrg shift 6859bd41f2cSmrg done 6869bd41f2cSmrg shift 6879bd41f2cSmrg fi 6889bd41f2cSmrg 6890da4cdccSmrg # Remove '-o $object'. 6909bd41f2cSmrg IFS=" " 6919bd41f2cSmrg for arg 6929bd41f2cSmrg do 6939bd41f2cSmrg case $arg in 6949bd41f2cSmrg -o) 6959bd41f2cSmrg shift 6969bd41f2cSmrg ;; 6979bd41f2cSmrg $object) 6989bd41f2cSmrg shift 6999bd41f2cSmrg ;; 7009bd41f2cSmrg *) 7019bd41f2cSmrg set fnord "$@" "$arg" 7029bd41f2cSmrg shift # fnord 7039bd41f2cSmrg shift # $arg 7049bd41f2cSmrg ;; 7059bd41f2cSmrg esac 7069bd41f2cSmrg done 7079bd41f2cSmrg 708084f91ccSmrg "$@" -E \ 709084f91ccSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710084f91ccSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711084f91ccSmrg | sed '$ s: \\$::' > "$tmpdepfile" 7129bd41f2cSmrg rm -f "$depfile" 7139bd41f2cSmrg echo "$object : \\" > "$depfile" 7149bd41f2cSmrg cat < "$tmpdepfile" >> "$depfile" 7159bd41f2cSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7169bd41f2cSmrg rm -f "$tmpdepfile" 7179bd41f2cSmrg ;; 7189bd41f2cSmrg 7199bd41f2cSmrgmsvisualcpp) 7209bd41f2cSmrg # Important note: in order to support this mode, a compiler *must* 7210da4cdccSmrg # always write the preprocessed file to stdout. 7229bd41f2cSmrg "$@" || exit $? 7230da4cdccSmrg 7240da4cdccSmrg # Remove the call to Libtool. 7250da4cdccSmrg if test "$libtool" = yes; then 7260da4cdccSmrg while test "X$1" != 'X--mode=compile'; do 7270da4cdccSmrg shift 7280da4cdccSmrg done 7290da4cdccSmrg shift 7300da4cdccSmrg fi 7310da4cdccSmrg 7329bd41f2cSmrg IFS=" " 7339bd41f2cSmrg for arg 7349bd41f2cSmrg do 7359bd41f2cSmrg case "$arg" in 7360da4cdccSmrg -o) 7370da4cdccSmrg shift 7380da4cdccSmrg ;; 7390da4cdccSmrg $object) 7400da4cdccSmrg shift 7410da4cdccSmrg ;; 7429bd41f2cSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743084f91ccSmrg set fnord "$@" 744084f91ccSmrg shift 745084f91ccSmrg shift 746084f91ccSmrg ;; 7479bd41f2cSmrg *) 748084f91ccSmrg set fnord "$@" "$arg" 749084f91ccSmrg shift 750084f91ccSmrg shift 751084f91ccSmrg ;; 7529bd41f2cSmrg esac 7539bd41f2cSmrg done 7540da4cdccSmrg "$@" -E 2>/dev/null | 7550da4cdccSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7569bd41f2cSmrg rm -f "$depfile" 7579bd41f2cSmrg echo "$object : \\" > "$depfile" 7580da4cdccSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7590da4cdccSmrg echo "$tab" >> "$depfile" 7600da4cdccSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7619bd41f2cSmrg rm -f "$tmpdepfile" 7629bd41f2cSmrg ;; 7639bd41f2cSmrg 7640da4cdccSmrgmsvcmsys) 7650da4cdccSmrg # This case exists only to let depend.m4 do its work. It works by 7660da4cdccSmrg # looking at the text of this script. This case will never be run, 7670da4cdccSmrg # since it is checked for above. 7680da4cdccSmrg exit 1 7690da4cdccSmrg ;; 7700da4cdccSmrg 7719bd41f2cSmrgnone) 7729bd41f2cSmrg exec "$@" 7739bd41f2cSmrg ;; 7749bd41f2cSmrg 7759bd41f2cSmrg*) 7769bd41f2cSmrg echo "Unknown depmode $depmode" 1>&2 7779bd41f2cSmrg exit 1 7789bd41f2cSmrg ;; 7799bd41f2cSmrgesac 7809bd41f2cSmrg 7819bd41f2cSmrgexit 0 7829bd41f2cSmrg 7839bd41f2cSmrg# Local Variables: 7849bd41f2cSmrg# mode: shell-script 7859bd41f2cSmrg# sh-indentation: 2 786084f91ccSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7879bd41f2cSmrg# time-stamp-start: "scriptversion=" 7889bd41f2cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789084f91ccSmrg# time-stamp-time-zone: "UTC0" 7900da4cdccSmrg# time-stamp-end: "; # UTC" 7919bd41f2cSmrg# End: 792