depcomp revision 25dbecb6
16df26cacSmrg#! /bin/sh 26df26cacSmrg# depcomp - compile a program generating dependencies as side-effects 36df26cacSmrg 425dbecb6Smrgscriptversion=2018-03-07.03; # UTC 56df26cacSmrg 625dbecb6Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 76df26cacSmrg 86df26cacSmrg# This program is free software; you can redistribute it and/or modify 96df26cacSmrg# it under the terms of the GNU General Public License as published by 106df26cacSmrg# the Free Software Foundation; either version 2, or (at your option) 116df26cacSmrg# any later version. 126df26cacSmrg 136df26cacSmrg# This program is distributed in the hope that it will be useful, 146df26cacSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 156df26cacSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 166df26cacSmrg# GNU General Public License for more details. 176df26cacSmrg 186df26cacSmrg# You should have received a copy of the GNU General Public License 1925dbecb6Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 206df26cacSmrg 216df26cacSmrg# As a special exception to the GNU General Public License, if you 226df26cacSmrg# distribute this file as part of a program that contains a 236df26cacSmrg# configuration script generated by Autoconf, you may include it under 246df26cacSmrg# the same distribution terms that you use for the rest of that program. 256df26cacSmrg 266df26cacSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 276df26cacSmrg 286df26cacSmrgcase $1 in 296df26cacSmrg '') 3025dbecb6Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3125dbecb6Smrg exit 1; 3225dbecb6Smrg ;; 336df26cacSmrg -h | --h*) 346df26cacSmrg cat <<\EOF 356df26cacSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 366df26cacSmrg 376df26cacSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 386df26cacSmrgas side-effects. 396df26cacSmrg 406df26cacSmrgEnvironment variables: 416df26cacSmrg depmode Dependency tracking mode. 4225dbecb6Smrg source Source file read by 'PROGRAMS ARGS'. 4325dbecb6Smrg object Object file output by 'PROGRAMS ARGS'. 446df26cacSmrg DEPDIR directory where to store dependencies. 456df26cacSmrg depfile Dependency file to output. 4625dbecb6Smrg tmpdepfile Temporary file to use when outputting dependencies. 476df26cacSmrg libtool Whether libtool is used (yes/no). 486df26cacSmrg 496df26cacSmrgReport bugs to <bug-automake@gnu.org>. 506df26cacSmrgEOF 516df26cacSmrg exit $? 526df26cacSmrg ;; 536df26cacSmrg -v | --v*) 546df26cacSmrg echo "depcomp $scriptversion" 556df26cacSmrg exit $? 566df26cacSmrg ;; 576df26cacSmrgesac 586df26cacSmrg 5925dbecb6Smrg# Get the directory component of the given path, and save it in the 6025dbecb6Smrg# global variables '$dir'. Note that this directory component will 6125dbecb6Smrg# be either empty or ending with a '/' character. This is deliberate. 6225dbecb6Smrgset_dir_from () 6325dbecb6Smrg{ 6425dbecb6Smrg case $1 in 6525dbecb6Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6625dbecb6Smrg *) dir=;; 6725dbecb6Smrg esac 6825dbecb6Smrg} 6925dbecb6Smrg 7025dbecb6Smrg# Get the suffix-stripped basename of the given path, and save it the 7125dbecb6Smrg# global variable '$base'. 7225dbecb6Smrgset_base_from () 7325dbecb6Smrg{ 7425dbecb6Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7525dbecb6Smrg} 7625dbecb6Smrg 7725dbecb6Smrg# If no dependency file was actually created by the compiler invocation, 7825dbecb6Smrg# we still have to create a dummy depfile, to avoid errors with the 7925dbecb6Smrg# Makefile "include basename.Plo" scheme. 8025dbecb6Smrgmake_dummy_depfile () 8125dbecb6Smrg{ 8225dbecb6Smrg echo "#dummy" > "$depfile" 8325dbecb6Smrg} 8425dbecb6Smrg 8525dbecb6Smrg# Factor out some common post-processing of the generated depfile. 8625dbecb6Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8725dbecb6Smrgaix_post_process_depfile () 8825dbecb6Smrg{ 8925dbecb6Smrg # If the compiler actually managed to produce a dependency file, 9025dbecb6Smrg # post-process it. 9125dbecb6Smrg if test -f "$tmpdepfile"; then 9225dbecb6Smrg # Each line is of the form 'foo.o: dependency.h'. 9325dbecb6Smrg # Do two passes, one to just change these to 9425dbecb6Smrg # $object: dependency.h 9525dbecb6Smrg # and one to simply output 9625dbecb6Smrg # dependency.h: 9725dbecb6Smrg # which is needed to avoid the deleted-header problem. 9825dbecb6Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9925dbecb6Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10025dbecb6Smrg } > "$depfile" 10125dbecb6Smrg rm -f "$tmpdepfile" 10225dbecb6Smrg else 10325dbecb6Smrg make_dummy_depfile 10425dbecb6Smrg fi 10525dbecb6Smrg} 10625dbecb6Smrg 10725dbecb6Smrg# A tabulation character. 10825dbecb6Smrgtab=' ' 10925dbecb6Smrg# A newline character. 11025dbecb6Smrgnl=' 11125dbecb6Smrg' 11225dbecb6Smrg# Character ranges might be problematic outside the C locale. 11325dbecb6Smrg# These definitions help. 11425dbecb6Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11525dbecb6Smrglower=abcdefghijklmnopqrstuvwxyz 11625dbecb6Smrgdigits=0123456789 11725dbecb6Smrgalpha=${upper}${lower} 11825dbecb6Smrg 1196df26cacSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1206df26cacSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1216df26cacSmrg exit 1 1226df26cacSmrgfi 1236df26cacSmrg 1246df26cacSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1256df26cacSmrgdepfile=${depfile-`echo "$object" | 1266df26cacSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1276df26cacSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1286df26cacSmrg 1296df26cacSmrgrm -f "$tmpdepfile" 1306df26cacSmrg 13125dbecb6Smrg# Avoid interferences from the environment. 13225dbecb6Smrggccflag= dashmflag= 13325dbecb6Smrg 1346df26cacSmrg# Some modes work just like other modes, but use different flags. We 1356df26cacSmrg# parameterize here, but still list the modes in the big case below, 1366df26cacSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1376df26cacSmrg# here, because this file can only contain one case statement. 1386df26cacSmrgif test "$depmode" = hp; then 1396df26cacSmrg # HP compiler uses -M and no extra arg. 1406df26cacSmrg gccflag=-M 1416df26cacSmrg depmode=gcc 1426df26cacSmrgfi 1436df26cacSmrg 1446df26cacSmrgif test "$depmode" = dashXmstdout; then 14525dbecb6Smrg # This is just like dashmstdout with a different argument. 14625dbecb6Smrg dashmflag=-xM 14725dbecb6Smrg depmode=dashmstdout 14825dbecb6Smrgfi 14925dbecb6Smrg 15025dbecb6Smrgcygpath_u="cygpath -u -f -" 15125dbecb6Smrgif test "$depmode" = msvcmsys; then 15225dbecb6Smrg # This is just like msvisualcpp but w/o cygpath translation. 15325dbecb6Smrg # Just convert the backslash-escaped backslashes to single forward 15425dbecb6Smrg # slashes to satisfy depend.m4 15525dbecb6Smrg cygpath_u='sed s,\\\\,/,g' 15625dbecb6Smrg depmode=msvisualcpp 15725dbecb6Smrgfi 15825dbecb6Smrg 15925dbecb6Smrgif test "$depmode" = msvc7msys; then 16025dbecb6Smrg # This is just like msvc7 but w/o cygpath translation. 16125dbecb6Smrg # Just convert the backslash-escaped backslashes to single forward 16225dbecb6Smrg # slashes to satisfy depend.m4 16325dbecb6Smrg cygpath_u='sed s,\\\\,/,g' 16425dbecb6Smrg depmode=msvc7 16525dbecb6Smrgfi 16625dbecb6Smrg 16725dbecb6Smrgif test "$depmode" = xlc; then 16825dbecb6Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16925dbecb6Smrg gccflag=-qmakedep=gcc,-MF 17025dbecb6Smrg depmode=gcc 1716df26cacSmrgfi 1726df26cacSmrg 1736df26cacSmrgcase "$depmode" in 1746df26cacSmrggcc3) 1756df26cacSmrg## gcc 3 implements dependency tracking that does exactly what 1766df26cacSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1776df26cacSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 178b68e1f86Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179b68e1f86Smrg## the command line argument order; so add the flags where they 180b68e1f86Smrg## appear in depend2.am. Note that the slowdown incurred here 181b68e1f86Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182b68e1f86Smrg for arg 183b68e1f86Smrg do 184b68e1f86Smrg case $arg in 185b68e1f86Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186b68e1f86Smrg *) set fnord "$@" "$arg" ;; 187b68e1f86Smrg esac 188b68e1f86Smrg shift # fnord 189b68e1f86Smrg shift # $arg 190b68e1f86Smrg done 191b68e1f86Smrg "$@" 1926df26cacSmrg stat=$? 19325dbecb6Smrg if test $stat -ne 0; then 1946df26cacSmrg rm -f "$tmpdepfile" 1956df26cacSmrg exit $stat 1966df26cacSmrg fi 1976df26cacSmrg mv "$tmpdepfile" "$depfile" 1986df26cacSmrg ;; 1996df26cacSmrg 2006df26cacSmrggcc) 20125dbecb6Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20225dbecb6Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20325dbecb6Smrg## (see the conditional assignment to $gccflag above). 2046df26cacSmrg## There are various ways to get dependency output from gcc. Here's 2056df26cacSmrg## why we pick this rather obscure method: 2066df26cacSmrg## - Don't want to use -MD because we'd like the dependencies to end 2076df26cacSmrg## up in a subdir. Having to rename by hand is ugly. 2086df26cacSmrg## (We might end up doing this anyway to support other compilers.) 2096df26cacSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21025dbecb6Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21125dbecb6Smrg## supported by the other compilers which use the 'gcc' depmode. 2126df26cacSmrg## - Using -M directly means running the compiler twice (even worse 2136df26cacSmrg## than renaming). 2146df26cacSmrg if test -z "$gccflag"; then 2156df26cacSmrg gccflag=-MD, 2166df26cacSmrg fi 2176df26cacSmrg "$@" -Wp,"$gccflag$tmpdepfile" 2186df26cacSmrg stat=$? 21925dbecb6Smrg if test $stat -ne 0; then 2206df26cacSmrg rm -f "$tmpdepfile" 2216df26cacSmrg exit $stat 2226df26cacSmrg fi 2236df26cacSmrg rm -f "$depfile" 2246df26cacSmrg echo "$object : \\" > "$depfile" 22525dbecb6Smrg # The second -e expression handles DOS-style file names with drive 22625dbecb6Smrg # letters. 2276df26cacSmrg sed -e 's/^[^:]*: / /' \ 2286df26cacSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22925dbecb6Smrg## This next piece of magic avoids the "deleted header file" problem. 2306df26cacSmrg## The problem is that when a header file which appears in a .P file 2316df26cacSmrg## is deleted, the dependency causes make to die (because there is 2326df26cacSmrg## typically no way to rebuild the header). We avoid this by adding 2336df26cacSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 2346df26cacSmrg## this for us directly. 23525dbecb6Smrg## Some versions of gcc put a space before the ':'. On the theory 2366df26cacSmrg## that the space means something, we add a space to the output as 23725dbecb6Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23825dbecb6Smrg## to the object. Take care to not repeat it in the output. 2396df26cacSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 2406df26cacSmrg## correctly. Breaking it into two sed invocations is a workaround. 24125dbecb6Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24225dbecb6Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24325dbecb6Smrg | sed -e 's/$/ :/' >> "$depfile" 2446df26cacSmrg rm -f "$tmpdepfile" 2456df26cacSmrg ;; 2466df26cacSmrg 2476df26cacSmrghp) 2486df26cacSmrg # This case exists only to let depend.m4 do its work. It works by 2496df26cacSmrg # looking at the text of this script. This case will never be run, 2506df26cacSmrg # since it is checked for above. 2516df26cacSmrg exit 1 2526df26cacSmrg ;; 2536df26cacSmrg 2546df26cacSmrgsgi) 2556df26cacSmrg if test "$libtool" = yes; then 2566df26cacSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2576df26cacSmrg else 2586df26cacSmrg "$@" -MDupdate "$tmpdepfile" 2596df26cacSmrg fi 2606df26cacSmrg stat=$? 26125dbecb6Smrg if test $stat -ne 0; then 2626df26cacSmrg rm -f "$tmpdepfile" 2636df26cacSmrg exit $stat 2646df26cacSmrg fi 2656df26cacSmrg rm -f "$depfile" 2666df26cacSmrg 2676df26cacSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2686df26cacSmrg echo "$object : \\" > "$depfile" 2696df26cacSmrg # Clip off the initial element (the dependent). Don't try to be 2706df26cacSmrg # clever and replace this with sed code, as IRIX sed won't handle 2716df26cacSmrg # lines with more than a fixed number of characters (4096 in 2726df26cacSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27325dbecb6Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2746df26cacSmrg # dependency line. 27525dbecb6Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27625dbecb6Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27725dbecb6Smrg | tr "$nl" ' ' >> "$depfile" 27825dbecb6Smrg echo >> "$depfile" 2796df26cacSmrg # The second pass generates a dummy entry for each header file. 28025dbecb6Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28125dbecb6Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28225dbecb6Smrg >> "$depfile" 2836df26cacSmrg else 28425dbecb6Smrg make_dummy_depfile 2856df26cacSmrg fi 2866df26cacSmrg rm -f "$tmpdepfile" 2876df26cacSmrg ;; 2886df26cacSmrg 28925dbecb6Smrgxlc) 29025dbecb6Smrg # This case exists only to let depend.m4 do its work. It works by 29125dbecb6Smrg # looking at the text of this script. This case will never be run, 29225dbecb6Smrg # since it is checked for above. 29325dbecb6Smrg exit 1 29425dbecb6Smrg ;; 29525dbecb6Smrg 2966df26cacSmrgaix) 2976df26cacSmrg # The C for AIX Compiler uses -M and outputs the dependencies 2986df26cacSmrg # in a .u file. In older versions, this file always lives in the 29925dbecb6Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3006df26cacSmrg # start of each line; $object doesn't have directory information. 3016df26cacSmrg # Version 6 uses the directory in both cases. 30225dbecb6Smrg set_dir_from "$object" 30325dbecb6Smrg set_base_from "$object" 3046df26cacSmrg if test "$libtool" = yes; then 305b68e1f86Smrg tmpdepfile1=$dir$base.u 306b68e1f86Smrg tmpdepfile2=$base.u 307b68e1f86Smrg tmpdepfile3=$dir.libs/$base.u 3086df26cacSmrg "$@" -Wc,-M 3096df26cacSmrg else 310b68e1f86Smrg tmpdepfile1=$dir$base.u 311b68e1f86Smrg tmpdepfile2=$dir$base.u 312b68e1f86Smrg tmpdepfile3=$dir$base.u 3136df26cacSmrg "$@" -M 3146df26cacSmrg fi 3156df26cacSmrg stat=$? 31625dbecb6Smrg if test $stat -ne 0; then 317b68e1f86Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3186df26cacSmrg exit $stat 3196df26cacSmrg fi 3206df26cacSmrg 321b68e1f86Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322b68e1f86Smrg do 323b68e1f86Smrg test -f "$tmpdepfile" && break 324b68e1f86Smrg done 32525dbecb6Smrg aix_post_process_depfile 32625dbecb6Smrg ;; 32725dbecb6Smrg 32825dbecb6Smrgtcc) 32925dbecb6Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33025dbecb6Smrg # FIXME: That version still under development at the moment of writing. 33125dbecb6Smrg # Make that this statement remains true also for stable, released 33225dbecb6Smrg # versions. 33325dbecb6Smrg # It will wrap lines (doesn't matter whether long or short) with a 33425dbecb6Smrg # trailing '\', as in: 33525dbecb6Smrg # 33625dbecb6Smrg # foo.o : \ 33725dbecb6Smrg # foo.c \ 33825dbecb6Smrg # foo.h \ 33925dbecb6Smrg # 34025dbecb6Smrg # It will put a trailing '\' even on the last line, and will use leading 34125dbecb6Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34225dbecb6Smrg # "Emit spaces for -MD"). 34325dbecb6Smrg "$@" -MD -MF "$tmpdepfile" 34425dbecb6Smrg stat=$? 34525dbecb6Smrg if test $stat -ne 0; then 34625dbecb6Smrg rm -f "$tmpdepfile" 34725dbecb6Smrg exit $stat 3486df26cacSmrg fi 34925dbecb6Smrg rm -f "$depfile" 35025dbecb6Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35125dbecb6Smrg # We have to change lines of the first kind to '$object: \'. 35225dbecb6Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35325dbecb6Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35425dbecb6Smrg # dummy dependency, to avoid the deleted-header problem. 35525dbecb6Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3566df26cacSmrg rm -f "$tmpdepfile" 3576df26cacSmrg ;; 3586df26cacSmrg 35925dbecb6Smrg## The order of this option in the case statement is important, since the 36025dbecb6Smrg## shell code in configure will try each of these formats in the order 36125dbecb6Smrg## listed in this file. A plain '-MD' option would be understood by many 36225dbecb6Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36325dbecb6Smrgpgcc) 36425dbecb6Smrg # Portland's C compiler understands '-MD'. 36525dbecb6Smrg # Will always output deps to 'file.d' where file is the root name of the 36625dbecb6Smrg # source file under compilation, even if file resides in a subdirectory. 36725dbecb6Smrg # The object file name does not affect the name of the '.d' file. 36825dbecb6Smrg # pgcc 10.2 will output 3696df26cacSmrg # foo.o: sub/foo.c sub/foo.h 37025dbecb6Smrg # and will wrap long lines using '\' : 3716df26cacSmrg # foo.o: sub/foo.c ... \ 3726df26cacSmrg # sub/foo.h ... \ 3736df26cacSmrg # ... 37425dbecb6Smrg set_dir_from "$object" 37525dbecb6Smrg # Use the source, not the object, to determine the base name, since 37625dbecb6Smrg # that's sadly what pgcc will do too. 37725dbecb6Smrg set_base_from "$source" 37825dbecb6Smrg tmpdepfile=$base.d 37925dbecb6Smrg 38025dbecb6Smrg # For projects that build the same source file twice into different object 38125dbecb6Smrg # files, the pgcc approach of using the *source* file root name can cause 38225dbecb6Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38325dbecb6Smrg # the same $tmpdepfile. 38425dbecb6Smrg lockdir=$base.d-lock 38525dbecb6Smrg trap " 38625dbecb6Smrg echo '$0: caught signal, cleaning up...' >&2 38725dbecb6Smrg rmdir '$lockdir' 38825dbecb6Smrg exit 1 38925dbecb6Smrg " 1 2 13 15 39025dbecb6Smrg numtries=100 39125dbecb6Smrg i=$numtries 39225dbecb6Smrg while test $i -gt 0; do 39325dbecb6Smrg # mkdir is a portable test-and-set. 39425dbecb6Smrg if mkdir "$lockdir" 2>/dev/null; then 39525dbecb6Smrg # This process acquired the lock. 39625dbecb6Smrg "$@" -MD 39725dbecb6Smrg stat=$? 39825dbecb6Smrg # Release the lock. 39925dbecb6Smrg rmdir "$lockdir" 40025dbecb6Smrg break 40125dbecb6Smrg else 40225dbecb6Smrg # If the lock is being held by a different process, wait 40325dbecb6Smrg # until the winning process is done or we timeout. 40425dbecb6Smrg while test -d "$lockdir" && test $i -gt 0; do 40525dbecb6Smrg sleep 1 40625dbecb6Smrg i=`expr $i - 1` 40725dbecb6Smrg done 40825dbecb6Smrg fi 40925dbecb6Smrg i=`expr $i - 1` 41025dbecb6Smrg done 41125dbecb6Smrg trap - 1 2 13 15 41225dbecb6Smrg if test $i -le 0; then 41325dbecb6Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41425dbecb6Smrg echo "$0: check lockdir '$lockdir'" >&2 41525dbecb6Smrg exit 1 41625dbecb6Smrg fi 41734a0776dSmrg 41825dbecb6Smrg if test $stat -ne 0; then 4196df26cacSmrg rm -f "$tmpdepfile" 4206df26cacSmrg exit $stat 4216df26cacSmrg fi 4226df26cacSmrg rm -f "$depfile" 42334a0776dSmrg # Each line is of the form `foo.o: dependent.h', 42434a0776dSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4256df26cacSmrg # Do two passes, one to just change these to 42634a0776dSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 42734a0776dSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42834a0776dSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 42934a0776dSmrg # correctly. Breaking it into two sed invocations is a workaround. 43025dbecb6Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43125dbecb6Smrg | sed -e 's/$/ :/' >> "$depfile" 4326df26cacSmrg rm -f "$tmpdepfile" 4336df26cacSmrg ;; 4346df26cacSmrg 435b68e1f86Smrghp2) 436b68e1f86Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437b68e1f86Smrg # compilers, which have integrated preprocessors. The correct option 438b68e1f86Smrg # to use with these is +Maked; it writes dependencies to a file named 439b68e1f86Smrg # 'foo.d', which lands next to the object file, wherever that 440b68e1f86Smrg # happens to be. 441b68e1f86Smrg # Much of this is similar to the tru64 case; see comments there. 44225dbecb6Smrg set_dir_from "$object" 44325dbecb6Smrg set_base_from "$object" 444b68e1f86Smrg if test "$libtool" = yes; then 445b68e1f86Smrg tmpdepfile1=$dir$base.d 446b68e1f86Smrg tmpdepfile2=$dir.libs/$base.d 447b68e1f86Smrg "$@" -Wc,+Maked 448b68e1f86Smrg else 449b68e1f86Smrg tmpdepfile1=$dir$base.d 450b68e1f86Smrg tmpdepfile2=$dir$base.d 451b68e1f86Smrg "$@" +Maked 452b68e1f86Smrg fi 453b68e1f86Smrg stat=$? 45425dbecb6Smrg if test $stat -ne 0; then 455b68e1f86Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456b68e1f86Smrg exit $stat 457b68e1f86Smrg fi 458b68e1f86Smrg 459b68e1f86Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460b68e1f86Smrg do 461b68e1f86Smrg test -f "$tmpdepfile" && break 462b68e1f86Smrg done 463b68e1f86Smrg if test -f "$tmpdepfile"; then 46425dbecb6Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46525dbecb6Smrg # Add 'dependent.h:' lines. 46625dbecb6Smrg sed -ne '2,${ 46725dbecb6Smrg s/^ *// 46825dbecb6Smrg s/ \\*$// 46925dbecb6Smrg s/$/:/ 47025dbecb6Smrg p 47125dbecb6Smrg }' "$tmpdepfile" >> "$depfile" 472b68e1f86Smrg else 47325dbecb6Smrg make_dummy_depfile 474b68e1f86Smrg fi 475b68e1f86Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 476b68e1f86Smrg ;; 477b68e1f86Smrg 4786df26cacSmrgtru64) 47925dbecb6Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48025dbecb6Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48125dbecb6Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48225dbecb6Smrg # dependencies in 'foo.d' instead, so we check for that too. 48325dbecb6Smrg # Subdirectories are respected. 48425dbecb6Smrg set_dir_from "$object" 48525dbecb6Smrg set_base_from "$object" 48625dbecb6Smrg 48725dbecb6Smrg if test "$libtool" = yes; then 48825dbecb6Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48925dbecb6Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49025dbecb6Smrg # in $dir$base.o.d. We have to check for both files, because 49125dbecb6Smrg # one of the two compilations can be disabled. We should prefer 49225dbecb6Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49325dbecb6Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49425dbecb6Smrg # the former would cause a distcleancheck panic. 49525dbecb6Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49625dbecb6Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49725dbecb6Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49825dbecb6Smrg "$@" -Wc,-MD 49925dbecb6Smrg else 50025dbecb6Smrg tmpdepfile1=$dir$base.d 50125dbecb6Smrg tmpdepfile2=$dir$base.d 50225dbecb6Smrg tmpdepfile3=$dir$base.d 50325dbecb6Smrg "$@" -MD 50425dbecb6Smrg fi 50525dbecb6Smrg 50625dbecb6Smrg stat=$? 50725dbecb6Smrg if test $stat -ne 0; then 50825dbecb6Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50925dbecb6Smrg exit $stat 51025dbecb6Smrg fi 51125dbecb6Smrg 51225dbecb6Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51325dbecb6Smrg do 51425dbecb6Smrg test -f "$tmpdepfile" && break 51525dbecb6Smrg done 51625dbecb6Smrg # Same post-processing that is required for AIX mode. 51725dbecb6Smrg aix_post_process_depfile 51825dbecb6Smrg ;; 51925dbecb6Smrg 52025dbecb6Smrgmsvc7) 52125dbecb6Smrg if test "$libtool" = yes; then 52225dbecb6Smrg showIncludes=-Wc,-showIncludes 52325dbecb6Smrg else 52425dbecb6Smrg showIncludes=-showIncludes 52525dbecb6Smrg fi 52625dbecb6Smrg "$@" $showIncludes > "$tmpdepfile" 52725dbecb6Smrg stat=$? 52825dbecb6Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52925dbecb6Smrg if test $stat -ne 0; then 53025dbecb6Smrg rm -f "$tmpdepfile" 53125dbecb6Smrg exit $stat 53225dbecb6Smrg fi 53325dbecb6Smrg rm -f "$depfile" 53425dbecb6Smrg echo "$object : \\" > "$depfile" 53525dbecb6Smrg # The first sed program below extracts the file names and escapes 53625dbecb6Smrg # backslashes for cygpath. The second sed program outputs the file 53725dbecb6Smrg # name when reading, but also accumulates all include files in the 53825dbecb6Smrg # hold buffer in order to output them again at the end. This only 53925dbecb6Smrg # works with sed implementations that can handle large buffers. 54025dbecb6Smrg sed < "$tmpdepfile" -n ' 54125dbecb6Smrg/^Note: including file: *\(.*\)/ { 54225dbecb6Smrg s//\1/ 54325dbecb6Smrg s/\\/\\\\/g 54425dbecb6Smrg p 54525dbecb6Smrg}' | $cygpath_u | sort -u | sed -n ' 54625dbecb6Smrgs/ /\\ /g 54725dbecb6Smrgs/\(.*\)/'"$tab"'\1 \\/p 54825dbecb6Smrgs/.\(.*\) \\/\1:/ 54925dbecb6SmrgH 55025dbecb6Smrg$ { 55125dbecb6Smrg s/.*/'"$tab"'/ 55225dbecb6Smrg G 55325dbecb6Smrg p 55425dbecb6Smrg}' >> "$depfile" 55525dbecb6Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55625dbecb6Smrg rm -f "$tmpdepfile" 55725dbecb6Smrg ;; 55825dbecb6Smrg 55925dbecb6Smrgmsvc7msys) 56025dbecb6Smrg # This case exists only to let depend.m4 do its work. It works by 56125dbecb6Smrg # looking at the text of this script. This case will never be run, 56225dbecb6Smrg # since it is checked for above. 56325dbecb6Smrg exit 1 56425dbecb6Smrg ;; 5656df26cacSmrg 5666df26cacSmrg#nosideeffect) 5676df26cacSmrg # This comment above is used by automake to tell side-effect 5686df26cacSmrg # dependency tracking mechanisms from slower ones. 5696df26cacSmrg 5706df26cacSmrgdashmstdout) 5716df26cacSmrg # Important note: in order to support this mode, a compiler *must* 5726df26cacSmrg # always write the preprocessed file to stdout, regardless of -o. 5736df26cacSmrg "$@" || exit $? 5746df26cacSmrg 5756df26cacSmrg # Remove the call to Libtool. 5766df26cacSmrg if test "$libtool" = yes; then 57725dbecb6Smrg while test "X$1" != 'X--mode=compile'; do 5786df26cacSmrg shift 5796df26cacSmrg done 5806df26cacSmrg shift 5816df26cacSmrg fi 5826df26cacSmrg 58325dbecb6Smrg # Remove '-o $object'. 5846df26cacSmrg IFS=" " 5856df26cacSmrg for arg 5866df26cacSmrg do 5876df26cacSmrg case $arg in 5886df26cacSmrg -o) 5896df26cacSmrg shift 5906df26cacSmrg ;; 5916df26cacSmrg $object) 5926df26cacSmrg shift 5936df26cacSmrg ;; 5946df26cacSmrg *) 5956df26cacSmrg set fnord "$@" "$arg" 5966df26cacSmrg shift # fnord 5976df26cacSmrg shift # $arg 5986df26cacSmrg ;; 5996df26cacSmrg esac 6006df26cacSmrg done 6016df26cacSmrg 6026df26cacSmrg test -z "$dashmflag" && dashmflag=-M 60325dbecb6Smrg # Require at least two characters before searching for ':' 6046df26cacSmrg # in the target name. This is to cope with DOS-style filenames: 60525dbecb6Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6066df26cacSmrg "$@" $dashmflag | 60725dbecb6Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6086df26cacSmrg rm -f "$depfile" 6096df26cacSmrg cat < "$tmpdepfile" > "$depfile" 61025dbecb6Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61125dbecb6Smrg # correctly. Breaking it into two sed invocations is a workaround. 61225dbecb6Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61325dbecb6Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61425dbecb6Smrg | sed -e 's/$/ :/' >> "$depfile" 6156df26cacSmrg rm -f "$tmpdepfile" 6166df26cacSmrg ;; 6176df26cacSmrg 6186df26cacSmrgdashXmstdout) 6196df26cacSmrg # This case only exists to satisfy depend.m4. It is never actually 6206df26cacSmrg # run, as this mode is specially recognized in the preamble. 6216df26cacSmrg exit 1 6226df26cacSmrg ;; 6236df26cacSmrg 6246df26cacSmrgmakedepend) 6256df26cacSmrg "$@" || exit $? 6266df26cacSmrg # Remove any Libtool call 6276df26cacSmrg if test "$libtool" = yes; then 62825dbecb6Smrg while test "X$1" != 'X--mode=compile'; do 6296df26cacSmrg shift 6306df26cacSmrg done 6316df26cacSmrg shift 6326df26cacSmrg fi 6336df26cacSmrg # X makedepend 6346df26cacSmrg shift 63525dbecb6Smrg cleared=no eat=no 63625dbecb6Smrg for arg 63725dbecb6Smrg do 6386df26cacSmrg case $cleared in 6396df26cacSmrg no) 6406df26cacSmrg set ""; shift 6416df26cacSmrg cleared=yes ;; 6426df26cacSmrg esac 64325dbecb6Smrg if test $eat = yes; then 64425dbecb6Smrg eat=no 64525dbecb6Smrg continue 64625dbecb6Smrg fi 6476df26cacSmrg case "$arg" in 6486df26cacSmrg -D*|-I*) 6496df26cacSmrg set fnord "$@" "$arg"; shift ;; 6506df26cacSmrg # Strip any option that makedepend may not understand. Remove 6516df26cacSmrg # the object too, otherwise makedepend will parse it as a source file. 65225dbecb6Smrg -arch) 65325dbecb6Smrg eat=yes ;; 6546df26cacSmrg -*|$object) 6556df26cacSmrg ;; 6566df26cacSmrg *) 6576df26cacSmrg set fnord "$@" "$arg"; shift ;; 6586df26cacSmrg esac 6596df26cacSmrg done 66025dbecb6Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6616df26cacSmrg touch "$tmpdepfile" 6626df26cacSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6636df26cacSmrg rm -f "$depfile" 66425dbecb6Smrg # makedepend may prepend the VPATH from the source file name to the object. 66525dbecb6Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66625dbecb6Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66725dbecb6Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66825dbecb6Smrg # correctly. Breaking it into two sed invocations is a workaround. 66925dbecb6Smrg sed '1,2d' "$tmpdepfile" \ 67025dbecb6Smrg | tr ' ' "$nl" \ 67125dbecb6Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67225dbecb6Smrg | sed -e 's/$/ :/' >> "$depfile" 6736df26cacSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6746df26cacSmrg ;; 6756df26cacSmrg 6766df26cacSmrgcpp) 6776df26cacSmrg # Important note: in order to support this mode, a compiler *must* 6786df26cacSmrg # always write the preprocessed file to stdout. 6796df26cacSmrg "$@" || exit $? 6806df26cacSmrg 6816df26cacSmrg # Remove the call to Libtool. 6826df26cacSmrg if test "$libtool" = yes; then 68325dbecb6Smrg while test "X$1" != 'X--mode=compile'; do 6846df26cacSmrg shift 6856df26cacSmrg done 6866df26cacSmrg shift 6876df26cacSmrg fi 6886df26cacSmrg 68925dbecb6Smrg # Remove '-o $object'. 6906df26cacSmrg IFS=" " 6916df26cacSmrg for arg 6926df26cacSmrg do 6936df26cacSmrg case $arg in 6946df26cacSmrg -o) 6956df26cacSmrg shift 6966df26cacSmrg ;; 6976df26cacSmrg $object) 6986df26cacSmrg shift 6996df26cacSmrg ;; 7006df26cacSmrg *) 7016df26cacSmrg set fnord "$@" "$arg" 7026df26cacSmrg shift # fnord 7036df26cacSmrg shift # $arg 7046df26cacSmrg ;; 7056df26cacSmrg esac 7066df26cacSmrg done 7076df26cacSmrg 70825dbecb6Smrg "$@" -E \ 70925dbecb6Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71025dbecb6Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71125dbecb6Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7126df26cacSmrg rm -f "$depfile" 7136df26cacSmrg echo "$object : \\" > "$depfile" 7146df26cacSmrg cat < "$tmpdepfile" >> "$depfile" 7156df26cacSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7166df26cacSmrg rm -f "$tmpdepfile" 7176df26cacSmrg ;; 7186df26cacSmrg 7196df26cacSmrgmsvisualcpp) 7206df26cacSmrg # Important note: in order to support this mode, a compiler *must* 72125dbecb6Smrg # always write the preprocessed file to stdout. 7226df26cacSmrg "$@" || exit $? 72325dbecb6Smrg 72425dbecb6Smrg # Remove the call to Libtool. 72525dbecb6Smrg if test "$libtool" = yes; then 72625dbecb6Smrg while test "X$1" != 'X--mode=compile'; do 72725dbecb6Smrg shift 72825dbecb6Smrg done 72925dbecb6Smrg shift 73025dbecb6Smrg fi 73125dbecb6Smrg 7326df26cacSmrg IFS=" " 7336df26cacSmrg for arg 7346df26cacSmrg do 7356df26cacSmrg case "$arg" in 73625dbecb6Smrg -o) 73725dbecb6Smrg shift 73825dbecb6Smrg ;; 73925dbecb6Smrg $object) 74025dbecb6Smrg shift 74125dbecb6Smrg ;; 7426df26cacSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74325dbecb6Smrg set fnord "$@" 74425dbecb6Smrg shift 74525dbecb6Smrg shift 74625dbecb6Smrg ;; 7476df26cacSmrg *) 74825dbecb6Smrg set fnord "$@" "$arg" 74925dbecb6Smrg shift 75025dbecb6Smrg shift 75125dbecb6Smrg ;; 7526df26cacSmrg esac 7536df26cacSmrg done 75425dbecb6Smrg "$@" -E 2>/dev/null | 75525dbecb6Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7566df26cacSmrg rm -f "$depfile" 7576df26cacSmrg echo "$object : \\" > "$depfile" 75825dbecb6Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75925dbecb6Smrg echo "$tab" >> "$depfile" 76025dbecb6Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7616df26cacSmrg rm -f "$tmpdepfile" 7626df26cacSmrg ;; 7636df26cacSmrg 76425dbecb6Smrgmsvcmsys) 76525dbecb6Smrg # This case exists only to let depend.m4 do its work. It works by 76625dbecb6Smrg # looking at the text of this script. This case will never be run, 76725dbecb6Smrg # since it is checked for above. 76825dbecb6Smrg exit 1 76925dbecb6Smrg ;; 77025dbecb6Smrg 7716df26cacSmrgnone) 7726df26cacSmrg exec "$@" 7736df26cacSmrg ;; 7746df26cacSmrg 7756df26cacSmrg*) 7766df26cacSmrg echo "Unknown depmode $depmode" 1>&2 7776df26cacSmrg exit 1 7786df26cacSmrg ;; 7796df26cacSmrgesac 7806df26cacSmrg 7816df26cacSmrgexit 0 7826df26cacSmrg 7836df26cacSmrg# Local Variables: 7846df26cacSmrg# mode: shell-script 7856df26cacSmrg# sh-indentation: 2 78625dbecb6Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 7876df26cacSmrg# time-stamp-start: "scriptversion=" 7886df26cacSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78925dbecb6Smrg# time-stamp-time-zone: "UTC0" 79025dbecb6Smrg# time-stamp-end: "; # UTC" 7916df26cacSmrg# End: 792