1117610Sdes#! /bin/sh 2117610Sdes# depcomp - compile a program generating dependencies as side-effects 3117610Sdes 4348980Sdesscriptversion=2018-03-07.03; # UTC 5141098Sdes 6348980Sdes# Copyright (C) 1999-2018 Free Software Foundation, Inc. 7141098Sdes 8117610Sdes# This program is free software; you can redistribute it and/or modify 9117610Sdes# it under the terms of the GNU General Public License as published by 10117610Sdes# the Free Software Foundation; either version 2, or (at your option) 11117610Sdes# any later version. 12117610Sdes 13117610Sdes# This program is distributed in the hope that it will be useful, 14117610Sdes# but WITHOUT ANY WARRANTY; without even the implied warranty of 15117610Sdes# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16117610Sdes# GNU General Public License for more details. 17117610Sdes 18117610Sdes# You should have received a copy of the GNU General Public License 19348980Sdes# along with this program. If not, see <https://www.gnu.org/licenses/>. 20117610Sdes 21117610Sdes# As a special exception to the GNU General Public License, if you 22117610Sdes# distribute this file as part of a program that contains a 23117610Sdes# configuration script generated by Autoconf, you may include it under 24117610Sdes# the same distribution terms that you use for the rest of that program. 25117610Sdes 26117610Sdes# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27117610Sdes 28141098Sdescase $1 in 29141098Sdes '') 30255376Sdes echo "$0: No command. Try '$0 --help' for more information." 1>&2 31255376Sdes exit 1; 32255376Sdes ;; 33141098Sdes -h | --h*) 34141098Sdes cat <<\EOF 35141098SdesUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36141098Sdes 37141098SdesRun PROGRAMS ARGS to compile a file, generating dependencies 38141098Sdesas side-effects. 39141098Sdes 40141098SdesEnvironment variables: 41141098Sdes depmode Dependency tracking mode. 42255376Sdes source Source file read by 'PROGRAMS ARGS'. 43255376Sdes object Object file output by 'PROGRAMS ARGS'. 44174832Sdes DEPDIR directory where to store dependencies. 45141098Sdes depfile Dependency file to output. 46255376Sdes tmpdepfile Temporary file to use when outputting dependencies. 47141098Sdes libtool Whether libtool is used (yes/no). 48141098Sdes 49141098SdesReport bugs to <bug-automake@gnu.org>. 50141098SdesEOF 51174832Sdes exit $? 52141098Sdes ;; 53141098Sdes -v | --v*) 54141098Sdes echo "depcomp $scriptversion" 55174832Sdes exit $? 56141098Sdes ;; 57141098Sdesesac 58141098Sdes 59255376Sdes# Get the directory component of the given path, and save it in the 60255376Sdes# global variables '$dir'. Note that this directory component will 61255376Sdes# be either empty or ending with a '/' character. This is deliberate. 62255376Sdesset_dir_from () 63255376Sdes{ 64255376Sdes case $1 in 65255376Sdes */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66255376Sdes *) dir=;; 67255376Sdes esac 68255376Sdes} 69255376Sdes 70255376Sdes# Get the suffix-stripped basename of the given path, and save it the 71255376Sdes# global variable '$base'. 72255376Sdesset_base_from () 73255376Sdes{ 74255376Sdes base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75255376Sdes} 76255376Sdes 77255376Sdes# If no dependency file was actually created by the compiler invocation, 78255376Sdes# we still have to create a dummy depfile, to avoid errors with the 79255376Sdes# Makefile "include basename.Plo" scheme. 80255376Sdesmake_dummy_depfile () 81255376Sdes{ 82255376Sdes echo "#dummy" > "$depfile" 83255376Sdes} 84255376Sdes 85255376Sdes# Factor out some common post-processing of the generated depfile. 86255376Sdes# Requires the auxiliary global variable '$tmpdepfile' to be set. 87255376Sdesaix_post_process_depfile () 88255376Sdes{ 89255376Sdes # If the compiler actually managed to produce a dependency file, 90255376Sdes # post-process it. 91255376Sdes if test -f "$tmpdepfile"; then 92255376Sdes # Each line is of the form 'foo.o: dependency.h'. 93255376Sdes # Do two passes, one to just change these to 94255376Sdes # $object: dependency.h 95255376Sdes # and one to simply output 96255376Sdes # dependency.h: 97255376Sdes # which is needed to avoid the deleted-header problem. 98255376Sdes { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99255376Sdes sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100255376Sdes } > "$depfile" 101255376Sdes rm -f "$tmpdepfile" 102255376Sdes else 103255376Sdes make_dummy_depfile 104255376Sdes fi 105255376Sdes} 106255376Sdes 107255376Sdes# A tabulation character. 108255376Sdestab=' ' 109255376Sdes# A newline character. 110255376Sdesnl=' 111255376Sdes' 112255376Sdes# Character ranges might be problematic outside the C locale. 113255376Sdes# These definitions help. 114255376Sdesupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115255376Sdeslower=abcdefghijklmnopqrstuvwxyz 116255376Sdesdigits=0123456789 117255376Sdesalpha=${upper}${lower} 118255376Sdes 119117610Sdesif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120117610Sdes echo "depcomp: Variables source, object and depmode must be set" 1>&2 121117610Sdes exit 1 122117610Sdesfi 123117610Sdes 124174832Sdes# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125174832Sdesdepfile=${depfile-`echo "$object" | 126174832Sdes sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127117610Sdestmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128117610Sdes 129117610Sdesrm -f "$tmpdepfile" 130117610Sdes 131255376Sdes# Avoid interferences from the environment. 132255376Sdesgccflag= dashmflag= 133255376Sdes 134117610Sdes# Some modes work just like other modes, but use different flags. We 135117610Sdes# parameterize here, but still list the modes in the big case below, 136117610Sdes# to make depend.m4 easier to write. Note that we *cannot* use a case 137117610Sdes# here, because this file can only contain one case statement. 138117610Sdesif test "$depmode" = hp; then 139117610Sdes # HP compiler uses -M and no extra arg. 140117610Sdes gccflag=-M 141117610Sdes depmode=gcc 142117610Sdesfi 143117610Sdes 144117610Sdesif test "$depmode" = dashXmstdout; then 145255376Sdes # This is just like dashmstdout with a different argument. 146255376Sdes dashmflag=-xM 147255376Sdes depmode=dashmstdout 148117610Sdesfi 149117610Sdes 150228692Sdescygpath_u="cygpath -u -f -" 151228692Sdesif test "$depmode" = msvcmsys; then 152255376Sdes # This is just like msvisualcpp but w/o cygpath translation. 153255376Sdes # Just convert the backslash-escaped backslashes to single forward 154255376Sdes # slashes to satisfy depend.m4 155255376Sdes cygpath_u='sed s,\\\\,/,g' 156255376Sdes depmode=msvisualcpp 157228692Sdesfi 158228692Sdes 159255376Sdesif test "$depmode" = msvc7msys; then 160255376Sdes # This is just like msvc7 but w/o cygpath translation. 161255376Sdes # Just convert the backslash-escaped backslashes to single forward 162255376Sdes # slashes to satisfy depend.m4 163255376Sdes cygpath_u='sed s,\\\\,/,g' 164255376Sdes depmode=msvc7 165255376Sdesfi 166255376Sdes 167255376Sdesif test "$depmode" = xlc; then 168255376Sdes # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169255376Sdes gccflag=-qmakedep=gcc,-MF 170255376Sdes depmode=gcc 171255376Sdesfi 172255376Sdes 173117610Sdescase "$depmode" in 174117610Sdesgcc3) 175117610Sdes## gcc 3 implements dependency tracking that does exactly what 176117610Sdes## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177117610Sdes## it if -MD -MP comes after the -MF stuff. Hmm. 178228692Sdes## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179228692Sdes## the command line argument order; so add the flags where they 180228692Sdes## appear in depend2.am. Note that the slowdown incurred here 181228692Sdes## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182228692Sdes for arg 183228692Sdes do 184228692Sdes case $arg in 185228692Sdes -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186228692Sdes *) set fnord "$@" "$arg" ;; 187228692Sdes esac 188228692Sdes shift # fnord 189228692Sdes shift # $arg 190228692Sdes done 191228692Sdes "$@" 192117610Sdes stat=$? 193255376Sdes if test $stat -ne 0; then 194117610Sdes rm -f "$tmpdepfile" 195117610Sdes exit $stat 196117610Sdes fi 197117610Sdes mv "$tmpdepfile" "$depfile" 198117610Sdes ;; 199117610Sdes 200117610Sdesgcc) 201255376Sdes## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202255376Sdes## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203255376Sdes## (see the conditional assignment to $gccflag above). 204117610Sdes## There are various ways to get dependency output from gcc. Here's 205117610Sdes## why we pick this rather obscure method: 206117610Sdes## - Don't want to use -MD because we'd like the dependencies to end 207117610Sdes## up in a subdir. Having to rename by hand is ugly. 208117610Sdes## (We might end up doing this anyway to support other compilers.) 209117610Sdes## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210255376Sdes## -MM, not -M (despite what the docs say). Also, it might not be 211255376Sdes## supported by the other compilers which use the 'gcc' depmode. 212117610Sdes## - Using -M directly means running the compiler twice (even worse 213117610Sdes## than renaming). 214117610Sdes if test -z "$gccflag"; then 215117610Sdes gccflag=-MD, 216117610Sdes fi 217117610Sdes "$@" -Wp,"$gccflag$tmpdepfile" 218117610Sdes stat=$? 219255376Sdes if test $stat -ne 0; then 220117610Sdes rm -f "$tmpdepfile" 221117610Sdes exit $stat 222117610Sdes fi 223117610Sdes rm -f "$depfile" 224117610Sdes echo "$object : \\" > "$depfile" 225255376Sdes # The second -e expression handles DOS-style file names with drive 226255376Sdes # letters. 227117610Sdes sed -e 's/^[^:]*: / /' \ 228117610Sdes -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229255376Sdes## This next piece of magic avoids the "deleted header file" problem. 230117610Sdes## The problem is that when a header file which appears in a .P file 231117610Sdes## is deleted, the dependency causes make to die (because there is 232117610Sdes## typically no way to rebuild the header). We avoid this by adding 233117610Sdes## dummy dependencies for each header file. Too bad gcc doesn't do 234117610Sdes## this for us directly. 235255376Sdes## Some versions of gcc put a space before the ':'. On the theory 236117610Sdes## that the space means something, we add a space to the output as 237255376Sdes## well. hp depmode also adds that space, but also prefixes the VPATH 238255376Sdes## to the object. Take care to not repeat it in the output. 239117610Sdes## Some versions of the HPUX 10.20 sed can't process this invocation 240117610Sdes## correctly. Breaking it into two sed invocations is a workaround. 241255376Sdes tr ' ' "$nl" < "$tmpdepfile" \ 242255376Sdes | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243255376Sdes | sed -e 's/$/ :/' >> "$depfile" 244117610Sdes rm -f "$tmpdepfile" 245117610Sdes ;; 246117610Sdes 247117610Sdeshp) 248117610Sdes # This case exists only to let depend.m4 do its work. It works by 249117610Sdes # looking at the text of this script. This case will never be run, 250117610Sdes # since it is checked for above. 251117610Sdes exit 1 252117610Sdes ;; 253117610Sdes 254117610Sdessgi) 255117610Sdes if test "$libtool" = yes; then 256117610Sdes "$@" "-Wp,-MDupdate,$tmpdepfile" 257117610Sdes else 258117610Sdes "$@" -MDupdate "$tmpdepfile" 259117610Sdes fi 260117610Sdes stat=$? 261255376Sdes if test $stat -ne 0; then 262117610Sdes rm -f "$tmpdepfile" 263117610Sdes exit $stat 264117610Sdes fi 265117610Sdes rm -f "$depfile" 266117610Sdes 267117610Sdes if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268117610Sdes echo "$object : \\" > "$depfile" 269117610Sdes # Clip off the initial element (the dependent). Don't try to be 270117610Sdes # clever and replace this with sed code, as IRIX sed won't handle 271117610Sdes # lines with more than a fixed number of characters (4096 in 272117610Sdes # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273255376Sdes # the IRIX cc adds comments like '#:fec' to the end of the 274117610Sdes # dependency line. 275255376Sdes tr ' ' "$nl" < "$tmpdepfile" \ 276255376Sdes | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277255376Sdes | tr "$nl" ' ' >> "$depfile" 278228692Sdes echo >> "$depfile" 279117610Sdes # The second pass generates a dummy entry for each header file. 280255376Sdes tr ' ' "$nl" < "$tmpdepfile" \ 281255376Sdes | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282255376Sdes >> "$depfile" 283117610Sdes else 284255376Sdes make_dummy_depfile 285117610Sdes fi 286117610Sdes rm -f "$tmpdepfile" 287117610Sdes ;; 288117610Sdes 289255376Sdesxlc) 290255376Sdes # This case exists only to let depend.m4 do its work. It works by 291255376Sdes # looking at the text of this script. This case will never be run, 292255376Sdes # since it is checked for above. 293255376Sdes exit 1 294255376Sdes ;; 295255376Sdes 296117610Sdesaix) 297117610Sdes # The C for AIX Compiler uses -M and outputs the dependencies 298141098Sdes # in a .u file. In older versions, this file always lives in the 299255376Sdes # current directory. Also, the AIX compiler puts '$object:' at the 300141098Sdes # start of each line; $object doesn't have directory information. 301141098Sdes # Version 6 uses the directory in both cases. 302255376Sdes set_dir_from "$object" 303255376Sdes set_base_from "$object" 304117610Sdes if test "$libtool" = yes; then 305228692Sdes tmpdepfile1=$dir$base.u 306228692Sdes tmpdepfile2=$base.u 307228692Sdes tmpdepfile3=$dir.libs/$base.u 308117610Sdes "$@" -Wc,-M 309117610Sdes else 310228692Sdes tmpdepfile1=$dir$base.u 311228692Sdes tmpdepfile2=$dir$base.u 312228692Sdes tmpdepfile3=$dir$base.u 313117610Sdes "$@" -M 314117610Sdes fi 315141098Sdes stat=$? 316255376Sdes if test $stat -ne 0; then 317228692Sdes rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318117610Sdes exit $stat 319117610Sdes fi 320117610Sdes 321228692Sdes for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322228692Sdes do 323228692Sdes test -f "$tmpdepfile" && break 324228692Sdes done 325255376Sdes aix_post_process_depfile 326255376Sdes ;; 327255376Sdes 328255376Sdestcc) 329255376Sdes # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330255376Sdes # FIXME: That version still under development at the moment of writing. 331255376Sdes # Make that this statement remains true also for stable, released 332255376Sdes # versions. 333255376Sdes # It will wrap lines (doesn't matter whether long or short) with a 334255376Sdes # trailing '\', as in: 335255376Sdes # 336255376Sdes # foo.o : \ 337255376Sdes # foo.c \ 338255376Sdes # foo.h \ 339255376Sdes # 340255376Sdes # It will put a trailing '\' even on the last line, and will use leading 341255376Sdes # spaces rather than leading tabs (at least since its commit 0394caf7 342255376Sdes # "Emit spaces for -MD"). 343255376Sdes "$@" -MD -MF "$tmpdepfile" 344255376Sdes stat=$? 345255376Sdes if test $stat -ne 0; then 346255376Sdes rm -f "$tmpdepfile" 347255376Sdes exit $stat 348117610Sdes fi 349255376Sdes rm -f "$depfile" 350255376Sdes # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351255376Sdes # We have to change lines of the first kind to '$object: \'. 352255376Sdes sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353255376Sdes # And for each line of the second kind, we have to emit a 'dep.h:' 354255376Sdes # dummy dependency, to avoid the deleted-header problem. 355255376Sdes sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356117610Sdes rm -f "$tmpdepfile" 357117610Sdes ;; 358117610Sdes 359255376Sdes## The order of this option in the case statement is important, since the 360255376Sdes## shell code in configure will try each of these formats in the order 361255376Sdes## listed in this file. A plain '-MD' option would be understood by many 362255376Sdes## compilers, so we must ensure this comes after the gcc and icc options. 363255376Sdespgcc) 364255376Sdes # Portland's C compiler understands '-MD'. 365255376Sdes # Will always output deps to 'file.d' where file is the root name of the 366255376Sdes # source file under compilation, even if file resides in a subdirectory. 367255376Sdes # The object file name does not affect the name of the '.d' file. 368255376Sdes # pgcc 10.2 will output 369141098Sdes # foo.o: sub/foo.c sub/foo.h 370255376Sdes # and will wrap long lines using '\' : 371141098Sdes # foo.o: sub/foo.c ... \ 372141098Sdes # sub/foo.h ... \ 373141098Sdes # ... 374255376Sdes set_dir_from "$object" 375255376Sdes # Use the source, not the object, to determine the base name, since 376255376Sdes # that's sadly what pgcc will do too. 377255376Sdes set_base_from "$source" 378255376Sdes tmpdepfile=$base.d 379141098Sdes 380255376Sdes # For projects that build the same source file twice into different object 381255376Sdes # files, the pgcc approach of using the *source* file root name can cause 382255376Sdes # problems in parallel builds. Use a locking strategy to avoid stomping on 383255376Sdes # the same $tmpdepfile. 384255376Sdes lockdir=$base.d-lock 385255376Sdes trap " 386255376Sdes echo '$0: caught signal, cleaning up...' >&2 387255376Sdes rmdir '$lockdir' 388255376Sdes exit 1 389255376Sdes " 1 2 13 15 390255376Sdes numtries=100 391255376Sdes i=$numtries 392255376Sdes while test $i -gt 0; do 393255376Sdes # mkdir is a portable test-and-set. 394255376Sdes if mkdir "$lockdir" 2>/dev/null; then 395255376Sdes # This process acquired the lock. 396255376Sdes "$@" -MD 397255376Sdes stat=$? 398255376Sdes # Release the lock. 399255376Sdes rmdir "$lockdir" 400255376Sdes break 401255376Sdes else 402255376Sdes # If the lock is being held by a different process, wait 403255376Sdes # until the winning process is done or we timeout. 404255376Sdes while test -d "$lockdir" && test $i -gt 0; do 405255376Sdes sleep 1 406255376Sdes i=`expr $i - 1` 407255376Sdes done 408255376Sdes fi 409255376Sdes i=`expr $i - 1` 410255376Sdes done 411255376Sdes trap - 1 2 13 15 412255376Sdes if test $i -le 0; then 413255376Sdes echo "$0: failed to acquire lock after $numtries attempts" >&2 414255376Sdes echo "$0: check lockdir '$lockdir'" >&2 415255376Sdes exit 1 416255376Sdes fi 417255376Sdes 418255376Sdes if test $stat -ne 0; then 419141098Sdes rm -f "$tmpdepfile" 420141098Sdes exit $stat 421141098Sdes fi 422141098Sdes rm -f "$depfile" 423141098Sdes # Each line is of the form `foo.o: dependent.h', 424141098Sdes # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425141098Sdes # Do two passes, one to just change these to 426141098Sdes # `$object: dependent.h' and one to simply `dependent.h:'. 427141098Sdes sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428141098Sdes # Some versions of the HPUX 10.20 sed can't process this invocation 429141098Sdes # correctly. Breaking it into two sed invocations is a workaround. 430255376Sdes sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431255376Sdes | sed -e 's/$/ :/' >> "$depfile" 432141098Sdes rm -f "$tmpdepfile" 433141098Sdes ;; 434141098Sdes 435228692Sdeshp2) 436228692Sdes # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437228692Sdes # compilers, which have integrated preprocessors. The correct option 438228692Sdes # to use with these is +Maked; it writes dependencies to a file named 439228692Sdes # 'foo.d', which lands next to the object file, wherever that 440228692Sdes # happens to be. 441228692Sdes # Much of this is similar to the tru64 case; see comments there. 442255376Sdes set_dir_from "$object" 443255376Sdes set_base_from "$object" 444228692Sdes if test "$libtool" = yes; then 445228692Sdes tmpdepfile1=$dir$base.d 446228692Sdes tmpdepfile2=$dir.libs/$base.d 447228692Sdes "$@" -Wc,+Maked 448228692Sdes else 449228692Sdes tmpdepfile1=$dir$base.d 450228692Sdes tmpdepfile2=$dir$base.d 451228692Sdes "$@" +Maked 452228692Sdes fi 453228692Sdes stat=$? 454255376Sdes if test $stat -ne 0; then 455228692Sdes rm -f "$tmpdepfile1" "$tmpdepfile2" 456228692Sdes exit $stat 457228692Sdes fi 458228692Sdes 459228692Sdes for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460228692Sdes do 461228692Sdes test -f "$tmpdepfile" && break 462228692Sdes done 463228692Sdes if test -f "$tmpdepfile"; then 464255376Sdes sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465255376Sdes # Add 'dependent.h:' lines. 466228692Sdes sed -ne '2,${ 467255376Sdes s/^ *// 468255376Sdes s/ \\*$// 469255376Sdes s/$/:/ 470255376Sdes p 471255376Sdes }' "$tmpdepfile" >> "$depfile" 472228692Sdes else 473255376Sdes make_dummy_depfile 474228692Sdes fi 475228692Sdes rm -f "$tmpdepfile" "$tmpdepfile2" 476228692Sdes ;; 477228692Sdes 478117610Sdestru64) 479255376Sdes # The Tru64 compiler uses -MD to generate dependencies as a side 480255376Sdes # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481255376Sdes # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482255376Sdes # dependencies in 'foo.d' instead, so we check for that too. 483255376Sdes # Subdirectories are respected. 484255376Sdes set_dir_from "$object" 485255376Sdes set_base_from "$object" 486117610Sdes 487255376Sdes if test "$libtool" = yes; then 488255376Sdes # Libtool generates 2 separate objects for the 2 libraries. These 489255376Sdes # two compilations output dependencies in $dir.libs/$base.o.d and 490255376Sdes # in $dir$base.o.d. We have to check for both files, because 491255376Sdes # one of the two compilations can be disabled. We should prefer 492255376Sdes # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493255376Sdes # automatically cleaned when .libs/ is deleted, while ignoring 494255376Sdes # the former would cause a distcleancheck panic. 495255376Sdes tmpdepfile1=$dir$base.o.d # libtool 1.5 496255376Sdes tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497255376Sdes tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498255376Sdes "$@" -Wc,-MD 499255376Sdes else 500255376Sdes tmpdepfile1=$dir$base.d 501255376Sdes tmpdepfile2=$dir$base.d 502255376Sdes tmpdepfile3=$dir$base.d 503255376Sdes "$@" -MD 504255376Sdes fi 505117610Sdes 506255376Sdes stat=$? 507255376Sdes if test $stat -ne 0; then 508255376Sdes rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509255376Sdes exit $stat 510255376Sdes fi 511117610Sdes 512255376Sdes for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513255376Sdes do 514255376Sdes test -f "$tmpdepfile" && break 515255376Sdes done 516255376Sdes # Same post-processing that is required for AIX mode. 517255376Sdes aix_post_process_depfile 518255376Sdes ;; 519117610Sdes 520255376Sdesmsvc7) 521255376Sdes if test "$libtool" = yes; then 522255376Sdes showIncludes=-Wc,-showIncludes 523255376Sdes else 524255376Sdes showIncludes=-showIncludes 525255376Sdes fi 526255376Sdes "$@" $showIncludes > "$tmpdepfile" 527255376Sdes stat=$? 528255376Sdes grep -v '^Note: including file: ' "$tmpdepfile" 529255376Sdes if test $stat -ne 0; then 530255376Sdes rm -f "$tmpdepfile" 531255376Sdes exit $stat 532255376Sdes fi 533255376Sdes rm -f "$depfile" 534255376Sdes echo "$object : \\" > "$depfile" 535255376Sdes # The first sed program below extracts the file names and escapes 536255376Sdes # backslashes for cygpath. The second sed program outputs the file 537255376Sdes # name when reading, but also accumulates all include files in the 538255376Sdes # hold buffer in order to output them again at the end. This only 539255376Sdes # works with sed implementations that can handle large buffers. 540255376Sdes sed < "$tmpdepfile" -n ' 541255376Sdes/^Note: including file: *\(.*\)/ { 542255376Sdes s//\1/ 543255376Sdes s/\\/\\\\/g 544255376Sdes p 545255376Sdes}' | $cygpath_u | sort -u | sed -n ' 546255376Sdess/ /\\ /g 547255376Sdess/\(.*\)/'"$tab"'\1 \\/p 548255376Sdess/.\(.*\) \\/\1:/ 549255376SdesH 550255376Sdes$ { 551255376Sdes s/.*/'"$tab"'/ 552255376Sdes G 553255376Sdes p 554255376Sdes}' >> "$depfile" 555255376Sdes echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556255376Sdes rm -f "$tmpdepfile" 557255376Sdes ;; 558255376Sdes 559255376Sdesmsvc7msys) 560255376Sdes # This case exists only to let depend.m4 do its work. It works by 561255376Sdes # looking at the text of this script. This case will never be run, 562255376Sdes # since it is checked for above. 563255376Sdes exit 1 564255376Sdes ;; 565255376Sdes 566117610Sdes#nosideeffect) 567117610Sdes # This comment above is used by automake to tell side-effect 568117610Sdes # dependency tracking mechanisms from slower ones. 569117610Sdes 570117610Sdesdashmstdout) 571117610Sdes # Important note: in order to support this mode, a compiler *must* 572141098Sdes # always write the preprocessed file to stdout, regardless of -o. 573141098Sdes "$@" || exit $? 574141098Sdes 575141098Sdes # Remove the call to Libtool. 576141098Sdes if test "$libtool" = yes; then 577228692Sdes while test "X$1" != 'X--mode=compile'; do 578141098Sdes shift 579141098Sdes done 580141098Sdes shift 581141098Sdes fi 582141098Sdes 583255376Sdes # Remove '-o $object'. 584141098Sdes IFS=" " 585141098Sdes for arg 586141098Sdes do 587141098Sdes case $arg in 588141098Sdes -o) 589141098Sdes shift 590117610Sdes ;; 591141098Sdes $object) 592141098Sdes shift 593141098Sdes ;; 594141098Sdes *) 595141098Sdes set fnord "$@" "$arg" 596141098Sdes shift # fnord 597141098Sdes shift # $arg 598141098Sdes ;; 599117610Sdes esac 600141098Sdes done 601141098Sdes 602141098Sdes test -z "$dashmflag" && dashmflag=-M 603255376Sdes # Require at least two characters before searching for ':' 604141098Sdes # in the target name. This is to cope with DOS-style filenames: 605255376Sdes # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606141098Sdes "$@" $dashmflag | 607255376Sdes sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608117610Sdes rm -f "$depfile" 609117610Sdes cat < "$tmpdepfile" > "$depfile" 610255376Sdes # Some versions of the HPUX 10.20 sed can't process this sed invocation 611255376Sdes # correctly. Breaking it into two sed invocations is a workaround. 612255376Sdes tr ' ' "$nl" < "$tmpdepfile" \ 613255376Sdes | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614255376Sdes | sed -e 's/$/ :/' >> "$depfile" 615117610Sdes rm -f "$tmpdepfile" 616117610Sdes ;; 617117610Sdes 618117610SdesdashXmstdout) 619117610Sdes # This case only exists to satisfy depend.m4. It is never actually 620117610Sdes # run, as this mode is specially recognized in the preamble. 621117610Sdes exit 1 622117610Sdes ;; 623117610Sdes 624117610Sdesmakedepend) 625141098Sdes "$@" || exit $? 626141098Sdes # Remove any Libtool call 627141098Sdes if test "$libtool" = yes; then 628228692Sdes while test "X$1" != 'X--mode=compile'; do 629141098Sdes shift 630141098Sdes done 631141098Sdes shift 632141098Sdes fi 633117610Sdes # X makedepend 634141098Sdes shift 635228692Sdes cleared=no eat=no 636228692Sdes for arg 637228692Sdes do 638141098Sdes case $cleared in 639141098Sdes no) 640141098Sdes set ""; shift 641141098Sdes cleared=yes ;; 642141098Sdes esac 643228692Sdes if test $eat = yes; then 644228692Sdes eat=no 645228692Sdes continue 646228692Sdes fi 647141098Sdes case "$arg" in 648141098Sdes -D*|-I*) 649141098Sdes set fnord "$@" "$arg"; shift ;; 650141098Sdes # Strip any option that makedepend may not understand. Remove 651141098Sdes # the object too, otherwise makedepend will parse it as a source file. 652228692Sdes -arch) 653228692Sdes eat=yes ;; 654141098Sdes -*|$object) 655141098Sdes ;; 656141098Sdes *) 657141098Sdes set fnord "$@" "$arg"; shift ;; 658141098Sdes esac 659141098Sdes done 660228692Sdes obj_suffix=`echo "$object" | sed 's/^.*\././'` 661141098Sdes touch "$tmpdepfile" 662141098Sdes ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663117610Sdes rm -f "$depfile" 664255376Sdes # makedepend may prepend the VPATH from the source file name to the object. 665255376Sdes # No need to regex-escape $object, excess matching of '.' is harmless. 666255376Sdes sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667255376Sdes # Some versions of the HPUX 10.20 sed can't process the last invocation 668255376Sdes # correctly. Breaking it into two sed invocations is a workaround. 669255376Sdes sed '1,2d' "$tmpdepfile" \ 670255376Sdes | tr ' ' "$nl" \ 671255376Sdes | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672255376Sdes | sed -e 's/$/ :/' >> "$depfile" 673117610Sdes rm -f "$tmpdepfile" "$tmpdepfile".bak 674117610Sdes ;; 675117610Sdes 676117610Sdescpp) 677117610Sdes # Important note: in order to support this mode, a compiler *must* 678141098Sdes # always write the preprocessed file to stdout. 679141098Sdes "$@" || exit $? 680141098Sdes 681141098Sdes # Remove the call to Libtool. 682141098Sdes if test "$libtool" = yes; then 683228692Sdes while test "X$1" != 'X--mode=compile'; do 684141098Sdes shift 685141098Sdes done 686141098Sdes shift 687141098Sdes fi 688141098Sdes 689255376Sdes # Remove '-o $object'. 690141098Sdes IFS=" " 691141098Sdes for arg 692141098Sdes do 693141098Sdes case $arg in 694141098Sdes -o) 695141098Sdes shift 696117610Sdes ;; 697141098Sdes $object) 698141098Sdes shift 699141098Sdes ;; 700141098Sdes *) 701141098Sdes set fnord "$@" "$arg" 702141098Sdes shift # fnord 703141098Sdes shift # $arg 704141098Sdes ;; 705117610Sdes esac 706141098Sdes done 707141098Sdes 708255376Sdes "$@" -E \ 709255376Sdes | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710255376Sdes -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711255376Sdes | sed '$ s: \\$::' > "$tmpdepfile" 712117610Sdes rm -f "$depfile" 713117610Sdes echo "$object : \\" > "$depfile" 714117610Sdes cat < "$tmpdepfile" >> "$depfile" 715117610Sdes sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716117610Sdes rm -f "$tmpdepfile" 717117610Sdes ;; 718117610Sdes 719117610Sdesmsvisualcpp) 720117610Sdes # Important note: in order to support this mode, a compiler *must* 721228692Sdes # always write the preprocessed file to stdout. 722141098Sdes "$@" || exit $? 723228692Sdes 724228692Sdes # Remove the call to Libtool. 725228692Sdes if test "$libtool" = yes; then 726228692Sdes while test "X$1" != 'X--mode=compile'; do 727228692Sdes shift 728228692Sdes done 729228692Sdes shift 730228692Sdes fi 731228692Sdes 732141098Sdes IFS=" " 733141098Sdes for arg 734141098Sdes do 735141098Sdes case "$arg" in 736228692Sdes -o) 737228692Sdes shift 738228692Sdes ;; 739228692Sdes $object) 740228692Sdes shift 741228692Sdes ;; 742141098Sdes "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743255376Sdes set fnord "$@" 744255376Sdes shift 745255376Sdes shift 746255376Sdes ;; 747141098Sdes *) 748255376Sdes set fnord "$@" "$arg" 749255376Sdes shift 750255376Sdes shift 751255376Sdes ;; 752117610Sdes esac 753141098Sdes done 754228692Sdes "$@" -E 2>/dev/null | 755228692Sdes sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756117610Sdes rm -f "$depfile" 757117610Sdes echo "$object : \\" > "$depfile" 758255376Sdes sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759255376Sdes echo "$tab" >> "$depfile" 760228692Sdes sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761117610Sdes rm -f "$tmpdepfile" 762117610Sdes ;; 763117610Sdes 764228692Sdesmsvcmsys) 765228692Sdes # This case exists only to let depend.m4 do its work. It works by 766228692Sdes # looking at the text of this script. This case will never be run, 767228692Sdes # since it is checked for above. 768228692Sdes exit 1 769228692Sdes ;; 770228692Sdes 771117610Sdesnone) 772117610Sdes exec "$@" 773117610Sdes ;; 774117610Sdes 775117610Sdes*) 776117610Sdes echo "Unknown depmode $depmode" 1>&2 777117610Sdes exit 1 778117610Sdes ;; 779117610Sdesesac 780117610Sdes 781117610Sdesexit 0 782141098Sdes 783141098Sdes# Local Variables: 784141098Sdes# mode: shell-script 785141098Sdes# sh-indentation: 2 786348980Sdes# eval: (add-hook 'before-save-hook 'time-stamp) 787141098Sdes# time-stamp-start: "scriptversion=" 788141098Sdes# time-stamp-format: "%:y-%02m-%02d.%02H" 789348980Sdes# time-stamp-time-zone: "UTC0" 790228692Sdes# time-stamp-end: "; # UTC" 791141098Sdes# End: 792