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