1c76ae52dSmrg#! /bin/sh 2c76ae52dSmrg# depcomp - compile a program generating dependencies as side-effects 3c76ae52dSmrg 484febdacSmrgscriptversion=2018-03-07.03; # UTC 5c76ae52dSmrg 625420f97Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7c76ae52dSmrg 8c76ae52dSmrg# This program is free software; you can redistribute it and/or modify 9c76ae52dSmrg# it under the terms of the GNU General Public License as published by 10c76ae52dSmrg# the Free Software Foundation; either version 2, or (at your option) 11c76ae52dSmrg# any later version. 12c76ae52dSmrg 13c76ae52dSmrg# This program is distributed in the hope that it will be useful, 14c76ae52dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15c76ae52dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c76ae52dSmrg# GNU General Public License for more details. 17c76ae52dSmrg 18c76ae52dSmrg# You should have received a copy of the GNU General Public License 1984febdacSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20c76ae52dSmrg 21c76ae52dSmrg# As a special exception to the GNU General Public License, if you 22c76ae52dSmrg# distribute this file as part of a program that contains a 23c76ae52dSmrg# configuration script generated by Autoconf, you may include it under 24c76ae52dSmrg# the same distribution terms that you use for the rest of that program. 25c76ae52dSmrg 26c76ae52dSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27c76ae52dSmrg 28c76ae52dSmrgcase $1 in 29c76ae52dSmrg '') 30dff01e5aSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31dff01e5aSmrg exit 1; 32dff01e5aSmrg ;; 33c76ae52dSmrg -h | --h*) 34c76ae52dSmrg cat <<\EOF 35c76ae52dSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36c76ae52dSmrg 37c76ae52dSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38c76ae52dSmrgas side-effects. 39c76ae52dSmrg 40c76ae52dSmrgEnvironment variables: 41c76ae52dSmrg depmode Dependency tracking mode. 42dff01e5aSmrg source Source file read by 'PROGRAMS ARGS'. 43dff01e5aSmrg object Object file output by 'PROGRAMS ARGS'. 44c76ae52dSmrg DEPDIR directory where to store dependencies. 45c76ae52dSmrg depfile Dependency file to output. 462836776bSmrg tmpdepfile Temporary file to use when outputting dependencies. 47c76ae52dSmrg libtool Whether libtool is used (yes/no). 48c76ae52dSmrg 49c76ae52dSmrgReport bugs to <bug-automake@gnu.org>. 50c76ae52dSmrgEOF 51c76ae52dSmrg exit $? 52c76ae52dSmrg ;; 53c76ae52dSmrg -v | --v*) 54c76ae52dSmrg echo "depcomp $scriptversion" 55c76ae52dSmrg exit $? 56c76ae52dSmrg ;; 57c76ae52dSmrgesac 58c76ae52dSmrg 59dff01e5aSmrg# Get the directory component of the given path, and save it in the 60dff01e5aSmrg# global variables '$dir'. Note that this directory component will 61dff01e5aSmrg# be either empty or ending with a '/' character. This is deliberate. 62dff01e5aSmrgset_dir_from () 63dff01e5aSmrg{ 64dff01e5aSmrg case $1 in 65dff01e5aSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66dff01e5aSmrg *) dir=;; 67dff01e5aSmrg esac 68dff01e5aSmrg} 69dff01e5aSmrg 70dff01e5aSmrg# Get the suffix-stripped basename of the given path, and save it the 71dff01e5aSmrg# global variable '$base'. 72dff01e5aSmrgset_base_from () 73dff01e5aSmrg{ 74dff01e5aSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75dff01e5aSmrg} 76dff01e5aSmrg 77dff01e5aSmrg# If no dependency file was actually created by the compiler invocation, 78dff01e5aSmrg# we still have to create a dummy depfile, to avoid errors with the 79dff01e5aSmrg# Makefile "include basename.Plo" scheme. 80dff01e5aSmrgmake_dummy_depfile () 81dff01e5aSmrg{ 82dff01e5aSmrg echo "#dummy" > "$depfile" 83dff01e5aSmrg} 84dff01e5aSmrg 85dff01e5aSmrg# Factor out some common post-processing of the generated depfile. 86dff01e5aSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87dff01e5aSmrgaix_post_process_depfile () 88dff01e5aSmrg{ 89dff01e5aSmrg # If the compiler actually managed to produce a dependency file, 90dff01e5aSmrg # post-process it. 91dff01e5aSmrg if test -f "$tmpdepfile"; then 92dff01e5aSmrg # Each line is of the form 'foo.o: dependency.h'. 93dff01e5aSmrg # Do two passes, one to just change these to 94dff01e5aSmrg # $object: dependency.h 95dff01e5aSmrg # and one to simply output 96dff01e5aSmrg # dependency.h: 97dff01e5aSmrg # which is needed to avoid the deleted-header problem. 98dff01e5aSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99dff01e5aSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100dff01e5aSmrg } > "$depfile" 101dff01e5aSmrg rm -f "$tmpdepfile" 102dff01e5aSmrg else 103dff01e5aSmrg make_dummy_depfile 104dff01e5aSmrg fi 105dff01e5aSmrg} 106dff01e5aSmrg 107dff01e5aSmrg# A tabulation character. 108dff01e5aSmrgtab=' ' 109dff01e5aSmrg# A newline character. 110dff01e5aSmrgnl=' 111dff01e5aSmrg' 112dff01e5aSmrg# Character ranges might be problematic outside the C locale. 113dff01e5aSmrg# These definitions help. 114dff01e5aSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115dff01e5aSmrglower=abcdefghijklmnopqrstuvwxyz 116dff01e5aSmrgdigits=0123456789 117dff01e5aSmrgalpha=${upper}${lower} 118dff01e5aSmrg 119c76ae52dSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120c76ae52dSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121c76ae52dSmrg exit 1 122c76ae52dSmrgfi 123c76ae52dSmrg 124c76ae52dSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125c76ae52dSmrgdepfile=${depfile-`echo "$object" | 126c76ae52dSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127c76ae52dSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128c76ae52dSmrg 129c76ae52dSmrgrm -f "$tmpdepfile" 130c76ae52dSmrg 131dff01e5aSmrg# Avoid interferences from the environment. 132dff01e5aSmrggccflag= dashmflag= 133dff01e5aSmrg 134c76ae52dSmrg# Some modes work just like other modes, but use different flags. We 135c76ae52dSmrg# parameterize here, but still list the modes in the big case below, 136c76ae52dSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137c76ae52dSmrg# here, because this file can only contain one case statement. 138c76ae52dSmrgif test "$depmode" = hp; then 139c76ae52dSmrg # HP compiler uses -M and no extra arg. 140c76ae52dSmrg gccflag=-M 141c76ae52dSmrg depmode=gcc 142c76ae52dSmrgfi 143c76ae52dSmrg 144c76ae52dSmrgif test "$depmode" = dashXmstdout; then 145dff01e5aSmrg # This is just like dashmstdout with a different argument. 146dff01e5aSmrg dashmflag=-xM 147dff01e5aSmrg depmode=dashmstdout 148c76ae52dSmrgfi 149c76ae52dSmrg 1500d590c07Smrgcygpath_u="cygpath -u -f -" 1510d590c07Smrgif test "$depmode" = msvcmsys; then 152dff01e5aSmrg # This is just like msvisualcpp but w/o cygpath translation. 153dff01e5aSmrg # Just convert the backslash-escaped backslashes to single forward 154dff01e5aSmrg # slashes to satisfy depend.m4 155dff01e5aSmrg cygpath_u='sed s,\\\\,/,g' 156dff01e5aSmrg depmode=msvisualcpp 1570d590c07Smrgfi 1580d590c07Smrg 1592836776bSmrgif test "$depmode" = msvc7msys; then 160dff01e5aSmrg # This is just like msvc7 but w/o cygpath translation. 161dff01e5aSmrg # Just convert the backslash-escaped backslashes to single forward 162dff01e5aSmrg # slashes to satisfy depend.m4 163dff01e5aSmrg cygpath_u='sed s,\\\\,/,g' 164dff01e5aSmrg depmode=msvc7 165dff01e5aSmrgfi 166dff01e5aSmrg 167dff01e5aSmrgif test "$depmode" = xlc; then 168dff01e5aSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169dff01e5aSmrg gccflag=-qmakedep=gcc,-MF 170dff01e5aSmrg depmode=gcc 1712836776bSmrgfi 1722836776bSmrg 173c76ae52dSmrgcase "$depmode" in 174c76ae52dSmrggcc3) 175c76ae52dSmrg## gcc 3 implements dependency tracking that does exactly what 176c76ae52dSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177c76ae52dSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 1780d590c07Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1790d590c07Smrg## the command line argument order; so add the flags where they 1800d590c07Smrg## appear in depend2.am. Note that the slowdown incurred here 1810d590c07Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1820d590c07Smrg for arg 1830d590c07Smrg do 1840d590c07Smrg case $arg in 1850d590c07Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1860d590c07Smrg *) set fnord "$@" "$arg" ;; 1870d590c07Smrg esac 1880d590c07Smrg shift # fnord 1890d590c07Smrg shift # $arg 1900d590c07Smrg done 1910d590c07Smrg "$@" 192c76ae52dSmrg stat=$? 193dff01e5aSmrg if test $stat -ne 0; then 194c76ae52dSmrg rm -f "$tmpdepfile" 195c76ae52dSmrg exit $stat 196c76ae52dSmrg fi 197c76ae52dSmrg mv "$tmpdepfile" "$depfile" 198c76ae52dSmrg ;; 199c76ae52dSmrg 200c76ae52dSmrggcc) 201dff01e5aSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202dff01e5aSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203dff01e5aSmrg## (see the conditional assignment to $gccflag above). 204c76ae52dSmrg## There are various ways to get dependency output from gcc. Here's 205c76ae52dSmrg## why we pick this rather obscure method: 206c76ae52dSmrg## - Don't want to use -MD because we'd like the dependencies to end 207c76ae52dSmrg## up in a subdir. Having to rename by hand is ugly. 208c76ae52dSmrg## (We might end up doing this anyway to support other compilers.) 209c76ae52dSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210dff01e5aSmrg## -MM, not -M (despite what the docs say). Also, it might not be 211dff01e5aSmrg## supported by the other compilers which use the 'gcc' depmode. 212c76ae52dSmrg## - Using -M directly means running the compiler twice (even worse 213c76ae52dSmrg## than renaming). 214c76ae52dSmrg if test -z "$gccflag"; then 215c76ae52dSmrg gccflag=-MD, 216c76ae52dSmrg fi 217c76ae52dSmrg "$@" -Wp,"$gccflag$tmpdepfile" 218c76ae52dSmrg stat=$? 219dff01e5aSmrg if test $stat -ne 0; then 220c76ae52dSmrg rm -f "$tmpdepfile" 221c76ae52dSmrg exit $stat 222c76ae52dSmrg fi 223c76ae52dSmrg rm -f "$depfile" 224c76ae52dSmrg echo "$object : \\" > "$depfile" 225dff01e5aSmrg # The second -e expression handles DOS-style file names with drive 226dff01e5aSmrg # letters. 227c76ae52dSmrg sed -e 's/^[^:]*: / /' \ 228c76ae52dSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229dff01e5aSmrg## This next piece of magic avoids the "deleted header file" problem. 230c76ae52dSmrg## The problem is that when a header file which appears in a .P file 231c76ae52dSmrg## is deleted, the dependency causes make to die (because there is 232c76ae52dSmrg## typically no way to rebuild the header). We avoid this by adding 233c76ae52dSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 234c76ae52dSmrg## this for us directly. 235dff01e5aSmrg## Some versions of gcc put a space before the ':'. On the theory 236c76ae52dSmrg## that the space means something, we add a space to the output as 2372836776bSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 2382836776bSmrg## to the object. Take care to not repeat it in the output. 239c76ae52dSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 240c76ae52dSmrg## correctly. Breaking it into two sed invocations is a workaround. 241dff01e5aSmrg tr ' ' "$nl" < "$tmpdepfile" \ 242dff01e5aSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243dff01e5aSmrg | sed -e 's/$/ :/' >> "$depfile" 244c76ae52dSmrg rm -f "$tmpdepfile" 245c76ae52dSmrg ;; 246c76ae52dSmrg 247c76ae52dSmrghp) 248c76ae52dSmrg # This case exists only to let depend.m4 do its work. It works by 249c76ae52dSmrg # looking at the text of this script. This case will never be run, 250c76ae52dSmrg # since it is checked for above. 251c76ae52dSmrg exit 1 252c76ae52dSmrg ;; 253c76ae52dSmrg 254c76ae52dSmrgsgi) 255c76ae52dSmrg if test "$libtool" = yes; then 256c76ae52dSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257c76ae52dSmrg else 258c76ae52dSmrg "$@" -MDupdate "$tmpdepfile" 259c76ae52dSmrg fi 260c76ae52dSmrg stat=$? 261dff01e5aSmrg if test $stat -ne 0; then 262c76ae52dSmrg rm -f "$tmpdepfile" 263c76ae52dSmrg exit $stat 264c76ae52dSmrg fi 265c76ae52dSmrg rm -f "$depfile" 266c76ae52dSmrg 267c76ae52dSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268c76ae52dSmrg echo "$object : \\" > "$depfile" 269c76ae52dSmrg # Clip off the initial element (the dependent). Don't try to be 270c76ae52dSmrg # clever and replace this with sed code, as IRIX sed won't handle 271c76ae52dSmrg # lines with more than a fixed number of characters (4096 in 272c76ae52dSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273dff01e5aSmrg # the IRIX cc adds comments like '#:fec' to the end of the 274c76ae52dSmrg # dependency line. 275dff01e5aSmrg tr ' ' "$nl" < "$tmpdepfile" \ 276dff01e5aSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277dff01e5aSmrg | tr "$nl" ' ' >> "$depfile" 2780d590c07Smrg echo >> "$depfile" 279c76ae52dSmrg # The second pass generates a dummy entry for each header file. 280dff01e5aSmrg tr ' ' "$nl" < "$tmpdepfile" \ 281dff01e5aSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282dff01e5aSmrg >> "$depfile" 283c76ae52dSmrg else 284dff01e5aSmrg make_dummy_depfile 285c76ae52dSmrg fi 286c76ae52dSmrg rm -f "$tmpdepfile" 287c76ae52dSmrg ;; 288c76ae52dSmrg 289dff01e5aSmrgxlc) 290dff01e5aSmrg # This case exists only to let depend.m4 do its work. It works by 291dff01e5aSmrg # looking at the text of this script. This case will never be run, 292dff01e5aSmrg # since it is checked for above. 293dff01e5aSmrg exit 1 294dff01e5aSmrg ;; 295dff01e5aSmrg 296c76ae52dSmrgaix) 297c76ae52dSmrg # The C for AIX Compiler uses -M and outputs the dependencies 298c76ae52dSmrg # in a .u file. In older versions, this file always lives in the 299dff01e5aSmrg # current directory. Also, the AIX compiler puts '$object:' at the 300c76ae52dSmrg # start of each line; $object doesn't have directory information. 301c76ae52dSmrg # Version 6 uses the directory in both cases. 302dff01e5aSmrg set_dir_from "$object" 303dff01e5aSmrg set_base_from "$object" 304c76ae52dSmrg if test "$libtool" = yes; then 3050d590c07Smrg tmpdepfile1=$dir$base.u 3060d590c07Smrg tmpdepfile2=$base.u 3070d590c07Smrg tmpdepfile3=$dir.libs/$base.u 308c76ae52dSmrg "$@" -Wc,-M 309c76ae52dSmrg else 3100d590c07Smrg tmpdepfile1=$dir$base.u 3110d590c07Smrg tmpdepfile2=$dir$base.u 3120d590c07Smrg tmpdepfile3=$dir$base.u 313c76ae52dSmrg "$@" -M 314c76ae52dSmrg fi 315c76ae52dSmrg stat=$? 316dff01e5aSmrg if test $stat -ne 0; then 3170d590c07Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318c76ae52dSmrg exit $stat 319c76ae52dSmrg fi 320c76ae52dSmrg 3210d590c07Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3220d590c07Smrg do 3230d590c07Smrg test -f "$tmpdepfile" && break 3240d590c07Smrg done 325dff01e5aSmrg aix_post_process_depfile 326dff01e5aSmrg ;; 327dff01e5aSmrg 328dff01e5aSmrgtcc) 329dff01e5aSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330dff01e5aSmrg # FIXME: That version still under development at the moment of writing. 331dff01e5aSmrg # Make that this statement remains true also for stable, released 332dff01e5aSmrg # versions. 333dff01e5aSmrg # It will wrap lines (doesn't matter whether long or short) with a 334dff01e5aSmrg # trailing '\', as in: 335dff01e5aSmrg # 336dff01e5aSmrg # foo.o : \ 337dff01e5aSmrg # foo.c \ 338dff01e5aSmrg # foo.h \ 339dff01e5aSmrg # 340dff01e5aSmrg # It will put a trailing '\' even on the last line, and will use leading 341dff01e5aSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 342dff01e5aSmrg # "Emit spaces for -MD"). 343dff01e5aSmrg "$@" -MD -MF "$tmpdepfile" 344dff01e5aSmrg stat=$? 345dff01e5aSmrg if test $stat -ne 0; then 346dff01e5aSmrg rm -f "$tmpdepfile" 347dff01e5aSmrg exit $stat 348c76ae52dSmrg fi 349dff01e5aSmrg rm -f "$depfile" 350dff01e5aSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351dff01e5aSmrg # We have to change lines of the first kind to '$object: \'. 352dff01e5aSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353dff01e5aSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 354dff01e5aSmrg # dummy dependency, to avoid the deleted-header problem. 355dff01e5aSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356c76ae52dSmrg rm -f "$tmpdepfile" 357c76ae52dSmrg ;; 358c76ae52dSmrg 359dff01e5aSmrg## The order of this option in the case statement is important, since the 360dff01e5aSmrg## shell code in configure will try each of these formats in the order 361dff01e5aSmrg## listed in this file. A plain '-MD' option would be understood by many 362dff01e5aSmrg## compilers, so we must ensure this comes after the gcc and icc options. 363dff01e5aSmrgpgcc) 364dff01e5aSmrg # Portland's C compiler understands '-MD'. 365dff01e5aSmrg # Will always output deps to 'file.d' where file is the root name of the 366dff01e5aSmrg # source file under compilation, even if file resides in a subdirectory. 367dff01e5aSmrg # The object file name does not affect the name of the '.d' file. 368dff01e5aSmrg # pgcc 10.2 will output 369c76ae52dSmrg # foo.o: sub/foo.c sub/foo.h 370dff01e5aSmrg # and will wrap long lines using '\' : 371c76ae52dSmrg # foo.o: sub/foo.c ... \ 372c76ae52dSmrg # sub/foo.h ... \ 373c76ae52dSmrg # ... 374dff01e5aSmrg set_dir_from "$object" 375dff01e5aSmrg # Use the source, not the object, to determine the base name, since 376dff01e5aSmrg # that's sadly what pgcc will do too. 377dff01e5aSmrg set_base_from "$source" 378dff01e5aSmrg tmpdepfile=$base.d 379dff01e5aSmrg 380dff01e5aSmrg # For projects that build the same source file twice into different object 381dff01e5aSmrg # files, the pgcc approach of using the *source* file root name can cause 382dff01e5aSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383dff01e5aSmrg # the same $tmpdepfile. 384dff01e5aSmrg lockdir=$base.d-lock 385dff01e5aSmrg trap " 386dff01e5aSmrg echo '$0: caught signal, cleaning up...' >&2 387dff01e5aSmrg rmdir '$lockdir' 388dff01e5aSmrg exit 1 389dff01e5aSmrg " 1 2 13 15 390dff01e5aSmrg numtries=100 391dff01e5aSmrg i=$numtries 392dff01e5aSmrg while test $i -gt 0; do 393dff01e5aSmrg # mkdir is a portable test-and-set. 394dff01e5aSmrg if mkdir "$lockdir" 2>/dev/null; then 395dff01e5aSmrg # This process acquired the lock. 396dff01e5aSmrg "$@" -MD 397dff01e5aSmrg stat=$? 398dff01e5aSmrg # Release the lock. 399dff01e5aSmrg rmdir "$lockdir" 400dff01e5aSmrg break 401dff01e5aSmrg else 402dff01e5aSmrg # If the lock is being held by a different process, wait 403dff01e5aSmrg # until the winning process is done or we timeout. 404dff01e5aSmrg while test -d "$lockdir" && test $i -gt 0; do 405dff01e5aSmrg sleep 1 406dff01e5aSmrg i=`expr $i - 1` 407dff01e5aSmrg done 408dff01e5aSmrg fi 409dff01e5aSmrg i=`expr $i - 1` 410dff01e5aSmrg done 411dff01e5aSmrg trap - 1 2 13 15 412dff01e5aSmrg if test $i -le 0; then 413dff01e5aSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414dff01e5aSmrg echo "$0: check lockdir '$lockdir'" >&2 415dff01e5aSmrg exit 1 416dff01e5aSmrg fi 417c76ae52dSmrg 418dff01e5aSmrg if test $stat -ne 0; then 419c76ae52dSmrg rm -f "$tmpdepfile" 420c76ae52dSmrg exit $stat 421c76ae52dSmrg fi 422c76ae52dSmrg rm -f "$depfile" 423c76ae52dSmrg # Each line is of the form `foo.o: dependent.h', 424c76ae52dSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425c76ae52dSmrg # Do two passes, one to just change these to 426c76ae52dSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427c76ae52dSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428c76ae52dSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429c76ae52dSmrg # correctly. Breaking it into two sed invocations is a workaround. 430dff01e5aSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431dff01e5aSmrg | sed -e 's/$/ :/' >> "$depfile" 432c76ae52dSmrg rm -f "$tmpdepfile" 433c76ae52dSmrg ;; 434c76ae52dSmrg 4350d590c07Smrghp2) 4360d590c07Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4370d590c07Smrg # compilers, which have integrated preprocessors. The correct option 4380d590c07Smrg # to use with these is +Maked; it writes dependencies to a file named 4390d590c07Smrg # 'foo.d', which lands next to the object file, wherever that 4400d590c07Smrg # happens to be. 4410d590c07Smrg # Much of this is similar to the tru64 case; see comments there. 442dff01e5aSmrg set_dir_from "$object" 443dff01e5aSmrg set_base_from "$object" 4440d590c07Smrg if test "$libtool" = yes; then 4450d590c07Smrg tmpdepfile1=$dir$base.d 4460d590c07Smrg tmpdepfile2=$dir.libs/$base.d 4470d590c07Smrg "$@" -Wc,+Maked 4480d590c07Smrg else 4490d590c07Smrg tmpdepfile1=$dir$base.d 4500d590c07Smrg tmpdepfile2=$dir$base.d 4510d590c07Smrg "$@" +Maked 4520d590c07Smrg fi 4530d590c07Smrg stat=$? 454dff01e5aSmrg if test $stat -ne 0; then 4550d590c07Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4560d590c07Smrg exit $stat 4570d590c07Smrg fi 4580d590c07Smrg 4590d590c07Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4600d590c07Smrg do 4610d590c07Smrg test -f "$tmpdepfile" && break 4620d590c07Smrg done 4630d590c07Smrg if test -f "$tmpdepfile"; then 464dff01e5aSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465dff01e5aSmrg # Add 'dependent.h:' lines. 4660d590c07Smrg sed -ne '2,${ 467dff01e5aSmrg s/^ *// 468dff01e5aSmrg s/ \\*$// 469dff01e5aSmrg s/$/:/ 470dff01e5aSmrg p 471dff01e5aSmrg }' "$tmpdepfile" >> "$depfile" 4720d590c07Smrg else 473dff01e5aSmrg make_dummy_depfile 4740d590c07Smrg fi 4750d590c07Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4760d590c07Smrg ;; 4770d590c07Smrg 478c76ae52dSmrgtru64) 479dff01e5aSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 480dff01e5aSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481dff01e5aSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482dff01e5aSmrg # dependencies in 'foo.d' instead, so we check for that too. 483dff01e5aSmrg # Subdirectories are respected. 484dff01e5aSmrg set_dir_from "$object" 485dff01e5aSmrg set_base_from "$object" 486dff01e5aSmrg 487dff01e5aSmrg if test "$libtool" = yes; then 488dff01e5aSmrg # Libtool generates 2 separate objects for the 2 libraries. These 489dff01e5aSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 490dff01e5aSmrg # in $dir$base.o.d. We have to check for both files, because 491dff01e5aSmrg # one of the two compilations can be disabled. We should prefer 492dff01e5aSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493dff01e5aSmrg # automatically cleaned when .libs/ is deleted, while ignoring 494dff01e5aSmrg # the former would cause a distcleancheck panic. 495dff01e5aSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496dff01e5aSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497dff01e5aSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498dff01e5aSmrg "$@" -Wc,-MD 499dff01e5aSmrg else 500dff01e5aSmrg tmpdepfile1=$dir$base.d 501dff01e5aSmrg tmpdepfile2=$dir$base.d 502dff01e5aSmrg tmpdepfile3=$dir$base.d 503dff01e5aSmrg "$@" -MD 504dff01e5aSmrg fi 505dff01e5aSmrg 506dff01e5aSmrg stat=$? 507dff01e5aSmrg if test $stat -ne 0; then 508dff01e5aSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509dff01e5aSmrg exit $stat 510dff01e5aSmrg fi 511dff01e5aSmrg 512dff01e5aSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513dff01e5aSmrg do 514dff01e5aSmrg test -f "$tmpdepfile" && break 515dff01e5aSmrg done 516dff01e5aSmrg # Same post-processing that is required for AIX mode. 517dff01e5aSmrg aix_post_process_depfile 518dff01e5aSmrg ;; 519c76ae52dSmrg 5202836776bSmrgmsvc7) 5212836776bSmrg if test "$libtool" = yes; then 5222836776bSmrg showIncludes=-Wc,-showIncludes 5232836776bSmrg else 5242836776bSmrg showIncludes=-showIncludes 5252836776bSmrg fi 5262836776bSmrg "$@" $showIncludes > "$tmpdepfile" 5272836776bSmrg stat=$? 5282836776bSmrg grep -v '^Note: including file: ' "$tmpdepfile" 529dff01e5aSmrg if test $stat -ne 0; then 5302836776bSmrg rm -f "$tmpdepfile" 5312836776bSmrg exit $stat 5322836776bSmrg fi 5332836776bSmrg rm -f "$depfile" 5342836776bSmrg echo "$object : \\" > "$depfile" 5352836776bSmrg # The first sed program below extracts the file names and escapes 5362836776bSmrg # backslashes for cygpath. The second sed program outputs the file 5372836776bSmrg # name when reading, but also accumulates all include files in the 5382836776bSmrg # hold buffer in order to output them again at the end. This only 5392836776bSmrg # works with sed implementations that can handle large buffers. 5402836776bSmrg sed < "$tmpdepfile" -n ' 5412836776bSmrg/^Note: including file: *\(.*\)/ { 5422836776bSmrg s//\1/ 5432836776bSmrg s/\\/\\\\/g 5442836776bSmrg p 5452836776bSmrg}' | $cygpath_u | sort -u | sed -n ' 5462836776bSmrgs/ /\\ /g 547dff01e5aSmrgs/\(.*\)/'"$tab"'\1 \\/p 5482836776bSmrgs/.\(.*\) \\/\1:/ 5492836776bSmrgH 5502836776bSmrg$ { 551dff01e5aSmrg s/.*/'"$tab"'/ 5522836776bSmrg G 5532836776bSmrg p 5542836776bSmrg}' >> "$depfile" 555dff01e5aSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5562836776bSmrg rm -f "$tmpdepfile" 5572836776bSmrg ;; 5582836776bSmrg 5592836776bSmrgmsvc7msys) 5602836776bSmrg # This case exists only to let depend.m4 do its work. It works by 5612836776bSmrg # looking at the text of this script. This case will never be run, 5622836776bSmrg # since it is checked for above. 5632836776bSmrg exit 1 5642836776bSmrg ;; 5652836776bSmrg 566c76ae52dSmrg#nosideeffect) 567c76ae52dSmrg # This comment above is used by automake to tell side-effect 568c76ae52dSmrg # dependency tracking mechanisms from slower ones. 569c76ae52dSmrg 570c76ae52dSmrgdashmstdout) 571c76ae52dSmrg # Important note: in order to support this mode, a compiler *must* 572c76ae52dSmrg # always write the preprocessed file to stdout, regardless of -o. 573c76ae52dSmrg "$@" || exit $? 574c76ae52dSmrg 575c76ae52dSmrg # Remove the call to Libtool. 576c76ae52dSmrg if test "$libtool" = yes; then 5770d590c07Smrg while test "X$1" != 'X--mode=compile'; do 578c76ae52dSmrg shift 579c76ae52dSmrg done 580c76ae52dSmrg shift 581c76ae52dSmrg fi 582c76ae52dSmrg 583dff01e5aSmrg # Remove '-o $object'. 584c76ae52dSmrg IFS=" " 585c76ae52dSmrg for arg 586c76ae52dSmrg do 587c76ae52dSmrg case $arg in 588c76ae52dSmrg -o) 589c76ae52dSmrg shift 590c76ae52dSmrg ;; 591c76ae52dSmrg $object) 592c76ae52dSmrg shift 593c76ae52dSmrg ;; 594c76ae52dSmrg *) 595c76ae52dSmrg set fnord "$@" "$arg" 596c76ae52dSmrg shift # fnord 597c76ae52dSmrg shift # $arg 598c76ae52dSmrg ;; 599c76ae52dSmrg esac 600c76ae52dSmrg done 601c76ae52dSmrg 602c76ae52dSmrg test -z "$dashmflag" && dashmflag=-M 603dff01e5aSmrg # Require at least two characters before searching for ':' 604c76ae52dSmrg # in the target name. This is to cope with DOS-style filenames: 605dff01e5aSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606c76ae52dSmrg "$@" $dashmflag | 607dff01e5aSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608c76ae52dSmrg rm -f "$depfile" 609c76ae52dSmrg cat < "$tmpdepfile" > "$depfile" 610dff01e5aSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611dff01e5aSmrg # correctly. Breaking it into two sed invocations is a workaround. 612dff01e5aSmrg tr ' ' "$nl" < "$tmpdepfile" \ 613dff01e5aSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614dff01e5aSmrg | sed -e 's/$/ :/' >> "$depfile" 615c76ae52dSmrg rm -f "$tmpdepfile" 616c76ae52dSmrg ;; 617c76ae52dSmrg 618c76ae52dSmrgdashXmstdout) 619c76ae52dSmrg # This case only exists to satisfy depend.m4. It is never actually 620c76ae52dSmrg # run, as this mode is specially recognized in the preamble. 621c76ae52dSmrg exit 1 622c76ae52dSmrg ;; 623c76ae52dSmrg 624c76ae52dSmrgmakedepend) 625c76ae52dSmrg "$@" || exit $? 626c76ae52dSmrg # Remove any Libtool call 627c76ae52dSmrg if test "$libtool" = yes; then 6280d590c07Smrg while test "X$1" != 'X--mode=compile'; do 629c76ae52dSmrg shift 630c76ae52dSmrg done 631c76ae52dSmrg shift 632c76ae52dSmrg fi 633c76ae52dSmrg # X makedepend 634c76ae52dSmrg shift 6350d590c07Smrg cleared=no eat=no 6360d590c07Smrg for arg 6370d590c07Smrg do 638c76ae52dSmrg case $cleared in 639c76ae52dSmrg no) 640c76ae52dSmrg set ""; shift 641c76ae52dSmrg cleared=yes ;; 642c76ae52dSmrg esac 6430d590c07Smrg if test $eat = yes; then 6440d590c07Smrg eat=no 6450d590c07Smrg continue 6460d590c07Smrg fi 647c76ae52dSmrg case "$arg" in 648c76ae52dSmrg -D*|-I*) 649c76ae52dSmrg set fnord "$@" "$arg"; shift ;; 650c76ae52dSmrg # Strip any option that makedepend may not understand. Remove 651c76ae52dSmrg # the object too, otherwise makedepend will parse it as a source file. 6520d590c07Smrg -arch) 6530d590c07Smrg eat=yes ;; 654c76ae52dSmrg -*|$object) 655c76ae52dSmrg ;; 656c76ae52dSmrg *) 657c76ae52dSmrg set fnord "$@" "$arg"; shift ;; 658c76ae52dSmrg esac 659c76ae52dSmrg done 6600d590c07Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661c76ae52dSmrg touch "$tmpdepfile" 662c76ae52dSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663c76ae52dSmrg rm -f "$depfile" 6642836776bSmrg # makedepend may prepend the VPATH from the source file name to the object. 6652836776bSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 6662836776bSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667dff01e5aSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668dff01e5aSmrg # correctly. Breaking it into two sed invocations is a workaround. 669dff01e5aSmrg sed '1,2d' "$tmpdepfile" \ 670dff01e5aSmrg | tr ' ' "$nl" \ 671dff01e5aSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672dff01e5aSmrg | sed -e 's/$/ :/' >> "$depfile" 673c76ae52dSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674c76ae52dSmrg ;; 675c76ae52dSmrg 676c76ae52dSmrgcpp) 677c76ae52dSmrg # Important note: in order to support this mode, a compiler *must* 678c76ae52dSmrg # always write the preprocessed file to stdout. 679c76ae52dSmrg "$@" || exit $? 680c76ae52dSmrg 681c76ae52dSmrg # Remove the call to Libtool. 682c76ae52dSmrg if test "$libtool" = yes; then 6830d590c07Smrg while test "X$1" != 'X--mode=compile'; do 684c76ae52dSmrg shift 685c76ae52dSmrg done 686c76ae52dSmrg shift 687c76ae52dSmrg fi 688c76ae52dSmrg 689dff01e5aSmrg # Remove '-o $object'. 690c76ae52dSmrg IFS=" " 691c76ae52dSmrg for arg 692c76ae52dSmrg do 693c76ae52dSmrg case $arg in 694c76ae52dSmrg -o) 695c76ae52dSmrg shift 696c76ae52dSmrg ;; 697c76ae52dSmrg $object) 698c76ae52dSmrg shift 699c76ae52dSmrg ;; 700c76ae52dSmrg *) 701c76ae52dSmrg set fnord "$@" "$arg" 702c76ae52dSmrg shift # fnord 703c76ae52dSmrg shift # $arg 704c76ae52dSmrg ;; 705c76ae52dSmrg esac 706c76ae52dSmrg done 707c76ae52dSmrg 708dff01e5aSmrg "$@" -E \ 709dff01e5aSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710dff01e5aSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711dff01e5aSmrg | sed '$ s: \\$::' > "$tmpdepfile" 712c76ae52dSmrg rm -f "$depfile" 713c76ae52dSmrg echo "$object : \\" > "$depfile" 714c76ae52dSmrg cat < "$tmpdepfile" >> "$depfile" 715c76ae52dSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716c76ae52dSmrg rm -f "$tmpdepfile" 717c76ae52dSmrg ;; 718c76ae52dSmrg 719c76ae52dSmrgmsvisualcpp) 720c76ae52dSmrg # Important note: in order to support this mode, a compiler *must* 7210d590c07Smrg # always write the preprocessed file to stdout. 722c76ae52dSmrg "$@" || exit $? 7230d590c07Smrg 7240d590c07Smrg # Remove the call to Libtool. 7250d590c07Smrg if test "$libtool" = yes; then 7260d590c07Smrg while test "X$1" != 'X--mode=compile'; do 7270d590c07Smrg shift 7280d590c07Smrg done 7290d590c07Smrg shift 7300d590c07Smrg fi 7310d590c07Smrg 732c76ae52dSmrg IFS=" " 733c76ae52dSmrg for arg 734c76ae52dSmrg do 735c76ae52dSmrg case "$arg" in 7360d590c07Smrg -o) 7370d590c07Smrg shift 7380d590c07Smrg ;; 7390d590c07Smrg $object) 7400d590c07Smrg shift 7410d590c07Smrg ;; 742c76ae52dSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743dff01e5aSmrg set fnord "$@" 744dff01e5aSmrg shift 745dff01e5aSmrg shift 746dff01e5aSmrg ;; 747c76ae52dSmrg *) 748dff01e5aSmrg set fnord "$@" "$arg" 749dff01e5aSmrg shift 750dff01e5aSmrg shift 751dff01e5aSmrg ;; 752c76ae52dSmrg esac 753c76ae52dSmrg done 7540d590c07Smrg "$@" -E 2>/dev/null | 7550d590c07Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756c76ae52dSmrg rm -f "$depfile" 757c76ae52dSmrg echo "$object : \\" > "$depfile" 758dff01e5aSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759dff01e5aSmrg echo "$tab" >> "$depfile" 7600d590c07Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761c76ae52dSmrg rm -f "$tmpdepfile" 762c76ae52dSmrg ;; 763c76ae52dSmrg 7640d590c07Smrgmsvcmsys) 7650d590c07Smrg # This case exists only to let depend.m4 do its work. It works by 7660d590c07Smrg # looking at the text of this script. This case will never be run, 7670d590c07Smrg # since it is checked for above. 7680d590c07Smrg exit 1 7690d590c07Smrg ;; 7700d590c07Smrg 771c76ae52dSmrgnone) 772c76ae52dSmrg exec "$@" 773c76ae52dSmrg ;; 774c76ae52dSmrg 775c76ae52dSmrg*) 776c76ae52dSmrg echo "Unknown depmode $depmode" 1>&2 777c76ae52dSmrg exit 1 778c76ae52dSmrg ;; 779c76ae52dSmrgesac 780c76ae52dSmrg 781c76ae52dSmrgexit 0 782c76ae52dSmrg 783c76ae52dSmrg# Local Variables: 784c76ae52dSmrg# mode: shell-script 785c76ae52dSmrg# sh-indentation: 2 78684febdacSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 787c76ae52dSmrg# time-stamp-start: "scriptversion=" 788c76ae52dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78984febdacSmrg# time-stamp-time-zone: "UTC0" 7900d590c07Smrg# time-stamp-end: "; # UTC" 791c76ae52dSmrg# End: 792