depcomp revision 8f34cbf9
1bbe1b32bSmrg#! /bin/sh 2bbe1b32bSmrg# depcomp - compile a program generating dependencies as side-effects 3bbe1b32bSmrg 48f34cbf9Ssnjscriptversion=2013-05-30.07; # UTC 5bbe1b32bSmrg 68f34cbf9Ssnj# Copyright (C) 1999-2013 Free Software Foundation, Inc. 7bbe1b32bSmrg 8bbe1b32bSmrg# This program is free software; you can redistribute it and/or modify 9bbe1b32bSmrg# it under the terms of the GNU General Public License as published by 10bbe1b32bSmrg# the Free Software Foundation; either version 2, or (at your option) 11bbe1b32bSmrg# any later version. 12bbe1b32bSmrg 13bbe1b32bSmrg# This program is distributed in the hope that it will be useful, 14bbe1b32bSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15bbe1b32bSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16bbe1b32bSmrg# GNU General Public License for more details. 17bbe1b32bSmrg 18bbe1b32bSmrg# You should have received a copy of the GNU General Public License 1930f8ce46Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20bbe1b32bSmrg 21bbe1b32bSmrg# As a special exception to the GNU General Public License, if you 22bbe1b32bSmrg# distribute this file as part of a program that contains a 23bbe1b32bSmrg# configuration script generated by Autoconf, you may include it under 24bbe1b32bSmrg# the same distribution terms that you use for the rest of that program. 25bbe1b32bSmrg 26bbe1b32bSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27bbe1b32bSmrg 28bbe1b32bSmrgcase $1 in 29bbe1b32bSmrg '') 308f34cbf9Ssnj echo "$0: No command. Try '$0 --help' for more information." 1>&2 318f34cbf9Ssnj exit 1; 328f34cbf9Ssnj ;; 33bbe1b32bSmrg -h | --h*) 34bbe1b32bSmrg cat <<\EOF 35bbe1b32bSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36bbe1b32bSmrg 37bbe1b32bSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38bbe1b32bSmrgas side-effects. 39bbe1b32bSmrg 40bbe1b32bSmrgEnvironment variables: 41bbe1b32bSmrg depmode Dependency tracking mode. 428f34cbf9Ssnj source Source file read by 'PROGRAMS ARGS'. 438f34cbf9Ssnj object Object file output by 'PROGRAMS ARGS'. 44bbe1b32bSmrg DEPDIR directory where to store dependencies. 45bbe1b32bSmrg depfile Dependency file to output. 4634f90d55Smrg tmpdepfile Temporary file to use when outputting dependencies. 47bbe1b32bSmrg libtool Whether libtool is used (yes/no). 48bbe1b32bSmrg 49bbe1b32bSmrgReport bugs to <bug-automake@gnu.org>. 50bbe1b32bSmrgEOF 51bbe1b32bSmrg exit $? 52bbe1b32bSmrg ;; 53bbe1b32bSmrg -v | --v*) 54bbe1b32bSmrg echo "depcomp $scriptversion" 55bbe1b32bSmrg exit $? 56bbe1b32bSmrg ;; 57bbe1b32bSmrgesac 58bbe1b32bSmrg 598f34cbf9Ssnj# Get the directory component of the given path, and save it in the 608f34cbf9Ssnj# global variables '$dir'. Note that this directory component will 618f34cbf9Ssnj# be either empty or ending with a '/' character. This is deliberate. 628f34cbf9Ssnjset_dir_from () 638f34cbf9Ssnj{ 648f34cbf9Ssnj case $1 in 658f34cbf9Ssnj */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 668f34cbf9Ssnj *) dir=;; 678f34cbf9Ssnj esac 688f34cbf9Ssnj} 698f34cbf9Ssnj 708f34cbf9Ssnj# Get the suffix-stripped basename of the given path, and save it the 718f34cbf9Ssnj# global variable '$base'. 728f34cbf9Ssnjset_base_from () 738f34cbf9Ssnj{ 748f34cbf9Ssnj base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 758f34cbf9Ssnj} 768f34cbf9Ssnj 778f34cbf9Ssnj# If no dependency file was actually created by the compiler invocation, 788f34cbf9Ssnj# we still have to create a dummy depfile, to avoid errors with the 798f34cbf9Ssnj# Makefile "include basename.Plo" scheme. 808f34cbf9Ssnjmake_dummy_depfile () 818f34cbf9Ssnj{ 828f34cbf9Ssnj echo "#dummy" > "$depfile" 838f34cbf9Ssnj} 848f34cbf9Ssnj 858f34cbf9Ssnj# Factor out some common post-processing of the generated depfile. 868f34cbf9Ssnj# Requires the auxiliary global variable '$tmpdepfile' to be set. 878f34cbf9Ssnjaix_post_process_depfile () 888f34cbf9Ssnj{ 898f34cbf9Ssnj # If the compiler actually managed to produce a dependency file, 908f34cbf9Ssnj # post-process it. 918f34cbf9Ssnj if test -f "$tmpdepfile"; then 928f34cbf9Ssnj # Each line is of the form 'foo.o: dependency.h'. 938f34cbf9Ssnj # Do two passes, one to just change these to 948f34cbf9Ssnj # $object: dependency.h 958f34cbf9Ssnj # and one to simply output 968f34cbf9Ssnj # dependency.h: 978f34cbf9Ssnj # which is needed to avoid the deleted-header problem. 988f34cbf9Ssnj { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 998f34cbf9Ssnj sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1008f34cbf9Ssnj } > "$depfile" 1018f34cbf9Ssnj rm -f "$tmpdepfile" 1028f34cbf9Ssnj else 1038f34cbf9Ssnj make_dummy_depfile 1048f34cbf9Ssnj fi 1058f34cbf9Ssnj} 1068f34cbf9Ssnj 1078f34cbf9Ssnj# A tabulation character. 1088f34cbf9Ssnjtab=' ' 1098f34cbf9Ssnj# A newline character. 1108f34cbf9Ssnjnl=' 1118f34cbf9Ssnj' 1128f34cbf9Ssnj# Character ranges might be problematic outside the C locale. 1138f34cbf9Ssnj# These definitions help. 1148f34cbf9Ssnjupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1158f34cbf9Ssnjlower=abcdefghijklmnopqrstuvwxyz 1168f34cbf9Ssnjdigits=0123456789 1178f34cbf9Ssnjalpha=${upper}${lower} 1188f34cbf9Ssnj 119bbe1b32bSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120bbe1b32bSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121bbe1b32bSmrg exit 1 122bbe1b32bSmrgfi 123bbe1b32bSmrg 124bbe1b32bSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125bbe1b32bSmrgdepfile=${depfile-`echo "$object" | 126bbe1b32bSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127bbe1b32bSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128bbe1b32bSmrg 129bbe1b32bSmrgrm -f "$tmpdepfile" 130bbe1b32bSmrg 1318f34cbf9Ssnj# Avoid interferences from the environment. 1328f34cbf9Ssnjgccflag= dashmflag= 1338f34cbf9Ssnj 134bbe1b32bSmrg# Some modes work just like other modes, but use different flags. We 135bbe1b32bSmrg# parameterize here, but still list the modes in the big case below, 136bbe1b32bSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137bbe1b32bSmrg# here, because this file can only contain one case statement. 138bbe1b32bSmrgif test "$depmode" = hp; then 139bbe1b32bSmrg # HP compiler uses -M and no extra arg. 140bbe1b32bSmrg gccflag=-M 141bbe1b32bSmrg depmode=gcc 142bbe1b32bSmrgfi 143bbe1b32bSmrg 144bbe1b32bSmrgif test "$depmode" = dashXmstdout; then 1458f34cbf9Ssnj # This is just like dashmstdout with a different argument. 1468f34cbf9Ssnj dashmflag=-xM 1478f34cbf9Ssnj depmode=dashmstdout 148bbe1b32bSmrgfi 149bbe1b32bSmrg 15030f8ce46Smrgcygpath_u="cygpath -u -f -" 15130f8ce46Smrgif test "$depmode" = msvcmsys; then 1528f34cbf9Ssnj # This is just like msvisualcpp but w/o cygpath translation. 1538f34cbf9Ssnj # Just convert the backslash-escaped backslashes to single forward 1548f34cbf9Ssnj # slashes to satisfy depend.m4 1558f34cbf9Ssnj cygpath_u='sed s,\\\\,/,g' 1568f34cbf9Ssnj depmode=msvisualcpp 15730f8ce46Smrgfi 15830f8ce46Smrg 15934f90d55Smrgif test "$depmode" = msvc7msys; then 1608f34cbf9Ssnj # This is just like msvc7 but w/o cygpath translation. 1618f34cbf9Ssnj # Just convert the backslash-escaped backslashes to single forward 1628f34cbf9Ssnj # slashes to satisfy depend.m4 1638f34cbf9Ssnj cygpath_u='sed s,\\\\,/,g' 1648f34cbf9Ssnj depmode=msvc7 1658f34cbf9Ssnjfi 1668f34cbf9Ssnj 1678f34cbf9Ssnjif test "$depmode" = xlc; then 1688f34cbf9Ssnj # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1698f34cbf9Ssnj gccflag=-qmakedep=gcc,-MF 1708f34cbf9Ssnj depmode=gcc 17134f90d55Smrgfi 17234f90d55Smrg 173bbe1b32bSmrgcase "$depmode" in 174bbe1b32bSmrggcc3) 175bbe1b32bSmrg## gcc 3 implements dependency tracking that does exactly what 176bbe1b32bSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177bbe1b32bSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 178ce6676dbSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179ce6676dbSmrg## the command line argument order; so add the flags where they 180ce6676dbSmrg## appear in depend2.am. Note that the slowdown incurred here 181ce6676dbSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182ce6676dbSmrg for arg 183ce6676dbSmrg do 184ce6676dbSmrg case $arg in 185ce6676dbSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186ce6676dbSmrg *) set fnord "$@" "$arg" ;; 187ce6676dbSmrg esac 188ce6676dbSmrg shift # fnord 189ce6676dbSmrg shift # $arg 190ce6676dbSmrg done 191ce6676dbSmrg "$@" 192bbe1b32bSmrg stat=$? 1938f34cbf9Ssnj if test $stat -ne 0; then 194bbe1b32bSmrg rm -f "$tmpdepfile" 195bbe1b32bSmrg exit $stat 196bbe1b32bSmrg fi 197bbe1b32bSmrg mv "$tmpdepfile" "$depfile" 198bbe1b32bSmrg ;; 199bbe1b32bSmrg 200bbe1b32bSmrggcc) 2018f34cbf9Ssnj## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2028f34cbf9Ssnj## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2038f34cbf9Ssnj## (see the conditional assignment to $gccflag above). 204bbe1b32bSmrg## There are various ways to get dependency output from gcc. Here's 205bbe1b32bSmrg## why we pick this rather obscure method: 206bbe1b32bSmrg## - Don't want to use -MD because we'd like the dependencies to end 207bbe1b32bSmrg## up in a subdir. Having to rename by hand is ugly. 208bbe1b32bSmrg## (We might end up doing this anyway to support other compilers.) 209bbe1b32bSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2108f34cbf9Ssnj## -MM, not -M (despite what the docs say). Also, it might not be 2118f34cbf9Ssnj## supported by the other compilers which use the 'gcc' depmode. 212bbe1b32bSmrg## - Using -M directly means running the compiler twice (even worse 213bbe1b32bSmrg## than renaming). 214bbe1b32bSmrg if test -z "$gccflag"; then 215bbe1b32bSmrg gccflag=-MD, 216bbe1b32bSmrg fi 217bbe1b32bSmrg "$@" -Wp,"$gccflag$tmpdepfile" 218bbe1b32bSmrg stat=$? 2198f34cbf9Ssnj if test $stat -ne 0; then 220bbe1b32bSmrg rm -f "$tmpdepfile" 221bbe1b32bSmrg exit $stat 222bbe1b32bSmrg fi 223bbe1b32bSmrg rm -f "$depfile" 224bbe1b32bSmrg echo "$object : \\" > "$depfile" 2258f34cbf9Ssnj # The second -e expression handles DOS-style file names with drive 2268f34cbf9Ssnj # letters. 227bbe1b32bSmrg sed -e 's/^[^:]*: / /' \ 228bbe1b32bSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2298f34cbf9Ssnj## This next piece of magic avoids the "deleted header file" problem. 230bbe1b32bSmrg## The problem is that when a header file which appears in a .P file 231bbe1b32bSmrg## is deleted, the dependency causes make to die (because there is 232bbe1b32bSmrg## typically no way to rebuild the header). We avoid this by adding 233bbe1b32bSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 234bbe1b32bSmrg## this for us directly. 2358f34cbf9Ssnj## Some versions of gcc put a space before the ':'. On the theory 236bbe1b32bSmrg## that the space means something, we add a space to the output as 23734f90d55Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23834f90d55Smrg## to the object. Take care to not repeat it in the output. 239bbe1b32bSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 240bbe1b32bSmrg## correctly. Breaking it into two sed invocations is a workaround. 2418f34cbf9Ssnj tr ' ' "$nl" < "$tmpdepfile" \ 2428f34cbf9Ssnj | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2438f34cbf9Ssnj | sed -e 's/$/ :/' >> "$depfile" 244bbe1b32bSmrg rm -f "$tmpdepfile" 245bbe1b32bSmrg ;; 246bbe1b32bSmrg 247bbe1b32bSmrghp) 248bbe1b32bSmrg # This case exists only to let depend.m4 do its work. It works by 249bbe1b32bSmrg # looking at the text of this script. This case will never be run, 250bbe1b32bSmrg # since it is checked for above. 251bbe1b32bSmrg exit 1 252bbe1b32bSmrg ;; 253bbe1b32bSmrg 254bbe1b32bSmrgsgi) 255bbe1b32bSmrg if test "$libtool" = yes; then 256bbe1b32bSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257bbe1b32bSmrg else 258bbe1b32bSmrg "$@" -MDupdate "$tmpdepfile" 259bbe1b32bSmrg fi 260bbe1b32bSmrg stat=$? 2618f34cbf9Ssnj if test $stat -ne 0; then 262bbe1b32bSmrg rm -f "$tmpdepfile" 263bbe1b32bSmrg exit $stat 264bbe1b32bSmrg fi 265bbe1b32bSmrg rm -f "$depfile" 266bbe1b32bSmrg 267bbe1b32bSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268bbe1b32bSmrg echo "$object : \\" > "$depfile" 269bbe1b32bSmrg # Clip off the initial element (the dependent). Don't try to be 270bbe1b32bSmrg # clever and replace this with sed code, as IRIX sed won't handle 271bbe1b32bSmrg # lines with more than a fixed number of characters (4096 in 272bbe1b32bSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2738f34cbf9Ssnj # the IRIX cc adds comments like '#:fec' to the end of the 274bbe1b32bSmrg # dependency line. 2758f34cbf9Ssnj tr ' ' "$nl" < "$tmpdepfile" \ 2768f34cbf9Ssnj | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2778f34cbf9Ssnj | tr "$nl" ' ' >> "$depfile" 27830f8ce46Smrg echo >> "$depfile" 279bbe1b32bSmrg # The second pass generates a dummy entry for each header file. 2808f34cbf9Ssnj tr ' ' "$nl" < "$tmpdepfile" \ 2818f34cbf9Ssnj | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2828f34cbf9Ssnj >> "$depfile" 283bbe1b32bSmrg else 2848f34cbf9Ssnj make_dummy_depfile 285bbe1b32bSmrg fi 286bbe1b32bSmrg rm -f "$tmpdepfile" 287bbe1b32bSmrg ;; 288bbe1b32bSmrg 2898f34cbf9Ssnjxlc) 2908f34cbf9Ssnj # This case exists only to let depend.m4 do its work. It works by 2918f34cbf9Ssnj # looking at the text of this script. This case will never be run, 2928f34cbf9Ssnj # since it is checked for above. 2938f34cbf9Ssnj exit 1 2948f34cbf9Ssnj ;; 2958f34cbf9Ssnj 296bbe1b32bSmrgaix) 297bbe1b32bSmrg # The C for AIX Compiler uses -M and outputs the dependencies 298bbe1b32bSmrg # in a .u file. In older versions, this file always lives in the 2998f34cbf9Ssnj # current directory. Also, the AIX compiler puts '$object:' at the 300bbe1b32bSmrg # start of each line; $object doesn't have directory information. 301bbe1b32bSmrg # Version 6 uses the directory in both cases. 3028f34cbf9Ssnj set_dir_from "$object" 3038f34cbf9Ssnj set_base_from "$object" 304bbe1b32bSmrg if test "$libtool" = yes; then 30530f8ce46Smrg tmpdepfile1=$dir$base.u 30630f8ce46Smrg tmpdepfile2=$base.u 30730f8ce46Smrg tmpdepfile3=$dir.libs/$base.u 308bbe1b32bSmrg "$@" -Wc,-M 309bbe1b32bSmrg else 31030f8ce46Smrg tmpdepfile1=$dir$base.u 31130f8ce46Smrg tmpdepfile2=$dir$base.u 31230f8ce46Smrg tmpdepfile3=$dir$base.u 313bbe1b32bSmrg "$@" -M 314bbe1b32bSmrg fi 315bbe1b32bSmrg stat=$? 3168f34cbf9Ssnj if test $stat -ne 0; then 31730f8ce46Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318bbe1b32bSmrg exit $stat 319bbe1b32bSmrg fi 320bbe1b32bSmrg 32130f8ce46Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32230f8ce46Smrg do 32330f8ce46Smrg test -f "$tmpdepfile" && break 32430f8ce46Smrg done 3258f34cbf9Ssnj aix_post_process_depfile 3268f34cbf9Ssnj ;; 3278f34cbf9Ssnj 3288f34cbf9Ssnjtcc) 3298f34cbf9Ssnj # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3308f34cbf9Ssnj # FIXME: That version still under development at the moment of writing. 3318f34cbf9Ssnj # Make that this statement remains true also for stable, released 3328f34cbf9Ssnj # versions. 3338f34cbf9Ssnj # It will wrap lines (doesn't matter whether long or short) with a 3348f34cbf9Ssnj # trailing '\', as in: 3358f34cbf9Ssnj # 3368f34cbf9Ssnj # foo.o : \ 3378f34cbf9Ssnj # foo.c \ 3388f34cbf9Ssnj # foo.h \ 3398f34cbf9Ssnj # 3408f34cbf9Ssnj # It will put a trailing '\' even on the last line, and will use leading 3418f34cbf9Ssnj # spaces rather than leading tabs (at least since its commit 0394caf7 3428f34cbf9Ssnj # "Emit spaces for -MD"). 3438f34cbf9Ssnj "$@" -MD -MF "$tmpdepfile" 3448f34cbf9Ssnj stat=$? 3458f34cbf9Ssnj if test $stat -ne 0; then 3468f34cbf9Ssnj rm -f "$tmpdepfile" 3478f34cbf9Ssnj exit $stat 348bbe1b32bSmrg fi 3498f34cbf9Ssnj rm -f "$depfile" 3508f34cbf9Ssnj # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3518f34cbf9Ssnj # We have to change lines of the first kind to '$object: \'. 3528f34cbf9Ssnj sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3538f34cbf9Ssnj # And for each line of the second kind, we have to emit a 'dep.h:' 3548f34cbf9Ssnj # dummy dependency, to avoid the deleted-header problem. 3558f34cbf9Ssnj sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356bbe1b32bSmrg rm -f "$tmpdepfile" 357bbe1b32bSmrg ;; 358bbe1b32bSmrg 3598f34cbf9Ssnj## The order of this option in the case statement is important, since the 3608f34cbf9Ssnj## shell code in configure will try each of these formats in the order 3618f34cbf9Ssnj## listed in this file. A plain '-MD' option would be understood by many 3628f34cbf9Ssnj## compilers, so we must ensure this comes after the gcc and icc options. 3638f34cbf9Ssnjpgcc) 3648f34cbf9Ssnj # Portland's C compiler understands '-MD'. 3658f34cbf9Ssnj # Will always output deps to 'file.d' where file is the root name of the 3668f34cbf9Ssnj # source file under compilation, even if file resides in a subdirectory. 3678f34cbf9Ssnj # The object file name does not affect the name of the '.d' file. 3688f34cbf9Ssnj # pgcc 10.2 will output 369bbe1b32bSmrg # foo.o: sub/foo.c sub/foo.h 3708f34cbf9Ssnj # and will wrap long lines using '\' : 371bbe1b32bSmrg # foo.o: sub/foo.c ... \ 372bbe1b32bSmrg # sub/foo.h ... \ 373bbe1b32bSmrg # ... 3748f34cbf9Ssnj set_dir_from "$object" 3758f34cbf9Ssnj # Use the source, not the object, to determine the base name, since 3768f34cbf9Ssnj # that's sadly what pgcc will do too. 3778f34cbf9Ssnj set_base_from "$source" 3788f34cbf9Ssnj tmpdepfile=$base.d 3798f34cbf9Ssnj 3808f34cbf9Ssnj # For projects that build the same source file twice into different object 3818f34cbf9Ssnj # files, the pgcc approach of using the *source* file root name can cause 3828f34cbf9Ssnj # problems in parallel builds. Use a locking strategy to avoid stomping on 3838f34cbf9Ssnj # the same $tmpdepfile. 3848f34cbf9Ssnj lockdir=$base.d-lock 3858f34cbf9Ssnj trap " 3868f34cbf9Ssnj echo '$0: caught signal, cleaning up...' >&2 3878f34cbf9Ssnj rmdir '$lockdir' 3888f34cbf9Ssnj exit 1 3898f34cbf9Ssnj " 1 2 13 15 3908f34cbf9Ssnj numtries=100 3918f34cbf9Ssnj i=$numtries 3928f34cbf9Ssnj while test $i -gt 0; do 3938f34cbf9Ssnj # mkdir is a portable test-and-set. 3948f34cbf9Ssnj if mkdir "$lockdir" 2>/dev/null; then 3958f34cbf9Ssnj # This process acquired the lock. 3968f34cbf9Ssnj "$@" -MD 3978f34cbf9Ssnj stat=$? 3988f34cbf9Ssnj # Release the lock. 3998f34cbf9Ssnj rmdir "$lockdir" 4008f34cbf9Ssnj break 4018f34cbf9Ssnj else 4028f34cbf9Ssnj # If the lock is being held by a different process, wait 4038f34cbf9Ssnj # until the winning process is done or we timeout. 4048f34cbf9Ssnj while test -d "$lockdir" && test $i -gt 0; do 4058f34cbf9Ssnj sleep 1 4068f34cbf9Ssnj i=`expr $i - 1` 4078f34cbf9Ssnj done 4088f34cbf9Ssnj fi 4098f34cbf9Ssnj i=`expr $i - 1` 4108f34cbf9Ssnj done 4118f34cbf9Ssnj trap - 1 2 13 15 4128f34cbf9Ssnj if test $i -le 0; then 4138f34cbf9Ssnj echo "$0: failed to acquire lock after $numtries attempts" >&2 4148f34cbf9Ssnj echo "$0: check lockdir '$lockdir'" >&2 4158f34cbf9Ssnj exit 1 4168f34cbf9Ssnj fi 417bbe1b32bSmrg 4188f34cbf9Ssnj if test $stat -ne 0; then 419bbe1b32bSmrg rm -f "$tmpdepfile" 420bbe1b32bSmrg exit $stat 421bbe1b32bSmrg fi 422bbe1b32bSmrg rm -f "$depfile" 423bbe1b32bSmrg # Each line is of the form `foo.o: dependent.h', 424bbe1b32bSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425bbe1b32bSmrg # Do two passes, one to just change these to 426bbe1b32bSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427bbe1b32bSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428bbe1b32bSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429bbe1b32bSmrg # correctly. Breaking it into two sed invocations is a workaround. 4308f34cbf9Ssnj sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4318f34cbf9Ssnj | sed -e 's/$/ :/' >> "$depfile" 432bbe1b32bSmrg rm -f "$tmpdepfile" 433bbe1b32bSmrg ;; 434bbe1b32bSmrg 435ce6676dbSmrghp2) 436ce6676dbSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437ce6676dbSmrg # compilers, which have integrated preprocessors. The correct option 438ce6676dbSmrg # to use with these is +Maked; it writes dependencies to a file named 439ce6676dbSmrg # 'foo.d', which lands next to the object file, wherever that 440ce6676dbSmrg # happens to be. 441ce6676dbSmrg # Much of this is similar to the tru64 case; see comments there. 4428f34cbf9Ssnj set_dir_from "$object" 4438f34cbf9Ssnj set_base_from "$object" 444ce6676dbSmrg if test "$libtool" = yes; then 445ce6676dbSmrg tmpdepfile1=$dir$base.d 446ce6676dbSmrg tmpdepfile2=$dir.libs/$base.d 447ce6676dbSmrg "$@" -Wc,+Maked 448ce6676dbSmrg else 449ce6676dbSmrg tmpdepfile1=$dir$base.d 450ce6676dbSmrg tmpdepfile2=$dir$base.d 451ce6676dbSmrg "$@" +Maked 452ce6676dbSmrg fi 453ce6676dbSmrg stat=$? 4548f34cbf9Ssnj if test $stat -ne 0; then 455ce6676dbSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456ce6676dbSmrg exit $stat 457ce6676dbSmrg fi 458ce6676dbSmrg 459ce6676dbSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460ce6676dbSmrg do 461ce6676dbSmrg test -f "$tmpdepfile" && break 462ce6676dbSmrg done 463ce6676dbSmrg if test -f "$tmpdepfile"; then 4648f34cbf9Ssnj sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4658f34cbf9Ssnj # Add 'dependent.h:' lines. 46630f8ce46Smrg sed -ne '2,${ 4678f34cbf9Ssnj s/^ *// 4688f34cbf9Ssnj s/ \\*$// 4698f34cbf9Ssnj s/$/:/ 4708f34cbf9Ssnj p 4718f34cbf9Ssnj }' "$tmpdepfile" >> "$depfile" 472ce6676dbSmrg else 4738f34cbf9Ssnj make_dummy_depfile 474ce6676dbSmrg fi 475ce6676dbSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 476ce6676dbSmrg ;; 477ce6676dbSmrg 478bbe1b32bSmrgtru64) 4798f34cbf9Ssnj # The Tru64 compiler uses -MD to generate dependencies as a side 4808f34cbf9Ssnj # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4818f34cbf9Ssnj # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4828f34cbf9Ssnj # dependencies in 'foo.d' instead, so we check for that too. 4838f34cbf9Ssnj # Subdirectories are respected. 4848f34cbf9Ssnj set_dir_from "$object" 4858f34cbf9Ssnj set_base_from "$object" 4868f34cbf9Ssnj 4878f34cbf9Ssnj if test "$libtool" = yes; then 4888f34cbf9Ssnj # Libtool generates 2 separate objects for the 2 libraries. These 4898f34cbf9Ssnj # two compilations output dependencies in $dir.libs/$base.o.d and 4908f34cbf9Ssnj # in $dir$base.o.d. We have to check for both files, because 4918f34cbf9Ssnj # one of the two compilations can be disabled. We should prefer 4928f34cbf9Ssnj # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4938f34cbf9Ssnj # automatically cleaned when .libs/ is deleted, while ignoring 4948f34cbf9Ssnj # the former would cause a distcleancheck panic. 4958f34cbf9Ssnj tmpdepfile1=$dir$base.o.d # libtool 1.5 4968f34cbf9Ssnj tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4978f34cbf9Ssnj tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4988f34cbf9Ssnj "$@" -Wc,-MD 4998f34cbf9Ssnj else 5008f34cbf9Ssnj tmpdepfile1=$dir$base.d 5018f34cbf9Ssnj tmpdepfile2=$dir$base.d 5028f34cbf9Ssnj tmpdepfile3=$dir$base.d 5038f34cbf9Ssnj "$@" -MD 5048f34cbf9Ssnj fi 5058f34cbf9Ssnj 5068f34cbf9Ssnj stat=$? 5078f34cbf9Ssnj if test $stat -ne 0; then 5088f34cbf9Ssnj rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5098f34cbf9Ssnj exit $stat 5108f34cbf9Ssnj fi 5118f34cbf9Ssnj 5128f34cbf9Ssnj for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5138f34cbf9Ssnj do 5148f34cbf9Ssnj test -f "$tmpdepfile" && break 5158f34cbf9Ssnj done 5168f34cbf9Ssnj # Same post-processing that is required for AIX mode. 5178f34cbf9Ssnj aix_post_process_depfile 5188f34cbf9Ssnj ;; 519bbe1b32bSmrg 52034f90d55Smrgmsvc7) 52134f90d55Smrg if test "$libtool" = yes; then 52234f90d55Smrg showIncludes=-Wc,-showIncludes 52334f90d55Smrg else 52434f90d55Smrg showIncludes=-showIncludes 52534f90d55Smrg fi 52634f90d55Smrg "$@" $showIncludes > "$tmpdepfile" 52734f90d55Smrg stat=$? 52834f90d55Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5298f34cbf9Ssnj if test $stat -ne 0; then 53034f90d55Smrg rm -f "$tmpdepfile" 53134f90d55Smrg exit $stat 53234f90d55Smrg fi 53334f90d55Smrg rm -f "$depfile" 53434f90d55Smrg echo "$object : \\" > "$depfile" 53534f90d55Smrg # The first sed program below extracts the file names and escapes 53634f90d55Smrg # backslashes for cygpath. The second sed program outputs the file 53734f90d55Smrg # name when reading, but also accumulates all include files in the 53834f90d55Smrg # hold buffer in order to output them again at the end. This only 53934f90d55Smrg # works with sed implementations that can handle large buffers. 54034f90d55Smrg sed < "$tmpdepfile" -n ' 54134f90d55Smrg/^Note: including file: *\(.*\)/ { 54234f90d55Smrg s//\1/ 54334f90d55Smrg s/\\/\\\\/g 54434f90d55Smrg p 54534f90d55Smrg}' | $cygpath_u | sort -u | sed -n ' 54634f90d55Smrgs/ /\\ /g 5478f34cbf9Ssnjs/\(.*\)/'"$tab"'\1 \\/p 54834f90d55Smrgs/.\(.*\) \\/\1:/ 54934f90d55SmrgH 55034f90d55Smrg$ { 5518f34cbf9Ssnj s/.*/'"$tab"'/ 55234f90d55Smrg G 55334f90d55Smrg p 55434f90d55Smrg}' >> "$depfile" 5558f34cbf9Ssnj echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55634f90d55Smrg rm -f "$tmpdepfile" 55734f90d55Smrg ;; 55834f90d55Smrg 55934f90d55Smrgmsvc7msys) 56034f90d55Smrg # This case exists only to let depend.m4 do its work. It works by 56134f90d55Smrg # looking at the text of this script. This case will never be run, 56234f90d55Smrg # since it is checked for above. 56334f90d55Smrg exit 1 56434f90d55Smrg ;; 56534f90d55Smrg 566bbe1b32bSmrg#nosideeffect) 567bbe1b32bSmrg # This comment above is used by automake to tell side-effect 568bbe1b32bSmrg # dependency tracking mechanisms from slower ones. 569bbe1b32bSmrg 570bbe1b32bSmrgdashmstdout) 571bbe1b32bSmrg # Important note: in order to support this mode, a compiler *must* 572bbe1b32bSmrg # always write the preprocessed file to stdout, regardless of -o. 573bbe1b32bSmrg "$@" || exit $? 574bbe1b32bSmrg 575bbe1b32bSmrg # Remove the call to Libtool. 576bbe1b32bSmrg if test "$libtool" = yes; then 57730f8ce46Smrg while test "X$1" != 'X--mode=compile'; do 578bbe1b32bSmrg shift 579bbe1b32bSmrg done 580bbe1b32bSmrg shift 581bbe1b32bSmrg fi 582bbe1b32bSmrg 5838f34cbf9Ssnj # Remove '-o $object'. 584bbe1b32bSmrg IFS=" " 585bbe1b32bSmrg for arg 586bbe1b32bSmrg do 587bbe1b32bSmrg case $arg in 588bbe1b32bSmrg -o) 589bbe1b32bSmrg shift 590bbe1b32bSmrg ;; 591bbe1b32bSmrg $object) 592bbe1b32bSmrg shift 593bbe1b32bSmrg ;; 594bbe1b32bSmrg *) 595bbe1b32bSmrg set fnord "$@" "$arg" 596bbe1b32bSmrg shift # fnord 597bbe1b32bSmrg shift # $arg 598bbe1b32bSmrg ;; 599bbe1b32bSmrg esac 600bbe1b32bSmrg done 601bbe1b32bSmrg 602bbe1b32bSmrg test -z "$dashmflag" && dashmflag=-M 6038f34cbf9Ssnj # Require at least two characters before searching for ':' 604bbe1b32bSmrg # in the target name. This is to cope with DOS-style filenames: 6058f34cbf9Ssnj # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606bbe1b32bSmrg "$@" $dashmflag | 6078f34cbf9Ssnj sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608bbe1b32bSmrg rm -f "$depfile" 609bbe1b32bSmrg cat < "$tmpdepfile" > "$depfile" 6108f34cbf9Ssnj # Some versions of the HPUX 10.20 sed can't process this sed invocation 6118f34cbf9Ssnj # correctly. Breaking it into two sed invocations is a workaround. 6128f34cbf9Ssnj tr ' ' "$nl" < "$tmpdepfile" \ 6138f34cbf9Ssnj | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6148f34cbf9Ssnj | sed -e 's/$/ :/' >> "$depfile" 615bbe1b32bSmrg rm -f "$tmpdepfile" 616bbe1b32bSmrg ;; 617bbe1b32bSmrg 618bbe1b32bSmrgdashXmstdout) 619bbe1b32bSmrg # This case only exists to satisfy depend.m4. It is never actually 620bbe1b32bSmrg # run, as this mode is specially recognized in the preamble. 621bbe1b32bSmrg exit 1 622bbe1b32bSmrg ;; 623bbe1b32bSmrg 624bbe1b32bSmrgmakedepend) 625bbe1b32bSmrg "$@" || exit $? 626bbe1b32bSmrg # Remove any Libtool call 627bbe1b32bSmrg if test "$libtool" = yes; then 62830f8ce46Smrg while test "X$1" != 'X--mode=compile'; do 629bbe1b32bSmrg shift 630bbe1b32bSmrg done 631bbe1b32bSmrg shift 632bbe1b32bSmrg fi 633bbe1b32bSmrg # X makedepend 634bbe1b32bSmrg shift 63530f8ce46Smrg cleared=no eat=no 63630f8ce46Smrg for arg 63730f8ce46Smrg do 638bbe1b32bSmrg case $cleared in 639bbe1b32bSmrg no) 640bbe1b32bSmrg set ""; shift 641bbe1b32bSmrg cleared=yes ;; 642bbe1b32bSmrg esac 64330f8ce46Smrg if test $eat = yes; then 64430f8ce46Smrg eat=no 64530f8ce46Smrg continue 64630f8ce46Smrg fi 647bbe1b32bSmrg case "$arg" in 648bbe1b32bSmrg -D*|-I*) 649bbe1b32bSmrg set fnord "$@" "$arg"; shift ;; 650bbe1b32bSmrg # Strip any option that makedepend may not understand. Remove 651bbe1b32bSmrg # the object too, otherwise makedepend will parse it as a source file. 65230f8ce46Smrg -arch) 65330f8ce46Smrg eat=yes ;; 654bbe1b32bSmrg -*|$object) 655bbe1b32bSmrg ;; 656bbe1b32bSmrg *) 657bbe1b32bSmrg set fnord "$@" "$arg"; shift ;; 658bbe1b32bSmrg esac 659bbe1b32bSmrg done 66030f8ce46Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661bbe1b32bSmrg touch "$tmpdepfile" 662bbe1b32bSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663bbe1b32bSmrg rm -f "$depfile" 66434f90d55Smrg # makedepend may prepend the VPATH from the source file name to the object. 66534f90d55Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66634f90d55Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6678f34cbf9Ssnj # Some versions of the HPUX 10.20 sed can't process the last invocation 6688f34cbf9Ssnj # correctly. Breaking it into two sed invocations is a workaround. 6698f34cbf9Ssnj sed '1,2d' "$tmpdepfile" \ 6708f34cbf9Ssnj | tr ' ' "$nl" \ 6718f34cbf9Ssnj | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6728f34cbf9Ssnj | sed -e 's/$/ :/' >> "$depfile" 673bbe1b32bSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674bbe1b32bSmrg ;; 675bbe1b32bSmrg 676bbe1b32bSmrgcpp) 677bbe1b32bSmrg # Important note: in order to support this mode, a compiler *must* 678bbe1b32bSmrg # always write the preprocessed file to stdout. 679bbe1b32bSmrg "$@" || exit $? 680bbe1b32bSmrg 681bbe1b32bSmrg # Remove the call to Libtool. 682bbe1b32bSmrg if test "$libtool" = yes; then 68330f8ce46Smrg while test "X$1" != 'X--mode=compile'; do 684bbe1b32bSmrg shift 685bbe1b32bSmrg done 686bbe1b32bSmrg shift 687bbe1b32bSmrg fi 688bbe1b32bSmrg 6898f34cbf9Ssnj # Remove '-o $object'. 690bbe1b32bSmrg IFS=" " 691bbe1b32bSmrg for arg 692bbe1b32bSmrg do 693bbe1b32bSmrg case $arg in 694bbe1b32bSmrg -o) 695bbe1b32bSmrg shift 696bbe1b32bSmrg ;; 697bbe1b32bSmrg $object) 698bbe1b32bSmrg shift 699bbe1b32bSmrg ;; 700bbe1b32bSmrg *) 701bbe1b32bSmrg set fnord "$@" "$arg" 702bbe1b32bSmrg shift # fnord 703bbe1b32bSmrg shift # $arg 704bbe1b32bSmrg ;; 705bbe1b32bSmrg esac 706bbe1b32bSmrg done 707bbe1b32bSmrg 7088f34cbf9Ssnj "$@" -E \ 7098f34cbf9Ssnj | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7108f34cbf9Ssnj -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7118f34cbf9Ssnj | sed '$ s: \\$::' > "$tmpdepfile" 712bbe1b32bSmrg rm -f "$depfile" 713bbe1b32bSmrg echo "$object : \\" > "$depfile" 714bbe1b32bSmrg cat < "$tmpdepfile" >> "$depfile" 715bbe1b32bSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716bbe1b32bSmrg rm -f "$tmpdepfile" 717bbe1b32bSmrg ;; 718bbe1b32bSmrg 719bbe1b32bSmrgmsvisualcpp) 720bbe1b32bSmrg # Important note: in order to support this mode, a compiler *must* 72130f8ce46Smrg # always write the preprocessed file to stdout. 722bbe1b32bSmrg "$@" || exit $? 72330f8ce46Smrg 72430f8ce46Smrg # Remove the call to Libtool. 72530f8ce46Smrg if test "$libtool" = yes; then 72630f8ce46Smrg while test "X$1" != 'X--mode=compile'; do 72730f8ce46Smrg shift 72830f8ce46Smrg done 72930f8ce46Smrg shift 73030f8ce46Smrg fi 73130f8ce46Smrg 732bbe1b32bSmrg IFS=" " 733bbe1b32bSmrg for arg 734bbe1b32bSmrg do 735bbe1b32bSmrg case "$arg" in 73630f8ce46Smrg -o) 73730f8ce46Smrg shift 73830f8ce46Smrg ;; 73930f8ce46Smrg $object) 74030f8ce46Smrg shift 74130f8ce46Smrg ;; 742bbe1b32bSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7438f34cbf9Ssnj set fnord "$@" 7448f34cbf9Ssnj shift 7458f34cbf9Ssnj shift 7468f34cbf9Ssnj ;; 747bbe1b32bSmrg *) 7488f34cbf9Ssnj set fnord "$@" "$arg" 7498f34cbf9Ssnj shift 7508f34cbf9Ssnj shift 7518f34cbf9Ssnj ;; 752bbe1b32bSmrg esac 753bbe1b32bSmrg done 75430f8ce46Smrg "$@" -E 2>/dev/null | 75530f8ce46Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756bbe1b32bSmrg rm -f "$depfile" 757bbe1b32bSmrg echo "$object : \\" > "$depfile" 7588f34cbf9Ssnj sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7598f34cbf9Ssnj echo "$tab" >> "$depfile" 76030f8ce46Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761bbe1b32bSmrg rm -f "$tmpdepfile" 762bbe1b32bSmrg ;; 763bbe1b32bSmrg 76430f8ce46Smrgmsvcmsys) 76530f8ce46Smrg # This case exists only to let depend.m4 do its work. It works by 76630f8ce46Smrg # looking at the text of this script. This case will never be run, 76730f8ce46Smrg # since it is checked for above. 76830f8ce46Smrg exit 1 76930f8ce46Smrg ;; 77030f8ce46Smrg 771bbe1b32bSmrgnone) 772bbe1b32bSmrg exec "$@" 773bbe1b32bSmrg ;; 774bbe1b32bSmrg 775bbe1b32bSmrg*) 776bbe1b32bSmrg echo "Unknown depmode $depmode" 1>&2 777bbe1b32bSmrg exit 1 778bbe1b32bSmrg ;; 779bbe1b32bSmrgesac 780bbe1b32bSmrg 781bbe1b32bSmrgexit 0 782bbe1b32bSmrg 783bbe1b32bSmrg# Local Variables: 784bbe1b32bSmrg# mode: shell-script 785bbe1b32bSmrg# sh-indentation: 2 786bbe1b32bSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 787bbe1b32bSmrg# time-stamp-start: "scriptversion=" 788bbe1b32bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78930f8ce46Smrg# time-stamp-time-zone: "UTC" 79030f8ce46Smrg# time-stamp-end: "; # UTC" 791bbe1b32bSmrg# End: 792