1ee3138f1Smrg#! /bin/sh 2ee3138f1Smrg# depcomp - compile a program generating dependencies as side-effects 3ee3138f1Smrg 48d623946Smrgscriptversion=2018-03-07.03; # UTC 5ee3138f1Smrg 68d623946Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7ee3138f1Smrg 8ee3138f1Smrg# This program is free software; you can redistribute it and/or modify 9ee3138f1Smrg# it under the terms of the GNU General Public License as published by 10ee3138f1Smrg# the Free Software Foundation; either version 2, or (at your option) 11ee3138f1Smrg# any later version. 12ee3138f1Smrg 13ee3138f1Smrg# This program is distributed in the hope that it will be useful, 14ee3138f1Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15ee3138f1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16ee3138f1Smrg# GNU General Public License for more details. 17ee3138f1Smrg 18ee3138f1Smrg# You should have received a copy of the GNU General Public License 198d623946Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20ee3138f1Smrg 21ee3138f1Smrg# As a special exception to the GNU General Public License, if you 22ee3138f1Smrg# distribute this file as part of a program that contains a 23ee3138f1Smrg# configuration script generated by Autoconf, you may include it under 24ee3138f1Smrg# the same distribution terms that you use for the rest of that program. 25ee3138f1Smrg 26ee3138f1Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27ee3138f1Smrg 28ee3138f1Smrgcase $1 in 29ee3138f1Smrg '') 30414bd68fSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31414bd68fSmrg exit 1; 32414bd68fSmrg ;; 33ee3138f1Smrg -h | --h*) 34ee3138f1Smrg cat <<\EOF 35ee3138f1SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36ee3138f1Smrg 37ee3138f1SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38ee3138f1Smrgas side-effects. 39ee3138f1Smrg 40ee3138f1SmrgEnvironment variables: 41ee3138f1Smrg depmode Dependency tracking mode. 423e72ca8cSmrg source Source file read by 'PROGRAMS ARGS'. 433e72ca8cSmrg object Object file output by 'PROGRAMS ARGS'. 44ee3138f1Smrg DEPDIR directory where to store dependencies. 45ee3138f1Smrg depfile Dependency file to output. 463e72ca8cSmrg tmpdepfile Temporary file to use when outputting dependencies. 47ee3138f1Smrg libtool Whether libtool is used (yes/no). 48ee3138f1Smrg 49ee3138f1SmrgReport bugs to <bug-automake@gnu.org>. 50ee3138f1SmrgEOF 51ee3138f1Smrg exit $? 52ee3138f1Smrg ;; 53ee3138f1Smrg -v | --v*) 54ee3138f1Smrg echo "depcomp $scriptversion" 55ee3138f1Smrg exit $? 56ee3138f1Smrg ;; 57ee3138f1Smrgesac 58ee3138f1Smrg 59414bd68fSmrg# Get the directory component of the given path, and save it in the 60414bd68fSmrg# global variables '$dir'. Note that this directory component will 61414bd68fSmrg# be either empty or ending with a '/' character. This is deliberate. 62414bd68fSmrgset_dir_from () 63414bd68fSmrg{ 64414bd68fSmrg case $1 in 65414bd68fSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66414bd68fSmrg *) dir=;; 67414bd68fSmrg esac 68414bd68fSmrg} 69414bd68fSmrg 70414bd68fSmrg# Get the suffix-stripped basename of the given path, and save it the 71414bd68fSmrg# global variable '$base'. 72414bd68fSmrgset_base_from () 73414bd68fSmrg{ 74414bd68fSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75414bd68fSmrg} 76414bd68fSmrg 77414bd68fSmrg# If no dependency file was actually created by the compiler invocation, 78414bd68fSmrg# we still have to create a dummy depfile, to avoid errors with the 79414bd68fSmrg# Makefile "include basename.Plo" scheme. 80414bd68fSmrgmake_dummy_depfile () 81414bd68fSmrg{ 82414bd68fSmrg echo "#dummy" > "$depfile" 83414bd68fSmrg} 84414bd68fSmrg 85414bd68fSmrg# Factor out some common post-processing of the generated depfile. 86414bd68fSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87414bd68fSmrgaix_post_process_depfile () 88414bd68fSmrg{ 89414bd68fSmrg # If the compiler actually managed to produce a dependency file, 90414bd68fSmrg # post-process it. 91414bd68fSmrg if test -f "$tmpdepfile"; then 92414bd68fSmrg # Each line is of the form 'foo.o: dependency.h'. 93414bd68fSmrg # Do two passes, one to just change these to 94414bd68fSmrg # $object: dependency.h 95414bd68fSmrg # and one to simply output 96414bd68fSmrg # dependency.h: 97414bd68fSmrg # which is needed to avoid the deleted-header problem. 98414bd68fSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99414bd68fSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100414bd68fSmrg } > "$depfile" 101414bd68fSmrg rm -f "$tmpdepfile" 102414bd68fSmrg else 103414bd68fSmrg make_dummy_depfile 104414bd68fSmrg fi 105414bd68fSmrg} 106414bd68fSmrg 1073e72ca8cSmrg# A tabulation character. 1083e72ca8cSmrgtab=' ' 1093e72ca8cSmrg# A newline character. 1103e72ca8cSmrgnl=' 1113e72ca8cSmrg' 112414bd68fSmrg# Character ranges might be problematic outside the C locale. 113414bd68fSmrg# These definitions help. 114414bd68fSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115414bd68fSmrglower=abcdefghijklmnopqrstuvwxyz 116414bd68fSmrgdigits=0123456789 117414bd68fSmrgalpha=${upper}${lower} 1183e72ca8cSmrg 119ee3138f1Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120ee3138f1Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121ee3138f1Smrg exit 1 122ee3138f1Smrgfi 123ee3138f1Smrg 124ee3138f1Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125ee3138f1Smrgdepfile=${depfile-`echo "$object" | 126ee3138f1Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127ee3138f1Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128ee3138f1Smrg 129ee3138f1Smrgrm -f "$tmpdepfile" 130ee3138f1Smrg 131414bd68fSmrg# Avoid interferences from the environment. 132414bd68fSmrggccflag= dashmflag= 133414bd68fSmrg 134ee3138f1Smrg# Some modes work just like other modes, but use different flags. We 135ee3138f1Smrg# parameterize here, but still list the modes in the big case below, 136ee3138f1Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137ee3138f1Smrg# here, because this file can only contain one case statement. 138ee3138f1Smrgif test "$depmode" = hp; then 139ee3138f1Smrg # HP compiler uses -M and no extra arg. 140ee3138f1Smrg gccflag=-M 141ee3138f1Smrg depmode=gcc 142ee3138f1Smrgfi 143ee3138f1Smrg 144ee3138f1Smrgif test "$depmode" = dashXmstdout; then 145414bd68fSmrg # This is just like dashmstdout with a different argument. 146414bd68fSmrg dashmflag=-xM 147414bd68fSmrg depmode=dashmstdout 148ee3138f1Smrgfi 149ee3138f1Smrg 15034977a2fSmrgcygpath_u="cygpath -u -f -" 15134977a2fSmrgif test "$depmode" = msvcmsys; then 152414bd68fSmrg # This is just like msvisualcpp but w/o cygpath translation. 153414bd68fSmrg # Just convert the backslash-escaped backslashes to single forward 154414bd68fSmrg # slashes to satisfy depend.m4 155414bd68fSmrg cygpath_u='sed s,\\\\,/,g' 156414bd68fSmrg depmode=msvisualcpp 15734977a2fSmrgfi 15834977a2fSmrg 1593e72ca8cSmrgif test "$depmode" = msvc7msys; then 160414bd68fSmrg # This is just like msvc7 but w/o cygpath translation. 161414bd68fSmrg # Just convert the backslash-escaped backslashes to single forward 162414bd68fSmrg # slashes to satisfy depend.m4 163414bd68fSmrg cygpath_u='sed s,\\\\,/,g' 164414bd68fSmrg depmode=msvc7 1653e72ca8cSmrgfi 1663e72ca8cSmrg 1673e72ca8cSmrgif test "$depmode" = xlc; then 168414bd68fSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169414bd68fSmrg gccflag=-qmakedep=gcc,-MF 170414bd68fSmrg depmode=gcc 1713e72ca8cSmrgfi 1723e72ca8cSmrg 173ee3138f1Smrgcase "$depmode" in 174ee3138f1Smrggcc3) 175ee3138f1Smrg## gcc 3 implements dependency tracking that does exactly what 176ee3138f1Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177ee3138f1Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178ee3138f1Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179ee3138f1Smrg## the command line argument order; so add the flags where they 180ee3138f1Smrg## appear in depend2.am. Note that the slowdown incurred here 181ee3138f1Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182ee3138f1Smrg for arg 183ee3138f1Smrg do 184ee3138f1Smrg case $arg in 185ee3138f1Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186ee3138f1Smrg *) set fnord "$@" "$arg" ;; 187ee3138f1Smrg esac 188ee3138f1Smrg shift # fnord 189ee3138f1Smrg shift # $arg 190ee3138f1Smrg done 191ee3138f1Smrg "$@" 192ee3138f1Smrg stat=$? 193414bd68fSmrg if test $stat -ne 0; then 194ee3138f1Smrg rm -f "$tmpdepfile" 195ee3138f1Smrg exit $stat 196ee3138f1Smrg fi 197ee3138f1Smrg mv "$tmpdepfile" "$depfile" 198ee3138f1Smrg ;; 199ee3138f1Smrg 200ee3138f1Smrggcc) 201414bd68fSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202414bd68fSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203414bd68fSmrg## (see the conditional assignment to $gccflag above). 204ee3138f1Smrg## There are various ways to get dependency output from gcc. Here's 205ee3138f1Smrg## why we pick this rather obscure method: 206ee3138f1Smrg## - Don't want to use -MD because we'd like the dependencies to end 207ee3138f1Smrg## up in a subdir. Having to rename by hand is ugly. 208ee3138f1Smrg## (We might end up doing this anyway to support other compilers.) 209ee3138f1Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210414bd68fSmrg## -MM, not -M (despite what the docs say). Also, it might not be 211414bd68fSmrg## supported by the other compilers which use the 'gcc' depmode. 212ee3138f1Smrg## - Using -M directly means running the compiler twice (even worse 213ee3138f1Smrg## than renaming). 214ee3138f1Smrg if test -z "$gccflag"; then 215ee3138f1Smrg gccflag=-MD, 216ee3138f1Smrg fi 217ee3138f1Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218ee3138f1Smrg stat=$? 219414bd68fSmrg if test $stat -ne 0; then 220ee3138f1Smrg rm -f "$tmpdepfile" 221ee3138f1Smrg exit $stat 222ee3138f1Smrg fi 223ee3138f1Smrg rm -f "$depfile" 224ee3138f1Smrg echo "$object : \\" > "$depfile" 225414bd68fSmrg # The second -e expression handles DOS-style file names with drive 226414bd68fSmrg # letters. 227ee3138f1Smrg sed -e 's/^[^:]*: / /' \ 228ee3138f1Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2293e72ca8cSmrg## This next piece of magic avoids the "deleted header file" problem. 230ee3138f1Smrg## The problem is that when a header file which appears in a .P file 231ee3138f1Smrg## is deleted, the dependency causes make to die (because there is 232ee3138f1Smrg## typically no way to rebuild the header). We avoid this by adding 233ee3138f1Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234ee3138f1Smrg## this for us directly. 2353e72ca8cSmrg## Some versions of gcc put a space before the ':'. On the theory 236ee3138f1Smrg## that the space means something, we add a space to the output as 2373e72ca8cSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 2383e72ca8cSmrg## to the object. Take care to not repeat it in the output. 239ee3138f1Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240ee3138f1Smrg## correctly. Breaking it into two sed invocations is a workaround. 241414bd68fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 242414bd68fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243414bd68fSmrg | sed -e 's/$/ :/' >> "$depfile" 244ee3138f1Smrg rm -f "$tmpdepfile" 245ee3138f1Smrg ;; 246ee3138f1Smrg 247ee3138f1Smrghp) 248ee3138f1Smrg # This case exists only to let depend.m4 do its work. It works by 249ee3138f1Smrg # looking at the text of this script. This case will never be run, 250ee3138f1Smrg # since it is checked for above. 251ee3138f1Smrg exit 1 252ee3138f1Smrg ;; 253ee3138f1Smrg 254ee3138f1Smrgsgi) 255ee3138f1Smrg if test "$libtool" = yes; then 256ee3138f1Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257ee3138f1Smrg else 258ee3138f1Smrg "$@" -MDupdate "$tmpdepfile" 259ee3138f1Smrg fi 260ee3138f1Smrg stat=$? 261414bd68fSmrg if test $stat -ne 0; then 262ee3138f1Smrg rm -f "$tmpdepfile" 263ee3138f1Smrg exit $stat 264ee3138f1Smrg fi 265ee3138f1Smrg rm -f "$depfile" 266ee3138f1Smrg 267ee3138f1Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268ee3138f1Smrg echo "$object : \\" > "$depfile" 269ee3138f1Smrg # Clip off the initial element (the dependent). Don't try to be 270ee3138f1Smrg # clever and replace this with sed code, as IRIX sed won't handle 271ee3138f1Smrg # lines with more than a fixed number of characters (4096 in 272ee3138f1Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2733e72ca8cSmrg # the IRIX cc adds comments like '#:fec' to the end of the 274ee3138f1Smrg # dependency line. 2753e72ca8cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 276414bd68fSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277414bd68fSmrg | tr "$nl" ' ' >> "$depfile" 27834977a2fSmrg echo >> "$depfile" 279ee3138f1Smrg # The second pass generates a dummy entry for each header file. 2803e72ca8cSmrg tr ' ' "$nl" < "$tmpdepfile" \ 281414bd68fSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282414bd68fSmrg >> "$depfile" 283ee3138f1Smrg else 284414bd68fSmrg make_dummy_depfile 285ee3138f1Smrg fi 286ee3138f1Smrg rm -f "$tmpdepfile" 287ee3138f1Smrg ;; 288ee3138f1Smrg 2893e72ca8cSmrgxlc) 2903e72ca8cSmrg # This case exists only to let depend.m4 do its work. It works by 2913e72ca8cSmrg # looking at the text of this script. This case will never be run, 2923e72ca8cSmrg # since it is checked for above. 2933e72ca8cSmrg exit 1 2943e72ca8cSmrg ;; 2953e72ca8cSmrg 296ee3138f1Smrgaix) 297ee3138f1Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298ee3138f1Smrg # in a .u file. In older versions, this file always lives in the 2993e72ca8cSmrg # current directory. Also, the AIX compiler puts '$object:' at the 300ee3138f1Smrg # start of each line; $object doesn't have directory information. 301ee3138f1Smrg # Version 6 uses the directory in both cases. 302414bd68fSmrg set_dir_from "$object" 303414bd68fSmrg set_base_from "$object" 304ee3138f1Smrg if test "$libtool" = yes; then 30579a8a9c6Smrg tmpdepfile1=$dir$base.u 30679a8a9c6Smrg tmpdepfile2=$base.u 30779a8a9c6Smrg tmpdepfile3=$dir.libs/$base.u 308ee3138f1Smrg "$@" -Wc,-M 309ee3138f1Smrg else 31079a8a9c6Smrg tmpdepfile1=$dir$base.u 31179a8a9c6Smrg tmpdepfile2=$dir$base.u 31279a8a9c6Smrg tmpdepfile3=$dir$base.u 313ee3138f1Smrg "$@" -M 314ee3138f1Smrg fi 315ee3138f1Smrg stat=$? 316414bd68fSmrg if test $stat -ne 0; then 31779a8a9c6Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318ee3138f1Smrg exit $stat 319ee3138f1Smrg fi 320ee3138f1Smrg 32179a8a9c6Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32279a8a9c6Smrg do 32379a8a9c6Smrg test -f "$tmpdepfile" && break 32479a8a9c6Smrg done 325414bd68fSmrg aix_post_process_depfile 326414bd68fSmrg ;; 327414bd68fSmrg 328414bd68fSmrgtcc) 329414bd68fSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330414bd68fSmrg # FIXME: That version still under development at the moment of writing. 331414bd68fSmrg # Make that this statement remains true also for stable, released 332414bd68fSmrg # versions. 333414bd68fSmrg # It will wrap lines (doesn't matter whether long or short) with a 334414bd68fSmrg # trailing '\', as in: 335414bd68fSmrg # 336414bd68fSmrg # foo.o : \ 337414bd68fSmrg # foo.c \ 338414bd68fSmrg # foo.h \ 339414bd68fSmrg # 340414bd68fSmrg # It will put a trailing '\' even on the last line, and will use leading 341414bd68fSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 342414bd68fSmrg # "Emit spaces for -MD"). 343414bd68fSmrg "$@" -MD -MF "$tmpdepfile" 344414bd68fSmrg stat=$? 345414bd68fSmrg if test $stat -ne 0; then 346414bd68fSmrg rm -f "$tmpdepfile" 347414bd68fSmrg exit $stat 348ee3138f1Smrg fi 349414bd68fSmrg rm -f "$depfile" 350414bd68fSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351414bd68fSmrg # We have to change lines of the first kind to '$object: \'. 352414bd68fSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353414bd68fSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 354414bd68fSmrg # dummy dependency, to avoid the deleted-header problem. 355414bd68fSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356ee3138f1Smrg rm -f "$tmpdepfile" 357ee3138f1Smrg ;; 358ee3138f1Smrg 359414bd68fSmrg## The order of this option in the case statement is important, since the 360414bd68fSmrg## shell code in configure will try each of these formats in the order 361414bd68fSmrg## listed in this file. A plain '-MD' option would be understood by many 362414bd68fSmrg## compilers, so we must ensure this comes after the gcc and icc options. 363414bd68fSmrgpgcc) 364414bd68fSmrg # Portland's C compiler understands '-MD'. 365414bd68fSmrg # Will always output deps to 'file.d' where file is the root name of the 366414bd68fSmrg # source file under compilation, even if file resides in a subdirectory. 367414bd68fSmrg # The object file name does not affect the name of the '.d' file. 368414bd68fSmrg # pgcc 10.2 will output 369ee3138f1Smrg # foo.o: sub/foo.c sub/foo.h 370414bd68fSmrg # and will wrap long lines using '\' : 371ee3138f1Smrg # foo.o: sub/foo.c ... \ 372ee3138f1Smrg # sub/foo.h ... \ 373ee3138f1Smrg # ... 374414bd68fSmrg set_dir_from "$object" 375414bd68fSmrg # Use the source, not the object, to determine the base name, since 376414bd68fSmrg # that's sadly what pgcc will do too. 377414bd68fSmrg set_base_from "$source" 378414bd68fSmrg tmpdepfile=$base.d 379414bd68fSmrg 380414bd68fSmrg # For projects that build the same source file twice into different object 381414bd68fSmrg # files, the pgcc approach of using the *source* file root name can cause 382414bd68fSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383414bd68fSmrg # the same $tmpdepfile. 384414bd68fSmrg lockdir=$base.d-lock 385414bd68fSmrg trap " 386414bd68fSmrg echo '$0: caught signal, cleaning up...' >&2 387414bd68fSmrg rmdir '$lockdir' 388414bd68fSmrg exit 1 389414bd68fSmrg " 1 2 13 15 390414bd68fSmrg numtries=100 391414bd68fSmrg i=$numtries 392414bd68fSmrg while test $i -gt 0; do 393414bd68fSmrg # mkdir is a portable test-and-set. 394414bd68fSmrg if mkdir "$lockdir" 2>/dev/null; then 395414bd68fSmrg # This process acquired the lock. 396414bd68fSmrg "$@" -MD 397414bd68fSmrg stat=$? 398414bd68fSmrg # Release the lock. 399414bd68fSmrg rmdir "$lockdir" 400414bd68fSmrg break 401414bd68fSmrg else 402414bd68fSmrg # If the lock is being held by a different process, wait 403414bd68fSmrg # until the winning process is done or we timeout. 404414bd68fSmrg while test -d "$lockdir" && test $i -gt 0; do 405414bd68fSmrg sleep 1 406414bd68fSmrg i=`expr $i - 1` 407414bd68fSmrg done 408414bd68fSmrg fi 409414bd68fSmrg i=`expr $i - 1` 410414bd68fSmrg done 411414bd68fSmrg trap - 1 2 13 15 412414bd68fSmrg if test $i -le 0; then 413414bd68fSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414414bd68fSmrg echo "$0: check lockdir '$lockdir'" >&2 415414bd68fSmrg exit 1 416414bd68fSmrg fi 417414bd68fSmrg 418414bd68fSmrg if test $stat -ne 0; then 419ee3138f1Smrg rm -f "$tmpdepfile" 420ee3138f1Smrg exit $stat 421ee3138f1Smrg fi 422ee3138f1Smrg rm -f "$depfile" 423414bd68fSmrg # Each line is of the form `foo.o: dependent.h', 424414bd68fSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425ee3138f1Smrg # Do two passes, one to just change these to 426414bd68fSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427414bd68fSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428414bd68fSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429414bd68fSmrg # correctly. Breaking it into two sed invocations is a workaround. 430414bd68fSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431414bd68fSmrg | sed -e 's/$/ :/' >> "$depfile" 432ee3138f1Smrg rm -f "$tmpdepfile" 433ee3138f1Smrg ;; 434ee3138f1Smrg 435ee3138f1Smrghp2) 436ee3138f1Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437ee3138f1Smrg # compilers, which have integrated preprocessors. The correct option 438ee3138f1Smrg # to use with these is +Maked; it writes dependencies to a file named 439ee3138f1Smrg # 'foo.d', which lands next to the object file, wherever that 440ee3138f1Smrg # happens to be. 441ee3138f1Smrg # Much of this is similar to the tru64 case; see comments there. 442414bd68fSmrg set_dir_from "$object" 443414bd68fSmrg set_base_from "$object" 444ee3138f1Smrg if test "$libtool" = yes; then 445ee3138f1Smrg tmpdepfile1=$dir$base.d 446ee3138f1Smrg tmpdepfile2=$dir.libs/$base.d 447ee3138f1Smrg "$@" -Wc,+Maked 448ee3138f1Smrg else 449ee3138f1Smrg tmpdepfile1=$dir$base.d 450ee3138f1Smrg tmpdepfile2=$dir$base.d 451ee3138f1Smrg "$@" +Maked 452ee3138f1Smrg fi 453ee3138f1Smrg stat=$? 454414bd68fSmrg if test $stat -ne 0; then 455ee3138f1Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456ee3138f1Smrg exit $stat 457ee3138f1Smrg fi 458ee3138f1Smrg 459ee3138f1Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460ee3138f1Smrg do 461ee3138f1Smrg test -f "$tmpdepfile" && break 462ee3138f1Smrg done 463ee3138f1Smrg if test -f "$tmpdepfile"; then 464414bd68fSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4653e72ca8cSmrg # Add 'dependent.h:' lines. 46634977a2fSmrg sed -ne '2,${ 467414bd68fSmrg s/^ *// 468414bd68fSmrg s/ \\*$// 469414bd68fSmrg s/$/:/ 470414bd68fSmrg p 471414bd68fSmrg }' "$tmpdepfile" >> "$depfile" 472ee3138f1Smrg else 473414bd68fSmrg make_dummy_depfile 474ee3138f1Smrg fi 475ee3138f1Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 476ee3138f1Smrg ;; 477ee3138f1Smrg 478ee3138f1Smrgtru64) 479414bd68fSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 480414bd68fSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481414bd68fSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482414bd68fSmrg # dependencies in 'foo.d' instead, so we check for that too. 483414bd68fSmrg # Subdirectories are respected. 484414bd68fSmrg set_dir_from "$object" 485414bd68fSmrg set_base_from "$object" 486414bd68fSmrg 487414bd68fSmrg if test "$libtool" = yes; then 488414bd68fSmrg # Libtool generates 2 separate objects for the 2 libraries. These 489414bd68fSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 490414bd68fSmrg # in $dir$base.o.d. We have to check for both files, because 491414bd68fSmrg # one of the two compilations can be disabled. We should prefer 492414bd68fSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493414bd68fSmrg # automatically cleaned when .libs/ is deleted, while ignoring 494414bd68fSmrg # the former would cause a distcleancheck panic. 495414bd68fSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496414bd68fSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497414bd68fSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498414bd68fSmrg "$@" -Wc,-MD 499414bd68fSmrg else 500414bd68fSmrg tmpdepfile1=$dir$base.d 501414bd68fSmrg tmpdepfile2=$dir$base.d 502414bd68fSmrg tmpdepfile3=$dir$base.d 503414bd68fSmrg "$@" -MD 504414bd68fSmrg fi 505414bd68fSmrg 506414bd68fSmrg stat=$? 507414bd68fSmrg if test $stat -ne 0; then 508414bd68fSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509414bd68fSmrg exit $stat 510414bd68fSmrg fi 511414bd68fSmrg 512414bd68fSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513414bd68fSmrg do 514414bd68fSmrg test -f "$tmpdepfile" && break 515414bd68fSmrg done 516414bd68fSmrg # Same post-processing that is required for AIX mode. 517414bd68fSmrg aix_post_process_depfile 518414bd68fSmrg ;; 519ee3138f1Smrg 5203e72ca8cSmrgmsvc7) 5213e72ca8cSmrg if test "$libtool" = yes; then 5223e72ca8cSmrg showIncludes=-Wc,-showIncludes 5233e72ca8cSmrg else 5243e72ca8cSmrg showIncludes=-showIncludes 5253e72ca8cSmrg fi 5263e72ca8cSmrg "$@" $showIncludes > "$tmpdepfile" 5273e72ca8cSmrg stat=$? 5283e72ca8cSmrg grep -v '^Note: including file: ' "$tmpdepfile" 529414bd68fSmrg if test $stat -ne 0; then 5303e72ca8cSmrg rm -f "$tmpdepfile" 5313e72ca8cSmrg exit $stat 5323e72ca8cSmrg fi 5333e72ca8cSmrg rm -f "$depfile" 5343e72ca8cSmrg echo "$object : \\" > "$depfile" 5353e72ca8cSmrg # The first sed program below extracts the file names and escapes 5363e72ca8cSmrg # backslashes for cygpath. The second sed program outputs the file 5373e72ca8cSmrg # name when reading, but also accumulates all include files in the 5383e72ca8cSmrg # hold buffer in order to output them again at the end. This only 5393e72ca8cSmrg # works with sed implementations that can handle large buffers. 5403e72ca8cSmrg sed < "$tmpdepfile" -n ' 5413e72ca8cSmrg/^Note: including file: *\(.*\)/ { 5423e72ca8cSmrg s//\1/ 5433e72ca8cSmrg s/\\/\\\\/g 5443e72ca8cSmrg p 5453e72ca8cSmrg}' | $cygpath_u | sort -u | sed -n ' 5463e72ca8cSmrgs/ /\\ /g 5473e72ca8cSmrgs/\(.*\)/'"$tab"'\1 \\/p 5483e72ca8cSmrgs/.\(.*\) \\/\1:/ 5493e72ca8cSmrgH 5503e72ca8cSmrg$ { 5513e72ca8cSmrg s/.*/'"$tab"'/ 5523e72ca8cSmrg G 5533e72ca8cSmrg p 5543e72ca8cSmrg}' >> "$depfile" 555414bd68fSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5563e72ca8cSmrg rm -f "$tmpdepfile" 5573e72ca8cSmrg ;; 5583e72ca8cSmrg 5593e72ca8cSmrgmsvc7msys) 5603e72ca8cSmrg # This case exists only to let depend.m4 do its work. It works by 5613e72ca8cSmrg # looking at the text of this script. This case will never be run, 5623e72ca8cSmrg # since it is checked for above. 5633e72ca8cSmrg exit 1 5643e72ca8cSmrg ;; 5653e72ca8cSmrg 566ee3138f1Smrg#nosideeffect) 567ee3138f1Smrg # This comment above is used by automake to tell side-effect 568ee3138f1Smrg # dependency tracking mechanisms from slower ones. 569ee3138f1Smrg 570ee3138f1Smrgdashmstdout) 571ee3138f1Smrg # Important note: in order to support this mode, a compiler *must* 572ee3138f1Smrg # always write the preprocessed file to stdout, regardless of -o. 573ee3138f1Smrg "$@" || exit $? 574ee3138f1Smrg 575ee3138f1Smrg # Remove the call to Libtool. 576ee3138f1Smrg if test "$libtool" = yes; then 57734977a2fSmrg while test "X$1" != 'X--mode=compile'; do 578ee3138f1Smrg shift 579ee3138f1Smrg done 580ee3138f1Smrg shift 581ee3138f1Smrg fi 582ee3138f1Smrg 5833e72ca8cSmrg # Remove '-o $object'. 584ee3138f1Smrg IFS=" " 585ee3138f1Smrg for arg 586ee3138f1Smrg do 587ee3138f1Smrg case $arg in 588ee3138f1Smrg -o) 589ee3138f1Smrg shift 590ee3138f1Smrg ;; 591ee3138f1Smrg $object) 592ee3138f1Smrg shift 593ee3138f1Smrg ;; 594ee3138f1Smrg *) 595ee3138f1Smrg set fnord "$@" "$arg" 596ee3138f1Smrg shift # fnord 597ee3138f1Smrg shift # $arg 598ee3138f1Smrg ;; 599ee3138f1Smrg esac 600ee3138f1Smrg done 601ee3138f1Smrg 602ee3138f1Smrg test -z "$dashmflag" && dashmflag=-M 6033e72ca8cSmrg # Require at least two characters before searching for ':' 604ee3138f1Smrg # in the target name. This is to cope with DOS-style filenames: 6053e72ca8cSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606ee3138f1Smrg "$@" $dashmflag | 607414bd68fSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608ee3138f1Smrg rm -f "$depfile" 609ee3138f1Smrg cat < "$tmpdepfile" > "$depfile" 610414bd68fSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611414bd68fSmrg # correctly. Breaking it into two sed invocations is a workaround. 612414bd68fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 613414bd68fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614414bd68fSmrg | sed -e 's/$/ :/' >> "$depfile" 615ee3138f1Smrg rm -f "$tmpdepfile" 616ee3138f1Smrg ;; 617ee3138f1Smrg 618ee3138f1SmrgdashXmstdout) 619ee3138f1Smrg # This case only exists to satisfy depend.m4. It is never actually 620ee3138f1Smrg # run, as this mode is specially recognized in the preamble. 621ee3138f1Smrg exit 1 622ee3138f1Smrg ;; 623ee3138f1Smrg 624ee3138f1Smrgmakedepend) 625ee3138f1Smrg "$@" || exit $? 626ee3138f1Smrg # Remove any Libtool call 627ee3138f1Smrg if test "$libtool" = yes; then 62834977a2fSmrg while test "X$1" != 'X--mode=compile'; do 629ee3138f1Smrg shift 630ee3138f1Smrg done 631ee3138f1Smrg shift 632ee3138f1Smrg fi 633ee3138f1Smrg # X makedepend 634ee3138f1Smrg shift 63534977a2fSmrg cleared=no eat=no 63634977a2fSmrg for arg 63734977a2fSmrg do 638ee3138f1Smrg case $cleared in 639ee3138f1Smrg no) 640ee3138f1Smrg set ""; shift 641ee3138f1Smrg cleared=yes ;; 642ee3138f1Smrg esac 64334977a2fSmrg if test $eat = yes; then 64434977a2fSmrg eat=no 64534977a2fSmrg continue 64634977a2fSmrg fi 647ee3138f1Smrg case "$arg" in 648ee3138f1Smrg -D*|-I*) 649ee3138f1Smrg set fnord "$@" "$arg"; shift ;; 650ee3138f1Smrg # Strip any option that makedepend may not understand. Remove 651ee3138f1Smrg # the object too, otherwise makedepend will parse it as a source file. 65234977a2fSmrg -arch) 65334977a2fSmrg eat=yes ;; 654ee3138f1Smrg -*|$object) 655ee3138f1Smrg ;; 656ee3138f1Smrg *) 657ee3138f1Smrg set fnord "$@" "$arg"; shift ;; 658ee3138f1Smrg esac 659ee3138f1Smrg done 66034977a2fSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661ee3138f1Smrg touch "$tmpdepfile" 662ee3138f1Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663ee3138f1Smrg rm -f "$depfile" 6643e72ca8cSmrg # makedepend may prepend the VPATH from the source file name to the object. 6653e72ca8cSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 6663e72ca8cSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667414bd68fSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668414bd68fSmrg # correctly. Breaking it into two sed invocations is a workaround. 669414bd68fSmrg sed '1,2d' "$tmpdepfile" \ 670414bd68fSmrg | tr ' ' "$nl" \ 671414bd68fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672414bd68fSmrg | sed -e 's/$/ :/' >> "$depfile" 673ee3138f1Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674ee3138f1Smrg ;; 675ee3138f1Smrg 676ee3138f1Smrgcpp) 677ee3138f1Smrg # Important note: in order to support this mode, a compiler *must* 678ee3138f1Smrg # always write the preprocessed file to stdout. 679ee3138f1Smrg "$@" || exit $? 680ee3138f1Smrg 681ee3138f1Smrg # Remove the call to Libtool. 682ee3138f1Smrg if test "$libtool" = yes; then 68334977a2fSmrg while test "X$1" != 'X--mode=compile'; do 684ee3138f1Smrg shift 685ee3138f1Smrg done 686ee3138f1Smrg shift 687ee3138f1Smrg fi 688ee3138f1Smrg 6893e72ca8cSmrg # Remove '-o $object'. 690ee3138f1Smrg IFS=" " 691ee3138f1Smrg for arg 692ee3138f1Smrg do 693ee3138f1Smrg case $arg in 694ee3138f1Smrg -o) 695ee3138f1Smrg shift 696ee3138f1Smrg ;; 697ee3138f1Smrg $object) 698ee3138f1Smrg shift 699ee3138f1Smrg ;; 700ee3138f1Smrg *) 701ee3138f1Smrg set fnord "$@" "$arg" 702ee3138f1Smrg shift # fnord 703ee3138f1Smrg shift # $arg 704ee3138f1Smrg ;; 705ee3138f1Smrg esac 706ee3138f1Smrg done 707ee3138f1Smrg 708414bd68fSmrg "$@" -E \ 709414bd68fSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710414bd68fSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711414bd68fSmrg | sed '$ s: \\$::' > "$tmpdepfile" 712ee3138f1Smrg rm -f "$depfile" 713ee3138f1Smrg echo "$object : \\" > "$depfile" 714ee3138f1Smrg cat < "$tmpdepfile" >> "$depfile" 715ee3138f1Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716ee3138f1Smrg rm -f "$tmpdepfile" 717ee3138f1Smrg ;; 718ee3138f1Smrg 719ee3138f1Smrgmsvisualcpp) 720ee3138f1Smrg # Important note: in order to support this mode, a compiler *must* 72134977a2fSmrg # always write the preprocessed file to stdout. 722ee3138f1Smrg "$@" || exit $? 72334977a2fSmrg 72434977a2fSmrg # Remove the call to Libtool. 72534977a2fSmrg if test "$libtool" = yes; then 72634977a2fSmrg while test "X$1" != 'X--mode=compile'; do 72734977a2fSmrg shift 72834977a2fSmrg done 72934977a2fSmrg shift 73034977a2fSmrg fi 73134977a2fSmrg 732ee3138f1Smrg IFS=" " 733ee3138f1Smrg for arg 734ee3138f1Smrg do 735ee3138f1Smrg case "$arg" in 73634977a2fSmrg -o) 73734977a2fSmrg shift 73834977a2fSmrg ;; 73934977a2fSmrg $object) 74034977a2fSmrg shift 74134977a2fSmrg ;; 742ee3138f1Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743414bd68fSmrg set fnord "$@" 744414bd68fSmrg shift 745414bd68fSmrg shift 746414bd68fSmrg ;; 747ee3138f1Smrg *) 748414bd68fSmrg set fnord "$@" "$arg" 749414bd68fSmrg shift 750414bd68fSmrg shift 751414bd68fSmrg ;; 752ee3138f1Smrg esac 753ee3138f1Smrg done 75434977a2fSmrg "$@" -E 2>/dev/null | 75534977a2fSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756ee3138f1Smrg rm -f "$depfile" 757ee3138f1Smrg echo "$object : \\" > "$depfile" 7583e72ca8cSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7593e72ca8cSmrg echo "$tab" >> "$depfile" 76034977a2fSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761ee3138f1Smrg rm -f "$tmpdepfile" 762ee3138f1Smrg ;; 763ee3138f1Smrg 76434977a2fSmrgmsvcmsys) 76534977a2fSmrg # This case exists only to let depend.m4 do its work. It works by 76634977a2fSmrg # looking at the text of this script. This case will never be run, 76734977a2fSmrg # since it is checked for above. 76834977a2fSmrg exit 1 76934977a2fSmrg ;; 77034977a2fSmrg 771ee3138f1Smrgnone) 772ee3138f1Smrg exec "$@" 773ee3138f1Smrg ;; 774ee3138f1Smrg 775ee3138f1Smrg*) 776ee3138f1Smrg echo "Unknown depmode $depmode" 1>&2 777ee3138f1Smrg exit 1 778ee3138f1Smrg ;; 779ee3138f1Smrgesac 780ee3138f1Smrg 781ee3138f1Smrgexit 0 782ee3138f1Smrg 783ee3138f1Smrg# Local Variables: 784ee3138f1Smrg# mode: shell-script 785ee3138f1Smrg# sh-indentation: 2 7868d623946Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 787ee3138f1Smrg# time-stamp-start: "scriptversion=" 788ee3138f1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7898d623946Smrg# time-stamp-time-zone: "UTC0" 79034977a2fSmrg# time-stamp-end: "; # UTC" 791ee3138f1Smrg# End: 792