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