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