1*a5a4af3bSchristos#! /bin/sh 2*a5a4af3bSchristos# depcomp - compile a program generating dependencies as side-effects 3*a5a4af3bSchristos 4*a5a4af3bSchristosscriptversion=2013-05-30.07; # UTC 5*a5a4af3bSchristos 6*a5a4af3bSchristos# Copyright (C) 1999-2014 Free Software Foundation, Inc. 7*a5a4af3bSchristos 8*a5a4af3bSchristos# This program is free software; you can redistribute it and/or modify 9*a5a4af3bSchristos# it under the terms of the GNU General Public License as published by 10*a5a4af3bSchristos# the Free Software Foundation; either version 2, or (at your option) 11*a5a4af3bSchristos# any later version. 12*a5a4af3bSchristos 13*a5a4af3bSchristos# This program is distributed in the hope that it will be useful, 14*a5a4af3bSchristos# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*a5a4af3bSchristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*a5a4af3bSchristos# GNU General Public License for more details. 17*a5a4af3bSchristos 18*a5a4af3bSchristos# You should have received a copy of the GNU General Public License 19*a5a4af3bSchristos# along with this program. If not, see <http://www.gnu.org/licenses/>. 20*a5a4af3bSchristos 21*a5a4af3bSchristos# As a special exception to the GNU General Public License, if you 22*a5a4af3bSchristos# distribute this file as part of a program that contains a 23*a5a4af3bSchristos# configuration script generated by Autoconf, you may include it under 24*a5a4af3bSchristos# the same distribution terms that you use for the rest of that program. 25*a5a4af3bSchristos 26*a5a4af3bSchristos# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27*a5a4af3bSchristos 28*a5a4af3bSchristoscase $1 in 29*a5a4af3bSchristos '') 30*a5a4af3bSchristos echo "$0: No command. Try '$0 --help' for more information." 1>&2 31*a5a4af3bSchristos exit 1; 32*a5a4af3bSchristos ;; 33*a5a4af3bSchristos -h | --h*) 34*a5a4af3bSchristos cat <<\EOF 35*a5a4af3bSchristosUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36*a5a4af3bSchristos 37*a5a4af3bSchristosRun PROGRAMS ARGS to compile a file, generating dependencies 38*a5a4af3bSchristosas side-effects. 39*a5a4af3bSchristos 40*a5a4af3bSchristosEnvironment variables: 41*a5a4af3bSchristos depmode Dependency tracking mode. 42*a5a4af3bSchristos source Source file read by 'PROGRAMS ARGS'. 43*a5a4af3bSchristos object Object file output by 'PROGRAMS ARGS'. 44*a5a4af3bSchristos DEPDIR directory where to store dependencies. 45*a5a4af3bSchristos depfile Dependency file to output. 46*a5a4af3bSchristos tmpdepfile Temporary file to use when outputting dependencies. 47*a5a4af3bSchristos libtool Whether libtool is used (yes/no). 48*a5a4af3bSchristos 49*a5a4af3bSchristosReport bugs to <bug-automake@gnu.org>. 50*a5a4af3bSchristosEOF 51*a5a4af3bSchristos exit $? 52*a5a4af3bSchristos ;; 53*a5a4af3bSchristos -v | --v*) 54*a5a4af3bSchristos echo "depcomp $scriptversion" 55*a5a4af3bSchristos exit $? 56*a5a4af3bSchristos ;; 57*a5a4af3bSchristosesac 58*a5a4af3bSchristos 59*a5a4af3bSchristos# Get the directory component of the given path, and save it in the 60*a5a4af3bSchristos# global variables '$dir'. Note that this directory component will 61*a5a4af3bSchristos# be either empty or ending with a '/' character. This is deliberate. 62*a5a4af3bSchristosset_dir_from () 63*a5a4af3bSchristos{ 64*a5a4af3bSchristos case $1 in 65*a5a4af3bSchristos */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66*a5a4af3bSchristos *) dir=;; 67*a5a4af3bSchristos esac 68*a5a4af3bSchristos} 69*a5a4af3bSchristos 70*a5a4af3bSchristos# Get the suffix-stripped basename of the given path, and save it the 71*a5a4af3bSchristos# global variable '$base'. 72*a5a4af3bSchristosset_base_from () 73*a5a4af3bSchristos{ 74*a5a4af3bSchristos base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75*a5a4af3bSchristos} 76*a5a4af3bSchristos 77*a5a4af3bSchristos# If no dependency file was actually created by the compiler invocation, 78*a5a4af3bSchristos# we still have to create a dummy depfile, to avoid errors with the 79*a5a4af3bSchristos# Makefile "include basename.Plo" scheme. 80*a5a4af3bSchristosmake_dummy_depfile () 81*a5a4af3bSchristos{ 82*a5a4af3bSchristos echo "#dummy" > "$depfile" 83*a5a4af3bSchristos} 84*a5a4af3bSchristos 85*a5a4af3bSchristos# Factor out some common post-processing of the generated depfile. 86*a5a4af3bSchristos# Requires the auxiliary global variable '$tmpdepfile' to be set. 87*a5a4af3bSchristosaix_post_process_depfile () 88*a5a4af3bSchristos{ 89*a5a4af3bSchristos # If the compiler actually managed to produce a dependency file, 90*a5a4af3bSchristos # post-process it. 91*a5a4af3bSchristos if test -f "$tmpdepfile"; then 92*a5a4af3bSchristos # Each line is of the form 'foo.o: dependency.h'. 93*a5a4af3bSchristos # Do two passes, one to just change these to 94*a5a4af3bSchristos # $object: dependency.h 95*a5a4af3bSchristos # and one to simply output 96*a5a4af3bSchristos # dependency.h: 97*a5a4af3bSchristos # which is needed to avoid the deleted-header problem. 98*a5a4af3bSchristos { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99*a5a4af3bSchristos sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100*a5a4af3bSchristos } > "$depfile" 101*a5a4af3bSchristos rm -f "$tmpdepfile" 102*a5a4af3bSchristos else 103*a5a4af3bSchristos make_dummy_depfile 104*a5a4af3bSchristos fi 105*a5a4af3bSchristos} 106*a5a4af3bSchristos 107*a5a4af3bSchristos# A tabulation character. 108*a5a4af3bSchristostab=' ' 109*a5a4af3bSchristos# A newline character. 110*a5a4af3bSchristosnl=' 111*a5a4af3bSchristos' 112*a5a4af3bSchristos# Character ranges might be problematic outside the C locale. 113*a5a4af3bSchristos# These definitions help. 114*a5a4af3bSchristosupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115*a5a4af3bSchristoslower=abcdefghijklmnopqrstuvwxyz 116*a5a4af3bSchristosdigits=0123456789 117*a5a4af3bSchristosalpha=${upper}${lower} 118*a5a4af3bSchristos 119*a5a4af3bSchristosif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120*a5a4af3bSchristos echo "depcomp: Variables source, object and depmode must be set" 1>&2 121*a5a4af3bSchristos exit 1 122*a5a4af3bSchristosfi 123*a5a4af3bSchristos 124*a5a4af3bSchristos# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125*a5a4af3bSchristosdepfile=${depfile-`echo "$object" | 126*a5a4af3bSchristos sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127*a5a4af3bSchristostmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128*a5a4af3bSchristos 129*a5a4af3bSchristosrm -f "$tmpdepfile" 130*a5a4af3bSchristos 131*a5a4af3bSchristos# Avoid interferences from the environment. 132*a5a4af3bSchristosgccflag= dashmflag= 133*a5a4af3bSchristos 134*a5a4af3bSchristos# Some modes work just like other modes, but use different flags. We 135*a5a4af3bSchristos# parameterize here, but still list the modes in the big case below, 136*a5a4af3bSchristos# to make depend.m4 easier to write. Note that we *cannot* use a case 137*a5a4af3bSchristos# here, because this file can only contain one case statement. 138*a5a4af3bSchristosif test "$depmode" = hp; then 139*a5a4af3bSchristos # HP compiler uses -M and no extra arg. 140*a5a4af3bSchristos gccflag=-M 141*a5a4af3bSchristos depmode=gcc 142*a5a4af3bSchristosfi 143*a5a4af3bSchristos 144*a5a4af3bSchristosif test "$depmode" = dashXmstdout; then 145*a5a4af3bSchristos # This is just like dashmstdout with a different argument. 146*a5a4af3bSchristos dashmflag=-xM 147*a5a4af3bSchristos depmode=dashmstdout 148*a5a4af3bSchristosfi 149*a5a4af3bSchristos 150*a5a4af3bSchristoscygpath_u="cygpath -u -f -" 151*a5a4af3bSchristosif test "$depmode" = msvcmsys; then 152*a5a4af3bSchristos # This is just like msvisualcpp but w/o cygpath translation. 153*a5a4af3bSchristos # Just convert the backslash-escaped backslashes to single forward 154*a5a4af3bSchristos # slashes to satisfy depend.m4 155*a5a4af3bSchristos cygpath_u='sed s,\\\\,/,g' 156*a5a4af3bSchristos depmode=msvisualcpp 157*a5a4af3bSchristosfi 158*a5a4af3bSchristos 159*a5a4af3bSchristosif test "$depmode" = msvc7msys; then 160*a5a4af3bSchristos # This is just like msvc7 but w/o cygpath translation. 161*a5a4af3bSchristos # Just convert the backslash-escaped backslashes to single forward 162*a5a4af3bSchristos # slashes to satisfy depend.m4 163*a5a4af3bSchristos cygpath_u='sed s,\\\\,/,g' 164*a5a4af3bSchristos depmode=msvc7 165*a5a4af3bSchristosfi 166*a5a4af3bSchristos 167*a5a4af3bSchristosif test "$depmode" = xlc; then 168*a5a4af3bSchristos # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169*a5a4af3bSchristos gccflag=-qmakedep=gcc,-MF 170*a5a4af3bSchristos depmode=gcc 171*a5a4af3bSchristosfi 172*a5a4af3bSchristos 173*a5a4af3bSchristoscase "$depmode" in 174*a5a4af3bSchristosgcc3) 175*a5a4af3bSchristos## gcc 3 implements dependency tracking that does exactly what 176*a5a4af3bSchristos## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177*a5a4af3bSchristos## it if -MD -MP comes after the -MF stuff. Hmm. 178*a5a4af3bSchristos## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179*a5a4af3bSchristos## the command line argument order; so add the flags where they 180*a5a4af3bSchristos## appear in depend2.am. Note that the slowdown incurred here 181*a5a4af3bSchristos## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182*a5a4af3bSchristos for arg 183*a5a4af3bSchristos do 184*a5a4af3bSchristos case $arg in 185*a5a4af3bSchristos -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186*a5a4af3bSchristos *) set fnord "$@" "$arg" ;; 187*a5a4af3bSchristos esac 188*a5a4af3bSchristos shift # fnord 189*a5a4af3bSchristos shift # $arg 190*a5a4af3bSchristos done 191*a5a4af3bSchristos "$@" 192*a5a4af3bSchristos stat=$? 193*a5a4af3bSchristos if test $stat -ne 0; then 194*a5a4af3bSchristos rm -f "$tmpdepfile" 195*a5a4af3bSchristos exit $stat 196*a5a4af3bSchristos fi 197*a5a4af3bSchristos mv "$tmpdepfile" "$depfile" 198*a5a4af3bSchristos ;; 199*a5a4af3bSchristos 200*a5a4af3bSchristosgcc) 201*a5a4af3bSchristos## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202*a5a4af3bSchristos## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203*a5a4af3bSchristos## (see the conditional assignment to $gccflag above). 204*a5a4af3bSchristos## There are various ways to get dependency output from gcc. Here's 205*a5a4af3bSchristos## why we pick this rather obscure method: 206*a5a4af3bSchristos## - Don't want to use -MD because we'd like the dependencies to end 207*a5a4af3bSchristos## up in a subdir. Having to rename by hand is ugly. 208*a5a4af3bSchristos## (We might end up doing this anyway to support other compilers.) 209*a5a4af3bSchristos## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210*a5a4af3bSchristos## -MM, not -M (despite what the docs say). Also, it might not be 211*a5a4af3bSchristos## supported by the other compilers which use the 'gcc' depmode. 212*a5a4af3bSchristos## - Using -M directly means running the compiler twice (even worse 213*a5a4af3bSchristos## than renaming). 214*a5a4af3bSchristos if test -z "$gccflag"; then 215*a5a4af3bSchristos gccflag=-MD, 216*a5a4af3bSchristos fi 217*a5a4af3bSchristos "$@" -Wp,"$gccflag$tmpdepfile" 218*a5a4af3bSchristos stat=$? 219*a5a4af3bSchristos if test $stat -ne 0; then 220*a5a4af3bSchristos rm -f "$tmpdepfile" 221*a5a4af3bSchristos exit $stat 222*a5a4af3bSchristos fi 223*a5a4af3bSchristos rm -f "$depfile" 224*a5a4af3bSchristos echo "$object : \\" > "$depfile" 225*a5a4af3bSchristos # The second -e expression handles DOS-style file names with drive 226*a5a4af3bSchristos # letters. 227*a5a4af3bSchristos sed -e 's/^[^:]*: / /' \ 228*a5a4af3bSchristos -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229*a5a4af3bSchristos## This next piece of magic avoids the "deleted header file" problem. 230*a5a4af3bSchristos## The problem is that when a header file which appears in a .P file 231*a5a4af3bSchristos## is deleted, the dependency causes make to die (because there is 232*a5a4af3bSchristos## typically no way to rebuild the header). We avoid this by adding 233*a5a4af3bSchristos## dummy dependencies for each header file. Too bad gcc doesn't do 234*a5a4af3bSchristos## this for us directly. 235*a5a4af3bSchristos## Some versions of gcc put a space before the ':'. On the theory 236*a5a4af3bSchristos## that the space means something, we add a space to the output as 237*a5a4af3bSchristos## well. hp depmode also adds that space, but also prefixes the VPATH 238*a5a4af3bSchristos## to the object. Take care to not repeat it in the output. 239*a5a4af3bSchristos## Some versions of the HPUX 10.20 sed can't process this invocation 240*a5a4af3bSchristos## correctly. Breaking it into two sed invocations is a workaround. 241*a5a4af3bSchristos tr ' ' "$nl" < "$tmpdepfile" \ 242*a5a4af3bSchristos | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243*a5a4af3bSchristos | sed -e 's/$/ :/' >> "$depfile" 244*a5a4af3bSchristos rm -f "$tmpdepfile" 245*a5a4af3bSchristos ;; 246*a5a4af3bSchristos 247*a5a4af3bSchristoshp) 248*a5a4af3bSchristos # This case exists only to let depend.m4 do its work. It works by 249*a5a4af3bSchristos # looking at the text of this script. This case will never be run, 250*a5a4af3bSchristos # since it is checked for above. 251*a5a4af3bSchristos exit 1 252*a5a4af3bSchristos ;; 253*a5a4af3bSchristos 254*a5a4af3bSchristosxlc) 255*a5a4af3bSchristos # This case exists only to let depend.m4 do its work. It works by 256*a5a4af3bSchristos # looking at the text of this script. This case will never be run, 257*a5a4af3bSchristos # since it is checked for above. 258*a5a4af3bSchristos exit 1 259*a5a4af3bSchristos ;; 260*a5a4af3bSchristos 261*a5a4af3bSchristosaix) 262*a5a4af3bSchristos # The C for AIX Compiler uses -M and outputs the dependencies 263*a5a4af3bSchristos # in a .u file. In older versions, this file always lives in the 264*a5a4af3bSchristos # current directory. Also, the AIX compiler puts '$object:' at the 265*a5a4af3bSchristos # start of each line; $object doesn't have directory information. 266*a5a4af3bSchristos # Version 6 uses the directory in both cases. 267*a5a4af3bSchristos set_dir_from "$object" 268*a5a4af3bSchristos set_base_from "$object" 269*a5a4af3bSchristos if test "$libtool" = yes; then 270*a5a4af3bSchristos tmpdepfile1=$dir$base.u 271*a5a4af3bSchristos tmpdepfile2=$base.u 272*a5a4af3bSchristos tmpdepfile3=$dir.libs/$base.u 273*a5a4af3bSchristos "$@" -Wc,-M 274*a5a4af3bSchristos else 275*a5a4af3bSchristos tmpdepfile1=$dir$base.u 276*a5a4af3bSchristos tmpdepfile2=$dir$base.u 277*a5a4af3bSchristos tmpdepfile3=$dir$base.u 278*a5a4af3bSchristos "$@" -M 279*a5a4af3bSchristos fi 280*a5a4af3bSchristos stat=$? 281*a5a4af3bSchristos if test $stat -ne 0; then 282*a5a4af3bSchristos rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 283*a5a4af3bSchristos exit $stat 284*a5a4af3bSchristos fi 285*a5a4af3bSchristos 286*a5a4af3bSchristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 287*a5a4af3bSchristos do 288*a5a4af3bSchristos test -f "$tmpdepfile" && break 289*a5a4af3bSchristos done 290*a5a4af3bSchristos aix_post_process_depfile 291*a5a4af3bSchristos ;; 292*a5a4af3bSchristos 293*a5a4af3bSchristostcc) 294*a5a4af3bSchristos # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 295*a5a4af3bSchristos # FIXME: That version still under development at the moment of writing. 296*a5a4af3bSchristos # Make that this statement remains true also for stable, released 297*a5a4af3bSchristos # versions. 298*a5a4af3bSchristos # It will wrap lines (doesn't matter whether long or short) with a 299*a5a4af3bSchristos # trailing '\', as in: 300*a5a4af3bSchristos # 301*a5a4af3bSchristos # foo.o : \ 302*a5a4af3bSchristos # foo.c \ 303*a5a4af3bSchristos # foo.h \ 304*a5a4af3bSchristos # 305*a5a4af3bSchristos # It will put a trailing '\' even on the last line, and will use leading 306*a5a4af3bSchristos # spaces rather than leading tabs (at least since its commit 0394caf7 307*a5a4af3bSchristos # "Emit spaces for -MD"). 308*a5a4af3bSchristos "$@" -MD -MF "$tmpdepfile" 309*a5a4af3bSchristos stat=$? 310*a5a4af3bSchristos if test $stat -ne 0; then 311*a5a4af3bSchristos rm -f "$tmpdepfile" 312*a5a4af3bSchristos exit $stat 313*a5a4af3bSchristos fi 314*a5a4af3bSchristos rm -f "$depfile" 315*a5a4af3bSchristos # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 316*a5a4af3bSchristos # We have to change lines of the first kind to '$object: \'. 317*a5a4af3bSchristos sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 318*a5a4af3bSchristos # And for each line of the second kind, we have to emit a 'dep.h:' 319*a5a4af3bSchristos # dummy dependency, to avoid the deleted-header problem. 320*a5a4af3bSchristos sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 321*a5a4af3bSchristos rm -f "$tmpdepfile" 322*a5a4af3bSchristos ;; 323*a5a4af3bSchristos 324*a5a4af3bSchristos## The order of this option in the case statement is important, since the 325*a5a4af3bSchristos## shell code in configure will try each of these formats in the order 326*a5a4af3bSchristos## listed in this file. A plain '-MD' option would be understood by many 327*a5a4af3bSchristos## compilers, so we must ensure this comes after the gcc and icc options. 328*a5a4af3bSchristospgcc) 329*a5a4af3bSchristos # Portland's C compiler understands '-MD'. 330*a5a4af3bSchristos # Will always output deps to 'file.d' where file is the root name of the 331*a5a4af3bSchristos # source file under compilation, even if file resides in a subdirectory. 332*a5a4af3bSchristos # The object file name does not affect the name of the '.d' file. 333*a5a4af3bSchristos # pgcc 10.2 will output 334*a5a4af3bSchristos # foo.o: sub/foo.c sub/foo.h 335*a5a4af3bSchristos # and will wrap long lines using '\' : 336*a5a4af3bSchristos # foo.o: sub/foo.c ... \ 337*a5a4af3bSchristos # sub/foo.h ... \ 338*a5a4af3bSchristos # ... 339*a5a4af3bSchristos set_dir_from "$object" 340*a5a4af3bSchristos # Use the source, not the object, to determine the base name, since 341*a5a4af3bSchristos # that's sadly what pgcc will do too. 342*a5a4af3bSchristos set_base_from "$source" 343*a5a4af3bSchristos tmpdepfile=$base.d 344*a5a4af3bSchristos 345*a5a4af3bSchristos # For projects that build the same source file twice into different object 346*a5a4af3bSchristos # files, the pgcc approach of using the *source* file root name can cause 347*a5a4af3bSchristos # problems in parallel builds. Use a locking strategy to avoid stomping on 348*a5a4af3bSchristos # the same $tmpdepfile. 349*a5a4af3bSchristos lockdir=$base.d-lock 350*a5a4af3bSchristos trap " 351*a5a4af3bSchristos echo '$0: caught signal, cleaning up...' >&2 352*a5a4af3bSchristos rmdir '$lockdir' 353*a5a4af3bSchristos exit 1 354*a5a4af3bSchristos " 1 2 13 15 355*a5a4af3bSchristos numtries=100 356*a5a4af3bSchristos i=$numtries 357*a5a4af3bSchristos while test $i -gt 0; do 358*a5a4af3bSchristos # mkdir is a portable test-and-set. 359*a5a4af3bSchristos if mkdir "$lockdir" 2>/dev/null; then 360*a5a4af3bSchristos # This process acquired the lock. 361*a5a4af3bSchristos "$@" -MD 362*a5a4af3bSchristos stat=$? 363*a5a4af3bSchristos # Release the lock. 364*a5a4af3bSchristos rmdir "$lockdir" 365*a5a4af3bSchristos break 366*a5a4af3bSchristos else 367*a5a4af3bSchristos # If the lock is being held by a different process, wait 368*a5a4af3bSchristos # until the winning process is done or we timeout. 369*a5a4af3bSchristos while test -d "$lockdir" && test $i -gt 0; do 370*a5a4af3bSchristos sleep 1 371*a5a4af3bSchristos i=`expr $i - 1` 372*a5a4af3bSchristos done 373*a5a4af3bSchristos fi 374*a5a4af3bSchristos i=`expr $i - 1` 375*a5a4af3bSchristos done 376*a5a4af3bSchristos trap - 1 2 13 15 377*a5a4af3bSchristos if test $i -le 0; then 378*a5a4af3bSchristos echo "$0: failed to acquire lock after $numtries attempts" >&2 379*a5a4af3bSchristos echo "$0: check lockdir '$lockdir'" >&2 380*a5a4af3bSchristos exit 1 381*a5a4af3bSchristos fi 382*a5a4af3bSchristos 383*a5a4af3bSchristos if test $stat -ne 0; then 384*a5a4af3bSchristos rm -f "$tmpdepfile" 385*a5a4af3bSchristos exit $stat 386*a5a4af3bSchristos fi 387*a5a4af3bSchristos rm -f "$depfile" 388*a5a4af3bSchristos # Each line is of the form `foo.o: dependent.h', 389*a5a4af3bSchristos # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 390*a5a4af3bSchristos # Do two passes, one to just change these to 391*a5a4af3bSchristos # `$object: dependent.h' and one to simply `dependent.h:'. 392*a5a4af3bSchristos sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 393*a5a4af3bSchristos # Some versions of the HPUX 10.20 sed can't process this invocation 394*a5a4af3bSchristos # correctly. Breaking it into two sed invocations is a workaround. 395*a5a4af3bSchristos sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 396*a5a4af3bSchristos | sed -e 's/$/ :/' >> "$depfile" 397*a5a4af3bSchristos rm -f "$tmpdepfile" 398*a5a4af3bSchristos ;; 399*a5a4af3bSchristos 400*a5a4af3bSchristoshp2) 401*a5a4af3bSchristos # The "hp" stanza above does not work with aCC (C++) and HP's ia64 402*a5a4af3bSchristos # compilers, which have integrated preprocessors. The correct option 403*a5a4af3bSchristos # to use with these is +Maked; it writes dependencies to a file named 404*a5a4af3bSchristos # 'foo.d', which lands next to the object file, wherever that 405*a5a4af3bSchristos # happens to be. 406*a5a4af3bSchristos # Much of this is similar to the tru64 case; see comments there. 407*a5a4af3bSchristos set_dir_from "$object" 408*a5a4af3bSchristos set_base_from "$object" 409*a5a4af3bSchristos if test "$libtool" = yes; then 410*a5a4af3bSchristos tmpdepfile1=$dir$base.d 411*a5a4af3bSchristos tmpdepfile2=$dir.libs/$base.d 412*a5a4af3bSchristos "$@" -Wc,+Maked 413*a5a4af3bSchristos else 414*a5a4af3bSchristos tmpdepfile1=$dir$base.d 415*a5a4af3bSchristos tmpdepfile2=$dir$base.d 416*a5a4af3bSchristos "$@" +Maked 417*a5a4af3bSchristos fi 418*a5a4af3bSchristos stat=$? 419*a5a4af3bSchristos if test $stat -ne 0; then 420*a5a4af3bSchristos rm -f "$tmpdepfile1" "$tmpdepfile2" 421*a5a4af3bSchristos exit $stat 422*a5a4af3bSchristos fi 423*a5a4af3bSchristos 424*a5a4af3bSchristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 425*a5a4af3bSchristos do 426*a5a4af3bSchristos test -f "$tmpdepfile" && break 427*a5a4af3bSchristos done 428*a5a4af3bSchristos if test -f "$tmpdepfile"; then 429*a5a4af3bSchristos sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 430*a5a4af3bSchristos # Add 'dependent.h:' lines. 431*a5a4af3bSchristos sed -ne '2,${ 432*a5a4af3bSchristos s/^ *// 433*a5a4af3bSchristos s/ \\*$// 434*a5a4af3bSchristos s/$/:/ 435*a5a4af3bSchristos p 436*a5a4af3bSchristos }' "$tmpdepfile" >> "$depfile" 437*a5a4af3bSchristos else 438*a5a4af3bSchristos make_dummy_depfile 439*a5a4af3bSchristos fi 440*a5a4af3bSchristos rm -f "$tmpdepfile" "$tmpdepfile2" 441*a5a4af3bSchristos ;; 442*a5a4af3bSchristos 443*a5a4af3bSchristostru64) 444*a5a4af3bSchristos # The Tru64 compiler uses -MD to generate dependencies as a side 445*a5a4af3bSchristos # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 446*a5a4af3bSchristos # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 447*a5a4af3bSchristos # dependencies in 'foo.d' instead, so we check for that too. 448*a5a4af3bSchristos # Subdirectories are respected. 449*a5a4af3bSchristos set_dir_from "$object" 450*a5a4af3bSchristos set_base_from "$object" 451*a5a4af3bSchristos 452*a5a4af3bSchristos if test "$libtool" = yes; then 453*a5a4af3bSchristos # Libtool generates 2 separate objects for the 2 libraries. These 454*a5a4af3bSchristos # two compilations output dependencies in $dir.libs/$base.o.d and 455*a5a4af3bSchristos # in $dir$base.o.d. We have to check for both files, because 456*a5a4af3bSchristos # one of the two compilations can be disabled. We should prefer 457*a5a4af3bSchristos # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 458*a5a4af3bSchristos # automatically cleaned when .libs/ is deleted, while ignoring 459*a5a4af3bSchristos # the former would cause a distcleancheck panic. 460*a5a4af3bSchristos tmpdepfile1=$dir$base.o.d # libtool 1.5 461*a5a4af3bSchristos tmpdepfile2=$dir.libs/$base.o.d # Likewise. 462*a5a4af3bSchristos tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 463*a5a4af3bSchristos "$@" -Wc,-MD 464*a5a4af3bSchristos else 465*a5a4af3bSchristos tmpdepfile1=$dir$base.d 466*a5a4af3bSchristos tmpdepfile2=$dir$base.d 467*a5a4af3bSchristos tmpdepfile3=$dir$base.d 468*a5a4af3bSchristos "$@" -MD 469*a5a4af3bSchristos fi 470*a5a4af3bSchristos 471*a5a4af3bSchristos stat=$? 472*a5a4af3bSchristos if test $stat -ne 0; then 473*a5a4af3bSchristos rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 474*a5a4af3bSchristos exit $stat 475*a5a4af3bSchristos fi 476*a5a4af3bSchristos 477*a5a4af3bSchristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 478*a5a4af3bSchristos do 479*a5a4af3bSchristos test -f "$tmpdepfile" && break 480*a5a4af3bSchristos done 481*a5a4af3bSchristos # Same post-processing that is required for AIX mode. 482*a5a4af3bSchristos aix_post_process_depfile 483*a5a4af3bSchristos ;; 484*a5a4af3bSchristos 485*a5a4af3bSchristosmsvc7) 486*a5a4af3bSchristos if test "$libtool" = yes; then 487*a5a4af3bSchristos showIncludes=-Wc,-showIncludes 488*a5a4af3bSchristos else 489*a5a4af3bSchristos showIncludes=-showIncludes 490*a5a4af3bSchristos fi 491*a5a4af3bSchristos "$@" $showIncludes > "$tmpdepfile" 492*a5a4af3bSchristos stat=$? 493*a5a4af3bSchristos grep -v '^Note: including file: ' "$tmpdepfile" 494*a5a4af3bSchristos if test $stat -ne 0; then 495*a5a4af3bSchristos rm -f "$tmpdepfile" 496*a5a4af3bSchristos exit $stat 497*a5a4af3bSchristos fi 498*a5a4af3bSchristos rm -f "$depfile" 499*a5a4af3bSchristos echo "$object : \\" > "$depfile" 500*a5a4af3bSchristos # The first sed program below extracts the file names and escapes 501*a5a4af3bSchristos # backslashes for cygpath. The second sed program outputs the file 502*a5a4af3bSchristos # name when reading, but also accumulates all include files in the 503*a5a4af3bSchristos # hold buffer in order to output them again at the end. This only 504*a5a4af3bSchristos # works with sed implementations that can handle large buffers. 505*a5a4af3bSchristos sed < "$tmpdepfile" -n ' 506*a5a4af3bSchristos/^Note: including file: *\(.*\)/ { 507*a5a4af3bSchristos s//\1/ 508*a5a4af3bSchristos s/\\/\\\\/g 509*a5a4af3bSchristos p 510*a5a4af3bSchristos}' | $cygpath_u | sort -u | sed -n ' 511*a5a4af3bSchristoss/ /\\ /g 512*a5a4af3bSchristoss/\(.*\)/'"$tab"'\1 \\/p 513*a5a4af3bSchristoss/.\(.*\) \\/\1:/ 514*a5a4af3bSchristosH 515*a5a4af3bSchristos$ { 516*a5a4af3bSchristos s/.*/'"$tab"'/ 517*a5a4af3bSchristos G 518*a5a4af3bSchristos p 519*a5a4af3bSchristos}' >> "$depfile" 520*a5a4af3bSchristos echo >> "$depfile" # make sure the fragment doesn't end with a backslash 521*a5a4af3bSchristos rm -f "$tmpdepfile" 522*a5a4af3bSchristos ;; 523*a5a4af3bSchristos 524*a5a4af3bSchristosmsvc7msys) 525*a5a4af3bSchristos # This case exists only to let depend.m4 do its work. It works by 526*a5a4af3bSchristos # looking at the text of this script. This case will never be run, 527*a5a4af3bSchristos # since it is checked for above. 528*a5a4af3bSchristos exit 1 529*a5a4af3bSchristos ;; 530*a5a4af3bSchristos 531*a5a4af3bSchristos#nosideeffect) 532*a5a4af3bSchristos # This comment above is used by automake to tell side-effect 533*a5a4af3bSchristos # dependency tracking mechanisms from slower ones. 534*a5a4af3bSchristos 535*a5a4af3bSchristosdashmstdout) 536*a5a4af3bSchristos # Important note: in order to support this mode, a compiler *must* 537*a5a4af3bSchristos # always write the preprocessed file to stdout, regardless of -o. 538*a5a4af3bSchristos "$@" || exit $? 539*a5a4af3bSchristos 540*a5a4af3bSchristos # Remove the call to Libtool. 541*a5a4af3bSchristos if test "$libtool" = yes; then 542*a5a4af3bSchristos while test "X$1" != 'X--mode=compile'; do 543*a5a4af3bSchristos shift 544*a5a4af3bSchristos done 545*a5a4af3bSchristos shift 546*a5a4af3bSchristos fi 547*a5a4af3bSchristos 548*a5a4af3bSchristos # Remove '-o $object'. 549*a5a4af3bSchristos IFS=" " 550*a5a4af3bSchristos for arg 551*a5a4af3bSchristos do 552*a5a4af3bSchristos case $arg in 553*a5a4af3bSchristos -o) 554*a5a4af3bSchristos shift 555*a5a4af3bSchristos ;; 556*a5a4af3bSchristos $object) 557*a5a4af3bSchristos shift 558*a5a4af3bSchristos ;; 559*a5a4af3bSchristos *) 560*a5a4af3bSchristos set fnord "$@" "$arg" 561*a5a4af3bSchristos shift # fnord 562*a5a4af3bSchristos shift # $arg 563*a5a4af3bSchristos ;; 564*a5a4af3bSchristos esac 565*a5a4af3bSchristos done 566*a5a4af3bSchristos 567*a5a4af3bSchristos test -z "$dashmflag" && dashmflag=-M 568*a5a4af3bSchristos # Require at least two characters before searching for ':' 569*a5a4af3bSchristos # in the target name. This is to cope with DOS-style filenames: 570*a5a4af3bSchristos # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 571*a5a4af3bSchristos "$@" $dashmflag | 572*a5a4af3bSchristos sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 573*a5a4af3bSchristos rm -f "$depfile" 574*a5a4af3bSchristos cat < "$tmpdepfile" > "$depfile" 575*a5a4af3bSchristos # Some versions of the HPUX 10.20 sed can't process this sed invocation 576*a5a4af3bSchristos # correctly. Breaking it into two sed invocations is a workaround. 577*a5a4af3bSchristos tr ' ' "$nl" < "$tmpdepfile" \ 578*a5a4af3bSchristos | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 579*a5a4af3bSchristos | sed -e 's/$/ :/' >> "$depfile" 580*a5a4af3bSchristos rm -f "$tmpdepfile" 581*a5a4af3bSchristos ;; 582*a5a4af3bSchristos 583*a5a4af3bSchristosdashXmstdout) 584*a5a4af3bSchristos # This case only exists to satisfy depend.m4. It is never actually 585*a5a4af3bSchristos # run, as this mode is specially recognized in the preamble. 586*a5a4af3bSchristos exit 1 587*a5a4af3bSchristos ;; 588*a5a4af3bSchristos 589*a5a4af3bSchristosmakedepend) 590*a5a4af3bSchristos "$@" || exit $? 591*a5a4af3bSchristos # Remove any Libtool call 592*a5a4af3bSchristos if test "$libtool" = yes; then 593*a5a4af3bSchristos while test "X$1" != 'X--mode=compile'; do 594*a5a4af3bSchristos shift 595*a5a4af3bSchristos done 596*a5a4af3bSchristos shift 597*a5a4af3bSchristos fi 598*a5a4af3bSchristos # X makedepend 599*a5a4af3bSchristos shift 600*a5a4af3bSchristos cleared=no eat=no 601*a5a4af3bSchristos for arg 602*a5a4af3bSchristos do 603*a5a4af3bSchristos case $cleared in 604*a5a4af3bSchristos no) 605*a5a4af3bSchristos set ""; shift 606*a5a4af3bSchristos cleared=yes ;; 607*a5a4af3bSchristos esac 608*a5a4af3bSchristos if test $eat = yes; then 609*a5a4af3bSchristos eat=no 610*a5a4af3bSchristos continue 611*a5a4af3bSchristos fi 612*a5a4af3bSchristos case "$arg" in 613*a5a4af3bSchristos -D*|-I*) 614*a5a4af3bSchristos set fnord "$@" "$arg"; shift ;; 615*a5a4af3bSchristos # Strip any option that makedepend may not understand. Remove 616*a5a4af3bSchristos # the object too, otherwise makedepend will parse it as a source file. 617*a5a4af3bSchristos -arch) 618*a5a4af3bSchristos eat=yes ;; 619*a5a4af3bSchristos -*|$object) 620*a5a4af3bSchristos ;; 621*a5a4af3bSchristos *) 622*a5a4af3bSchristos set fnord "$@" "$arg"; shift ;; 623*a5a4af3bSchristos esac 624*a5a4af3bSchristos done 625*a5a4af3bSchristos obj_suffix=`echo "$object" | sed 's/^.*\././'` 626*a5a4af3bSchristos touch "$tmpdepfile" 627*a5a4af3bSchristos ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 628*a5a4af3bSchristos rm -f "$depfile" 629*a5a4af3bSchristos # makedepend may prepend the VPATH from the source file name to the object. 630*a5a4af3bSchristos # No need to regex-escape $object, excess matching of '.' is harmless. 631*a5a4af3bSchristos sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 632*a5a4af3bSchristos # Some versions of the HPUX 10.20 sed can't process the last invocation 633*a5a4af3bSchristos # correctly. Breaking it into two sed invocations is a workaround. 634*a5a4af3bSchristos sed '1,2d' "$tmpdepfile" \ 635*a5a4af3bSchristos | tr ' ' "$nl" \ 636*a5a4af3bSchristos | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 637*a5a4af3bSchristos | sed -e 's/$/ :/' >> "$depfile" 638*a5a4af3bSchristos rm -f "$tmpdepfile" "$tmpdepfile".bak 639*a5a4af3bSchristos ;; 640*a5a4af3bSchristos 641*a5a4af3bSchristoscpp) 642*a5a4af3bSchristos # Important note: in order to support this mode, a compiler *must* 643*a5a4af3bSchristos # always write the preprocessed file to stdout. 644*a5a4af3bSchristos "$@" || exit $? 645*a5a4af3bSchristos 646*a5a4af3bSchristos # Remove the call to Libtool. 647*a5a4af3bSchristos if test "$libtool" = yes; then 648*a5a4af3bSchristos while test "X$1" != 'X--mode=compile'; do 649*a5a4af3bSchristos shift 650*a5a4af3bSchristos done 651*a5a4af3bSchristos shift 652*a5a4af3bSchristos fi 653*a5a4af3bSchristos 654*a5a4af3bSchristos # Remove '-o $object'. 655*a5a4af3bSchristos IFS=" " 656*a5a4af3bSchristos for arg 657*a5a4af3bSchristos do 658*a5a4af3bSchristos case $arg in 659*a5a4af3bSchristos -o) 660*a5a4af3bSchristos shift 661*a5a4af3bSchristos ;; 662*a5a4af3bSchristos $object) 663*a5a4af3bSchristos shift 664*a5a4af3bSchristos ;; 665*a5a4af3bSchristos *) 666*a5a4af3bSchristos set fnord "$@" "$arg" 667*a5a4af3bSchristos shift # fnord 668*a5a4af3bSchristos shift # $arg 669*a5a4af3bSchristos ;; 670*a5a4af3bSchristos esac 671*a5a4af3bSchristos done 672*a5a4af3bSchristos 673*a5a4af3bSchristos "$@" -E \ 674*a5a4af3bSchristos | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 675*a5a4af3bSchristos -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 676*a5a4af3bSchristos | sed '$ s: \\$::' > "$tmpdepfile" 677*a5a4af3bSchristos rm -f "$depfile" 678*a5a4af3bSchristos echo "$object : \\" > "$depfile" 679*a5a4af3bSchristos cat < "$tmpdepfile" >> "$depfile" 680*a5a4af3bSchristos sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 681*a5a4af3bSchristos rm -f "$tmpdepfile" 682*a5a4af3bSchristos ;; 683*a5a4af3bSchristos 684*a5a4af3bSchristosmsvisualcpp) 685*a5a4af3bSchristos # Important note: in order to support this mode, a compiler *must* 686*a5a4af3bSchristos # always write the preprocessed file to stdout. 687*a5a4af3bSchristos "$@" || exit $? 688*a5a4af3bSchristos 689*a5a4af3bSchristos # Remove the call to Libtool. 690*a5a4af3bSchristos if test "$libtool" = yes; then 691*a5a4af3bSchristos while test "X$1" != 'X--mode=compile'; do 692*a5a4af3bSchristos shift 693*a5a4af3bSchristos done 694*a5a4af3bSchristos shift 695*a5a4af3bSchristos fi 696*a5a4af3bSchristos 697*a5a4af3bSchristos IFS=" " 698*a5a4af3bSchristos for arg 699*a5a4af3bSchristos do 700*a5a4af3bSchristos case "$arg" in 701*a5a4af3bSchristos -o) 702*a5a4af3bSchristos shift 703*a5a4af3bSchristos ;; 704*a5a4af3bSchristos $object) 705*a5a4af3bSchristos shift 706*a5a4af3bSchristos ;; 707*a5a4af3bSchristos "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 708*a5a4af3bSchristos set fnord "$@" 709*a5a4af3bSchristos shift 710*a5a4af3bSchristos shift 711*a5a4af3bSchristos ;; 712*a5a4af3bSchristos *) 713*a5a4af3bSchristos set fnord "$@" "$arg" 714*a5a4af3bSchristos shift 715*a5a4af3bSchristos shift 716*a5a4af3bSchristos ;; 717*a5a4af3bSchristos esac 718*a5a4af3bSchristos done 719*a5a4af3bSchristos "$@" -E 2>/dev/null | 720*a5a4af3bSchristos sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 721*a5a4af3bSchristos rm -f "$depfile" 722*a5a4af3bSchristos echo "$object : \\" > "$depfile" 723*a5a4af3bSchristos sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 724*a5a4af3bSchristos echo "$tab" >> "$depfile" 725*a5a4af3bSchristos sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 726*a5a4af3bSchristos rm -f "$tmpdepfile" 727*a5a4af3bSchristos ;; 728*a5a4af3bSchristos 729*a5a4af3bSchristosmsvcmsys) 730*a5a4af3bSchristos # This case exists only to let depend.m4 do its work. It works by 731*a5a4af3bSchristos # looking at the text of this script. This case will never be run, 732*a5a4af3bSchristos # since it is checked for above. 733*a5a4af3bSchristos exit 1 734*a5a4af3bSchristos ;; 735*a5a4af3bSchristos 736*a5a4af3bSchristosnone) 737*a5a4af3bSchristos exec "$@" 738*a5a4af3bSchristos ;; 739*a5a4af3bSchristos 740*a5a4af3bSchristos*) 741*a5a4af3bSchristos echo "Unknown depmode $depmode" 1>&2 742*a5a4af3bSchristos exit 1 743*a5a4af3bSchristos ;; 744*a5a4af3bSchristosesac 745*a5a4af3bSchristos 746*a5a4af3bSchristosexit 0 747*a5a4af3bSchristos 748*a5a4af3bSchristos# Local Variables: 749*a5a4af3bSchristos# mode: shell-script 750*a5a4af3bSchristos# sh-indentation: 2 751*a5a4af3bSchristos# eval: (add-hook 'write-file-hooks 'time-stamp) 752*a5a4af3bSchristos# time-stamp-start: "scriptversion=" 753*a5a4af3bSchristos# time-stamp-format: "%:y-%02m-%02d.%02H" 754*a5a4af3bSchristos# time-stamp-time-zone: "UTC" 755*a5a4af3bSchristos# time-stamp-end: "; # UTC" 756*a5a4af3bSchristos# End: 757