depcomp revision 533545b5
1264fa531Smrg#! /bin/sh 2264fa531Smrg# depcomp - compile a program generating dependencies as side-effects 3c37a63b8Smrg 4533545b5Smrgscriptversion=2013-05-30.07; # UTC 5c37a63b8Smrg 6533545b5Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc. 7264fa531Smrg 8264fa531Smrg# This program is free software; you can redistribute it and/or modify 9264fa531Smrg# it under the terms of the GNU General Public License as published by 10264fa531Smrg# the Free Software Foundation; either version 2, or (at your option) 11264fa531Smrg# any later version. 12264fa531Smrg 13264fa531Smrg# This program is distributed in the hope that it will be useful, 14264fa531Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15264fa531Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16264fa531Smrg# GNU General Public License for more details. 17264fa531Smrg 18264fa531Smrg# You should have received a copy of the GNU General Public License 19c37a63b8Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20264fa531Smrg 21264fa531Smrg# As a special exception to the GNU General Public License, if you 22264fa531Smrg# distribute this file as part of a program that contains a 23264fa531Smrg# configuration script generated by Autoconf, you may include it under 24264fa531Smrg# the same distribution terms that you use for the rest of that program. 25264fa531Smrg 26264fa531Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27264fa531Smrg 28c37a63b8Smrgcase $1 in 29c37a63b8Smrg '') 30533545b5Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31533545b5Smrg exit 1; 32533545b5Smrg ;; 33c37a63b8Smrg -h | --h*) 34c37a63b8Smrg cat <<\EOF 35c37a63b8SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36c37a63b8Smrg 37c37a63b8SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38c37a63b8Smrgas side-effects. 39c37a63b8Smrg 40c37a63b8SmrgEnvironment variables: 41c37a63b8Smrg depmode Dependency tracking mode. 42533545b5Smrg source Source file read by 'PROGRAMS ARGS'. 43533545b5Smrg object Object file output by 'PROGRAMS ARGS'. 44c37a63b8Smrg DEPDIR directory where to store dependencies. 45c37a63b8Smrg depfile Dependency file to output. 46533545b5Smrg tmpdepfile Temporary file to use when outputting dependencies. 47c37a63b8Smrg libtool Whether libtool is used (yes/no). 48c37a63b8Smrg 49c37a63b8SmrgReport bugs to <bug-automake@gnu.org>. 50c37a63b8SmrgEOF 51c37a63b8Smrg exit $? 52c37a63b8Smrg ;; 53c37a63b8Smrg -v | --v*) 54c37a63b8Smrg echo "depcomp $scriptversion" 55c37a63b8Smrg exit $? 56c37a63b8Smrg ;; 57c37a63b8Smrgesac 58c37a63b8Smrg 59533545b5Smrg# Get the directory component of the given path, and save it in the 60533545b5Smrg# global variables '$dir'. Note that this directory component will 61533545b5Smrg# be either empty or ending with a '/' character. This is deliberate. 62533545b5Smrgset_dir_from () 63533545b5Smrg{ 64533545b5Smrg case $1 in 65533545b5Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66533545b5Smrg *) dir=;; 67533545b5Smrg esac 68533545b5Smrg} 69533545b5Smrg 70533545b5Smrg# Get the suffix-stripped basename of the given path, and save it the 71533545b5Smrg# global variable '$base'. 72533545b5Smrgset_base_from () 73533545b5Smrg{ 74533545b5Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75533545b5Smrg} 76533545b5Smrg 77533545b5Smrg# If no dependency file was actually created by the compiler invocation, 78533545b5Smrg# we still have to create a dummy depfile, to avoid errors with the 79533545b5Smrg# Makefile "include basename.Plo" scheme. 80533545b5Smrgmake_dummy_depfile () 81533545b5Smrg{ 82533545b5Smrg echo "#dummy" > "$depfile" 83533545b5Smrg} 84533545b5Smrg 85533545b5Smrg# Factor out some common post-processing of the generated depfile. 86533545b5Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87533545b5Smrgaix_post_process_depfile () 88533545b5Smrg{ 89533545b5Smrg # If the compiler actually managed to produce a dependency file, 90533545b5Smrg # post-process it. 91533545b5Smrg if test -f "$tmpdepfile"; then 92533545b5Smrg # Each line is of the form 'foo.o: dependency.h'. 93533545b5Smrg # Do two passes, one to just change these to 94533545b5Smrg # $object: dependency.h 95533545b5Smrg # and one to simply output 96533545b5Smrg # dependency.h: 97533545b5Smrg # which is needed to avoid the deleted-header problem. 98533545b5Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99533545b5Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100533545b5Smrg } > "$depfile" 101533545b5Smrg rm -f "$tmpdepfile" 102533545b5Smrg else 103533545b5Smrg make_dummy_depfile 104533545b5Smrg fi 105533545b5Smrg} 106533545b5Smrg 107533545b5Smrg# A tabulation character. 108533545b5Smrgtab=' ' 109533545b5Smrg# A newline character. 110533545b5Smrgnl=' 111533545b5Smrg' 112533545b5Smrg# Character ranges might be problematic outside the C locale. 113533545b5Smrg# These definitions help. 114533545b5Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115533545b5Smrglower=abcdefghijklmnopqrstuvwxyz 116533545b5Smrgdigits=0123456789 117533545b5Smrgalpha=${upper}${lower} 118533545b5Smrg 119264fa531Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120264fa531Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121264fa531Smrg exit 1 122264fa531Smrgfi 123264fa531Smrg 124c37a63b8Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125c37a63b8Smrgdepfile=${depfile-`echo "$object" | 126c37a63b8Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127264fa531Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128264fa531Smrg 129264fa531Smrgrm -f "$tmpdepfile" 130264fa531Smrg 131533545b5Smrg# Avoid interferences from the environment. 132533545b5Smrggccflag= dashmflag= 133533545b5Smrg 134264fa531Smrg# Some modes work just like other modes, but use different flags. We 135264fa531Smrg# parameterize here, but still list the modes in the big case below, 136264fa531Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137264fa531Smrg# here, because this file can only contain one case statement. 138264fa531Smrgif test "$depmode" = hp; then 139264fa531Smrg # HP compiler uses -M and no extra arg. 140264fa531Smrg gccflag=-M 141264fa531Smrg depmode=gcc 142264fa531Smrgfi 143264fa531Smrg 144264fa531Smrgif test "$depmode" = dashXmstdout; then 145533545b5Smrg # This is just like dashmstdout with a different argument. 146533545b5Smrg dashmflag=-xM 147533545b5Smrg depmode=dashmstdout 148264fa531Smrgfi 149264fa531Smrg 150c37a63b8Smrgcygpath_u="cygpath -u -f -" 151c37a63b8Smrgif test "$depmode" = msvcmsys; then 152533545b5Smrg # This is just like msvisualcpp but w/o cygpath translation. 153533545b5Smrg # Just convert the backslash-escaped backslashes to single forward 154533545b5Smrg # slashes to satisfy depend.m4 155533545b5Smrg cygpath_u='sed s,\\\\,/,g' 156533545b5Smrg depmode=msvisualcpp 157533545b5Smrgfi 158533545b5Smrg 159533545b5Smrgif test "$depmode" = msvc7msys; then 160533545b5Smrg # This is just like msvc7 but w/o cygpath translation. 161533545b5Smrg # Just convert the backslash-escaped backslashes to single forward 162533545b5Smrg # slashes to satisfy depend.m4 163533545b5Smrg cygpath_u='sed s,\\\\,/,g' 164533545b5Smrg depmode=msvc7 165533545b5Smrgfi 166533545b5Smrg 167533545b5Smrgif test "$depmode" = xlc; then 168533545b5Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169533545b5Smrg gccflag=-qmakedep=gcc,-MF 170533545b5Smrg depmode=gcc 171c37a63b8Smrgfi 172c37a63b8Smrg 173264fa531Smrgcase "$depmode" in 174264fa531Smrggcc3) 175264fa531Smrg## gcc 3 implements dependency tracking that does exactly what 176264fa531Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177264fa531Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178c37a63b8Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179c37a63b8Smrg## the command line argument order; so add the flags where they 180c37a63b8Smrg## appear in depend2.am. Note that the slowdown incurred here 181c37a63b8Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182c37a63b8Smrg for arg 183c37a63b8Smrg do 184c37a63b8Smrg case $arg in 185c37a63b8Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186c37a63b8Smrg *) set fnord "$@" "$arg" ;; 187c37a63b8Smrg esac 188c37a63b8Smrg shift # fnord 189c37a63b8Smrg shift # $arg 190c37a63b8Smrg done 191c37a63b8Smrg "$@" 192264fa531Smrg stat=$? 193533545b5Smrg if test $stat -ne 0; then 194264fa531Smrg rm -f "$tmpdepfile" 195264fa531Smrg exit $stat 196264fa531Smrg fi 197264fa531Smrg mv "$tmpdepfile" "$depfile" 198264fa531Smrg ;; 199264fa531Smrg 200264fa531Smrggcc) 201533545b5Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202533545b5Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203533545b5Smrg## (see the conditional assignment to $gccflag above). 204264fa531Smrg## There are various ways to get dependency output from gcc. Here's 205264fa531Smrg## why we pick this rather obscure method: 206264fa531Smrg## - Don't want to use -MD because we'd like the dependencies to end 207264fa531Smrg## up in a subdir. Having to rename by hand is ugly. 208264fa531Smrg## (We might end up doing this anyway to support other compilers.) 209264fa531Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210533545b5Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211533545b5Smrg## supported by the other compilers which use the 'gcc' depmode. 212264fa531Smrg## - Using -M directly means running the compiler twice (even worse 213264fa531Smrg## than renaming). 214264fa531Smrg if test -z "$gccflag"; then 215264fa531Smrg gccflag=-MD, 216264fa531Smrg fi 217264fa531Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218264fa531Smrg stat=$? 219533545b5Smrg if test $stat -ne 0; then 220264fa531Smrg rm -f "$tmpdepfile" 221264fa531Smrg exit $stat 222264fa531Smrg fi 223264fa531Smrg rm -f "$depfile" 224264fa531Smrg echo "$object : \\" > "$depfile" 225533545b5Smrg # The second -e expression handles DOS-style file names with drive 226533545b5Smrg # letters. 227264fa531Smrg sed -e 's/^[^:]*: / /' \ 228264fa531Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229533545b5Smrg## This next piece of magic avoids the "deleted header file" problem. 230264fa531Smrg## The problem is that when a header file which appears in a .P file 231264fa531Smrg## is deleted, the dependency causes make to die (because there is 232264fa531Smrg## typically no way to rebuild the header). We avoid this by adding 233264fa531Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234264fa531Smrg## this for us directly. 235533545b5Smrg## Some versions of gcc put a space before the ':'. On the theory 236264fa531Smrg## that the space means something, we add a space to the output as 237533545b5Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238533545b5Smrg## to the object. Take care to not repeat it in the output. 239264fa531Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240264fa531Smrg## correctly. Breaking it into two sed invocations is a workaround. 241533545b5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242533545b5Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243533545b5Smrg | sed -e 's/$/ :/' >> "$depfile" 244264fa531Smrg rm -f "$tmpdepfile" 245264fa531Smrg ;; 246264fa531Smrg 247264fa531Smrghp) 248264fa531Smrg # This case exists only to let depend.m4 do its work. It works by 249264fa531Smrg # looking at the text of this script. This case will never be run, 250264fa531Smrg # since it is checked for above. 251264fa531Smrg exit 1 252264fa531Smrg ;; 253264fa531Smrg 254264fa531Smrgsgi) 255264fa531Smrg if test "$libtool" = yes; then 256264fa531Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257264fa531Smrg else 258264fa531Smrg "$@" -MDupdate "$tmpdepfile" 259264fa531Smrg fi 260264fa531Smrg stat=$? 261533545b5Smrg if test $stat -ne 0; then 262264fa531Smrg rm -f "$tmpdepfile" 263264fa531Smrg exit $stat 264264fa531Smrg fi 265264fa531Smrg rm -f "$depfile" 266264fa531Smrg 267264fa531Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268264fa531Smrg echo "$object : \\" > "$depfile" 269264fa531Smrg # Clip off the initial element (the dependent). Don't try to be 270264fa531Smrg # clever and replace this with sed code, as IRIX sed won't handle 271264fa531Smrg # lines with more than a fixed number of characters (4096 in 272264fa531Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273533545b5Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274264fa531Smrg # dependency line. 275533545b5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276533545b5Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277533545b5Smrg | tr "$nl" ' ' >> "$depfile" 278c37a63b8Smrg echo >> "$depfile" 279264fa531Smrg # The second pass generates a dummy entry for each header file. 280533545b5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281533545b5Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282533545b5Smrg >> "$depfile" 283264fa531Smrg else 284533545b5Smrg make_dummy_depfile 285264fa531Smrg fi 286264fa531Smrg rm -f "$tmpdepfile" 287264fa531Smrg ;; 288264fa531Smrg 289533545b5Smrgxlc) 290533545b5Smrg # This case exists only to let depend.m4 do its work. It works by 291533545b5Smrg # looking at the text of this script. This case will never be run, 292533545b5Smrg # since it is checked for above. 293533545b5Smrg exit 1 294533545b5Smrg ;; 295533545b5Smrg 296264fa531Smrgaix) 297264fa531Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298264fa531Smrg # in a .u file. In older versions, this file always lives in the 299533545b5Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300264fa531Smrg # start of each line; $object doesn't have directory information. 301264fa531Smrg # Version 6 uses the directory in both cases. 302533545b5Smrg set_dir_from "$object" 303533545b5Smrg set_base_from "$object" 304264fa531Smrg if test "$libtool" = yes; then 305c37a63b8Smrg tmpdepfile1=$dir$base.u 306c37a63b8Smrg tmpdepfile2=$base.u 307c37a63b8Smrg tmpdepfile3=$dir.libs/$base.u 308264fa531Smrg "$@" -Wc,-M 309264fa531Smrg else 310c37a63b8Smrg tmpdepfile1=$dir$base.u 311c37a63b8Smrg tmpdepfile2=$dir$base.u 312c37a63b8Smrg tmpdepfile3=$dir$base.u 313264fa531Smrg "$@" -M 314264fa531Smrg fi 315264fa531Smrg stat=$? 316533545b5Smrg if test $stat -ne 0; then 317c37a63b8Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318264fa531Smrg exit $stat 319264fa531Smrg fi 320264fa531Smrg 321c37a63b8Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322c37a63b8Smrg do 323c37a63b8Smrg test -f "$tmpdepfile" && break 324c37a63b8Smrg done 325533545b5Smrg aix_post_process_depfile 326533545b5Smrg ;; 327533545b5Smrg 328533545b5Smrgtcc) 329533545b5Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330533545b5Smrg # FIXME: That version still under development at the moment of writing. 331533545b5Smrg # Make that this statement remains true also for stable, released 332533545b5Smrg # versions. 333533545b5Smrg # It will wrap lines (doesn't matter whether long or short) with a 334533545b5Smrg # trailing '\', as in: 335533545b5Smrg # 336533545b5Smrg # foo.o : \ 337533545b5Smrg # foo.c \ 338533545b5Smrg # foo.h \ 339533545b5Smrg # 340533545b5Smrg # It will put a trailing '\' even on the last line, and will use leading 341533545b5Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342533545b5Smrg # "Emit spaces for -MD"). 343533545b5Smrg "$@" -MD -MF "$tmpdepfile" 344533545b5Smrg stat=$? 345533545b5Smrg if test $stat -ne 0; then 346533545b5Smrg rm -f "$tmpdepfile" 347533545b5Smrg exit $stat 348264fa531Smrg fi 349533545b5Smrg rm -f "$depfile" 350533545b5Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351533545b5Smrg # We have to change lines of the first kind to '$object: \'. 352533545b5Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353533545b5Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354533545b5Smrg # dummy dependency, to avoid the deleted-header problem. 355533545b5Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356264fa531Smrg rm -f "$tmpdepfile" 357264fa531Smrg ;; 358264fa531Smrg 359533545b5Smrg## The order of this option in the case statement is important, since the 360533545b5Smrg## shell code in configure will try each of these formats in the order 361533545b5Smrg## listed in this file. A plain '-MD' option would be understood by many 362533545b5Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363533545b5Smrgpgcc) 364533545b5Smrg # Portland's C compiler understands '-MD'. 365533545b5Smrg # Will always output deps to 'file.d' where file is the root name of the 366533545b5Smrg # source file under compilation, even if file resides in a subdirectory. 367533545b5Smrg # The object file name does not affect the name of the '.d' file. 368533545b5Smrg # pgcc 10.2 will output 369264fa531Smrg # foo.o: sub/foo.c sub/foo.h 370533545b5Smrg # and will wrap long lines using '\' : 371264fa531Smrg # foo.o: sub/foo.c ... \ 372264fa531Smrg # sub/foo.h ... \ 373264fa531Smrg # ... 374533545b5Smrg set_dir_from "$object" 375533545b5Smrg # Use the source, not the object, to determine the base name, since 376533545b5Smrg # that's sadly what pgcc will do too. 377533545b5Smrg set_base_from "$source" 378533545b5Smrg tmpdepfile=$base.d 379533545b5Smrg 380533545b5Smrg # For projects that build the same source file twice into different object 381533545b5Smrg # files, the pgcc approach of using the *source* file root name can cause 382533545b5Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383533545b5Smrg # the same $tmpdepfile. 384533545b5Smrg lockdir=$base.d-lock 385533545b5Smrg trap " 386533545b5Smrg echo '$0: caught signal, cleaning up...' >&2 387533545b5Smrg rmdir '$lockdir' 388533545b5Smrg exit 1 389533545b5Smrg " 1 2 13 15 390533545b5Smrg numtries=100 391533545b5Smrg i=$numtries 392533545b5Smrg while test $i -gt 0; do 393533545b5Smrg # mkdir is a portable test-and-set. 394533545b5Smrg if mkdir "$lockdir" 2>/dev/null; then 395533545b5Smrg # This process acquired the lock. 396533545b5Smrg "$@" -MD 397533545b5Smrg stat=$? 398533545b5Smrg # Release the lock. 399533545b5Smrg rmdir "$lockdir" 400533545b5Smrg break 401533545b5Smrg else 402533545b5Smrg # If the lock is being held by a different process, wait 403533545b5Smrg # until the winning process is done or we timeout. 404533545b5Smrg while test -d "$lockdir" && test $i -gt 0; do 405533545b5Smrg sleep 1 406533545b5Smrg i=`expr $i - 1` 407533545b5Smrg done 408533545b5Smrg fi 409533545b5Smrg i=`expr $i - 1` 410533545b5Smrg done 411533545b5Smrg trap - 1 2 13 15 412533545b5Smrg if test $i -le 0; then 413533545b5Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414533545b5Smrg echo "$0: check lockdir '$lockdir'" >&2 415533545b5Smrg exit 1 416533545b5Smrg fi 417264fa531Smrg 418533545b5Smrg if test $stat -ne 0; then 419264fa531Smrg rm -f "$tmpdepfile" 420264fa531Smrg exit $stat 421264fa531Smrg fi 422264fa531Smrg rm -f "$depfile" 423264fa531Smrg # Each line is of the form `foo.o: dependent.h', 424264fa531Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425264fa531Smrg # Do two passes, one to just change these to 426264fa531Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427264fa531Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428264fa531Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429264fa531Smrg # correctly. Breaking it into two sed invocations is a workaround. 430533545b5Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431533545b5Smrg | sed -e 's/$/ :/' >> "$depfile" 432264fa531Smrg rm -f "$tmpdepfile" 433264fa531Smrg ;; 434264fa531Smrg 435c37a63b8Smrghp2) 436c37a63b8Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437c37a63b8Smrg # compilers, which have integrated preprocessors. The correct option 438c37a63b8Smrg # to use with these is +Maked; it writes dependencies to a file named 439c37a63b8Smrg # 'foo.d', which lands next to the object file, wherever that 440c37a63b8Smrg # happens to be. 441c37a63b8Smrg # Much of this is similar to the tru64 case; see comments there. 442533545b5Smrg set_dir_from "$object" 443533545b5Smrg set_base_from "$object" 444c37a63b8Smrg if test "$libtool" = yes; then 445c37a63b8Smrg tmpdepfile1=$dir$base.d 446c37a63b8Smrg tmpdepfile2=$dir.libs/$base.d 447c37a63b8Smrg "$@" -Wc,+Maked 448c37a63b8Smrg else 449c37a63b8Smrg tmpdepfile1=$dir$base.d 450c37a63b8Smrg tmpdepfile2=$dir$base.d 451c37a63b8Smrg "$@" +Maked 452c37a63b8Smrg fi 453c37a63b8Smrg stat=$? 454533545b5Smrg if test $stat -ne 0; then 455c37a63b8Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456c37a63b8Smrg exit $stat 457c37a63b8Smrg fi 458c37a63b8Smrg 459c37a63b8Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460c37a63b8Smrg do 461c37a63b8Smrg test -f "$tmpdepfile" && break 462c37a63b8Smrg done 463c37a63b8Smrg if test -f "$tmpdepfile"; then 464533545b5Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465533545b5Smrg # Add 'dependent.h:' lines. 466c37a63b8Smrg sed -ne '2,${ 467533545b5Smrg s/^ *// 468533545b5Smrg s/ \\*$// 469533545b5Smrg s/$/:/ 470533545b5Smrg p 471533545b5Smrg }' "$tmpdepfile" >> "$depfile" 472c37a63b8Smrg else 473533545b5Smrg make_dummy_depfile 474c37a63b8Smrg fi 475c37a63b8Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 476c37a63b8Smrg ;; 477c37a63b8Smrg 478264fa531Smrgtru64) 479533545b5Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480533545b5Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481533545b5Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482533545b5Smrg # dependencies in 'foo.d' instead, so we check for that too. 483533545b5Smrg # Subdirectories are respected. 484533545b5Smrg set_dir_from "$object" 485533545b5Smrg set_base_from "$object" 486533545b5Smrg 487533545b5Smrg if test "$libtool" = yes; then 488533545b5Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489533545b5Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490533545b5Smrg # in $dir$base.o.d. We have to check for both files, because 491533545b5Smrg # one of the two compilations can be disabled. We should prefer 492533545b5Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493533545b5Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494533545b5Smrg # the former would cause a distcleancheck panic. 495533545b5Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496533545b5Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497533545b5Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498533545b5Smrg "$@" -Wc,-MD 499533545b5Smrg else 500533545b5Smrg tmpdepfile1=$dir$base.d 501533545b5Smrg tmpdepfile2=$dir$base.d 502533545b5Smrg tmpdepfile3=$dir$base.d 503533545b5Smrg "$@" -MD 504533545b5Smrg fi 505533545b5Smrg 506533545b5Smrg stat=$? 507533545b5Smrg if test $stat -ne 0; then 508533545b5Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509533545b5Smrg exit $stat 510533545b5Smrg fi 511533545b5Smrg 512533545b5Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513533545b5Smrg do 514533545b5Smrg test -f "$tmpdepfile" && break 515533545b5Smrg done 516533545b5Smrg # Same post-processing that is required for AIX mode. 517533545b5Smrg aix_post_process_depfile 518533545b5Smrg ;; 519533545b5Smrg 520533545b5Smrgmsvc7) 521533545b5Smrg if test "$libtool" = yes; then 522533545b5Smrg showIncludes=-Wc,-showIncludes 523533545b5Smrg else 524533545b5Smrg showIncludes=-showIncludes 525533545b5Smrg fi 526533545b5Smrg "$@" $showIncludes > "$tmpdepfile" 527533545b5Smrg stat=$? 528533545b5Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529533545b5Smrg if test $stat -ne 0; then 530533545b5Smrg rm -f "$tmpdepfile" 531533545b5Smrg exit $stat 532533545b5Smrg fi 533533545b5Smrg rm -f "$depfile" 534533545b5Smrg echo "$object : \\" > "$depfile" 535533545b5Smrg # The first sed program below extracts the file names and escapes 536533545b5Smrg # backslashes for cygpath. The second sed program outputs the file 537533545b5Smrg # name when reading, but also accumulates all include files in the 538533545b5Smrg # hold buffer in order to output them again at the end. This only 539533545b5Smrg # works with sed implementations that can handle large buffers. 540533545b5Smrg sed < "$tmpdepfile" -n ' 541533545b5Smrg/^Note: including file: *\(.*\)/ { 542533545b5Smrg s//\1/ 543533545b5Smrg s/\\/\\\\/g 544533545b5Smrg p 545533545b5Smrg}' | $cygpath_u | sort -u | sed -n ' 546533545b5Smrgs/ /\\ /g 547533545b5Smrgs/\(.*\)/'"$tab"'\1 \\/p 548533545b5Smrgs/.\(.*\) \\/\1:/ 549533545b5SmrgH 550533545b5Smrg$ { 551533545b5Smrg s/.*/'"$tab"'/ 552533545b5Smrg G 553533545b5Smrg p 554533545b5Smrg}' >> "$depfile" 555533545b5Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556533545b5Smrg rm -f "$tmpdepfile" 557533545b5Smrg ;; 558533545b5Smrg 559533545b5Smrgmsvc7msys) 560533545b5Smrg # This case exists only to let depend.m4 do its work. It works by 561533545b5Smrg # looking at the text of this script. This case will never be run, 562533545b5Smrg # since it is checked for above. 563533545b5Smrg exit 1 564533545b5Smrg ;; 565264fa531Smrg 566264fa531Smrg#nosideeffect) 567264fa531Smrg # This comment above is used by automake to tell side-effect 568264fa531Smrg # dependency tracking mechanisms from slower ones. 569264fa531Smrg 570264fa531Smrgdashmstdout) 571264fa531Smrg # Important note: in order to support this mode, a compiler *must* 572264fa531Smrg # always write the preprocessed file to stdout, regardless of -o. 573264fa531Smrg "$@" || exit $? 574264fa531Smrg 575264fa531Smrg # Remove the call to Libtool. 576264fa531Smrg if test "$libtool" = yes; then 577c37a63b8Smrg while test "X$1" != 'X--mode=compile'; do 578264fa531Smrg shift 579264fa531Smrg done 580264fa531Smrg shift 581264fa531Smrg fi 582264fa531Smrg 583533545b5Smrg # Remove '-o $object'. 584264fa531Smrg IFS=" " 585264fa531Smrg for arg 586264fa531Smrg do 587264fa531Smrg case $arg in 588264fa531Smrg -o) 589264fa531Smrg shift 590264fa531Smrg ;; 591264fa531Smrg $object) 592264fa531Smrg shift 593264fa531Smrg ;; 594264fa531Smrg *) 595264fa531Smrg set fnord "$@" "$arg" 596264fa531Smrg shift # fnord 597264fa531Smrg shift # $arg 598264fa531Smrg ;; 599264fa531Smrg esac 600264fa531Smrg done 601264fa531Smrg 602264fa531Smrg test -z "$dashmflag" && dashmflag=-M 603533545b5Smrg # Require at least two characters before searching for ':' 604264fa531Smrg # in the target name. This is to cope with DOS-style filenames: 605533545b5Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606264fa531Smrg "$@" $dashmflag | 607533545b5Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608264fa531Smrg rm -f "$depfile" 609264fa531Smrg cat < "$tmpdepfile" > "$depfile" 610533545b5Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611533545b5Smrg # correctly. Breaking it into two sed invocations is a workaround. 612533545b5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613533545b5Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614533545b5Smrg | sed -e 's/$/ :/' >> "$depfile" 615264fa531Smrg rm -f "$tmpdepfile" 616264fa531Smrg ;; 617264fa531Smrg 618264fa531SmrgdashXmstdout) 619264fa531Smrg # This case only exists to satisfy depend.m4. It is never actually 620264fa531Smrg # run, as this mode is specially recognized in the preamble. 621264fa531Smrg exit 1 622264fa531Smrg ;; 623264fa531Smrg 624264fa531Smrgmakedepend) 625264fa531Smrg "$@" || exit $? 626264fa531Smrg # Remove any Libtool call 627264fa531Smrg if test "$libtool" = yes; then 628c37a63b8Smrg while test "X$1" != 'X--mode=compile'; do 629264fa531Smrg shift 630264fa531Smrg done 631264fa531Smrg shift 632264fa531Smrg fi 633264fa531Smrg # X makedepend 634264fa531Smrg shift 635c37a63b8Smrg cleared=no eat=no 636c37a63b8Smrg for arg 637c37a63b8Smrg do 638264fa531Smrg case $cleared in 639264fa531Smrg no) 640264fa531Smrg set ""; shift 641264fa531Smrg cleared=yes ;; 642264fa531Smrg esac 643c37a63b8Smrg if test $eat = yes; then 644c37a63b8Smrg eat=no 645c37a63b8Smrg continue 646c37a63b8Smrg fi 647264fa531Smrg case "$arg" in 648264fa531Smrg -D*|-I*) 649264fa531Smrg set fnord "$@" "$arg"; shift ;; 650264fa531Smrg # Strip any option that makedepend may not understand. Remove 651264fa531Smrg # the object too, otherwise makedepend will parse it as a source file. 652c37a63b8Smrg -arch) 653c37a63b8Smrg eat=yes ;; 654264fa531Smrg -*|$object) 655264fa531Smrg ;; 656264fa531Smrg *) 657264fa531Smrg set fnord "$@" "$arg"; shift ;; 658264fa531Smrg esac 659264fa531Smrg done 660c37a63b8Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661264fa531Smrg touch "$tmpdepfile" 662264fa531Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663264fa531Smrg rm -f "$depfile" 664533545b5Smrg # makedepend may prepend the VPATH from the source file name to the object. 665533545b5Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666533545b5Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667533545b5Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668533545b5Smrg # correctly. Breaking it into two sed invocations is a workaround. 669533545b5Smrg sed '1,2d' "$tmpdepfile" \ 670533545b5Smrg | tr ' ' "$nl" \ 671533545b5Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672533545b5Smrg | sed -e 's/$/ :/' >> "$depfile" 673264fa531Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674264fa531Smrg ;; 675264fa531Smrg 676264fa531Smrgcpp) 677264fa531Smrg # Important note: in order to support this mode, a compiler *must* 678264fa531Smrg # always write the preprocessed file to stdout. 679264fa531Smrg "$@" || exit $? 680264fa531Smrg 681264fa531Smrg # Remove the call to Libtool. 682264fa531Smrg if test "$libtool" = yes; then 683c37a63b8Smrg while test "X$1" != 'X--mode=compile'; do 684264fa531Smrg shift 685264fa531Smrg done 686264fa531Smrg shift 687264fa531Smrg fi 688264fa531Smrg 689533545b5Smrg # Remove '-o $object'. 690264fa531Smrg IFS=" " 691264fa531Smrg for arg 692264fa531Smrg do 693264fa531Smrg case $arg in 694264fa531Smrg -o) 695264fa531Smrg shift 696264fa531Smrg ;; 697264fa531Smrg $object) 698264fa531Smrg shift 699264fa531Smrg ;; 700264fa531Smrg *) 701264fa531Smrg set fnord "$@" "$arg" 702264fa531Smrg shift # fnord 703264fa531Smrg shift # $arg 704264fa531Smrg ;; 705264fa531Smrg esac 706264fa531Smrg done 707264fa531Smrg 708533545b5Smrg "$@" -E \ 709533545b5Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710533545b5Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711533545b5Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712264fa531Smrg rm -f "$depfile" 713264fa531Smrg echo "$object : \\" > "$depfile" 714264fa531Smrg cat < "$tmpdepfile" >> "$depfile" 715264fa531Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716264fa531Smrg rm -f "$tmpdepfile" 717264fa531Smrg ;; 718264fa531Smrg 719264fa531Smrgmsvisualcpp) 720264fa531Smrg # Important note: in order to support this mode, a compiler *must* 721c37a63b8Smrg # always write the preprocessed file to stdout. 722264fa531Smrg "$@" || exit $? 723c37a63b8Smrg 724c37a63b8Smrg # Remove the call to Libtool. 725c37a63b8Smrg if test "$libtool" = yes; then 726c37a63b8Smrg while test "X$1" != 'X--mode=compile'; do 727c37a63b8Smrg shift 728c37a63b8Smrg done 729c37a63b8Smrg shift 730c37a63b8Smrg fi 731c37a63b8Smrg 732264fa531Smrg IFS=" " 733264fa531Smrg for arg 734264fa531Smrg do 735264fa531Smrg case "$arg" in 736c37a63b8Smrg -o) 737c37a63b8Smrg shift 738c37a63b8Smrg ;; 739c37a63b8Smrg $object) 740c37a63b8Smrg shift 741c37a63b8Smrg ;; 742264fa531Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743533545b5Smrg set fnord "$@" 744533545b5Smrg shift 745533545b5Smrg shift 746533545b5Smrg ;; 747264fa531Smrg *) 748533545b5Smrg set fnord "$@" "$arg" 749533545b5Smrg shift 750533545b5Smrg shift 751533545b5Smrg ;; 752264fa531Smrg esac 753264fa531Smrg done 754c37a63b8Smrg "$@" -E 2>/dev/null | 755c37a63b8Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756264fa531Smrg rm -f "$depfile" 757264fa531Smrg echo "$object : \\" > "$depfile" 758533545b5Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759533545b5Smrg echo "$tab" >> "$depfile" 760c37a63b8Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761264fa531Smrg rm -f "$tmpdepfile" 762264fa531Smrg ;; 763264fa531Smrg 764c37a63b8Smrgmsvcmsys) 765c37a63b8Smrg # This case exists only to let depend.m4 do its work. It works by 766c37a63b8Smrg # looking at the text of this script. This case will never be run, 767c37a63b8Smrg # since it is checked for above. 768c37a63b8Smrg exit 1 769c37a63b8Smrg ;; 770c37a63b8Smrg 771264fa531Smrgnone) 772264fa531Smrg exec "$@" 773264fa531Smrg ;; 774264fa531Smrg 775264fa531Smrg*) 776264fa531Smrg echo "Unknown depmode $depmode" 1>&2 777264fa531Smrg exit 1 778264fa531Smrg ;; 779264fa531Smrgesac 780264fa531Smrg 781264fa531Smrgexit 0 782c37a63b8Smrg 783c37a63b8Smrg# Local Variables: 784c37a63b8Smrg# mode: shell-script 785c37a63b8Smrg# sh-indentation: 2 786c37a63b8Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 787c37a63b8Smrg# time-stamp-start: "scriptversion=" 788c37a63b8Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789c37a63b8Smrg# time-stamp-time-zone: "UTC" 790c37a63b8Smrg# time-stamp-end: "; # UTC" 791c37a63b8Smrg# End: 792