14e179ddaSchristos#! /bin/sh 24e179ddaSchristos# depcomp - compile a program generating dependencies as side-effects 34e179ddaSchristos 4*8f3b9483Schristosscriptversion=2016-01-11.22; # UTC 54e179ddaSchristos 6*8f3b9483Schristos# Copyright (C) 1999-2017 Free Software Foundation, Inc. 74e179ddaSchristos 84e179ddaSchristos# This program is free software; you can redistribute it and/or modify 94e179ddaSchristos# it under the terms of the GNU General Public License as published by 104e179ddaSchristos# the Free Software Foundation; either version 2, or (at your option) 114e179ddaSchristos# any later version. 124e179ddaSchristos 134e179ddaSchristos# This program is distributed in the hope that it will be useful, 144e179ddaSchristos# but WITHOUT ANY WARRANTY; without even the implied warranty of 154e179ddaSchristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 164e179ddaSchristos# GNU General Public License for more details. 174e179ddaSchristos 184e179ddaSchristos# You should have received a copy of the GNU General Public License 194e179ddaSchristos# along with this program. If not, see <http://www.gnu.org/licenses/>. 204e179ddaSchristos 214e179ddaSchristos# As a special exception to the GNU General Public License, if you 224e179ddaSchristos# distribute this file as part of a program that contains a 234e179ddaSchristos# configuration script generated by Autoconf, you may include it under 244e179ddaSchristos# the same distribution terms that you use for the rest of that program. 254e179ddaSchristos 264e179ddaSchristos# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 274e179ddaSchristos 284e179ddaSchristoscase $1 in 294e179ddaSchristos '') 304e179ddaSchristos echo "$0: No command. Try '$0 --help' for more information." 1>&2 314e179ddaSchristos exit 1; 324e179ddaSchristos ;; 334e179ddaSchristos -h | --h*) 344e179ddaSchristos cat <<\EOF 354e179ddaSchristosUsage: depcomp [--help] [--version] PROGRAM [ARGS] 364e179ddaSchristos 374e179ddaSchristosRun PROGRAMS ARGS to compile a file, generating dependencies 384e179ddaSchristosas side-effects. 394e179ddaSchristos 404e179ddaSchristosEnvironment variables: 414e179ddaSchristos depmode Dependency tracking mode. 424e179ddaSchristos source Source file read by 'PROGRAMS ARGS'. 434e179ddaSchristos object Object file output by 'PROGRAMS ARGS'. 444e179ddaSchristos DEPDIR directory where to store dependencies. 454e179ddaSchristos depfile Dependency file to output. 464e179ddaSchristos tmpdepfile Temporary file to use when outputting dependencies. 474e179ddaSchristos libtool Whether libtool is used (yes/no). 484e179ddaSchristos 494e179ddaSchristosReport bugs to <bug-automake@gnu.org>. 504e179ddaSchristosEOF 514e179ddaSchristos exit $? 524e179ddaSchristos ;; 534e179ddaSchristos -v | --v*) 544e179ddaSchristos echo "depcomp $scriptversion" 554e179ddaSchristos exit $? 564e179ddaSchristos ;; 574e179ddaSchristosesac 584e179ddaSchristos 594e179ddaSchristos# Get the directory component of the given path, and save it in the 604e179ddaSchristos# global variables '$dir'. Note that this directory component will 614e179ddaSchristos# be either empty or ending with a '/' character. This is deliberate. 624e179ddaSchristosset_dir_from () 634e179ddaSchristos{ 644e179ddaSchristos case $1 in 654e179ddaSchristos */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 664e179ddaSchristos *) dir=;; 674e179ddaSchristos esac 684e179ddaSchristos} 694e179ddaSchristos 704e179ddaSchristos# Get the suffix-stripped basename of the given path, and save it the 714e179ddaSchristos# global variable '$base'. 724e179ddaSchristosset_base_from () 734e179ddaSchristos{ 744e179ddaSchristos base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 754e179ddaSchristos} 764e179ddaSchristos 774e179ddaSchristos# If no dependency file was actually created by the compiler invocation, 784e179ddaSchristos# we still have to create a dummy depfile, to avoid errors with the 794e179ddaSchristos# Makefile "include basename.Plo" scheme. 804e179ddaSchristosmake_dummy_depfile () 814e179ddaSchristos{ 824e179ddaSchristos echo "#dummy" > "$depfile" 834e179ddaSchristos} 844e179ddaSchristos 854e179ddaSchristos# Factor out some common post-processing of the generated depfile. 864e179ddaSchristos# Requires the auxiliary global variable '$tmpdepfile' to be set. 874e179ddaSchristosaix_post_process_depfile () 884e179ddaSchristos{ 894e179ddaSchristos # If the compiler actually managed to produce a dependency file, 904e179ddaSchristos # post-process it. 914e179ddaSchristos if test -f "$tmpdepfile"; then 924e179ddaSchristos # Each line is of the form 'foo.o: dependency.h'. 934e179ddaSchristos # Do two passes, one to just change these to 944e179ddaSchristos # $object: dependency.h 954e179ddaSchristos # and one to simply output 964e179ddaSchristos # dependency.h: 974e179ddaSchristos # which is needed to avoid the deleted-header problem. 984e179ddaSchristos { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 994e179ddaSchristos sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1004e179ddaSchristos } > "$depfile" 1014e179ddaSchristos rm -f "$tmpdepfile" 1024e179ddaSchristos else 1034e179ddaSchristos make_dummy_depfile 1044e179ddaSchristos fi 1054e179ddaSchristos} 1064e179ddaSchristos 1074e179ddaSchristos# A tabulation character. 1084e179ddaSchristostab=' ' 1094e179ddaSchristos# A newline character. 1104e179ddaSchristosnl=' 1114e179ddaSchristos' 1124e179ddaSchristos# Character ranges might be problematic outside the C locale. 1134e179ddaSchristos# These definitions help. 1144e179ddaSchristosupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1154e179ddaSchristoslower=abcdefghijklmnopqrstuvwxyz 1164e179ddaSchristosdigits=0123456789 1174e179ddaSchristosalpha=${upper}${lower} 1184e179ddaSchristos 1194e179ddaSchristosif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1204e179ddaSchristos echo "depcomp: Variables source, object and depmode must be set" 1>&2 1214e179ddaSchristos exit 1 1224e179ddaSchristosfi 1234e179ddaSchristos 1244e179ddaSchristos# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1254e179ddaSchristosdepfile=${depfile-`echo "$object" | 1264e179ddaSchristos sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1274e179ddaSchristostmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1284e179ddaSchristos 1294e179ddaSchristosrm -f "$tmpdepfile" 1304e179ddaSchristos 1314e179ddaSchristos# Avoid interferences from the environment. 1324e179ddaSchristosgccflag= dashmflag= 1334e179ddaSchristos 1344e179ddaSchristos# Some modes work just like other modes, but use different flags. We 1354e179ddaSchristos# parameterize here, but still list the modes in the big case below, 1364e179ddaSchristos# to make depend.m4 easier to write. Note that we *cannot* use a case 1374e179ddaSchristos# here, because this file can only contain one case statement. 1384e179ddaSchristosif test "$depmode" = hp; then 1394e179ddaSchristos # HP compiler uses -M and no extra arg. 1404e179ddaSchristos gccflag=-M 1414e179ddaSchristos depmode=gcc 1424e179ddaSchristosfi 1434e179ddaSchristos 1444e179ddaSchristosif test "$depmode" = dashXmstdout; then 1454e179ddaSchristos # This is just like dashmstdout with a different argument. 1464e179ddaSchristos dashmflag=-xM 1474e179ddaSchristos depmode=dashmstdout 1484e179ddaSchristosfi 1494e179ddaSchristos 1504e179ddaSchristoscygpath_u="cygpath -u -f -" 1514e179ddaSchristosif test "$depmode" = msvcmsys; then 1524e179ddaSchristos # This is just like msvisualcpp but w/o cygpath translation. 1534e179ddaSchristos # Just convert the backslash-escaped backslashes to single forward 1544e179ddaSchristos # slashes to satisfy depend.m4 1554e179ddaSchristos cygpath_u='sed s,\\\\,/,g' 1564e179ddaSchristos depmode=msvisualcpp 1574e179ddaSchristosfi 1584e179ddaSchristos 1594e179ddaSchristosif test "$depmode" = msvc7msys; then 1604e179ddaSchristos # This is just like msvc7 but w/o cygpath translation. 1614e179ddaSchristos # Just convert the backslash-escaped backslashes to single forward 1624e179ddaSchristos # slashes to satisfy depend.m4 1634e179ddaSchristos cygpath_u='sed s,\\\\,/,g' 1644e179ddaSchristos depmode=msvc7 1654e179ddaSchristosfi 1664e179ddaSchristos 1674e179ddaSchristosif test "$depmode" = xlc; then 1684e179ddaSchristos # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1694e179ddaSchristos gccflag=-qmakedep=gcc,-MF 1704e179ddaSchristos depmode=gcc 1714e179ddaSchristosfi 1724e179ddaSchristos 1734e179ddaSchristoscase "$depmode" in 1744e179ddaSchristosgcc3) 1754e179ddaSchristos## gcc 3 implements dependency tracking that does exactly what 1764e179ddaSchristos## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1774e179ddaSchristos## it if -MD -MP comes after the -MF stuff. Hmm. 1784e179ddaSchristos## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1794e179ddaSchristos## the command line argument order; so add the flags where they 1804e179ddaSchristos## appear in depend2.am. Note that the slowdown incurred here 1814e179ddaSchristos## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1824e179ddaSchristos for arg 1834e179ddaSchristos do 1844e179ddaSchristos case $arg in 1854e179ddaSchristos -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1864e179ddaSchristos *) set fnord "$@" "$arg" ;; 1874e179ddaSchristos esac 1884e179ddaSchristos shift # fnord 1894e179ddaSchristos shift # $arg 1904e179ddaSchristos done 1914e179ddaSchristos "$@" 1924e179ddaSchristos stat=$? 1934e179ddaSchristos if test $stat -ne 0; then 1944e179ddaSchristos rm -f "$tmpdepfile" 1954e179ddaSchristos exit $stat 1964e179ddaSchristos fi 1974e179ddaSchristos mv "$tmpdepfile" "$depfile" 1984e179ddaSchristos ;; 1994e179ddaSchristos 2004e179ddaSchristosgcc) 2014e179ddaSchristos## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2024e179ddaSchristos## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2034e179ddaSchristos## (see the conditional assignment to $gccflag above). 2044e179ddaSchristos## There are various ways to get dependency output from gcc. Here's 2054e179ddaSchristos## why we pick this rather obscure method: 2064e179ddaSchristos## - Don't want to use -MD because we'd like the dependencies to end 2074e179ddaSchristos## up in a subdir. Having to rename by hand is ugly. 2084e179ddaSchristos## (We might end up doing this anyway to support other compilers.) 2094e179ddaSchristos## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2104e179ddaSchristos## -MM, not -M (despite what the docs say). Also, it might not be 2114e179ddaSchristos## supported by the other compilers which use the 'gcc' depmode. 2124e179ddaSchristos## - Using -M directly means running the compiler twice (even worse 2134e179ddaSchristos## than renaming). 2144e179ddaSchristos if test -z "$gccflag"; then 2154e179ddaSchristos gccflag=-MD, 2164e179ddaSchristos fi 2174e179ddaSchristos "$@" -Wp,"$gccflag$tmpdepfile" 2184e179ddaSchristos stat=$? 2194e179ddaSchristos if test $stat -ne 0; then 2204e179ddaSchristos rm -f "$tmpdepfile" 2214e179ddaSchristos exit $stat 2224e179ddaSchristos fi 2234e179ddaSchristos rm -f "$depfile" 2244e179ddaSchristos echo "$object : \\" > "$depfile" 2254e179ddaSchristos # The second -e expression handles DOS-style file names with drive 2264e179ddaSchristos # letters. 2274e179ddaSchristos sed -e 's/^[^:]*: / /' \ 2284e179ddaSchristos -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2294e179ddaSchristos## This next piece of magic avoids the "deleted header file" problem. 2304e179ddaSchristos## The problem is that when a header file which appears in a .P file 2314e179ddaSchristos## is deleted, the dependency causes make to die (because there is 2324e179ddaSchristos## typically no way to rebuild the header). We avoid this by adding 2334e179ddaSchristos## dummy dependencies for each header file. Too bad gcc doesn't do 2344e179ddaSchristos## this for us directly. 2354e179ddaSchristos## Some versions of gcc put a space before the ':'. On the theory 2364e179ddaSchristos## that the space means something, we add a space to the output as 2374e179ddaSchristos## well. hp depmode also adds that space, but also prefixes the VPATH 2384e179ddaSchristos## to the object. Take care to not repeat it in the output. 2394e179ddaSchristos## Some versions of the HPUX 10.20 sed can't process this invocation 2404e179ddaSchristos## correctly. Breaking it into two sed invocations is a workaround. 2414e179ddaSchristos tr ' ' "$nl" < "$tmpdepfile" \ 2424e179ddaSchristos | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2434e179ddaSchristos | sed -e 's/$/ :/' >> "$depfile" 2444e179ddaSchristos rm -f "$tmpdepfile" 2454e179ddaSchristos ;; 2464e179ddaSchristos 2474e179ddaSchristoshp) 2484e179ddaSchristos # This case exists only to let depend.m4 do its work. It works by 2494e179ddaSchristos # looking at the text of this script. This case will never be run, 2504e179ddaSchristos # since it is checked for above. 2514e179ddaSchristos exit 1 2524e179ddaSchristos ;; 2534e179ddaSchristos 2544e179ddaSchristossgi) 2554e179ddaSchristos if test "$libtool" = yes; then 2564e179ddaSchristos "$@" "-Wp,-MDupdate,$tmpdepfile" 2574e179ddaSchristos else 2584e179ddaSchristos "$@" -MDupdate "$tmpdepfile" 2594e179ddaSchristos fi 2604e179ddaSchristos stat=$? 2614e179ddaSchristos if test $stat -ne 0; then 2624e179ddaSchristos rm -f "$tmpdepfile" 2634e179ddaSchristos exit $stat 2644e179ddaSchristos fi 2654e179ddaSchristos rm -f "$depfile" 2664e179ddaSchristos 2674e179ddaSchristos if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2684e179ddaSchristos echo "$object : \\" > "$depfile" 2694e179ddaSchristos # Clip off the initial element (the dependent). Don't try to be 2704e179ddaSchristos # clever and replace this with sed code, as IRIX sed won't handle 2714e179ddaSchristos # lines with more than a fixed number of characters (4096 in 2724e179ddaSchristos # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2734e179ddaSchristos # the IRIX cc adds comments like '#:fec' to the end of the 2744e179ddaSchristos # dependency line. 2754e179ddaSchristos tr ' ' "$nl" < "$tmpdepfile" \ 2764e179ddaSchristos | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2774e179ddaSchristos | tr "$nl" ' ' >> "$depfile" 2784e179ddaSchristos echo >> "$depfile" 2794e179ddaSchristos # The second pass generates a dummy entry for each header file. 2804e179ddaSchristos tr ' ' "$nl" < "$tmpdepfile" \ 2814e179ddaSchristos | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2824e179ddaSchristos >> "$depfile" 2834e179ddaSchristos else 2844e179ddaSchristos make_dummy_depfile 2854e179ddaSchristos fi 2864e179ddaSchristos rm -f "$tmpdepfile" 2874e179ddaSchristos ;; 2884e179ddaSchristos 2894e179ddaSchristosxlc) 2904e179ddaSchristos # This case exists only to let depend.m4 do its work. It works by 2914e179ddaSchristos # looking at the text of this script. This case will never be run, 2924e179ddaSchristos # since it is checked for above. 2934e179ddaSchristos exit 1 2944e179ddaSchristos ;; 2954e179ddaSchristos 2964e179ddaSchristosaix) 2974e179ddaSchristos # The C for AIX Compiler uses -M and outputs the dependencies 2984e179ddaSchristos # in a .u file. In older versions, this file always lives in the 2994e179ddaSchristos # current directory. Also, the AIX compiler puts '$object:' at the 3004e179ddaSchristos # start of each line; $object doesn't have directory information. 3014e179ddaSchristos # Version 6 uses the directory in both cases. 3024e179ddaSchristos set_dir_from "$object" 3034e179ddaSchristos set_base_from "$object" 3044e179ddaSchristos if test "$libtool" = yes; then 3054e179ddaSchristos tmpdepfile1=$dir$base.u 3064e179ddaSchristos tmpdepfile2=$base.u 3074e179ddaSchristos tmpdepfile3=$dir.libs/$base.u 3084e179ddaSchristos "$@" -Wc,-M 3094e179ddaSchristos else 3104e179ddaSchristos tmpdepfile1=$dir$base.u 3114e179ddaSchristos tmpdepfile2=$dir$base.u 3124e179ddaSchristos tmpdepfile3=$dir$base.u 3134e179ddaSchristos "$@" -M 3144e179ddaSchristos fi 3154e179ddaSchristos stat=$? 3164e179ddaSchristos if test $stat -ne 0; then 3174e179ddaSchristos rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3184e179ddaSchristos exit $stat 3194e179ddaSchristos fi 3204e179ddaSchristos 3214e179ddaSchristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3224e179ddaSchristos do 3234e179ddaSchristos test -f "$tmpdepfile" && break 3244e179ddaSchristos done 3254e179ddaSchristos aix_post_process_depfile 3264e179ddaSchristos ;; 3274e179ddaSchristos 3284e179ddaSchristostcc) 3294e179ddaSchristos # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3304e179ddaSchristos # FIXME: That version still under development at the moment of writing. 3314e179ddaSchristos # Make that this statement remains true also for stable, released 3324e179ddaSchristos # versions. 3334e179ddaSchristos # It will wrap lines (doesn't matter whether long or short) with a 3344e179ddaSchristos # trailing '\', as in: 3354e179ddaSchristos # 3364e179ddaSchristos # foo.o : \ 3374e179ddaSchristos # foo.c \ 3384e179ddaSchristos # foo.h \ 3394e179ddaSchristos # 3404e179ddaSchristos # It will put a trailing '\' even on the last line, and will use leading 3414e179ddaSchristos # spaces rather than leading tabs (at least since its commit 0394caf7 3424e179ddaSchristos # "Emit spaces for -MD"). 3434e179ddaSchristos "$@" -MD -MF "$tmpdepfile" 3444e179ddaSchristos stat=$? 3454e179ddaSchristos if test $stat -ne 0; then 3464e179ddaSchristos rm -f "$tmpdepfile" 3474e179ddaSchristos exit $stat 3484e179ddaSchristos fi 3494e179ddaSchristos rm -f "$depfile" 3504e179ddaSchristos # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3514e179ddaSchristos # We have to change lines of the first kind to '$object: \'. 3524e179ddaSchristos sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3534e179ddaSchristos # And for each line of the second kind, we have to emit a 'dep.h:' 3544e179ddaSchristos # dummy dependency, to avoid the deleted-header problem. 3554e179ddaSchristos sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3564e179ddaSchristos rm -f "$tmpdepfile" 3574e179ddaSchristos ;; 3584e179ddaSchristos 3594e179ddaSchristos## The order of this option in the case statement is important, since the 3604e179ddaSchristos## shell code in configure will try each of these formats in the order 3614e179ddaSchristos## listed in this file. A plain '-MD' option would be understood by many 3624e179ddaSchristos## compilers, so we must ensure this comes after the gcc and icc options. 3634e179ddaSchristospgcc) 3644e179ddaSchristos # Portland's C compiler understands '-MD'. 3654e179ddaSchristos # Will always output deps to 'file.d' where file is the root name of the 3664e179ddaSchristos # source file under compilation, even if file resides in a subdirectory. 3674e179ddaSchristos # The object file name does not affect the name of the '.d' file. 3684e179ddaSchristos # pgcc 10.2 will output 3694e179ddaSchristos # foo.o: sub/foo.c sub/foo.h 3704e179ddaSchristos # and will wrap long lines using '\' : 3714e179ddaSchristos # foo.o: sub/foo.c ... \ 3724e179ddaSchristos # sub/foo.h ... \ 3734e179ddaSchristos # ... 3744e179ddaSchristos set_dir_from "$object" 3754e179ddaSchristos # Use the source, not the object, to determine the base name, since 3764e179ddaSchristos # that's sadly what pgcc will do too. 3774e179ddaSchristos set_base_from "$source" 3784e179ddaSchristos tmpdepfile=$base.d 3794e179ddaSchristos 3804e179ddaSchristos # For projects that build the same source file twice into different object 3814e179ddaSchristos # files, the pgcc approach of using the *source* file root name can cause 3824e179ddaSchristos # problems in parallel builds. Use a locking strategy to avoid stomping on 3834e179ddaSchristos # the same $tmpdepfile. 3844e179ddaSchristos lockdir=$base.d-lock 3854e179ddaSchristos trap " 3864e179ddaSchristos echo '$0: caught signal, cleaning up...' >&2 3874e179ddaSchristos rmdir '$lockdir' 3884e179ddaSchristos exit 1 3894e179ddaSchristos " 1 2 13 15 3904e179ddaSchristos numtries=100 3914e179ddaSchristos i=$numtries 3924e179ddaSchristos while test $i -gt 0; do 3934e179ddaSchristos # mkdir is a portable test-and-set. 3944e179ddaSchristos if mkdir "$lockdir" 2>/dev/null; then 3954e179ddaSchristos # This process acquired the lock. 3964e179ddaSchristos "$@" -MD 3974e179ddaSchristos stat=$? 3984e179ddaSchristos # Release the lock. 3994e179ddaSchristos rmdir "$lockdir" 4004e179ddaSchristos break 4014e179ddaSchristos else 4024e179ddaSchristos # If the lock is being held by a different process, wait 4034e179ddaSchristos # until the winning process is done or we timeout. 4044e179ddaSchristos while test -d "$lockdir" && test $i -gt 0; do 4054e179ddaSchristos sleep 1 4064e179ddaSchristos i=`expr $i - 1` 4074e179ddaSchristos done 4084e179ddaSchristos fi 4094e179ddaSchristos i=`expr $i - 1` 4104e179ddaSchristos done 4114e179ddaSchristos trap - 1 2 13 15 4124e179ddaSchristos if test $i -le 0; then 4134e179ddaSchristos echo "$0: failed to acquire lock after $numtries attempts" >&2 4144e179ddaSchristos echo "$0: check lockdir '$lockdir'" >&2 4154e179ddaSchristos exit 1 4164e179ddaSchristos fi 4174e179ddaSchristos 4184e179ddaSchristos if test $stat -ne 0; then 4194e179ddaSchristos rm -f "$tmpdepfile" 4204e179ddaSchristos exit $stat 4214e179ddaSchristos fi 4224e179ddaSchristos rm -f "$depfile" 4234e179ddaSchristos # Each line is of the form `foo.o: dependent.h', 4244e179ddaSchristos # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4254e179ddaSchristos # Do two passes, one to just change these to 4264e179ddaSchristos # `$object: dependent.h' and one to simply `dependent.h:'. 4274e179ddaSchristos sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4284e179ddaSchristos # Some versions of the HPUX 10.20 sed can't process this invocation 4294e179ddaSchristos # correctly. Breaking it into two sed invocations is a workaround. 4304e179ddaSchristos sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4314e179ddaSchristos | sed -e 's/$/ :/' >> "$depfile" 4324e179ddaSchristos rm -f "$tmpdepfile" 4334e179ddaSchristos ;; 4344e179ddaSchristos 4354e179ddaSchristoshp2) 4364e179ddaSchristos # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4374e179ddaSchristos # compilers, which have integrated preprocessors. The correct option 4384e179ddaSchristos # to use with these is +Maked; it writes dependencies to a file named 4394e179ddaSchristos # 'foo.d', which lands next to the object file, wherever that 4404e179ddaSchristos # happens to be. 4414e179ddaSchristos # Much of this is similar to the tru64 case; see comments there. 4424e179ddaSchristos set_dir_from "$object" 4434e179ddaSchristos set_base_from "$object" 4444e179ddaSchristos if test "$libtool" = yes; then 4454e179ddaSchristos tmpdepfile1=$dir$base.d 4464e179ddaSchristos tmpdepfile2=$dir.libs/$base.d 4474e179ddaSchristos "$@" -Wc,+Maked 4484e179ddaSchristos else 4494e179ddaSchristos tmpdepfile1=$dir$base.d 4504e179ddaSchristos tmpdepfile2=$dir$base.d 4514e179ddaSchristos "$@" +Maked 4524e179ddaSchristos fi 4534e179ddaSchristos stat=$? 4544e179ddaSchristos if test $stat -ne 0; then 4554e179ddaSchristos rm -f "$tmpdepfile1" "$tmpdepfile2" 4564e179ddaSchristos exit $stat 4574e179ddaSchristos fi 4584e179ddaSchristos 4594e179ddaSchristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4604e179ddaSchristos do 4614e179ddaSchristos test -f "$tmpdepfile" && break 4624e179ddaSchristos done 4634e179ddaSchristos if test -f "$tmpdepfile"; then 4644e179ddaSchristos sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4654e179ddaSchristos # Add 'dependent.h:' lines. 4664e179ddaSchristos sed -ne '2,${ 4674e179ddaSchristos s/^ *// 4684e179ddaSchristos s/ \\*$// 4694e179ddaSchristos s/$/:/ 4704e179ddaSchristos p 4714e179ddaSchristos }' "$tmpdepfile" >> "$depfile" 4724e179ddaSchristos else 4734e179ddaSchristos make_dummy_depfile 4744e179ddaSchristos fi 4754e179ddaSchristos rm -f "$tmpdepfile" "$tmpdepfile2" 4764e179ddaSchristos ;; 4774e179ddaSchristos 4784e179ddaSchristostru64) 4794e179ddaSchristos # The Tru64 compiler uses -MD to generate dependencies as a side 4804e179ddaSchristos # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4814e179ddaSchristos # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4824e179ddaSchristos # dependencies in 'foo.d' instead, so we check for that too. 4834e179ddaSchristos # Subdirectories are respected. 4844e179ddaSchristos set_dir_from "$object" 4854e179ddaSchristos set_base_from "$object" 4864e179ddaSchristos 4874e179ddaSchristos if test "$libtool" = yes; then 4884e179ddaSchristos # Libtool generates 2 separate objects for the 2 libraries. These 4894e179ddaSchristos # two compilations output dependencies in $dir.libs/$base.o.d and 4904e179ddaSchristos # in $dir$base.o.d. We have to check for both files, because 4914e179ddaSchristos # one of the two compilations can be disabled. We should prefer 4924e179ddaSchristos # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4934e179ddaSchristos # automatically cleaned when .libs/ is deleted, while ignoring 4944e179ddaSchristos # the former would cause a distcleancheck panic. 4954e179ddaSchristos tmpdepfile1=$dir$base.o.d # libtool 1.5 4964e179ddaSchristos tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4974e179ddaSchristos tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4984e179ddaSchristos "$@" -Wc,-MD 4994e179ddaSchristos else 5004e179ddaSchristos tmpdepfile1=$dir$base.d 5014e179ddaSchristos tmpdepfile2=$dir$base.d 5024e179ddaSchristos tmpdepfile3=$dir$base.d 5034e179ddaSchristos "$@" -MD 5044e179ddaSchristos fi 5054e179ddaSchristos 5064e179ddaSchristos stat=$? 5074e179ddaSchristos if test $stat -ne 0; then 5084e179ddaSchristos rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5094e179ddaSchristos exit $stat 5104e179ddaSchristos fi 5114e179ddaSchristos 5124e179ddaSchristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5134e179ddaSchristos do 5144e179ddaSchristos test -f "$tmpdepfile" && break 5154e179ddaSchristos done 5164e179ddaSchristos # Same post-processing that is required for AIX mode. 5174e179ddaSchristos aix_post_process_depfile 5184e179ddaSchristos ;; 5194e179ddaSchristos 5204e179ddaSchristosmsvc7) 5214e179ddaSchristos if test "$libtool" = yes; then 5224e179ddaSchristos showIncludes=-Wc,-showIncludes 5234e179ddaSchristos else 5244e179ddaSchristos showIncludes=-showIncludes 5254e179ddaSchristos fi 5264e179ddaSchristos "$@" $showIncludes > "$tmpdepfile" 5274e179ddaSchristos stat=$? 5284e179ddaSchristos grep -v '^Note: including file: ' "$tmpdepfile" 5294e179ddaSchristos if test $stat -ne 0; then 5304e179ddaSchristos rm -f "$tmpdepfile" 5314e179ddaSchristos exit $stat 5324e179ddaSchristos fi 5334e179ddaSchristos rm -f "$depfile" 5344e179ddaSchristos echo "$object : \\" > "$depfile" 5354e179ddaSchristos # The first sed program below extracts the file names and escapes 5364e179ddaSchristos # backslashes for cygpath. The second sed program outputs the file 5374e179ddaSchristos # name when reading, but also accumulates all include files in the 5384e179ddaSchristos # hold buffer in order to output them again at the end. This only 5394e179ddaSchristos # works with sed implementations that can handle large buffers. 5404e179ddaSchristos sed < "$tmpdepfile" -n ' 5414e179ddaSchristos/^Note: including file: *\(.*\)/ { 5424e179ddaSchristos s//\1/ 5434e179ddaSchristos s/\\/\\\\/g 5444e179ddaSchristos p 5454e179ddaSchristos}' | $cygpath_u | sort -u | sed -n ' 5464e179ddaSchristoss/ /\\ /g 5474e179ddaSchristoss/\(.*\)/'"$tab"'\1 \\/p 5484e179ddaSchristoss/.\(.*\) \\/\1:/ 5494e179ddaSchristosH 5504e179ddaSchristos$ { 5514e179ddaSchristos s/.*/'"$tab"'/ 5524e179ddaSchristos G 5534e179ddaSchristos p 5544e179ddaSchristos}' >> "$depfile" 5554e179ddaSchristos echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5564e179ddaSchristos rm -f "$tmpdepfile" 5574e179ddaSchristos ;; 5584e179ddaSchristos 5594e179ddaSchristosmsvc7msys) 5604e179ddaSchristos # This case exists only to let depend.m4 do its work. It works by 5614e179ddaSchristos # looking at the text of this script. This case will never be run, 5624e179ddaSchristos # since it is checked for above. 5634e179ddaSchristos exit 1 5644e179ddaSchristos ;; 5654e179ddaSchristos 5664e179ddaSchristos#nosideeffect) 5674e179ddaSchristos # This comment above is used by automake to tell side-effect 5684e179ddaSchristos # dependency tracking mechanisms from slower ones. 5694e179ddaSchristos 5704e179ddaSchristosdashmstdout) 5714e179ddaSchristos # Important note: in order to support this mode, a compiler *must* 5724e179ddaSchristos # always write the preprocessed file to stdout, regardless of -o. 5734e179ddaSchristos "$@" || exit $? 5744e179ddaSchristos 5754e179ddaSchristos # Remove the call to Libtool. 5764e179ddaSchristos if test "$libtool" = yes; then 5774e179ddaSchristos while test "X$1" != 'X--mode=compile'; do 5784e179ddaSchristos shift 5794e179ddaSchristos done 5804e179ddaSchristos shift 5814e179ddaSchristos fi 5824e179ddaSchristos 5834e179ddaSchristos # Remove '-o $object'. 5844e179ddaSchristos IFS=" " 5854e179ddaSchristos for arg 5864e179ddaSchristos do 5874e179ddaSchristos case $arg in 5884e179ddaSchristos -o) 5894e179ddaSchristos shift 5904e179ddaSchristos ;; 5914e179ddaSchristos $object) 5924e179ddaSchristos shift 5934e179ddaSchristos ;; 5944e179ddaSchristos *) 5954e179ddaSchristos set fnord "$@" "$arg" 5964e179ddaSchristos shift # fnord 5974e179ddaSchristos shift # $arg 5984e179ddaSchristos ;; 5994e179ddaSchristos esac 6004e179ddaSchristos done 6014e179ddaSchristos 6024e179ddaSchristos test -z "$dashmflag" && dashmflag=-M 6034e179ddaSchristos # Require at least two characters before searching for ':' 6044e179ddaSchristos # in the target name. This is to cope with DOS-style filenames: 6054e179ddaSchristos # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6064e179ddaSchristos "$@" $dashmflag | 6074e179ddaSchristos sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6084e179ddaSchristos rm -f "$depfile" 6094e179ddaSchristos cat < "$tmpdepfile" > "$depfile" 6104e179ddaSchristos # Some versions of the HPUX 10.20 sed can't process this sed invocation 6114e179ddaSchristos # correctly. Breaking it into two sed invocations is a workaround. 6124e179ddaSchristos tr ' ' "$nl" < "$tmpdepfile" \ 6134e179ddaSchristos | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6144e179ddaSchristos | sed -e 's/$/ :/' >> "$depfile" 6154e179ddaSchristos rm -f "$tmpdepfile" 6164e179ddaSchristos ;; 6174e179ddaSchristos 6184e179ddaSchristosdashXmstdout) 6194e179ddaSchristos # This case only exists to satisfy depend.m4. It is never actually 6204e179ddaSchristos # run, as this mode is specially recognized in the preamble. 6214e179ddaSchristos exit 1 6224e179ddaSchristos ;; 6234e179ddaSchristos 6244e179ddaSchristosmakedepend) 6254e179ddaSchristos "$@" || exit $? 6264e179ddaSchristos # Remove any Libtool call 6274e179ddaSchristos if test "$libtool" = yes; then 6284e179ddaSchristos while test "X$1" != 'X--mode=compile'; do 6294e179ddaSchristos shift 6304e179ddaSchristos done 6314e179ddaSchristos shift 6324e179ddaSchristos fi 6334e179ddaSchristos # X makedepend 6344e179ddaSchristos shift 6354e179ddaSchristos cleared=no eat=no 6364e179ddaSchristos for arg 6374e179ddaSchristos do 6384e179ddaSchristos case $cleared in 6394e179ddaSchristos no) 6404e179ddaSchristos set ""; shift 6414e179ddaSchristos cleared=yes ;; 6424e179ddaSchristos esac 6434e179ddaSchristos if test $eat = yes; then 6444e179ddaSchristos eat=no 6454e179ddaSchristos continue 6464e179ddaSchristos fi 6474e179ddaSchristos case "$arg" in 6484e179ddaSchristos -D*|-I*) 6494e179ddaSchristos set fnord "$@" "$arg"; shift ;; 6504e179ddaSchristos # Strip any option that makedepend may not understand. Remove 6514e179ddaSchristos # the object too, otherwise makedepend will parse it as a source file. 6524e179ddaSchristos -arch) 6534e179ddaSchristos eat=yes ;; 6544e179ddaSchristos -*|$object) 6554e179ddaSchristos ;; 6564e179ddaSchristos *) 6574e179ddaSchristos set fnord "$@" "$arg"; shift ;; 6584e179ddaSchristos esac 6594e179ddaSchristos done 6604e179ddaSchristos obj_suffix=`echo "$object" | sed 's/^.*\././'` 6614e179ddaSchristos touch "$tmpdepfile" 6624e179ddaSchristos ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6634e179ddaSchristos rm -f "$depfile" 6644e179ddaSchristos # makedepend may prepend the VPATH from the source file name to the object. 6654e179ddaSchristos # No need to regex-escape $object, excess matching of '.' is harmless. 6664e179ddaSchristos sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6674e179ddaSchristos # Some versions of the HPUX 10.20 sed can't process the last invocation 6684e179ddaSchristos # correctly. Breaking it into two sed invocations is a workaround. 6694e179ddaSchristos sed '1,2d' "$tmpdepfile" \ 6704e179ddaSchristos | tr ' ' "$nl" \ 6714e179ddaSchristos | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6724e179ddaSchristos | sed -e 's/$/ :/' >> "$depfile" 6734e179ddaSchristos rm -f "$tmpdepfile" "$tmpdepfile".bak 6744e179ddaSchristos ;; 6754e179ddaSchristos 6764e179ddaSchristoscpp) 6774e179ddaSchristos # Important note: in order to support this mode, a compiler *must* 6784e179ddaSchristos # always write the preprocessed file to stdout. 6794e179ddaSchristos "$@" || exit $? 6804e179ddaSchristos 6814e179ddaSchristos # Remove the call to Libtool. 6824e179ddaSchristos if test "$libtool" = yes; then 6834e179ddaSchristos while test "X$1" != 'X--mode=compile'; do 6844e179ddaSchristos shift 6854e179ddaSchristos done 6864e179ddaSchristos shift 6874e179ddaSchristos fi 6884e179ddaSchristos 6894e179ddaSchristos # Remove '-o $object'. 6904e179ddaSchristos IFS=" " 6914e179ddaSchristos for arg 6924e179ddaSchristos do 6934e179ddaSchristos case $arg in 6944e179ddaSchristos -o) 6954e179ddaSchristos shift 6964e179ddaSchristos ;; 6974e179ddaSchristos $object) 6984e179ddaSchristos shift 6994e179ddaSchristos ;; 7004e179ddaSchristos *) 7014e179ddaSchristos set fnord "$@" "$arg" 7024e179ddaSchristos shift # fnord 7034e179ddaSchristos shift # $arg 7044e179ddaSchristos ;; 7054e179ddaSchristos esac 7064e179ddaSchristos done 7074e179ddaSchristos 7084e179ddaSchristos "$@" -E \ 7094e179ddaSchristos | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7104e179ddaSchristos -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7114e179ddaSchristos | sed '$ s: \\$::' > "$tmpdepfile" 7124e179ddaSchristos rm -f "$depfile" 7134e179ddaSchristos echo "$object : \\" > "$depfile" 7144e179ddaSchristos cat < "$tmpdepfile" >> "$depfile" 7154e179ddaSchristos sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7164e179ddaSchristos rm -f "$tmpdepfile" 7174e179ddaSchristos ;; 7184e179ddaSchristos 7194e179ddaSchristosmsvisualcpp) 7204e179ddaSchristos # Important note: in order to support this mode, a compiler *must* 7214e179ddaSchristos # always write the preprocessed file to stdout. 7224e179ddaSchristos "$@" || exit $? 7234e179ddaSchristos 7244e179ddaSchristos # Remove the call to Libtool. 7254e179ddaSchristos if test "$libtool" = yes; then 7264e179ddaSchristos while test "X$1" != 'X--mode=compile'; do 7274e179ddaSchristos shift 7284e179ddaSchristos done 7294e179ddaSchristos shift 7304e179ddaSchristos fi 7314e179ddaSchristos 7324e179ddaSchristos IFS=" " 7334e179ddaSchristos for arg 7344e179ddaSchristos do 7354e179ddaSchristos case "$arg" in 7364e179ddaSchristos -o) 7374e179ddaSchristos shift 7384e179ddaSchristos ;; 7394e179ddaSchristos $object) 7404e179ddaSchristos shift 7414e179ddaSchristos ;; 7424e179ddaSchristos "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7434e179ddaSchristos set fnord "$@" 7444e179ddaSchristos shift 7454e179ddaSchristos shift 7464e179ddaSchristos ;; 7474e179ddaSchristos *) 7484e179ddaSchristos set fnord "$@" "$arg" 7494e179ddaSchristos shift 7504e179ddaSchristos shift 7514e179ddaSchristos ;; 7524e179ddaSchristos esac 7534e179ddaSchristos done 7544e179ddaSchristos "$@" -E 2>/dev/null | 7554e179ddaSchristos sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7564e179ddaSchristos rm -f "$depfile" 7574e179ddaSchristos echo "$object : \\" > "$depfile" 7584e179ddaSchristos sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7594e179ddaSchristos echo "$tab" >> "$depfile" 7604e179ddaSchristos sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7614e179ddaSchristos rm -f "$tmpdepfile" 7624e179ddaSchristos ;; 7634e179ddaSchristos 7644e179ddaSchristosmsvcmsys) 7654e179ddaSchristos # This case exists only to let depend.m4 do its work. It works by 7664e179ddaSchristos # looking at the text of this script. This case will never be run, 7674e179ddaSchristos # since it is checked for above. 7684e179ddaSchristos exit 1 7694e179ddaSchristos ;; 7704e179ddaSchristos 7714e179ddaSchristosnone) 7724e179ddaSchristos exec "$@" 7734e179ddaSchristos ;; 7744e179ddaSchristos 7754e179ddaSchristos*) 7764e179ddaSchristos echo "Unknown depmode $depmode" 1>&2 7774e179ddaSchristos exit 1 7784e179ddaSchristos ;; 7794e179ddaSchristosesac 7804e179ddaSchristos 7814e179ddaSchristosexit 0 7824e179ddaSchristos 7834e179ddaSchristos# Local Variables: 7844e179ddaSchristos# mode: shell-script 7854e179ddaSchristos# sh-indentation: 2 7864e179ddaSchristos# eval: (add-hook 'write-file-hooks 'time-stamp) 7874e179ddaSchristos# time-stamp-start: "scriptversion=" 7884e179ddaSchristos# time-stamp-format: "%:y-%02m-%02d.%02H" 789*8f3b9483Schristos# time-stamp-time-zone: "UTC0" 7904e179ddaSchristos# time-stamp-end: "; # UTC" 7914e179ddaSchristos# End: 792