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