depcomp revision b41a30aa
1a253d6aeSmrg#! /bin/sh 2a253d6aeSmrg# depcomp - compile a program generating dependencies as side-effects 3a253d6aeSmrg 4b41a30aaSmrgscriptversion=2018-03-07.03; # UTC 5a253d6aeSmrg 6b41a30aaSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7a253d6aeSmrg 8a253d6aeSmrg# This program is free software; you can redistribute it and/or modify 9a253d6aeSmrg# it under the terms of the GNU General Public License as published by 10a253d6aeSmrg# the Free Software Foundation; either version 2, or (at your option) 11a253d6aeSmrg# any later version. 12a253d6aeSmrg 13a253d6aeSmrg# This program is distributed in the hope that it will be useful, 14a253d6aeSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15a253d6aeSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a253d6aeSmrg# GNU General Public License for more details. 17a253d6aeSmrg 18a253d6aeSmrg# You should have received a copy of the GNU General Public License 19b41a30aaSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20a253d6aeSmrg 21a253d6aeSmrg# As a special exception to the GNU General Public License, if you 22a253d6aeSmrg# distribute this file as part of a program that contains a 23a253d6aeSmrg# configuration script generated by Autoconf, you may include it under 24a253d6aeSmrg# the same distribution terms that you use for the rest of that program. 25a253d6aeSmrg 26a253d6aeSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27a253d6aeSmrg 28a253d6aeSmrgcase $1 in 29a253d6aeSmrg '') 3057ee1794Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3157ee1794Smrg exit 1; 3257ee1794Smrg ;; 33a253d6aeSmrg -h | --h*) 34a253d6aeSmrg cat <<\EOF 35a253d6aeSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36a253d6aeSmrg 37a253d6aeSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38a253d6aeSmrgas side-effects. 39a253d6aeSmrg 40a253d6aeSmrgEnvironment variables: 41a253d6aeSmrg depmode Dependency tracking mode. 4257ee1794Smrg source Source file read by 'PROGRAMS ARGS'. 4357ee1794Smrg object Object file output by 'PROGRAMS ARGS'. 44a253d6aeSmrg DEPDIR directory where to store dependencies. 45a253d6aeSmrg depfile Dependency file to output. 4657ee1794Smrg tmpdepfile Temporary file to use when outputting dependencies. 47a253d6aeSmrg libtool Whether libtool is used (yes/no). 48a253d6aeSmrg 49a253d6aeSmrgReport bugs to <bug-automake@gnu.org>. 50a253d6aeSmrgEOF 51a253d6aeSmrg exit $? 52a253d6aeSmrg ;; 53a253d6aeSmrg -v | --v*) 54a253d6aeSmrg echo "depcomp $scriptversion" 55a253d6aeSmrg exit $? 56a253d6aeSmrg ;; 57a253d6aeSmrgesac 58a253d6aeSmrg 5957ee1794Smrg# Get the directory component of the given path, and save it in the 6057ee1794Smrg# global variables '$dir'. Note that this directory component will 6157ee1794Smrg# be either empty or ending with a '/' character. This is deliberate. 6257ee1794Smrgset_dir_from () 6357ee1794Smrg{ 6457ee1794Smrg case $1 in 6557ee1794Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6657ee1794Smrg *) dir=;; 6757ee1794Smrg esac 6857ee1794Smrg} 6957ee1794Smrg 7057ee1794Smrg# Get the suffix-stripped basename of the given path, and save it the 7157ee1794Smrg# global variable '$base'. 7257ee1794Smrgset_base_from () 7357ee1794Smrg{ 7457ee1794Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7557ee1794Smrg} 7657ee1794Smrg 7757ee1794Smrg# If no dependency file was actually created by the compiler invocation, 7857ee1794Smrg# we still have to create a dummy depfile, to avoid errors with the 7957ee1794Smrg# Makefile "include basename.Plo" scheme. 8057ee1794Smrgmake_dummy_depfile () 8157ee1794Smrg{ 8257ee1794Smrg echo "#dummy" > "$depfile" 8357ee1794Smrg} 8457ee1794Smrg 8557ee1794Smrg# Factor out some common post-processing of the generated depfile. 8657ee1794Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8757ee1794Smrgaix_post_process_depfile () 8857ee1794Smrg{ 8957ee1794Smrg # If the compiler actually managed to produce a dependency file, 9057ee1794Smrg # post-process it. 9157ee1794Smrg if test -f "$tmpdepfile"; then 9257ee1794Smrg # Each line is of the form 'foo.o: dependency.h'. 9357ee1794Smrg # Do two passes, one to just change these to 9457ee1794Smrg # $object: dependency.h 9557ee1794Smrg # and one to simply output 9657ee1794Smrg # dependency.h: 9757ee1794Smrg # which is needed to avoid the deleted-header problem. 9857ee1794Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9957ee1794Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10057ee1794Smrg } > "$depfile" 10157ee1794Smrg rm -f "$tmpdepfile" 10257ee1794Smrg else 10357ee1794Smrg make_dummy_depfile 10457ee1794Smrg fi 10557ee1794Smrg} 10657ee1794Smrg 10757ee1794Smrg# A tabulation character. 10857ee1794Smrgtab=' ' 10957ee1794Smrg# A newline character. 11057ee1794Smrgnl=' 11157ee1794Smrg' 11257ee1794Smrg# Character ranges might be problematic outside the C locale. 11357ee1794Smrg# These definitions help. 11457ee1794Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11557ee1794Smrglower=abcdefghijklmnopqrstuvwxyz 11657ee1794Smrgdigits=0123456789 11757ee1794Smrgalpha=${upper}${lower} 11857ee1794Smrg 119a253d6aeSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120a253d6aeSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121a253d6aeSmrg exit 1 122a253d6aeSmrgfi 123a253d6aeSmrg 124a253d6aeSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125a253d6aeSmrgdepfile=${depfile-`echo "$object" | 126a253d6aeSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127a253d6aeSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128a253d6aeSmrg 129a253d6aeSmrgrm -f "$tmpdepfile" 130a253d6aeSmrg 13157ee1794Smrg# Avoid interferences from the environment. 13257ee1794Smrggccflag= dashmflag= 13357ee1794Smrg 134a253d6aeSmrg# Some modes work just like other modes, but use different flags. We 135a253d6aeSmrg# parameterize here, but still list the modes in the big case below, 136a253d6aeSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137a253d6aeSmrg# here, because this file can only contain one case statement. 138a253d6aeSmrgif test "$depmode" = hp; then 139a253d6aeSmrg # HP compiler uses -M and no extra arg. 140a253d6aeSmrg gccflag=-M 141a253d6aeSmrg depmode=gcc 142a253d6aeSmrgfi 143a253d6aeSmrg 144a253d6aeSmrgif test "$depmode" = dashXmstdout; then 14557ee1794Smrg # This is just like dashmstdout with a different argument. 14657ee1794Smrg dashmflag=-xM 14757ee1794Smrg depmode=dashmstdout 148a253d6aeSmrgfi 149a253d6aeSmrg 15025b89263Smrgcygpath_u="cygpath -u -f -" 15125b89263Smrgif test "$depmode" = msvcmsys; then 15257ee1794Smrg # This is just like msvisualcpp but w/o cygpath translation. 15357ee1794Smrg # Just convert the backslash-escaped backslashes to single forward 15457ee1794Smrg # slashes to satisfy depend.m4 15557ee1794Smrg cygpath_u='sed s,\\\\,/,g' 15657ee1794Smrg depmode=msvisualcpp 15757ee1794Smrgfi 15857ee1794Smrg 15957ee1794Smrgif test "$depmode" = msvc7msys; then 16057ee1794Smrg # This is just like msvc7 but w/o cygpath translation. 16157ee1794Smrg # Just convert the backslash-escaped backslashes to single forward 16257ee1794Smrg # slashes to satisfy depend.m4 16357ee1794Smrg cygpath_u='sed s,\\\\,/,g' 16457ee1794Smrg depmode=msvc7 16557ee1794Smrgfi 16657ee1794Smrg 16757ee1794Smrgif test "$depmode" = xlc; then 16857ee1794Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16957ee1794Smrg gccflag=-qmakedep=gcc,-MF 17057ee1794Smrg depmode=gcc 17125b89263Smrgfi 17225b89263Smrg 173a253d6aeSmrgcase "$depmode" in 174a253d6aeSmrggcc3) 175a253d6aeSmrg## gcc 3 implements dependency tracking that does exactly what 176a253d6aeSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177a253d6aeSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 178a253d6aeSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179a253d6aeSmrg## the command line argument order; so add the flags where they 180a253d6aeSmrg## appear in depend2.am. Note that the slowdown incurred here 181a253d6aeSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182a253d6aeSmrg for arg 183a253d6aeSmrg do 184a253d6aeSmrg case $arg in 185a253d6aeSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186a253d6aeSmrg *) set fnord "$@" "$arg" ;; 187a253d6aeSmrg esac 188a253d6aeSmrg shift # fnord 189a253d6aeSmrg shift # $arg 190a253d6aeSmrg done 191a253d6aeSmrg "$@" 192a253d6aeSmrg stat=$? 19357ee1794Smrg if test $stat -ne 0; then 194a253d6aeSmrg rm -f "$tmpdepfile" 195a253d6aeSmrg exit $stat 196a253d6aeSmrg fi 197a253d6aeSmrg mv "$tmpdepfile" "$depfile" 198a253d6aeSmrg ;; 199a253d6aeSmrg 200a253d6aeSmrggcc) 20157ee1794Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20257ee1794Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20357ee1794Smrg## (see the conditional assignment to $gccflag above). 204a253d6aeSmrg## There are various ways to get dependency output from gcc. Here's 205a253d6aeSmrg## why we pick this rather obscure method: 206a253d6aeSmrg## - Don't want to use -MD because we'd like the dependencies to end 207a253d6aeSmrg## up in a subdir. Having to rename by hand is ugly. 208a253d6aeSmrg## (We might end up doing this anyway to support other compilers.) 209a253d6aeSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21057ee1794Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21157ee1794Smrg## supported by the other compilers which use the 'gcc' depmode. 212a253d6aeSmrg## - Using -M directly means running the compiler twice (even worse 213a253d6aeSmrg## than renaming). 214a253d6aeSmrg if test -z "$gccflag"; then 215a253d6aeSmrg gccflag=-MD, 216a253d6aeSmrg fi 217a253d6aeSmrg "$@" -Wp,"$gccflag$tmpdepfile" 218a253d6aeSmrg stat=$? 21957ee1794Smrg if test $stat -ne 0; then 220a253d6aeSmrg rm -f "$tmpdepfile" 221a253d6aeSmrg exit $stat 222a253d6aeSmrg fi 223a253d6aeSmrg rm -f "$depfile" 224a253d6aeSmrg echo "$object : \\" > "$depfile" 22557ee1794Smrg # The second -e expression handles DOS-style file names with drive 22657ee1794Smrg # letters. 227a253d6aeSmrg sed -e 's/^[^:]*: / /' \ 228a253d6aeSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22957ee1794Smrg## This next piece of magic avoids the "deleted header file" problem. 230a253d6aeSmrg## The problem is that when a header file which appears in a .P file 231a253d6aeSmrg## is deleted, the dependency causes make to die (because there is 232a253d6aeSmrg## typically no way to rebuild the header). We avoid this by adding 233a253d6aeSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 234a253d6aeSmrg## this for us directly. 23557ee1794Smrg## Some versions of gcc put a space before the ':'. On the theory 236a253d6aeSmrg## that the space means something, we add a space to the output as 23757ee1794Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23857ee1794Smrg## to the object. Take care to not repeat it in the output. 239a253d6aeSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 240a253d6aeSmrg## correctly. Breaking it into two sed invocations is a workaround. 24157ee1794Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24257ee1794Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24357ee1794Smrg | sed -e 's/$/ :/' >> "$depfile" 244a253d6aeSmrg rm -f "$tmpdepfile" 245a253d6aeSmrg ;; 246a253d6aeSmrg 247a253d6aeSmrghp) 248a253d6aeSmrg # This case exists only to let depend.m4 do its work. It works by 249a253d6aeSmrg # looking at the text of this script. This case will never be run, 250a253d6aeSmrg # since it is checked for above. 251a253d6aeSmrg exit 1 252a253d6aeSmrg ;; 253a253d6aeSmrg 254a253d6aeSmrgsgi) 255a253d6aeSmrg if test "$libtool" = yes; then 256a253d6aeSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257a253d6aeSmrg else 258a253d6aeSmrg "$@" -MDupdate "$tmpdepfile" 259a253d6aeSmrg fi 260a253d6aeSmrg stat=$? 26157ee1794Smrg if test $stat -ne 0; then 262a253d6aeSmrg rm -f "$tmpdepfile" 263a253d6aeSmrg exit $stat 264a253d6aeSmrg fi 265a253d6aeSmrg rm -f "$depfile" 266a253d6aeSmrg 267a253d6aeSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268a253d6aeSmrg echo "$object : \\" > "$depfile" 269a253d6aeSmrg # Clip off the initial element (the dependent). Don't try to be 270a253d6aeSmrg # clever and replace this with sed code, as IRIX sed won't handle 271a253d6aeSmrg # lines with more than a fixed number of characters (4096 in 272a253d6aeSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27357ee1794Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274a253d6aeSmrg # dependency line. 27557ee1794Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27657ee1794Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27757ee1794Smrg | tr "$nl" ' ' >> "$depfile" 27825b89263Smrg echo >> "$depfile" 279a253d6aeSmrg # The second pass generates a dummy entry for each header file. 28057ee1794Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28157ee1794Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28257ee1794Smrg >> "$depfile" 283a253d6aeSmrg else 28457ee1794Smrg make_dummy_depfile 285a253d6aeSmrg fi 286a253d6aeSmrg rm -f "$tmpdepfile" 287a253d6aeSmrg ;; 288a253d6aeSmrg 28957ee1794Smrgxlc) 29057ee1794Smrg # This case exists only to let depend.m4 do its work. It works by 29157ee1794Smrg # looking at the text of this script. This case will never be run, 29257ee1794Smrg # since it is checked for above. 29357ee1794Smrg exit 1 29457ee1794Smrg ;; 29557ee1794Smrg 296a253d6aeSmrgaix) 297a253d6aeSmrg # The C for AIX Compiler uses -M and outputs the dependencies 298a253d6aeSmrg # in a .u file. In older versions, this file always lives in the 29957ee1794Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300a253d6aeSmrg # start of each line; $object doesn't have directory information. 301a253d6aeSmrg # Version 6 uses the directory in both cases. 30257ee1794Smrg set_dir_from "$object" 30357ee1794Smrg set_base_from "$object" 304a253d6aeSmrg if test "$libtool" = yes; then 305ea133fd7Smrg tmpdepfile1=$dir$base.u 306ea133fd7Smrg tmpdepfile2=$base.u 307ea133fd7Smrg tmpdepfile3=$dir.libs/$base.u 308a253d6aeSmrg "$@" -Wc,-M 309a253d6aeSmrg else 310ea133fd7Smrg tmpdepfile1=$dir$base.u 311ea133fd7Smrg tmpdepfile2=$dir$base.u 312ea133fd7Smrg tmpdepfile3=$dir$base.u 313a253d6aeSmrg "$@" -M 314a253d6aeSmrg fi 315a253d6aeSmrg stat=$? 31657ee1794Smrg if test $stat -ne 0; then 317ea133fd7Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318a253d6aeSmrg exit $stat 319a253d6aeSmrg fi 320a253d6aeSmrg 321ea133fd7Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322ea133fd7Smrg do 323ea133fd7Smrg test -f "$tmpdepfile" && break 324ea133fd7Smrg done 32557ee1794Smrg aix_post_process_depfile 32657ee1794Smrg ;; 32757ee1794Smrg 32857ee1794Smrgtcc) 32957ee1794Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33057ee1794Smrg # FIXME: That version still under development at the moment of writing. 33157ee1794Smrg # Make that this statement remains true also for stable, released 33257ee1794Smrg # versions. 33357ee1794Smrg # It will wrap lines (doesn't matter whether long or short) with a 33457ee1794Smrg # trailing '\', as in: 33557ee1794Smrg # 33657ee1794Smrg # foo.o : \ 33757ee1794Smrg # foo.c \ 33857ee1794Smrg # foo.h \ 33957ee1794Smrg # 34057ee1794Smrg # It will put a trailing '\' even on the last line, and will use leading 34157ee1794Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34257ee1794Smrg # "Emit spaces for -MD"). 34357ee1794Smrg "$@" -MD -MF "$tmpdepfile" 34457ee1794Smrg stat=$? 34557ee1794Smrg if test $stat -ne 0; then 34657ee1794Smrg rm -f "$tmpdepfile" 34757ee1794Smrg exit $stat 348a253d6aeSmrg fi 34957ee1794Smrg rm -f "$depfile" 35057ee1794Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35157ee1794Smrg # We have to change lines of the first kind to '$object: \'. 35257ee1794Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35357ee1794Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35457ee1794Smrg # dummy dependency, to avoid the deleted-header problem. 35557ee1794Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356a253d6aeSmrg rm -f "$tmpdepfile" 357a253d6aeSmrg ;; 358a253d6aeSmrg 35957ee1794Smrg## The order of this option in the case statement is important, since the 36057ee1794Smrg## shell code in configure will try each of these formats in the order 36157ee1794Smrg## listed in this file. A plain '-MD' option would be understood by many 36257ee1794Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36357ee1794Smrgpgcc) 36457ee1794Smrg # Portland's C compiler understands '-MD'. 36557ee1794Smrg # Will always output deps to 'file.d' where file is the root name of the 36657ee1794Smrg # source file under compilation, even if file resides in a subdirectory. 36757ee1794Smrg # The object file name does not affect the name of the '.d' file. 36857ee1794Smrg # pgcc 10.2 will output 369a253d6aeSmrg # foo.o: sub/foo.c sub/foo.h 37057ee1794Smrg # and will wrap long lines using '\' : 371a253d6aeSmrg # foo.o: sub/foo.c ... \ 372a253d6aeSmrg # sub/foo.h ... \ 373a253d6aeSmrg # ... 37457ee1794Smrg set_dir_from "$object" 37557ee1794Smrg # Use the source, not the object, to determine the base name, since 37657ee1794Smrg # that's sadly what pgcc will do too. 37757ee1794Smrg set_base_from "$source" 37857ee1794Smrg tmpdepfile=$base.d 37957ee1794Smrg 38057ee1794Smrg # For projects that build the same source file twice into different object 38157ee1794Smrg # files, the pgcc approach of using the *source* file root name can cause 38257ee1794Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38357ee1794Smrg # the same $tmpdepfile. 38457ee1794Smrg lockdir=$base.d-lock 38557ee1794Smrg trap " 38657ee1794Smrg echo '$0: caught signal, cleaning up...' >&2 38757ee1794Smrg rmdir '$lockdir' 38857ee1794Smrg exit 1 38957ee1794Smrg " 1 2 13 15 39057ee1794Smrg numtries=100 39157ee1794Smrg i=$numtries 39257ee1794Smrg while test $i -gt 0; do 39357ee1794Smrg # mkdir is a portable test-and-set. 39457ee1794Smrg if mkdir "$lockdir" 2>/dev/null; then 39557ee1794Smrg # This process acquired the lock. 39657ee1794Smrg "$@" -MD 39757ee1794Smrg stat=$? 39857ee1794Smrg # Release the lock. 39957ee1794Smrg rmdir "$lockdir" 40057ee1794Smrg break 40157ee1794Smrg else 40257ee1794Smrg # If the lock is being held by a different process, wait 40357ee1794Smrg # until the winning process is done or we timeout. 40457ee1794Smrg while test -d "$lockdir" && test $i -gt 0; do 40557ee1794Smrg sleep 1 40657ee1794Smrg i=`expr $i - 1` 40757ee1794Smrg done 40857ee1794Smrg fi 40957ee1794Smrg i=`expr $i - 1` 41057ee1794Smrg done 41157ee1794Smrg trap - 1 2 13 15 41257ee1794Smrg if test $i -le 0; then 41357ee1794Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41457ee1794Smrg echo "$0: check lockdir '$lockdir'" >&2 41557ee1794Smrg exit 1 41657ee1794Smrg fi 417a253d6aeSmrg 41857ee1794Smrg if test $stat -ne 0; then 419a253d6aeSmrg rm -f "$tmpdepfile" 420a253d6aeSmrg exit $stat 421a253d6aeSmrg fi 422a253d6aeSmrg rm -f "$depfile" 423a253d6aeSmrg # Each line is of the form `foo.o: dependent.h', 424a253d6aeSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425a253d6aeSmrg # Do two passes, one to just change these to 426a253d6aeSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427a253d6aeSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428a253d6aeSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429a253d6aeSmrg # correctly. Breaking it into two sed invocations is a workaround. 43057ee1794Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43157ee1794Smrg | sed -e 's/$/ :/' >> "$depfile" 432a253d6aeSmrg rm -f "$tmpdepfile" 433a253d6aeSmrg ;; 434a253d6aeSmrg 435a253d6aeSmrghp2) 436a253d6aeSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437a253d6aeSmrg # compilers, which have integrated preprocessors. The correct option 438a253d6aeSmrg # to use with these is +Maked; it writes dependencies to a file named 439a253d6aeSmrg # 'foo.d', which lands next to the object file, wherever that 440a253d6aeSmrg # happens to be. 441a253d6aeSmrg # Much of this is similar to the tru64 case; see comments there. 44257ee1794Smrg set_dir_from "$object" 44357ee1794Smrg set_base_from "$object" 444a253d6aeSmrg if test "$libtool" = yes; then 445a253d6aeSmrg tmpdepfile1=$dir$base.d 446a253d6aeSmrg tmpdepfile2=$dir.libs/$base.d 447a253d6aeSmrg "$@" -Wc,+Maked 448a253d6aeSmrg else 449a253d6aeSmrg tmpdepfile1=$dir$base.d 450a253d6aeSmrg tmpdepfile2=$dir$base.d 451a253d6aeSmrg "$@" +Maked 452a253d6aeSmrg fi 453a253d6aeSmrg stat=$? 45457ee1794Smrg if test $stat -ne 0; then 455a253d6aeSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456a253d6aeSmrg exit $stat 457a253d6aeSmrg fi 458a253d6aeSmrg 459a253d6aeSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460a253d6aeSmrg do 461a253d6aeSmrg test -f "$tmpdepfile" && break 462a253d6aeSmrg done 463a253d6aeSmrg if test -f "$tmpdepfile"; then 46457ee1794Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46557ee1794Smrg # Add 'dependent.h:' lines. 46625b89263Smrg sed -ne '2,${ 46757ee1794Smrg s/^ *// 46857ee1794Smrg s/ \\*$// 46957ee1794Smrg s/$/:/ 47057ee1794Smrg p 47157ee1794Smrg }' "$tmpdepfile" >> "$depfile" 472a253d6aeSmrg else 47357ee1794Smrg make_dummy_depfile 474a253d6aeSmrg fi 475a253d6aeSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 476a253d6aeSmrg ;; 477a253d6aeSmrg 478a253d6aeSmrgtru64) 47957ee1794Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48057ee1794Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48157ee1794Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48257ee1794Smrg # dependencies in 'foo.d' instead, so we check for that too. 48357ee1794Smrg # Subdirectories are respected. 48457ee1794Smrg set_dir_from "$object" 48557ee1794Smrg set_base_from "$object" 48657ee1794Smrg 48757ee1794Smrg if test "$libtool" = yes; then 48857ee1794Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48957ee1794Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49057ee1794Smrg # in $dir$base.o.d. We have to check for both files, because 49157ee1794Smrg # one of the two compilations can be disabled. We should prefer 49257ee1794Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49357ee1794Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49457ee1794Smrg # the former would cause a distcleancheck panic. 49557ee1794Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49657ee1794Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49757ee1794Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49857ee1794Smrg "$@" -Wc,-MD 49957ee1794Smrg else 50057ee1794Smrg tmpdepfile1=$dir$base.d 50157ee1794Smrg tmpdepfile2=$dir$base.d 50257ee1794Smrg tmpdepfile3=$dir$base.d 50357ee1794Smrg "$@" -MD 50457ee1794Smrg fi 50557ee1794Smrg 50657ee1794Smrg stat=$? 50757ee1794Smrg if test $stat -ne 0; then 50857ee1794Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50957ee1794Smrg exit $stat 51057ee1794Smrg fi 51157ee1794Smrg 51257ee1794Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51357ee1794Smrg do 51457ee1794Smrg test -f "$tmpdepfile" && break 51557ee1794Smrg done 51657ee1794Smrg # Same post-processing that is required for AIX mode. 51757ee1794Smrg aix_post_process_depfile 51857ee1794Smrg ;; 51957ee1794Smrg 52057ee1794Smrgmsvc7) 52157ee1794Smrg if test "$libtool" = yes; then 52257ee1794Smrg showIncludes=-Wc,-showIncludes 52357ee1794Smrg else 52457ee1794Smrg showIncludes=-showIncludes 52557ee1794Smrg fi 52657ee1794Smrg "$@" $showIncludes > "$tmpdepfile" 52757ee1794Smrg stat=$? 52857ee1794Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52957ee1794Smrg if test $stat -ne 0; then 53057ee1794Smrg rm -f "$tmpdepfile" 53157ee1794Smrg exit $stat 53257ee1794Smrg fi 53357ee1794Smrg rm -f "$depfile" 53457ee1794Smrg echo "$object : \\" > "$depfile" 53557ee1794Smrg # The first sed program below extracts the file names and escapes 53657ee1794Smrg # backslashes for cygpath. The second sed program outputs the file 53757ee1794Smrg # name when reading, but also accumulates all include files in the 53857ee1794Smrg # hold buffer in order to output them again at the end. This only 53957ee1794Smrg # works with sed implementations that can handle large buffers. 54057ee1794Smrg sed < "$tmpdepfile" -n ' 54157ee1794Smrg/^Note: including file: *\(.*\)/ { 54257ee1794Smrg s//\1/ 54357ee1794Smrg s/\\/\\\\/g 54457ee1794Smrg p 54557ee1794Smrg}' | $cygpath_u | sort -u | sed -n ' 54657ee1794Smrgs/ /\\ /g 54757ee1794Smrgs/\(.*\)/'"$tab"'\1 \\/p 54857ee1794Smrgs/.\(.*\) \\/\1:/ 54957ee1794SmrgH 55057ee1794Smrg$ { 55157ee1794Smrg s/.*/'"$tab"'/ 55257ee1794Smrg G 55357ee1794Smrg p 55457ee1794Smrg}' >> "$depfile" 55531637056Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55657ee1794Smrg rm -f "$tmpdepfile" 55757ee1794Smrg ;; 55857ee1794Smrg 55957ee1794Smrgmsvc7msys) 56057ee1794Smrg # This case exists only to let depend.m4 do its work. It works by 56157ee1794Smrg # looking at the text of this script. This case will never be run, 56257ee1794Smrg # since it is checked for above. 56357ee1794Smrg exit 1 56457ee1794Smrg ;; 565a253d6aeSmrg 566a253d6aeSmrg#nosideeffect) 567a253d6aeSmrg # This comment above is used by automake to tell side-effect 568a253d6aeSmrg # dependency tracking mechanisms from slower ones. 569a253d6aeSmrg 570a253d6aeSmrgdashmstdout) 571a253d6aeSmrg # Important note: in order to support this mode, a compiler *must* 572a253d6aeSmrg # always write the preprocessed file to stdout, regardless of -o. 573a253d6aeSmrg "$@" || exit $? 574a253d6aeSmrg 575a253d6aeSmrg # Remove the call to Libtool. 576a253d6aeSmrg if test "$libtool" = yes; then 57725b89263Smrg while test "X$1" != 'X--mode=compile'; do 578a253d6aeSmrg shift 579a253d6aeSmrg done 580a253d6aeSmrg shift 581a253d6aeSmrg fi 582a253d6aeSmrg 58357ee1794Smrg # Remove '-o $object'. 584a253d6aeSmrg IFS=" " 585a253d6aeSmrg for arg 586a253d6aeSmrg do 587a253d6aeSmrg case $arg in 588a253d6aeSmrg -o) 589a253d6aeSmrg shift 590a253d6aeSmrg ;; 591a253d6aeSmrg $object) 592a253d6aeSmrg shift 593a253d6aeSmrg ;; 594a253d6aeSmrg *) 595a253d6aeSmrg set fnord "$@" "$arg" 596a253d6aeSmrg shift # fnord 597a253d6aeSmrg shift # $arg 598a253d6aeSmrg ;; 599a253d6aeSmrg esac 600a253d6aeSmrg done 601a253d6aeSmrg 602a253d6aeSmrg test -z "$dashmflag" && dashmflag=-M 60357ee1794Smrg # Require at least two characters before searching for ':' 604a253d6aeSmrg # in the target name. This is to cope with DOS-style filenames: 60557ee1794Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606a253d6aeSmrg "$@" $dashmflag | 60757ee1794Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608a253d6aeSmrg rm -f "$depfile" 609a253d6aeSmrg cat < "$tmpdepfile" > "$depfile" 61057ee1794Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61157ee1794Smrg # correctly. Breaking it into two sed invocations is a workaround. 61257ee1794Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61357ee1794Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61457ee1794Smrg | sed -e 's/$/ :/' >> "$depfile" 615a253d6aeSmrg rm -f "$tmpdepfile" 616a253d6aeSmrg ;; 617a253d6aeSmrg 618a253d6aeSmrgdashXmstdout) 619a253d6aeSmrg # This case only exists to satisfy depend.m4. It is never actually 620a253d6aeSmrg # run, as this mode is specially recognized in the preamble. 621a253d6aeSmrg exit 1 622a253d6aeSmrg ;; 623a253d6aeSmrg 624a253d6aeSmrgmakedepend) 625a253d6aeSmrg "$@" || exit $? 626a253d6aeSmrg # Remove any Libtool call 627a253d6aeSmrg if test "$libtool" = yes; then 62825b89263Smrg while test "X$1" != 'X--mode=compile'; do 629a253d6aeSmrg shift 630a253d6aeSmrg done 631a253d6aeSmrg shift 632a253d6aeSmrg fi 633a253d6aeSmrg # X makedepend 634a253d6aeSmrg shift 63525b89263Smrg cleared=no eat=no 63625b89263Smrg for arg 63725b89263Smrg do 638a253d6aeSmrg case $cleared in 639a253d6aeSmrg no) 640a253d6aeSmrg set ""; shift 641a253d6aeSmrg cleared=yes ;; 642a253d6aeSmrg esac 64325b89263Smrg if test $eat = yes; then 64425b89263Smrg eat=no 64525b89263Smrg continue 64625b89263Smrg fi 647a253d6aeSmrg case "$arg" in 648a253d6aeSmrg -D*|-I*) 649a253d6aeSmrg set fnord "$@" "$arg"; shift ;; 650a253d6aeSmrg # Strip any option that makedepend may not understand. Remove 651a253d6aeSmrg # the object too, otherwise makedepend will parse it as a source file. 65225b89263Smrg -arch) 65325b89263Smrg eat=yes ;; 654a253d6aeSmrg -*|$object) 655a253d6aeSmrg ;; 656a253d6aeSmrg *) 657a253d6aeSmrg set fnord "$@" "$arg"; shift ;; 658a253d6aeSmrg esac 659a253d6aeSmrg done 66025b89263Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661a253d6aeSmrg touch "$tmpdepfile" 662a253d6aeSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663a253d6aeSmrg rm -f "$depfile" 66457ee1794Smrg # makedepend may prepend the VPATH from the source file name to the object. 66557ee1794Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66657ee1794Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66757ee1794Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66857ee1794Smrg # correctly. Breaking it into two sed invocations is a workaround. 66957ee1794Smrg sed '1,2d' "$tmpdepfile" \ 67057ee1794Smrg | tr ' ' "$nl" \ 67157ee1794Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67257ee1794Smrg | sed -e 's/$/ :/' >> "$depfile" 673a253d6aeSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674a253d6aeSmrg ;; 675a253d6aeSmrg 676a253d6aeSmrgcpp) 677a253d6aeSmrg # Important note: in order to support this mode, a compiler *must* 678a253d6aeSmrg # always write the preprocessed file to stdout. 679a253d6aeSmrg "$@" || exit $? 680a253d6aeSmrg 681a253d6aeSmrg # Remove the call to Libtool. 682a253d6aeSmrg if test "$libtool" = yes; then 68325b89263Smrg while test "X$1" != 'X--mode=compile'; do 684a253d6aeSmrg shift 685a253d6aeSmrg done 686a253d6aeSmrg shift 687a253d6aeSmrg fi 688a253d6aeSmrg 68957ee1794Smrg # Remove '-o $object'. 690a253d6aeSmrg IFS=" " 691a253d6aeSmrg for arg 692a253d6aeSmrg do 693a253d6aeSmrg case $arg in 694a253d6aeSmrg -o) 695a253d6aeSmrg shift 696a253d6aeSmrg ;; 697a253d6aeSmrg $object) 698a253d6aeSmrg shift 699a253d6aeSmrg ;; 700a253d6aeSmrg *) 701a253d6aeSmrg set fnord "$@" "$arg" 702a253d6aeSmrg shift # fnord 703a253d6aeSmrg shift # $arg 704a253d6aeSmrg ;; 705a253d6aeSmrg esac 706a253d6aeSmrg done 707a253d6aeSmrg 70857ee1794Smrg "$@" -E \ 70957ee1794Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71057ee1794Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71157ee1794Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712a253d6aeSmrg rm -f "$depfile" 713a253d6aeSmrg echo "$object : \\" > "$depfile" 714a253d6aeSmrg cat < "$tmpdepfile" >> "$depfile" 715a253d6aeSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716a253d6aeSmrg rm -f "$tmpdepfile" 717a253d6aeSmrg ;; 718a253d6aeSmrg 719a253d6aeSmrgmsvisualcpp) 720a253d6aeSmrg # Important note: in order to support this mode, a compiler *must* 72125b89263Smrg # always write the preprocessed file to stdout. 722a253d6aeSmrg "$@" || exit $? 72325b89263Smrg 72425b89263Smrg # Remove the call to Libtool. 72525b89263Smrg if test "$libtool" = yes; then 72625b89263Smrg while test "X$1" != 'X--mode=compile'; do 72725b89263Smrg shift 72825b89263Smrg done 72925b89263Smrg shift 73025b89263Smrg fi 73125b89263Smrg 732a253d6aeSmrg IFS=" " 733a253d6aeSmrg for arg 734a253d6aeSmrg do 735a253d6aeSmrg case "$arg" in 73625b89263Smrg -o) 73725b89263Smrg shift 73825b89263Smrg ;; 73925b89263Smrg $object) 74025b89263Smrg shift 74125b89263Smrg ;; 742a253d6aeSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74357ee1794Smrg set fnord "$@" 74457ee1794Smrg shift 74557ee1794Smrg shift 74657ee1794Smrg ;; 747a253d6aeSmrg *) 74857ee1794Smrg set fnord "$@" "$arg" 74957ee1794Smrg shift 75057ee1794Smrg shift 75157ee1794Smrg ;; 752a253d6aeSmrg esac 753a253d6aeSmrg done 75425b89263Smrg "$@" -E 2>/dev/null | 75525b89263Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756a253d6aeSmrg rm -f "$depfile" 757a253d6aeSmrg echo "$object : \\" > "$depfile" 75857ee1794Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75957ee1794Smrg echo "$tab" >> "$depfile" 76025b89263Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761a253d6aeSmrg rm -f "$tmpdepfile" 762a253d6aeSmrg ;; 763a253d6aeSmrg 76425b89263Smrgmsvcmsys) 76525b89263Smrg # This case exists only to let depend.m4 do its work. It works by 76625b89263Smrg # looking at the text of this script. This case will never be run, 76725b89263Smrg # since it is checked for above. 76825b89263Smrg exit 1 76925b89263Smrg ;; 77025b89263Smrg 771a253d6aeSmrgnone) 772a253d6aeSmrg exec "$@" 773a253d6aeSmrg ;; 774a253d6aeSmrg 775a253d6aeSmrg*) 776a253d6aeSmrg echo "Unknown depmode $depmode" 1>&2 777a253d6aeSmrg exit 1 778a253d6aeSmrg ;; 779a253d6aeSmrgesac 780a253d6aeSmrg 781a253d6aeSmrgexit 0 782a253d6aeSmrg 783a253d6aeSmrg# Local Variables: 784a253d6aeSmrg# mode: shell-script 785a253d6aeSmrg# sh-indentation: 2 786b41a30aaSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 787a253d6aeSmrg# time-stamp-start: "scriptversion=" 788a253d6aeSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789b41a30aaSmrg# time-stamp-time-zone: "UTC0" 79025b89263Smrg# time-stamp-end: "; # UTC" 791a253d6aeSmrg# End: 792