depcomp revision 25ad54ca
1e4da13eeSmacallan#! /bin/sh 2e4da13eeSmacallan# depcomp - compile a program generating dependencies as side-effects 3e4da13eeSmacallan 425ad54caSmrgscriptversion=2018-03-07.03; # UTC 5e4da13eeSmacallan 625ad54caSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7e4da13eeSmacallan 8e4da13eeSmacallan# This program is free software; you can redistribute it and/or modify 9e4da13eeSmacallan# it under the terms of the GNU General Public License as published by 10e4da13eeSmacallan# the Free Software Foundation; either version 2, or (at your option) 11e4da13eeSmacallan# any later version. 12e4da13eeSmacallan 13e4da13eeSmacallan# This program is distributed in the hope that it will be useful, 14e4da13eeSmacallan# but WITHOUT ANY WARRANTY; without even the implied warranty of 15e4da13eeSmacallan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16e4da13eeSmacallan# GNU General Public License for more details. 17e4da13eeSmacallan 18e4da13eeSmacallan# You should have received a copy of the GNU General Public License 1925ad54caSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20e4da13eeSmacallan 21e4da13eeSmacallan# As a special exception to the GNU General Public License, if you 22e4da13eeSmacallan# distribute this file as part of a program that contains a 23e4da13eeSmacallan# configuration script generated by Autoconf, you may include it under 24e4da13eeSmacallan# the same distribution terms that you use for the rest of that program. 25e4da13eeSmacallan 26e4da13eeSmacallan# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27e4da13eeSmacallan 28e4da13eeSmacallancase $1 in 29e4da13eeSmacallan '') 3025ad54caSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3125ad54caSmrg exit 1; 3225ad54caSmrg ;; 33e4da13eeSmacallan -h | --h*) 34e4da13eeSmacallan cat <<\EOF 35e4da13eeSmacallanUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36e4da13eeSmacallan 37e4da13eeSmacallanRun PROGRAMS ARGS to compile a file, generating dependencies 38e4da13eeSmacallanas side-effects. 39e4da13eeSmacallan 40e4da13eeSmacallanEnvironment variables: 41e4da13eeSmacallan depmode Dependency tracking mode. 4265d490d0Smrg source Source file read by 'PROGRAMS ARGS'. 4365d490d0Smrg object Object file output by 'PROGRAMS ARGS'. 44e4da13eeSmacallan DEPDIR directory where to store dependencies. 45e4da13eeSmacallan depfile Dependency file to output. 4665d490d0Smrg tmpdepfile Temporary file to use when outputting dependencies. 47e4da13eeSmacallan libtool Whether libtool is used (yes/no). 48e4da13eeSmacallan 49e4da13eeSmacallanReport bugs to <bug-automake@gnu.org>. 50e4da13eeSmacallanEOF 51e4da13eeSmacallan exit $? 52e4da13eeSmacallan ;; 53e4da13eeSmacallan -v | --v*) 54e4da13eeSmacallan echo "depcomp $scriptversion" 55e4da13eeSmacallan exit $? 56e4da13eeSmacallan ;; 57e4da13eeSmacallanesac 58e4da13eeSmacallan 5925ad54caSmrg# Get the directory component of the given path, and save it in the 6025ad54caSmrg# global variables '$dir'. Note that this directory component will 6125ad54caSmrg# be either empty or ending with a '/' character. This is deliberate. 6225ad54caSmrgset_dir_from () 6325ad54caSmrg{ 6425ad54caSmrg case $1 in 6525ad54caSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6625ad54caSmrg *) dir=;; 6725ad54caSmrg esac 6825ad54caSmrg} 6925ad54caSmrg 7025ad54caSmrg# Get the suffix-stripped basename of the given path, and save it the 7125ad54caSmrg# global variable '$base'. 7225ad54caSmrgset_base_from () 7325ad54caSmrg{ 7425ad54caSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7525ad54caSmrg} 7625ad54caSmrg 7725ad54caSmrg# If no dependency file was actually created by the compiler invocation, 7825ad54caSmrg# we still have to create a dummy depfile, to avoid errors with the 7925ad54caSmrg# Makefile "include basename.Plo" scheme. 8025ad54caSmrgmake_dummy_depfile () 8125ad54caSmrg{ 8225ad54caSmrg echo "#dummy" > "$depfile" 8325ad54caSmrg} 8425ad54caSmrg 8525ad54caSmrg# Factor out some common post-processing of the generated depfile. 8625ad54caSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8725ad54caSmrgaix_post_process_depfile () 8825ad54caSmrg{ 8925ad54caSmrg # If the compiler actually managed to produce a dependency file, 9025ad54caSmrg # post-process it. 9125ad54caSmrg if test -f "$tmpdepfile"; then 9225ad54caSmrg # Each line is of the form 'foo.o: dependency.h'. 9325ad54caSmrg # Do two passes, one to just change these to 9425ad54caSmrg # $object: dependency.h 9525ad54caSmrg # and one to simply output 9625ad54caSmrg # dependency.h: 9725ad54caSmrg # which is needed to avoid the deleted-header problem. 9825ad54caSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9925ad54caSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10025ad54caSmrg } > "$depfile" 10125ad54caSmrg rm -f "$tmpdepfile" 10225ad54caSmrg else 10325ad54caSmrg make_dummy_depfile 10425ad54caSmrg fi 10525ad54caSmrg} 10625ad54caSmrg 10765d490d0Smrg# A tabulation character. 10865d490d0Smrgtab=' ' 10965d490d0Smrg# A newline character. 11065d490d0Smrgnl=' 11165d490d0Smrg' 11225ad54caSmrg# Character ranges might be problematic outside the C locale. 11325ad54caSmrg# These definitions help. 11425ad54caSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11525ad54caSmrglower=abcdefghijklmnopqrstuvwxyz 11625ad54caSmrgdigits=0123456789 11725ad54caSmrgalpha=${upper}${lower} 11865d490d0Smrg 119e4da13eeSmacallanif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120e4da13eeSmacallan echo "depcomp: Variables source, object and depmode must be set" 1>&2 121e4da13eeSmacallan exit 1 122e4da13eeSmacallanfi 123e4da13eeSmacallan 124e4da13eeSmacallan# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125e4da13eeSmacallandepfile=${depfile-`echo "$object" | 126e4da13eeSmacallan sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127e4da13eeSmacallantmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128e4da13eeSmacallan 129e4da13eeSmacallanrm -f "$tmpdepfile" 130e4da13eeSmacallan 13165d490d0Smrg# Avoid interferences from the environment. 13265d490d0Smrggccflag= dashmflag= 13365d490d0Smrg 134e4da13eeSmacallan# Some modes work just like other modes, but use different flags. We 135e4da13eeSmacallan# parameterize here, but still list the modes in the big case below, 136e4da13eeSmacallan# to make depend.m4 easier to write. Note that we *cannot* use a case 137e4da13eeSmacallan# here, because this file can only contain one case statement. 138e4da13eeSmacallanif test "$depmode" = hp; then 139e4da13eeSmacallan # HP compiler uses -M and no extra arg. 140e4da13eeSmacallan gccflag=-M 141e4da13eeSmacallan depmode=gcc 142e4da13eeSmacallanfi 143e4da13eeSmacallan 144e4da13eeSmacallanif test "$depmode" = dashXmstdout; then 14525ad54caSmrg # This is just like dashmstdout with a different argument. 14625ad54caSmrg dashmflag=-xM 14725ad54caSmrg depmode=dashmstdout 148e4da13eeSmacallanfi 149e4da13eeSmacallan 15065d490d0Smrgcygpath_u="cygpath -u -f -" 15165d490d0Smrgif test "$depmode" = msvcmsys; then 15225ad54caSmrg # This is just like msvisualcpp but w/o cygpath translation. 15325ad54caSmrg # Just convert the backslash-escaped backslashes to single forward 15425ad54caSmrg # slashes to satisfy depend.m4 15525ad54caSmrg cygpath_u='sed s,\\\\,/,g' 15625ad54caSmrg depmode=msvisualcpp 15765d490d0Smrgfi 15865d490d0Smrg 15965d490d0Smrgif test "$depmode" = msvc7msys; then 16025ad54caSmrg # This is just like msvc7 but w/o cygpath translation. 16125ad54caSmrg # Just convert the backslash-escaped backslashes to single forward 16225ad54caSmrg # slashes to satisfy depend.m4 16325ad54caSmrg cygpath_u='sed s,\\\\,/,g' 16425ad54caSmrg depmode=msvc7 16565d490d0Smrgfi 16665d490d0Smrg 16765d490d0Smrgif test "$depmode" = xlc; then 16825ad54caSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16925ad54caSmrg gccflag=-qmakedep=gcc,-MF 17025ad54caSmrg depmode=gcc 17165d490d0Smrgfi 17265d490d0Smrg 173e4da13eeSmacallancase "$depmode" in 174e4da13eeSmacallangcc3) 175e4da13eeSmacallan## gcc 3 implements dependency tracking that does exactly what 176e4da13eeSmacallan## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177e4da13eeSmacallan## it if -MD -MP comes after the -MF stuff. Hmm. 178e4da13eeSmacallan## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179e4da13eeSmacallan## the command line argument order; so add the flags where they 180e4da13eeSmacallan## appear in depend2.am. Note that the slowdown incurred here 181e4da13eeSmacallan## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182e4da13eeSmacallan for arg 183e4da13eeSmacallan do 184e4da13eeSmacallan case $arg in 185e4da13eeSmacallan -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186e4da13eeSmacallan *) set fnord "$@" "$arg" ;; 187e4da13eeSmacallan esac 188e4da13eeSmacallan shift # fnord 189e4da13eeSmacallan shift # $arg 190e4da13eeSmacallan done 191e4da13eeSmacallan "$@" 192e4da13eeSmacallan stat=$? 19325ad54caSmrg if test $stat -ne 0; then 194e4da13eeSmacallan rm -f "$tmpdepfile" 195e4da13eeSmacallan exit $stat 196e4da13eeSmacallan fi 197e4da13eeSmacallan mv "$tmpdepfile" "$depfile" 198e4da13eeSmacallan ;; 199e4da13eeSmacallan 200e4da13eeSmacallangcc) 20165d490d0Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20265d490d0Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20365d490d0Smrg## (see the conditional assignment to $gccflag above). 204e4da13eeSmacallan## There are various ways to get dependency output from gcc. Here's 205e4da13eeSmacallan## why we pick this rather obscure method: 206e4da13eeSmacallan## - Don't want to use -MD because we'd like the dependencies to end 207e4da13eeSmacallan## up in a subdir. Having to rename by hand is ugly. 208e4da13eeSmacallan## (We might end up doing this anyway to support other compilers.) 209e4da13eeSmacallan## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21065d490d0Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21165d490d0Smrg## supported by the other compilers which use the 'gcc' depmode. 212e4da13eeSmacallan## - Using -M directly means running the compiler twice (even worse 213e4da13eeSmacallan## than renaming). 214e4da13eeSmacallan if test -z "$gccflag"; then 215e4da13eeSmacallan gccflag=-MD, 216e4da13eeSmacallan fi 217e4da13eeSmacallan "$@" -Wp,"$gccflag$tmpdepfile" 218e4da13eeSmacallan stat=$? 21925ad54caSmrg if test $stat -ne 0; then 220e4da13eeSmacallan rm -f "$tmpdepfile" 221e4da13eeSmacallan exit $stat 222e4da13eeSmacallan fi 223e4da13eeSmacallan rm -f "$depfile" 224e4da13eeSmacallan echo "$object : \\" > "$depfile" 22525ad54caSmrg # The second -e expression handles DOS-style file names with drive 22625ad54caSmrg # letters. 227e4da13eeSmacallan sed -e 's/^[^:]*: / /' \ 228e4da13eeSmacallan -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22965d490d0Smrg## This next piece of magic avoids the "deleted header file" problem. 230e4da13eeSmacallan## The problem is that when a header file which appears in a .P file 231e4da13eeSmacallan## is deleted, the dependency causes make to die (because there is 232e4da13eeSmacallan## typically no way to rebuild the header). We avoid this by adding 233e4da13eeSmacallan## dummy dependencies for each header file. Too bad gcc doesn't do 234e4da13eeSmacallan## this for us directly. 23565d490d0Smrg## Some versions of gcc put a space before the ':'. On the theory 236e4da13eeSmacallan## that the space means something, we add a space to the output as 23765d490d0Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23865d490d0Smrg## to the object. Take care to not repeat it in the output. 239e4da13eeSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation 240e4da13eeSmacallan## correctly. Breaking it into two sed invocations is a workaround. 24125ad54caSmrg tr ' ' "$nl" < "$tmpdepfile" \ 24225ad54caSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24325ad54caSmrg | sed -e 's/$/ :/' >> "$depfile" 244e4da13eeSmacallan rm -f "$tmpdepfile" 245e4da13eeSmacallan ;; 246e4da13eeSmacallan 247e4da13eeSmacallanhp) 248e4da13eeSmacallan # This case exists only to let depend.m4 do its work. It works by 249e4da13eeSmacallan # looking at the text of this script. This case will never be run, 250e4da13eeSmacallan # since it is checked for above. 251e4da13eeSmacallan exit 1 252e4da13eeSmacallan ;; 253e4da13eeSmacallan 254e4da13eeSmacallansgi) 255e4da13eeSmacallan if test "$libtool" = yes; then 256e4da13eeSmacallan "$@" "-Wp,-MDupdate,$tmpdepfile" 257e4da13eeSmacallan else 258e4da13eeSmacallan "$@" -MDupdate "$tmpdepfile" 259e4da13eeSmacallan fi 260e4da13eeSmacallan stat=$? 26125ad54caSmrg if test $stat -ne 0; then 262e4da13eeSmacallan rm -f "$tmpdepfile" 263e4da13eeSmacallan exit $stat 264e4da13eeSmacallan fi 265e4da13eeSmacallan rm -f "$depfile" 266e4da13eeSmacallan 267e4da13eeSmacallan if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268e4da13eeSmacallan echo "$object : \\" > "$depfile" 269e4da13eeSmacallan # Clip off the initial element (the dependent). Don't try to be 270e4da13eeSmacallan # clever and replace this with sed code, as IRIX sed won't handle 271e4da13eeSmacallan # lines with more than a fixed number of characters (4096 in 272e4da13eeSmacallan # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27365d490d0Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274e4da13eeSmacallan # dependency line. 27565d490d0Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27625ad54caSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27725ad54caSmrg | tr "$nl" ' ' >> "$depfile" 27865d490d0Smrg echo >> "$depfile" 279e4da13eeSmacallan # The second pass generates a dummy entry for each header file. 28065d490d0Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28125ad54caSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28225ad54caSmrg >> "$depfile" 283e4da13eeSmacallan else 28425ad54caSmrg make_dummy_depfile 285e4da13eeSmacallan fi 286e4da13eeSmacallan rm -f "$tmpdepfile" 287e4da13eeSmacallan ;; 288e4da13eeSmacallan 28965d490d0Smrgxlc) 29065d490d0Smrg # This case exists only to let depend.m4 do its work. It works by 29165d490d0Smrg # looking at the text of this script. This case will never be run, 29265d490d0Smrg # since it is checked for above. 29365d490d0Smrg exit 1 29465d490d0Smrg ;; 29565d490d0Smrg 296e4da13eeSmacallanaix) 297e4da13eeSmacallan # The C for AIX Compiler uses -M and outputs the dependencies 298e4da13eeSmacallan # in a .u file. In older versions, this file always lives in the 29965d490d0Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300e4da13eeSmacallan # start of each line; $object doesn't have directory information. 301e4da13eeSmacallan # Version 6 uses the directory in both cases. 30225ad54caSmrg set_dir_from "$object" 30325ad54caSmrg set_base_from "$object" 304e4da13eeSmacallan if test "$libtool" = yes; then 305e4da13eeSmacallan tmpdepfile1=$dir$base.u 306e4da13eeSmacallan tmpdepfile2=$base.u 307e4da13eeSmacallan tmpdepfile3=$dir.libs/$base.u 308e4da13eeSmacallan "$@" -Wc,-M 309e4da13eeSmacallan else 310e4da13eeSmacallan tmpdepfile1=$dir$base.u 311e4da13eeSmacallan tmpdepfile2=$dir$base.u 312e4da13eeSmacallan tmpdepfile3=$dir$base.u 313e4da13eeSmacallan "$@" -M 314e4da13eeSmacallan fi 315e4da13eeSmacallan stat=$? 31625ad54caSmrg if test $stat -ne 0; then 317e4da13eeSmacallan rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318e4da13eeSmacallan exit $stat 319e4da13eeSmacallan fi 320e4da13eeSmacallan 321e4da13eeSmacallan for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322e4da13eeSmacallan do 323e4da13eeSmacallan test -f "$tmpdepfile" && break 324e4da13eeSmacallan done 32525ad54caSmrg aix_post_process_depfile 326e4da13eeSmacallan ;; 327e4da13eeSmacallan 32825ad54caSmrgtcc) 32925ad54caSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33025ad54caSmrg # FIXME: That version still under development at the moment of writing. 33125ad54caSmrg # Make that this statement remains true also for stable, released 33225ad54caSmrg # versions. 33325ad54caSmrg # It will wrap lines (doesn't matter whether long or short) with a 33425ad54caSmrg # trailing '\', as in: 33525ad54caSmrg # 33625ad54caSmrg # foo.o : \ 33725ad54caSmrg # foo.c \ 33825ad54caSmrg # foo.h \ 33925ad54caSmrg # 34025ad54caSmrg # It will put a trailing '\' even on the last line, and will use leading 34125ad54caSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 34225ad54caSmrg # "Emit spaces for -MD"). 343e4da13eeSmacallan "$@" -MD -MF "$tmpdepfile" 344e4da13eeSmacallan stat=$? 34525ad54caSmrg if test $stat -ne 0; then 346e4da13eeSmacallan rm -f "$tmpdepfile" 347e4da13eeSmacallan exit $stat 348e4da13eeSmacallan fi 349e4da13eeSmacallan rm -f "$depfile" 35025ad54caSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35125ad54caSmrg # We have to change lines of the first kind to '$object: \'. 35225ad54caSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35325ad54caSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 35425ad54caSmrg # dummy dependency, to avoid the deleted-header problem. 35525ad54caSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35665d490d0Smrg rm -f "$tmpdepfile" 35765d490d0Smrg ;; 35865d490d0Smrg 35965d490d0Smrg## The order of this option in the case statement is important, since the 36065d490d0Smrg## shell code in configure will try each of these formats in the order 36165d490d0Smrg## listed in this file. A plain '-MD' option would be understood by many 36265d490d0Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36365d490d0Smrgpgcc) 36465d490d0Smrg # Portland's C compiler understands '-MD'. 36565d490d0Smrg # Will always output deps to 'file.d' where file is the root name of the 36665d490d0Smrg # source file under compilation, even if file resides in a subdirectory. 36765d490d0Smrg # The object file name does not affect the name of the '.d' file. 36865d490d0Smrg # pgcc 10.2 will output 36965d490d0Smrg # foo.o: sub/foo.c sub/foo.h 37065d490d0Smrg # and will wrap long lines using '\' : 37165d490d0Smrg # foo.o: sub/foo.c ... \ 37265d490d0Smrg # sub/foo.h ... \ 37365d490d0Smrg # ... 37425ad54caSmrg set_dir_from "$object" 37565d490d0Smrg # Use the source, not the object, to determine the base name, since 37665d490d0Smrg # that's sadly what pgcc will do too. 37725ad54caSmrg set_base_from "$source" 37825ad54caSmrg tmpdepfile=$base.d 37965d490d0Smrg 38065d490d0Smrg # For projects that build the same source file twice into different object 38165d490d0Smrg # files, the pgcc approach of using the *source* file root name can cause 38265d490d0Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38365d490d0Smrg # the same $tmpdepfile. 38425ad54caSmrg lockdir=$base.d-lock 38525ad54caSmrg trap " 38625ad54caSmrg echo '$0: caught signal, cleaning up...' >&2 38725ad54caSmrg rmdir '$lockdir' 38825ad54caSmrg exit 1 38925ad54caSmrg " 1 2 13 15 39065d490d0Smrg numtries=100 39165d490d0Smrg i=$numtries 39225ad54caSmrg while test $i -gt 0; do 39365d490d0Smrg # mkdir is a portable test-and-set. 39425ad54caSmrg if mkdir "$lockdir" 2>/dev/null; then 39565d490d0Smrg # This process acquired the lock. 39665d490d0Smrg "$@" -MD 39765d490d0Smrg stat=$? 39865d490d0Smrg # Release the lock. 39925ad54caSmrg rmdir "$lockdir" 40065d490d0Smrg break 40165d490d0Smrg else 40225ad54caSmrg # If the lock is being held by a different process, wait 40325ad54caSmrg # until the winning process is done or we timeout. 40425ad54caSmrg while test -d "$lockdir" && test $i -gt 0; do 40565d490d0Smrg sleep 1 40665d490d0Smrg i=`expr $i - 1` 40765d490d0Smrg done 40865d490d0Smrg fi 40965d490d0Smrg i=`expr $i - 1` 41065d490d0Smrg done 41165d490d0Smrg trap - 1 2 13 15 41265d490d0Smrg if test $i -le 0; then 41365d490d0Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41465d490d0Smrg echo "$0: check lockdir '$lockdir'" >&2 41565d490d0Smrg exit 1 41665d490d0Smrg fi 41765d490d0Smrg 41865d490d0Smrg if test $stat -ne 0; then 41965d490d0Smrg rm -f "$tmpdepfile" 42065d490d0Smrg exit $stat 42165d490d0Smrg fi 42265d490d0Smrg rm -f "$depfile" 423e4da13eeSmacallan # Each line is of the form `foo.o: dependent.h', 424e4da13eeSmacallan # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425e4da13eeSmacallan # Do two passes, one to just change these to 426e4da13eeSmacallan # `$object: dependent.h' and one to simply `dependent.h:'. 427e4da13eeSmacallan sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428e4da13eeSmacallan # Some versions of the HPUX 10.20 sed can't process this invocation 429e4da13eeSmacallan # correctly. Breaking it into two sed invocations is a workaround. 43025ad54caSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43125ad54caSmrg | sed -e 's/$/ :/' >> "$depfile" 432e4da13eeSmacallan rm -f "$tmpdepfile" 433e4da13eeSmacallan ;; 434e4da13eeSmacallan 435e4da13eeSmacallanhp2) 436e4da13eeSmacallan # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437e4da13eeSmacallan # compilers, which have integrated preprocessors. The correct option 438e4da13eeSmacallan # to use with these is +Maked; it writes dependencies to a file named 439e4da13eeSmacallan # 'foo.d', which lands next to the object file, wherever that 440e4da13eeSmacallan # happens to be. 441e4da13eeSmacallan # Much of this is similar to the tru64 case; see comments there. 44225ad54caSmrg set_dir_from "$object" 44325ad54caSmrg set_base_from "$object" 444e4da13eeSmacallan if test "$libtool" = yes; then 445e4da13eeSmacallan tmpdepfile1=$dir$base.d 446e4da13eeSmacallan tmpdepfile2=$dir.libs/$base.d 447e4da13eeSmacallan "$@" -Wc,+Maked 448e4da13eeSmacallan else 449e4da13eeSmacallan tmpdepfile1=$dir$base.d 450e4da13eeSmacallan tmpdepfile2=$dir$base.d 451e4da13eeSmacallan "$@" +Maked 452e4da13eeSmacallan fi 453e4da13eeSmacallan stat=$? 45425ad54caSmrg if test $stat -ne 0; then 455e4da13eeSmacallan rm -f "$tmpdepfile1" "$tmpdepfile2" 456e4da13eeSmacallan exit $stat 457e4da13eeSmacallan fi 458e4da13eeSmacallan 459e4da13eeSmacallan for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460e4da13eeSmacallan do 461e4da13eeSmacallan test -f "$tmpdepfile" && break 462e4da13eeSmacallan done 463e4da13eeSmacallan if test -f "$tmpdepfile"; then 46425ad54caSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46565d490d0Smrg # Add 'dependent.h:' lines. 46665d490d0Smrg sed -ne '2,${ 46725ad54caSmrg s/^ *// 46825ad54caSmrg s/ \\*$// 46925ad54caSmrg s/$/:/ 47025ad54caSmrg p 47125ad54caSmrg }' "$tmpdepfile" >> "$depfile" 472e4da13eeSmacallan else 47325ad54caSmrg make_dummy_depfile 474e4da13eeSmacallan fi 475e4da13eeSmacallan rm -f "$tmpdepfile" "$tmpdepfile2" 476e4da13eeSmacallan ;; 477e4da13eeSmacallan 478e4da13eeSmacallantru64) 47925ad54caSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 48025ad54caSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48125ad54caSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48225ad54caSmrg # dependencies in 'foo.d' instead, so we check for that too. 48325ad54caSmrg # Subdirectories are respected. 48425ad54caSmrg set_dir_from "$object" 48525ad54caSmrg set_base_from "$object" 48625ad54caSmrg 48725ad54caSmrg if test "$libtool" = yes; then 48825ad54caSmrg # Libtool generates 2 separate objects for the 2 libraries. These 48925ad54caSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 49025ad54caSmrg # in $dir$base.o.d. We have to check for both files, because 49125ad54caSmrg # one of the two compilations can be disabled. We should prefer 49225ad54caSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49325ad54caSmrg # automatically cleaned when .libs/ is deleted, while ignoring 49425ad54caSmrg # the former would cause a distcleancheck panic. 49525ad54caSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49625ad54caSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49725ad54caSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49825ad54caSmrg "$@" -Wc,-MD 49925ad54caSmrg else 50025ad54caSmrg tmpdepfile1=$dir$base.d 50125ad54caSmrg tmpdepfile2=$dir$base.d 50225ad54caSmrg tmpdepfile3=$dir$base.d 50325ad54caSmrg "$@" -MD 50425ad54caSmrg fi 50525ad54caSmrg 50625ad54caSmrg stat=$? 50725ad54caSmrg if test $stat -ne 0; then 50825ad54caSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50925ad54caSmrg exit $stat 51025ad54caSmrg fi 51125ad54caSmrg 51225ad54caSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51325ad54caSmrg do 51425ad54caSmrg test -f "$tmpdepfile" && break 51525ad54caSmrg done 51625ad54caSmrg # Same post-processing that is required for AIX mode. 51725ad54caSmrg aix_post_process_depfile 51825ad54caSmrg ;; 519e4da13eeSmacallan 52065d490d0Smrgmsvc7) 52165d490d0Smrg if test "$libtool" = yes; then 52265d490d0Smrg showIncludes=-Wc,-showIncludes 52365d490d0Smrg else 52465d490d0Smrg showIncludes=-showIncludes 52565d490d0Smrg fi 52665d490d0Smrg "$@" $showIncludes > "$tmpdepfile" 52765d490d0Smrg stat=$? 52865d490d0Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52925ad54caSmrg if test $stat -ne 0; then 53065d490d0Smrg rm -f "$tmpdepfile" 53165d490d0Smrg exit $stat 53265d490d0Smrg fi 53365d490d0Smrg rm -f "$depfile" 53465d490d0Smrg echo "$object : \\" > "$depfile" 53565d490d0Smrg # The first sed program below extracts the file names and escapes 53665d490d0Smrg # backslashes for cygpath. The second sed program outputs the file 53765d490d0Smrg # name when reading, but also accumulates all include files in the 53865d490d0Smrg # hold buffer in order to output them again at the end. This only 53965d490d0Smrg # works with sed implementations that can handle large buffers. 54065d490d0Smrg sed < "$tmpdepfile" -n ' 54165d490d0Smrg/^Note: including file: *\(.*\)/ { 54265d490d0Smrg s//\1/ 54365d490d0Smrg s/\\/\\\\/g 54465d490d0Smrg p 54565d490d0Smrg}' | $cygpath_u | sort -u | sed -n ' 54665d490d0Smrgs/ /\\ /g 54765d490d0Smrgs/\(.*\)/'"$tab"'\1 \\/p 54865d490d0Smrgs/.\(.*\) \\/\1:/ 54965d490d0SmrgH 55065d490d0Smrg$ { 55165d490d0Smrg s/.*/'"$tab"'/ 55265d490d0Smrg G 55365d490d0Smrg p 55465d490d0Smrg}' >> "$depfile" 55525ad54caSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55665d490d0Smrg rm -f "$tmpdepfile" 55765d490d0Smrg ;; 55865d490d0Smrg 55965d490d0Smrgmsvc7msys) 56065d490d0Smrg # This case exists only to let depend.m4 do its work. It works by 56165d490d0Smrg # looking at the text of this script. This case will never be run, 56265d490d0Smrg # since it is checked for above. 56365d490d0Smrg exit 1 56465d490d0Smrg ;; 56565d490d0Smrg 566e4da13eeSmacallan#nosideeffect) 567e4da13eeSmacallan # This comment above is used by automake to tell side-effect 568e4da13eeSmacallan # dependency tracking mechanisms from slower ones. 569e4da13eeSmacallan 570e4da13eeSmacallandashmstdout) 571e4da13eeSmacallan # Important note: in order to support this mode, a compiler *must* 572e4da13eeSmacallan # always write the preprocessed file to stdout, regardless of -o. 573e4da13eeSmacallan "$@" || exit $? 574e4da13eeSmacallan 575e4da13eeSmacallan # Remove the call to Libtool. 576e4da13eeSmacallan if test "$libtool" = yes; then 57765d490d0Smrg while test "X$1" != 'X--mode=compile'; do 578e4da13eeSmacallan shift 579e4da13eeSmacallan done 580e4da13eeSmacallan shift 581e4da13eeSmacallan fi 582e4da13eeSmacallan 58365d490d0Smrg # Remove '-o $object'. 584e4da13eeSmacallan IFS=" " 585e4da13eeSmacallan for arg 586e4da13eeSmacallan do 587e4da13eeSmacallan case $arg in 588e4da13eeSmacallan -o) 589e4da13eeSmacallan shift 590e4da13eeSmacallan ;; 591e4da13eeSmacallan $object) 592e4da13eeSmacallan shift 593e4da13eeSmacallan ;; 594e4da13eeSmacallan *) 595e4da13eeSmacallan set fnord "$@" "$arg" 596e4da13eeSmacallan shift # fnord 597e4da13eeSmacallan shift # $arg 598e4da13eeSmacallan ;; 599e4da13eeSmacallan esac 600e4da13eeSmacallan done 601e4da13eeSmacallan 602e4da13eeSmacallan test -z "$dashmflag" && dashmflag=-M 60365d490d0Smrg # Require at least two characters before searching for ':' 604e4da13eeSmacallan # in the target name. This is to cope with DOS-style filenames: 60565d490d0Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606e4da13eeSmacallan "$@" $dashmflag | 60725ad54caSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608e4da13eeSmacallan rm -f "$depfile" 609e4da13eeSmacallan cat < "$tmpdepfile" > "$depfile" 61025ad54caSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61125ad54caSmrg # correctly. Breaking it into two sed invocations is a workaround. 61225ad54caSmrg tr ' ' "$nl" < "$tmpdepfile" \ 61325ad54caSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61425ad54caSmrg | sed -e 's/$/ :/' >> "$depfile" 615e4da13eeSmacallan rm -f "$tmpdepfile" 616e4da13eeSmacallan ;; 617e4da13eeSmacallan 618e4da13eeSmacallandashXmstdout) 619e4da13eeSmacallan # This case only exists to satisfy depend.m4. It is never actually 620e4da13eeSmacallan # run, as this mode is specially recognized in the preamble. 621e4da13eeSmacallan exit 1 622e4da13eeSmacallan ;; 623e4da13eeSmacallan 624e4da13eeSmacallanmakedepend) 625e4da13eeSmacallan "$@" || exit $? 626e4da13eeSmacallan # Remove any Libtool call 627e4da13eeSmacallan if test "$libtool" = yes; then 62865d490d0Smrg while test "X$1" != 'X--mode=compile'; do 629e4da13eeSmacallan shift 630e4da13eeSmacallan done 631e4da13eeSmacallan shift 632e4da13eeSmacallan fi 633e4da13eeSmacallan # X makedepend 634e4da13eeSmacallan shift 63565d490d0Smrg cleared=no eat=no 63665d490d0Smrg for arg 63765d490d0Smrg do 638e4da13eeSmacallan case $cleared in 639e4da13eeSmacallan no) 640e4da13eeSmacallan set ""; shift 641e4da13eeSmacallan cleared=yes ;; 642e4da13eeSmacallan esac 64365d490d0Smrg if test $eat = yes; then 64465d490d0Smrg eat=no 64565d490d0Smrg continue 64665d490d0Smrg fi 647e4da13eeSmacallan case "$arg" in 648e4da13eeSmacallan -D*|-I*) 649e4da13eeSmacallan set fnord "$@" "$arg"; shift ;; 650e4da13eeSmacallan # Strip any option that makedepend may not understand. Remove 651e4da13eeSmacallan # the object too, otherwise makedepend will parse it as a source file. 65265d490d0Smrg -arch) 65365d490d0Smrg eat=yes ;; 654e4da13eeSmacallan -*|$object) 655e4da13eeSmacallan ;; 656e4da13eeSmacallan *) 657e4da13eeSmacallan set fnord "$@" "$arg"; shift ;; 658e4da13eeSmacallan esac 659e4da13eeSmacallan done 66065d490d0Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661e4da13eeSmacallan touch "$tmpdepfile" 662e4da13eeSmacallan ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663e4da13eeSmacallan rm -f "$depfile" 66465d490d0Smrg # makedepend may prepend the VPATH from the source file name to the object. 66565d490d0Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66665d490d0Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66725ad54caSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66825ad54caSmrg # correctly. Breaking it into two sed invocations is a workaround. 66925ad54caSmrg sed '1,2d' "$tmpdepfile" \ 67025ad54caSmrg | tr ' ' "$nl" \ 67125ad54caSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67225ad54caSmrg | sed -e 's/$/ :/' >> "$depfile" 673e4da13eeSmacallan rm -f "$tmpdepfile" "$tmpdepfile".bak 674e4da13eeSmacallan ;; 675e4da13eeSmacallan 676e4da13eeSmacallancpp) 677e4da13eeSmacallan # Important note: in order to support this mode, a compiler *must* 678e4da13eeSmacallan # always write the preprocessed file to stdout. 679e4da13eeSmacallan "$@" || exit $? 680e4da13eeSmacallan 681e4da13eeSmacallan # Remove the call to Libtool. 682e4da13eeSmacallan if test "$libtool" = yes; then 68365d490d0Smrg while test "X$1" != 'X--mode=compile'; do 684e4da13eeSmacallan shift 685e4da13eeSmacallan done 686e4da13eeSmacallan shift 687e4da13eeSmacallan fi 688e4da13eeSmacallan 68965d490d0Smrg # Remove '-o $object'. 690e4da13eeSmacallan IFS=" " 691e4da13eeSmacallan for arg 692e4da13eeSmacallan do 693e4da13eeSmacallan case $arg in 694e4da13eeSmacallan -o) 695e4da13eeSmacallan shift 696e4da13eeSmacallan ;; 697e4da13eeSmacallan $object) 698e4da13eeSmacallan shift 699e4da13eeSmacallan ;; 700e4da13eeSmacallan *) 701e4da13eeSmacallan set fnord "$@" "$arg" 702e4da13eeSmacallan shift # fnord 703e4da13eeSmacallan shift # $arg 704e4da13eeSmacallan ;; 705e4da13eeSmacallan esac 706e4da13eeSmacallan done 707e4da13eeSmacallan 70825ad54caSmrg "$@" -E \ 70925ad54caSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71025ad54caSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71125ad54caSmrg | sed '$ s: \\$::' > "$tmpdepfile" 712e4da13eeSmacallan rm -f "$depfile" 713e4da13eeSmacallan echo "$object : \\" > "$depfile" 714e4da13eeSmacallan cat < "$tmpdepfile" >> "$depfile" 715e4da13eeSmacallan sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716e4da13eeSmacallan rm -f "$tmpdepfile" 717e4da13eeSmacallan ;; 718e4da13eeSmacallan 719e4da13eeSmacallanmsvisualcpp) 720e4da13eeSmacallan # Important note: in order to support this mode, a compiler *must* 72165d490d0Smrg # always write the preprocessed file to stdout. 722e4da13eeSmacallan "$@" || exit $? 72365d490d0Smrg 72465d490d0Smrg # Remove the call to Libtool. 72565d490d0Smrg if test "$libtool" = yes; then 72665d490d0Smrg while test "X$1" != 'X--mode=compile'; do 72765d490d0Smrg shift 72865d490d0Smrg done 72965d490d0Smrg shift 73065d490d0Smrg fi 73165d490d0Smrg 732e4da13eeSmacallan IFS=" " 733e4da13eeSmacallan for arg 734e4da13eeSmacallan do 735e4da13eeSmacallan case "$arg" in 73665d490d0Smrg -o) 73765d490d0Smrg shift 73865d490d0Smrg ;; 73965d490d0Smrg $object) 74065d490d0Smrg shift 74165d490d0Smrg ;; 742e4da13eeSmacallan "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74325ad54caSmrg set fnord "$@" 74425ad54caSmrg shift 74525ad54caSmrg shift 74625ad54caSmrg ;; 747e4da13eeSmacallan *) 74825ad54caSmrg set fnord "$@" "$arg" 74925ad54caSmrg shift 75025ad54caSmrg shift 75125ad54caSmrg ;; 752e4da13eeSmacallan esac 753e4da13eeSmacallan done 75465d490d0Smrg "$@" -E 2>/dev/null | 75565d490d0Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756e4da13eeSmacallan rm -f "$depfile" 757e4da13eeSmacallan echo "$object : \\" > "$depfile" 75865d490d0Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75965d490d0Smrg echo "$tab" >> "$depfile" 76065d490d0Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761e4da13eeSmacallan rm -f "$tmpdepfile" 762e4da13eeSmacallan ;; 763e4da13eeSmacallan 76465d490d0Smrgmsvcmsys) 76565d490d0Smrg # This case exists only to let depend.m4 do its work. It works by 76665d490d0Smrg # looking at the text of this script. This case will never be run, 76765d490d0Smrg # since it is checked for above. 76865d490d0Smrg exit 1 76965d490d0Smrg ;; 77065d490d0Smrg 771e4da13eeSmacallannone) 772e4da13eeSmacallan exec "$@" 773e4da13eeSmacallan ;; 774e4da13eeSmacallan 775e4da13eeSmacallan*) 776e4da13eeSmacallan echo "Unknown depmode $depmode" 1>&2 777e4da13eeSmacallan exit 1 778e4da13eeSmacallan ;; 779e4da13eeSmacallanesac 780e4da13eeSmacallan 781e4da13eeSmacallanexit 0 782e4da13eeSmacallan 783e4da13eeSmacallan# Local Variables: 784e4da13eeSmacallan# mode: shell-script 785e4da13eeSmacallan# sh-indentation: 2 78625ad54caSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 787e4da13eeSmacallan# time-stamp-start: "scriptversion=" 788e4da13eeSmacallan# time-stamp-format: "%:y-%02m-%02d.%02H" 78925ad54caSmrg# time-stamp-time-zone: "UTC0" 79065d490d0Smrg# time-stamp-end: "; # UTC" 791e4da13eeSmacallan# End: 792