depcomp revision e1db7cd1
1bbe1b32bSmrg#! /bin/sh 2bbe1b32bSmrg# depcomp - compile a program generating dependencies as side-effects 3bbe1b32bSmrg 4e1db7cd1Smrgscriptversion=2024-06-19.01; # UTC 5bbe1b32bSmrg 6e1db7cd1Smrg# Copyright (C) 1999-2024 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 1976028eb6Smrg# along with this program. If not, see <https://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>. 50e1db7cd1SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 51e1db7cd1SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 52bbe1b32bSmrgEOF 53bbe1b32bSmrg exit $? 54bbe1b32bSmrg ;; 55bbe1b32bSmrg -v | --v*) 56e1db7cd1Smrg echo "depcomp (GNU Automake) $scriptversion" 57bbe1b32bSmrg exit $? 58bbe1b32bSmrg ;; 59bbe1b32bSmrgesac 60bbe1b32bSmrg 618f34cbf9Ssnj# Get the directory component of the given path, and save it in the 628f34cbf9Ssnj# global variables '$dir'. Note that this directory component will 638f34cbf9Ssnj# be either empty or ending with a '/' character. This is deliberate. 648f34cbf9Ssnjset_dir_from () 658f34cbf9Ssnj{ 668f34cbf9Ssnj case $1 in 678f34cbf9Ssnj */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 688f34cbf9Ssnj *) dir=;; 698f34cbf9Ssnj esac 708f34cbf9Ssnj} 718f34cbf9Ssnj 728f34cbf9Ssnj# Get the suffix-stripped basename of the given path, and save it the 738f34cbf9Ssnj# global variable '$base'. 748f34cbf9Ssnjset_base_from () 758f34cbf9Ssnj{ 768f34cbf9Ssnj base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 778f34cbf9Ssnj} 788f34cbf9Ssnj 798f34cbf9Ssnj# If no dependency file was actually created by the compiler invocation, 808f34cbf9Ssnj# we still have to create a dummy depfile, to avoid errors with the 818f34cbf9Ssnj# Makefile "include basename.Plo" scheme. 828f34cbf9Ssnjmake_dummy_depfile () 838f34cbf9Ssnj{ 848f34cbf9Ssnj echo "#dummy" > "$depfile" 858f34cbf9Ssnj} 868f34cbf9Ssnj 878f34cbf9Ssnj# Factor out some common post-processing of the generated depfile. 888f34cbf9Ssnj# Requires the auxiliary global variable '$tmpdepfile' to be set. 898f34cbf9Ssnjaix_post_process_depfile () 908f34cbf9Ssnj{ 918f34cbf9Ssnj # If the compiler actually managed to produce a dependency file, 928f34cbf9Ssnj # post-process it. 938f34cbf9Ssnj if test -f "$tmpdepfile"; then 948f34cbf9Ssnj # Each line is of the form 'foo.o: dependency.h'. 958f34cbf9Ssnj # Do two passes, one to just change these to 968f34cbf9Ssnj # $object: dependency.h 978f34cbf9Ssnj # and one to simply output 988f34cbf9Ssnj # dependency.h: 998f34cbf9Ssnj # which is needed to avoid the deleted-header problem. 1008f34cbf9Ssnj { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 1018f34cbf9Ssnj sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1028f34cbf9Ssnj } > "$depfile" 1038f34cbf9Ssnj rm -f "$tmpdepfile" 1048f34cbf9Ssnj else 1058f34cbf9Ssnj make_dummy_depfile 1068f34cbf9Ssnj fi 1078f34cbf9Ssnj} 1088f34cbf9Ssnj 1098f34cbf9Ssnj# A tabulation character. 1108f34cbf9Ssnjtab=' ' 1118f34cbf9Ssnj# A newline character. 1128f34cbf9Ssnjnl=' 1138f34cbf9Ssnj' 1148f34cbf9Ssnj# Character ranges might be problematic outside the C locale. 1158f34cbf9Ssnj# These definitions help. 1168f34cbf9Ssnjupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1178f34cbf9Ssnjlower=abcdefghijklmnopqrstuvwxyz 1188f34cbf9Ssnjalpha=${upper}${lower} 1198f34cbf9Ssnj 120bbe1b32bSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 121bbe1b32bSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 122bbe1b32bSmrg exit 1 123bbe1b32bSmrgfi 124bbe1b32bSmrg 125bbe1b32bSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 126bbe1b32bSmrgdepfile=${depfile-`echo "$object" | 127bbe1b32bSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 128bbe1b32bSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 129bbe1b32bSmrg 130bbe1b32bSmrgrm -f "$tmpdepfile" 131bbe1b32bSmrg 132e1db7cd1Smrg# Avoid interference from the environment. 1338f34cbf9Ssnjgccflag= dashmflag= 1348f34cbf9Ssnj 135bbe1b32bSmrg# Some modes work just like other modes, but use different flags. We 136bbe1b32bSmrg# parameterize here, but still list the modes in the big case below, 137bbe1b32bSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 138bbe1b32bSmrg# here, because this file can only contain one case statement. 139bbe1b32bSmrgif test "$depmode" = hp; then 140bbe1b32bSmrg # HP compiler uses -M and no extra arg. 141bbe1b32bSmrg gccflag=-M 142bbe1b32bSmrg depmode=gcc 143bbe1b32bSmrgfi 144bbe1b32bSmrg 145bbe1b32bSmrgif test "$depmode" = dashXmstdout; then 1468f34cbf9Ssnj # This is just like dashmstdout with a different argument. 1478f34cbf9Ssnj dashmflag=-xM 1488f34cbf9Ssnj depmode=dashmstdout 149bbe1b32bSmrgfi 150bbe1b32bSmrg 15130f8ce46Smrgcygpath_u="cygpath -u -f -" 15230f8ce46Smrgif test "$depmode" = msvcmsys; then 1538f34cbf9Ssnj # This is just like msvisualcpp but w/o cygpath translation. 1548f34cbf9Ssnj # Just convert the backslash-escaped backslashes to single forward 1558f34cbf9Ssnj # slashes to satisfy depend.m4 1568f34cbf9Ssnj cygpath_u='sed s,\\\\,/,g' 1578f34cbf9Ssnj depmode=msvisualcpp 15830f8ce46Smrgfi 15930f8ce46Smrg 16034f90d55Smrgif test "$depmode" = msvc7msys; then 1618f34cbf9Ssnj # This is just like msvc7 but w/o cygpath translation. 1628f34cbf9Ssnj # Just convert the backslash-escaped backslashes to single forward 1638f34cbf9Ssnj # slashes to satisfy depend.m4 1648f34cbf9Ssnj cygpath_u='sed s,\\\\,/,g' 1658f34cbf9Ssnj depmode=msvc7 1668f34cbf9Ssnjfi 1678f34cbf9Ssnj 1688f34cbf9Ssnjif test "$depmode" = xlc; then 1698f34cbf9Ssnj # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1708f34cbf9Ssnj gccflag=-qmakedep=gcc,-MF 1718f34cbf9Ssnj depmode=gcc 17234f90d55Smrgfi 17334f90d55Smrg 174bbe1b32bSmrgcase "$depmode" in 175bbe1b32bSmrggcc3) 176bbe1b32bSmrg## gcc 3 implements dependency tracking that does exactly what 177bbe1b32bSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 178bbe1b32bSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 179ce6676dbSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 180ce6676dbSmrg## the command line argument order; so add the flags where they 181ce6676dbSmrg## appear in depend2.am. Note that the slowdown incurred here 182ce6676dbSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 183ce6676dbSmrg for arg 184ce6676dbSmrg do 185ce6676dbSmrg case $arg in 186ce6676dbSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 187ce6676dbSmrg *) set fnord "$@" "$arg" ;; 188ce6676dbSmrg esac 189ce6676dbSmrg shift # fnord 190ce6676dbSmrg shift # $arg 191ce6676dbSmrg done 192ce6676dbSmrg "$@" 193bbe1b32bSmrg stat=$? 1948f34cbf9Ssnj if test $stat -ne 0; then 195bbe1b32bSmrg rm -f "$tmpdepfile" 196bbe1b32bSmrg exit $stat 197bbe1b32bSmrg fi 198bbe1b32bSmrg mv "$tmpdepfile" "$depfile" 199bbe1b32bSmrg ;; 200bbe1b32bSmrg 201bbe1b32bSmrggcc) 202e1db7cd1Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 203e1db7cd1Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 2048f34cbf9Ssnj## (see the conditional assignment to $gccflag above). 205bbe1b32bSmrg## There are various ways to get dependency output from gcc. Here's 206bbe1b32bSmrg## why we pick this rather obscure method: 207bbe1b32bSmrg## - Don't want to use -MD because we'd like the dependencies to end 208bbe1b32bSmrg## up in a subdir. Having to rename by hand is ugly. 209bbe1b32bSmrg## (We might end up doing this anyway to support other compilers.) 210bbe1b32bSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2118f34cbf9Ssnj## -MM, not -M (despite what the docs say). Also, it might not be 2128f34cbf9Ssnj## supported by the other compilers which use the 'gcc' depmode. 213bbe1b32bSmrg## - Using -M directly means running the compiler twice (even worse 214bbe1b32bSmrg## than renaming). 215bbe1b32bSmrg if test -z "$gccflag"; then 216bbe1b32bSmrg gccflag=-MD, 217bbe1b32bSmrg fi 218bbe1b32bSmrg "$@" -Wp,"$gccflag$tmpdepfile" 219bbe1b32bSmrg stat=$? 2208f34cbf9Ssnj if test $stat -ne 0; then 221bbe1b32bSmrg rm -f "$tmpdepfile" 222bbe1b32bSmrg exit $stat 223bbe1b32bSmrg fi 224bbe1b32bSmrg rm -f "$depfile" 225bbe1b32bSmrg echo "$object : \\" > "$depfile" 2268f34cbf9Ssnj # The second -e expression handles DOS-style file names with drive 2278f34cbf9Ssnj # letters. 228bbe1b32bSmrg sed -e 's/^[^:]*: / /' \ 229bbe1b32bSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2308f34cbf9Ssnj## This next piece of magic avoids the "deleted header file" problem. 231bbe1b32bSmrg## The problem is that when a header file which appears in a .P file 232bbe1b32bSmrg## is deleted, the dependency causes make to die (because there is 233bbe1b32bSmrg## typically no way to rebuild the header). We avoid this by adding 234bbe1b32bSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 235bbe1b32bSmrg## this for us directly. 2368f34cbf9Ssnj## Some versions of gcc put a space before the ':'. On the theory 237bbe1b32bSmrg## that the space means something, we add a space to the output as 23834f90d55Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23934f90d55Smrg## to the object. Take care to not repeat it in the output. 240bbe1b32bSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 241bbe1b32bSmrg## correctly. Breaking it into two sed invocations is a workaround. 2428f34cbf9Ssnj tr ' ' "$nl" < "$tmpdepfile" \ 2438f34cbf9Ssnj | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2448f34cbf9Ssnj | sed -e 's/$/ :/' >> "$depfile" 245bbe1b32bSmrg rm -f "$tmpdepfile" 246bbe1b32bSmrg ;; 247bbe1b32bSmrg 248bbe1b32bSmrghp) 249bbe1b32bSmrg # This case exists only to let depend.m4 do its work. It works by 250bbe1b32bSmrg # looking at the text of this script. This case will never be run, 251bbe1b32bSmrg # since it is checked for above. 252bbe1b32bSmrg exit 1 253bbe1b32bSmrg ;; 254bbe1b32bSmrg 255bbe1b32bSmrgsgi) 256bbe1b32bSmrg if test "$libtool" = yes; then 257bbe1b32bSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 258bbe1b32bSmrg else 259bbe1b32bSmrg "$@" -MDupdate "$tmpdepfile" 260bbe1b32bSmrg fi 261bbe1b32bSmrg stat=$? 2628f34cbf9Ssnj if test $stat -ne 0; then 263bbe1b32bSmrg rm -f "$tmpdepfile" 264bbe1b32bSmrg exit $stat 265bbe1b32bSmrg fi 266bbe1b32bSmrg rm -f "$depfile" 267bbe1b32bSmrg 268bbe1b32bSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 269bbe1b32bSmrg echo "$object : \\" > "$depfile" 270bbe1b32bSmrg # Clip off the initial element (the dependent). Don't try to be 271bbe1b32bSmrg # clever and replace this with sed code, as IRIX sed won't handle 272bbe1b32bSmrg # lines with more than a fixed number of characters (4096 in 273bbe1b32bSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2748f34cbf9Ssnj # the IRIX cc adds comments like '#:fec' to the end of the 275bbe1b32bSmrg # dependency line. 2768f34cbf9Ssnj tr ' ' "$nl" < "$tmpdepfile" \ 2778f34cbf9Ssnj | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2788f34cbf9Ssnj | tr "$nl" ' ' >> "$depfile" 27930f8ce46Smrg echo >> "$depfile" 280bbe1b32bSmrg # The second pass generates a dummy entry for each header file. 2818f34cbf9Ssnj tr ' ' "$nl" < "$tmpdepfile" \ 2828f34cbf9Ssnj | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2838f34cbf9Ssnj >> "$depfile" 284bbe1b32bSmrg else 2858f34cbf9Ssnj make_dummy_depfile 286bbe1b32bSmrg fi 287bbe1b32bSmrg rm -f "$tmpdepfile" 288bbe1b32bSmrg ;; 289bbe1b32bSmrg 2908f34cbf9Ssnjxlc) 2918f34cbf9Ssnj # This case exists only to let depend.m4 do its work. It works by 2928f34cbf9Ssnj # looking at the text of this script. This case will never be run, 2938f34cbf9Ssnj # since it is checked for above. 2948f34cbf9Ssnj exit 1 2958f34cbf9Ssnj ;; 2968f34cbf9Ssnj 297bbe1b32bSmrgaix) 298bbe1b32bSmrg # The C for AIX Compiler uses -M and outputs the dependencies 299bbe1b32bSmrg # in a .u file. In older versions, this file always lives in the 3008f34cbf9Ssnj # current directory. Also, the AIX compiler puts '$object:' at the 301bbe1b32bSmrg # start of each line; $object doesn't have directory information. 302bbe1b32bSmrg # Version 6 uses the directory in both cases. 3038f34cbf9Ssnj set_dir_from "$object" 3048f34cbf9Ssnj set_base_from "$object" 305bbe1b32bSmrg if test "$libtool" = yes; then 30630f8ce46Smrg tmpdepfile1=$dir$base.u 30730f8ce46Smrg tmpdepfile2=$base.u 30830f8ce46Smrg tmpdepfile3=$dir.libs/$base.u 309bbe1b32bSmrg "$@" -Wc,-M 310bbe1b32bSmrg else 31130f8ce46Smrg tmpdepfile1=$dir$base.u 31230f8ce46Smrg tmpdepfile2=$dir$base.u 31330f8ce46Smrg tmpdepfile3=$dir$base.u 314bbe1b32bSmrg "$@" -M 315bbe1b32bSmrg fi 316bbe1b32bSmrg stat=$? 3178f34cbf9Ssnj if test $stat -ne 0; then 31830f8ce46Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 319bbe1b32bSmrg exit $stat 320bbe1b32bSmrg fi 321bbe1b32bSmrg 32230f8ce46Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32330f8ce46Smrg do 32430f8ce46Smrg test -f "$tmpdepfile" && break 32530f8ce46Smrg done 3268f34cbf9Ssnj aix_post_process_depfile 3278f34cbf9Ssnj ;; 3288f34cbf9Ssnj 3298f34cbf9Ssnjtcc) 3308f34cbf9Ssnj # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3318f34cbf9Ssnj # FIXME: That version still under development at the moment of writing. 3328f34cbf9Ssnj # Make that this statement remains true also for stable, released 3338f34cbf9Ssnj # versions. 3348f34cbf9Ssnj # It will wrap lines (doesn't matter whether long or short) with a 3358f34cbf9Ssnj # trailing '\', as in: 3368f34cbf9Ssnj # 3378f34cbf9Ssnj # foo.o : \ 3388f34cbf9Ssnj # foo.c \ 3398f34cbf9Ssnj # foo.h \ 3408f34cbf9Ssnj # 3418f34cbf9Ssnj # It will put a trailing '\' even on the last line, and will use leading 3428f34cbf9Ssnj # spaces rather than leading tabs (at least since its commit 0394caf7 3438f34cbf9Ssnj # "Emit spaces for -MD"). 3448f34cbf9Ssnj "$@" -MD -MF "$tmpdepfile" 3458f34cbf9Ssnj stat=$? 3468f34cbf9Ssnj if test $stat -ne 0; then 3478f34cbf9Ssnj rm -f "$tmpdepfile" 3488f34cbf9Ssnj exit $stat 349bbe1b32bSmrg fi 3508f34cbf9Ssnj rm -f "$depfile" 3518f34cbf9Ssnj # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3528f34cbf9Ssnj # We have to change lines of the first kind to '$object: \'. 3538f34cbf9Ssnj sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3548f34cbf9Ssnj # And for each line of the second kind, we have to emit a 'dep.h:' 3558f34cbf9Ssnj # dummy dependency, to avoid the deleted-header problem. 3568f34cbf9Ssnj sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 357bbe1b32bSmrg rm -f "$tmpdepfile" 358bbe1b32bSmrg ;; 359bbe1b32bSmrg 3608f34cbf9Ssnj## The order of this option in the case statement is important, since the 3618f34cbf9Ssnj## shell code in configure will try each of these formats in the order 3628f34cbf9Ssnj## listed in this file. A plain '-MD' option would be understood by many 3638f34cbf9Ssnj## compilers, so we must ensure this comes after the gcc and icc options. 3648f34cbf9Ssnjpgcc) 3658f34cbf9Ssnj # Portland's C compiler understands '-MD'. 3668f34cbf9Ssnj # Will always output deps to 'file.d' where file is the root name of the 3678f34cbf9Ssnj # source file under compilation, even if file resides in a subdirectory. 3688f34cbf9Ssnj # The object file name does not affect the name of the '.d' file. 3698f34cbf9Ssnj # pgcc 10.2 will output 370bbe1b32bSmrg # foo.o: sub/foo.c sub/foo.h 3718f34cbf9Ssnj # and will wrap long lines using '\' : 372bbe1b32bSmrg # foo.o: sub/foo.c ... \ 373bbe1b32bSmrg # sub/foo.h ... \ 374bbe1b32bSmrg # ... 3758f34cbf9Ssnj set_dir_from "$object" 3768f34cbf9Ssnj # Use the source, not the object, to determine the base name, since 3778f34cbf9Ssnj # that's sadly what pgcc will do too. 3788f34cbf9Ssnj set_base_from "$source" 3798f34cbf9Ssnj tmpdepfile=$base.d 3808f34cbf9Ssnj 3818f34cbf9Ssnj # For projects that build the same source file twice into different object 3828f34cbf9Ssnj # files, the pgcc approach of using the *source* file root name can cause 3838f34cbf9Ssnj # problems in parallel builds. Use a locking strategy to avoid stomping on 3848f34cbf9Ssnj # the same $tmpdepfile. 3858f34cbf9Ssnj lockdir=$base.d-lock 3868f34cbf9Ssnj trap " 3878f34cbf9Ssnj echo '$0: caught signal, cleaning up...' >&2 3888f34cbf9Ssnj rmdir '$lockdir' 3898f34cbf9Ssnj exit 1 3908f34cbf9Ssnj " 1 2 13 15 3918f34cbf9Ssnj numtries=100 3928f34cbf9Ssnj i=$numtries 3938f34cbf9Ssnj while test $i -gt 0; do 3948f34cbf9Ssnj # mkdir is a portable test-and-set. 3958f34cbf9Ssnj if mkdir "$lockdir" 2>/dev/null; then 3968f34cbf9Ssnj # This process acquired the lock. 3978f34cbf9Ssnj "$@" -MD 3988f34cbf9Ssnj stat=$? 3998f34cbf9Ssnj # Release the lock. 4008f34cbf9Ssnj rmdir "$lockdir" 4018f34cbf9Ssnj break 4028f34cbf9Ssnj else 4038f34cbf9Ssnj # If the lock is being held by a different process, wait 4048f34cbf9Ssnj # until the winning process is done or we timeout. 4058f34cbf9Ssnj while test -d "$lockdir" && test $i -gt 0; do 4068f34cbf9Ssnj sleep 1 4078f34cbf9Ssnj i=`expr $i - 1` 4088f34cbf9Ssnj done 4098f34cbf9Ssnj fi 4108f34cbf9Ssnj i=`expr $i - 1` 4118f34cbf9Ssnj done 4128f34cbf9Ssnj trap - 1 2 13 15 4138f34cbf9Ssnj if test $i -le 0; then 4148f34cbf9Ssnj echo "$0: failed to acquire lock after $numtries attempts" >&2 4158f34cbf9Ssnj echo "$0: check lockdir '$lockdir'" >&2 4168f34cbf9Ssnj exit 1 4178f34cbf9Ssnj fi 418bbe1b32bSmrg 4198f34cbf9Ssnj if test $stat -ne 0; then 420bbe1b32bSmrg rm -f "$tmpdepfile" 421bbe1b32bSmrg exit $stat 422bbe1b32bSmrg fi 423bbe1b32bSmrg rm -f "$depfile" 424bbe1b32bSmrg # Each line is of the form `foo.o: dependent.h', 425bbe1b32bSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 426bbe1b32bSmrg # Do two passes, one to just change these to 427bbe1b32bSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 428bbe1b32bSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 429bbe1b32bSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 430bbe1b32bSmrg # correctly. Breaking it into two sed invocations is a workaround. 4318f34cbf9Ssnj sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4328f34cbf9Ssnj | sed -e 's/$/ :/' >> "$depfile" 433bbe1b32bSmrg rm -f "$tmpdepfile" 434bbe1b32bSmrg ;; 435bbe1b32bSmrg 436ce6676dbSmrghp2) 437ce6676dbSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 438ce6676dbSmrg # compilers, which have integrated preprocessors. The correct option 439ce6676dbSmrg # to use with these is +Maked; it writes dependencies to a file named 440ce6676dbSmrg # 'foo.d', which lands next to the object file, wherever that 441ce6676dbSmrg # happens to be. 442ce6676dbSmrg # Much of this is similar to the tru64 case; see comments there. 4438f34cbf9Ssnj set_dir_from "$object" 4448f34cbf9Ssnj set_base_from "$object" 445ce6676dbSmrg if test "$libtool" = yes; then 446ce6676dbSmrg tmpdepfile1=$dir$base.d 447ce6676dbSmrg tmpdepfile2=$dir.libs/$base.d 448ce6676dbSmrg "$@" -Wc,+Maked 449ce6676dbSmrg else 450ce6676dbSmrg tmpdepfile1=$dir$base.d 451ce6676dbSmrg tmpdepfile2=$dir$base.d 452ce6676dbSmrg "$@" +Maked 453ce6676dbSmrg fi 454ce6676dbSmrg stat=$? 4558f34cbf9Ssnj if test $stat -ne 0; then 456ce6676dbSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 457ce6676dbSmrg exit $stat 458ce6676dbSmrg fi 459ce6676dbSmrg 460ce6676dbSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 461ce6676dbSmrg do 462ce6676dbSmrg test -f "$tmpdepfile" && break 463ce6676dbSmrg done 464ce6676dbSmrg if test -f "$tmpdepfile"; then 4658f34cbf9Ssnj sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4668f34cbf9Ssnj # Add 'dependent.h:' lines. 46730f8ce46Smrg sed -ne '2,${ 4688f34cbf9Ssnj s/^ *// 4698f34cbf9Ssnj s/ \\*$// 4708f34cbf9Ssnj s/$/:/ 4718f34cbf9Ssnj p 4728f34cbf9Ssnj }' "$tmpdepfile" >> "$depfile" 473ce6676dbSmrg else 4748f34cbf9Ssnj make_dummy_depfile 475ce6676dbSmrg fi 476ce6676dbSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 477ce6676dbSmrg ;; 478ce6676dbSmrg 479bbe1b32bSmrgtru64) 4808f34cbf9Ssnj # The Tru64 compiler uses -MD to generate dependencies as a side 4818f34cbf9Ssnj # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4828f34cbf9Ssnj # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4838f34cbf9Ssnj # dependencies in 'foo.d' instead, so we check for that too. 4848f34cbf9Ssnj # Subdirectories are respected. 4858f34cbf9Ssnj set_dir_from "$object" 4868f34cbf9Ssnj set_base_from "$object" 4878f34cbf9Ssnj 4888f34cbf9Ssnj if test "$libtool" = yes; then 4898f34cbf9Ssnj # Libtool generates 2 separate objects for the 2 libraries. These 4908f34cbf9Ssnj # two compilations output dependencies in $dir.libs/$base.o.d and 4918f34cbf9Ssnj # in $dir$base.o.d. We have to check for both files, because 4928f34cbf9Ssnj # one of the two compilations can be disabled. We should prefer 4938f34cbf9Ssnj # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4948f34cbf9Ssnj # automatically cleaned when .libs/ is deleted, while ignoring 4958f34cbf9Ssnj # the former would cause a distcleancheck panic. 4968f34cbf9Ssnj tmpdepfile1=$dir$base.o.d # libtool 1.5 4978f34cbf9Ssnj tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4988f34cbf9Ssnj tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4998f34cbf9Ssnj "$@" -Wc,-MD 5008f34cbf9Ssnj else 5018f34cbf9Ssnj tmpdepfile1=$dir$base.d 5028f34cbf9Ssnj tmpdepfile2=$dir$base.d 5038f34cbf9Ssnj tmpdepfile3=$dir$base.d 5048f34cbf9Ssnj "$@" -MD 5058f34cbf9Ssnj fi 5068f34cbf9Ssnj 5078f34cbf9Ssnj stat=$? 5088f34cbf9Ssnj if test $stat -ne 0; then 5098f34cbf9Ssnj rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5108f34cbf9Ssnj exit $stat 5118f34cbf9Ssnj fi 5128f34cbf9Ssnj 5138f34cbf9Ssnj for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5148f34cbf9Ssnj do 5158f34cbf9Ssnj test -f "$tmpdepfile" && break 5168f34cbf9Ssnj done 5178f34cbf9Ssnj # Same post-processing that is required for AIX mode. 5188f34cbf9Ssnj aix_post_process_depfile 5198f34cbf9Ssnj ;; 520bbe1b32bSmrg 52134f90d55Smrgmsvc7) 52234f90d55Smrg if test "$libtool" = yes; then 52334f90d55Smrg showIncludes=-Wc,-showIncludes 52434f90d55Smrg else 52534f90d55Smrg showIncludes=-showIncludes 52634f90d55Smrg fi 52734f90d55Smrg "$@" $showIncludes > "$tmpdepfile" 52834f90d55Smrg stat=$? 52934f90d55Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5308f34cbf9Ssnj if test $stat -ne 0; then 53134f90d55Smrg rm -f "$tmpdepfile" 53234f90d55Smrg exit $stat 53334f90d55Smrg fi 53434f90d55Smrg rm -f "$depfile" 53534f90d55Smrg echo "$object : \\" > "$depfile" 53634f90d55Smrg # The first sed program below extracts the file names and escapes 53734f90d55Smrg # backslashes for cygpath. The second sed program outputs the file 53834f90d55Smrg # name when reading, but also accumulates all include files in the 53934f90d55Smrg # hold buffer in order to output them again at the end. This only 54034f90d55Smrg # works with sed implementations that can handle large buffers. 54134f90d55Smrg sed < "$tmpdepfile" -n ' 54234f90d55Smrg/^Note: including file: *\(.*\)/ { 54334f90d55Smrg s//\1/ 54434f90d55Smrg s/\\/\\\\/g 54534f90d55Smrg p 54634f90d55Smrg}' | $cygpath_u | sort -u | sed -n ' 54734f90d55Smrgs/ /\\ /g 5488f34cbf9Ssnjs/\(.*\)/'"$tab"'\1 \\/p 54934f90d55Smrgs/.\(.*\) \\/\1:/ 55034f90d55SmrgH 55134f90d55Smrg$ { 5528f34cbf9Ssnj s/.*/'"$tab"'/ 55334f90d55Smrg G 55434f90d55Smrg p 55534f90d55Smrg}' >> "$depfile" 5568f34cbf9Ssnj echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55734f90d55Smrg rm -f "$tmpdepfile" 55834f90d55Smrg ;; 55934f90d55Smrg 56034f90d55Smrgmsvc7msys) 56134f90d55Smrg # This case exists only to let depend.m4 do its work. It works by 56234f90d55Smrg # looking at the text of this script. This case will never be run, 56334f90d55Smrg # since it is checked for above. 56434f90d55Smrg exit 1 56534f90d55Smrg ;; 56634f90d55Smrg 567bbe1b32bSmrg#nosideeffect) 568bbe1b32bSmrg # This comment above is used by automake to tell side-effect 569bbe1b32bSmrg # dependency tracking mechanisms from slower ones. 570bbe1b32bSmrg 571bbe1b32bSmrgdashmstdout) 572bbe1b32bSmrg # Important note: in order to support this mode, a compiler *must* 573bbe1b32bSmrg # always write the preprocessed file to stdout, regardless of -o. 574bbe1b32bSmrg "$@" || exit $? 575bbe1b32bSmrg 576bbe1b32bSmrg # Remove the call to Libtool. 577bbe1b32bSmrg if test "$libtool" = yes; then 57830f8ce46Smrg while test "X$1" != 'X--mode=compile'; do 579bbe1b32bSmrg shift 580bbe1b32bSmrg done 581bbe1b32bSmrg shift 582bbe1b32bSmrg fi 583bbe1b32bSmrg 5848f34cbf9Ssnj # Remove '-o $object'. 585bbe1b32bSmrg IFS=" " 586bbe1b32bSmrg for arg 587bbe1b32bSmrg do 588bbe1b32bSmrg case $arg in 589bbe1b32bSmrg -o) 590bbe1b32bSmrg shift 591bbe1b32bSmrg ;; 592bbe1b32bSmrg $object) 593bbe1b32bSmrg shift 594bbe1b32bSmrg ;; 595bbe1b32bSmrg *) 596bbe1b32bSmrg set fnord "$@" "$arg" 597bbe1b32bSmrg shift # fnord 598bbe1b32bSmrg shift # $arg 599bbe1b32bSmrg ;; 600bbe1b32bSmrg esac 601bbe1b32bSmrg done 602bbe1b32bSmrg 603bbe1b32bSmrg test -z "$dashmflag" && dashmflag=-M 6048f34cbf9Ssnj # Require at least two characters before searching for ':' 605bbe1b32bSmrg # in the target name. This is to cope with DOS-style filenames: 6068f34cbf9Ssnj # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 607bbe1b32bSmrg "$@" $dashmflag | 6088f34cbf9Ssnj sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 609bbe1b32bSmrg rm -f "$depfile" 610bbe1b32bSmrg cat < "$tmpdepfile" > "$depfile" 6118f34cbf9Ssnj # Some versions of the HPUX 10.20 sed can't process this sed invocation 6128f34cbf9Ssnj # correctly. Breaking it into two sed invocations is a workaround. 6138f34cbf9Ssnj tr ' ' "$nl" < "$tmpdepfile" \ 6148f34cbf9Ssnj | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6158f34cbf9Ssnj | sed -e 's/$/ :/' >> "$depfile" 616bbe1b32bSmrg rm -f "$tmpdepfile" 617bbe1b32bSmrg ;; 618bbe1b32bSmrg 619bbe1b32bSmrgdashXmstdout) 620bbe1b32bSmrg # This case only exists to satisfy depend.m4. It is never actually 621bbe1b32bSmrg # run, as this mode is specially recognized in the preamble. 622bbe1b32bSmrg exit 1 623bbe1b32bSmrg ;; 624bbe1b32bSmrg 625bbe1b32bSmrgmakedepend) 626bbe1b32bSmrg "$@" || exit $? 627bbe1b32bSmrg # Remove any Libtool call 628bbe1b32bSmrg if test "$libtool" = yes; then 62930f8ce46Smrg while test "X$1" != 'X--mode=compile'; do 630bbe1b32bSmrg shift 631bbe1b32bSmrg done 632bbe1b32bSmrg shift 633bbe1b32bSmrg fi 634bbe1b32bSmrg # X makedepend 635bbe1b32bSmrg shift 63630f8ce46Smrg cleared=no eat=no 63730f8ce46Smrg for arg 63830f8ce46Smrg do 639bbe1b32bSmrg case $cleared in 640bbe1b32bSmrg no) 641bbe1b32bSmrg set ""; shift 642bbe1b32bSmrg cleared=yes ;; 643bbe1b32bSmrg esac 64430f8ce46Smrg if test $eat = yes; then 64530f8ce46Smrg eat=no 64630f8ce46Smrg continue 64730f8ce46Smrg fi 648bbe1b32bSmrg case "$arg" in 649bbe1b32bSmrg -D*|-I*) 650bbe1b32bSmrg set fnord "$@" "$arg"; shift ;; 651bbe1b32bSmrg # Strip any option that makedepend may not understand. Remove 652bbe1b32bSmrg # the object too, otherwise makedepend will parse it as a source file. 65330f8ce46Smrg -arch) 65430f8ce46Smrg eat=yes ;; 655bbe1b32bSmrg -*|$object) 656bbe1b32bSmrg ;; 657bbe1b32bSmrg *) 658bbe1b32bSmrg set fnord "$@" "$arg"; shift ;; 659bbe1b32bSmrg esac 660bbe1b32bSmrg done 66130f8ce46Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 662bbe1b32bSmrg touch "$tmpdepfile" 663bbe1b32bSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 664bbe1b32bSmrg rm -f "$depfile" 66534f90d55Smrg # makedepend may prepend the VPATH from the source file name to the object. 66634f90d55Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66734f90d55Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6688f34cbf9Ssnj # Some versions of the HPUX 10.20 sed can't process the last invocation 6698f34cbf9Ssnj # correctly. Breaking it into two sed invocations is a workaround. 6708f34cbf9Ssnj sed '1,2d' "$tmpdepfile" \ 6718f34cbf9Ssnj | tr ' ' "$nl" \ 6728f34cbf9Ssnj | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6738f34cbf9Ssnj | sed -e 's/$/ :/' >> "$depfile" 674bbe1b32bSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 675bbe1b32bSmrg ;; 676bbe1b32bSmrg 677bbe1b32bSmrgcpp) 678bbe1b32bSmrg # Important note: in order to support this mode, a compiler *must* 679bbe1b32bSmrg # always write the preprocessed file to stdout. 680bbe1b32bSmrg "$@" || exit $? 681bbe1b32bSmrg 682bbe1b32bSmrg # Remove the call to Libtool. 683bbe1b32bSmrg if test "$libtool" = yes; then 68430f8ce46Smrg while test "X$1" != 'X--mode=compile'; do 685bbe1b32bSmrg shift 686bbe1b32bSmrg done 687bbe1b32bSmrg shift 688bbe1b32bSmrg fi 689bbe1b32bSmrg 6908f34cbf9Ssnj # Remove '-o $object'. 691bbe1b32bSmrg IFS=" " 692bbe1b32bSmrg for arg 693bbe1b32bSmrg do 694bbe1b32bSmrg case $arg in 695bbe1b32bSmrg -o) 696bbe1b32bSmrg shift 697bbe1b32bSmrg ;; 698bbe1b32bSmrg $object) 699bbe1b32bSmrg shift 700bbe1b32bSmrg ;; 701bbe1b32bSmrg *) 702bbe1b32bSmrg set fnord "$@" "$arg" 703bbe1b32bSmrg shift # fnord 704bbe1b32bSmrg shift # $arg 705bbe1b32bSmrg ;; 706bbe1b32bSmrg esac 707bbe1b32bSmrg done 708bbe1b32bSmrg 7098f34cbf9Ssnj "$@" -E \ 7108f34cbf9Ssnj | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7118f34cbf9Ssnj -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7128f34cbf9Ssnj | sed '$ s: \\$::' > "$tmpdepfile" 713bbe1b32bSmrg rm -f "$depfile" 714bbe1b32bSmrg echo "$object : \\" > "$depfile" 715bbe1b32bSmrg cat < "$tmpdepfile" >> "$depfile" 716bbe1b32bSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 717bbe1b32bSmrg rm -f "$tmpdepfile" 718bbe1b32bSmrg ;; 719bbe1b32bSmrg 720bbe1b32bSmrgmsvisualcpp) 721bbe1b32bSmrg # Important note: in order to support this mode, a compiler *must* 72230f8ce46Smrg # always write the preprocessed file to stdout. 723bbe1b32bSmrg "$@" || exit $? 72430f8ce46Smrg 72530f8ce46Smrg # Remove the call to Libtool. 72630f8ce46Smrg if test "$libtool" = yes; then 72730f8ce46Smrg while test "X$1" != 'X--mode=compile'; do 72830f8ce46Smrg shift 72930f8ce46Smrg done 73030f8ce46Smrg shift 73130f8ce46Smrg fi 73230f8ce46Smrg 733bbe1b32bSmrg IFS=" " 734bbe1b32bSmrg for arg 735bbe1b32bSmrg do 736bbe1b32bSmrg case "$arg" in 73730f8ce46Smrg -o) 73830f8ce46Smrg shift 73930f8ce46Smrg ;; 74030f8ce46Smrg $object) 74130f8ce46Smrg shift 74230f8ce46Smrg ;; 743bbe1b32bSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7448f34cbf9Ssnj set fnord "$@" 7458f34cbf9Ssnj shift 7468f34cbf9Ssnj shift 7478f34cbf9Ssnj ;; 748bbe1b32bSmrg *) 7498f34cbf9Ssnj set fnord "$@" "$arg" 7508f34cbf9Ssnj shift 7518f34cbf9Ssnj shift 7528f34cbf9Ssnj ;; 753bbe1b32bSmrg esac 754bbe1b32bSmrg done 75530f8ce46Smrg "$@" -E 2>/dev/null | 75630f8ce46Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 757bbe1b32bSmrg rm -f "$depfile" 758bbe1b32bSmrg echo "$object : \\" > "$depfile" 7598f34cbf9Ssnj sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7608f34cbf9Ssnj echo "$tab" >> "$depfile" 76130f8ce46Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 762bbe1b32bSmrg rm -f "$tmpdepfile" 763bbe1b32bSmrg ;; 764bbe1b32bSmrg 76530f8ce46Smrgmsvcmsys) 76630f8ce46Smrg # This case exists only to let depend.m4 do its work. It works by 76730f8ce46Smrg # looking at the text of this script. This case will never be run, 76830f8ce46Smrg # since it is checked for above. 76930f8ce46Smrg exit 1 77030f8ce46Smrg ;; 77130f8ce46Smrg 772bbe1b32bSmrgnone) 773bbe1b32bSmrg exec "$@" 774bbe1b32bSmrg ;; 775bbe1b32bSmrg 776bbe1b32bSmrg*) 777bbe1b32bSmrg echo "Unknown depmode $depmode" 1>&2 778bbe1b32bSmrg exit 1 779bbe1b32bSmrg ;; 780bbe1b32bSmrgesac 781bbe1b32bSmrg 782bbe1b32bSmrgexit 0 783bbe1b32bSmrg 784bbe1b32bSmrg# Local Variables: 785bbe1b32bSmrg# mode: shell-script 786bbe1b32bSmrg# sh-indentation: 2 78776028eb6Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 788bbe1b32bSmrg# time-stamp-start: "scriptversion=" 789bbe1b32bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 79040c5823bSmrg# time-stamp-time-zone: "UTC0" 79130f8ce46Smrg# time-stamp-end: "; # UTC" 792bbe1b32bSmrg# End: 793