19027f4a0Smrg#! /bin/sh 29027f4a0Smrg# depcomp - compile a program generating dependencies as side-effects 39027f4a0Smrg 40d6f290aSmrgscriptversion=2018-03-07.03; # UTC 59027f4a0Smrg 60d6f290aSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 79027f4a0Smrg 89027f4a0Smrg# This program is free software; you can redistribute it and/or modify 99027f4a0Smrg# it under the terms of the GNU General Public License as published by 109027f4a0Smrg# the Free Software Foundation; either version 2, or (at your option) 119027f4a0Smrg# any later version. 129027f4a0Smrg 139027f4a0Smrg# This program is distributed in the hope that it will be useful, 149027f4a0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 159027f4a0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 169027f4a0Smrg# GNU General Public License for more details. 179027f4a0Smrg 189027f4a0Smrg# You should have received a copy of the GNU General Public License 190d6f290aSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 209027f4a0Smrg 219027f4a0Smrg# As a special exception to the GNU General Public License, if you 229027f4a0Smrg# distribute this file as part of a program that contains a 239027f4a0Smrg# configuration script generated by Autoconf, you may include it under 249027f4a0Smrg# the same distribution terms that you use for the rest of that program. 259027f4a0Smrg 269027f4a0Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 279027f4a0Smrg 289027f4a0Smrgcase $1 in 299027f4a0Smrg '') 30fe2ac8d7Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31fe2ac8d7Smrg exit 1; 32fe2ac8d7Smrg ;; 339027f4a0Smrg -h | --h*) 349027f4a0Smrg cat <<\EOF 359027f4a0SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 369027f4a0Smrg 379027f4a0SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 389027f4a0Smrgas side-effects. 399027f4a0Smrg 409027f4a0SmrgEnvironment variables: 419027f4a0Smrg depmode Dependency tracking mode. 42fe2ac8d7Smrg source Source file read by 'PROGRAMS ARGS'. 43fe2ac8d7Smrg object Object file output by 'PROGRAMS ARGS'. 449027f4a0Smrg DEPDIR directory where to store dependencies. 459027f4a0Smrg depfile Dependency file to output. 46fe2ac8d7Smrg tmpdepfile Temporary file to use when outputting dependencies. 479027f4a0Smrg libtool Whether libtool is used (yes/no). 489027f4a0Smrg 499027f4a0SmrgReport bugs to <bug-automake@gnu.org>. 509027f4a0SmrgEOF 519027f4a0Smrg exit $? 529027f4a0Smrg ;; 539027f4a0Smrg -v | --v*) 549027f4a0Smrg echo "depcomp $scriptversion" 559027f4a0Smrg exit $? 569027f4a0Smrg ;; 579027f4a0Smrgesac 589027f4a0Smrg 59fe2ac8d7Smrg# Get the directory component of the given path, and save it in the 60fe2ac8d7Smrg# global variables '$dir'. Note that this directory component will 61fe2ac8d7Smrg# be either empty or ending with a '/' character. This is deliberate. 62fe2ac8d7Smrgset_dir_from () 63fe2ac8d7Smrg{ 64fe2ac8d7Smrg case $1 in 65fe2ac8d7Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66fe2ac8d7Smrg *) dir=;; 67fe2ac8d7Smrg esac 68fe2ac8d7Smrg} 69fe2ac8d7Smrg 70fe2ac8d7Smrg# Get the suffix-stripped basename of the given path, and save it the 71fe2ac8d7Smrg# global variable '$base'. 72fe2ac8d7Smrgset_base_from () 73fe2ac8d7Smrg{ 74fe2ac8d7Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75fe2ac8d7Smrg} 76fe2ac8d7Smrg 77fe2ac8d7Smrg# If no dependency file was actually created by the compiler invocation, 78fe2ac8d7Smrg# we still have to create a dummy depfile, to avoid errors with the 79fe2ac8d7Smrg# Makefile "include basename.Plo" scheme. 80fe2ac8d7Smrgmake_dummy_depfile () 81fe2ac8d7Smrg{ 82fe2ac8d7Smrg echo "#dummy" > "$depfile" 83fe2ac8d7Smrg} 84fe2ac8d7Smrg 85fe2ac8d7Smrg# Factor out some common post-processing of the generated depfile. 86fe2ac8d7Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87fe2ac8d7Smrgaix_post_process_depfile () 88fe2ac8d7Smrg{ 89fe2ac8d7Smrg # If the compiler actually managed to produce a dependency file, 90fe2ac8d7Smrg # post-process it. 91fe2ac8d7Smrg if test -f "$tmpdepfile"; then 92fe2ac8d7Smrg # Each line is of the form 'foo.o: dependency.h'. 93fe2ac8d7Smrg # Do two passes, one to just change these to 94fe2ac8d7Smrg # $object: dependency.h 95fe2ac8d7Smrg # and one to simply output 96fe2ac8d7Smrg # dependency.h: 97fe2ac8d7Smrg # which is needed to avoid the deleted-header problem. 98fe2ac8d7Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99fe2ac8d7Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100fe2ac8d7Smrg } > "$depfile" 101fe2ac8d7Smrg rm -f "$tmpdepfile" 102fe2ac8d7Smrg else 103fe2ac8d7Smrg make_dummy_depfile 104fe2ac8d7Smrg fi 105fe2ac8d7Smrg} 106fe2ac8d7Smrg 107fe2ac8d7Smrg# A tabulation character. 108fe2ac8d7Smrgtab=' ' 109fe2ac8d7Smrg# A newline character. 110fe2ac8d7Smrgnl=' 111fe2ac8d7Smrg' 112fe2ac8d7Smrg# Character ranges might be problematic outside the C locale. 113fe2ac8d7Smrg# These definitions help. 114fe2ac8d7Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115fe2ac8d7Smrglower=abcdefghijklmnopqrstuvwxyz 116fe2ac8d7Smrgdigits=0123456789 117fe2ac8d7Smrgalpha=${upper}${lower} 118fe2ac8d7Smrg 1199027f4a0Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1209027f4a0Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1219027f4a0Smrg exit 1 1229027f4a0Smrgfi 1239027f4a0Smrg 1249027f4a0Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1259027f4a0Smrgdepfile=${depfile-`echo "$object" | 1269027f4a0Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1279027f4a0Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1289027f4a0Smrg 1299027f4a0Smrgrm -f "$tmpdepfile" 1309027f4a0Smrg 131fe2ac8d7Smrg# Avoid interferences from the environment. 132fe2ac8d7Smrggccflag= dashmflag= 133fe2ac8d7Smrg 1349027f4a0Smrg# Some modes work just like other modes, but use different flags. We 1359027f4a0Smrg# parameterize here, but still list the modes in the big case below, 1369027f4a0Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1379027f4a0Smrg# here, because this file can only contain one case statement. 1389027f4a0Smrgif test "$depmode" = hp; then 1399027f4a0Smrg # HP compiler uses -M and no extra arg. 1409027f4a0Smrg gccflag=-M 1419027f4a0Smrg depmode=gcc 1429027f4a0Smrgfi 1439027f4a0Smrg 1449027f4a0Smrgif test "$depmode" = dashXmstdout; then 145fe2ac8d7Smrg # This is just like dashmstdout with a different argument. 146fe2ac8d7Smrg dashmflag=-xM 147fe2ac8d7Smrg depmode=dashmstdout 1489027f4a0Smrgfi 1499027f4a0Smrg 1503a72f200Smrgcygpath_u="cygpath -u -f -" 1513a72f200Smrgif test "$depmode" = msvcmsys; then 152fe2ac8d7Smrg # This is just like msvisualcpp but w/o cygpath translation. 153fe2ac8d7Smrg # Just convert the backslash-escaped backslashes to single forward 154fe2ac8d7Smrg # slashes to satisfy depend.m4 155fe2ac8d7Smrg cygpath_u='sed s,\\\\,/,g' 156fe2ac8d7Smrg depmode=msvisualcpp 157fe2ac8d7Smrgfi 158fe2ac8d7Smrg 159fe2ac8d7Smrgif test "$depmode" = msvc7msys; then 160fe2ac8d7Smrg # This is just like msvc7 but w/o cygpath translation. 161fe2ac8d7Smrg # Just convert the backslash-escaped backslashes to single forward 162fe2ac8d7Smrg # slashes to satisfy depend.m4 163fe2ac8d7Smrg cygpath_u='sed s,\\\\,/,g' 164fe2ac8d7Smrg depmode=msvc7 165fe2ac8d7Smrgfi 166fe2ac8d7Smrg 167fe2ac8d7Smrgif test "$depmode" = xlc; then 168fe2ac8d7Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169fe2ac8d7Smrg gccflag=-qmakedep=gcc,-MF 170fe2ac8d7Smrg depmode=gcc 1713a72f200Smrgfi 1723a72f200Smrg 1739027f4a0Smrgcase "$depmode" in 1749027f4a0Smrggcc3) 1759027f4a0Smrg## gcc 3 implements dependency tracking that does exactly what 1769027f4a0Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1779027f4a0Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1783a72f200Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1793a72f200Smrg## the command line argument order; so add the flags where they 1803a72f200Smrg## appear in depend2.am. Note that the slowdown incurred here 1813a72f200Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1823a72f200Smrg for arg 1833a72f200Smrg do 1843a72f200Smrg case $arg in 1853a72f200Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1863a72f200Smrg *) set fnord "$@" "$arg" ;; 1873a72f200Smrg esac 1883a72f200Smrg shift # fnord 1893a72f200Smrg shift # $arg 1903a72f200Smrg done 1913a72f200Smrg "$@" 1929027f4a0Smrg stat=$? 193fe2ac8d7Smrg if test $stat -ne 0; then 1949027f4a0Smrg rm -f "$tmpdepfile" 1959027f4a0Smrg exit $stat 1969027f4a0Smrg fi 1979027f4a0Smrg mv "$tmpdepfile" "$depfile" 1989027f4a0Smrg ;; 1999027f4a0Smrg 2009027f4a0Smrggcc) 201fe2ac8d7Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202fe2ac8d7Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203fe2ac8d7Smrg## (see the conditional assignment to $gccflag above). 2049027f4a0Smrg## There are various ways to get dependency output from gcc. Here's 2059027f4a0Smrg## why we pick this rather obscure method: 2069027f4a0Smrg## - Don't want to use -MD because we'd like the dependencies to end 2079027f4a0Smrg## up in a subdir. Having to rename by hand is ugly. 2089027f4a0Smrg## (We might end up doing this anyway to support other compilers.) 2099027f4a0Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210fe2ac8d7Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211fe2ac8d7Smrg## supported by the other compilers which use the 'gcc' depmode. 2129027f4a0Smrg## - Using -M directly means running the compiler twice (even worse 2139027f4a0Smrg## than renaming). 2149027f4a0Smrg if test -z "$gccflag"; then 2159027f4a0Smrg gccflag=-MD, 2169027f4a0Smrg fi 2179027f4a0Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2189027f4a0Smrg stat=$? 219fe2ac8d7Smrg if test $stat -ne 0; then 2209027f4a0Smrg rm -f "$tmpdepfile" 2219027f4a0Smrg exit $stat 2229027f4a0Smrg fi 2239027f4a0Smrg rm -f "$depfile" 2249027f4a0Smrg echo "$object : \\" > "$depfile" 225fe2ac8d7Smrg # The second -e expression handles DOS-style file names with drive 226fe2ac8d7Smrg # letters. 2279027f4a0Smrg sed -e 's/^[^:]*: / /' \ 2289027f4a0Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229fe2ac8d7Smrg## This next piece of magic avoids the "deleted header file" problem. 2309027f4a0Smrg## The problem is that when a header file which appears in a .P file 2319027f4a0Smrg## is deleted, the dependency causes make to die (because there is 2329027f4a0Smrg## typically no way to rebuild the header). We avoid this by adding 2339027f4a0Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2349027f4a0Smrg## this for us directly. 235fe2ac8d7Smrg## Some versions of gcc put a space before the ':'. On the theory 2369027f4a0Smrg## that the space means something, we add a space to the output as 237fe2ac8d7Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238fe2ac8d7Smrg## to the object. Take care to not repeat it in the output. 2399027f4a0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2409027f4a0Smrg## correctly. Breaking it into two sed invocations is a workaround. 241fe2ac8d7Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242fe2ac8d7Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243fe2ac8d7Smrg | sed -e 's/$/ :/' >> "$depfile" 2449027f4a0Smrg rm -f "$tmpdepfile" 2459027f4a0Smrg ;; 2469027f4a0Smrg 2479027f4a0Smrghp) 2489027f4a0Smrg # This case exists only to let depend.m4 do its work. It works by 2499027f4a0Smrg # looking at the text of this script. This case will never be run, 2509027f4a0Smrg # since it is checked for above. 2519027f4a0Smrg exit 1 2529027f4a0Smrg ;; 2539027f4a0Smrg 2549027f4a0Smrgsgi) 2559027f4a0Smrg if test "$libtool" = yes; then 2569027f4a0Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2579027f4a0Smrg else 2589027f4a0Smrg "$@" -MDupdate "$tmpdepfile" 2599027f4a0Smrg fi 2609027f4a0Smrg stat=$? 261fe2ac8d7Smrg if test $stat -ne 0; then 2629027f4a0Smrg rm -f "$tmpdepfile" 2639027f4a0Smrg exit $stat 2649027f4a0Smrg fi 2659027f4a0Smrg rm -f "$depfile" 2669027f4a0Smrg 2679027f4a0Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2689027f4a0Smrg echo "$object : \\" > "$depfile" 2699027f4a0Smrg # Clip off the initial element (the dependent). Don't try to be 2709027f4a0Smrg # clever and replace this with sed code, as IRIX sed won't handle 2719027f4a0Smrg # lines with more than a fixed number of characters (4096 in 2729027f4a0Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273fe2ac8d7Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2749027f4a0Smrg # dependency line. 275fe2ac8d7Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276fe2ac8d7Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277fe2ac8d7Smrg | tr "$nl" ' ' >> "$depfile" 2783a72f200Smrg echo >> "$depfile" 2799027f4a0Smrg # The second pass generates a dummy entry for each header file. 280fe2ac8d7Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281fe2ac8d7Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282fe2ac8d7Smrg >> "$depfile" 2839027f4a0Smrg else 284fe2ac8d7Smrg make_dummy_depfile 2859027f4a0Smrg fi 2869027f4a0Smrg rm -f "$tmpdepfile" 2879027f4a0Smrg ;; 2889027f4a0Smrg 289fe2ac8d7Smrgxlc) 290fe2ac8d7Smrg # This case exists only to let depend.m4 do its work. It works by 291fe2ac8d7Smrg # looking at the text of this script. This case will never be run, 292fe2ac8d7Smrg # since it is checked for above. 293fe2ac8d7Smrg exit 1 294fe2ac8d7Smrg ;; 295fe2ac8d7Smrg 2969027f4a0Smrgaix) 2979027f4a0Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2989027f4a0Smrg # in a .u file. In older versions, this file always lives in the 299fe2ac8d7Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3009027f4a0Smrg # start of each line; $object doesn't have directory information. 3019027f4a0Smrg # Version 6 uses the directory in both cases. 302fe2ac8d7Smrg set_dir_from "$object" 303fe2ac8d7Smrg set_base_from "$object" 3049027f4a0Smrg if test "$libtool" = yes; then 3053a72f200Smrg tmpdepfile1=$dir$base.u 3063a72f200Smrg tmpdepfile2=$base.u 3073a72f200Smrg tmpdepfile3=$dir.libs/$base.u 3089027f4a0Smrg "$@" -Wc,-M 3099027f4a0Smrg else 3103a72f200Smrg tmpdepfile1=$dir$base.u 3113a72f200Smrg tmpdepfile2=$dir$base.u 3123a72f200Smrg tmpdepfile3=$dir$base.u 3139027f4a0Smrg "$@" -M 3149027f4a0Smrg fi 3159027f4a0Smrg stat=$? 316fe2ac8d7Smrg if test $stat -ne 0; then 3173a72f200Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3189027f4a0Smrg exit $stat 3199027f4a0Smrg fi 3209027f4a0Smrg 3213a72f200Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3223a72f200Smrg do 3233a72f200Smrg test -f "$tmpdepfile" && break 3243a72f200Smrg done 325fe2ac8d7Smrg aix_post_process_depfile 326fe2ac8d7Smrg ;; 327fe2ac8d7Smrg 328fe2ac8d7Smrgtcc) 329fe2ac8d7Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330fe2ac8d7Smrg # FIXME: That version still under development at the moment of writing. 331fe2ac8d7Smrg # Make that this statement remains true also for stable, released 332fe2ac8d7Smrg # versions. 333fe2ac8d7Smrg # It will wrap lines (doesn't matter whether long or short) with a 334fe2ac8d7Smrg # trailing '\', as in: 335fe2ac8d7Smrg # 336fe2ac8d7Smrg # foo.o : \ 337fe2ac8d7Smrg # foo.c \ 338fe2ac8d7Smrg # foo.h \ 339fe2ac8d7Smrg # 340fe2ac8d7Smrg # It will put a trailing '\' even on the last line, and will use leading 341fe2ac8d7Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342fe2ac8d7Smrg # "Emit spaces for -MD"). 343fe2ac8d7Smrg "$@" -MD -MF "$tmpdepfile" 344fe2ac8d7Smrg stat=$? 345fe2ac8d7Smrg if test $stat -ne 0; then 346fe2ac8d7Smrg rm -f "$tmpdepfile" 347fe2ac8d7Smrg exit $stat 3489027f4a0Smrg fi 349fe2ac8d7Smrg rm -f "$depfile" 350fe2ac8d7Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351fe2ac8d7Smrg # We have to change lines of the first kind to '$object: \'. 352fe2ac8d7Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353fe2ac8d7Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354fe2ac8d7Smrg # dummy dependency, to avoid the deleted-header problem. 355fe2ac8d7Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3569027f4a0Smrg rm -f "$tmpdepfile" 3579027f4a0Smrg ;; 3589027f4a0Smrg 359fe2ac8d7Smrg## The order of this option in the case statement is important, since the 360fe2ac8d7Smrg## shell code in configure will try each of these formats in the order 361fe2ac8d7Smrg## listed in this file. A plain '-MD' option would be understood by many 362fe2ac8d7Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363fe2ac8d7Smrgpgcc) 364fe2ac8d7Smrg # Portland's C compiler understands '-MD'. 365fe2ac8d7Smrg # Will always output deps to 'file.d' where file is the root name of the 366fe2ac8d7Smrg # source file under compilation, even if file resides in a subdirectory. 367fe2ac8d7Smrg # The object file name does not affect the name of the '.d' file. 368fe2ac8d7Smrg # pgcc 10.2 will output 3699027f4a0Smrg # foo.o: sub/foo.c sub/foo.h 370fe2ac8d7Smrg # and will wrap long lines using '\' : 3719027f4a0Smrg # foo.o: sub/foo.c ... \ 3729027f4a0Smrg # sub/foo.h ... \ 3739027f4a0Smrg # ... 374fe2ac8d7Smrg set_dir_from "$object" 375fe2ac8d7Smrg # Use the source, not the object, to determine the base name, since 376fe2ac8d7Smrg # that's sadly what pgcc will do too. 377fe2ac8d7Smrg set_base_from "$source" 378fe2ac8d7Smrg tmpdepfile=$base.d 379fe2ac8d7Smrg 380fe2ac8d7Smrg # For projects that build the same source file twice into different object 381fe2ac8d7Smrg # files, the pgcc approach of using the *source* file root name can cause 382fe2ac8d7Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383fe2ac8d7Smrg # the same $tmpdepfile. 384fe2ac8d7Smrg lockdir=$base.d-lock 385fe2ac8d7Smrg trap " 386fe2ac8d7Smrg echo '$0: caught signal, cleaning up...' >&2 387fe2ac8d7Smrg rmdir '$lockdir' 388fe2ac8d7Smrg exit 1 389fe2ac8d7Smrg " 1 2 13 15 390fe2ac8d7Smrg numtries=100 391fe2ac8d7Smrg i=$numtries 392fe2ac8d7Smrg while test $i -gt 0; do 393fe2ac8d7Smrg # mkdir is a portable test-and-set. 394fe2ac8d7Smrg if mkdir "$lockdir" 2>/dev/null; then 395fe2ac8d7Smrg # This process acquired the lock. 396fe2ac8d7Smrg "$@" -MD 397fe2ac8d7Smrg stat=$? 398fe2ac8d7Smrg # Release the lock. 399fe2ac8d7Smrg rmdir "$lockdir" 400fe2ac8d7Smrg break 401fe2ac8d7Smrg else 402fe2ac8d7Smrg # If the lock is being held by a different process, wait 403fe2ac8d7Smrg # until the winning process is done or we timeout. 404fe2ac8d7Smrg while test -d "$lockdir" && test $i -gt 0; do 405fe2ac8d7Smrg sleep 1 406fe2ac8d7Smrg i=`expr $i - 1` 407fe2ac8d7Smrg done 408fe2ac8d7Smrg fi 409fe2ac8d7Smrg i=`expr $i - 1` 410fe2ac8d7Smrg done 411fe2ac8d7Smrg trap - 1 2 13 15 412fe2ac8d7Smrg if test $i -le 0; then 413fe2ac8d7Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414fe2ac8d7Smrg echo "$0: check lockdir '$lockdir'" >&2 415fe2ac8d7Smrg exit 1 416fe2ac8d7Smrg fi 4179027f4a0Smrg 418fe2ac8d7Smrg if test $stat -ne 0; then 4199027f4a0Smrg rm -f "$tmpdepfile" 4209027f4a0Smrg exit $stat 4219027f4a0Smrg fi 4229027f4a0Smrg rm -f "$depfile" 4239027f4a0Smrg # Each line is of the form `foo.o: dependent.h', 4249027f4a0Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4259027f4a0Smrg # Do two passes, one to just change these to 4269027f4a0Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4279027f4a0Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4289027f4a0Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4299027f4a0Smrg # correctly. Breaking it into two sed invocations is a workaround. 430fe2ac8d7Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431fe2ac8d7Smrg | sed -e 's/$/ :/' >> "$depfile" 4329027f4a0Smrg rm -f "$tmpdepfile" 4339027f4a0Smrg ;; 4349027f4a0Smrg 4353a72f200Smrghp2) 4363a72f200Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4373a72f200Smrg # compilers, which have integrated preprocessors. The correct option 4383a72f200Smrg # to use with these is +Maked; it writes dependencies to a file named 4393a72f200Smrg # 'foo.d', which lands next to the object file, wherever that 4403a72f200Smrg # happens to be. 4413a72f200Smrg # Much of this is similar to the tru64 case; see comments there. 442fe2ac8d7Smrg set_dir_from "$object" 443fe2ac8d7Smrg set_base_from "$object" 4443a72f200Smrg if test "$libtool" = yes; then 4453a72f200Smrg tmpdepfile1=$dir$base.d 4463a72f200Smrg tmpdepfile2=$dir.libs/$base.d 4473a72f200Smrg "$@" -Wc,+Maked 4483a72f200Smrg else 4493a72f200Smrg tmpdepfile1=$dir$base.d 4503a72f200Smrg tmpdepfile2=$dir$base.d 4513a72f200Smrg "$@" +Maked 4523a72f200Smrg fi 4533a72f200Smrg stat=$? 454fe2ac8d7Smrg if test $stat -ne 0; then 4553a72f200Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4563a72f200Smrg exit $stat 4573a72f200Smrg fi 4583a72f200Smrg 4593a72f200Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4603a72f200Smrg do 4613a72f200Smrg test -f "$tmpdepfile" && break 4623a72f200Smrg done 4633a72f200Smrg if test -f "$tmpdepfile"; then 464fe2ac8d7Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465fe2ac8d7Smrg # Add 'dependent.h:' lines. 4663a72f200Smrg sed -ne '2,${ 467fe2ac8d7Smrg s/^ *// 468fe2ac8d7Smrg s/ \\*$// 469fe2ac8d7Smrg s/$/:/ 470fe2ac8d7Smrg p 471fe2ac8d7Smrg }' "$tmpdepfile" >> "$depfile" 4723a72f200Smrg else 473fe2ac8d7Smrg make_dummy_depfile 4743a72f200Smrg fi 4753a72f200Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4763a72f200Smrg ;; 4773a72f200Smrg 4789027f4a0Smrgtru64) 479fe2ac8d7Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480fe2ac8d7Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481fe2ac8d7Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482fe2ac8d7Smrg # dependencies in 'foo.d' instead, so we check for that too. 483fe2ac8d7Smrg # Subdirectories are respected. 484fe2ac8d7Smrg set_dir_from "$object" 485fe2ac8d7Smrg set_base_from "$object" 486fe2ac8d7Smrg 487fe2ac8d7Smrg if test "$libtool" = yes; then 488fe2ac8d7Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489fe2ac8d7Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490fe2ac8d7Smrg # in $dir$base.o.d. We have to check for both files, because 491fe2ac8d7Smrg # one of the two compilations can be disabled. We should prefer 492fe2ac8d7Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493fe2ac8d7Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494fe2ac8d7Smrg # the former would cause a distcleancheck panic. 495fe2ac8d7Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496fe2ac8d7Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497fe2ac8d7Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498fe2ac8d7Smrg "$@" -Wc,-MD 499fe2ac8d7Smrg else 500fe2ac8d7Smrg tmpdepfile1=$dir$base.d 501fe2ac8d7Smrg tmpdepfile2=$dir$base.d 502fe2ac8d7Smrg tmpdepfile3=$dir$base.d 503fe2ac8d7Smrg "$@" -MD 504fe2ac8d7Smrg fi 505fe2ac8d7Smrg 506fe2ac8d7Smrg stat=$? 507fe2ac8d7Smrg if test $stat -ne 0; then 508fe2ac8d7Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509fe2ac8d7Smrg exit $stat 510fe2ac8d7Smrg fi 511fe2ac8d7Smrg 512fe2ac8d7Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513fe2ac8d7Smrg do 514fe2ac8d7Smrg test -f "$tmpdepfile" && break 515fe2ac8d7Smrg done 516fe2ac8d7Smrg # Same post-processing that is required for AIX mode. 517fe2ac8d7Smrg aix_post_process_depfile 518fe2ac8d7Smrg ;; 519fe2ac8d7Smrg 520fe2ac8d7Smrgmsvc7) 521fe2ac8d7Smrg if test "$libtool" = yes; then 522fe2ac8d7Smrg showIncludes=-Wc,-showIncludes 523fe2ac8d7Smrg else 524fe2ac8d7Smrg showIncludes=-showIncludes 525fe2ac8d7Smrg fi 526fe2ac8d7Smrg "$@" $showIncludes > "$tmpdepfile" 527fe2ac8d7Smrg stat=$? 528fe2ac8d7Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529fe2ac8d7Smrg if test $stat -ne 0; then 530fe2ac8d7Smrg rm -f "$tmpdepfile" 531fe2ac8d7Smrg exit $stat 532fe2ac8d7Smrg fi 533fe2ac8d7Smrg rm -f "$depfile" 534fe2ac8d7Smrg echo "$object : \\" > "$depfile" 535fe2ac8d7Smrg # The first sed program below extracts the file names and escapes 536fe2ac8d7Smrg # backslashes for cygpath. The second sed program outputs the file 537fe2ac8d7Smrg # name when reading, but also accumulates all include files in the 538fe2ac8d7Smrg # hold buffer in order to output them again at the end. This only 539fe2ac8d7Smrg # works with sed implementations that can handle large buffers. 540fe2ac8d7Smrg sed < "$tmpdepfile" -n ' 541fe2ac8d7Smrg/^Note: including file: *\(.*\)/ { 542fe2ac8d7Smrg s//\1/ 543fe2ac8d7Smrg s/\\/\\\\/g 544fe2ac8d7Smrg p 545fe2ac8d7Smrg}' | $cygpath_u | sort -u | sed -n ' 546fe2ac8d7Smrgs/ /\\ /g 547fe2ac8d7Smrgs/\(.*\)/'"$tab"'\1 \\/p 548fe2ac8d7Smrgs/.\(.*\) \\/\1:/ 549fe2ac8d7SmrgH 550fe2ac8d7Smrg$ { 551fe2ac8d7Smrg s/.*/'"$tab"'/ 552fe2ac8d7Smrg G 553fe2ac8d7Smrg p 554fe2ac8d7Smrg}' >> "$depfile" 555376c9fa8Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556fe2ac8d7Smrg rm -f "$tmpdepfile" 557fe2ac8d7Smrg ;; 558fe2ac8d7Smrg 559fe2ac8d7Smrgmsvc7msys) 560fe2ac8d7Smrg # This case exists only to let depend.m4 do its work. It works by 561fe2ac8d7Smrg # looking at the text of this script. This case will never be run, 562fe2ac8d7Smrg # since it is checked for above. 563fe2ac8d7Smrg exit 1 564fe2ac8d7Smrg ;; 5659027f4a0Smrg 5669027f4a0Smrg#nosideeffect) 5679027f4a0Smrg # This comment above is used by automake to tell side-effect 5689027f4a0Smrg # dependency tracking mechanisms from slower ones. 5699027f4a0Smrg 5709027f4a0Smrgdashmstdout) 5719027f4a0Smrg # Important note: in order to support this mode, a compiler *must* 5729027f4a0Smrg # always write the preprocessed file to stdout, regardless of -o. 5739027f4a0Smrg "$@" || exit $? 5749027f4a0Smrg 5759027f4a0Smrg # Remove the call to Libtool. 5769027f4a0Smrg if test "$libtool" = yes; then 5773a72f200Smrg while test "X$1" != 'X--mode=compile'; do 5789027f4a0Smrg shift 5799027f4a0Smrg done 5809027f4a0Smrg shift 5819027f4a0Smrg fi 5829027f4a0Smrg 583fe2ac8d7Smrg # Remove '-o $object'. 5849027f4a0Smrg IFS=" " 5859027f4a0Smrg for arg 5869027f4a0Smrg do 5879027f4a0Smrg case $arg in 5889027f4a0Smrg -o) 5899027f4a0Smrg shift 5909027f4a0Smrg ;; 5919027f4a0Smrg $object) 5929027f4a0Smrg shift 5939027f4a0Smrg ;; 5949027f4a0Smrg *) 5959027f4a0Smrg set fnord "$@" "$arg" 5969027f4a0Smrg shift # fnord 5979027f4a0Smrg shift # $arg 5989027f4a0Smrg ;; 5999027f4a0Smrg esac 6009027f4a0Smrg done 6019027f4a0Smrg 6029027f4a0Smrg test -z "$dashmflag" && dashmflag=-M 603fe2ac8d7Smrg # Require at least two characters before searching for ':' 6049027f4a0Smrg # in the target name. This is to cope with DOS-style filenames: 605fe2ac8d7Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6069027f4a0Smrg "$@" $dashmflag | 607fe2ac8d7Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6089027f4a0Smrg rm -f "$depfile" 6099027f4a0Smrg cat < "$tmpdepfile" > "$depfile" 610fe2ac8d7Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611fe2ac8d7Smrg # correctly. Breaking it into two sed invocations is a workaround. 612fe2ac8d7Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613fe2ac8d7Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614fe2ac8d7Smrg | sed -e 's/$/ :/' >> "$depfile" 6159027f4a0Smrg rm -f "$tmpdepfile" 6169027f4a0Smrg ;; 6179027f4a0Smrg 6189027f4a0SmrgdashXmstdout) 6199027f4a0Smrg # This case only exists to satisfy depend.m4. It is never actually 6209027f4a0Smrg # run, as this mode is specially recognized in the preamble. 6219027f4a0Smrg exit 1 6229027f4a0Smrg ;; 6239027f4a0Smrg 6249027f4a0Smrgmakedepend) 6259027f4a0Smrg "$@" || exit $? 6269027f4a0Smrg # Remove any Libtool call 6279027f4a0Smrg if test "$libtool" = yes; then 6283a72f200Smrg while test "X$1" != 'X--mode=compile'; do 6299027f4a0Smrg shift 6309027f4a0Smrg done 6319027f4a0Smrg shift 6329027f4a0Smrg fi 6339027f4a0Smrg # X makedepend 6349027f4a0Smrg shift 6353a72f200Smrg cleared=no eat=no 6363a72f200Smrg for arg 6373a72f200Smrg do 6389027f4a0Smrg case $cleared in 6399027f4a0Smrg no) 6409027f4a0Smrg set ""; shift 6419027f4a0Smrg cleared=yes ;; 6429027f4a0Smrg esac 6433a72f200Smrg if test $eat = yes; then 6443a72f200Smrg eat=no 6453a72f200Smrg continue 6463a72f200Smrg fi 6479027f4a0Smrg case "$arg" in 6489027f4a0Smrg -D*|-I*) 6499027f4a0Smrg set fnord "$@" "$arg"; shift ;; 6509027f4a0Smrg # Strip any option that makedepend may not understand. Remove 6519027f4a0Smrg # the object too, otherwise makedepend will parse it as a source file. 6523a72f200Smrg -arch) 6533a72f200Smrg eat=yes ;; 6549027f4a0Smrg -*|$object) 6559027f4a0Smrg ;; 6569027f4a0Smrg *) 6579027f4a0Smrg set fnord "$@" "$arg"; shift ;; 6589027f4a0Smrg esac 6599027f4a0Smrg done 6603a72f200Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6619027f4a0Smrg touch "$tmpdepfile" 6629027f4a0Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6639027f4a0Smrg rm -f "$depfile" 664fe2ac8d7Smrg # makedepend may prepend the VPATH from the source file name to the object. 665fe2ac8d7Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666fe2ac8d7Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667fe2ac8d7Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668fe2ac8d7Smrg # correctly. Breaking it into two sed invocations is a workaround. 669fe2ac8d7Smrg sed '1,2d' "$tmpdepfile" \ 670fe2ac8d7Smrg | tr ' ' "$nl" \ 671fe2ac8d7Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672fe2ac8d7Smrg | sed -e 's/$/ :/' >> "$depfile" 6739027f4a0Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6749027f4a0Smrg ;; 6759027f4a0Smrg 6769027f4a0Smrgcpp) 6779027f4a0Smrg # Important note: in order to support this mode, a compiler *must* 6789027f4a0Smrg # always write the preprocessed file to stdout. 6799027f4a0Smrg "$@" || exit $? 6809027f4a0Smrg 6819027f4a0Smrg # Remove the call to Libtool. 6829027f4a0Smrg if test "$libtool" = yes; then 6833a72f200Smrg while test "X$1" != 'X--mode=compile'; do 6849027f4a0Smrg shift 6859027f4a0Smrg done 6869027f4a0Smrg shift 6879027f4a0Smrg fi 6889027f4a0Smrg 689fe2ac8d7Smrg # Remove '-o $object'. 6909027f4a0Smrg IFS=" " 6919027f4a0Smrg for arg 6929027f4a0Smrg do 6939027f4a0Smrg case $arg in 6949027f4a0Smrg -o) 6959027f4a0Smrg shift 6969027f4a0Smrg ;; 6979027f4a0Smrg $object) 6989027f4a0Smrg shift 6999027f4a0Smrg ;; 7009027f4a0Smrg *) 7019027f4a0Smrg set fnord "$@" "$arg" 7029027f4a0Smrg shift # fnord 7039027f4a0Smrg shift # $arg 7049027f4a0Smrg ;; 7059027f4a0Smrg esac 7069027f4a0Smrg done 7079027f4a0Smrg 708fe2ac8d7Smrg "$@" -E \ 709fe2ac8d7Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710fe2ac8d7Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711fe2ac8d7Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7129027f4a0Smrg rm -f "$depfile" 7139027f4a0Smrg echo "$object : \\" > "$depfile" 7149027f4a0Smrg cat < "$tmpdepfile" >> "$depfile" 7159027f4a0Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7169027f4a0Smrg rm -f "$tmpdepfile" 7179027f4a0Smrg ;; 7189027f4a0Smrg 7199027f4a0Smrgmsvisualcpp) 7209027f4a0Smrg # Important note: in order to support this mode, a compiler *must* 7213a72f200Smrg # always write the preprocessed file to stdout. 7229027f4a0Smrg "$@" || exit $? 7233a72f200Smrg 7243a72f200Smrg # Remove the call to Libtool. 7253a72f200Smrg if test "$libtool" = yes; then 7263a72f200Smrg while test "X$1" != 'X--mode=compile'; do 7273a72f200Smrg shift 7283a72f200Smrg done 7293a72f200Smrg shift 7303a72f200Smrg fi 7313a72f200Smrg 7329027f4a0Smrg IFS=" " 7339027f4a0Smrg for arg 7349027f4a0Smrg do 7359027f4a0Smrg case "$arg" in 7363a72f200Smrg -o) 7373a72f200Smrg shift 7383a72f200Smrg ;; 7393a72f200Smrg $object) 7403a72f200Smrg shift 7413a72f200Smrg ;; 7429027f4a0Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743fe2ac8d7Smrg set fnord "$@" 744fe2ac8d7Smrg shift 745fe2ac8d7Smrg shift 746fe2ac8d7Smrg ;; 7479027f4a0Smrg *) 748fe2ac8d7Smrg set fnord "$@" "$arg" 749fe2ac8d7Smrg shift 750fe2ac8d7Smrg shift 751fe2ac8d7Smrg ;; 7529027f4a0Smrg esac 7539027f4a0Smrg done 7543a72f200Smrg "$@" -E 2>/dev/null | 7553a72f200Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7569027f4a0Smrg rm -f "$depfile" 7579027f4a0Smrg echo "$object : \\" > "$depfile" 758fe2ac8d7Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759fe2ac8d7Smrg echo "$tab" >> "$depfile" 7603a72f200Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7619027f4a0Smrg rm -f "$tmpdepfile" 7629027f4a0Smrg ;; 7639027f4a0Smrg 7643a72f200Smrgmsvcmsys) 7653a72f200Smrg # This case exists only to let depend.m4 do its work. It works by 7663a72f200Smrg # looking at the text of this script. This case will never be run, 7673a72f200Smrg # since it is checked for above. 7683a72f200Smrg exit 1 7693a72f200Smrg ;; 7703a72f200Smrg 7719027f4a0Smrgnone) 7729027f4a0Smrg exec "$@" 7739027f4a0Smrg ;; 7749027f4a0Smrg 7759027f4a0Smrg*) 7769027f4a0Smrg echo "Unknown depmode $depmode" 1>&2 7779027f4a0Smrg exit 1 7789027f4a0Smrg ;; 7799027f4a0Smrgesac 7809027f4a0Smrg 7819027f4a0Smrgexit 0 7829027f4a0Smrg 7839027f4a0Smrg# Local Variables: 7849027f4a0Smrg# mode: shell-script 7859027f4a0Smrg# sh-indentation: 2 7860d6f290aSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7879027f4a0Smrg# time-stamp-start: "scriptversion=" 7889027f4a0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7890d6f290aSmrg# time-stamp-time-zone: "UTC0" 7903a72f200Smrg# time-stamp-end: "; # UTC" 7919027f4a0Smrg# End: 792