188cd5fc2Smrg#! /bin/sh 288cd5fc2Smrg# depcomp - compile a program generating dependencies as side-effects 388cd5fc2Smrg 4a33c354dSmrgscriptversion=2018-03-07.03; # UTC 588cd5fc2Smrg 6a33c354dSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 788cd5fc2Smrg 888cd5fc2Smrg# This program is free software; you can redistribute it and/or modify 988cd5fc2Smrg# it under the terms of the GNU General Public License as published by 1088cd5fc2Smrg# the Free Software Foundation; either version 2, or (at your option) 1188cd5fc2Smrg# any later version. 1288cd5fc2Smrg 1388cd5fc2Smrg# This program is distributed in the hope that it will be useful, 1488cd5fc2Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1588cd5fc2Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1688cd5fc2Smrg# GNU General Public License for more details. 1788cd5fc2Smrg 1888cd5fc2Smrg# You should have received a copy of the GNU General Public License 19a33c354dSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2088cd5fc2Smrg 2188cd5fc2Smrg# As a special exception to the GNU General Public License, if you 2288cd5fc2Smrg# distribute this file as part of a program that contains a 2388cd5fc2Smrg# configuration script generated by Autoconf, you may include it under 2488cd5fc2Smrg# the same distribution terms that you use for the rest of that program. 2588cd5fc2Smrg 2688cd5fc2Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2788cd5fc2Smrg 2888cd5fc2Smrgcase $1 in 2988cd5fc2Smrg '') 3088cd5fc2Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3188cd5fc2Smrg exit 1; 3288cd5fc2Smrg ;; 3388cd5fc2Smrg -h | --h*) 3488cd5fc2Smrg cat <<\EOF 3588cd5fc2SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3688cd5fc2Smrg 3788cd5fc2SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3888cd5fc2Smrgas side-effects. 3988cd5fc2Smrg 4088cd5fc2SmrgEnvironment variables: 4188cd5fc2Smrg depmode Dependency tracking mode. 4288cd5fc2Smrg source Source file read by 'PROGRAMS ARGS'. 4388cd5fc2Smrg object Object file output by 'PROGRAMS ARGS'. 4488cd5fc2Smrg DEPDIR directory where to store dependencies. 4588cd5fc2Smrg depfile Dependency file to output. 4688cd5fc2Smrg tmpdepfile Temporary file to use when outputting dependencies. 4788cd5fc2Smrg libtool Whether libtool is used (yes/no). 4888cd5fc2Smrg 4988cd5fc2SmrgReport bugs to <bug-automake@gnu.org>. 5088cd5fc2SmrgEOF 5188cd5fc2Smrg exit $? 5288cd5fc2Smrg ;; 5388cd5fc2Smrg -v | --v*) 5488cd5fc2Smrg echo "depcomp $scriptversion" 5588cd5fc2Smrg exit $? 5688cd5fc2Smrg ;; 5788cd5fc2Smrgesac 5888cd5fc2Smrg 5988cd5fc2Smrg# Get the directory component of the given path, and save it in the 6088cd5fc2Smrg# global variables '$dir'. Note that this directory component will 6188cd5fc2Smrg# be either empty or ending with a '/' character. This is deliberate. 6288cd5fc2Smrgset_dir_from () 6388cd5fc2Smrg{ 6488cd5fc2Smrg case $1 in 6588cd5fc2Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6688cd5fc2Smrg *) dir=;; 6788cd5fc2Smrg esac 6888cd5fc2Smrg} 6988cd5fc2Smrg 7088cd5fc2Smrg# Get the suffix-stripped basename of the given path, and save it the 7188cd5fc2Smrg# global variable '$base'. 7288cd5fc2Smrgset_base_from () 7388cd5fc2Smrg{ 7488cd5fc2Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7588cd5fc2Smrg} 7688cd5fc2Smrg 7788cd5fc2Smrg# If no dependency file was actually created by the compiler invocation, 7888cd5fc2Smrg# we still have to create a dummy depfile, to avoid errors with the 7988cd5fc2Smrg# Makefile "include basename.Plo" scheme. 8088cd5fc2Smrgmake_dummy_depfile () 8188cd5fc2Smrg{ 8288cd5fc2Smrg echo "#dummy" > "$depfile" 8388cd5fc2Smrg} 8488cd5fc2Smrg 8588cd5fc2Smrg# Factor out some common post-processing of the generated depfile. 8688cd5fc2Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8788cd5fc2Smrgaix_post_process_depfile () 8888cd5fc2Smrg{ 8988cd5fc2Smrg # If the compiler actually managed to produce a dependency file, 9088cd5fc2Smrg # post-process it. 9188cd5fc2Smrg if test -f "$tmpdepfile"; then 9288cd5fc2Smrg # Each line is of the form 'foo.o: dependency.h'. 9388cd5fc2Smrg # Do two passes, one to just change these to 9488cd5fc2Smrg # $object: dependency.h 9588cd5fc2Smrg # and one to simply output 9688cd5fc2Smrg # dependency.h: 9788cd5fc2Smrg # which is needed to avoid the deleted-header problem. 9888cd5fc2Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9988cd5fc2Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10088cd5fc2Smrg } > "$depfile" 10188cd5fc2Smrg rm -f "$tmpdepfile" 10288cd5fc2Smrg else 10388cd5fc2Smrg make_dummy_depfile 10488cd5fc2Smrg fi 10588cd5fc2Smrg} 10688cd5fc2Smrg 10788cd5fc2Smrg# A tabulation character. 10888cd5fc2Smrgtab=' ' 10988cd5fc2Smrg# A newline character. 11088cd5fc2Smrgnl=' 11188cd5fc2Smrg' 11288cd5fc2Smrg# Character ranges might be problematic outside the C locale. 11388cd5fc2Smrg# These definitions help. 11488cd5fc2Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11588cd5fc2Smrglower=abcdefghijklmnopqrstuvwxyz 11688cd5fc2Smrgdigits=0123456789 11788cd5fc2Smrgalpha=${upper}${lower} 11888cd5fc2Smrg 11988cd5fc2Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12088cd5fc2Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12188cd5fc2Smrg exit 1 12288cd5fc2Smrgfi 12388cd5fc2Smrg 12488cd5fc2Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12588cd5fc2Smrgdepfile=${depfile-`echo "$object" | 12688cd5fc2Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12788cd5fc2Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12888cd5fc2Smrg 12988cd5fc2Smrgrm -f "$tmpdepfile" 13088cd5fc2Smrg 13188cd5fc2Smrg# Avoid interferences from the environment. 13288cd5fc2Smrggccflag= dashmflag= 13388cd5fc2Smrg 13488cd5fc2Smrg# Some modes work just like other modes, but use different flags. We 13588cd5fc2Smrg# parameterize here, but still list the modes in the big case below, 13688cd5fc2Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13788cd5fc2Smrg# here, because this file can only contain one case statement. 13888cd5fc2Smrgif test "$depmode" = hp; then 13988cd5fc2Smrg # HP compiler uses -M and no extra arg. 14088cd5fc2Smrg gccflag=-M 14188cd5fc2Smrg depmode=gcc 14288cd5fc2Smrgfi 14388cd5fc2Smrg 14488cd5fc2Smrgif test "$depmode" = dashXmstdout; then 14588cd5fc2Smrg # This is just like dashmstdout with a different argument. 14688cd5fc2Smrg dashmflag=-xM 14788cd5fc2Smrg depmode=dashmstdout 14888cd5fc2Smrgfi 14988cd5fc2Smrg 15088cd5fc2Smrgcygpath_u="cygpath -u -f -" 15188cd5fc2Smrgif test "$depmode" = msvcmsys; then 15288cd5fc2Smrg # This is just like msvisualcpp but w/o cygpath translation. 15388cd5fc2Smrg # Just convert the backslash-escaped backslashes to single forward 15488cd5fc2Smrg # slashes to satisfy depend.m4 15588cd5fc2Smrg cygpath_u='sed s,\\\\,/,g' 15688cd5fc2Smrg depmode=msvisualcpp 15788cd5fc2Smrgfi 15888cd5fc2Smrg 15988cd5fc2Smrgif test "$depmode" = msvc7msys; then 16088cd5fc2Smrg # This is just like msvc7 but w/o cygpath translation. 16188cd5fc2Smrg # Just convert the backslash-escaped backslashes to single forward 16288cd5fc2Smrg # slashes to satisfy depend.m4 16388cd5fc2Smrg cygpath_u='sed s,\\\\,/,g' 16488cd5fc2Smrg depmode=msvc7 16588cd5fc2Smrgfi 16688cd5fc2Smrg 16788cd5fc2Smrgif test "$depmode" = xlc; then 16888cd5fc2Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16988cd5fc2Smrg gccflag=-qmakedep=gcc,-MF 17088cd5fc2Smrg depmode=gcc 17188cd5fc2Smrgfi 17288cd5fc2Smrg 17388cd5fc2Smrgcase "$depmode" in 17488cd5fc2Smrggcc3) 17588cd5fc2Smrg## gcc 3 implements dependency tracking that does exactly what 17688cd5fc2Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17788cd5fc2Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 17888cd5fc2Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 17988cd5fc2Smrg## the command line argument order; so add the flags where they 18088cd5fc2Smrg## appear in depend2.am. Note that the slowdown incurred here 18188cd5fc2Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 18288cd5fc2Smrg for arg 18388cd5fc2Smrg do 18488cd5fc2Smrg case $arg in 18588cd5fc2Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 18688cd5fc2Smrg *) set fnord "$@" "$arg" ;; 18788cd5fc2Smrg esac 18888cd5fc2Smrg shift # fnord 18988cd5fc2Smrg shift # $arg 19088cd5fc2Smrg done 19188cd5fc2Smrg "$@" 19288cd5fc2Smrg stat=$? 19388cd5fc2Smrg if test $stat -ne 0; then 19488cd5fc2Smrg rm -f "$tmpdepfile" 19588cd5fc2Smrg exit $stat 19688cd5fc2Smrg fi 19788cd5fc2Smrg mv "$tmpdepfile" "$depfile" 19888cd5fc2Smrg ;; 19988cd5fc2Smrg 20088cd5fc2Smrggcc) 20188cd5fc2Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20288cd5fc2Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20388cd5fc2Smrg## (see the conditional assignment to $gccflag above). 20488cd5fc2Smrg## There are various ways to get dependency output from gcc. Here's 20588cd5fc2Smrg## why we pick this rather obscure method: 20688cd5fc2Smrg## - Don't want to use -MD because we'd like the dependencies to end 20788cd5fc2Smrg## up in a subdir. Having to rename by hand is ugly. 20888cd5fc2Smrg## (We might end up doing this anyway to support other compilers.) 20988cd5fc2Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21088cd5fc2Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21188cd5fc2Smrg## supported by the other compilers which use the 'gcc' depmode. 21288cd5fc2Smrg## - Using -M directly means running the compiler twice (even worse 21388cd5fc2Smrg## than renaming). 21488cd5fc2Smrg if test -z "$gccflag"; then 21588cd5fc2Smrg gccflag=-MD, 21688cd5fc2Smrg fi 21788cd5fc2Smrg "$@" -Wp,"$gccflag$tmpdepfile" 21888cd5fc2Smrg stat=$? 21988cd5fc2Smrg if test $stat -ne 0; then 22088cd5fc2Smrg rm -f "$tmpdepfile" 22188cd5fc2Smrg exit $stat 22288cd5fc2Smrg fi 22388cd5fc2Smrg rm -f "$depfile" 22488cd5fc2Smrg echo "$object : \\" > "$depfile" 22588cd5fc2Smrg # The second -e expression handles DOS-style file names with drive 22688cd5fc2Smrg # letters. 22788cd5fc2Smrg sed -e 's/^[^:]*: / /' \ 22888cd5fc2Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22988cd5fc2Smrg## This next piece of magic avoids the "deleted header file" problem. 23088cd5fc2Smrg## The problem is that when a header file which appears in a .P file 23188cd5fc2Smrg## is deleted, the dependency causes make to die (because there is 23288cd5fc2Smrg## typically no way to rebuild the header). We avoid this by adding 23388cd5fc2Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 23488cd5fc2Smrg## this for us directly. 23588cd5fc2Smrg## Some versions of gcc put a space before the ':'. On the theory 23688cd5fc2Smrg## that the space means something, we add a space to the output as 23788cd5fc2Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23888cd5fc2Smrg## to the object. Take care to not repeat it in the output. 23988cd5fc2Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 24088cd5fc2Smrg## correctly. Breaking it into two sed invocations is a workaround. 24188cd5fc2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24288cd5fc2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24388cd5fc2Smrg | sed -e 's/$/ :/' >> "$depfile" 24488cd5fc2Smrg rm -f "$tmpdepfile" 24588cd5fc2Smrg ;; 24688cd5fc2Smrg 24788cd5fc2Smrghp) 24888cd5fc2Smrg # This case exists only to let depend.m4 do its work. It works by 24988cd5fc2Smrg # looking at the text of this script. This case will never be run, 25088cd5fc2Smrg # since it is checked for above. 25188cd5fc2Smrg exit 1 25288cd5fc2Smrg ;; 25388cd5fc2Smrg 25488cd5fc2Smrgsgi) 25588cd5fc2Smrg if test "$libtool" = yes; then 25688cd5fc2Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25788cd5fc2Smrg else 25888cd5fc2Smrg "$@" -MDupdate "$tmpdepfile" 25988cd5fc2Smrg fi 26088cd5fc2Smrg stat=$? 26188cd5fc2Smrg if test $stat -ne 0; then 26288cd5fc2Smrg rm -f "$tmpdepfile" 26388cd5fc2Smrg exit $stat 26488cd5fc2Smrg fi 26588cd5fc2Smrg rm -f "$depfile" 26688cd5fc2Smrg 26788cd5fc2Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26888cd5fc2Smrg echo "$object : \\" > "$depfile" 26988cd5fc2Smrg # Clip off the initial element (the dependent). Don't try to be 27088cd5fc2Smrg # clever and replace this with sed code, as IRIX sed won't handle 27188cd5fc2Smrg # lines with more than a fixed number of characters (4096 in 27288cd5fc2Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27388cd5fc2Smrg # the IRIX cc adds comments like '#:fec' to the end of the 27488cd5fc2Smrg # dependency line. 27588cd5fc2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27688cd5fc2Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27788cd5fc2Smrg | tr "$nl" ' ' >> "$depfile" 27888cd5fc2Smrg echo >> "$depfile" 27988cd5fc2Smrg # The second pass generates a dummy entry for each header file. 28088cd5fc2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28188cd5fc2Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28288cd5fc2Smrg >> "$depfile" 28388cd5fc2Smrg else 28488cd5fc2Smrg make_dummy_depfile 28588cd5fc2Smrg fi 28688cd5fc2Smrg rm -f "$tmpdepfile" 28788cd5fc2Smrg ;; 28888cd5fc2Smrg 28988cd5fc2Smrgxlc) 29088cd5fc2Smrg # This case exists only to let depend.m4 do its work. It works by 29188cd5fc2Smrg # looking at the text of this script. This case will never be run, 29288cd5fc2Smrg # since it is checked for above. 29388cd5fc2Smrg exit 1 29488cd5fc2Smrg ;; 29588cd5fc2Smrg 29688cd5fc2Smrgaix) 29788cd5fc2Smrg # The C for AIX Compiler uses -M and outputs the dependencies 29888cd5fc2Smrg # in a .u file. In older versions, this file always lives in the 29988cd5fc2Smrg # current directory. Also, the AIX compiler puts '$object:' at the 30088cd5fc2Smrg # start of each line; $object doesn't have directory information. 30188cd5fc2Smrg # Version 6 uses the directory in both cases. 30288cd5fc2Smrg set_dir_from "$object" 30388cd5fc2Smrg set_base_from "$object" 30488cd5fc2Smrg if test "$libtool" = yes; then 30588cd5fc2Smrg tmpdepfile1=$dir$base.u 30688cd5fc2Smrg tmpdepfile2=$base.u 30788cd5fc2Smrg tmpdepfile3=$dir.libs/$base.u 30888cd5fc2Smrg "$@" -Wc,-M 30988cd5fc2Smrg else 31088cd5fc2Smrg tmpdepfile1=$dir$base.u 31188cd5fc2Smrg tmpdepfile2=$dir$base.u 31288cd5fc2Smrg tmpdepfile3=$dir$base.u 31388cd5fc2Smrg "$@" -M 31488cd5fc2Smrg fi 31588cd5fc2Smrg stat=$? 31688cd5fc2Smrg if test $stat -ne 0; then 31788cd5fc2Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31888cd5fc2Smrg exit $stat 31988cd5fc2Smrg fi 32088cd5fc2Smrg 32188cd5fc2Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32288cd5fc2Smrg do 32388cd5fc2Smrg test -f "$tmpdepfile" && break 32488cd5fc2Smrg done 32588cd5fc2Smrg aix_post_process_depfile 32688cd5fc2Smrg ;; 32788cd5fc2Smrg 32888cd5fc2Smrgtcc) 32988cd5fc2Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33088cd5fc2Smrg # FIXME: That version still under development at the moment of writing. 33188cd5fc2Smrg # Make that this statement remains true also for stable, released 33288cd5fc2Smrg # versions. 33388cd5fc2Smrg # It will wrap lines (doesn't matter whether long or short) with a 33488cd5fc2Smrg # trailing '\', as in: 33588cd5fc2Smrg # 33688cd5fc2Smrg # foo.o : \ 33788cd5fc2Smrg # foo.c \ 33888cd5fc2Smrg # foo.h \ 33988cd5fc2Smrg # 34088cd5fc2Smrg # It will put a trailing '\' even on the last line, and will use leading 34188cd5fc2Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34288cd5fc2Smrg # "Emit spaces for -MD"). 34388cd5fc2Smrg "$@" -MD -MF "$tmpdepfile" 34488cd5fc2Smrg stat=$? 34588cd5fc2Smrg if test $stat -ne 0; then 34688cd5fc2Smrg rm -f "$tmpdepfile" 34788cd5fc2Smrg exit $stat 34888cd5fc2Smrg fi 34988cd5fc2Smrg rm -f "$depfile" 35088cd5fc2Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35188cd5fc2Smrg # We have to change lines of the first kind to '$object: \'. 35288cd5fc2Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35388cd5fc2Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35488cd5fc2Smrg # dummy dependency, to avoid the deleted-header problem. 35588cd5fc2Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35688cd5fc2Smrg rm -f "$tmpdepfile" 35788cd5fc2Smrg ;; 35888cd5fc2Smrg 35988cd5fc2Smrg## The order of this option in the case statement is important, since the 36088cd5fc2Smrg## shell code in configure will try each of these formats in the order 36188cd5fc2Smrg## listed in this file. A plain '-MD' option would be understood by many 36288cd5fc2Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36388cd5fc2Smrgpgcc) 36488cd5fc2Smrg # Portland's C compiler understands '-MD'. 36588cd5fc2Smrg # Will always output deps to 'file.d' where file is the root name of the 36688cd5fc2Smrg # source file under compilation, even if file resides in a subdirectory. 36788cd5fc2Smrg # The object file name does not affect the name of the '.d' file. 36888cd5fc2Smrg # pgcc 10.2 will output 36988cd5fc2Smrg # foo.o: sub/foo.c sub/foo.h 37088cd5fc2Smrg # and will wrap long lines using '\' : 37188cd5fc2Smrg # foo.o: sub/foo.c ... \ 37288cd5fc2Smrg # sub/foo.h ... \ 37388cd5fc2Smrg # ... 37488cd5fc2Smrg set_dir_from "$object" 37588cd5fc2Smrg # Use the source, not the object, to determine the base name, since 37688cd5fc2Smrg # that's sadly what pgcc will do too. 37788cd5fc2Smrg set_base_from "$source" 37888cd5fc2Smrg tmpdepfile=$base.d 37988cd5fc2Smrg 38088cd5fc2Smrg # For projects that build the same source file twice into different object 38188cd5fc2Smrg # files, the pgcc approach of using the *source* file root name can cause 38288cd5fc2Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38388cd5fc2Smrg # the same $tmpdepfile. 38488cd5fc2Smrg lockdir=$base.d-lock 38588cd5fc2Smrg trap " 38688cd5fc2Smrg echo '$0: caught signal, cleaning up...' >&2 38788cd5fc2Smrg rmdir '$lockdir' 38888cd5fc2Smrg exit 1 38988cd5fc2Smrg " 1 2 13 15 39088cd5fc2Smrg numtries=100 39188cd5fc2Smrg i=$numtries 39288cd5fc2Smrg while test $i -gt 0; do 39388cd5fc2Smrg # mkdir is a portable test-and-set. 39488cd5fc2Smrg if mkdir "$lockdir" 2>/dev/null; then 39588cd5fc2Smrg # This process acquired the lock. 39688cd5fc2Smrg "$@" -MD 39788cd5fc2Smrg stat=$? 39888cd5fc2Smrg # Release the lock. 39988cd5fc2Smrg rmdir "$lockdir" 40088cd5fc2Smrg break 40188cd5fc2Smrg else 40288cd5fc2Smrg # If the lock is being held by a different process, wait 40388cd5fc2Smrg # until the winning process is done or we timeout. 40488cd5fc2Smrg while test -d "$lockdir" && test $i -gt 0; do 40588cd5fc2Smrg sleep 1 40688cd5fc2Smrg i=`expr $i - 1` 40788cd5fc2Smrg done 40888cd5fc2Smrg fi 40988cd5fc2Smrg i=`expr $i - 1` 41088cd5fc2Smrg done 41188cd5fc2Smrg trap - 1 2 13 15 41288cd5fc2Smrg if test $i -le 0; then 41388cd5fc2Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41488cd5fc2Smrg echo "$0: check lockdir '$lockdir'" >&2 41588cd5fc2Smrg exit 1 41688cd5fc2Smrg fi 41788cd5fc2Smrg 41888cd5fc2Smrg if test $stat -ne 0; then 41988cd5fc2Smrg rm -f "$tmpdepfile" 42088cd5fc2Smrg exit $stat 42188cd5fc2Smrg fi 42288cd5fc2Smrg rm -f "$depfile" 42388cd5fc2Smrg # Each line is of the form `foo.o: dependent.h', 42488cd5fc2Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42588cd5fc2Smrg # Do two passes, one to just change these to 42688cd5fc2Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 42788cd5fc2Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42888cd5fc2Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 42988cd5fc2Smrg # correctly. Breaking it into two sed invocations is a workaround. 43088cd5fc2Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43188cd5fc2Smrg | sed -e 's/$/ :/' >> "$depfile" 43288cd5fc2Smrg rm -f "$tmpdepfile" 43388cd5fc2Smrg ;; 43488cd5fc2Smrg 43588cd5fc2Smrghp2) 43688cd5fc2Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 43788cd5fc2Smrg # compilers, which have integrated preprocessors. The correct option 43888cd5fc2Smrg # to use with these is +Maked; it writes dependencies to a file named 43988cd5fc2Smrg # 'foo.d', which lands next to the object file, wherever that 44088cd5fc2Smrg # happens to be. 44188cd5fc2Smrg # Much of this is similar to the tru64 case; see comments there. 44288cd5fc2Smrg set_dir_from "$object" 44388cd5fc2Smrg set_base_from "$object" 44488cd5fc2Smrg if test "$libtool" = yes; then 44588cd5fc2Smrg tmpdepfile1=$dir$base.d 44688cd5fc2Smrg tmpdepfile2=$dir.libs/$base.d 44788cd5fc2Smrg "$@" -Wc,+Maked 44888cd5fc2Smrg else 44988cd5fc2Smrg tmpdepfile1=$dir$base.d 45088cd5fc2Smrg tmpdepfile2=$dir$base.d 45188cd5fc2Smrg "$@" +Maked 45288cd5fc2Smrg fi 45388cd5fc2Smrg stat=$? 45488cd5fc2Smrg if test $stat -ne 0; then 45588cd5fc2Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 45688cd5fc2Smrg exit $stat 45788cd5fc2Smrg fi 45888cd5fc2Smrg 45988cd5fc2Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 46088cd5fc2Smrg do 46188cd5fc2Smrg test -f "$tmpdepfile" && break 46288cd5fc2Smrg done 46388cd5fc2Smrg if test -f "$tmpdepfile"; then 46488cd5fc2Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46588cd5fc2Smrg # Add 'dependent.h:' lines. 46688cd5fc2Smrg sed -ne '2,${ 46788cd5fc2Smrg s/^ *// 46888cd5fc2Smrg s/ \\*$// 46988cd5fc2Smrg s/$/:/ 47088cd5fc2Smrg p 47188cd5fc2Smrg }' "$tmpdepfile" >> "$depfile" 47288cd5fc2Smrg else 47388cd5fc2Smrg make_dummy_depfile 47488cd5fc2Smrg fi 47588cd5fc2Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 47688cd5fc2Smrg ;; 47788cd5fc2Smrg 47888cd5fc2Smrgtru64) 47988cd5fc2Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48088cd5fc2Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48188cd5fc2Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48288cd5fc2Smrg # dependencies in 'foo.d' instead, so we check for that too. 48388cd5fc2Smrg # Subdirectories are respected. 48488cd5fc2Smrg set_dir_from "$object" 48588cd5fc2Smrg set_base_from "$object" 48688cd5fc2Smrg 48788cd5fc2Smrg if test "$libtool" = yes; then 48888cd5fc2Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48988cd5fc2Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49088cd5fc2Smrg # in $dir$base.o.d. We have to check for both files, because 49188cd5fc2Smrg # one of the two compilations can be disabled. We should prefer 49288cd5fc2Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49388cd5fc2Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49488cd5fc2Smrg # the former would cause a distcleancheck panic. 49588cd5fc2Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49688cd5fc2Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49788cd5fc2Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49888cd5fc2Smrg "$@" -Wc,-MD 49988cd5fc2Smrg else 50088cd5fc2Smrg tmpdepfile1=$dir$base.d 50188cd5fc2Smrg tmpdepfile2=$dir$base.d 50288cd5fc2Smrg tmpdepfile3=$dir$base.d 50388cd5fc2Smrg "$@" -MD 50488cd5fc2Smrg fi 50588cd5fc2Smrg 50688cd5fc2Smrg stat=$? 50788cd5fc2Smrg if test $stat -ne 0; then 50888cd5fc2Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50988cd5fc2Smrg exit $stat 51088cd5fc2Smrg fi 51188cd5fc2Smrg 51288cd5fc2Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51388cd5fc2Smrg do 51488cd5fc2Smrg test -f "$tmpdepfile" && break 51588cd5fc2Smrg done 51688cd5fc2Smrg # Same post-processing that is required for AIX mode. 51788cd5fc2Smrg aix_post_process_depfile 51888cd5fc2Smrg ;; 51988cd5fc2Smrg 52088cd5fc2Smrgmsvc7) 52188cd5fc2Smrg if test "$libtool" = yes; then 52288cd5fc2Smrg showIncludes=-Wc,-showIncludes 52388cd5fc2Smrg else 52488cd5fc2Smrg showIncludes=-showIncludes 52588cd5fc2Smrg fi 52688cd5fc2Smrg "$@" $showIncludes > "$tmpdepfile" 52788cd5fc2Smrg stat=$? 52888cd5fc2Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52988cd5fc2Smrg if test $stat -ne 0; then 53088cd5fc2Smrg rm -f "$tmpdepfile" 53188cd5fc2Smrg exit $stat 53288cd5fc2Smrg fi 53388cd5fc2Smrg rm -f "$depfile" 53488cd5fc2Smrg echo "$object : \\" > "$depfile" 53588cd5fc2Smrg # The first sed program below extracts the file names and escapes 53688cd5fc2Smrg # backslashes for cygpath. The second sed program outputs the file 53788cd5fc2Smrg # name when reading, but also accumulates all include files in the 53888cd5fc2Smrg # hold buffer in order to output them again at the end. This only 53988cd5fc2Smrg # works with sed implementations that can handle large buffers. 54088cd5fc2Smrg sed < "$tmpdepfile" -n ' 54188cd5fc2Smrg/^Note: including file: *\(.*\)/ { 54288cd5fc2Smrg s//\1/ 54388cd5fc2Smrg s/\\/\\\\/g 54488cd5fc2Smrg p 54588cd5fc2Smrg}' | $cygpath_u | sort -u | sed -n ' 54688cd5fc2Smrgs/ /\\ /g 54788cd5fc2Smrgs/\(.*\)/'"$tab"'\1 \\/p 54888cd5fc2Smrgs/.\(.*\) \\/\1:/ 54988cd5fc2SmrgH 55088cd5fc2Smrg$ { 55188cd5fc2Smrg s/.*/'"$tab"'/ 55288cd5fc2Smrg G 55388cd5fc2Smrg p 55488cd5fc2Smrg}' >> "$depfile" 55588cd5fc2Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55688cd5fc2Smrg rm -f "$tmpdepfile" 55788cd5fc2Smrg ;; 55888cd5fc2Smrg 55988cd5fc2Smrgmsvc7msys) 56088cd5fc2Smrg # This case exists only to let depend.m4 do its work. It works by 56188cd5fc2Smrg # looking at the text of this script. This case will never be run, 56288cd5fc2Smrg # since it is checked for above. 56388cd5fc2Smrg exit 1 56488cd5fc2Smrg ;; 56588cd5fc2Smrg 56688cd5fc2Smrg#nosideeffect) 56788cd5fc2Smrg # This comment above is used by automake to tell side-effect 56888cd5fc2Smrg # dependency tracking mechanisms from slower ones. 56988cd5fc2Smrg 57088cd5fc2Smrgdashmstdout) 57188cd5fc2Smrg # Important note: in order to support this mode, a compiler *must* 57288cd5fc2Smrg # always write the preprocessed file to stdout, regardless of -o. 57388cd5fc2Smrg "$@" || exit $? 57488cd5fc2Smrg 57588cd5fc2Smrg # Remove the call to Libtool. 57688cd5fc2Smrg if test "$libtool" = yes; then 57788cd5fc2Smrg while test "X$1" != 'X--mode=compile'; do 57888cd5fc2Smrg shift 57988cd5fc2Smrg done 58088cd5fc2Smrg shift 58188cd5fc2Smrg fi 58288cd5fc2Smrg 58388cd5fc2Smrg # Remove '-o $object'. 58488cd5fc2Smrg IFS=" " 58588cd5fc2Smrg for arg 58688cd5fc2Smrg do 58788cd5fc2Smrg case $arg in 58888cd5fc2Smrg -o) 58988cd5fc2Smrg shift 59088cd5fc2Smrg ;; 59188cd5fc2Smrg $object) 59288cd5fc2Smrg shift 59388cd5fc2Smrg ;; 59488cd5fc2Smrg *) 59588cd5fc2Smrg set fnord "$@" "$arg" 59688cd5fc2Smrg shift # fnord 59788cd5fc2Smrg shift # $arg 59888cd5fc2Smrg ;; 59988cd5fc2Smrg esac 60088cd5fc2Smrg done 60188cd5fc2Smrg 60288cd5fc2Smrg test -z "$dashmflag" && dashmflag=-M 60388cd5fc2Smrg # Require at least two characters before searching for ':' 60488cd5fc2Smrg # in the target name. This is to cope with DOS-style filenames: 60588cd5fc2Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60688cd5fc2Smrg "$@" $dashmflag | 60788cd5fc2Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60888cd5fc2Smrg rm -f "$depfile" 60988cd5fc2Smrg cat < "$tmpdepfile" > "$depfile" 61088cd5fc2Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61188cd5fc2Smrg # correctly. Breaking it into two sed invocations is a workaround. 61288cd5fc2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61388cd5fc2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61488cd5fc2Smrg | sed -e 's/$/ :/' >> "$depfile" 61588cd5fc2Smrg rm -f "$tmpdepfile" 61688cd5fc2Smrg ;; 61788cd5fc2Smrg 61888cd5fc2SmrgdashXmstdout) 61988cd5fc2Smrg # This case only exists to satisfy depend.m4. It is never actually 62088cd5fc2Smrg # run, as this mode is specially recognized in the preamble. 62188cd5fc2Smrg exit 1 62288cd5fc2Smrg ;; 62388cd5fc2Smrg 62488cd5fc2Smrgmakedepend) 62588cd5fc2Smrg "$@" || exit $? 62688cd5fc2Smrg # Remove any Libtool call 62788cd5fc2Smrg if test "$libtool" = yes; then 62888cd5fc2Smrg while test "X$1" != 'X--mode=compile'; do 62988cd5fc2Smrg shift 63088cd5fc2Smrg done 63188cd5fc2Smrg shift 63288cd5fc2Smrg fi 63388cd5fc2Smrg # X makedepend 63488cd5fc2Smrg shift 63588cd5fc2Smrg cleared=no eat=no 63688cd5fc2Smrg for arg 63788cd5fc2Smrg do 63888cd5fc2Smrg case $cleared in 63988cd5fc2Smrg no) 64088cd5fc2Smrg set ""; shift 64188cd5fc2Smrg cleared=yes ;; 64288cd5fc2Smrg esac 64388cd5fc2Smrg if test $eat = yes; then 64488cd5fc2Smrg eat=no 64588cd5fc2Smrg continue 64688cd5fc2Smrg fi 64788cd5fc2Smrg case "$arg" in 64888cd5fc2Smrg -D*|-I*) 64988cd5fc2Smrg set fnord "$@" "$arg"; shift ;; 65088cd5fc2Smrg # Strip any option that makedepend may not understand. Remove 65188cd5fc2Smrg # the object too, otherwise makedepend will parse it as a source file. 65288cd5fc2Smrg -arch) 65388cd5fc2Smrg eat=yes ;; 65488cd5fc2Smrg -*|$object) 65588cd5fc2Smrg ;; 65688cd5fc2Smrg *) 65788cd5fc2Smrg set fnord "$@" "$arg"; shift ;; 65888cd5fc2Smrg esac 65988cd5fc2Smrg done 66088cd5fc2Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66188cd5fc2Smrg touch "$tmpdepfile" 66288cd5fc2Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66388cd5fc2Smrg rm -f "$depfile" 66488cd5fc2Smrg # makedepend may prepend the VPATH from the source file name to the object. 66588cd5fc2Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66688cd5fc2Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66788cd5fc2Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66888cd5fc2Smrg # correctly. Breaking it into two sed invocations is a workaround. 66988cd5fc2Smrg sed '1,2d' "$tmpdepfile" \ 67088cd5fc2Smrg | tr ' ' "$nl" \ 67188cd5fc2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67288cd5fc2Smrg | sed -e 's/$/ :/' >> "$depfile" 67388cd5fc2Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67488cd5fc2Smrg ;; 67588cd5fc2Smrg 67688cd5fc2Smrgcpp) 67788cd5fc2Smrg # Important note: in order to support this mode, a compiler *must* 67888cd5fc2Smrg # always write the preprocessed file to stdout. 67988cd5fc2Smrg "$@" || exit $? 68088cd5fc2Smrg 68188cd5fc2Smrg # Remove the call to Libtool. 68288cd5fc2Smrg if test "$libtool" = yes; then 68388cd5fc2Smrg while test "X$1" != 'X--mode=compile'; do 68488cd5fc2Smrg shift 68588cd5fc2Smrg done 68688cd5fc2Smrg shift 68788cd5fc2Smrg fi 68888cd5fc2Smrg 68988cd5fc2Smrg # Remove '-o $object'. 69088cd5fc2Smrg IFS=" " 69188cd5fc2Smrg for arg 69288cd5fc2Smrg do 69388cd5fc2Smrg case $arg in 69488cd5fc2Smrg -o) 69588cd5fc2Smrg shift 69688cd5fc2Smrg ;; 69788cd5fc2Smrg $object) 69888cd5fc2Smrg shift 69988cd5fc2Smrg ;; 70088cd5fc2Smrg *) 70188cd5fc2Smrg set fnord "$@" "$arg" 70288cd5fc2Smrg shift # fnord 70388cd5fc2Smrg shift # $arg 70488cd5fc2Smrg ;; 70588cd5fc2Smrg esac 70688cd5fc2Smrg done 70788cd5fc2Smrg 70888cd5fc2Smrg "$@" -E \ 70988cd5fc2Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71088cd5fc2Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71188cd5fc2Smrg | sed '$ s: \\$::' > "$tmpdepfile" 71288cd5fc2Smrg rm -f "$depfile" 71388cd5fc2Smrg echo "$object : \\" > "$depfile" 71488cd5fc2Smrg cat < "$tmpdepfile" >> "$depfile" 71588cd5fc2Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71688cd5fc2Smrg rm -f "$tmpdepfile" 71788cd5fc2Smrg ;; 71888cd5fc2Smrg 71988cd5fc2Smrgmsvisualcpp) 72088cd5fc2Smrg # Important note: in order to support this mode, a compiler *must* 72188cd5fc2Smrg # always write the preprocessed file to stdout. 72288cd5fc2Smrg "$@" || exit $? 72388cd5fc2Smrg 72488cd5fc2Smrg # Remove the call to Libtool. 72588cd5fc2Smrg if test "$libtool" = yes; then 72688cd5fc2Smrg while test "X$1" != 'X--mode=compile'; do 72788cd5fc2Smrg shift 72888cd5fc2Smrg done 72988cd5fc2Smrg shift 73088cd5fc2Smrg fi 73188cd5fc2Smrg 73288cd5fc2Smrg IFS=" " 73388cd5fc2Smrg for arg 73488cd5fc2Smrg do 73588cd5fc2Smrg case "$arg" in 73688cd5fc2Smrg -o) 73788cd5fc2Smrg shift 73888cd5fc2Smrg ;; 73988cd5fc2Smrg $object) 74088cd5fc2Smrg shift 74188cd5fc2Smrg ;; 74288cd5fc2Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74388cd5fc2Smrg set fnord "$@" 74488cd5fc2Smrg shift 74588cd5fc2Smrg shift 74688cd5fc2Smrg ;; 74788cd5fc2Smrg *) 74888cd5fc2Smrg set fnord "$@" "$arg" 74988cd5fc2Smrg shift 75088cd5fc2Smrg shift 75188cd5fc2Smrg ;; 75288cd5fc2Smrg esac 75388cd5fc2Smrg done 75488cd5fc2Smrg "$@" -E 2>/dev/null | 75588cd5fc2Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75688cd5fc2Smrg rm -f "$depfile" 75788cd5fc2Smrg echo "$object : \\" > "$depfile" 75888cd5fc2Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75988cd5fc2Smrg echo "$tab" >> "$depfile" 76088cd5fc2Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76188cd5fc2Smrg rm -f "$tmpdepfile" 76288cd5fc2Smrg ;; 76388cd5fc2Smrg 76488cd5fc2Smrgmsvcmsys) 76588cd5fc2Smrg # This case exists only to let depend.m4 do its work. It works by 76688cd5fc2Smrg # looking at the text of this script. This case will never be run, 76788cd5fc2Smrg # since it is checked for above. 76888cd5fc2Smrg exit 1 76988cd5fc2Smrg ;; 77088cd5fc2Smrg 77188cd5fc2Smrgnone) 77288cd5fc2Smrg exec "$@" 77388cd5fc2Smrg ;; 77488cd5fc2Smrg 77588cd5fc2Smrg*) 77688cd5fc2Smrg echo "Unknown depmode $depmode" 1>&2 77788cd5fc2Smrg exit 1 77888cd5fc2Smrg ;; 77988cd5fc2Smrgesac 78088cd5fc2Smrg 78188cd5fc2Smrgexit 0 78288cd5fc2Smrg 78388cd5fc2Smrg# Local Variables: 78488cd5fc2Smrg# mode: shell-script 78588cd5fc2Smrg# sh-indentation: 2 786a33c354dSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 78788cd5fc2Smrg# time-stamp-start: "scriptversion=" 78888cd5fc2Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789a33c354dSmrg# time-stamp-time-zone: "UTC0" 79088cd5fc2Smrg# time-stamp-end: "; # UTC" 79188cd5fc2Smrg# End: 792