1bb2e14f3Smrg#! /bin/sh 2bb2e14f3Smrg# depcomp - compile a program generating dependencies as side-effects 3bb2e14f3Smrg 4e5db2183Smrgscriptversion=2018-03-07.03; # UTC 5bb2e14f3Smrg 6e5db2183Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7bb2e14f3Smrg 8bb2e14f3Smrg# This program is free software; you can redistribute it and/or modify 9bb2e14f3Smrg# it under the terms of the GNU General Public License as published by 10bb2e14f3Smrg# the Free Software Foundation; either version 2, or (at your option) 11bb2e14f3Smrg# any later version. 12bb2e14f3Smrg 13bb2e14f3Smrg# This program is distributed in the hope that it will be useful, 14bb2e14f3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15bb2e14f3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16bb2e14f3Smrg# GNU General Public License for more details. 17bb2e14f3Smrg 18bb2e14f3Smrg# You should have received a copy of the GNU General Public License 19e5db2183Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20bb2e14f3Smrg 21bb2e14f3Smrg# As a special exception to the GNU General Public License, if you 22bb2e14f3Smrg# distribute this file as part of a program that contains a 23bb2e14f3Smrg# configuration script generated by Autoconf, you may include it under 24bb2e14f3Smrg# the same distribution terms that you use for the rest of that program. 25bb2e14f3Smrg 26bb2e14f3Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27bb2e14f3Smrg 28bb2e14f3Smrgcase $1 in 29bb2e14f3Smrg '') 3039f9c979Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3139f9c979Smrg exit 1; 3239f9c979Smrg ;; 33bb2e14f3Smrg -h | --h*) 34bb2e14f3Smrg cat <<\EOF 35bb2e14f3SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36bb2e14f3Smrg 37bb2e14f3SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38bb2e14f3Smrgas side-effects. 39bb2e14f3Smrg 40bb2e14f3SmrgEnvironment variables: 41bb2e14f3Smrg depmode Dependency tracking mode. 4239f9c979Smrg source Source file read by 'PROGRAMS ARGS'. 4339f9c979Smrg object Object file output by 'PROGRAMS ARGS'. 44bb2e14f3Smrg DEPDIR directory where to store dependencies. 45bb2e14f3Smrg depfile Dependency file to output. 4639f9c979Smrg tmpdepfile Temporary file to use when outputting dependencies. 47bb2e14f3Smrg libtool Whether libtool is used (yes/no). 48bb2e14f3Smrg 49bb2e14f3SmrgReport bugs to <bug-automake@gnu.org>. 50bb2e14f3SmrgEOF 51bb2e14f3Smrg exit $? 52bb2e14f3Smrg ;; 53bb2e14f3Smrg -v | --v*) 54bb2e14f3Smrg echo "depcomp $scriptversion" 55bb2e14f3Smrg exit $? 56bb2e14f3Smrg ;; 57bb2e14f3Smrgesac 58bb2e14f3Smrg 5939f9c979Smrg# Get the directory component of the given path, and save it in the 6039f9c979Smrg# global variables '$dir'. Note that this directory component will 6139f9c979Smrg# be either empty or ending with a '/' character. This is deliberate. 6239f9c979Smrgset_dir_from () 6339f9c979Smrg{ 6439f9c979Smrg case $1 in 6539f9c979Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6639f9c979Smrg *) dir=;; 6739f9c979Smrg esac 6839f9c979Smrg} 6939f9c979Smrg 7039f9c979Smrg# Get the suffix-stripped basename of the given path, and save it the 7139f9c979Smrg# global variable '$base'. 7239f9c979Smrgset_base_from () 7339f9c979Smrg{ 7439f9c979Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7539f9c979Smrg} 7639f9c979Smrg 7739f9c979Smrg# If no dependency file was actually created by the compiler invocation, 7839f9c979Smrg# we still have to create a dummy depfile, to avoid errors with the 7939f9c979Smrg# Makefile "include basename.Plo" scheme. 8039f9c979Smrgmake_dummy_depfile () 8139f9c979Smrg{ 8239f9c979Smrg echo "#dummy" > "$depfile" 8339f9c979Smrg} 8439f9c979Smrg 8539f9c979Smrg# Factor out some common post-processing of the generated depfile. 8639f9c979Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8739f9c979Smrgaix_post_process_depfile () 8839f9c979Smrg{ 8939f9c979Smrg # If the compiler actually managed to produce a dependency file, 9039f9c979Smrg # post-process it. 9139f9c979Smrg if test -f "$tmpdepfile"; then 9239f9c979Smrg # Each line is of the form 'foo.o: dependency.h'. 9339f9c979Smrg # Do two passes, one to just change these to 9439f9c979Smrg # $object: dependency.h 9539f9c979Smrg # and one to simply output 9639f9c979Smrg # dependency.h: 9739f9c979Smrg # which is needed to avoid the deleted-header problem. 9839f9c979Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9939f9c979Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10039f9c979Smrg } > "$depfile" 10139f9c979Smrg rm -f "$tmpdepfile" 10239f9c979Smrg else 10339f9c979Smrg make_dummy_depfile 10439f9c979Smrg fi 10539f9c979Smrg} 10639f9c979Smrg 10739f9c979Smrg# A tabulation character. 10839f9c979Smrgtab=' ' 10939f9c979Smrg# A newline character. 11039f9c979Smrgnl=' 11139f9c979Smrg' 11239f9c979Smrg# Character ranges might be problematic outside the C locale. 11339f9c979Smrg# These definitions help. 11439f9c979Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11539f9c979Smrglower=abcdefghijklmnopqrstuvwxyz 11639f9c979Smrgdigits=0123456789 11739f9c979Smrgalpha=${upper}${lower} 11839f9c979Smrg 119bb2e14f3Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120bb2e14f3Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121bb2e14f3Smrg exit 1 122bb2e14f3Smrgfi 123bb2e14f3Smrg 124bb2e14f3Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125bb2e14f3Smrgdepfile=${depfile-`echo "$object" | 126bb2e14f3Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127bb2e14f3Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128bb2e14f3Smrg 129bb2e14f3Smrgrm -f "$tmpdepfile" 130bb2e14f3Smrg 13139f9c979Smrg# Avoid interferences from the environment. 13239f9c979Smrggccflag= dashmflag= 13339f9c979Smrg 134bb2e14f3Smrg# Some modes work just like other modes, but use different flags. We 135bb2e14f3Smrg# parameterize here, but still list the modes in the big case below, 136bb2e14f3Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137bb2e14f3Smrg# here, because this file can only contain one case statement. 138bb2e14f3Smrgif test "$depmode" = hp; then 139bb2e14f3Smrg # HP compiler uses -M and no extra arg. 140bb2e14f3Smrg gccflag=-M 141bb2e14f3Smrg depmode=gcc 142bb2e14f3Smrgfi 143bb2e14f3Smrg 144bb2e14f3Smrgif test "$depmode" = dashXmstdout; then 14539f9c979Smrg # This is just like dashmstdout with a different argument. 14639f9c979Smrg dashmflag=-xM 14739f9c979Smrg depmode=dashmstdout 148bb2e14f3Smrgfi 149bb2e14f3Smrg 150a5399cb1Smrgcygpath_u="cygpath -u -f -" 151a5399cb1Smrgif test "$depmode" = msvcmsys; then 15239f9c979Smrg # This is just like msvisualcpp but w/o cygpath translation. 15339f9c979Smrg # Just convert the backslash-escaped backslashes to single forward 15439f9c979Smrg # slashes to satisfy depend.m4 15539f9c979Smrg cygpath_u='sed s,\\\\,/,g' 15639f9c979Smrg depmode=msvisualcpp 15739f9c979Smrgfi 15839f9c979Smrg 15939f9c979Smrgif test "$depmode" = msvc7msys; then 16039f9c979Smrg # This is just like msvc7 but w/o cygpath translation. 16139f9c979Smrg # Just convert the backslash-escaped backslashes to single forward 16239f9c979Smrg # slashes to satisfy depend.m4 16339f9c979Smrg cygpath_u='sed s,\\\\,/,g' 16439f9c979Smrg depmode=msvc7 16539f9c979Smrgfi 16639f9c979Smrg 16739f9c979Smrgif test "$depmode" = xlc; then 16839f9c979Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16939f9c979Smrg gccflag=-qmakedep=gcc,-MF 17039f9c979Smrg depmode=gcc 171a5399cb1Smrgfi 172a5399cb1Smrg 173bb2e14f3Smrgcase "$depmode" in 174bb2e14f3Smrggcc3) 175bb2e14f3Smrg## gcc 3 implements dependency tracking that does exactly what 176bb2e14f3Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177bb2e14f3Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178a5399cb1Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179a5399cb1Smrg## the command line argument order; so add the flags where they 180a5399cb1Smrg## appear in depend2.am. Note that the slowdown incurred here 181a5399cb1Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182a5399cb1Smrg for arg 183a5399cb1Smrg do 184a5399cb1Smrg case $arg in 185a5399cb1Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186a5399cb1Smrg *) set fnord "$@" "$arg" ;; 187a5399cb1Smrg esac 188a5399cb1Smrg shift # fnord 189a5399cb1Smrg shift # $arg 190a5399cb1Smrg done 191a5399cb1Smrg "$@" 192bb2e14f3Smrg stat=$? 19339f9c979Smrg if test $stat -ne 0; then 194bb2e14f3Smrg rm -f "$tmpdepfile" 195bb2e14f3Smrg exit $stat 196bb2e14f3Smrg fi 197bb2e14f3Smrg mv "$tmpdepfile" "$depfile" 198bb2e14f3Smrg ;; 199bb2e14f3Smrg 200bb2e14f3Smrggcc) 20139f9c979Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20239f9c979Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20339f9c979Smrg## (see the conditional assignment to $gccflag above). 204bb2e14f3Smrg## There are various ways to get dependency output from gcc. Here's 205bb2e14f3Smrg## why we pick this rather obscure method: 206bb2e14f3Smrg## - Don't want to use -MD because we'd like the dependencies to end 207bb2e14f3Smrg## up in a subdir. Having to rename by hand is ugly. 208bb2e14f3Smrg## (We might end up doing this anyway to support other compilers.) 209bb2e14f3Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21039f9c979Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21139f9c979Smrg## supported by the other compilers which use the 'gcc' depmode. 212bb2e14f3Smrg## - Using -M directly means running the compiler twice (even worse 213bb2e14f3Smrg## than renaming). 214bb2e14f3Smrg if test -z "$gccflag"; then 215bb2e14f3Smrg gccflag=-MD, 216bb2e14f3Smrg fi 217bb2e14f3Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218bb2e14f3Smrg stat=$? 21939f9c979Smrg if test $stat -ne 0; then 220bb2e14f3Smrg rm -f "$tmpdepfile" 221bb2e14f3Smrg exit $stat 222bb2e14f3Smrg fi 223bb2e14f3Smrg rm -f "$depfile" 224bb2e14f3Smrg echo "$object : \\" > "$depfile" 22539f9c979Smrg # The second -e expression handles DOS-style file names with drive 22639f9c979Smrg # letters. 227bb2e14f3Smrg sed -e 's/^[^:]*: / /' \ 228bb2e14f3Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22939f9c979Smrg## This next piece of magic avoids the "deleted header file" problem. 230bb2e14f3Smrg## The problem is that when a header file which appears in a .P file 231bb2e14f3Smrg## is deleted, the dependency causes make to die (because there is 232bb2e14f3Smrg## typically no way to rebuild the header). We avoid this by adding 233bb2e14f3Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234bb2e14f3Smrg## this for us directly. 23539f9c979Smrg## Some versions of gcc put a space before the ':'. On the theory 236bb2e14f3Smrg## that the space means something, we add a space to the output as 23739f9c979Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23839f9c979Smrg## to the object. Take care to not repeat it in the output. 239bb2e14f3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240bb2e14f3Smrg## correctly. Breaking it into two sed invocations is a workaround. 24139f9c979Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24239f9c979Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24339f9c979Smrg | sed -e 's/$/ :/' >> "$depfile" 244bb2e14f3Smrg rm -f "$tmpdepfile" 245bb2e14f3Smrg ;; 246bb2e14f3Smrg 247bb2e14f3Smrghp) 248bb2e14f3Smrg # This case exists only to let depend.m4 do its work. It works by 249bb2e14f3Smrg # looking at the text of this script. This case will never be run, 250bb2e14f3Smrg # since it is checked for above. 251bb2e14f3Smrg exit 1 252bb2e14f3Smrg ;; 253bb2e14f3Smrg 254bb2e14f3Smrgsgi) 255bb2e14f3Smrg if test "$libtool" = yes; then 256bb2e14f3Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257bb2e14f3Smrg else 258bb2e14f3Smrg "$@" -MDupdate "$tmpdepfile" 259bb2e14f3Smrg fi 260bb2e14f3Smrg stat=$? 26139f9c979Smrg if test $stat -ne 0; then 262bb2e14f3Smrg rm -f "$tmpdepfile" 263bb2e14f3Smrg exit $stat 264bb2e14f3Smrg fi 265bb2e14f3Smrg rm -f "$depfile" 266bb2e14f3Smrg 267bb2e14f3Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268bb2e14f3Smrg echo "$object : \\" > "$depfile" 269bb2e14f3Smrg # Clip off the initial element (the dependent). Don't try to be 270bb2e14f3Smrg # clever and replace this with sed code, as IRIX sed won't handle 271bb2e14f3Smrg # lines with more than a fixed number of characters (4096 in 272bb2e14f3Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27339f9c979Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274bb2e14f3Smrg # dependency line. 27539f9c979Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27639f9c979Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27739f9c979Smrg | tr "$nl" ' ' >> "$depfile" 278a5399cb1Smrg echo >> "$depfile" 279bb2e14f3Smrg # The second pass generates a dummy entry for each header file. 28039f9c979Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28139f9c979Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28239f9c979Smrg >> "$depfile" 283bb2e14f3Smrg else 28439f9c979Smrg make_dummy_depfile 285bb2e14f3Smrg fi 286bb2e14f3Smrg rm -f "$tmpdepfile" 287bb2e14f3Smrg ;; 288bb2e14f3Smrg 28939f9c979Smrgxlc) 29039f9c979Smrg # This case exists only to let depend.m4 do its work. It works by 29139f9c979Smrg # looking at the text of this script. This case will never be run, 29239f9c979Smrg # since it is checked for above. 29339f9c979Smrg exit 1 29439f9c979Smrg ;; 29539f9c979Smrg 296bb2e14f3Smrgaix) 297bb2e14f3Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298bb2e14f3Smrg # in a .u file. In older versions, this file always lives in the 29939f9c979Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300bb2e14f3Smrg # start of each line; $object doesn't have directory information. 301bb2e14f3Smrg # Version 6 uses the directory in both cases. 30239f9c979Smrg set_dir_from "$object" 30339f9c979Smrg set_base_from "$object" 304bb2e14f3Smrg if test "$libtool" = yes; then 305a5399cb1Smrg tmpdepfile1=$dir$base.u 306a5399cb1Smrg tmpdepfile2=$base.u 307a5399cb1Smrg tmpdepfile3=$dir.libs/$base.u 308bb2e14f3Smrg "$@" -Wc,-M 309bb2e14f3Smrg else 310a5399cb1Smrg tmpdepfile1=$dir$base.u 311a5399cb1Smrg tmpdepfile2=$dir$base.u 312a5399cb1Smrg tmpdepfile3=$dir$base.u 313bb2e14f3Smrg "$@" -M 314bb2e14f3Smrg fi 315bb2e14f3Smrg stat=$? 31639f9c979Smrg if test $stat -ne 0; then 317a5399cb1Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318bb2e14f3Smrg exit $stat 319bb2e14f3Smrg fi 320bb2e14f3Smrg 321a5399cb1Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322a5399cb1Smrg do 323a5399cb1Smrg test -f "$tmpdepfile" && break 324a5399cb1Smrg done 32539f9c979Smrg aix_post_process_depfile 32639f9c979Smrg ;; 32739f9c979Smrg 32839f9c979Smrgtcc) 32939f9c979Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33039f9c979Smrg # FIXME: That version still under development at the moment of writing. 33139f9c979Smrg # Make that this statement remains true also for stable, released 33239f9c979Smrg # versions. 33339f9c979Smrg # It will wrap lines (doesn't matter whether long or short) with a 33439f9c979Smrg # trailing '\', as in: 33539f9c979Smrg # 33639f9c979Smrg # foo.o : \ 33739f9c979Smrg # foo.c \ 33839f9c979Smrg # foo.h \ 33939f9c979Smrg # 34039f9c979Smrg # It will put a trailing '\' even on the last line, and will use leading 34139f9c979Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34239f9c979Smrg # "Emit spaces for -MD"). 34339f9c979Smrg "$@" -MD -MF "$tmpdepfile" 34439f9c979Smrg stat=$? 34539f9c979Smrg if test $stat -ne 0; then 34639f9c979Smrg rm -f "$tmpdepfile" 34739f9c979Smrg exit $stat 348bb2e14f3Smrg fi 34939f9c979Smrg rm -f "$depfile" 35039f9c979Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35139f9c979Smrg # We have to change lines of the first kind to '$object: \'. 35239f9c979Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35339f9c979Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35439f9c979Smrg # dummy dependency, to avoid the deleted-header problem. 35539f9c979Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356bb2e14f3Smrg rm -f "$tmpdepfile" 357bb2e14f3Smrg ;; 358bb2e14f3Smrg 35939f9c979Smrg## The order of this option in the case statement is important, since the 36039f9c979Smrg## shell code in configure will try each of these formats in the order 36139f9c979Smrg## listed in this file. A plain '-MD' option would be understood by many 36239f9c979Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36339f9c979Smrgpgcc) 36439f9c979Smrg # Portland's C compiler understands '-MD'. 36539f9c979Smrg # Will always output deps to 'file.d' where file is the root name of the 36639f9c979Smrg # source file under compilation, even if file resides in a subdirectory. 36739f9c979Smrg # The object file name does not affect the name of the '.d' file. 36839f9c979Smrg # pgcc 10.2 will output 369bb2e14f3Smrg # foo.o: sub/foo.c sub/foo.h 37039f9c979Smrg # and will wrap long lines using '\' : 371bb2e14f3Smrg # foo.o: sub/foo.c ... \ 372bb2e14f3Smrg # sub/foo.h ... \ 373bb2e14f3Smrg # ... 37439f9c979Smrg set_dir_from "$object" 37539f9c979Smrg # Use the source, not the object, to determine the base name, since 37639f9c979Smrg # that's sadly what pgcc will do too. 37739f9c979Smrg set_base_from "$source" 37839f9c979Smrg tmpdepfile=$base.d 37939f9c979Smrg 38039f9c979Smrg # For projects that build the same source file twice into different object 38139f9c979Smrg # files, the pgcc approach of using the *source* file root name can cause 38239f9c979Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38339f9c979Smrg # the same $tmpdepfile. 38439f9c979Smrg lockdir=$base.d-lock 38539f9c979Smrg trap " 38639f9c979Smrg echo '$0: caught signal, cleaning up...' >&2 38739f9c979Smrg rmdir '$lockdir' 38839f9c979Smrg exit 1 38939f9c979Smrg " 1 2 13 15 39039f9c979Smrg numtries=100 39139f9c979Smrg i=$numtries 39239f9c979Smrg while test $i -gt 0; do 39339f9c979Smrg # mkdir is a portable test-and-set. 39439f9c979Smrg if mkdir "$lockdir" 2>/dev/null; then 39539f9c979Smrg # This process acquired the lock. 39639f9c979Smrg "$@" -MD 39739f9c979Smrg stat=$? 39839f9c979Smrg # Release the lock. 39939f9c979Smrg rmdir "$lockdir" 40039f9c979Smrg break 40139f9c979Smrg else 40239f9c979Smrg # If the lock is being held by a different process, wait 40339f9c979Smrg # until the winning process is done or we timeout. 40439f9c979Smrg while test -d "$lockdir" && test $i -gt 0; do 40539f9c979Smrg sleep 1 40639f9c979Smrg i=`expr $i - 1` 40739f9c979Smrg done 40839f9c979Smrg fi 40939f9c979Smrg i=`expr $i - 1` 41039f9c979Smrg done 41139f9c979Smrg trap - 1 2 13 15 41239f9c979Smrg if test $i -le 0; then 41339f9c979Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41439f9c979Smrg echo "$0: check lockdir '$lockdir'" >&2 41539f9c979Smrg exit 1 41639f9c979Smrg fi 417bb2e14f3Smrg 41839f9c979Smrg if test $stat -ne 0; then 419bb2e14f3Smrg rm -f "$tmpdepfile" 420bb2e14f3Smrg exit $stat 421bb2e14f3Smrg fi 422bb2e14f3Smrg rm -f "$depfile" 423bb2e14f3Smrg # Each line is of the form `foo.o: dependent.h', 424bb2e14f3Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425bb2e14f3Smrg # Do two passes, one to just change these to 426bb2e14f3Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427bb2e14f3Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428bb2e14f3Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429bb2e14f3Smrg # correctly. Breaking it into two sed invocations is a workaround. 43039f9c979Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43139f9c979Smrg | sed -e 's/$/ :/' >> "$depfile" 432bb2e14f3Smrg rm -f "$tmpdepfile" 433bb2e14f3Smrg ;; 434bb2e14f3Smrg 435a5399cb1Smrghp2) 436a5399cb1Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437a5399cb1Smrg # compilers, which have integrated preprocessors. The correct option 438a5399cb1Smrg # to use with these is +Maked; it writes dependencies to a file named 439a5399cb1Smrg # 'foo.d', which lands next to the object file, wherever that 440a5399cb1Smrg # happens to be. 441a5399cb1Smrg # Much of this is similar to the tru64 case; see comments there. 44239f9c979Smrg set_dir_from "$object" 44339f9c979Smrg set_base_from "$object" 444a5399cb1Smrg if test "$libtool" = yes; then 445a5399cb1Smrg tmpdepfile1=$dir$base.d 446a5399cb1Smrg tmpdepfile2=$dir.libs/$base.d 447a5399cb1Smrg "$@" -Wc,+Maked 448a5399cb1Smrg else 449a5399cb1Smrg tmpdepfile1=$dir$base.d 450a5399cb1Smrg tmpdepfile2=$dir$base.d 451a5399cb1Smrg "$@" +Maked 452a5399cb1Smrg fi 453a5399cb1Smrg stat=$? 45439f9c979Smrg if test $stat -ne 0; then 455a5399cb1Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456a5399cb1Smrg exit $stat 457a5399cb1Smrg fi 458a5399cb1Smrg 459a5399cb1Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460a5399cb1Smrg do 461a5399cb1Smrg test -f "$tmpdepfile" && break 462a5399cb1Smrg done 463a5399cb1Smrg if test -f "$tmpdepfile"; then 46439f9c979Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46539f9c979Smrg # Add 'dependent.h:' lines. 466a5399cb1Smrg sed -ne '2,${ 46739f9c979Smrg s/^ *// 46839f9c979Smrg s/ \\*$// 46939f9c979Smrg s/$/:/ 47039f9c979Smrg p 47139f9c979Smrg }' "$tmpdepfile" >> "$depfile" 472a5399cb1Smrg else 47339f9c979Smrg make_dummy_depfile 474a5399cb1Smrg fi 475a5399cb1Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 476a5399cb1Smrg ;; 477a5399cb1Smrg 478bb2e14f3Smrgtru64) 47939f9c979Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48039f9c979Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48139f9c979Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48239f9c979Smrg # dependencies in 'foo.d' instead, so we check for that too. 48339f9c979Smrg # Subdirectories are respected. 48439f9c979Smrg set_dir_from "$object" 48539f9c979Smrg set_base_from "$object" 48639f9c979Smrg 48739f9c979Smrg if test "$libtool" = yes; then 48839f9c979Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48939f9c979Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49039f9c979Smrg # in $dir$base.o.d. We have to check for both files, because 49139f9c979Smrg # one of the two compilations can be disabled. We should prefer 49239f9c979Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49339f9c979Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49439f9c979Smrg # the former would cause a distcleancheck panic. 49539f9c979Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49639f9c979Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49739f9c979Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49839f9c979Smrg "$@" -Wc,-MD 49939f9c979Smrg else 50039f9c979Smrg tmpdepfile1=$dir$base.d 50139f9c979Smrg tmpdepfile2=$dir$base.d 50239f9c979Smrg tmpdepfile3=$dir$base.d 50339f9c979Smrg "$@" -MD 50439f9c979Smrg fi 50539f9c979Smrg 50639f9c979Smrg stat=$? 50739f9c979Smrg if test $stat -ne 0; then 50839f9c979Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50939f9c979Smrg exit $stat 51039f9c979Smrg fi 51139f9c979Smrg 51239f9c979Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51339f9c979Smrg do 51439f9c979Smrg test -f "$tmpdepfile" && break 51539f9c979Smrg done 51639f9c979Smrg # Same post-processing that is required for AIX mode. 51739f9c979Smrg aix_post_process_depfile 51839f9c979Smrg ;; 51939f9c979Smrg 52039f9c979Smrgmsvc7) 52139f9c979Smrg if test "$libtool" = yes; then 52239f9c979Smrg showIncludes=-Wc,-showIncludes 52339f9c979Smrg else 52439f9c979Smrg showIncludes=-showIncludes 52539f9c979Smrg fi 52639f9c979Smrg "$@" $showIncludes > "$tmpdepfile" 52739f9c979Smrg stat=$? 52839f9c979Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52939f9c979Smrg if test $stat -ne 0; then 53039f9c979Smrg rm -f "$tmpdepfile" 53139f9c979Smrg exit $stat 53239f9c979Smrg fi 53339f9c979Smrg rm -f "$depfile" 53439f9c979Smrg echo "$object : \\" > "$depfile" 53539f9c979Smrg # The first sed program below extracts the file names and escapes 53639f9c979Smrg # backslashes for cygpath. The second sed program outputs the file 53739f9c979Smrg # name when reading, but also accumulates all include files in the 53839f9c979Smrg # hold buffer in order to output them again at the end. This only 53939f9c979Smrg # works with sed implementations that can handle large buffers. 54039f9c979Smrg sed < "$tmpdepfile" -n ' 54139f9c979Smrg/^Note: including file: *\(.*\)/ { 54239f9c979Smrg s//\1/ 54339f9c979Smrg s/\\/\\\\/g 54439f9c979Smrg p 54539f9c979Smrg}' | $cygpath_u | sort -u | sed -n ' 54639f9c979Smrgs/ /\\ /g 54739f9c979Smrgs/\(.*\)/'"$tab"'\1 \\/p 54839f9c979Smrgs/.\(.*\) \\/\1:/ 54939f9c979SmrgH 55039f9c979Smrg$ { 55139f9c979Smrg s/.*/'"$tab"'/ 55239f9c979Smrg G 55339f9c979Smrg p 55439f9c979Smrg}' >> "$depfile" 55539f9c979Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55639f9c979Smrg rm -f "$tmpdepfile" 55739f9c979Smrg ;; 55839f9c979Smrg 55939f9c979Smrgmsvc7msys) 56039f9c979Smrg # This case exists only to let depend.m4 do its work. It works by 56139f9c979Smrg # looking at the text of this script. This case will never be run, 56239f9c979Smrg # since it is checked for above. 56339f9c979Smrg exit 1 56439f9c979Smrg ;; 565bb2e14f3Smrg 566bb2e14f3Smrg#nosideeffect) 567bb2e14f3Smrg # This comment above is used by automake to tell side-effect 568bb2e14f3Smrg # dependency tracking mechanisms from slower ones. 569bb2e14f3Smrg 570bb2e14f3Smrgdashmstdout) 571bb2e14f3Smrg # Important note: in order to support this mode, a compiler *must* 572bb2e14f3Smrg # always write the preprocessed file to stdout, regardless of -o. 573bb2e14f3Smrg "$@" || exit $? 574bb2e14f3Smrg 575bb2e14f3Smrg # Remove the call to Libtool. 576bb2e14f3Smrg if test "$libtool" = yes; then 577a5399cb1Smrg while test "X$1" != 'X--mode=compile'; do 578bb2e14f3Smrg shift 579bb2e14f3Smrg done 580bb2e14f3Smrg shift 581bb2e14f3Smrg fi 582bb2e14f3Smrg 58339f9c979Smrg # Remove '-o $object'. 584bb2e14f3Smrg IFS=" " 585bb2e14f3Smrg for arg 586bb2e14f3Smrg do 587bb2e14f3Smrg case $arg in 588bb2e14f3Smrg -o) 589bb2e14f3Smrg shift 590bb2e14f3Smrg ;; 591bb2e14f3Smrg $object) 592bb2e14f3Smrg shift 593bb2e14f3Smrg ;; 594bb2e14f3Smrg *) 595bb2e14f3Smrg set fnord "$@" "$arg" 596bb2e14f3Smrg shift # fnord 597bb2e14f3Smrg shift # $arg 598bb2e14f3Smrg ;; 599bb2e14f3Smrg esac 600bb2e14f3Smrg done 601bb2e14f3Smrg 602bb2e14f3Smrg test -z "$dashmflag" && dashmflag=-M 60339f9c979Smrg # Require at least two characters before searching for ':' 604bb2e14f3Smrg # in the target name. This is to cope with DOS-style filenames: 60539f9c979Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606bb2e14f3Smrg "$@" $dashmflag | 60739f9c979Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608bb2e14f3Smrg rm -f "$depfile" 609bb2e14f3Smrg cat < "$tmpdepfile" > "$depfile" 61039f9c979Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61139f9c979Smrg # correctly. Breaking it into two sed invocations is a workaround. 61239f9c979Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61339f9c979Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61439f9c979Smrg | sed -e 's/$/ :/' >> "$depfile" 615bb2e14f3Smrg rm -f "$tmpdepfile" 616bb2e14f3Smrg ;; 617bb2e14f3Smrg 618bb2e14f3SmrgdashXmstdout) 619bb2e14f3Smrg # This case only exists to satisfy depend.m4. It is never actually 620bb2e14f3Smrg # run, as this mode is specially recognized in the preamble. 621bb2e14f3Smrg exit 1 622bb2e14f3Smrg ;; 623bb2e14f3Smrg 624bb2e14f3Smrgmakedepend) 625bb2e14f3Smrg "$@" || exit $? 626bb2e14f3Smrg # Remove any Libtool call 627bb2e14f3Smrg if test "$libtool" = yes; then 628a5399cb1Smrg while test "X$1" != 'X--mode=compile'; do 629bb2e14f3Smrg shift 630bb2e14f3Smrg done 631bb2e14f3Smrg shift 632bb2e14f3Smrg fi 633bb2e14f3Smrg # X makedepend 634bb2e14f3Smrg shift 635a5399cb1Smrg cleared=no eat=no 636a5399cb1Smrg for arg 637a5399cb1Smrg do 638bb2e14f3Smrg case $cleared in 639bb2e14f3Smrg no) 640bb2e14f3Smrg set ""; shift 641bb2e14f3Smrg cleared=yes ;; 642bb2e14f3Smrg esac 643a5399cb1Smrg if test $eat = yes; then 644a5399cb1Smrg eat=no 645a5399cb1Smrg continue 646a5399cb1Smrg fi 647bb2e14f3Smrg case "$arg" in 648bb2e14f3Smrg -D*|-I*) 649bb2e14f3Smrg set fnord "$@" "$arg"; shift ;; 650bb2e14f3Smrg # Strip any option that makedepend may not understand. Remove 651bb2e14f3Smrg # the object too, otherwise makedepend will parse it as a source file. 652a5399cb1Smrg -arch) 653a5399cb1Smrg eat=yes ;; 654bb2e14f3Smrg -*|$object) 655bb2e14f3Smrg ;; 656bb2e14f3Smrg *) 657bb2e14f3Smrg set fnord "$@" "$arg"; shift ;; 658bb2e14f3Smrg esac 659bb2e14f3Smrg done 660a5399cb1Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661bb2e14f3Smrg touch "$tmpdepfile" 662bb2e14f3Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663bb2e14f3Smrg rm -f "$depfile" 66439f9c979Smrg # makedepend may prepend the VPATH from the source file name to the object. 66539f9c979Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66639f9c979Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66739f9c979Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66839f9c979Smrg # correctly. Breaking it into two sed invocations is a workaround. 66939f9c979Smrg sed '1,2d' "$tmpdepfile" \ 67039f9c979Smrg | tr ' ' "$nl" \ 67139f9c979Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67239f9c979Smrg | sed -e 's/$/ :/' >> "$depfile" 673bb2e14f3Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674bb2e14f3Smrg ;; 675bb2e14f3Smrg 676bb2e14f3Smrgcpp) 677bb2e14f3Smrg # Important note: in order to support this mode, a compiler *must* 678bb2e14f3Smrg # always write the preprocessed file to stdout. 679bb2e14f3Smrg "$@" || exit $? 680bb2e14f3Smrg 681bb2e14f3Smrg # Remove the call to Libtool. 682bb2e14f3Smrg if test "$libtool" = yes; then 683a5399cb1Smrg while test "X$1" != 'X--mode=compile'; do 684bb2e14f3Smrg shift 685bb2e14f3Smrg done 686bb2e14f3Smrg shift 687bb2e14f3Smrg fi 688bb2e14f3Smrg 68939f9c979Smrg # Remove '-o $object'. 690bb2e14f3Smrg IFS=" " 691bb2e14f3Smrg for arg 692bb2e14f3Smrg do 693bb2e14f3Smrg case $arg in 694bb2e14f3Smrg -o) 695bb2e14f3Smrg shift 696bb2e14f3Smrg ;; 697bb2e14f3Smrg $object) 698bb2e14f3Smrg shift 699bb2e14f3Smrg ;; 700bb2e14f3Smrg *) 701bb2e14f3Smrg set fnord "$@" "$arg" 702bb2e14f3Smrg shift # fnord 703bb2e14f3Smrg shift # $arg 704bb2e14f3Smrg ;; 705bb2e14f3Smrg esac 706bb2e14f3Smrg done 707bb2e14f3Smrg 70839f9c979Smrg "$@" -E \ 70939f9c979Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71039f9c979Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71139f9c979Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712bb2e14f3Smrg rm -f "$depfile" 713bb2e14f3Smrg echo "$object : \\" > "$depfile" 714bb2e14f3Smrg cat < "$tmpdepfile" >> "$depfile" 715bb2e14f3Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716bb2e14f3Smrg rm -f "$tmpdepfile" 717bb2e14f3Smrg ;; 718bb2e14f3Smrg 719bb2e14f3Smrgmsvisualcpp) 720bb2e14f3Smrg # Important note: in order to support this mode, a compiler *must* 721a5399cb1Smrg # always write the preprocessed file to stdout. 722bb2e14f3Smrg "$@" || exit $? 723a5399cb1Smrg 724a5399cb1Smrg # Remove the call to Libtool. 725a5399cb1Smrg if test "$libtool" = yes; then 726a5399cb1Smrg while test "X$1" != 'X--mode=compile'; do 727a5399cb1Smrg shift 728a5399cb1Smrg done 729a5399cb1Smrg shift 730a5399cb1Smrg fi 731a5399cb1Smrg 732bb2e14f3Smrg IFS=" " 733bb2e14f3Smrg for arg 734bb2e14f3Smrg do 735bb2e14f3Smrg case "$arg" in 736a5399cb1Smrg -o) 737a5399cb1Smrg shift 738a5399cb1Smrg ;; 739a5399cb1Smrg $object) 740a5399cb1Smrg shift 741a5399cb1Smrg ;; 742bb2e14f3Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74339f9c979Smrg set fnord "$@" 74439f9c979Smrg shift 74539f9c979Smrg shift 74639f9c979Smrg ;; 747bb2e14f3Smrg *) 74839f9c979Smrg set fnord "$@" "$arg" 74939f9c979Smrg shift 75039f9c979Smrg shift 75139f9c979Smrg ;; 752bb2e14f3Smrg esac 753bb2e14f3Smrg done 754a5399cb1Smrg "$@" -E 2>/dev/null | 755a5399cb1Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756bb2e14f3Smrg rm -f "$depfile" 757bb2e14f3Smrg echo "$object : \\" > "$depfile" 75839f9c979Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75939f9c979Smrg echo "$tab" >> "$depfile" 760a5399cb1Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761bb2e14f3Smrg rm -f "$tmpdepfile" 762bb2e14f3Smrg ;; 763bb2e14f3Smrg 764a5399cb1Smrgmsvcmsys) 765a5399cb1Smrg # This case exists only to let depend.m4 do its work. It works by 766a5399cb1Smrg # looking at the text of this script. This case will never be run, 767a5399cb1Smrg # since it is checked for above. 768a5399cb1Smrg exit 1 769a5399cb1Smrg ;; 770a5399cb1Smrg 771bb2e14f3Smrgnone) 772bb2e14f3Smrg exec "$@" 773bb2e14f3Smrg ;; 774bb2e14f3Smrg 775bb2e14f3Smrg*) 776bb2e14f3Smrg echo "Unknown depmode $depmode" 1>&2 777bb2e14f3Smrg exit 1 778bb2e14f3Smrg ;; 779bb2e14f3Smrgesac 780bb2e14f3Smrg 781bb2e14f3Smrgexit 0 782bb2e14f3Smrg 783bb2e14f3Smrg# Local Variables: 784bb2e14f3Smrg# mode: shell-script 785bb2e14f3Smrg# sh-indentation: 2 786e5db2183Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 787bb2e14f3Smrg# time-stamp-start: "scriptversion=" 788bb2e14f3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789e5db2183Smrg# time-stamp-time-zone: "UTC0" 790a5399cb1Smrg# time-stamp-end: "; # UTC" 791bb2e14f3Smrg# End: 792