1bdcaa8d0Smrg#! /bin/sh 2bdcaa8d0Smrg# depcomp - compile a program generating dependencies as side-effects 3bdcaa8d0Smrg 44f00d7e1Smrgscriptversion=2013-05-30.07; # UTC 5bdcaa8d0Smrg 64f00d7e1Smrg# Copyright (C) 1999-2013 Free Software Foundation, Inc. 7bdcaa8d0Smrg 8bdcaa8d0Smrg# This program is free software; you can redistribute it and/or modify 9bdcaa8d0Smrg# it under the terms of the GNU General Public License as published by 10bdcaa8d0Smrg# the Free Software Foundation; either version 2, or (at your option) 11bdcaa8d0Smrg# any later version. 12bdcaa8d0Smrg 13bdcaa8d0Smrg# This program is distributed in the hope that it will be useful, 14bdcaa8d0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15bdcaa8d0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16bdcaa8d0Smrg# GNU General Public License for more details. 17bdcaa8d0Smrg 18bdcaa8d0Smrg# You should have received a copy of the GNU General Public License 1996ce994aSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20bdcaa8d0Smrg 21bdcaa8d0Smrg# As a special exception to the GNU General Public License, if you 22bdcaa8d0Smrg# distribute this file as part of a program that contains a 23bdcaa8d0Smrg# configuration script generated by Autoconf, you may include it under 24bdcaa8d0Smrg# the same distribution terms that you use for the rest of that program. 25bdcaa8d0Smrg 26bdcaa8d0Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27bdcaa8d0Smrg 28bdcaa8d0Smrgcase $1 in 29bdcaa8d0Smrg '') 304f00d7e1Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 314f00d7e1Smrg exit 1; 324f00d7e1Smrg ;; 33bdcaa8d0Smrg -h | --h*) 34bdcaa8d0Smrg cat <<\EOF 35bdcaa8d0SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36bdcaa8d0Smrg 37bdcaa8d0SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38bdcaa8d0Smrgas side-effects. 39bdcaa8d0Smrg 40bdcaa8d0SmrgEnvironment variables: 41bdcaa8d0Smrg depmode Dependency tracking mode. 424f00d7e1Smrg source Source file read by 'PROGRAMS ARGS'. 434f00d7e1Smrg object Object file output by 'PROGRAMS ARGS'. 44bdcaa8d0Smrg DEPDIR directory where to store dependencies. 45bdcaa8d0Smrg depfile Dependency file to output. 46880c7e28Smrg tmpdepfile Temporary file to use when outputting dependencies. 47bdcaa8d0Smrg libtool Whether libtool is used (yes/no). 48bdcaa8d0Smrg 49bdcaa8d0SmrgReport bugs to <bug-automake@gnu.org>. 50bdcaa8d0SmrgEOF 51bdcaa8d0Smrg exit $? 52bdcaa8d0Smrg ;; 53bdcaa8d0Smrg -v | --v*) 54bdcaa8d0Smrg echo "depcomp $scriptversion" 55bdcaa8d0Smrg exit $? 56bdcaa8d0Smrg ;; 57bdcaa8d0Smrgesac 58bdcaa8d0Smrg 594f00d7e1Smrg# Get the directory component of the given path, and save it in the 604f00d7e1Smrg# global variables '$dir'. Note that this directory component will 614f00d7e1Smrg# be either empty or ending with a '/' character. This is deliberate. 624f00d7e1Smrgset_dir_from () 634f00d7e1Smrg{ 644f00d7e1Smrg case $1 in 654f00d7e1Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 664f00d7e1Smrg *) dir=;; 674f00d7e1Smrg esac 684f00d7e1Smrg} 694f00d7e1Smrg 704f00d7e1Smrg# Get the suffix-stripped basename of the given path, and save it the 714f00d7e1Smrg# global variable '$base'. 724f00d7e1Smrgset_base_from () 734f00d7e1Smrg{ 744f00d7e1Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 754f00d7e1Smrg} 764f00d7e1Smrg 774f00d7e1Smrg# If no dependency file was actually created by the compiler invocation, 784f00d7e1Smrg# we still have to create a dummy depfile, to avoid errors with the 794f00d7e1Smrg# Makefile "include basename.Plo" scheme. 804f00d7e1Smrgmake_dummy_depfile () 814f00d7e1Smrg{ 824f00d7e1Smrg echo "#dummy" > "$depfile" 834f00d7e1Smrg} 844f00d7e1Smrg 854f00d7e1Smrg# Factor out some common post-processing of the generated depfile. 864f00d7e1Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 874f00d7e1Smrgaix_post_process_depfile () 884f00d7e1Smrg{ 894f00d7e1Smrg # If the compiler actually managed to produce a dependency file, 904f00d7e1Smrg # post-process it. 914f00d7e1Smrg if test -f "$tmpdepfile"; then 924f00d7e1Smrg # Each line is of the form 'foo.o: dependency.h'. 934f00d7e1Smrg # Do two passes, one to just change these to 944f00d7e1Smrg # $object: dependency.h 954f00d7e1Smrg # and one to simply output 964f00d7e1Smrg # dependency.h: 974f00d7e1Smrg # which is needed to avoid the deleted-header problem. 984f00d7e1Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 994f00d7e1Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1004f00d7e1Smrg } > "$depfile" 1014f00d7e1Smrg rm -f "$tmpdepfile" 1024f00d7e1Smrg else 1034f00d7e1Smrg make_dummy_depfile 1044f00d7e1Smrg fi 1054f00d7e1Smrg} 1064f00d7e1Smrg 1074f00d7e1Smrg# A tabulation character. 1084f00d7e1Smrgtab=' ' 1094f00d7e1Smrg# A newline character. 1104f00d7e1Smrgnl=' 1114f00d7e1Smrg' 1124f00d7e1Smrg# Character ranges might be problematic outside the C locale. 1134f00d7e1Smrg# These definitions help. 1144f00d7e1Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1154f00d7e1Smrglower=abcdefghijklmnopqrstuvwxyz 1164f00d7e1Smrgdigits=0123456789 1174f00d7e1Smrgalpha=${upper}${lower} 1184f00d7e1Smrg 119bdcaa8d0Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120bdcaa8d0Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121bdcaa8d0Smrg exit 1 122bdcaa8d0Smrgfi 123bdcaa8d0Smrg 124bdcaa8d0Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125bdcaa8d0Smrgdepfile=${depfile-`echo "$object" | 126bdcaa8d0Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127bdcaa8d0Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128bdcaa8d0Smrg 129bdcaa8d0Smrgrm -f "$tmpdepfile" 130bdcaa8d0Smrg 1314f00d7e1Smrg# Avoid interferences from the environment. 1324f00d7e1Smrggccflag= dashmflag= 1334f00d7e1Smrg 134bdcaa8d0Smrg# Some modes work just like other modes, but use different flags. We 135bdcaa8d0Smrg# parameterize here, but still list the modes in the big case below, 136bdcaa8d0Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137bdcaa8d0Smrg# here, because this file can only contain one case statement. 138bdcaa8d0Smrgif test "$depmode" = hp; then 139bdcaa8d0Smrg # HP compiler uses -M and no extra arg. 140bdcaa8d0Smrg gccflag=-M 141bdcaa8d0Smrg depmode=gcc 142bdcaa8d0Smrgfi 143bdcaa8d0Smrg 144bdcaa8d0Smrgif test "$depmode" = dashXmstdout; then 1454f00d7e1Smrg # This is just like dashmstdout with a different argument. 1464f00d7e1Smrg dashmflag=-xM 1474f00d7e1Smrg depmode=dashmstdout 148bdcaa8d0Smrgfi 149bdcaa8d0Smrg 15096ce994aSmrgcygpath_u="cygpath -u -f -" 15196ce994aSmrgif test "$depmode" = msvcmsys; then 1524f00d7e1Smrg # This is just like msvisualcpp but w/o cygpath translation. 1534f00d7e1Smrg # Just convert the backslash-escaped backslashes to single forward 1544f00d7e1Smrg # slashes to satisfy depend.m4 1554f00d7e1Smrg cygpath_u='sed s,\\\\,/,g' 1564f00d7e1Smrg depmode=msvisualcpp 15796ce994aSmrgfi 15896ce994aSmrg 159880c7e28Smrgif test "$depmode" = msvc7msys; then 1604f00d7e1Smrg # This is just like msvc7 but w/o cygpath translation. 1614f00d7e1Smrg # Just convert the backslash-escaped backslashes to single forward 1624f00d7e1Smrg # slashes to satisfy depend.m4 1634f00d7e1Smrg cygpath_u='sed s,\\\\,/,g' 1644f00d7e1Smrg depmode=msvc7 1654f00d7e1Smrgfi 1664f00d7e1Smrg 1674f00d7e1Smrgif test "$depmode" = xlc; then 1684f00d7e1Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1694f00d7e1Smrg gccflag=-qmakedep=gcc,-MF 1704f00d7e1Smrg depmode=gcc 171880c7e28Smrgfi 172880c7e28Smrg 173bdcaa8d0Smrgcase "$depmode" in 174bdcaa8d0Smrggcc3) 175bdcaa8d0Smrg## gcc 3 implements dependency tracking that does exactly what 176bdcaa8d0Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177bdcaa8d0Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 17872313efbSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 17972313efbSmrg## the command line argument order; so add the flags where they 18072313efbSmrg## appear in depend2.am. Note that the slowdown incurred here 18172313efbSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 18272313efbSmrg for arg 18372313efbSmrg do 18472313efbSmrg case $arg in 18572313efbSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 18672313efbSmrg *) set fnord "$@" "$arg" ;; 18772313efbSmrg esac 18872313efbSmrg shift # fnord 18972313efbSmrg shift # $arg 19072313efbSmrg done 19172313efbSmrg "$@" 192bdcaa8d0Smrg stat=$? 1934f00d7e1Smrg if test $stat -ne 0; then 194bdcaa8d0Smrg rm -f "$tmpdepfile" 195bdcaa8d0Smrg exit $stat 196bdcaa8d0Smrg fi 197bdcaa8d0Smrg mv "$tmpdepfile" "$depfile" 198bdcaa8d0Smrg ;; 199bdcaa8d0Smrg 200bdcaa8d0Smrggcc) 2014f00d7e1Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2024f00d7e1Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2034f00d7e1Smrg## (see the conditional assignment to $gccflag above). 204bdcaa8d0Smrg## There are various ways to get dependency output from gcc. Here's 205bdcaa8d0Smrg## why we pick this rather obscure method: 206bdcaa8d0Smrg## - Don't want to use -MD because we'd like the dependencies to end 207bdcaa8d0Smrg## up in a subdir. Having to rename by hand is ugly. 208bdcaa8d0Smrg## (We might end up doing this anyway to support other compilers.) 209bdcaa8d0Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2104f00d7e1Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2114f00d7e1Smrg## supported by the other compilers which use the 'gcc' depmode. 212bdcaa8d0Smrg## - Using -M directly means running the compiler twice (even worse 213bdcaa8d0Smrg## than renaming). 214bdcaa8d0Smrg if test -z "$gccflag"; then 215bdcaa8d0Smrg gccflag=-MD, 216bdcaa8d0Smrg fi 217bdcaa8d0Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218bdcaa8d0Smrg stat=$? 2194f00d7e1Smrg if test $stat -ne 0; then 220bdcaa8d0Smrg rm -f "$tmpdepfile" 221bdcaa8d0Smrg exit $stat 222bdcaa8d0Smrg fi 223bdcaa8d0Smrg rm -f "$depfile" 224bdcaa8d0Smrg echo "$object : \\" > "$depfile" 2254f00d7e1Smrg # The second -e expression handles DOS-style file names with drive 2264f00d7e1Smrg # letters. 227bdcaa8d0Smrg sed -e 's/^[^:]*: / /' \ 228bdcaa8d0Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2294f00d7e1Smrg## This next piece of magic avoids the "deleted header file" problem. 230bdcaa8d0Smrg## The problem is that when a header file which appears in a .P file 231bdcaa8d0Smrg## is deleted, the dependency causes make to die (because there is 232bdcaa8d0Smrg## typically no way to rebuild the header). We avoid this by adding 233bdcaa8d0Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234bdcaa8d0Smrg## this for us directly. 2354f00d7e1Smrg## Some versions of gcc put a space before the ':'. On the theory 236bdcaa8d0Smrg## that the space means something, we add a space to the output as 237880c7e28Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238880c7e28Smrg## to the object. Take care to not repeat it in the output. 239bdcaa8d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240bdcaa8d0Smrg## correctly. Breaking it into two sed invocations is a workaround. 2414f00d7e1Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2424f00d7e1Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2434f00d7e1Smrg | sed -e 's/$/ :/' >> "$depfile" 244bdcaa8d0Smrg rm -f "$tmpdepfile" 245bdcaa8d0Smrg ;; 246bdcaa8d0Smrg 247bdcaa8d0Smrghp) 248bdcaa8d0Smrg # This case exists only to let depend.m4 do its work. It works by 249bdcaa8d0Smrg # looking at the text of this script. This case will never be run, 250bdcaa8d0Smrg # since it is checked for above. 251bdcaa8d0Smrg exit 1 252bdcaa8d0Smrg ;; 253bdcaa8d0Smrg 254bdcaa8d0Smrgsgi) 255bdcaa8d0Smrg if test "$libtool" = yes; then 256bdcaa8d0Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257bdcaa8d0Smrg else 258bdcaa8d0Smrg "$@" -MDupdate "$tmpdepfile" 259bdcaa8d0Smrg fi 260bdcaa8d0Smrg stat=$? 2614f00d7e1Smrg if test $stat -ne 0; then 262bdcaa8d0Smrg rm -f "$tmpdepfile" 263bdcaa8d0Smrg exit $stat 264bdcaa8d0Smrg fi 265bdcaa8d0Smrg rm -f "$depfile" 266bdcaa8d0Smrg 267bdcaa8d0Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268bdcaa8d0Smrg echo "$object : \\" > "$depfile" 269bdcaa8d0Smrg # Clip off the initial element (the dependent). Don't try to be 270bdcaa8d0Smrg # clever and replace this with sed code, as IRIX sed won't handle 271bdcaa8d0Smrg # lines with more than a fixed number of characters (4096 in 272bdcaa8d0Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2734f00d7e1Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274bdcaa8d0Smrg # dependency line. 2754f00d7e1Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2764f00d7e1Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2774f00d7e1Smrg | tr "$nl" ' ' >> "$depfile" 27896ce994aSmrg echo >> "$depfile" 279bdcaa8d0Smrg # The second pass generates a dummy entry for each header file. 2804f00d7e1Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2814f00d7e1Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2824f00d7e1Smrg >> "$depfile" 283bdcaa8d0Smrg else 2844f00d7e1Smrg make_dummy_depfile 285bdcaa8d0Smrg fi 286bdcaa8d0Smrg rm -f "$tmpdepfile" 287bdcaa8d0Smrg ;; 288bdcaa8d0Smrg 2894f00d7e1Smrgxlc) 2904f00d7e1Smrg # This case exists only to let depend.m4 do its work. It works by 2914f00d7e1Smrg # looking at the text of this script. This case will never be run, 2924f00d7e1Smrg # since it is checked for above. 2934f00d7e1Smrg exit 1 2944f00d7e1Smrg ;; 2954f00d7e1Smrg 296bdcaa8d0Smrgaix) 297bdcaa8d0Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298bdcaa8d0Smrg # in a .u file. In older versions, this file always lives in the 2994f00d7e1Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300bdcaa8d0Smrg # start of each line; $object doesn't have directory information. 301bdcaa8d0Smrg # Version 6 uses the directory in both cases. 3024f00d7e1Smrg set_dir_from "$object" 3034f00d7e1Smrg set_base_from "$object" 304bdcaa8d0Smrg if test "$libtool" = yes; then 30572313efbSmrg tmpdepfile1=$dir$base.u 30672313efbSmrg tmpdepfile2=$base.u 30772313efbSmrg tmpdepfile3=$dir.libs/$base.u 308bdcaa8d0Smrg "$@" -Wc,-M 309bdcaa8d0Smrg else 31072313efbSmrg tmpdepfile1=$dir$base.u 31172313efbSmrg tmpdepfile2=$dir$base.u 31272313efbSmrg tmpdepfile3=$dir$base.u 313bdcaa8d0Smrg "$@" -M 314bdcaa8d0Smrg fi 315bdcaa8d0Smrg stat=$? 3164f00d7e1Smrg if test $stat -ne 0; then 31772313efbSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318bdcaa8d0Smrg exit $stat 319bdcaa8d0Smrg fi 320bdcaa8d0Smrg 32172313efbSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32272313efbSmrg do 32372313efbSmrg test -f "$tmpdepfile" && break 32472313efbSmrg done 3254f00d7e1Smrg aix_post_process_depfile 3264f00d7e1Smrg ;; 3274f00d7e1Smrg 3284f00d7e1Smrgtcc) 3294f00d7e1Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3304f00d7e1Smrg # FIXME: That version still under development at the moment of writing. 3314f00d7e1Smrg # Make that this statement remains true also for stable, released 3324f00d7e1Smrg # versions. 3334f00d7e1Smrg # It will wrap lines (doesn't matter whether long or short) with a 3344f00d7e1Smrg # trailing '\', as in: 3354f00d7e1Smrg # 3364f00d7e1Smrg # foo.o : \ 3374f00d7e1Smrg # foo.c \ 3384f00d7e1Smrg # foo.h \ 3394f00d7e1Smrg # 3404f00d7e1Smrg # It will put a trailing '\' even on the last line, and will use leading 3414f00d7e1Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3424f00d7e1Smrg # "Emit spaces for -MD"). 3434f00d7e1Smrg "$@" -MD -MF "$tmpdepfile" 3444f00d7e1Smrg stat=$? 3454f00d7e1Smrg if test $stat -ne 0; then 3464f00d7e1Smrg rm -f "$tmpdepfile" 3474f00d7e1Smrg exit $stat 348bdcaa8d0Smrg fi 3494f00d7e1Smrg rm -f "$depfile" 3504f00d7e1Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3514f00d7e1Smrg # We have to change lines of the first kind to '$object: \'. 3524f00d7e1Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3534f00d7e1Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3544f00d7e1Smrg # dummy dependency, to avoid the deleted-header problem. 3554f00d7e1Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356bdcaa8d0Smrg rm -f "$tmpdepfile" 357bdcaa8d0Smrg ;; 358bdcaa8d0Smrg 3594f00d7e1Smrg## The order of this option in the case statement is important, since the 3604f00d7e1Smrg## shell code in configure will try each of these formats in the order 3614f00d7e1Smrg## listed in this file. A plain '-MD' option would be understood by many 3624f00d7e1Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3634f00d7e1Smrgpgcc) 3644f00d7e1Smrg # Portland's C compiler understands '-MD'. 3654f00d7e1Smrg # Will always output deps to 'file.d' where file is the root name of the 3664f00d7e1Smrg # source file under compilation, even if file resides in a subdirectory. 3674f00d7e1Smrg # The object file name does not affect the name of the '.d' file. 3684f00d7e1Smrg # pgcc 10.2 will output 369bdcaa8d0Smrg # foo.o: sub/foo.c sub/foo.h 3704f00d7e1Smrg # and will wrap long lines using '\' : 371bdcaa8d0Smrg # foo.o: sub/foo.c ... \ 372bdcaa8d0Smrg # sub/foo.h ... \ 373bdcaa8d0Smrg # ... 3744f00d7e1Smrg set_dir_from "$object" 3754f00d7e1Smrg # Use the source, not the object, to determine the base name, since 3764f00d7e1Smrg # that's sadly what pgcc will do too. 3774f00d7e1Smrg set_base_from "$source" 3784f00d7e1Smrg tmpdepfile=$base.d 3794f00d7e1Smrg 3804f00d7e1Smrg # For projects that build the same source file twice into different object 3814f00d7e1Smrg # files, the pgcc approach of using the *source* file root name can cause 3824f00d7e1Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3834f00d7e1Smrg # the same $tmpdepfile. 3844f00d7e1Smrg lockdir=$base.d-lock 3854f00d7e1Smrg trap " 3864f00d7e1Smrg echo '$0: caught signal, cleaning up...' >&2 3874f00d7e1Smrg rmdir '$lockdir' 3884f00d7e1Smrg exit 1 3894f00d7e1Smrg " 1 2 13 15 3904f00d7e1Smrg numtries=100 3914f00d7e1Smrg i=$numtries 3924f00d7e1Smrg while test $i -gt 0; do 3934f00d7e1Smrg # mkdir is a portable test-and-set. 3944f00d7e1Smrg if mkdir "$lockdir" 2>/dev/null; then 3954f00d7e1Smrg # This process acquired the lock. 3964f00d7e1Smrg "$@" -MD 3974f00d7e1Smrg stat=$? 3984f00d7e1Smrg # Release the lock. 3994f00d7e1Smrg rmdir "$lockdir" 4004f00d7e1Smrg break 4014f00d7e1Smrg else 4024f00d7e1Smrg # If the lock is being held by a different process, wait 4034f00d7e1Smrg # until the winning process is done or we timeout. 4044f00d7e1Smrg while test -d "$lockdir" && test $i -gt 0; do 4054f00d7e1Smrg sleep 1 4064f00d7e1Smrg i=`expr $i - 1` 4074f00d7e1Smrg done 4084f00d7e1Smrg fi 4094f00d7e1Smrg i=`expr $i - 1` 4104f00d7e1Smrg done 4114f00d7e1Smrg trap - 1 2 13 15 4124f00d7e1Smrg if test $i -le 0; then 4134f00d7e1Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4144f00d7e1Smrg echo "$0: check lockdir '$lockdir'" >&2 4154f00d7e1Smrg exit 1 4164f00d7e1Smrg fi 417bdcaa8d0Smrg 4184f00d7e1Smrg if test $stat -ne 0; then 419bdcaa8d0Smrg rm -f "$tmpdepfile" 420bdcaa8d0Smrg exit $stat 421bdcaa8d0Smrg fi 422bdcaa8d0Smrg rm -f "$depfile" 423bdcaa8d0Smrg # Each line is of the form `foo.o: dependent.h', 424bdcaa8d0Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425bdcaa8d0Smrg # Do two passes, one to just change these to 426bdcaa8d0Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427bdcaa8d0Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428bdcaa8d0Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429bdcaa8d0Smrg # correctly. Breaking it into two sed invocations is a workaround. 4304f00d7e1Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4314f00d7e1Smrg | sed -e 's/$/ :/' >> "$depfile" 432bdcaa8d0Smrg rm -f "$tmpdepfile" 433bdcaa8d0Smrg ;; 434bdcaa8d0Smrg 43572313efbSmrghp2) 43672313efbSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 43772313efbSmrg # compilers, which have integrated preprocessors. The correct option 43872313efbSmrg # to use with these is +Maked; it writes dependencies to a file named 43972313efbSmrg # 'foo.d', which lands next to the object file, wherever that 44072313efbSmrg # happens to be. 44172313efbSmrg # Much of this is similar to the tru64 case; see comments there. 4424f00d7e1Smrg set_dir_from "$object" 4434f00d7e1Smrg set_base_from "$object" 44472313efbSmrg if test "$libtool" = yes; then 44572313efbSmrg tmpdepfile1=$dir$base.d 44672313efbSmrg tmpdepfile2=$dir.libs/$base.d 44772313efbSmrg "$@" -Wc,+Maked 44872313efbSmrg else 44972313efbSmrg tmpdepfile1=$dir$base.d 45072313efbSmrg tmpdepfile2=$dir$base.d 45172313efbSmrg "$@" +Maked 45272313efbSmrg fi 45372313efbSmrg stat=$? 4544f00d7e1Smrg if test $stat -ne 0; then 45572313efbSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 45672313efbSmrg exit $stat 45772313efbSmrg fi 45872313efbSmrg 45972313efbSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 46072313efbSmrg do 46172313efbSmrg test -f "$tmpdepfile" && break 46272313efbSmrg done 46372313efbSmrg if test -f "$tmpdepfile"; then 4644f00d7e1Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4654f00d7e1Smrg # Add 'dependent.h:' lines. 46696ce994aSmrg sed -ne '2,${ 4674f00d7e1Smrg s/^ *// 4684f00d7e1Smrg s/ \\*$// 4694f00d7e1Smrg s/$/:/ 4704f00d7e1Smrg p 4714f00d7e1Smrg }' "$tmpdepfile" >> "$depfile" 47272313efbSmrg else 4734f00d7e1Smrg make_dummy_depfile 47472313efbSmrg fi 47572313efbSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 47672313efbSmrg ;; 47772313efbSmrg 478bdcaa8d0Smrgtru64) 4794f00d7e1Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4804f00d7e1Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4814f00d7e1Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4824f00d7e1Smrg # dependencies in 'foo.d' instead, so we check for that too. 4834f00d7e1Smrg # Subdirectories are respected. 4844f00d7e1Smrg set_dir_from "$object" 4854f00d7e1Smrg set_base_from "$object" 4864f00d7e1Smrg 4874f00d7e1Smrg if test "$libtool" = yes; then 4884f00d7e1Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4894f00d7e1Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4904f00d7e1Smrg # in $dir$base.o.d. We have to check for both files, because 4914f00d7e1Smrg # one of the two compilations can be disabled. We should prefer 4924f00d7e1Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4934f00d7e1Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4944f00d7e1Smrg # the former would cause a distcleancheck panic. 4954f00d7e1Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4964f00d7e1Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4974f00d7e1Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4984f00d7e1Smrg "$@" -Wc,-MD 4994f00d7e1Smrg else 5004f00d7e1Smrg tmpdepfile1=$dir$base.d 5014f00d7e1Smrg tmpdepfile2=$dir$base.d 5024f00d7e1Smrg tmpdepfile3=$dir$base.d 5034f00d7e1Smrg "$@" -MD 5044f00d7e1Smrg fi 5054f00d7e1Smrg 5064f00d7e1Smrg stat=$? 5074f00d7e1Smrg if test $stat -ne 0; then 5084f00d7e1Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5094f00d7e1Smrg exit $stat 5104f00d7e1Smrg fi 5114f00d7e1Smrg 5124f00d7e1Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5134f00d7e1Smrg do 5144f00d7e1Smrg test -f "$tmpdepfile" && break 5154f00d7e1Smrg done 5164f00d7e1Smrg # Same post-processing that is required for AIX mode. 5174f00d7e1Smrg aix_post_process_depfile 5184f00d7e1Smrg ;; 519bdcaa8d0Smrg 520880c7e28Smrgmsvc7) 521880c7e28Smrg if test "$libtool" = yes; then 522880c7e28Smrg showIncludes=-Wc,-showIncludes 523880c7e28Smrg else 524880c7e28Smrg showIncludes=-showIncludes 525880c7e28Smrg fi 526880c7e28Smrg "$@" $showIncludes > "$tmpdepfile" 527880c7e28Smrg stat=$? 528880c7e28Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5294f00d7e1Smrg if test $stat -ne 0; then 530880c7e28Smrg rm -f "$tmpdepfile" 531880c7e28Smrg exit $stat 532880c7e28Smrg fi 533880c7e28Smrg rm -f "$depfile" 534880c7e28Smrg echo "$object : \\" > "$depfile" 535880c7e28Smrg # The first sed program below extracts the file names and escapes 536880c7e28Smrg # backslashes for cygpath. The second sed program outputs the file 537880c7e28Smrg # name when reading, but also accumulates all include files in the 538880c7e28Smrg # hold buffer in order to output them again at the end. This only 539880c7e28Smrg # works with sed implementations that can handle large buffers. 540880c7e28Smrg sed < "$tmpdepfile" -n ' 541880c7e28Smrg/^Note: including file: *\(.*\)/ { 542880c7e28Smrg s//\1/ 543880c7e28Smrg s/\\/\\\\/g 544880c7e28Smrg p 545880c7e28Smrg}' | $cygpath_u | sort -u | sed -n ' 546880c7e28Smrgs/ /\\ /g 5474f00d7e1Smrgs/\(.*\)/'"$tab"'\1 \\/p 548880c7e28Smrgs/.\(.*\) \\/\1:/ 549880c7e28SmrgH 550880c7e28Smrg$ { 5514f00d7e1Smrg s/.*/'"$tab"'/ 552880c7e28Smrg G 553880c7e28Smrg p 554880c7e28Smrg}' >> "$depfile" 5554f00d7e1Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556880c7e28Smrg rm -f "$tmpdepfile" 557880c7e28Smrg ;; 558880c7e28Smrg 559880c7e28Smrgmsvc7msys) 560880c7e28Smrg # This case exists only to let depend.m4 do its work. It works by 561880c7e28Smrg # looking at the text of this script. This case will never be run, 562880c7e28Smrg # since it is checked for above. 563880c7e28Smrg exit 1 564880c7e28Smrg ;; 565880c7e28Smrg 566bdcaa8d0Smrg#nosideeffect) 567bdcaa8d0Smrg # This comment above is used by automake to tell side-effect 568bdcaa8d0Smrg # dependency tracking mechanisms from slower ones. 569bdcaa8d0Smrg 570bdcaa8d0Smrgdashmstdout) 571bdcaa8d0Smrg # Important note: in order to support this mode, a compiler *must* 572bdcaa8d0Smrg # always write the preprocessed file to stdout, regardless of -o. 573bdcaa8d0Smrg "$@" || exit $? 574bdcaa8d0Smrg 575bdcaa8d0Smrg # Remove the call to Libtool. 576bdcaa8d0Smrg if test "$libtool" = yes; then 57796ce994aSmrg while test "X$1" != 'X--mode=compile'; do 578bdcaa8d0Smrg shift 579bdcaa8d0Smrg done 580bdcaa8d0Smrg shift 581bdcaa8d0Smrg fi 582bdcaa8d0Smrg 5834f00d7e1Smrg # Remove '-o $object'. 584bdcaa8d0Smrg IFS=" " 585bdcaa8d0Smrg for arg 586bdcaa8d0Smrg do 587bdcaa8d0Smrg case $arg in 588bdcaa8d0Smrg -o) 589bdcaa8d0Smrg shift 590bdcaa8d0Smrg ;; 591bdcaa8d0Smrg $object) 592bdcaa8d0Smrg shift 593bdcaa8d0Smrg ;; 594bdcaa8d0Smrg *) 595bdcaa8d0Smrg set fnord "$@" "$arg" 596bdcaa8d0Smrg shift # fnord 597bdcaa8d0Smrg shift # $arg 598bdcaa8d0Smrg ;; 599bdcaa8d0Smrg esac 600bdcaa8d0Smrg done 601bdcaa8d0Smrg 602bdcaa8d0Smrg test -z "$dashmflag" && dashmflag=-M 6034f00d7e1Smrg # Require at least two characters before searching for ':' 604bdcaa8d0Smrg # in the target name. This is to cope with DOS-style filenames: 6054f00d7e1Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606bdcaa8d0Smrg "$@" $dashmflag | 6074f00d7e1Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608bdcaa8d0Smrg rm -f "$depfile" 609bdcaa8d0Smrg cat < "$tmpdepfile" > "$depfile" 6104f00d7e1Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6114f00d7e1Smrg # correctly. Breaking it into two sed invocations is a workaround. 6124f00d7e1Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6134f00d7e1Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6144f00d7e1Smrg | sed -e 's/$/ :/' >> "$depfile" 615bdcaa8d0Smrg rm -f "$tmpdepfile" 616bdcaa8d0Smrg ;; 617bdcaa8d0Smrg 618bdcaa8d0SmrgdashXmstdout) 619bdcaa8d0Smrg # This case only exists to satisfy depend.m4. It is never actually 620bdcaa8d0Smrg # run, as this mode is specially recognized in the preamble. 621bdcaa8d0Smrg exit 1 622bdcaa8d0Smrg ;; 623bdcaa8d0Smrg 624bdcaa8d0Smrgmakedepend) 625bdcaa8d0Smrg "$@" || exit $? 626bdcaa8d0Smrg # Remove any Libtool call 627bdcaa8d0Smrg if test "$libtool" = yes; then 62896ce994aSmrg while test "X$1" != 'X--mode=compile'; do 629bdcaa8d0Smrg shift 630bdcaa8d0Smrg done 631bdcaa8d0Smrg shift 632bdcaa8d0Smrg fi 633bdcaa8d0Smrg # X makedepend 634bdcaa8d0Smrg shift 63596ce994aSmrg cleared=no eat=no 63696ce994aSmrg for arg 63796ce994aSmrg do 638bdcaa8d0Smrg case $cleared in 639bdcaa8d0Smrg no) 640bdcaa8d0Smrg set ""; shift 641bdcaa8d0Smrg cleared=yes ;; 642bdcaa8d0Smrg esac 64396ce994aSmrg if test $eat = yes; then 64496ce994aSmrg eat=no 64596ce994aSmrg continue 64696ce994aSmrg fi 647bdcaa8d0Smrg case "$arg" in 648bdcaa8d0Smrg -D*|-I*) 649bdcaa8d0Smrg set fnord "$@" "$arg"; shift ;; 650bdcaa8d0Smrg # Strip any option that makedepend may not understand. Remove 651bdcaa8d0Smrg # the object too, otherwise makedepend will parse it as a source file. 65296ce994aSmrg -arch) 65396ce994aSmrg eat=yes ;; 654bdcaa8d0Smrg -*|$object) 655bdcaa8d0Smrg ;; 656bdcaa8d0Smrg *) 657bdcaa8d0Smrg set fnord "$@" "$arg"; shift ;; 658bdcaa8d0Smrg esac 659bdcaa8d0Smrg done 66096ce994aSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661bdcaa8d0Smrg touch "$tmpdepfile" 662bdcaa8d0Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663bdcaa8d0Smrg rm -f "$depfile" 664880c7e28Smrg # makedepend may prepend the VPATH from the source file name to the object. 665880c7e28Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666880c7e28Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6674f00d7e1Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6684f00d7e1Smrg # correctly. Breaking it into two sed invocations is a workaround. 6694f00d7e1Smrg sed '1,2d' "$tmpdepfile" \ 6704f00d7e1Smrg | tr ' ' "$nl" \ 6714f00d7e1Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6724f00d7e1Smrg | sed -e 's/$/ :/' >> "$depfile" 673bdcaa8d0Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674bdcaa8d0Smrg ;; 675bdcaa8d0Smrg 676bdcaa8d0Smrgcpp) 677bdcaa8d0Smrg # Important note: in order to support this mode, a compiler *must* 678bdcaa8d0Smrg # always write the preprocessed file to stdout. 679bdcaa8d0Smrg "$@" || exit $? 680bdcaa8d0Smrg 681bdcaa8d0Smrg # Remove the call to Libtool. 682bdcaa8d0Smrg if test "$libtool" = yes; then 68396ce994aSmrg while test "X$1" != 'X--mode=compile'; do 684bdcaa8d0Smrg shift 685bdcaa8d0Smrg done 686bdcaa8d0Smrg shift 687bdcaa8d0Smrg fi 688bdcaa8d0Smrg 6894f00d7e1Smrg # Remove '-o $object'. 690bdcaa8d0Smrg IFS=" " 691bdcaa8d0Smrg for arg 692bdcaa8d0Smrg do 693bdcaa8d0Smrg case $arg in 694bdcaa8d0Smrg -o) 695bdcaa8d0Smrg shift 696bdcaa8d0Smrg ;; 697bdcaa8d0Smrg $object) 698bdcaa8d0Smrg shift 699bdcaa8d0Smrg ;; 700bdcaa8d0Smrg *) 701bdcaa8d0Smrg set fnord "$@" "$arg" 702bdcaa8d0Smrg shift # fnord 703bdcaa8d0Smrg shift # $arg 704bdcaa8d0Smrg ;; 705bdcaa8d0Smrg esac 706bdcaa8d0Smrg done 707bdcaa8d0Smrg 7084f00d7e1Smrg "$@" -E \ 7094f00d7e1Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7104f00d7e1Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7114f00d7e1Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712bdcaa8d0Smrg rm -f "$depfile" 713bdcaa8d0Smrg echo "$object : \\" > "$depfile" 714bdcaa8d0Smrg cat < "$tmpdepfile" >> "$depfile" 715bdcaa8d0Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716bdcaa8d0Smrg rm -f "$tmpdepfile" 717bdcaa8d0Smrg ;; 718bdcaa8d0Smrg 719bdcaa8d0Smrgmsvisualcpp) 720bdcaa8d0Smrg # Important note: in order to support this mode, a compiler *must* 72196ce994aSmrg # always write the preprocessed file to stdout. 722bdcaa8d0Smrg "$@" || exit $? 72396ce994aSmrg 72496ce994aSmrg # Remove the call to Libtool. 72596ce994aSmrg if test "$libtool" = yes; then 72696ce994aSmrg while test "X$1" != 'X--mode=compile'; do 72796ce994aSmrg shift 72896ce994aSmrg done 72996ce994aSmrg shift 73096ce994aSmrg fi 73196ce994aSmrg 732bdcaa8d0Smrg IFS=" " 733bdcaa8d0Smrg for arg 734bdcaa8d0Smrg do 735bdcaa8d0Smrg case "$arg" in 73696ce994aSmrg -o) 73796ce994aSmrg shift 73896ce994aSmrg ;; 73996ce994aSmrg $object) 74096ce994aSmrg shift 74196ce994aSmrg ;; 742bdcaa8d0Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7434f00d7e1Smrg set fnord "$@" 7444f00d7e1Smrg shift 7454f00d7e1Smrg shift 7464f00d7e1Smrg ;; 747bdcaa8d0Smrg *) 7484f00d7e1Smrg set fnord "$@" "$arg" 7494f00d7e1Smrg shift 7504f00d7e1Smrg shift 7514f00d7e1Smrg ;; 752bdcaa8d0Smrg esac 753bdcaa8d0Smrg done 75496ce994aSmrg "$@" -E 2>/dev/null | 75596ce994aSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756bdcaa8d0Smrg rm -f "$depfile" 757bdcaa8d0Smrg echo "$object : \\" > "$depfile" 7584f00d7e1Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7594f00d7e1Smrg echo "$tab" >> "$depfile" 76096ce994aSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761bdcaa8d0Smrg rm -f "$tmpdepfile" 762bdcaa8d0Smrg ;; 763bdcaa8d0Smrg 76496ce994aSmrgmsvcmsys) 76596ce994aSmrg # This case exists only to let depend.m4 do its work. It works by 76696ce994aSmrg # looking at the text of this script. This case will never be run, 76796ce994aSmrg # since it is checked for above. 76896ce994aSmrg exit 1 76996ce994aSmrg ;; 77096ce994aSmrg 771bdcaa8d0Smrgnone) 772bdcaa8d0Smrg exec "$@" 773bdcaa8d0Smrg ;; 774bdcaa8d0Smrg 775bdcaa8d0Smrg*) 776bdcaa8d0Smrg echo "Unknown depmode $depmode" 1>&2 777bdcaa8d0Smrg exit 1 778bdcaa8d0Smrg ;; 779bdcaa8d0Smrgesac 780bdcaa8d0Smrg 781bdcaa8d0Smrgexit 0 782bdcaa8d0Smrg 783bdcaa8d0Smrg# Local Variables: 784bdcaa8d0Smrg# mode: shell-script 785bdcaa8d0Smrg# sh-indentation: 2 786bdcaa8d0Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 787bdcaa8d0Smrg# time-stamp-start: "scriptversion=" 788bdcaa8d0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78996ce994aSmrg# time-stamp-time-zone: "UTC" 79096ce994aSmrg# time-stamp-end: "; # UTC" 791bdcaa8d0Smrg# End: 792