1603fc0a3Smrg#! /bin/sh 2603fc0a3Smrg# depcomp - compile a program generating dependencies as side-effects 3603fc0a3Smrg 4603fc0a3Smrgscriptversion=2018-03-07.03; # UTC 5603fc0a3Smrg 6603fc0a3Smrg# Copyright (C) 1999-2018 Free Software Foundation, Inc. 7603fc0a3Smrg 8603fc0a3Smrg# This program is free software; you can redistribute it and/or modify 9603fc0a3Smrg# it under the terms of the GNU General Public License as published by 10603fc0a3Smrg# the Free Software Foundation; either version 2, or (at your option) 11603fc0a3Smrg# any later version. 12603fc0a3Smrg 13603fc0a3Smrg# This program is distributed in the hope that it will be useful, 14603fc0a3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15603fc0a3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16603fc0a3Smrg# GNU General Public License for more details. 17603fc0a3Smrg 18603fc0a3Smrg# You should have received a copy of the GNU General Public License 19603fc0a3Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20603fc0a3Smrg 21603fc0a3Smrg# As a special exception to the GNU General Public License, if you 22603fc0a3Smrg# distribute this file as part of a program that contains a 23603fc0a3Smrg# configuration script generated by Autoconf, you may include it under 24603fc0a3Smrg# the same distribution terms that you use for the rest of that program. 25603fc0a3Smrg 26603fc0a3Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27603fc0a3Smrg 28603fc0a3Smrgcase $1 in 29603fc0a3Smrg '') 30603fc0a3Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31603fc0a3Smrg exit 1; 32603fc0a3Smrg ;; 33603fc0a3Smrg -h | --h*) 34603fc0a3Smrg cat <<\EOF 35603fc0a3SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36603fc0a3Smrg 37603fc0a3SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38603fc0a3Smrgas side-effects. 39603fc0a3Smrg 40603fc0a3SmrgEnvironment variables: 41603fc0a3Smrg depmode Dependency tracking mode. 42603fc0a3Smrg source Source file read by 'PROGRAMS ARGS'. 43603fc0a3Smrg object Object file output by 'PROGRAMS ARGS'. 44603fc0a3Smrg DEPDIR directory where to store dependencies. 45603fc0a3Smrg depfile Dependency file to output. 46603fc0a3Smrg tmpdepfile Temporary file to use when outputting dependencies. 47603fc0a3Smrg libtool Whether libtool is used (yes/no). 48603fc0a3Smrg 49603fc0a3SmrgReport bugs to <bug-automake@gnu.org>. 50603fc0a3SmrgEOF 51603fc0a3Smrg exit $? 52603fc0a3Smrg ;; 53603fc0a3Smrg -v | --v*) 54603fc0a3Smrg echo "depcomp $scriptversion" 55603fc0a3Smrg exit $? 56603fc0a3Smrg ;; 57603fc0a3Smrgesac 58603fc0a3Smrg 59603fc0a3Smrg# Get the directory component of the given path, and save it in the 60603fc0a3Smrg# global variables '$dir'. Note that this directory component will 61603fc0a3Smrg# be either empty or ending with a '/' character. This is deliberate. 62603fc0a3Smrgset_dir_from () 63603fc0a3Smrg{ 64603fc0a3Smrg case $1 in 65603fc0a3Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66603fc0a3Smrg *) dir=;; 67603fc0a3Smrg esac 68603fc0a3Smrg} 69603fc0a3Smrg 70603fc0a3Smrg# Get the suffix-stripped basename of the given path, and save it the 71603fc0a3Smrg# global variable '$base'. 72603fc0a3Smrgset_base_from () 73603fc0a3Smrg{ 74603fc0a3Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75603fc0a3Smrg} 76603fc0a3Smrg 77603fc0a3Smrg# If no dependency file was actually created by the compiler invocation, 78603fc0a3Smrg# we still have to create a dummy depfile, to avoid errors with the 79603fc0a3Smrg# Makefile "include basename.Plo" scheme. 80603fc0a3Smrgmake_dummy_depfile () 81603fc0a3Smrg{ 82603fc0a3Smrg echo "#dummy" > "$depfile" 83603fc0a3Smrg} 84603fc0a3Smrg 85603fc0a3Smrg# Factor out some common post-processing of the generated depfile. 86603fc0a3Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87603fc0a3Smrgaix_post_process_depfile () 88603fc0a3Smrg{ 89603fc0a3Smrg # If the compiler actually managed to produce a dependency file, 90603fc0a3Smrg # post-process it. 91603fc0a3Smrg if test -f "$tmpdepfile"; then 92603fc0a3Smrg # Each line is of the form 'foo.o: dependency.h'. 93603fc0a3Smrg # Do two passes, one to just change these to 94603fc0a3Smrg # $object: dependency.h 95603fc0a3Smrg # and one to simply output 96603fc0a3Smrg # dependency.h: 97603fc0a3Smrg # which is needed to avoid the deleted-header problem. 98603fc0a3Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99603fc0a3Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100603fc0a3Smrg } > "$depfile" 101603fc0a3Smrg rm -f "$tmpdepfile" 102603fc0a3Smrg else 103603fc0a3Smrg make_dummy_depfile 104603fc0a3Smrg fi 105603fc0a3Smrg} 106603fc0a3Smrg 107603fc0a3Smrg# A tabulation character. 108603fc0a3Smrgtab=' ' 109603fc0a3Smrg# A newline character. 110603fc0a3Smrgnl=' 111603fc0a3Smrg' 112603fc0a3Smrg# Character ranges might be problematic outside the C locale. 113603fc0a3Smrg# These definitions help. 114603fc0a3Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115603fc0a3Smrglower=abcdefghijklmnopqrstuvwxyz 116603fc0a3Smrgdigits=0123456789 117603fc0a3Smrgalpha=${upper}${lower} 118603fc0a3Smrg 119603fc0a3Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120603fc0a3Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121603fc0a3Smrg exit 1 122603fc0a3Smrgfi 123603fc0a3Smrg 124603fc0a3Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125603fc0a3Smrgdepfile=${depfile-`echo "$object" | 126603fc0a3Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127603fc0a3Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128603fc0a3Smrg 129603fc0a3Smrgrm -f "$tmpdepfile" 130603fc0a3Smrg 131603fc0a3Smrg# Avoid interferences from the environment. 132603fc0a3Smrggccflag= dashmflag= 133603fc0a3Smrg 134603fc0a3Smrg# Some modes work just like other modes, but use different flags. We 135603fc0a3Smrg# parameterize here, but still list the modes in the big case below, 136603fc0a3Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137603fc0a3Smrg# here, because this file can only contain one case statement. 138603fc0a3Smrgif test "$depmode" = hp; then 139603fc0a3Smrg # HP compiler uses -M and no extra arg. 140603fc0a3Smrg gccflag=-M 141603fc0a3Smrg depmode=gcc 142603fc0a3Smrgfi 143603fc0a3Smrg 144603fc0a3Smrgif test "$depmode" = dashXmstdout; then 145603fc0a3Smrg # This is just like dashmstdout with a different argument. 146603fc0a3Smrg dashmflag=-xM 147603fc0a3Smrg depmode=dashmstdout 148603fc0a3Smrgfi 149603fc0a3Smrg 150603fc0a3Smrgcygpath_u="cygpath -u -f -" 151603fc0a3Smrgif test "$depmode" = msvcmsys; then 152603fc0a3Smrg # This is just like msvisualcpp but w/o cygpath translation. 153603fc0a3Smrg # Just convert the backslash-escaped backslashes to single forward 154603fc0a3Smrg # slashes to satisfy depend.m4 155603fc0a3Smrg cygpath_u='sed s,\\\\,/,g' 156603fc0a3Smrg depmode=msvisualcpp 157603fc0a3Smrgfi 158603fc0a3Smrg 159603fc0a3Smrgif test "$depmode" = msvc7msys; then 160603fc0a3Smrg # This is just like msvc7 but w/o cygpath translation. 161603fc0a3Smrg # Just convert the backslash-escaped backslashes to single forward 162603fc0a3Smrg # slashes to satisfy depend.m4 163603fc0a3Smrg cygpath_u='sed s,\\\\,/,g' 164603fc0a3Smrg depmode=msvc7 165603fc0a3Smrgfi 166603fc0a3Smrg 167603fc0a3Smrgif test "$depmode" = xlc; then 168603fc0a3Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169603fc0a3Smrg gccflag=-qmakedep=gcc,-MF 170603fc0a3Smrg depmode=gcc 171603fc0a3Smrgfi 172603fc0a3Smrg 173603fc0a3Smrgcase "$depmode" in 174603fc0a3Smrggcc3) 175603fc0a3Smrg## gcc 3 implements dependency tracking that does exactly what 176603fc0a3Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177603fc0a3Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178603fc0a3Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179603fc0a3Smrg## the command line argument order; so add the flags where they 180603fc0a3Smrg## appear in depend2.am. Note that the slowdown incurred here 181603fc0a3Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182603fc0a3Smrg for arg 183603fc0a3Smrg do 184603fc0a3Smrg case $arg in 185603fc0a3Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186603fc0a3Smrg *) set fnord "$@" "$arg" ;; 187603fc0a3Smrg esac 188603fc0a3Smrg shift # fnord 189603fc0a3Smrg shift # $arg 190603fc0a3Smrg done 191603fc0a3Smrg "$@" 192603fc0a3Smrg stat=$? 193603fc0a3Smrg if test $stat -ne 0; then 194603fc0a3Smrg rm -f "$tmpdepfile" 195603fc0a3Smrg exit $stat 196603fc0a3Smrg fi 197603fc0a3Smrg mv "$tmpdepfile" "$depfile" 198603fc0a3Smrg ;; 199603fc0a3Smrg 200603fc0a3Smrggcc) 201603fc0a3Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202603fc0a3Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203603fc0a3Smrg## (see the conditional assignment to $gccflag above). 204603fc0a3Smrg## There are various ways to get dependency output from gcc. Here's 205603fc0a3Smrg## why we pick this rather obscure method: 206603fc0a3Smrg## - Don't want to use -MD because we'd like the dependencies to end 207603fc0a3Smrg## up in a subdir. Having to rename by hand is ugly. 208603fc0a3Smrg## (We might end up doing this anyway to support other compilers.) 209603fc0a3Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210603fc0a3Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211603fc0a3Smrg## supported by the other compilers which use the 'gcc' depmode. 212603fc0a3Smrg## - Using -M directly means running the compiler twice (even worse 213603fc0a3Smrg## than renaming). 214603fc0a3Smrg if test -z "$gccflag"; then 215603fc0a3Smrg gccflag=-MD, 216603fc0a3Smrg fi 217603fc0a3Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218603fc0a3Smrg stat=$? 219603fc0a3Smrg if test $stat -ne 0; then 220603fc0a3Smrg rm -f "$tmpdepfile" 221603fc0a3Smrg exit $stat 222603fc0a3Smrg fi 223603fc0a3Smrg rm -f "$depfile" 224603fc0a3Smrg echo "$object : \\" > "$depfile" 225603fc0a3Smrg # The second -e expression handles DOS-style file names with drive 226603fc0a3Smrg # letters. 227603fc0a3Smrg sed -e 's/^[^:]*: / /' \ 228603fc0a3Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229603fc0a3Smrg## This next piece of magic avoids the "deleted header file" problem. 230603fc0a3Smrg## The problem is that when a header file which appears in a .P file 231603fc0a3Smrg## is deleted, the dependency causes make to die (because there is 232603fc0a3Smrg## typically no way to rebuild the header). We avoid this by adding 233603fc0a3Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234603fc0a3Smrg## this for us directly. 235603fc0a3Smrg## Some versions of gcc put a space before the ':'. On the theory 236603fc0a3Smrg## that the space means something, we add a space to the output as 237603fc0a3Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238603fc0a3Smrg## to the object. Take care to not repeat it in the output. 239603fc0a3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240603fc0a3Smrg## correctly. Breaking it into two sed invocations is a workaround. 241603fc0a3Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242603fc0a3Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243603fc0a3Smrg | sed -e 's/$/ :/' >> "$depfile" 244603fc0a3Smrg rm -f "$tmpdepfile" 245603fc0a3Smrg ;; 246603fc0a3Smrg 247603fc0a3Smrghp) 248603fc0a3Smrg # This case exists only to let depend.m4 do its work. It works by 249603fc0a3Smrg # looking at the text of this script. This case will never be run, 250603fc0a3Smrg # since it is checked for above. 251603fc0a3Smrg exit 1 252603fc0a3Smrg ;; 253603fc0a3Smrg 254603fc0a3Smrgsgi) 255603fc0a3Smrg if test "$libtool" = yes; then 256603fc0a3Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257603fc0a3Smrg else 258603fc0a3Smrg "$@" -MDupdate "$tmpdepfile" 259603fc0a3Smrg fi 260603fc0a3Smrg stat=$? 261603fc0a3Smrg if test $stat -ne 0; then 262603fc0a3Smrg rm -f "$tmpdepfile" 263603fc0a3Smrg exit $stat 264603fc0a3Smrg fi 265603fc0a3Smrg rm -f "$depfile" 266603fc0a3Smrg 267603fc0a3Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268603fc0a3Smrg echo "$object : \\" > "$depfile" 269603fc0a3Smrg # Clip off the initial element (the dependent). Don't try to be 270603fc0a3Smrg # clever and replace this with sed code, as IRIX sed won't handle 271603fc0a3Smrg # lines with more than a fixed number of characters (4096 in 272603fc0a3Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273603fc0a3Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274603fc0a3Smrg # dependency line. 275603fc0a3Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276603fc0a3Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277603fc0a3Smrg | tr "$nl" ' ' >> "$depfile" 278603fc0a3Smrg echo >> "$depfile" 279603fc0a3Smrg # The second pass generates a dummy entry for each header file. 280603fc0a3Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281603fc0a3Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282603fc0a3Smrg >> "$depfile" 283603fc0a3Smrg else 284603fc0a3Smrg make_dummy_depfile 285603fc0a3Smrg fi 286603fc0a3Smrg rm -f "$tmpdepfile" 287603fc0a3Smrg ;; 288603fc0a3Smrg 289603fc0a3Smrgxlc) 290603fc0a3Smrg # This case exists only to let depend.m4 do its work. It works by 291603fc0a3Smrg # looking at the text of this script. This case will never be run, 292603fc0a3Smrg # since it is checked for above. 293603fc0a3Smrg exit 1 294603fc0a3Smrg ;; 295603fc0a3Smrg 296603fc0a3Smrgaix) 297603fc0a3Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298603fc0a3Smrg # in a .u file. In older versions, this file always lives in the 299603fc0a3Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300603fc0a3Smrg # start of each line; $object doesn't have directory information. 301603fc0a3Smrg # Version 6 uses the directory in both cases. 302603fc0a3Smrg set_dir_from "$object" 303603fc0a3Smrg set_base_from "$object" 304603fc0a3Smrg if test "$libtool" = yes; then 305603fc0a3Smrg tmpdepfile1=$dir$base.u 306603fc0a3Smrg tmpdepfile2=$base.u 307603fc0a3Smrg tmpdepfile3=$dir.libs/$base.u 308603fc0a3Smrg "$@" -Wc,-M 309603fc0a3Smrg else 310603fc0a3Smrg tmpdepfile1=$dir$base.u 311603fc0a3Smrg tmpdepfile2=$dir$base.u 312603fc0a3Smrg tmpdepfile3=$dir$base.u 313603fc0a3Smrg "$@" -M 314603fc0a3Smrg fi 315603fc0a3Smrg stat=$? 316603fc0a3Smrg if test $stat -ne 0; then 317603fc0a3Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318603fc0a3Smrg exit $stat 319603fc0a3Smrg fi 320603fc0a3Smrg 321603fc0a3Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322603fc0a3Smrg do 323603fc0a3Smrg test -f "$tmpdepfile" && break 324603fc0a3Smrg done 325603fc0a3Smrg aix_post_process_depfile 326603fc0a3Smrg ;; 327603fc0a3Smrg 328603fc0a3Smrgtcc) 329603fc0a3Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330603fc0a3Smrg # FIXME: That version still under development at the moment of writing. 331603fc0a3Smrg # Make that this statement remains true also for stable, released 332603fc0a3Smrg # versions. 333603fc0a3Smrg # It will wrap lines (doesn't matter whether long or short) with a 334603fc0a3Smrg # trailing '\', as in: 335603fc0a3Smrg # 336603fc0a3Smrg # foo.o : \ 337603fc0a3Smrg # foo.c \ 338603fc0a3Smrg # foo.h \ 339603fc0a3Smrg # 340603fc0a3Smrg # It will put a trailing '\' even on the last line, and will use leading 341603fc0a3Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342603fc0a3Smrg # "Emit spaces for -MD"). 343603fc0a3Smrg "$@" -MD -MF "$tmpdepfile" 344603fc0a3Smrg stat=$? 345603fc0a3Smrg if test $stat -ne 0; then 346603fc0a3Smrg rm -f "$tmpdepfile" 347603fc0a3Smrg exit $stat 348603fc0a3Smrg fi 349603fc0a3Smrg rm -f "$depfile" 350603fc0a3Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351603fc0a3Smrg # We have to change lines of the first kind to '$object: \'. 352603fc0a3Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353603fc0a3Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354603fc0a3Smrg # dummy dependency, to avoid the deleted-header problem. 355603fc0a3Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356603fc0a3Smrg rm -f "$tmpdepfile" 357603fc0a3Smrg ;; 358603fc0a3Smrg 359603fc0a3Smrg## The order of this option in the case statement is important, since the 360603fc0a3Smrg## shell code in configure will try each of these formats in the order 361603fc0a3Smrg## listed in this file. A plain '-MD' option would be understood by many 362603fc0a3Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363603fc0a3Smrgpgcc) 364603fc0a3Smrg # Portland's C compiler understands '-MD'. 365603fc0a3Smrg # Will always output deps to 'file.d' where file is the root name of the 366603fc0a3Smrg # source file under compilation, even if file resides in a subdirectory. 367603fc0a3Smrg # The object file name does not affect the name of the '.d' file. 368603fc0a3Smrg # pgcc 10.2 will output 369603fc0a3Smrg # foo.o: sub/foo.c sub/foo.h 370603fc0a3Smrg # and will wrap long lines using '\' : 371603fc0a3Smrg # foo.o: sub/foo.c ... \ 372603fc0a3Smrg # sub/foo.h ... \ 373603fc0a3Smrg # ... 374603fc0a3Smrg set_dir_from "$object" 375603fc0a3Smrg # Use the source, not the object, to determine the base name, since 376603fc0a3Smrg # that's sadly what pgcc will do too. 377603fc0a3Smrg set_base_from "$source" 378603fc0a3Smrg tmpdepfile=$base.d 379603fc0a3Smrg 380603fc0a3Smrg # For projects that build the same source file twice into different object 381603fc0a3Smrg # files, the pgcc approach of using the *source* file root name can cause 382603fc0a3Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383603fc0a3Smrg # the same $tmpdepfile. 384603fc0a3Smrg lockdir=$base.d-lock 385603fc0a3Smrg trap " 386603fc0a3Smrg echo '$0: caught signal, cleaning up...' >&2 387603fc0a3Smrg rmdir '$lockdir' 388603fc0a3Smrg exit 1 389603fc0a3Smrg " 1 2 13 15 390603fc0a3Smrg numtries=100 391603fc0a3Smrg i=$numtries 392603fc0a3Smrg while test $i -gt 0; do 393603fc0a3Smrg # mkdir is a portable test-and-set. 394603fc0a3Smrg if mkdir "$lockdir" 2>/dev/null; then 395603fc0a3Smrg # This process acquired the lock. 396603fc0a3Smrg "$@" -MD 397603fc0a3Smrg stat=$? 398603fc0a3Smrg # Release the lock. 399603fc0a3Smrg rmdir "$lockdir" 400603fc0a3Smrg break 401603fc0a3Smrg else 402603fc0a3Smrg # If the lock is being held by a different process, wait 403603fc0a3Smrg # until the winning process is done or we timeout. 404603fc0a3Smrg while test -d "$lockdir" && test $i -gt 0; do 405603fc0a3Smrg sleep 1 406603fc0a3Smrg i=`expr $i - 1` 407603fc0a3Smrg done 408603fc0a3Smrg fi 409603fc0a3Smrg i=`expr $i - 1` 410603fc0a3Smrg done 411603fc0a3Smrg trap - 1 2 13 15 412603fc0a3Smrg if test $i -le 0; then 413603fc0a3Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414603fc0a3Smrg echo "$0: check lockdir '$lockdir'" >&2 415603fc0a3Smrg exit 1 416603fc0a3Smrg fi 417603fc0a3Smrg 418603fc0a3Smrg if test $stat -ne 0; then 419603fc0a3Smrg rm -f "$tmpdepfile" 420603fc0a3Smrg exit $stat 421603fc0a3Smrg fi 422603fc0a3Smrg rm -f "$depfile" 423603fc0a3Smrg # Each line is of the form `foo.o: dependent.h', 424603fc0a3Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425603fc0a3Smrg # Do two passes, one to just change these to 426603fc0a3Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427603fc0a3Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428603fc0a3Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429603fc0a3Smrg # correctly. Breaking it into two sed invocations is a workaround. 430603fc0a3Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431603fc0a3Smrg | sed -e 's/$/ :/' >> "$depfile" 432603fc0a3Smrg rm -f "$tmpdepfile" 433603fc0a3Smrg ;; 434603fc0a3Smrg 435603fc0a3Smrghp2) 436603fc0a3Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437603fc0a3Smrg # compilers, which have integrated preprocessors. The correct option 438603fc0a3Smrg # to use with these is +Maked; it writes dependencies to a file named 439603fc0a3Smrg # 'foo.d', which lands next to the object file, wherever that 440603fc0a3Smrg # happens to be. 441603fc0a3Smrg # Much of this is similar to the tru64 case; see comments there. 442603fc0a3Smrg set_dir_from "$object" 443603fc0a3Smrg set_base_from "$object" 444603fc0a3Smrg if test "$libtool" = yes; then 445603fc0a3Smrg tmpdepfile1=$dir$base.d 446603fc0a3Smrg tmpdepfile2=$dir.libs/$base.d 447603fc0a3Smrg "$@" -Wc,+Maked 448603fc0a3Smrg else 449603fc0a3Smrg tmpdepfile1=$dir$base.d 450603fc0a3Smrg tmpdepfile2=$dir$base.d 451603fc0a3Smrg "$@" +Maked 452603fc0a3Smrg fi 453603fc0a3Smrg stat=$? 454603fc0a3Smrg if test $stat -ne 0; then 455603fc0a3Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456603fc0a3Smrg exit $stat 457603fc0a3Smrg fi 458603fc0a3Smrg 459603fc0a3Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460603fc0a3Smrg do 461603fc0a3Smrg test -f "$tmpdepfile" && break 462603fc0a3Smrg done 463603fc0a3Smrg if test -f "$tmpdepfile"; then 464603fc0a3Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465603fc0a3Smrg # Add 'dependent.h:' lines. 466603fc0a3Smrg sed -ne '2,${ 467603fc0a3Smrg s/^ *// 468603fc0a3Smrg s/ \\*$// 469603fc0a3Smrg s/$/:/ 470603fc0a3Smrg p 471603fc0a3Smrg }' "$tmpdepfile" >> "$depfile" 472603fc0a3Smrg else 473603fc0a3Smrg make_dummy_depfile 474603fc0a3Smrg fi 475603fc0a3Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 476603fc0a3Smrg ;; 477603fc0a3Smrg 478603fc0a3Smrgtru64) 479603fc0a3Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480603fc0a3Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481603fc0a3Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482603fc0a3Smrg # dependencies in 'foo.d' instead, so we check for that too. 483603fc0a3Smrg # Subdirectories are respected. 484603fc0a3Smrg set_dir_from "$object" 485603fc0a3Smrg set_base_from "$object" 486603fc0a3Smrg 487603fc0a3Smrg if test "$libtool" = yes; then 488603fc0a3Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489603fc0a3Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490603fc0a3Smrg # in $dir$base.o.d. We have to check for both files, because 491603fc0a3Smrg # one of the two compilations can be disabled. We should prefer 492603fc0a3Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493603fc0a3Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494603fc0a3Smrg # the former would cause a distcleancheck panic. 495603fc0a3Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496603fc0a3Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497603fc0a3Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498603fc0a3Smrg "$@" -Wc,-MD 499603fc0a3Smrg else 500603fc0a3Smrg tmpdepfile1=$dir$base.d 501603fc0a3Smrg tmpdepfile2=$dir$base.d 502603fc0a3Smrg tmpdepfile3=$dir$base.d 503603fc0a3Smrg "$@" -MD 504603fc0a3Smrg fi 505603fc0a3Smrg 506603fc0a3Smrg stat=$? 507603fc0a3Smrg if test $stat -ne 0; then 508603fc0a3Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509603fc0a3Smrg exit $stat 510603fc0a3Smrg fi 511603fc0a3Smrg 512603fc0a3Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513603fc0a3Smrg do 514603fc0a3Smrg test -f "$tmpdepfile" && break 515603fc0a3Smrg done 516603fc0a3Smrg # Same post-processing that is required for AIX mode. 517603fc0a3Smrg aix_post_process_depfile 518603fc0a3Smrg ;; 519603fc0a3Smrg 520603fc0a3Smrgmsvc7) 521603fc0a3Smrg if test "$libtool" = yes; then 522603fc0a3Smrg showIncludes=-Wc,-showIncludes 523603fc0a3Smrg else 524603fc0a3Smrg showIncludes=-showIncludes 525603fc0a3Smrg fi 526603fc0a3Smrg "$@" $showIncludes > "$tmpdepfile" 527603fc0a3Smrg stat=$? 528603fc0a3Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529603fc0a3Smrg if test $stat -ne 0; then 530603fc0a3Smrg rm -f "$tmpdepfile" 531603fc0a3Smrg exit $stat 532603fc0a3Smrg fi 533603fc0a3Smrg rm -f "$depfile" 534603fc0a3Smrg echo "$object : \\" > "$depfile" 535603fc0a3Smrg # The first sed program below extracts the file names and escapes 536603fc0a3Smrg # backslashes for cygpath. The second sed program outputs the file 537603fc0a3Smrg # name when reading, but also accumulates all include files in the 538603fc0a3Smrg # hold buffer in order to output them again at the end. This only 539603fc0a3Smrg # works with sed implementations that can handle large buffers. 540603fc0a3Smrg sed < "$tmpdepfile" -n ' 541603fc0a3Smrg/^Note: including file: *\(.*\)/ { 542603fc0a3Smrg s//\1/ 543603fc0a3Smrg s/\\/\\\\/g 544603fc0a3Smrg p 545603fc0a3Smrg}' | $cygpath_u | sort -u | sed -n ' 546603fc0a3Smrgs/ /\\ /g 547603fc0a3Smrgs/\(.*\)/'"$tab"'\1 \\/p 548603fc0a3Smrgs/.\(.*\) \\/\1:/ 549603fc0a3SmrgH 550603fc0a3Smrg$ { 551603fc0a3Smrg s/.*/'"$tab"'/ 552603fc0a3Smrg G 553603fc0a3Smrg p 554603fc0a3Smrg}' >> "$depfile" 555603fc0a3Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556603fc0a3Smrg rm -f "$tmpdepfile" 557603fc0a3Smrg ;; 558603fc0a3Smrg 559603fc0a3Smrgmsvc7msys) 560603fc0a3Smrg # This case exists only to let depend.m4 do its work. It works by 561603fc0a3Smrg # looking at the text of this script. This case will never be run, 562603fc0a3Smrg # since it is checked for above. 563603fc0a3Smrg exit 1 564603fc0a3Smrg ;; 565603fc0a3Smrg 566603fc0a3Smrg#nosideeffect) 567603fc0a3Smrg # This comment above is used by automake to tell side-effect 568603fc0a3Smrg # dependency tracking mechanisms from slower ones. 569603fc0a3Smrg 570603fc0a3Smrgdashmstdout) 571603fc0a3Smrg # Important note: in order to support this mode, a compiler *must* 572603fc0a3Smrg # always write the preprocessed file to stdout, regardless of -o. 573603fc0a3Smrg "$@" || exit $? 574603fc0a3Smrg 575603fc0a3Smrg # Remove the call to Libtool. 576603fc0a3Smrg if test "$libtool" = yes; then 577603fc0a3Smrg while test "X$1" != 'X--mode=compile'; do 578603fc0a3Smrg shift 579603fc0a3Smrg done 580603fc0a3Smrg shift 581603fc0a3Smrg fi 582603fc0a3Smrg 583603fc0a3Smrg # Remove '-o $object'. 584603fc0a3Smrg IFS=" " 585603fc0a3Smrg for arg 586603fc0a3Smrg do 587603fc0a3Smrg case $arg in 588603fc0a3Smrg -o) 589603fc0a3Smrg shift 590603fc0a3Smrg ;; 591603fc0a3Smrg $object) 592603fc0a3Smrg shift 593603fc0a3Smrg ;; 594603fc0a3Smrg *) 595603fc0a3Smrg set fnord "$@" "$arg" 596603fc0a3Smrg shift # fnord 597603fc0a3Smrg shift # $arg 598603fc0a3Smrg ;; 599603fc0a3Smrg esac 600603fc0a3Smrg done 601603fc0a3Smrg 602603fc0a3Smrg test -z "$dashmflag" && dashmflag=-M 603603fc0a3Smrg # Require at least two characters before searching for ':' 604603fc0a3Smrg # in the target name. This is to cope with DOS-style filenames: 605603fc0a3Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606603fc0a3Smrg "$@" $dashmflag | 607603fc0a3Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608603fc0a3Smrg rm -f "$depfile" 609603fc0a3Smrg cat < "$tmpdepfile" > "$depfile" 610603fc0a3Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611603fc0a3Smrg # correctly. Breaking it into two sed invocations is a workaround. 612603fc0a3Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613603fc0a3Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614603fc0a3Smrg | sed -e 's/$/ :/' >> "$depfile" 615603fc0a3Smrg rm -f "$tmpdepfile" 616603fc0a3Smrg ;; 617603fc0a3Smrg 618603fc0a3SmrgdashXmstdout) 619603fc0a3Smrg # This case only exists to satisfy depend.m4. It is never actually 620603fc0a3Smrg # run, as this mode is specially recognized in the preamble. 621603fc0a3Smrg exit 1 622603fc0a3Smrg ;; 623603fc0a3Smrg 624603fc0a3Smrgmakedepend) 625603fc0a3Smrg "$@" || exit $? 626603fc0a3Smrg # Remove any Libtool call 627603fc0a3Smrg if test "$libtool" = yes; then 628603fc0a3Smrg while test "X$1" != 'X--mode=compile'; do 629603fc0a3Smrg shift 630603fc0a3Smrg done 631603fc0a3Smrg shift 632603fc0a3Smrg fi 633603fc0a3Smrg # X makedepend 634603fc0a3Smrg shift 635603fc0a3Smrg cleared=no eat=no 636603fc0a3Smrg for arg 637603fc0a3Smrg do 638603fc0a3Smrg case $cleared in 639603fc0a3Smrg no) 640603fc0a3Smrg set ""; shift 641603fc0a3Smrg cleared=yes ;; 642603fc0a3Smrg esac 643603fc0a3Smrg if test $eat = yes; then 644603fc0a3Smrg eat=no 645603fc0a3Smrg continue 646603fc0a3Smrg fi 647603fc0a3Smrg case "$arg" in 648603fc0a3Smrg -D*|-I*) 649603fc0a3Smrg set fnord "$@" "$arg"; shift ;; 650603fc0a3Smrg # Strip any option that makedepend may not understand. Remove 651603fc0a3Smrg # the object too, otherwise makedepend will parse it as a source file. 652603fc0a3Smrg -arch) 653603fc0a3Smrg eat=yes ;; 654603fc0a3Smrg -*|$object) 655603fc0a3Smrg ;; 656603fc0a3Smrg *) 657603fc0a3Smrg set fnord "$@" "$arg"; shift ;; 658603fc0a3Smrg esac 659603fc0a3Smrg done 660603fc0a3Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661603fc0a3Smrg touch "$tmpdepfile" 662603fc0a3Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663603fc0a3Smrg rm -f "$depfile" 664603fc0a3Smrg # makedepend may prepend the VPATH from the source file name to the object. 665603fc0a3Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666603fc0a3Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667603fc0a3Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668603fc0a3Smrg # correctly. Breaking it into two sed invocations is a workaround. 669603fc0a3Smrg sed '1,2d' "$tmpdepfile" \ 670603fc0a3Smrg | tr ' ' "$nl" \ 671603fc0a3Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672603fc0a3Smrg | sed -e 's/$/ :/' >> "$depfile" 673603fc0a3Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674603fc0a3Smrg ;; 675603fc0a3Smrg 676603fc0a3Smrgcpp) 677603fc0a3Smrg # Important note: in order to support this mode, a compiler *must* 678603fc0a3Smrg # always write the preprocessed file to stdout. 679603fc0a3Smrg "$@" || exit $? 680603fc0a3Smrg 681603fc0a3Smrg # Remove the call to Libtool. 682603fc0a3Smrg if test "$libtool" = yes; then 683603fc0a3Smrg while test "X$1" != 'X--mode=compile'; do 684603fc0a3Smrg shift 685603fc0a3Smrg done 686603fc0a3Smrg shift 687603fc0a3Smrg fi 688603fc0a3Smrg 689603fc0a3Smrg # Remove '-o $object'. 690603fc0a3Smrg IFS=" " 691603fc0a3Smrg for arg 692603fc0a3Smrg do 693603fc0a3Smrg case $arg in 694603fc0a3Smrg -o) 695603fc0a3Smrg shift 696603fc0a3Smrg ;; 697603fc0a3Smrg $object) 698603fc0a3Smrg shift 699603fc0a3Smrg ;; 700603fc0a3Smrg *) 701603fc0a3Smrg set fnord "$@" "$arg" 702603fc0a3Smrg shift # fnord 703603fc0a3Smrg shift # $arg 704603fc0a3Smrg ;; 705603fc0a3Smrg esac 706603fc0a3Smrg done 707603fc0a3Smrg 708603fc0a3Smrg "$@" -E \ 709603fc0a3Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710603fc0a3Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711603fc0a3Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712603fc0a3Smrg rm -f "$depfile" 713603fc0a3Smrg echo "$object : \\" > "$depfile" 714603fc0a3Smrg cat < "$tmpdepfile" >> "$depfile" 715603fc0a3Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716603fc0a3Smrg rm -f "$tmpdepfile" 717603fc0a3Smrg ;; 718603fc0a3Smrg 719603fc0a3Smrgmsvisualcpp) 720603fc0a3Smrg # Important note: in order to support this mode, a compiler *must* 721603fc0a3Smrg # always write the preprocessed file to stdout. 722603fc0a3Smrg "$@" || exit $? 723603fc0a3Smrg 724603fc0a3Smrg # Remove the call to Libtool. 725603fc0a3Smrg if test "$libtool" = yes; then 726603fc0a3Smrg while test "X$1" != 'X--mode=compile'; do 727603fc0a3Smrg shift 728603fc0a3Smrg done 729603fc0a3Smrg shift 730603fc0a3Smrg fi 731603fc0a3Smrg 732603fc0a3Smrg IFS=" " 733603fc0a3Smrg for arg 734603fc0a3Smrg do 735603fc0a3Smrg case "$arg" in 736603fc0a3Smrg -o) 737603fc0a3Smrg shift 738603fc0a3Smrg ;; 739603fc0a3Smrg $object) 740603fc0a3Smrg shift 741603fc0a3Smrg ;; 742603fc0a3Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743603fc0a3Smrg set fnord "$@" 744603fc0a3Smrg shift 745603fc0a3Smrg shift 746603fc0a3Smrg ;; 747603fc0a3Smrg *) 748603fc0a3Smrg set fnord "$@" "$arg" 749603fc0a3Smrg shift 750603fc0a3Smrg shift 751603fc0a3Smrg ;; 752603fc0a3Smrg esac 753603fc0a3Smrg done 754603fc0a3Smrg "$@" -E 2>/dev/null | 755603fc0a3Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756603fc0a3Smrg rm -f "$depfile" 757603fc0a3Smrg echo "$object : \\" > "$depfile" 758603fc0a3Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759603fc0a3Smrg echo "$tab" >> "$depfile" 760603fc0a3Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761603fc0a3Smrg rm -f "$tmpdepfile" 762603fc0a3Smrg ;; 763603fc0a3Smrg 764603fc0a3Smrgmsvcmsys) 765603fc0a3Smrg # This case exists only to let depend.m4 do its work. It works by 766603fc0a3Smrg # looking at the text of this script. This case will never be run, 767603fc0a3Smrg # since it is checked for above. 768603fc0a3Smrg exit 1 769603fc0a3Smrg ;; 770603fc0a3Smrg 771603fc0a3Smrgnone) 772603fc0a3Smrg exec "$@" 773603fc0a3Smrg ;; 774603fc0a3Smrg 775603fc0a3Smrg*) 776603fc0a3Smrg echo "Unknown depmode $depmode" 1>&2 777603fc0a3Smrg exit 1 778603fc0a3Smrg ;; 779603fc0a3Smrgesac 780603fc0a3Smrg 781603fc0a3Smrgexit 0 782603fc0a3Smrg 783603fc0a3Smrg# Local Variables: 784603fc0a3Smrg# mode: shell-script 785603fc0a3Smrg# sh-indentation: 2 786603fc0a3Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 787603fc0a3Smrg# time-stamp-start: "scriptversion=" 788603fc0a3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789603fc0a3Smrg# time-stamp-time-zone: "UTC0" 790603fc0a3Smrg# time-stamp-end: "; # UTC" 791603fc0a3Smrg# End: 792