depcomp revision 95b7a5c8
127702724Smrg#! /bin/sh 227702724Smrg# depcomp - compile a program generating dependencies as side-effects 327702724Smrg 495b7a5c8Smrgscriptversion=2018-03-07.03; # UTC 527702724Smrg 695b7a5c8Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 727702724Smrg 827702724Smrg# This program is free software; you can redistribute it and/or modify 927702724Smrg# it under the terms of the GNU General Public License as published by 1027702724Smrg# the Free Software Foundation; either version 2, or (at your option) 1127702724Smrg# any later version. 1227702724Smrg 1327702724Smrg# This program is distributed in the hope that it will be useful, 1427702724Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1527702724Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1627702724Smrg# GNU General Public License for more details. 1727702724Smrg 1827702724Smrg# You should have received a copy of the GNU General Public License 1995b7a5c8Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2027702724Smrg 2127702724Smrg# As a special exception to the GNU General Public License, if you 2227702724Smrg# distribute this file as part of a program that contains a 2327702724Smrg# configuration script generated by Autoconf, you may include it under 2427702724Smrg# the same distribution terms that you use for the rest of that program. 2527702724Smrg 2627702724Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2727702724Smrg 2827702724Smrgcase $1 in 2927702724Smrg '') 30313a12fdSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31313a12fdSmrg exit 1; 32313a12fdSmrg ;; 3327702724Smrg -h | --h*) 3427702724Smrg cat <<\EOF 3527702724SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3627702724Smrg 3727702724SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3827702724Smrgas side-effects. 3927702724Smrg 4027702724SmrgEnvironment variables: 4127702724Smrg depmode Dependency tracking mode. 42313a12fdSmrg source Source file read by 'PROGRAMS ARGS'. 43313a12fdSmrg object Object file output by 'PROGRAMS ARGS'. 4427702724Smrg DEPDIR directory where to store dependencies. 4527702724Smrg depfile Dependency file to output. 46313a12fdSmrg tmpdepfile Temporary file to use when outputting dependencies. 4727702724Smrg libtool Whether libtool is used (yes/no). 4827702724Smrg 4927702724SmrgReport bugs to <bug-automake@gnu.org>. 5027702724SmrgEOF 5127702724Smrg exit $? 5227702724Smrg ;; 5327702724Smrg -v | --v*) 5427702724Smrg echo "depcomp $scriptversion" 5527702724Smrg exit $? 5627702724Smrg ;; 5727702724Smrgesac 5827702724Smrg 59313a12fdSmrg# Get the directory component of the given path, and save it in the 60313a12fdSmrg# global variables '$dir'. Note that this directory component will 61313a12fdSmrg# be either empty or ending with a '/' character. This is deliberate. 62313a12fdSmrgset_dir_from () 63313a12fdSmrg{ 64313a12fdSmrg case $1 in 65313a12fdSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66313a12fdSmrg *) dir=;; 67313a12fdSmrg esac 68313a12fdSmrg} 69313a12fdSmrg 70313a12fdSmrg# Get the suffix-stripped basename of the given path, and save it the 71313a12fdSmrg# global variable '$base'. 72313a12fdSmrgset_base_from () 73313a12fdSmrg{ 74313a12fdSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75313a12fdSmrg} 76313a12fdSmrg 77313a12fdSmrg# If no dependency file was actually created by the compiler invocation, 78313a12fdSmrg# we still have to create a dummy depfile, to avoid errors with the 79313a12fdSmrg# Makefile "include basename.Plo" scheme. 80313a12fdSmrgmake_dummy_depfile () 81313a12fdSmrg{ 82313a12fdSmrg echo "#dummy" > "$depfile" 83313a12fdSmrg} 84313a12fdSmrg 85313a12fdSmrg# Factor out some common post-processing of the generated depfile. 86313a12fdSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87313a12fdSmrgaix_post_process_depfile () 88313a12fdSmrg{ 89313a12fdSmrg # If the compiler actually managed to produce a dependency file, 90313a12fdSmrg # post-process it. 91313a12fdSmrg if test -f "$tmpdepfile"; then 92313a12fdSmrg # Each line is of the form 'foo.o: dependency.h'. 93313a12fdSmrg # Do two passes, one to just change these to 94313a12fdSmrg # $object: dependency.h 95313a12fdSmrg # and one to simply output 96313a12fdSmrg # dependency.h: 97313a12fdSmrg # which is needed to avoid the deleted-header problem. 98313a12fdSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99313a12fdSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100313a12fdSmrg } > "$depfile" 101313a12fdSmrg rm -f "$tmpdepfile" 102313a12fdSmrg else 103313a12fdSmrg make_dummy_depfile 104313a12fdSmrg fi 105313a12fdSmrg} 106313a12fdSmrg 107313a12fdSmrg# A tabulation character. 108313a12fdSmrgtab=' ' 109313a12fdSmrg# A newline character. 110313a12fdSmrgnl=' 111313a12fdSmrg' 112313a12fdSmrg# Character ranges might be problematic outside the C locale. 113313a12fdSmrg# These definitions help. 114313a12fdSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115313a12fdSmrglower=abcdefghijklmnopqrstuvwxyz 116313a12fdSmrgdigits=0123456789 117313a12fdSmrgalpha=${upper}${lower} 118313a12fdSmrg 11927702724Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12027702724Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12127702724Smrg exit 1 12227702724Smrgfi 12327702724Smrg 12427702724Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12527702724Smrgdepfile=${depfile-`echo "$object" | 12627702724Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12727702724Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12827702724Smrg 12927702724Smrgrm -f "$tmpdepfile" 13027702724Smrg 131313a12fdSmrg# Avoid interferences from the environment. 132313a12fdSmrggccflag= dashmflag= 133313a12fdSmrg 13427702724Smrg# Some modes work just like other modes, but use different flags. We 13527702724Smrg# parameterize here, but still list the modes in the big case below, 13627702724Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13727702724Smrg# here, because this file can only contain one case statement. 13827702724Smrgif test "$depmode" = hp; then 13927702724Smrg # HP compiler uses -M and no extra arg. 14027702724Smrg gccflag=-M 14127702724Smrg depmode=gcc 14227702724Smrgfi 14327702724Smrg 14427702724Smrgif test "$depmode" = dashXmstdout; then 145313a12fdSmrg # This is just like dashmstdout with a different argument. 146313a12fdSmrg dashmflag=-xM 147313a12fdSmrg depmode=dashmstdout 14827702724Smrgfi 14927702724Smrg 15000084f2cSmrgcygpath_u="cygpath -u -f -" 15100084f2cSmrgif test "$depmode" = msvcmsys; then 152313a12fdSmrg # This is just like msvisualcpp but w/o cygpath translation. 153313a12fdSmrg # Just convert the backslash-escaped backslashes to single forward 154313a12fdSmrg # slashes to satisfy depend.m4 155313a12fdSmrg cygpath_u='sed s,\\\\,/,g' 156313a12fdSmrg depmode=msvisualcpp 157313a12fdSmrgfi 158313a12fdSmrg 159313a12fdSmrgif test "$depmode" = msvc7msys; then 160313a12fdSmrg # This is just like msvc7 but w/o cygpath translation. 161313a12fdSmrg # Just convert the backslash-escaped backslashes to single forward 162313a12fdSmrg # slashes to satisfy depend.m4 163313a12fdSmrg cygpath_u='sed s,\\\\,/,g' 164313a12fdSmrg depmode=msvc7 165313a12fdSmrgfi 166313a12fdSmrg 167313a12fdSmrgif test "$depmode" = xlc; then 168313a12fdSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169313a12fdSmrg gccflag=-qmakedep=gcc,-MF 170313a12fdSmrg depmode=gcc 17100084f2cSmrgfi 17200084f2cSmrg 17327702724Smrgcase "$depmode" in 17427702724Smrggcc3) 17527702724Smrg## gcc 3 implements dependency tracking that does exactly what 17627702724Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17727702724Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178e19dfac4Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179e19dfac4Smrg## the command line argument order; so add the flags where they 180e19dfac4Smrg## appear in depend2.am. Note that the slowdown incurred here 181e19dfac4Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182e19dfac4Smrg for arg 183e19dfac4Smrg do 184e19dfac4Smrg case $arg in 185e19dfac4Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186e19dfac4Smrg *) set fnord "$@" "$arg" ;; 187e19dfac4Smrg esac 188e19dfac4Smrg shift # fnord 189e19dfac4Smrg shift # $arg 190e19dfac4Smrg done 191e19dfac4Smrg "$@" 19227702724Smrg stat=$? 193313a12fdSmrg if test $stat -ne 0; then 19427702724Smrg rm -f "$tmpdepfile" 19527702724Smrg exit $stat 19627702724Smrg fi 19727702724Smrg mv "$tmpdepfile" "$depfile" 19827702724Smrg ;; 19927702724Smrg 20027702724Smrggcc) 201313a12fdSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202313a12fdSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203313a12fdSmrg## (see the conditional assignment to $gccflag above). 20427702724Smrg## There are various ways to get dependency output from gcc. Here's 20527702724Smrg## why we pick this rather obscure method: 20627702724Smrg## - Don't want to use -MD because we'd like the dependencies to end 20727702724Smrg## up in a subdir. Having to rename by hand is ugly. 20827702724Smrg## (We might end up doing this anyway to support other compilers.) 20927702724Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210313a12fdSmrg## -MM, not -M (despite what the docs say). Also, it might not be 211313a12fdSmrg## supported by the other compilers which use the 'gcc' depmode. 21227702724Smrg## - Using -M directly means running the compiler twice (even worse 21327702724Smrg## than renaming). 21427702724Smrg if test -z "$gccflag"; then 21527702724Smrg gccflag=-MD, 21627702724Smrg fi 21727702724Smrg "$@" -Wp,"$gccflag$tmpdepfile" 21827702724Smrg stat=$? 219313a12fdSmrg if test $stat -ne 0; then 22027702724Smrg rm -f "$tmpdepfile" 22127702724Smrg exit $stat 22227702724Smrg fi 22327702724Smrg rm -f "$depfile" 22427702724Smrg echo "$object : \\" > "$depfile" 225313a12fdSmrg # The second -e expression handles DOS-style file names with drive 226313a12fdSmrg # letters. 22727702724Smrg sed -e 's/^[^:]*: / /' \ 22827702724Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229313a12fdSmrg## This next piece of magic avoids the "deleted header file" problem. 23027702724Smrg## The problem is that when a header file which appears in a .P file 23127702724Smrg## is deleted, the dependency causes make to die (because there is 23227702724Smrg## typically no way to rebuild the header). We avoid this by adding 23327702724Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 23427702724Smrg## this for us directly. 235313a12fdSmrg## Some versions of gcc put a space before the ':'. On the theory 23627702724Smrg## that the space means something, we add a space to the output as 237313a12fdSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 238313a12fdSmrg## to the object. Take care to not repeat it in the output. 23927702724Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 24027702724Smrg## correctly. Breaking it into two sed invocations is a workaround. 241313a12fdSmrg tr ' ' "$nl" < "$tmpdepfile" \ 242313a12fdSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243313a12fdSmrg | sed -e 's/$/ :/' >> "$depfile" 24427702724Smrg rm -f "$tmpdepfile" 24527702724Smrg ;; 24627702724Smrg 24727702724Smrghp) 24827702724Smrg # This case exists only to let depend.m4 do its work. It works by 24927702724Smrg # looking at the text of this script. This case will never be run, 25027702724Smrg # since it is checked for above. 25127702724Smrg exit 1 25227702724Smrg ;; 25327702724Smrg 25427702724Smrgsgi) 25527702724Smrg if test "$libtool" = yes; then 25627702724Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25727702724Smrg else 25827702724Smrg "$@" -MDupdate "$tmpdepfile" 25927702724Smrg fi 26027702724Smrg stat=$? 261313a12fdSmrg if test $stat -ne 0; then 26227702724Smrg rm -f "$tmpdepfile" 26327702724Smrg exit $stat 26427702724Smrg fi 26527702724Smrg rm -f "$depfile" 26627702724Smrg 26727702724Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26827702724Smrg echo "$object : \\" > "$depfile" 26927702724Smrg # Clip off the initial element (the dependent). Don't try to be 27027702724Smrg # clever and replace this with sed code, as IRIX sed won't handle 27127702724Smrg # lines with more than a fixed number of characters (4096 in 27227702724Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273313a12fdSmrg # the IRIX cc adds comments like '#:fec' to the end of the 27427702724Smrg # dependency line. 275313a12fdSmrg tr ' ' "$nl" < "$tmpdepfile" \ 276313a12fdSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277313a12fdSmrg | tr "$nl" ' ' >> "$depfile" 27800084f2cSmrg echo >> "$depfile" 27927702724Smrg # The second pass generates a dummy entry for each header file. 280313a12fdSmrg tr ' ' "$nl" < "$tmpdepfile" \ 281313a12fdSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282313a12fdSmrg >> "$depfile" 28327702724Smrg else 284313a12fdSmrg make_dummy_depfile 28527702724Smrg fi 28627702724Smrg rm -f "$tmpdepfile" 28727702724Smrg ;; 28827702724Smrg 289313a12fdSmrgxlc) 290313a12fdSmrg # This case exists only to let depend.m4 do its work. It works by 291313a12fdSmrg # looking at the text of this script. This case will never be run, 292313a12fdSmrg # since it is checked for above. 293313a12fdSmrg exit 1 294313a12fdSmrg ;; 295313a12fdSmrg 29627702724Smrgaix) 29727702724Smrg # The C for AIX Compiler uses -M and outputs the dependencies 29827702724Smrg # in a .u file. In older versions, this file always lives in the 299313a12fdSmrg # current directory. Also, the AIX compiler puts '$object:' at the 30027702724Smrg # start of each line; $object doesn't have directory information. 30127702724Smrg # Version 6 uses the directory in both cases. 302313a12fdSmrg set_dir_from "$object" 303313a12fdSmrg set_base_from "$object" 30427702724Smrg if test "$libtool" = yes; then 305e19dfac4Smrg tmpdepfile1=$dir$base.u 306e19dfac4Smrg tmpdepfile2=$base.u 307e19dfac4Smrg tmpdepfile3=$dir.libs/$base.u 30827702724Smrg "$@" -Wc,-M 30927702724Smrg else 310e19dfac4Smrg tmpdepfile1=$dir$base.u 311e19dfac4Smrg tmpdepfile2=$dir$base.u 312e19dfac4Smrg tmpdepfile3=$dir$base.u 31327702724Smrg "$@" -M 31427702724Smrg fi 31527702724Smrg stat=$? 316313a12fdSmrg if test $stat -ne 0; then 317e19dfac4Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31827702724Smrg exit $stat 31927702724Smrg fi 32027702724Smrg 321e19dfac4Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322e19dfac4Smrg do 323e19dfac4Smrg test -f "$tmpdepfile" && break 324e19dfac4Smrg done 325313a12fdSmrg aix_post_process_depfile 326313a12fdSmrg ;; 327313a12fdSmrg 328313a12fdSmrgtcc) 329313a12fdSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330313a12fdSmrg # FIXME: That version still under development at the moment of writing. 331313a12fdSmrg # Make that this statement remains true also for stable, released 332313a12fdSmrg # versions. 333313a12fdSmrg # It will wrap lines (doesn't matter whether long or short) with a 334313a12fdSmrg # trailing '\', as in: 335313a12fdSmrg # 336313a12fdSmrg # foo.o : \ 337313a12fdSmrg # foo.c \ 338313a12fdSmrg # foo.h \ 339313a12fdSmrg # 340313a12fdSmrg # It will put a trailing '\' even on the last line, and will use leading 341313a12fdSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 342313a12fdSmrg # "Emit spaces for -MD"). 343313a12fdSmrg "$@" -MD -MF "$tmpdepfile" 344313a12fdSmrg stat=$? 345313a12fdSmrg if test $stat -ne 0; then 346313a12fdSmrg rm -f "$tmpdepfile" 347313a12fdSmrg exit $stat 34827702724Smrg fi 349313a12fdSmrg rm -f "$depfile" 350313a12fdSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351313a12fdSmrg # We have to change lines of the first kind to '$object: \'. 352313a12fdSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353313a12fdSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 354313a12fdSmrg # dummy dependency, to avoid the deleted-header problem. 355313a12fdSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35627702724Smrg rm -f "$tmpdepfile" 35727702724Smrg ;; 35827702724Smrg 359313a12fdSmrg## The order of this option in the case statement is important, since the 360313a12fdSmrg## shell code in configure will try each of these formats in the order 361313a12fdSmrg## listed in this file. A plain '-MD' option would be understood by many 362313a12fdSmrg## compilers, so we must ensure this comes after the gcc and icc options. 363313a12fdSmrgpgcc) 364313a12fdSmrg # Portland's C compiler understands '-MD'. 365313a12fdSmrg # Will always output deps to 'file.d' where file is the root name of the 366313a12fdSmrg # source file under compilation, even if file resides in a subdirectory. 367313a12fdSmrg # The object file name does not affect the name of the '.d' file. 368313a12fdSmrg # pgcc 10.2 will output 36927702724Smrg # foo.o: sub/foo.c sub/foo.h 370313a12fdSmrg # and will wrap long lines using '\' : 37127702724Smrg # foo.o: sub/foo.c ... \ 37227702724Smrg # sub/foo.h ... \ 37327702724Smrg # ... 374313a12fdSmrg set_dir_from "$object" 375313a12fdSmrg # Use the source, not the object, to determine the base name, since 376313a12fdSmrg # that's sadly what pgcc will do too. 377313a12fdSmrg set_base_from "$source" 378313a12fdSmrg tmpdepfile=$base.d 379313a12fdSmrg 380313a12fdSmrg # For projects that build the same source file twice into different object 381313a12fdSmrg # files, the pgcc approach of using the *source* file root name can cause 382313a12fdSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383313a12fdSmrg # the same $tmpdepfile. 384313a12fdSmrg lockdir=$base.d-lock 385313a12fdSmrg trap " 386313a12fdSmrg echo '$0: caught signal, cleaning up...' >&2 387313a12fdSmrg rmdir '$lockdir' 388313a12fdSmrg exit 1 389313a12fdSmrg " 1 2 13 15 390313a12fdSmrg numtries=100 391313a12fdSmrg i=$numtries 392313a12fdSmrg while test $i -gt 0; do 393313a12fdSmrg # mkdir is a portable test-and-set. 394313a12fdSmrg if mkdir "$lockdir" 2>/dev/null; then 395313a12fdSmrg # This process acquired the lock. 396313a12fdSmrg "$@" -MD 397313a12fdSmrg stat=$? 398313a12fdSmrg # Release the lock. 399313a12fdSmrg rmdir "$lockdir" 400313a12fdSmrg break 401313a12fdSmrg else 402313a12fdSmrg # If the lock is being held by a different process, wait 403313a12fdSmrg # until the winning process is done or we timeout. 404313a12fdSmrg while test -d "$lockdir" && test $i -gt 0; do 405313a12fdSmrg sleep 1 406313a12fdSmrg i=`expr $i - 1` 407313a12fdSmrg done 408313a12fdSmrg fi 409313a12fdSmrg i=`expr $i - 1` 410313a12fdSmrg done 411313a12fdSmrg trap - 1 2 13 15 412313a12fdSmrg if test $i -le 0; then 413313a12fdSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414313a12fdSmrg echo "$0: check lockdir '$lockdir'" >&2 415313a12fdSmrg exit 1 416313a12fdSmrg fi 41727702724Smrg 418313a12fdSmrg if test $stat -ne 0; then 41927702724Smrg rm -f "$tmpdepfile" 42027702724Smrg exit $stat 42127702724Smrg fi 42227702724Smrg rm -f "$depfile" 42327702724Smrg # Each line is of the form `foo.o: dependent.h', 42427702724Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42527702724Smrg # Do two passes, one to just change these to 42627702724Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 42727702724Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42827702724Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 42927702724Smrg # correctly. Breaking it into two sed invocations is a workaround. 430313a12fdSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431313a12fdSmrg | sed -e 's/$/ :/' >> "$depfile" 43227702724Smrg rm -f "$tmpdepfile" 43327702724Smrg ;; 43427702724Smrg 435e19dfac4Smrghp2) 436e19dfac4Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437e19dfac4Smrg # compilers, which have integrated preprocessors. The correct option 438e19dfac4Smrg # to use with these is +Maked; it writes dependencies to a file named 439e19dfac4Smrg # 'foo.d', which lands next to the object file, wherever that 440e19dfac4Smrg # happens to be. 441e19dfac4Smrg # Much of this is similar to the tru64 case; see comments there. 442313a12fdSmrg set_dir_from "$object" 443313a12fdSmrg set_base_from "$object" 444e19dfac4Smrg if test "$libtool" = yes; then 445e19dfac4Smrg tmpdepfile1=$dir$base.d 446e19dfac4Smrg tmpdepfile2=$dir.libs/$base.d 447e19dfac4Smrg "$@" -Wc,+Maked 448e19dfac4Smrg else 449e19dfac4Smrg tmpdepfile1=$dir$base.d 450e19dfac4Smrg tmpdepfile2=$dir$base.d 451e19dfac4Smrg "$@" +Maked 452e19dfac4Smrg fi 453e19dfac4Smrg stat=$? 454313a12fdSmrg if test $stat -ne 0; then 455e19dfac4Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456e19dfac4Smrg exit $stat 457e19dfac4Smrg fi 458e19dfac4Smrg 459e19dfac4Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460e19dfac4Smrg do 461e19dfac4Smrg test -f "$tmpdepfile" && break 462e19dfac4Smrg done 463e19dfac4Smrg if test -f "$tmpdepfile"; then 464313a12fdSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465313a12fdSmrg # Add 'dependent.h:' lines. 46600084f2cSmrg sed -ne '2,${ 467313a12fdSmrg s/^ *// 468313a12fdSmrg s/ \\*$// 469313a12fdSmrg s/$/:/ 470313a12fdSmrg p 471313a12fdSmrg }' "$tmpdepfile" >> "$depfile" 472e19dfac4Smrg else 473313a12fdSmrg make_dummy_depfile 474e19dfac4Smrg fi 475e19dfac4Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 476e19dfac4Smrg ;; 477e19dfac4Smrg 47827702724Smrgtru64) 479313a12fdSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 480313a12fdSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481313a12fdSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482313a12fdSmrg # dependencies in 'foo.d' instead, so we check for that too. 483313a12fdSmrg # Subdirectories are respected. 484313a12fdSmrg set_dir_from "$object" 485313a12fdSmrg set_base_from "$object" 486313a12fdSmrg 487313a12fdSmrg if test "$libtool" = yes; then 488313a12fdSmrg # Libtool generates 2 separate objects for the 2 libraries. These 489313a12fdSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 490313a12fdSmrg # in $dir$base.o.d. We have to check for both files, because 491313a12fdSmrg # one of the two compilations can be disabled. We should prefer 492313a12fdSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493313a12fdSmrg # automatically cleaned when .libs/ is deleted, while ignoring 494313a12fdSmrg # the former would cause a distcleancheck panic. 495313a12fdSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496313a12fdSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497313a12fdSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498313a12fdSmrg "$@" -Wc,-MD 499313a12fdSmrg else 500313a12fdSmrg tmpdepfile1=$dir$base.d 501313a12fdSmrg tmpdepfile2=$dir$base.d 502313a12fdSmrg tmpdepfile3=$dir$base.d 503313a12fdSmrg "$@" -MD 504313a12fdSmrg fi 505313a12fdSmrg 506313a12fdSmrg stat=$? 507313a12fdSmrg if test $stat -ne 0; then 508313a12fdSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509313a12fdSmrg exit $stat 510313a12fdSmrg fi 511313a12fdSmrg 512313a12fdSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513313a12fdSmrg do 514313a12fdSmrg test -f "$tmpdepfile" && break 515313a12fdSmrg done 516313a12fdSmrg # Same post-processing that is required for AIX mode. 517313a12fdSmrg aix_post_process_depfile 518313a12fdSmrg ;; 519313a12fdSmrg 520313a12fdSmrgmsvc7) 521313a12fdSmrg if test "$libtool" = yes; then 522313a12fdSmrg showIncludes=-Wc,-showIncludes 523313a12fdSmrg else 524313a12fdSmrg showIncludes=-showIncludes 525313a12fdSmrg fi 526313a12fdSmrg "$@" $showIncludes > "$tmpdepfile" 527313a12fdSmrg stat=$? 528313a12fdSmrg grep -v '^Note: including file: ' "$tmpdepfile" 529313a12fdSmrg if test $stat -ne 0; then 530313a12fdSmrg rm -f "$tmpdepfile" 531313a12fdSmrg exit $stat 532313a12fdSmrg fi 533313a12fdSmrg rm -f "$depfile" 534313a12fdSmrg echo "$object : \\" > "$depfile" 535313a12fdSmrg # The first sed program below extracts the file names and escapes 536313a12fdSmrg # backslashes for cygpath. The second sed program outputs the file 537313a12fdSmrg # name when reading, but also accumulates all include files in the 538313a12fdSmrg # hold buffer in order to output them again at the end. This only 539313a12fdSmrg # works with sed implementations that can handle large buffers. 540313a12fdSmrg sed < "$tmpdepfile" -n ' 541313a12fdSmrg/^Note: including file: *\(.*\)/ { 542313a12fdSmrg s//\1/ 543313a12fdSmrg s/\\/\\\\/g 544313a12fdSmrg p 545313a12fdSmrg}' | $cygpath_u | sort -u | sed -n ' 546313a12fdSmrgs/ /\\ /g 547313a12fdSmrgs/\(.*\)/'"$tab"'\1 \\/p 548313a12fdSmrgs/.\(.*\) \\/\1:/ 549313a12fdSmrgH 550313a12fdSmrg$ { 551313a12fdSmrg s/.*/'"$tab"'/ 552313a12fdSmrg G 553313a12fdSmrg p 554313a12fdSmrg}' >> "$depfile" 5557cea3689Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556313a12fdSmrg rm -f "$tmpdepfile" 557313a12fdSmrg ;; 558313a12fdSmrg 559313a12fdSmrgmsvc7msys) 560313a12fdSmrg # This case exists only to let depend.m4 do its work. It works by 561313a12fdSmrg # looking at the text of this script. This case will never be run, 562313a12fdSmrg # since it is checked for above. 563313a12fdSmrg exit 1 564313a12fdSmrg ;; 56527702724Smrg 56627702724Smrg#nosideeffect) 56727702724Smrg # This comment above is used by automake to tell side-effect 56827702724Smrg # dependency tracking mechanisms from slower ones. 56927702724Smrg 57027702724Smrgdashmstdout) 57127702724Smrg # Important note: in order to support this mode, a compiler *must* 57227702724Smrg # always write the preprocessed file to stdout, regardless of -o. 57327702724Smrg "$@" || exit $? 57427702724Smrg 57527702724Smrg # Remove the call to Libtool. 57627702724Smrg if test "$libtool" = yes; then 57700084f2cSmrg while test "X$1" != 'X--mode=compile'; do 57827702724Smrg shift 57927702724Smrg done 58027702724Smrg shift 58127702724Smrg fi 58227702724Smrg 583313a12fdSmrg # Remove '-o $object'. 58427702724Smrg IFS=" " 58527702724Smrg for arg 58627702724Smrg do 58727702724Smrg case $arg in 58827702724Smrg -o) 58927702724Smrg shift 59027702724Smrg ;; 59127702724Smrg $object) 59227702724Smrg shift 59327702724Smrg ;; 59427702724Smrg *) 59527702724Smrg set fnord "$@" "$arg" 59627702724Smrg shift # fnord 59727702724Smrg shift # $arg 59827702724Smrg ;; 59927702724Smrg esac 60027702724Smrg done 60127702724Smrg 60227702724Smrg test -z "$dashmflag" && dashmflag=-M 603313a12fdSmrg # Require at least two characters before searching for ':' 60427702724Smrg # in the target name. This is to cope with DOS-style filenames: 605313a12fdSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60627702724Smrg "$@" $dashmflag | 607313a12fdSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60827702724Smrg rm -f "$depfile" 60927702724Smrg cat < "$tmpdepfile" > "$depfile" 610313a12fdSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611313a12fdSmrg # correctly. Breaking it into two sed invocations is a workaround. 612313a12fdSmrg tr ' ' "$nl" < "$tmpdepfile" \ 613313a12fdSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614313a12fdSmrg | sed -e 's/$/ :/' >> "$depfile" 61527702724Smrg rm -f "$tmpdepfile" 61627702724Smrg ;; 61727702724Smrg 61827702724SmrgdashXmstdout) 61927702724Smrg # This case only exists to satisfy depend.m4. It is never actually 62027702724Smrg # run, as this mode is specially recognized in the preamble. 62127702724Smrg exit 1 62227702724Smrg ;; 62327702724Smrg 62427702724Smrgmakedepend) 62527702724Smrg "$@" || exit $? 62627702724Smrg # Remove any Libtool call 62727702724Smrg if test "$libtool" = yes; then 62800084f2cSmrg while test "X$1" != 'X--mode=compile'; do 62927702724Smrg shift 63027702724Smrg done 63127702724Smrg shift 63227702724Smrg fi 63327702724Smrg # X makedepend 63427702724Smrg shift 63500084f2cSmrg cleared=no eat=no 63600084f2cSmrg for arg 63700084f2cSmrg do 63827702724Smrg case $cleared in 63927702724Smrg no) 64027702724Smrg set ""; shift 64127702724Smrg cleared=yes ;; 64227702724Smrg esac 64300084f2cSmrg if test $eat = yes; then 64400084f2cSmrg eat=no 64500084f2cSmrg continue 64600084f2cSmrg fi 64727702724Smrg case "$arg" in 64827702724Smrg -D*|-I*) 64927702724Smrg set fnord "$@" "$arg"; shift ;; 65027702724Smrg # Strip any option that makedepend may not understand. Remove 65127702724Smrg # the object too, otherwise makedepend will parse it as a source file. 65200084f2cSmrg -arch) 65300084f2cSmrg eat=yes ;; 65427702724Smrg -*|$object) 65527702724Smrg ;; 65627702724Smrg *) 65727702724Smrg set fnord "$@" "$arg"; shift ;; 65827702724Smrg esac 65927702724Smrg done 66000084f2cSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66127702724Smrg touch "$tmpdepfile" 66227702724Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66327702724Smrg rm -f "$depfile" 664313a12fdSmrg # makedepend may prepend the VPATH from the source file name to the object. 665313a12fdSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 666313a12fdSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667313a12fdSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668313a12fdSmrg # correctly. Breaking it into two sed invocations is a workaround. 669313a12fdSmrg sed '1,2d' "$tmpdepfile" \ 670313a12fdSmrg | tr ' ' "$nl" \ 671313a12fdSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672313a12fdSmrg | sed -e 's/$/ :/' >> "$depfile" 67327702724Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67427702724Smrg ;; 67527702724Smrg 67627702724Smrgcpp) 67727702724Smrg # Important note: in order to support this mode, a compiler *must* 67827702724Smrg # always write the preprocessed file to stdout. 67927702724Smrg "$@" || exit $? 68027702724Smrg 68127702724Smrg # Remove the call to Libtool. 68227702724Smrg if test "$libtool" = yes; then 68300084f2cSmrg while test "X$1" != 'X--mode=compile'; do 68427702724Smrg shift 68527702724Smrg done 68627702724Smrg shift 68727702724Smrg fi 68827702724Smrg 689313a12fdSmrg # Remove '-o $object'. 69027702724Smrg IFS=" " 69127702724Smrg for arg 69227702724Smrg do 69327702724Smrg case $arg in 69427702724Smrg -o) 69527702724Smrg shift 69627702724Smrg ;; 69727702724Smrg $object) 69827702724Smrg shift 69927702724Smrg ;; 70027702724Smrg *) 70127702724Smrg set fnord "$@" "$arg" 70227702724Smrg shift # fnord 70327702724Smrg shift # $arg 70427702724Smrg ;; 70527702724Smrg esac 70627702724Smrg done 70727702724Smrg 708313a12fdSmrg "$@" -E \ 709313a12fdSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710313a12fdSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711313a12fdSmrg | sed '$ s: \\$::' > "$tmpdepfile" 71227702724Smrg rm -f "$depfile" 71327702724Smrg echo "$object : \\" > "$depfile" 71427702724Smrg cat < "$tmpdepfile" >> "$depfile" 71527702724Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71627702724Smrg rm -f "$tmpdepfile" 71727702724Smrg ;; 71827702724Smrg 71927702724Smrgmsvisualcpp) 72027702724Smrg # Important note: in order to support this mode, a compiler *must* 72100084f2cSmrg # always write the preprocessed file to stdout. 72227702724Smrg "$@" || exit $? 72300084f2cSmrg 72400084f2cSmrg # Remove the call to Libtool. 72500084f2cSmrg if test "$libtool" = yes; then 72600084f2cSmrg while test "X$1" != 'X--mode=compile'; do 72700084f2cSmrg shift 72800084f2cSmrg done 72900084f2cSmrg shift 73000084f2cSmrg fi 73100084f2cSmrg 73227702724Smrg IFS=" " 73327702724Smrg for arg 73427702724Smrg do 73527702724Smrg case "$arg" in 73600084f2cSmrg -o) 73700084f2cSmrg shift 73800084f2cSmrg ;; 73900084f2cSmrg $object) 74000084f2cSmrg shift 74100084f2cSmrg ;; 74227702724Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743313a12fdSmrg set fnord "$@" 744313a12fdSmrg shift 745313a12fdSmrg shift 746313a12fdSmrg ;; 74727702724Smrg *) 748313a12fdSmrg set fnord "$@" "$arg" 749313a12fdSmrg shift 750313a12fdSmrg shift 751313a12fdSmrg ;; 75227702724Smrg esac 75327702724Smrg done 75400084f2cSmrg "$@" -E 2>/dev/null | 75500084f2cSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75627702724Smrg rm -f "$depfile" 75727702724Smrg echo "$object : \\" > "$depfile" 758313a12fdSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759313a12fdSmrg echo "$tab" >> "$depfile" 76000084f2cSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76127702724Smrg rm -f "$tmpdepfile" 76227702724Smrg ;; 76327702724Smrg 76400084f2cSmrgmsvcmsys) 76500084f2cSmrg # This case exists only to let depend.m4 do its work. It works by 76600084f2cSmrg # looking at the text of this script. This case will never be run, 76700084f2cSmrg # since it is checked for above. 76800084f2cSmrg exit 1 76900084f2cSmrg ;; 77000084f2cSmrg 77127702724Smrgnone) 77227702724Smrg exec "$@" 77327702724Smrg ;; 77427702724Smrg 77527702724Smrg*) 77627702724Smrg echo "Unknown depmode $depmode" 1>&2 77727702724Smrg exit 1 77827702724Smrg ;; 77927702724Smrgesac 78027702724Smrg 78127702724Smrgexit 0 78227702724Smrg 78327702724Smrg# Local Variables: 78427702724Smrg# mode: shell-script 78527702724Smrg# sh-indentation: 2 78695b7a5c8Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 78727702724Smrg# time-stamp-start: "scriptversion=" 78827702724Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78995b7a5c8Smrg# time-stamp-time-zone: "UTC0" 79000084f2cSmrg# time-stamp-end: "; # UTC" 79127702724Smrg# End: 792