129459361Smrg#! /bin/sh 229459361Smrg# depcomp - compile a program generating dependencies as side-effects 329459361Smrg 4291ca6f5Smrgscriptversion=2018-03-07.03; # UTC 529459361Smrg 6291ca6f5Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 729459361Smrg 829459361Smrg# This program is free software; you can redistribute it and/or modify 929459361Smrg# it under the terms of the GNU General Public License as published by 1029459361Smrg# the Free Software Foundation; either version 2, or (at your option) 1129459361Smrg# any later version. 1229459361Smrg 1329459361Smrg# This program is distributed in the hope that it will be useful, 1429459361Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1529459361Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1629459361Smrg# GNU General Public License for more details. 1729459361Smrg 1829459361Smrg# You should have received a copy of the GNU General Public License 19291ca6f5Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2029459361Smrg 2129459361Smrg# As a special exception to the GNU General Public License, if you 2229459361Smrg# distribute this file as part of a program that contains a 2329459361Smrg# configuration script generated by Autoconf, you may include it under 2429459361Smrg# the same distribution terms that you use for the rest of that program. 2529459361Smrg 2629459361Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2729459361Smrg 2829459361Smrgcase $1 in 2929459361Smrg '') 30f66e55a2Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31f66e55a2Smrg exit 1; 32f66e55a2Smrg ;; 3329459361Smrg -h | --h*) 3429459361Smrg cat <<\EOF 3529459361SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3629459361Smrg 3729459361SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3829459361Smrgas side-effects. 3929459361Smrg 4029459361SmrgEnvironment variables: 4129459361Smrg depmode Dependency tracking mode. 42f66e55a2Smrg source Source file read by 'PROGRAMS ARGS'. 43f66e55a2Smrg object Object file output by 'PROGRAMS ARGS'. 4429459361Smrg DEPDIR directory where to store dependencies. 4529459361Smrg depfile Dependency file to output. 46f66e55a2Smrg tmpdepfile Temporary file to use when outputting dependencies. 4729459361Smrg libtool Whether libtool is used (yes/no). 4829459361Smrg 4929459361SmrgReport bugs to <bug-automake@gnu.org>. 5029459361SmrgEOF 5129459361Smrg exit $? 5229459361Smrg ;; 5329459361Smrg -v | --v*) 5429459361Smrg echo "depcomp $scriptversion" 5529459361Smrg exit $? 5629459361Smrg ;; 5729459361Smrgesac 5829459361Smrg 59f66e55a2Smrg# Get the directory component of the given path, and save it in the 60f66e55a2Smrg# global variables '$dir'. Note that this directory component will 61f66e55a2Smrg# be either empty or ending with a '/' character. This is deliberate. 62f66e55a2Smrgset_dir_from () 63f66e55a2Smrg{ 64f66e55a2Smrg case $1 in 65f66e55a2Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66f66e55a2Smrg *) dir=;; 67f66e55a2Smrg esac 68f66e55a2Smrg} 69f66e55a2Smrg 70f66e55a2Smrg# Get the suffix-stripped basename of the given path, and save it the 71f66e55a2Smrg# global variable '$base'. 72f66e55a2Smrgset_base_from () 73f66e55a2Smrg{ 74f66e55a2Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75f66e55a2Smrg} 76f66e55a2Smrg 77f66e55a2Smrg# If no dependency file was actually created by the compiler invocation, 78f66e55a2Smrg# we still have to create a dummy depfile, to avoid errors with the 79f66e55a2Smrg# Makefile "include basename.Plo" scheme. 80f66e55a2Smrgmake_dummy_depfile () 81f66e55a2Smrg{ 82f66e55a2Smrg echo "#dummy" > "$depfile" 83f66e55a2Smrg} 84f66e55a2Smrg 85f66e55a2Smrg# Factor out some common post-processing of the generated depfile. 86f66e55a2Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87f66e55a2Smrgaix_post_process_depfile () 88f66e55a2Smrg{ 89f66e55a2Smrg # If the compiler actually managed to produce a dependency file, 90f66e55a2Smrg # post-process it. 91f66e55a2Smrg if test -f "$tmpdepfile"; then 92f66e55a2Smrg # Each line is of the form 'foo.o: dependency.h'. 93f66e55a2Smrg # Do two passes, one to just change these to 94f66e55a2Smrg # $object: dependency.h 95f66e55a2Smrg # and one to simply output 96f66e55a2Smrg # dependency.h: 97f66e55a2Smrg # which is needed to avoid the deleted-header problem. 98f66e55a2Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99f66e55a2Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100f66e55a2Smrg } > "$depfile" 101f66e55a2Smrg rm -f "$tmpdepfile" 102f66e55a2Smrg else 103f66e55a2Smrg make_dummy_depfile 104f66e55a2Smrg fi 105f66e55a2Smrg} 106f66e55a2Smrg 107f66e55a2Smrg# A tabulation character. 108f66e55a2Smrgtab=' ' 109f66e55a2Smrg# A newline character. 110f66e55a2Smrgnl=' 111f66e55a2Smrg' 112f66e55a2Smrg# Character ranges might be problematic outside the C locale. 113f66e55a2Smrg# These definitions help. 114f66e55a2Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115f66e55a2Smrglower=abcdefghijklmnopqrstuvwxyz 116f66e55a2Smrgdigits=0123456789 117f66e55a2Smrgalpha=${upper}${lower} 118f66e55a2Smrg 11929459361Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12029459361Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12129459361Smrg exit 1 12229459361Smrgfi 12329459361Smrg 12429459361Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12529459361Smrgdepfile=${depfile-`echo "$object" | 12629459361Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12729459361Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12829459361Smrg 12929459361Smrgrm -f "$tmpdepfile" 13029459361Smrg 131f66e55a2Smrg# Avoid interferences from the environment. 132f66e55a2Smrggccflag= dashmflag= 133f66e55a2Smrg 13429459361Smrg# Some modes work just like other modes, but use different flags. We 13529459361Smrg# parameterize here, but still list the modes in the big case below, 13629459361Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13729459361Smrg# here, because this file can only contain one case statement. 13829459361Smrgif test "$depmode" = hp; then 13929459361Smrg # HP compiler uses -M and no extra arg. 14029459361Smrg gccflag=-M 14129459361Smrg depmode=gcc 14229459361Smrgfi 14329459361Smrg 14429459361Smrgif test "$depmode" = dashXmstdout; then 145f66e55a2Smrg # This is just like dashmstdout with a different argument. 146f66e55a2Smrg dashmflag=-xM 147f66e55a2Smrg depmode=dashmstdout 14829459361Smrgfi 14929459361Smrg 1505715adc0Smrgcygpath_u="cygpath -u -f -" 1515715adc0Smrgif test "$depmode" = msvcmsys; then 152f66e55a2Smrg # This is just like msvisualcpp but w/o cygpath translation. 153f66e55a2Smrg # Just convert the backslash-escaped backslashes to single forward 154f66e55a2Smrg # slashes to satisfy depend.m4 155f66e55a2Smrg cygpath_u='sed s,\\\\,/,g' 156f66e55a2Smrg depmode=msvisualcpp 157f66e55a2Smrgfi 158f66e55a2Smrg 159f66e55a2Smrgif test "$depmode" = msvc7msys; then 160f66e55a2Smrg # This is just like msvc7 but w/o cygpath translation. 161f66e55a2Smrg # Just convert the backslash-escaped backslashes to single forward 162f66e55a2Smrg # slashes to satisfy depend.m4 163f66e55a2Smrg cygpath_u='sed s,\\\\,/,g' 164f66e55a2Smrg depmode=msvc7 165f66e55a2Smrgfi 166f66e55a2Smrg 167f66e55a2Smrgif test "$depmode" = xlc; then 168f66e55a2Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169f66e55a2Smrg gccflag=-qmakedep=gcc,-MF 170f66e55a2Smrg depmode=gcc 1715715adc0Smrgfi 1725715adc0Smrg 17329459361Smrgcase "$depmode" in 17429459361Smrggcc3) 17529459361Smrg## gcc 3 implements dependency tracking that does exactly what 17629459361Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17729459361Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1785715adc0Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1795715adc0Smrg## the command line argument order; so add the flags where they 1805715adc0Smrg## appear in depend2.am. Note that the slowdown incurred here 1815715adc0Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1825715adc0Smrg for arg 1835715adc0Smrg do 1845715adc0Smrg case $arg in 1855715adc0Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1865715adc0Smrg *) set fnord "$@" "$arg" ;; 1875715adc0Smrg esac 1885715adc0Smrg shift # fnord 1895715adc0Smrg shift # $arg 1905715adc0Smrg done 1915715adc0Smrg "$@" 19229459361Smrg stat=$? 193f66e55a2Smrg if test $stat -ne 0; then 19429459361Smrg rm -f "$tmpdepfile" 19529459361Smrg exit $stat 19629459361Smrg fi 19729459361Smrg mv "$tmpdepfile" "$depfile" 19829459361Smrg ;; 19929459361Smrg 20029459361Smrggcc) 201f66e55a2Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202f66e55a2Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203f66e55a2Smrg## (see the conditional assignment to $gccflag above). 20429459361Smrg## There are various ways to get dependency output from gcc. Here's 20529459361Smrg## why we pick this rather obscure method: 20629459361Smrg## - Don't want to use -MD because we'd like the dependencies to end 20729459361Smrg## up in a subdir. Having to rename by hand is ugly. 20829459361Smrg## (We might end up doing this anyway to support other compilers.) 20929459361Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210f66e55a2Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211f66e55a2Smrg## supported by the other compilers which use the 'gcc' depmode. 21229459361Smrg## - Using -M directly means running the compiler twice (even worse 21329459361Smrg## than renaming). 21429459361Smrg if test -z "$gccflag"; then 21529459361Smrg gccflag=-MD, 21629459361Smrg fi 21729459361Smrg "$@" -Wp,"$gccflag$tmpdepfile" 21829459361Smrg stat=$? 219f66e55a2Smrg if test $stat -ne 0; then 22029459361Smrg rm -f "$tmpdepfile" 22129459361Smrg exit $stat 22229459361Smrg fi 22329459361Smrg rm -f "$depfile" 22429459361Smrg echo "$object : \\" > "$depfile" 225f66e55a2Smrg # The second -e expression handles DOS-style file names with drive 226f66e55a2Smrg # letters. 22729459361Smrg sed -e 's/^[^:]*: / /' \ 22829459361Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229f66e55a2Smrg## This next piece of magic avoids the "deleted header file" problem. 23029459361Smrg## The problem is that when a header file which appears in a .P file 23129459361Smrg## is deleted, the dependency causes make to die (because there is 23229459361Smrg## typically no way to rebuild the header). We avoid this by adding 23329459361Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 23429459361Smrg## this for us directly. 235f66e55a2Smrg## Some versions of gcc put a space before the ':'. On the theory 23629459361Smrg## that the space means something, we add a space to the output as 237f66e55a2Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238f66e55a2Smrg## to the object. Take care to not repeat it in the output. 23929459361Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 24029459361Smrg## correctly. Breaking it into two sed invocations is a workaround. 241f66e55a2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242f66e55a2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243f66e55a2Smrg | sed -e 's/$/ :/' >> "$depfile" 24429459361Smrg rm -f "$tmpdepfile" 24529459361Smrg ;; 24629459361Smrg 24729459361Smrghp) 24829459361Smrg # This case exists only to let depend.m4 do its work. It works by 24929459361Smrg # looking at the text of this script. This case will never be run, 25029459361Smrg # since it is checked for above. 25129459361Smrg exit 1 25229459361Smrg ;; 25329459361Smrg 25429459361Smrgsgi) 25529459361Smrg if test "$libtool" = yes; then 25629459361Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25729459361Smrg else 25829459361Smrg "$@" -MDupdate "$tmpdepfile" 25929459361Smrg fi 26029459361Smrg stat=$? 261f66e55a2Smrg if test $stat -ne 0; then 26229459361Smrg rm -f "$tmpdepfile" 26329459361Smrg exit $stat 26429459361Smrg fi 26529459361Smrg rm -f "$depfile" 26629459361Smrg 26729459361Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26829459361Smrg echo "$object : \\" > "$depfile" 26929459361Smrg # Clip off the initial element (the dependent). Don't try to be 27029459361Smrg # clever and replace this with sed code, as IRIX sed won't handle 27129459361Smrg # lines with more than a fixed number of characters (4096 in 27229459361Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273f66e55a2Smrg # the IRIX cc adds comments like '#:fec' to the end of the 27429459361Smrg # dependency line. 275f66e55a2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276f66e55a2Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277f66e55a2Smrg | tr "$nl" ' ' >> "$depfile" 2785715adc0Smrg echo >> "$depfile" 27929459361Smrg # The second pass generates a dummy entry for each header file. 280f66e55a2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281f66e55a2Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282f66e55a2Smrg >> "$depfile" 28329459361Smrg else 284f66e55a2Smrg make_dummy_depfile 28529459361Smrg fi 28629459361Smrg rm -f "$tmpdepfile" 28729459361Smrg ;; 28829459361Smrg 289f66e55a2Smrgxlc) 290f66e55a2Smrg # This case exists only to let depend.m4 do its work. It works by 291f66e55a2Smrg # looking at the text of this script. This case will never be run, 292f66e55a2Smrg # since it is checked for above. 293f66e55a2Smrg exit 1 294f66e55a2Smrg ;; 295f66e55a2Smrg 29629459361Smrgaix) 29729459361Smrg # The C for AIX Compiler uses -M and outputs the dependencies 29829459361Smrg # in a .u file. In older versions, this file always lives in the 299f66e55a2Smrg # current directory. Also, the AIX compiler puts '$object:' at the 30029459361Smrg # start of each line; $object doesn't have directory information. 30129459361Smrg # Version 6 uses the directory in both cases. 302f66e55a2Smrg set_dir_from "$object" 303f66e55a2Smrg set_base_from "$object" 30429459361Smrg if test "$libtool" = yes; then 3055715adc0Smrg tmpdepfile1=$dir$base.u 3065715adc0Smrg tmpdepfile2=$base.u 3075715adc0Smrg tmpdepfile3=$dir.libs/$base.u 30829459361Smrg "$@" -Wc,-M 30929459361Smrg else 3105715adc0Smrg tmpdepfile1=$dir$base.u 3115715adc0Smrg tmpdepfile2=$dir$base.u 3125715adc0Smrg tmpdepfile3=$dir$base.u 31329459361Smrg "$@" -M 31429459361Smrg fi 31529459361Smrg stat=$? 316f66e55a2Smrg if test $stat -ne 0; then 3175715adc0Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31829459361Smrg exit $stat 31929459361Smrg fi 32029459361Smrg 3215715adc0Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3225715adc0Smrg do 3235715adc0Smrg test -f "$tmpdepfile" && break 3245715adc0Smrg done 325f66e55a2Smrg aix_post_process_depfile 326f66e55a2Smrg ;; 327f66e55a2Smrg 328f66e55a2Smrgtcc) 329f66e55a2Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330f66e55a2Smrg # FIXME: That version still under development at the moment of writing. 331f66e55a2Smrg # Make that this statement remains true also for stable, released 332f66e55a2Smrg # versions. 333f66e55a2Smrg # It will wrap lines (doesn't matter whether long or short) with a 334f66e55a2Smrg # trailing '\', as in: 335f66e55a2Smrg # 336f66e55a2Smrg # foo.o : \ 337f66e55a2Smrg # foo.c \ 338f66e55a2Smrg # foo.h \ 339f66e55a2Smrg # 340f66e55a2Smrg # It will put a trailing '\' even on the last line, and will use leading 341f66e55a2Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342f66e55a2Smrg # "Emit spaces for -MD"). 343f66e55a2Smrg "$@" -MD -MF "$tmpdepfile" 344f66e55a2Smrg stat=$? 345f66e55a2Smrg if test $stat -ne 0; then 346f66e55a2Smrg rm -f "$tmpdepfile" 347f66e55a2Smrg exit $stat 34829459361Smrg fi 349f66e55a2Smrg rm -f "$depfile" 350f66e55a2Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351f66e55a2Smrg # We have to change lines of the first kind to '$object: \'. 352f66e55a2Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353f66e55a2Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354f66e55a2Smrg # dummy dependency, to avoid the deleted-header problem. 355f66e55a2Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35629459361Smrg rm -f "$tmpdepfile" 35729459361Smrg ;; 35829459361Smrg 359f66e55a2Smrg## The order of this option in the case statement is important, since the 360f66e55a2Smrg## shell code in configure will try each of these formats in the order 361f66e55a2Smrg## listed in this file. A plain '-MD' option would be understood by many 362f66e55a2Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363f66e55a2Smrgpgcc) 364f66e55a2Smrg # Portland's C compiler understands '-MD'. 365f66e55a2Smrg # Will always output deps to 'file.d' where file is the root name of the 366f66e55a2Smrg # source file under compilation, even if file resides in a subdirectory. 367f66e55a2Smrg # The object file name does not affect the name of the '.d' file. 368f66e55a2Smrg # pgcc 10.2 will output 36929459361Smrg # foo.o: sub/foo.c sub/foo.h 370f66e55a2Smrg # and will wrap long lines using '\' : 37129459361Smrg # foo.o: sub/foo.c ... \ 37229459361Smrg # sub/foo.h ... \ 37329459361Smrg # ... 374f66e55a2Smrg set_dir_from "$object" 375f66e55a2Smrg # Use the source, not the object, to determine the base name, since 376f66e55a2Smrg # that's sadly what pgcc will do too. 377f66e55a2Smrg set_base_from "$source" 378f66e55a2Smrg tmpdepfile=$base.d 379f66e55a2Smrg 380f66e55a2Smrg # For projects that build the same source file twice into different object 381f66e55a2Smrg # files, the pgcc approach of using the *source* file root name can cause 382f66e55a2Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383f66e55a2Smrg # the same $tmpdepfile. 384f66e55a2Smrg lockdir=$base.d-lock 385f66e55a2Smrg trap " 386f66e55a2Smrg echo '$0: caught signal, cleaning up...' >&2 387f66e55a2Smrg rmdir '$lockdir' 388f66e55a2Smrg exit 1 389f66e55a2Smrg " 1 2 13 15 390f66e55a2Smrg numtries=100 391f66e55a2Smrg i=$numtries 392f66e55a2Smrg while test $i -gt 0; do 393f66e55a2Smrg # mkdir is a portable test-and-set. 394f66e55a2Smrg if mkdir "$lockdir" 2>/dev/null; then 395f66e55a2Smrg # This process acquired the lock. 396f66e55a2Smrg "$@" -MD 397f66e55a2Smrg stat=$? 398f66e55a2Smrg # Release the lock. 399f66e55a2Smrg rmdir "$lockdir" 400f66e55a2Smrg break 401f66e55a2Smrg else 402f66e55a2Smrg # If the lock is being held by a different process, wait 403f66e55a2Smrg # until the winning process is done or we timeout. 404f66e55a2Smrg while test -d "$lockdir" && test $i -gt 0; do 405f66e55a2Smrg sleep 1 406f66e55a2Smrg i=`expr $i - 1` 407f66e55a2Smrg done 408f66e55a2Smrg fi 409f66e55a2Smrg i=`expr $i - 1` 410f66e55a2Smrg done 411f66e55a2Smrg trap - 1 2 13 15 412f66e55a2Smrg if test $i -le 0; then 413f66e55a2Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414f66e55a2Smrg echo "$0: check lockdir '$lockdir'" >&2 415f66e55a2Smrg exit 1 416f66e55a2Smrg fi 41729459361Smrg 418f66e55a2Smrg if test $stat -ne 0; then 41929459361Smrg rm -f "$tmpdepfile" 42029459361Smrg exit $stat 42129459361Smrg fi 42229459361Smrg rm -f "$depfile" 42329459361Smrg # Each line is of the form `foo.o: dependent.h', 42429459361Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42529459361Smrg # Do two passes, one to just change these to 42629459361Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 42729459361Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42829459361Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 42929459361Smrg # correctly. Breaking it into two sed invocations is a workaround. 430f66e55a2Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431f66e55a2Smrg | sed -e 's/$/ :/' >> "$depfile" 43229459361Smrg rm -f "$tmpdepfile" 43329459361Smrg ;; 43429459361Smrg 4355715adc0Smrghp2) 4365715adc0Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4375715adc0Smrg # compilers, which have integrated preprocessors. The correct option 4385715adc0Smrg # to use with these is +Maked; it writes dependencies to a file named 4395715adc0Smrg # 'foo.d', which lands next to the object file, wherever that 4405715adc0Smrg # happens to be. 4415715adc0Smrg # Much of this is similar to the tru64 case; see comments there. 442f66e55a2Smrg set_dir_from "$object" 443f66e55a2Smrg set_base_from "$object" 4445715adc0Smrg if test "$libtool" = yes; then 4455715adc0Smrg tmpdepfile1=$dir$base.d 4465715adc0Smrg tmpdepfile2=$dir.libs/$base.d 4475715adc0Smrg "$@" -Wc,+Maked 4485715adc0Smrg else 4495715adc0Smrg tmpdepfile1=$dir$base.d 4505715adc0Smrg tmpdepfile2=$dir$base.d 4515715adc0Smrg "$@" +Maked 4525715adc0Smrg fi 4535715adc0Smrg stat=$? 454f66e55a2Smrg if test $stat -ne 0; then 4555715adc0Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4565715adc0Smrg exit $stat 4575715adc0Smrg fi 4585715adc0Smrg 4595715adc0Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4605715adc0Smrg do 4615715adc0Smrg test -f "$tmpdepfile" && break 4625715adc0Smrg done 4635715adc0Smrg if test -f "$tmpdepfile"; then 464f66e55a2Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465f66e55a2Smrg # Add 'dependent.h:' lines. 4665715adc0Smrg sed -ne '2,${ 467f66e55a2Smrg s/^ *// 468f66e55a2Smrg s/ \\*$// 469f66e55a2Smrg s/$/:/ 470f66e55a2Smrg p 471f66e55a2Smrg }' "$tmpdepfile" >> "$depfile" 4725715adc0Smrg else 473f66e55a2Smrg make_dummy_depfile 4745715adc0Smrg fi 4755715adc0Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4765715adc0Smrg ;; 4775715adc0Smrg 47829459361Smrgtru64) 479f66e55a2Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480f66e55a2Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481f66e55a2Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482f66e55a2Smrg # dependencies in 'foo.d' instead, so we check for that too. 483f66e55a2Smrg # Subdirectories are respected. 484f66e55a2Smrg set_dir_from "$object" 485f66e55a2Smrg set_base_from "$object" 486f66e55a2Smrg 487f66e55a2Smrg if test "$libtool" = yes; then 488f66e55a2Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489f66e55a2Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490f66e55a2Smrg # in $dir$base.o.d. We have to check for both files, because 491f66e55a2Smrg # one of the two compilations can be disabled. We should prefer 492f66e55a2Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493f66e55a2Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494f66e55a2Smrg # the former would cause a distcleancheck panic. 495f66e55a2Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496f66e55a2Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497f66e55a2Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498f66e55a2Smrg "$@" -Wc,-MD 499f66e55a2Smrg else 500f66e55a2Smrg tmpdepfile1=$dir$base.d 501f66e55a2Smrg tmpdepfile2=$dir$base.d 502f66e55a2Smrg tmpdepfile3=$dir$base.d 503f66e55a2Smrg "$@" -MD 504f66e55a2Smrg fi 505f66e55a2Smrg 506f66e55a2Smrg stat=$? 507f66e55a2Smrg if test $stat -ne 0; then 508f66e55a2Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509f66e55a2Smrg exit $stat 510f66e55a2Smrg fi 511f66e55a2Smrg 512f66e55a2Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513f66e55a2Smrg do 514f66e55a2Smrg test -f "$tmpdepfile" && break 515f66e55a2Smrg done 516f66e55a2Smrg # Same post-processing that is required for AIX mode. 517f66e55a2Smrg aix_post_process_depfile 518f66e55a2Smrg ;; 519f66e55a2Smrg 520f66e55a2Smrgmsvc7) 521f66e55a2Smrg if test "$libtool" = yes; then 522f66e55a2Smrg showIncludes=-Wc,-showIncludes 523f66e55a2Smrg else 524f66e55a2Smrg showIncludes=-showIncludes 525f66e55a2Smrg fi 526f66e55a2Smrg "$@" $showIncludes > "$tmpdepfile" 527f66e55a2Smrg stat=$? 528f66e55a2Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529f66e55a2Smrg if test $stat -ne 0; then 530f66e55a2Smrg rm -f "$tmpdepfile" 531f66e55a2Smrg exit $stat 532f66e55a2Smrg fi 533f66e55a2Smrg rm -f "$depfile" 534f66e55a2Smrg echo "$object : \\" > "$depfile" 535f66e55a2Smrg # The first sed program below extracts the file names and escapes 536f66e55a2Smrg # backslashes for cygpath. The second sed program outputs the file 537f66e55a2Smrg # name when reading, but also accumulates all include files in the 538f66e55a2Smrg # hold buffer in order to output them again at the end. This only 539f66e55a2Smrg # works with sed implementations that can handle large buffers. 540f66e55a2Smrg sed < "$tmpdepfile" -n ' 541f66e55a2Smrg/^Note: including file: *\(.*\)/ { 542f66e55a2Smrg s//\1/ 543f66e55a2Smrg s/\\/\\\\/g 544f66e55a2Smrg p 545f66e55a2Smrg}' | $cygpath_u | sort -u | sed -n ' 546f66e55a2Smrgs/ /\\ /g 547f66e55a2Smrgs/\(.*\)/'"$tab"'\1 \\/p 548f66e55a2Smrgs/.\(.*\) \\/\1:/ 549f66e55a2SmrgH 550f66e55a2Smrg$ { 551f66e55a2Smrg s/.*/'"$tab"'/ 552f66e55a2Smrg G 553f66e55a2Smrg p 554f66e55a2Smrg}' >> "$depfile" 55527935385Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556f66e55a2Smrg rm -f "$tmpdepfile" 557f66e55a2Smrg ;; 558f66e55a2Smrg 559f66e55a2Smrgmsvc7msys) 560f66e55a2Smrg # This case exists only to let depend.m4 do its work. It works by 561f66e55a2Smrg # looking at the text of this script. This case will never be run, 562f66e55a2Smrg # since it is checked for above. 563f66e55a2Smrg exit 1 564f66e55a2Smrg ;; 56529459361Smrg 56629459361Smrg#nosideeffect) 56729459361Smrg # This comment above is used by automake to tell side-effect 56829459361Smrg # dependency tracking mechanisms from slower ones. 56929459361Smrg 57029459361Smrgdashmstdout) 57129459361Smrg # Important note: in order to support this mode, a compiler *must* 57229459361Smrg # always write the preprocessed file to stdout, regardless of -o. 57329459361Smrg "$@" || exit $? 57429459361Smrg 57529459361Smrg # Remove the call to Libtool. 57629459361Smrg if test "$libtool" = yes; then 5775715adc0Smrg while test "X$1" != 'X--mode=compile'; do 57829459361Smrg shift 57929459361Smrg done 58029459361Smrg shift 58129459361Smrg fi 58229459361Smrg 583f66e55a2Smrg # Remove '-o $object'. 58429459361Smrg IFS=" " 58529459361Smrg for arg 58629459361Smrg do 58729459361Smrg case $arg in 58829459361Smrg -o) 58929459361Smrg shift 59029459361Smrg ;; 59129459361Smrg $object) 59229459361Smrg shift 59329459361Smrg ;; 59429459361Smrg *) 59529459361Smrg set fnord "$@" "$arg" 59629459361Smrg shift # fnord 59729459361Smrg shift # $arg 59829459361Smrg ;; 59929459361Smrg esac 60029459361Smrg done 60129459361Smrg 60229459361Smrg test -z "$dashmflag" && dashmflag=-M 603f66e55a2Smrg # Require at least two characters before searching for ':' 60429459361Smrg # in the target name. This is to cope with DOS-style filenames: 605f66e55a2Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60629459361Smrg "$@" $dashmflag | 607f66e55a2Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60829459361Smrg rm -f "$depfile" 60929459361Smrg cat < "$tmpdepfile" > "$depfile" 610f66e55a2Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611f66e55a2Smrg # correctly. Breaking it into two sed invocations is a workaround. 612f66e55a2Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613f66e55a2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614f66e55a2Smrg | sed -e 's/$/ :/' >> "$depfile" 61529459361Smrg rm -f "$tmpdepfile" 61629459361Smrg ;; 61729459361Smrg 61829459361SmrgdashXmstdout) 61929459361Smrg # This case only exists to satisfy depend.m4. It is never actually 62029459361Smrg # run, as this mode is specially recognized in the preamble. 62129459361Smrg exit 1 62229459361Smrg ;; 62329459361Smrg 62429459361Smrgmakedepend) 62529459361Smrg "$@" || exit $? 62629459361Smrg # Remove any Libtool call 62729459361Smrg if test "$libtool" = yes; then 6285715adc0Smrg while test "X$1" != 'X--mode=compile'; do 62929459361Smrg shift 63029459361Smrg done 63129459361Smrg shift 63229459361Smrg fi 63329459361Smrg # X makedepend 63429459361Smrg shift 6355715adc0Smrg cleared=no eat=no 6365715adc0Smrg for arg 6375715adc0Smrg do 63829459361Smrg case $cleared in 63929459361Smrg no) 64029459361Smrg set ""; shift 64129459361Smrg cleared=yes ;; 64229459361Smrg esac 6435715adc0Smrg if test $eat = yes; then 6445715adc0Smrg eat=no 6455715adc0Smrg continue 6465715adc0Smrg fi 64729459361Smrg case "$arg" in 64829459361Smrg -D*|-I*) 64929459361Smrg set fnord "$@" "$arg"; shift ;; 65029459361Smrg # Strip any option that makedepend may not understand. Remove 65129459361Smrg # the object too, otherwise makedepend will parse it as a source file. 6525715adc0Smrg -arch) 6535715adc0Smrg eat=yes ;; 65429459361Smrg -*|$object) 65529459361Smrg ;; 65629459361Smrg *) 65729459361Smrg set fnord "$@" "$arg"; shift ;; 65829459361Smrg esac 65929459361Smrg done 6605715adc0Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66129459361Smrg touch "$tmpdepfile" 66229459361Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66329459361Smrg rm -f "$depfile" 664f66e55a2Smrg # makedepend may prepend the VPATH from the source file name to the object. 665f66e55a2Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666f66e55a2Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667f66e55a2Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668f66e55a2Smrg # correctly. Breaking it into two sed invocations is a workaround. 669f66e55a2Smrg sed '1,2d' "$tmpdepfile" \ 670f66e55a2Smrg | tr ' ' "$nl" \ 671f66e55a2Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672f66e55a2Smrg | sed -e 's/$/ :/' >> "$depfile" 67329459361Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67429459361Smrg ;; 67529459361Smrg 67629459361Smrgcpp) 67729459361Smrg # Important note: in order to support this mode, a compiler *must* 67829459361Smrg # always write the preprocessed file to stdout. 67929459361Smrg "$@" || exit $? 68029459361Smrg 68129459361Smrg # Remove the call to Libtool. 68229459361Smrg if test "$libtool" = yes; then 6835715adc0Smrg while test "X$1" != 'X--mode=compile'; do 68429459361Smrg shift 68529459361Smrg done 68629459361Smrg shift 68729459361Smrg fi 68829459361Smrg 689f66e55a2Smrg # Remove '-o $object'. 69029459361Smrg IFS=" " 69129459361Smrg for arg 69229459361Smrg do 69329459361Smrg case $arg in 69429459361Smrg -o) 69529459361Smrg shift 69629459361Smrg ;; 69729459361Smrg $object) 69829459361Smrg shift 69929459361Smrg ;; 70029459361Smrg *) 70129459361Smrg set fnord "$@" "$arg" 70229459361Smrg shift # fnord 70329459361Smrg shift # $arg 70429459361Smrg ;; 70529459361Smrg esac 70629459361Smrg done 70729459361Smrg 708f66e55a2Smrg "$@" -E \ 709f66e55a2Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710f66e55a2Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711f66e55a2Smrg | sed '$ s: \\$::' > "$tmpdepfile" 71229459361Smrg rm -f "$depfile" 71329459361Smrg echo "$object : \\" > "$depfile" 71429459361Smrg cat < "$tmpdepfile" >> "$depfile" 71529459361Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71629459361Smrg rm -f "$tmpdepfile" 71729459361Smrg ;; 71829459361Smrg 71929459361Smrgmsvisualcpp) 72029459361Smrg # Important note: in order to support this mode, a compiler *must* 7215715adc0Smrg # always write the preprocessed file to stdout. 72229459361Smrg "$@" || exit $? 7235715adc0Smrg 7245715adc0Smrg # Remove the call to Libtool. 7255715adc0Smrg if test "$libtool" = yes; then 7265715adc0Smrg while test "X$1" != 'X--mode=compile'; do 7275715adc0Smrg shift 7285715adc0Smrg done 7295715adc0Smrg shift 7305715adc0Smrg fi 7315715adc0Smrg 73229459361Smrg IFS=" " 73329459361Smrg for arg 73429459361Smrg do 73529459361Smrg case "$arg" in 7365715adc0Smrg -o) 7375715adc0Smrg shift 7385715adc0Smrg ;; 7395715adc0Smrg $object) 7405715adc0Smrg shift 7415715adc0Smrg ;; 74229459361Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743f66e55a2Smrg set fnord "$@" 744f66e55a2Smrg shift 745f66e55a2Smrg shift 746f66e55a2Smrg ;; 74729459361Smrg *) 748f66e55a2Smrg set fnord "$@" "$arg" 749f66e55a2Smrg shift 750f66e55a2Smrg shift 751f66e55a2Smrg ;; 75229459361Smrg esac 75329459361Smrg done 7545715adc0Smrg "$@" -E 2>/dev/null | 7555715adc0Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75629459361Smrg rm -f "$depfile" 75729459361Smrg echo "$object : \\" > "$depfile" 758f66e55a2Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759f66e55a2Smrg echo "$tab" >> "$depfile" 7605715adc0Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76129459361Smrg rm -f "$tmpdepfile" 76229459361Smrg ;; 76329459361Smrg 7645715adc0Smrgmsvcmsys) 7655715adc0Smrg # This case exists only to let depend.m4 do its work. It works by 7665715adc0Smrg # looking at the text of this script. This case will never be run, 7675715adc0Smrg # since it is checked for above. 7685715adc0Smrg exit 1 7695715adc0Smrg ;; 7705715adc0Smrg 77129459361Smrgnone) 77229459361Smrg exec "$@" 77329459361Smrg ;; 77429459361Smrg 77529459361Smrg*) 77629459361Smrg echo "Unknown depmode $depmode" 1>&2 77729459361Smrg exit 1 77829459361Smrg ;; 77929459361Smrgesac 78029459361Smrg 78129459361Smrgexit 0 78229459361Smrg 78329459361Smrg# Local Variables: 78429459361Smrg# mode: shell-script 78529459361Smrg# sh-indentation: 2 786291ca6f5Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 78729459361Smrg# time-stamp-start: "scriptversion=" 78829459361Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789291ca6f5Smrg# time-stamp-time-zone: "UTC0" 7905715adc0Smrg# time-stamp-end: "; # UTC" 79129459361Smrg# End: 792