1597410b8Schristos#! /bin/sh 2597410b8Schristos# depcomp - compile a program generating dependencies as side-effects 3597410b8Schristos 4*9d210927Schristosscriptversion=2013-05-30.07; # UTC 5597410b8Schristos 6*9d210927Schristos# Copyright (C) 1999-2014 Free Software Foundation, Inc. 7597410b8Schristos 8597410b8Schristos# This program is free software; you can redistribute it and/or modify 9597410b8Schristos# it under the terms of the GNU General Public License as published by 10597410b8Schristos# the Free Software Foundation; either version 2, or (at your option) 11597410b8Schristos# any later version. 12597410b8Schristos 13597410b8Schristos# This program is distributed in the hope that it will be useful, 14597410b8Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of 15597410b8Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16597410b8Schristos# GNU General Public License for more details. 17597410b8Schristos 18597410b8Schristos# You should have received a copy of the GNU General Public License 19597410b8Schristos# along with this program. If not, see <http://www.gnu.org/licenses/>. 20597410b8Schristos 21597410b8Schristos# As a special exception to the GNU General Public License, if you 22597410b8Schristos# distribute this file as part of a program that contains a 23597410b8Schristos# configuration script generated by Autoconf, you may include it under 24597410b8Schristos# the same distribution terms that you use for the rest of that program. 25597410b8Schristos 26597410b8Schristos# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27597410b8Schristos 28597410b8Schristoscase $1 in 29597410b8Schristos '') 30*9d210927Schristos echo "$0: No command. Try '$0 --help' for more information." 1>&2 31597410b8Schristos exit 1; 32597410b8Schristos ;; 33597410b8Schristos -h | --h*) 34597410b8Schristos cat <<\EOF 35597410b8SchristosUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36597410b8Schristos 37597410b8SchristosRun PROGRAMS ARGS to compile a file, generating dependencies 38597410b8Schristosas side-effects. 39597410b8Schristos 40597410b8SchristosEnvironment variables: 41597410b8Schristos depmode Dependency tracking mode. 42*9d210927Schristos source Source file read by 'PROGRAMS ARGS'. 43*9d210927Schristos object Object file output by 'PROGRAMS ARGS'. 44597410b8Schristos DEPDIR directory where to store dependencies. 45597410b8Schristos depfile Dependency file to output. 46*9d210927Schristos tmpdepfile Temporary file to use when outputting dependencies. 47597410b8Schristos libtool Whether libtool is used (yes/no). 48597410b8Schristos 49597410b8SchristosReport bugs to <bug-automake@gnu.org>. 50597410b8SchristosEOF 51597410b8Schristos exit $? 52597410b8Schristos ;; 53597410b8Schristos -v | --v*) 54597410b8Schristos echo "depcomp $scriptversion" 55597410b8Schristos exit $? 56597410b8Schristos ;; 57597410b8Schristosesac 58597410b8Schristos 59*9d210927Schristos# Get the directory component of the given path, and save it in the 60*9d210927Schristos# global variables '$dir'. Note that this directory component will 61*9d210927Schristos# be either empty or ending with a '/' character. This is deliberate. 62*9d210927Schristosset_dir_from () 63*9d210927Schristos{ 64*9d210927Schristos case $1 in 65*9d210927Schristos */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66*9d210927Schristos *) dir=;; 67*9d210927Schristos esac 68*9d210927Schristos} 69*9d210927Schristos 70*9d210927Schristos# Get the suffix-stripped basename of the given path, and save it the 71*9d210927Schristos# global variable '$base'. 72*9d210927Schristosset_base_from () 73*9d210927Schristos{ 74*9d210927Schristos base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75*9d210927Schristos} 76*9d210927Schristos 77*9d210927Schristos# If no dependency file was actually created by the compiler invocation, 78*9d210927Schristos# we still have to create a dummy depfile, to avoid errors with the 79*9d210927Schristos# Makefile "include basename.Plo" scheme. 80*9d210927Schristosmake_dummy_depfile () 81*9d210927Schristos{ 82*9d210927Schristos echo "#dummy" > "$depfile" 83*9d210927Schristos} 84*9d210927Schristos 85*9d210927Schristos# Factor out some common post-processing of the generated depfile. 86*9d210927Schristos# Requires the auxiliary global variable '$tmpdepfile' to be set. 87*9d210927Schristosaix_post_process_depfile () 88*9d210927Schristos{ 89*9d210927Schristos # If the compiler actually managed to produce a dependency file, 90*9d210927Schristos # post-process it. 91*9d210927Schristos if test -f "$tmpdepfile"; then 92*9d210927Schristos # Each line is of the form 'foo.o: dependency.h'. 93*9d210927Schristos # Do two passes, one to just change these to 94*9d210927Schristos # $object: dependency.h 95*9d210927Schristos # and one to simply output 96*9d210927Schristos # dependency.h: 97*9d210927Schristos # which is needed to avoid the deleted-header problem. 98*9d210927Schristos { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99*9d210927Schristos sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100*9d210927Schristos } > "$depfile" 101*9d210927Schristos rm -f "$tmpdepfile" 102*9d210927Schristos else 103*9d210927Schristos make_dummy_depfile 104*9d210927Schristos fi 105*9d210927Schristos} 106*9d210927Schristos 107*9d210927Schristos# A tabulation character. 108*9d210927Schristostab=' ' 109*9d210927Schristos# A newline character. 110*9d210927Schristosnl=' 111*9d210927Schristos' 112*9d210927Schristos# Character ranges might be problematic outside the C locale. 113*9d210927Schristos# These definitions help. 114*9d210927Schristosupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115*9d210927Schristoslower=abcdefghijklmnopqrstuvwxyz 116*9d210927Schristosdigits=0123456789 117*9d210927Schristosalpha=${upper}${lower} 118*9d210927Schristos 119597410b8Schristosif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120597410b8Schristos echo "depcomp: Variables source, object and depmode must be set" 1>&2 121597410b8Schristos exit 1 122597410b8Schristosfi 123597410b8Schristos 124597410b8Schristos# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125597410b8Schristosdepfile=${depfile-`echo "$object" | 126597410b8Schristos sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127597410b8Schristostmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128597410b8Schristos 129597410b8Schristosrm -f "$tmpdepfile" 130597410b8Schristos 131*9d210927Schristos# Avoid interferences from the environment. 132*9d210927Schristosgccflag= dashmflag= 133*9d210927Schristos 134597410b8Schristos# Some modes work just like other modes, but use different flags. We 135597410b8Schristos# parameterize here, but still list the modes in the big case below, 136597410b8Schristos# to make depend.m4 easier to write. Note that we *cannot* use a case 137597410b8Schristos# here, because this file can only contain one case statement. 138597410b8Schristosif test "$depmode" = hp; then 139597410b8Schristos # HP compiler uses -M and no extra arg. 140597410b8Schristos gccflag=-M 141597410b8Schristos depmode=gcc 142597410b8Schristosfi 143597410b8Schristos 144597410b8Schristosif test "$depmode" = dashXmstdout; then 145597410b8Schristos # This is just like dashmstdout with a different argument. 146597410b8Schristos dashmflag=-xM 147597410b8Schristos depmode=dashmstdout 148597410b8Schristosfi 149597410b8Schristos 150597410b8Schristoscygpath_u="cygpath -u -f -" 151597410b8Schristosif test "$depmode" = msvcmsys; then 152597410b8Schristos # This is just like msvisualcpp but w/o cygpath translation. 153597410b8Schristos # Just convert the backslash-escaped backslashes to single forward 154597410b8Schristos # slashes to satisfy depend.m4 155*9d210927Schristos cygpath_u='sed s,\\\\,/,g' 156597410b8Schristos depmode=msvisualcpp 157597410b8Schristosfi 158597410b8Schristos 159*9d210927Schristosif test "$depmode" = msvc7msys; then 160*9d210927Schristos # This is just like msvc7 but w/o cygpath translation. 161*9d210927Schristos # Just convert the backslash-escaped backslashes to single forward 162*9d210927Schristos # slashes to satisfy depend.m4 163*9d210927Schristos cygpath_u='sed s,\\\\,/,g' 164*9d210927Schristos depmode=msvc7 165*9d210927Schristosfi 166*9d210927Schristos 167*9d210927Schristosif test "$depmode" = xlc; then 168*9d210927Schristos # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169*9d210927Schristos gccflag=-qmakedep=gcc,-MF 170*9d210927Schristos depmode=gcc 171*9d210927Schristosfi 172*9d210927Schristos 173597410b8Schristoscase "$depmode" in 174597410b8Schristosgcc3) 175597410b8Schristos## gcc 3 implements dependency tracking that does exactly what 176597410b8Schristos## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177597410b8Schristos## it if -MD -MP comes after the -MF stuff. Hmm. 178597410b8Schristos## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179597410b8Schristos## the command line argument order; so add the flags where they 180597410b8Schristos## appear in depend2.am. Note that the slowdown incurred here 181597410b8Schristos## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182597410b8Schristos for arg 183597410b8Schristos do 184597410b8Schristos case $arg in 185597410b8Schristos -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186597410b8Schristos *) set fnord "$@" "$arg" ;; 187597410b8Schristos esac 188597410b8Schristos shift # fnord 189597410b8Schristos shift # $arg 190597410b8Schristos done 191597410b8Schristos "$@" 192597410b8Schristos stat=$? 193*9d210927Schristos if test $stat -ne 0; then 194597410b8Schristos rm -f "$tmpdepfile" 195597410b8Schristos exit $stat 196597410b8Schristos fi 197597410b8Schristos mv "$tmpdepfile" "$depfile" 198597410b8Schristos ;; 199597410b8Schristos 200597410b8Schristosgcc) 201*9d210927Schristos## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202*9d210927Schristos## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203*9d210927Schristos## (see the conditional assignment to $gccflag above). 204597410b8Schristos## There are various ways to get dependency output from gcc. Here's 205597410b8Schristos## why we pick this rather obscure method: 206597410b8Schristos## - Don't want to use -MD because we'd like the dependencies to end 207597410b8Schristos## up in a subdir. Having to rename by hand is ugly. 208597410b8Schristos## (We might end up doing this anyway to support other compilers.) 209597410b8Schristos## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210*9d210927Schristos## -MM, not -M (despite what the docs say). Also, it might not be 211*9d210927Schristos## supported by the other compilers which use the 'gcc' depmode. 212597410b8Schristos## - Using -M directly means running the compiler twice (even worse 213597410b8Schristos## than renaming). 214597410b8Schristos if test -z "$gccflag"; then 215597410b8Schristos gccflag=-MD, 216597410b8Schristos fi 217597410b8Schristos "$@" -Wp,"$gccflag$tmpdepfile" 218597410b8Schristos stat=$? 219*9d210927Schristos if test $stat -ne 0; then 220597410b8Schristos rm -f "$tmpdepfile" 221597410b8Schristos exit $stat 222597410b8Schristos fi 223597410b8Schristos rm -f "$depfile" 224597410b8Schristos echo "$object : \\" > "$depfile" 225*9d210927Schristos # The second -e expression handles DOS-style file names with drive 226*9d210927Schristos # letters. 227597410b8Schristos sed -e 's/^[^:]*: / /' \ 228597410b8Schristos -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229*9d210927Schristos## This next piece of magic avoids the "deleted header file" problem. 230597410b8Schristos## The problem is that when a header file which appears in a .P file 231597410b8Schristos## is deleted, the dependency causes make to die (because there is 232597410b8Schristos## typically no way to rebuild the header). We avoid this by adding 233597410b8Schristos## dummy dependencies for each header file. Too bad gcc doesn't do 234597410b8Schristos## this for us directly. 235*9d210927Schristos## Some versions of gcc put a space before the ':'. On the theory 236597410b8Schristos## that the space means something, we add a space to the output as 237*9d210927Schristos## well. hp depmode also adds that space, but also prefixes the VPATH 238*9d210927Schristos## to the object. Take care to not repeat it in the output. 239597410b8Schristos## Some versions of the HPUX 10.20 sed can't process this invocation 240597410b8Schristos## correctly. Breaking it into two sed invocations is a workaround. 241*9d210927Schristos tr ' ' "$nl" < "$tmpdepfile" \ 242*9d210927Schristos | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243*9d210927Schristos | sed -e 's/$/ :/' >> "$depfile" 244597410b8Schristos rm -f "$tmpdepfile" 245597410b8Schristos ;; 246597410b8Schristos 247597410b8Schristoshp) 248597410b8Schristos # This case exists only to let depend.m4 do its work. It works by 249597410b8Schristos # looking at the text of this script. This case will never be run, 250597410b8Schristos # since it is checked for above. 251597410b8Schristos exit 1 252597410b8Schristos ;; 253597410b8Schristos 254*9d210927Schristosxlc) 255*9d210927Schristos # This case exists only to let depend.m4 do its work. It works by 256*9d210927Schristos # looking at the text of this script. This case will never be run, 257*9d210927Schristos # since it is checked for above. 258*9d210927Schristos exit 1 259597410b8Schristos ;; 260597410b8Schristos 261597410b8Schristosaix) 262597410b8Schristos # The C for AIX Compiler uses -M and outputs the dependencies 263597410b8Schristos # in a .u file. In older versions, this file always lives in the 264*9d210927Schristos # current directory. Also, the AIX compiler puts '$object:' at the 265597410b8Schristos # start of each line; $object doesn't have directory information. 266597410b8Schristos # Version 6 uses the directory in both cases. 267*9d210927Schristos set_dir_from "$object" 268*9d210927Schristos set_base_from "$object" 269597410b8Schristos if test "$libtool" = yes; then 270597410b8Schristos tmpdepfile1=$dir$base.u 271597410b8Schristos tmpdepfile2=$base.u 272597410b8Schristos tmpdepfile3=$dir.libs/$base.u 273597410b8Schristos "$@" -Wc,-M 274597410b8Schristos else 275597410b8Schristos tmpdepfile1=$dir$base.u 276597410b8Schristos tmpdepfile2=$dir$base.u 277597410b8Schristos tmpdepfile3=$dir$base.u 278597410b8Schristos "$@" -M 279597410b8Schristos fi 280597410b8Schristos stat=$? 281*9d210927Schristos if test $stat -ne 0; then 282597410b8Schristos rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 283597410b8Schristos exit $stat 284597410b8Schristos fi 285597410b8Schristos 286597410b8Schristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 287597410b8Schristos do 288597410b8Schristos test -f "$tmpdepfile" && break 289597410b8Schristos done 290*9d210927Schristos aix_post_process_depfile 291*9d210927Schristos ;; 292*9d210927Schristos 293*9d210927Schristostcc) 294*9d210927Schristos # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 295*9d210927Schristos # FIXME: That version still under development at the moment of writing. 296*9d210927Schristos # Make that this statement remains true also for stable, released 297*9d210927Schristos # versions. 298*9d210927Schristos # It will wrap lines (doesn't matter whether long or short) with a 299*9d210927Schristos # trailing '\', as in: 300*9d210927Schristos # 301*9d210927Schristos # foo.o : \ 302*9d210927Schristos # foo.c \ 303*9d210927Schristos # foo.h \ 304*9d210927Schristos # 305*9d210927Schristos # It will put a trailing '\' even on the last line, and will use leading 306*9d210927Schristos # spaces rather than leading tabs (at least since its commit 0394caf7 307*9d210927Schristos # "Emit spaces for -MD"). 308*9d210927Schristos "$@" -MD -MF "$tmpdepfile" 309*9d210927Schristos stat=$? 310*9d210927Schristos if test $stat -ne 0; then 311*9d210927Schristos rm -f "$tmpdepfile" 312*9d210927Schristos exit $stat 313597410b8Schristos fi 314*9d210927Schristos rm -f "$depfile" 315*9d210927Schristos # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 316*9d210927Schristos # We have to change lines of the first kind to '$object: \'. 317*9d210927Schristos sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 318*9d210927Schristos # And for each line of the second kind, we have to emit a 'dep.h:' 319*9d210927Schristos # dummy dependency, to avoid the deleted-header problem. 320*9d210927Schristos sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 321597410b8Schristos rm -f "$tmpdepfile" 322597410b8Schristos ;; 323597410b8Schristos 324*9d210927Schristos## The order of this option in the case statement is important, since the 325*9d210927Schristos## shell code in configure will try each of these formats in the order 326*9d210927Schristos## listed in this file. A plain '-MD' option would be understood by many 327*9d210927Schristos## compilers, so we must ensure this comes after the gcc and icc options. 328*9d210927Schristospgcc) 329*9d210927Schristos # Portland's C compiler understands '-MD'. 330*9d210927Schristos # Will always output deps to 'file.d' where file is the root name of the 331*9d210927Schristos # source file under compilation, even if file resides in a subdirectory. 332*9d210927Schristos # The object file name does not affect the name of the '.d' file. 333*9d210927Schristos # pgcc 10.2 will output 334597410b8Schristos # foo.o: sub/foo.c sub/foo.h 335*9d210927Schristos # and will wrap long lines using '\' : 336597410b8Schristos # foo.o: sub/foo.c ... \ 337597410b8Schristos # sub/foo.h ... \ 338597410b8Schristos # ... 339*9d210927Schristos set_dir_from "$object" 340*9d210927Schristos # Use the source, not the object, to determine the base name, since 341*9d210927Schristos # that's sadly what pgcc will do too. 342*9d210927Schristos set_base_from "$source" 343*9d210927Schristos tmpdepfile=$base.d 344597410b8Schristos 345*9d210927Schristos # For projects that build the same source file twice into different object 346*9d210927Schristos # files, the pgcc approach of using the *source* file root name can cause 347*9d210927Schristos # problems in parallel builds. Use a locking strategy to avoid stomping on 348*9d210927Schristos # the same $tmpdepfile. 349*9d210927Schristos lockdir=$base.d-lock 350*9d210927Schristos trap " 351*9d210927Schristos echo '$0: caught signal, cleaning up...' >&2 352*9d210927Schristos rmdir '$lockdir' 353*9d210927Schristos exit 1 354*9d210927Schristos " 1 2 13 15 355*9d210927Schristos numtries=100 356*9d210927Schristos i=$numtries 357*9d210927Schristos while test $i -gt 0; do 358*9d210927Schristos # mkdir is a portable test-and-set. 359*9d210927Schristos if mkdir "$lockdir" 2>/dev/null; then 360*9d210927Schristos # This process acquired the lock. 361*9d210927Schristos "$@" -MD 362597410b8Schristos stat=$? 363*9d210927Schristos # Release the lock. 364*9d210927Schristos rmdir "$lockdir" 365*9d210927Schristos break 366597410b8Schristos else 367*9d210927Schristos # If the lock is being held by a different process, wait 368*9d210927Schristos # until the winning process is done or we timeout. 369*9d210927Schristos while test -d "$lockdir" && test $i -gt 0; do 370*9d210927Schristos sleep 1 371*9d210927Schristos i=`expr $i - 1` 372*9d210927Schristos done 373*9d210927Schristos fi 374*9d210927Schristos i=`expr $i - 1` 375*9d210927Schristos done 376*9d210927Schristos trap - 1 2 13 15 377*9d210927Schristos if test $i -le 0; then 378*9d210927Schristos echo "$0: failed to acquire lock after $numtries attempts" >&2 379*9d210927Schristos echo "$0: check lockdir '$lockdir'" >&2 380*9d210927Schristos exit 1 381*9d210927Schristos fi 382*9d210927Schristos 383*9d210927Schristos if test $stat -ne 0; then 384597410b8Schristos rm -f "$tmpdepfile" 385597410b8Schristos exit $stat 386597410b8Schristos fi 387597410b8Schristos rm -f "$depfile" 388597410b8Schristos # Each line is of the form `foo.o: dependent.h', 389597410b8Schristos # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 390597410b8Schristos # Do two passes, one to just change these to 391597410b8Schristos # `$object: dependent.h' and one to simply `dependent.h:'. 392597410b8Schristos sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 393597410b8Schristos # Some versions of the HPUX 10.20 sed can't process this invocation 394597410b8Schristos # correctly. Breaking it into two sed invocations is a workaround. 395*9d210927Schristos sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 396*9d210927Schristos | sed -e 's/$/ :/' >> "$depfile" 397597410b8Schristos rm -f "$tmpdepfile" 398597410b8Schristos ;; 399597410b8Schristos 400597410b8Schristoshp2) 401597410b8Schristos # The "hp" stanza above does not work with aCC (C++) and HP's ia64 402597410b8Schristos # compilers, which have integrated preprocessors. The correct option 403597410b8Schristos # to use with these is +Maked; it writes dependencies to a file named 404597410b8Schristos # 'foo.d', which lands next to the object file, wherever that 405597410b8Schristos # happens to be. 406597410b8Schristos # Much of this is similar to the tru64 case; see comments there. 407*9d210927Schristos set_dir_from "$object" 408*9d210927Schristos set_base_from "$object" 409597410b8Schristos if test "$libtool" = yes; then 410597410b8Schristos tmpdepfile1=$dir$base.d 411597410b8Schristos tmpdepfile2=$dir.libs/$base.d 412597410b8Schristos "$@" -Wc,+Maked 413597410b8Schristos else 414597410b8Schristos tmpdepfile1=$dir$base.d 415597410b8Schristos tmpdepfile2=$dir$base.d 416597410b8Schristos "$@" +Maked 417597410b8Schristos fi 418597410b8Schristos stat=$? 419*9d210927Schristos if test $stat -ne 0; then 420597410b8Schristos rm -f "$tmpdepfile1" "$tmpdepfile2" 421597410b8Schristos exit $stat 422597410b8Schristos fi 423597410b8Schristos 424597410b8Schristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 425597410b8Schristos do 426597410b8Schristos test -f "$tmpdepfile" && break 427597410b8Schristos done 428597410b8Schristos if test -f "$tmpdepfile"; then 429*9d210927Schristos sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 430*9d210927Schristos # Add 'dependent.h:' lines. 431597410b8Schristos sed -ne '2,${ 432597410b8Schristos s/^ *// 433597410b8Schristos s/ \\*$// 434597410b8Schristos s/$/:/ 435597410b8Schristos p 436597410b8Schristos }' "$tmpdepfile" >> "$depfile" 437597410b8Schristos else 438*9d210927Schristos make_dummy_depfile 439597410b8Schristos fi 440597410b8Schristos rm -f "$tmpdepfile" "$tmpdepfile2" 441597410b8Schristos ;; 442597410b8Schristos 443597410b8Schristostru64) 444597410b8Schristos # The Tru64 compiler uses -MD to generate dependencies as a side 445*9d210927Schristos # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 446597410b8Schristos # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 447*9d210927Schristos # dependencies in 'foo.d' instead, so we check for that too. 448597410b8Schristos # Subdirectories are respected. 449*9d210927Schristos set_dir_from "$object" 450*9d210927Schristos set_base_from "$object" 451597410b8Schristos 452597410b8Schristos if test "$libtool" = yes; then 453*9d210927Schristos # Libtool generates 2 separate objects for the 2 libraries. These 454*9d210927Schristos # two compilations output dependencies in $dir.libs/$base.o.d and 455597410b8Schristos # in $dir$base.o.d. We have to check for both files, because 456597410b8Schristos # one of the two compilations can be disabled. We should prefer 457597410b8Schristos # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 458597410b8Schristos # automatically cleaned when .libs/ is deleted, while ignoring 459597410b8Schristos # the former would cause a distcleancheck panic. 460*9d210927Schristos tmpdepfile1=$dir$base.o.d # libtool 1.5 461*9d210927Schristos tmpdepfile2=$dir.libs/$base.o.d # Likewise. 462*9d210927Schristos tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 463597410b8Schristos "$@" -Wc,-MD 464597410b8Schristos else 465*9d210927Schristos tmpdepfile1=$dir$base.d 466597410b8Schristos tmpdepfile2=$dir$base.d 467597410b8Schristos tmpdepfile3=$dir$base.d 468597410b8Schristos "$@" -MD 469597410b8Schristos fi 470597410b8Schristos 471597410b8Schristos stat=$? 472*9d210927Schristos if test $stat -ne 0; then 473*9d210927Schristos rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 474597410b8Schristos exit $stat 475597410b8Schristos fi 476597410b8Schristos 477*9d210927Schristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 478597410b8Schristos do 479597410b8Schristos test -f "$tmpdepfile" && break 480597410b8Schristos done 481*9d210927Schristos # Same post-processing that is required for AIX mode. 482*9d210927Schristos aix_post_process_depfile 483*9d210927Schristos ;; 484*9d210927Schristos 485*9d210927Schristosmsvc7) 486*9d210927Schristos if test "$libtool" = yes; then 487*9d210927Schristos showIncludes=-Wc,-showIncludes 488597410b8Schristos else 489*9d210927Schristos showIncludes=-showIncludes 490597410b8Schristos fi 491*9d210927Schristos "$@" $showIncludes > "$tmpdepfile" 492*9d210927Schristos stat=$? 493*9d210927Schristos grep -v '^Note: including file: ' "$tmpdepfile" 494*9d210927Schristos if test $stat -ne 0; then 495597410b8Schristos rm -f "$tmpdepfile" 496*9d210927Schristos exit $stat 497*9d210927Schristos fi 498*9d210927Schristos rm -f "$depfile" 499*9d210927Schristos echo "$object : \\" > "$depfile" 500*9d210927Schristos # The first sed program below extracts the file names and escapes 501*9d210927Schristos # backslashes for cygpath. The second sed program outputs the file 502*9d210927Schristos # name when reading, but also accumulates all include files in the 503*9d210927Schristos # hold buffer in order to output them again at the end. This only 504*9d210927Schristos # works with sed implementations that can handle large buffers. 505*9d210927Schristos sed < "$tmpdepfile" -n ' 506*9d210927Schristos/^Note: including file: *\(.*\)/ { 507*9d210927Schristos s//\1/ 508*9d210927Schristos s/\\/\\\\/g 509*9d210927Schristos p 510*9d210927Schristos}' | $cygpath_u | sort -u | sed -n ' 511*9d210927Schristoss/ /\\ /g 512*9d210927Schristoss/\(.*\)/'"$tab"'\1 \\/p 513*9d210927Schristoss/.\(.*\) \\/\1:/ 514*9d210927SchristosH 515*9d210927Schristos$ { 516*9d210927Schristos s/.*/'"$tab"'/ 517*9d210927Schristos G 518*9d210927Schristos p 519*9d210927Schristos}' >> "$depfile" 520*9d210927Schristos echo >> "$depfile" # make sure the fragment doesn't end with a backslash 521*9d210927Schristos rm -f "$tmpdepfile" 522*9d210927Schristos ;; 523*9d210927Schristos 524*9d210927Schristosmsvc7msys) 525*9d210927Schristos # This case exists only to let depend.m4 do its work. It works by 526*9d210927Schristos # looking at the text of this script. This case will never be run, 527*9d210927Schristos # since it is checked for above. 528*9d210927Schristos exit 1 529597410b8Schristos ;; 530597410b8Schristos 531597410b8Schristos#nosideeffect) 532597410b8Schristos # This comment above is used by automake to tell side-effect 533597410b8Schristos # dependency tracking mechanisms from slower ones. 534597410b8Schristos 535597410b8Schristosdashmstdout) 536597410b8Schristos # Important note: in order to support this mode, a compiler *must* 537597410b8Schristos # always write the preprocessed file to stdout, regardless of -o. 538597410b8Schristos "$@" || exit $? 539597410b8Schristos 540597410b8Schristos # Remove the call to Libtool. 541597410b8Schristos if test "$libtool" = yes; then 542597410b8Schristos while test "X$1" != 'X--mode=compile'; do 543597410b8Schristos shift 544597410b8Schristos done 545597410b8Schristos shift 546597410b8Schristos fi 547597410b8Schristos 548*9d210927Schristos # Remove '-o $object'. 549597410b8Schristos IFS=" " 550597410b8Schristos for arg 551597410b8Schristos do 552597410b8Schristos case $arg in 553597410b8Schristos -o) 554597410b8Schristos shift 555597410b8Schristos ;; 556597410b8Schristos $object) 557597410b8Schristos shift 558597410b8Schristos ;; 559597410b8Schristos *) 560597410b8Schristos set fnord "$@" "$arg" 561597410b8Schristos shift # fnord 562597410b8Schristos shift # $arg 563597410b8Schristos ;; 564597410b8Schristos esac 565597410b8Schristos done 566597410b8Schristos 567597410b8Schristos test -z "$dashmflag" && dashmflag=-M 568*9d210927Schristos # Require at least two characters before searching for ':' 569597410b8Schristos # in the target name. This is to cope with DOS-style filenames: 570*9d210927Schristos # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 571597410b8Schristos "$@" $dashmflag | 572*9d210927Schristos sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 573597410b8Schristos rm -f "$depfile" 574597410b8Schristos cat < "$tmpdepfile" > "$depfile" 575*9d210927Schristos # Some versions of the HPUX 10.20 sed can't process this sed invocation 576*9d210927Schristos # correctly. Breaking it into two sed invocations is a workaround. 577*9d210927Schristos tr ' ' "$nl" < "$tmpdepfile" \ 578*9d210927Schristos | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 579*9d210927Schristos | sed -e 's/$/ :/' >> "$depfile" 580597410b8Schristos rm -f "$tmpdepfile" 581597410b8Schristos ;; 582597410b8Schristos 583597410b8SchristosdashXmstdout) 584597410b8Schristos # This case only exists to satisfy depend.m4. It is never actually 585597410b8Schristos # run, as this mode is specially recognized in the preamble. 586597410b8Schristos exit 1 587597410b8Schristos ;; 588597410b8Schristos 589597410b8Schristosmakedepend) 590597410b8Schristos "$@" || exit $? 591597410b8Schristos # Remove any Libtool call 592597410b8Schristos if test "$libtool" = yes; then 593597410b8Schristos while test "X$1" != 'X--mode=compile'; do 594597410b8Schristos shift 595597410b8Schristos done 596597410b8Schristos shift 597597410b8Schristos fi 598597410b8Schristos # X makedepend 599597410b8Schristos shift 600597410b8Schristos cleared=no eat=no 601597410b8Schristos for arg 602597410b8Schristos do 603597410b8Schristos case $cleared in 604597410b8Schristos no) 605597410b8Schristos set ""; shift 606597410b8Schristos cleared=yes ;; 607597410b8Schristos esac 608597410b8Schristos if test $eat = yes; then 609597410b8Schristos eat=no 610597410b8Schristos continue 611597410b8Schristos fi 612597410b8Schristos case "$arg" in 613597410b8Schristos -D*|-I*) 614597410b8Schristos set fnord "$@" "$arg"; shift ;; 615597410b8Schristos # Strip any option that makedepend may not understand. Remove 616597410b8Schristos # the object too, otherwise makedepend will parse it as a source file. 617597410b8Schristos -arch) 618597410b8Schristos eat=yes ;; 619597410b8Schristos -*|$object) 620597410b8Schristos ;; 621597410b8Schristos *) 622597410b8Schristos set fnord "$@" "$arg"; shift ;; 623597410b8Schristos esac 624597410b8Schristos done 625597410b8Schristos obj_suffix=`echo "$object" | sed 's/^.*\././'` 626597410b8Schristos touch "$tmpdepfile" 627597410b8Schristos ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 628597410b8Schristos rm -f "$depfile" 629*9d210927Schristos # makedepend may prepend the VPATH from the source file name to the object. 630*9d210927Schristos # No need to regex-escape $object, excess matching of '.' is harmless. 631*9d210927Schristos sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 632*9d210927Schristos # Some versions of the HPUX 10.20 sed can't process the last invocation 633*9d210927Schristos # correctly. Breaking it into two sed invocations is a workaround. 634*9d210927Schristos sed '1,2d' "$tmpdepfile" \ 635*9d210927Schristos | tr ' ' "$nl" \ 636*9d210927Schristos | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 637*9d210927Schristos | sed -e 's/$/ :/' >> "$depfile" 638597410b8Schristos rm -f "$tmpdepfile" "$tmpdepfile".bak 639597410b8Schristos ;; 640597410b8Schristos 641597410b8Schristoscpp) 642597410b8Schristos # Important note: in order to support this mode, a compiler *must* 643597410b8Schristos # always write the preprocessed file to stdout. 644597410b8Schristos "$@" || exit $? 645597410b8Schristos 646597410b8Schristos # Remove the call to Libtool. 647597410b8Schristos if test "$libtool" = yes; then 648597410b8Schristos while test "X$1" != 'X--mode=compile'; do 649597410b8Schristos shift 650597410b8Schristos done 651597410b8Schristos shift 652597410b8Schristos fi 653597410b8Schristos 654*9d210927Schristos # Remove '-o $object'. 655597410b8Schristos IFS=" " 656597410b8Schristos for arg 657597410b8Schristos do 658597410b8Schristos case $arg in 659597410b8Schristos -o) 660597410b8Schristos shift 661597410b8Schristos ;; 662597410b8Schristos $object) 663597410b8Schristos shift 664597410b8Schristos ;; 665597410b8Schristos *) 666597410b8Schristos set fnord "$@" "$arg" 667597410b8Schristos shift # fnord 668597410b8Schristos shift # $arg 669597410b8Schristos ;; 670597410b8Schristos esac 671597410b8Schristos done 672597410b8Schristos 673*9d210927Schristos "$@" -E \ 674*9d210927Schristos | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 675*9d210927Schristos -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 676*9d210927Schristos | sed '$ s: \\$::' > "$tmpdepfile" 677597410b8Schristos rm -f "$depfile" 678597410b8Schristos echo "$object : \\" > "$depfile" 679597410b8Schristos cat < "$tmpdepfile" >> "$depfile" 680597410b8Schristos sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 681597410b8Schristos rm -f "$tmpdepfile" 682597410b8Schristos ;; 683597410b8Schristos 684597410b8Schristosmsvisualcpp) 685597410b8Schristos # Important note: in order to support this mode, a compiler *must* 686597410b8Schristos # always write the preprocessed file to stdout. 687597410b8Schristos "$@" || exit $? 688597410b8Schristos 689597410b8Schristos # Remove the call to Libtool. 690597410b8Schristos if test "$libtool" = yes; then 691597410b8Schristos while test "X$1" != 'X--mode=compile'; do 692597410b8Schristos shift 693597410b8Schristos done 694597410b8Schristos shift 695597410b8Schristos fi 696597410b8Schristos 697597410b8Schristos IFS=" " 698597410b8Schristos for arg 699597410b8Schristos do 700597410b8Schristos case "$arg" in 701597410b8Schristos -o) 702597410b8Schristos shift 703597410b8Schristos ;; 704597410b8Schristos $object) 705597410b8Schristos shift 706597410b8Schristos ;; 707597410b8Schristos "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 708597410b8Schristos set fnord "$@" 709597410b8Schristos shift 710597410b8Schristos shift 711597410b8Schristos ;; 712597410b8Schristos *) 713597410b8Schristos set fnord "$@" "$arg" 714597410b8Schristos shift 715597410b8Schristos shift 716597410b8Schristos ;; 717597410b8Schristos esac 718597410b8Schristos done 719597410b8Schristos "$@" -E 2>/dev/null | 720597410b8Schristos sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 721597410b8Schristos rm -f "$depfile" 722597410b8Schristos echo "$object : \\" > "$depfile" 723*9d210927Schristos sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 724*9d210927Schristos echo "$tab" >> "$depfile" 725597410b8Schristos sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 726597410b8Schristos rm -f "$tmpdepfile" 727597410b8Schristos ;; 728597410b8Schristos 729597410b8Schristosmsvcmsys) 730597410b8Schristos # This case exists only to let depend.m4 do its work. It works by 731597410b8Schristos # looking at the text of this script. This case will never be run, 732597410b8Schristos # since it is checked for above. 733597410b8Schristos exit 1 734597410b8Schristos ;; 735597410b8Schristos 736597410b8Schristosnone) 737597410b8Schristos exec "$@" 738597410b8Schristos ;; 739597410b8Schristos 740597410b8Schristos*) 741597410b8Schristos echo "Unknown depmode $depmode" 1>&2 742597410b8Schristos exit 1 743597410b8Schristos ;; 744597410b8Schristosesac 745597410b8Schristos 746597410b8Schristosexit 0 747597410b8Schristos 748597410b8Schristos# Local Variables: 749597410b8Schristos# mode: shell-script 750597410b8Schristos# sh-indentation: 2 751597410b8Schristos# eval: (add-hook 'write-file-hooks 'time-stamp) 752597410b8Schristos# time-stamp-start: "scriptversion=" 753597410b8Schristos# time-stamp-format: "%:y-%02m-%02d.%02H" 754597410b8Schristos# time-stamp-time-zone: "UTC" 755597410b8Schristos# time-stamp-end: "; # UTC" 756597410b8Schristos# End: 757