164ce7165Smrg#! /bin/sh 264ce7165Smrg# depcomp - compile a program generating dependencies as side-effects 364ce7165Smrg 4b71ad168Smrgscriptversion=2018-03-07.03; # UTC 564ce7165Smrg 6b71ad168Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 764ce7165Smrg 864ce7165Smrg# This program is free software; you can redistribute it and/or modify 964ce7165Smrg# it under the terms of the GNU General Public License as published by 1064ce7165Smrg# the Free Software Foundation; either version 2, or (at your option) 1164ce7165Smrg# any later version. 1264ce7165Smrg 1364ce7165Smrg# This program is distributed in the hope that it will be useful, 1464ce7165Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1564ce7165Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1664ce7165Smrg# GNU General Public License for more details. 1764ce7165Smrg 1864ce7165Smrg# You should have received a copy of the GNU General Public License 19b71ad168Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2064ce7165Smrg 2164ce7165Smrg# As a special exception to the GNU General Public License, if you 2264ce7165Smrg# distribute this file as part of a program that contains a 2364ce7165Smrg# configuration script generated by Autoconf, you may include it under 2464ce7165Smrg# the same distribution terms that you use for the rest of that program. 2564ce7165Smrg 2664ce7165Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2764ce7165Smrg 2864ce7165Smrgcase $1 in 2964ce7165Smrg '') 3081440437Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3181440437Smrg exit 1; 3281440437Smrg ;; 3364ce7165Smrg -h | --h*) 3464ce7165Smrg cat <<\EOF 3564ce7165SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3664ce7165Smrg 3764ce7165SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3864ce7165Smrgas side-effects. 3964ce7165Smrg 4064ce7165SmrgEnvironment variables: 4164ce7165Smrg depmode Dependency tracking mode. 4281440437Smrg source Source file read by 'PROGRAMS ARGS'. 4381440437Smrg object Object file output by 'PROGRAMS ARGS'. 4464ce7165Smrg DEPDIR directory where to store dependencies. 4564ce7165Smrg depfile Dependency file to output. 4681440437Smrg tmpdepfile Temporary file to use when outputting dependencies. 4764ce7165Smrg libtool Whether libtool is used (yes/no). 4864ce7165Smrg 4964ce7165SmrgReport bugs to <bug-automake@gnu.org>. 5064ce7165SmrgEOF 5164ce7165Smrg exit $? 5264ce7165Smrg ;; 5364ce7165Smrg -v | --v*) 5464ce7165Smrg echo "depcomp $scriptversion" 5564ce7165Smrg exit $? 5664ce7165Smrg ;; 5764ce7165Smrgesac 5864ce7165Smrg 5981440437Smrg# Get the directory component of the given path, and save it in the 6081440437Smrg# global variables '$dir'. Note that this directory component will 6181440437Smrg# be either empty or ending with a '/' character. This is deliberate. 6281440437Smrgset_dir_from () 6381440437Smrg{ 6481440437Smrg case $1 in 6581440437Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6681440437Smrg *) dir=;; 6781440437Smrg esac 6881440437Smrg} 6981440437Smrg 7081440437Smrg# Get the suffix-stripped basename of the given path, and save it the 7181440437Smrg# global variable '$base'. 7281440437Smrgset_base_from () 7381440437Smrg{ 7481440437Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7581440437Smrg} 7681440437Smrg 7781440437Smrg# If no dependency file was actually created by the compiler invocation, 7881440437Smrg# we still have to create a dummy depfile, to avoid errors with the 7981440437Smrg# Makefile "include basename.Plo" scheme. 8081440437Smrgmake_dummy_depfile () 8181440437Smrg{ 8281440437Smrg echo "#dummy" > "$depfile" 8381440437Smrg} 8481440437Smrg 8581440437Smrg# Factor out some common post-processing of the generated depfile. 8681440437Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8781440437Smrgaix_post_process_depfile () 8881440437Smrg{ 8981440437Smrg # If the compiler actually managed to produce a dependency file, 9081440437Smrg # post-process it. 9181440437Smrg if test -f "$tmpdepfile"; then 9281440437Smrg # Each line is of the form 'foo.o: dependency.h'. 9381440437Smrg # Do two passes, one to just change these to 9481440437Smrg # $object: dependency.h 9581440437Smrg # and one to simply output 9681440437Smrg # dependency.h: 9781440437Smrg # which is needed to avoid the deleted-header problem. 9881440437Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9981440437Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10081440437Smrg } > "$depfile" 10181440437Smrg rm -f "$tmpdepfile" 10281440437Smrg else 10381440437Smrg make_dummy_depfile 10481440437Smrg fi 10581440437Smrg} 10681440437Smrg 10781440437Smrg# A tabulation character. 10881440437Smrgtab=' ' 10981440437Smrg# A newline character. 11081440437Smrgnl=' 11181440437Smrg' 11281440437Smrg# Character ranges might be problematic outside the C locale. 11381440437Smrg# These definitions help. 11481440437Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11581440437Smrglower=abcdefghijklmnopqrstuvwxyz 11681440437Smrgdigits=0123456789 11781440437Smrgalpha=${upper}${lower} 11881440437Smrg 11964ce7165Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12064ce7165Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12164ce7165Smrg exit 1 12264ce7165Smrgfi 12364ce7165Smrg 12464ce7165Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12564ce7165Smrgdepfile=${depfile-`echo "$object" | 12664ce7165Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12764ce7165Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12864ce7165Smrg 12964ce7165Smrgrm -f "$tmpdepfile" 13064ce7165Smrg 13181440437Smrg# Avoid interferences from the environment. 13281440437Smrggccflag= dashmflag= 13381440437Smrg 13464ce7165Smrg# Some modes work just like other modes, but use different flags. We 13564ce7165Smrg# parameterize here, but still list the modes in the big case below, 13664ce7165Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13764ce7165Smrg# here, because this file can only contain one case statement. 13864ce7165Smrgif test "$depmode" = hp; then 13964ce7165Smrg # HP compiler uses -M and no extra arg. 14064ce7165Smrg gccflag=-M 14164ce7165Smrg depmode=gcc 14264ce7165Smrgfi 14364ce7165Smrg 14464ce7165Smrgif test "$depmode" = dashXmstdout; then 14581440437Smrg # This is just like dashmstdout with a different argument. 14681440437Smrg dashmflag=-xM 14781440437Smrg depmode=dashmstdout 14864ce7165Smrgfi 14964ce7165Smrg 150fb23d3a8Smrgcygpath_u="cygpath -u -f -" 151fb23d3a8Smrgif test "$depmode" = msvcmsys; then 15281440437Smrg # This is just like msvisualcpp but w/o cygpath translation. 15381440437Smrg # Just convert the backslash-escaped backslashes to single forward 15481440437Smrg # slashes to satisfy depend.m4 15581440437Smrg cygpath_u='sed s,\\\\,/,g' 15681440437Smrg depmode=msvisualcpp 15781440437Smrgfi 15881440437Smrg 15981440437Smrgif test "$depmode" = msvc7msys; then 16081440437Smrg # This is just like msvc7 but w/o cygpath translation. 16181440437Smrg # Just convert the backslash-escaped backslashes to single forward 16281440437Smrg # slashes to satisfy depend.m4 16381440437Smrg cygpath_u='sed s,\\\\,/,g' 16481440437Smrg depmode=msvc7 16581440437Smrgfi 16681440437Smrg 16781440437Smrgif test "$depmode" = xlc; then 16881440437Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16981440437Smrg gccflag=-qmakedep=gcc,-MF 17081440437Smrg depmode=gcc 171fb23d3a8Smrgfi 172fb23d3a8Smrg 17364ce7165Smrgcase "$depmode" in 17464ce7165Smrggcc3) 17564ce7165Smrg## gcc 3 implements dependency tracking that does exactly what 17664ce7165Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17764ce7165Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 17864ce7165Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 17964ce7165Smrg## the command line argument order; so add the flags where they 18064ce7165Smrg## appear in depend2.am. Note that the slowdown incurred here 18164ce7165Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 18264ce7165Smrg for arg 18364ce7165Smrg do 18464ce7165Smrg case $arg in 18564ce7165Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 18664ce7165Smrg *) set fnord "$@" "$arg" ;; 18764ce7165Smrg esac 18864ce7165Smrg shift # fnord 18964ce7165Smrg shift # $arg 19064ce7165Smrg done 19164ce7165Smrg "$@" 19264ce7165Smrg stat=$? 19381440437Smrg if test $stat -ne 0; then 19464ce7165Smrg rm -f "$tmpdepfile" 19564ce7165Smrg exit $stat 19664ce7165Smrg fi 19764ce7165Smrg mv "$tmpdepfile" "$depfile" 19864ce7165Smrg ;; 19964ce7165Smrg 20064ce7165Smrggcc) 20181440437Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20281440437Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20381440437Smrg## (see the conditional assignment to $gccflag above). 20464ce7165Smrg## There are various ways to get dependency output from gcc. Here's 20564ce7165Smrg## why we pick this rather obscure method: 20664ce7165Smrg## - Don't want to use -MD because we'd like the dependencies to end 20764ce7165Smrg## up in a subdir. Having to rename by hand is ugly. 20864ce7165Smrg## (We might end up doing this anyway to support other compilers.) 20964ce7165Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21081440437Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21181440437Smrg## supported by the other compilers which use the 'gcc' depmode. 21264ce7165Smrg## - Using -M directly means running the compiler twice (even worse 21364ce7165Smrg## than renaming). 21464ce7165Smrg if test -z "$gccflag"; then 21564ce7165Smrg gccflag=-MD, 21664ce7165Smrg fi 21764ce7165Smrg "$@" -Wp,"$gccflag$tmpdepfile" 21864ce7165Smrg stat=$? 21981440437Smrg if test $stat -ne 0; then 22064ce7165Smrg rm -f "$tmpdepfile" 22164ce7165Smrg exit $stat 22264ce7165Smrg fi 22364ce7165Smrg rm -f "$depfile" 22464ce7165Smrg echo "$object : \\" > "$depfile" 22581440437Smrg # The second -e expression handles DOS-style file names with drive 22681440437Smrg # letters. 22764ce7165Smrg sed -e 's/^[^:]*: / /' \ 22864ce7165Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22981440437Smrg## This next piece of magic avoids the "deleted header file" problem. 23064ce7165Smrg## The problem is that when a header file which appears in a .P file 23164ce7165Smrg## is deleted, the dependency causes make to die (because there is 23264ce7165Smrg## typically no way to rebuild the header). We avoid this by adding 23364ce7165Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 23464ce7165Smrg## this for us directly. 23581440437Smrg## Some versions of gcc put a space before the ':'. On the theory 23664ce7165Smrg## that the space means something, we add a space to the output as 23781440437Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23881440437Smrg## to the object. Take care to not repeat it in the output. 23964ce7165Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 24064ce7165Smrg## correctly. Breaking it into two sed invocations is a workaround. 24181440437Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24281440437Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24381440437Smrg | sed -e 's/$/ :/' >> "$depfile" 24464ce7165Smrg rm -f "$tmpdepfile" 24564ce7165Smrg ;; 24664ce7165Smrg 24764ce7165Smrghp) 24864ce7165Smrg # This case exists only to let depend.m4 do its work. It works by 24964ce7165Smrg # looking at the text of this script. This case will never be run, 25064ce7165Smrg # since it is checked for above. 25164ce7165Smrg exit 1 25264ce7165Smrg ;; 25364ce7165Smrg 25464ce7165Smrgsgi) 25564ce7165Smrg if test "$libtool" = yes; then 25664ce7165Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25764ce7165Smrg else 25864ce7165Smrg "$@" -MDupdate "$tmpdepfile" 25964ce7165Smrg fi 26064ce7165Smrg stat=$? 26181440437Smrg if test $stat -ne 0; then 26264ce7165Smrg rm -f "$tmpdepfile" 26364ce7165Smrg exit $stat 26464ce7165Smrg fi 26564ce7165Smrg rm -f "$depfile" 26664ce7165Smrg 26764ce7165Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26864ce7165Smrg echo "$object : \\" > "$depfile" 26964ce7165Smrg # Clip off the initial element (the dependent). Don't try to be 27064ce7165Smrg # clever and replace this with sed code, as IRIX sed won't handle 27164ce7165Smrg # lines with more than a fixed number of characters (4096 in 27264ce7165Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27381440437Smrg # the IRIX cc adds comments like '#:fec' to the end of the 27464ce7165Smrg # dependency line. 27581440437Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27681440437Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27781440437Smrg | tr "$nl" ' ' >> "$depfile" 278fb23d3a8Smrg echo >> "$depfile" 27964ce7165Smrg # The second pass generates a dummy entry for each header file. 28081440437Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28181440437Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28281440437Smrg >> "$depfile" 28364ce7165Smrg else 28481440437Smrg make_dummy_depfile 28564ce7165Smrg fi 28664ce7165Smrg rm -f "$tmpdepfile" 28764ce7165Smrg ;; 28864ce7165Smrg 28981440437Smrgxlc) 29081440437Smrg # This case exists only to let depend.m4 do its work. It works by 29181440437Smrg # looking at the text of this script. This case will never be run, 29281440437Smrg # since it is checked for above. 29381440437Smrg exit 1 29481440437Smrg ;; 29581440437Smrg 29664ce7165Smrgaix) 29764ce7165Smrg # The C for AIX Compiler uses -M and outputs the dependencies 29864ce7165Smrg # in a .u file. In older versions, this file always lives in the 29981440437Smrg # current directory. Also, the AIX compiler puts '$object:' at the 30064ce7165Smrg # start of each line; $object doesn't have directory information. 30164ce7165Smrg # Version 6 uses the directory in both cases. 30281440437Smrg set_dir_from "$object" 30381440437Smrg set_base_from "$object" 30464ce7165Smrg if test "$libtool" = yes; then 305fb23d3a8Smrg tmpdepfile1=$dir$base.u 306fb23d3a8Smrg tmpdepfile2=$base.u 307fb23d3a8Smrg tmpdepfile3=$dir.libs/$base.u 30864ce7165Smrg "$@" -Wc,-M 30964ce7165Smrg else 310fb23d3a8Smrg tmpdepfile1=$dir$base.u 311fb23d3a8Smrg tmpdepfile2=$dir$base.u 312fb23d3a8Smrg tmpdepfile3=$dir$base.u 31364ce7165Smrg "$@" -M 31464ce7165Smrg fi 31564ce7165Smrg stat=$? 31681440437Smrg if test $stat -ne 0; then 317fb23d3a8Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31864ce7165Smrg exit $stat 31964ce7165Smrg fi 32064ce7165Smrg 321fb23d3a8Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322fb23d3a8Smrg do 323fb23d3a8Smrg test -f "$tmpdepfile" && break 324fb23d3a8Smrg done 32581440437Smrg aix_post_process_depfile 32681440437Smrg ;; 32781440437Smrg 32881440437Smrgtcc) 32981440437Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33081440437Smrg # FIXME: That version still under development at the moment of writing. 33181440437Smrg # Make that this statement remains true also for stable, released 33281440437Smrg # versions. 33381440437Smrg # It will wrap lines (doesn't matter whether long or short) with a 33481440437Smrg # trailing '\', as in: 33581440437Smrg # 33681440437Smrg # foo.o : \ 33781440437Smrg # foo.c \ 33881440437Smrg # foo.h \ 33981440437Smrg # 34081440437Smrg # It will put a trailing '\' even on the last line, and will use leading 34181440437Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34281440437Smrg # "Emit spaces for -MD"). 34381440437Smrg "$@" -MD -MF "$tmpdepfile" 34481440437Smrg stat=$? 34581440437Smrg if test $stat -ne 0; then 34681440437Smrg rm -f "$tmpdepfile" 34781440437Smrg exit $stat 34864ce7165Smrg fi 34981440437Smrg rm -f "$depfile" 35081440437Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35181440437Smrg # We have to change lines of the first kind to '$object: \'. 35281440437Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35381440437Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35481440437Smrg # dummy dependency, to avoid the deleted-header problem. 35581440437Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35664ce7165Smrg rm -f "$tmpdepfile" 35764ce7165Smrg ;; 35864ce7165Smrg 35981440437Smrg## The order of this option in the case statement is important, since the 36081440437Smrg## shell code in configure will try each of these formats in the order 36181440437Smrg## listed in this file. A plain '-MD' option would be understood by many 36281440437Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36381440437Smrgpgcc) 36481440437Smrg # Portland's C compiler understands '-MD'. 36581440437Smrg # Will always output deps to 'file.d' where file is the root name of the 36681440437Smrg # source file under compilation, even if file resides in a subdirectory. 36781440437Smrg # The object file name does not affect the name of the '.d' file. 36881440437Smrg # pgcc 10.2 will output 36964ce7165Smrg # foo.o: sub/foo.c sub/foo.h 37081440437Smrg # and will wrap long lines using '\' : 37164ce7165Smrg # foo.o: sub/foo.c ... \ 37264ce7165Smrg # sub/foo.h ... \ 37364ce7165Smrg # ... 37481440437Smrg set_dir_from "$object" 37581440437Smrg # Use the source, not the object, to determine the base name, since 37681440437Smrg # that's sadly what pgcc will do too. 37781440437Smrg set_base_from "$source" 37881440437Smrg tmpdepfile=$base.d 37981440437Smrg 38081440437Smrg # For projects that build the same source file twice into different object 38181440437Smrg # files, the pgcc approach of using the *source* file root name can cause 38281440437Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38381440437Smrg # the same $tmpdepfile. 38481440437Smrg lockdir=$base.d-lock 38581440437Smrg trap " 38681440437Smrg echo '$0: caught signal, cleaning up...' >&2 38781440437Smrg rmdir '$lockdir' 38881440437Smrg exit 1 38981440437Smrg " 1 2 13 15 39081440437Smrg numtries=100 39181440437Smrg i=$numtries 39281440437Smrg while test $i -gt 0; do 39381440437Smrg # mkdir is a portable test-and-set. 39481440437Smrg if mkdir "$lockdir" 2>/dev/null; then 39581440437Smrg # This process acquired the lock. 39681440437Smrg "$@" -MD 39781440437Smrg stat=$? 39881440437Smrg # Release the lock. 39981440437Smrg rmdir "$lockdir" 40081440437Smrg break 40181440437Smrg else 40281440437Smrg # If the lock is being held by a different process, wait 40381440437Smrg # until the winning process is done or we timeout. 40481440437Smrg while test -d "$lockdir" && test $i -gt 0; do 40581440437Smrg sleep 1 40681440437Smrg i=`expr $i - 1` 40781440437Smrg done 40881440437Smrg fi 40981440437Smrg i=`expr $i - 1` 41081440437Smrg done 41181440437Smrg trap - 1 2 13 15 41281440437Smrg if test $i -le 0; then 41381440437Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41481440437Smrg echo "$0: check lockdir '$lockdir'" >&2 41581440437Smrg exit 1 41681440437Smrg fi 41764ce7165Smrg 41881440437Smrg if test $stat -ne 0; then 41964ce7165Smrg rm -f "$tmpdepfile" 42064ce7165Smrg exit $stat 42164ce7165Smrg fi 42264ce7165Smrg rm -f "$depfile" 42364ce7165Smrg # Each line is of the form `foo.o: dependent.h', 42464ce7165Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42564ce7165Smrg # Do two passes, one to just change these to 42664ce7165Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 42764ce7165Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42864ce7165Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 42964ce7165Smrg # correctly. Breaking it into two sed invocations is a workaround. 43081440437Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43181440437Smrg | sed -e 's/$/ :/' >> "$depfile" 43264ce7165Smrg rm -f "$tmpdepfile" 43364ce7165Smrg ;; 43464ce7165Smrg 43564ce7165Smrghp2) 43664ce7165Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 43764ce7165Smrg # compilers, which have integrated preprocessors. The correct option 43864ce7165Smrg # to use with these is +Maked; it writes dependencies to a file named 43964ce7165Smrg # 'foo.d', which lands next to the object file, wherever that 44064ce7165Smrg # happens to be. 44164ce7165Smrg # Much of this is similar to the tru64 case; see comments there. 44281440437Smrg set_dir_from "$object" 44381440437Smrg set_base_from "$object" 44464ce7165Smrg if test "$libtool" = yes; then 44564ce7165Smrg tmpdepfile1=$dir$base.d 44664ce7165Smrg tmpdepfile2=$dir.libs/$base.d 44764ce7165Smrg "$@" -Wc,+Maked 44864ce7165Smrg else 44964ce7165Smrg tmpdepfile1=$dir$base.d 45064ce7165Smrg tmpdepfile2=$dir$base.d 45164ce7165Smrg "$@" +Maked 45264ce7165Smrg fi 45364ce7165Smrg stat=$? 45481440437Smrg if test $stat -ne 0; then 45564ce7165Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 45664ce7165Smrg exit $stat 45764ce7165Smrg fi 45864ce7165Smrg 45964ce7165Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 46064ce7165Smrg do 46164ce7165Smrg test -f "$tmpdepfile" && break 46264ce7165Smrg done 46364ce7165Smrg if test -f "$tmpdepfile"; then 46481440437Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46581440437Smrg # Add 'dependent.h:' lines. 466fb23d3a8Smrg sed -ne '2,${ 46781440437Smrg s/^ *// 46881440437Smrg s/ \\*$// 46981440437Smrg s/$/:/ 47081440437Smrg p 47181440437Smrg }' "$tmpdepfile" >> "$depfile" 47264ce7165Smrg else 47381440437Smrg make_dummy_depfile 47464ce7165Smrg fi 47564ce7165Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 47664ce7165Smrg ;; 47764ce7165Smrg 47864ce7165Smrgtru64) 47981440437Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48081440437Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48181440437Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48281440437Smrg # dependencies in 'foo.d' instead, so we check for that too. 48381440437Smrg # Subdirectories are respected. 48481440437Smrg set_dir_from "$object" 48581440437Smrg set_base_from "$object" 48681440437Smrg 48781440437Smrg if test "$libtool" = yes; then 48881440437Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48981440437Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49081440437Smrg # in $dir$base.o.d. We have to check for both files, because 49181440437Smrg # one of the two compilations can be disabled. We should prefer 49281440437Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49381440437Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49481440437Smrg # the former would cause a distcleancheck panic. 49581440437Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49681440437Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49781440437Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49881440437Smrg "$@" -Wc,-MD 49981440437Smrg else 50081440437Smrg tmpdepfile1=$dir$base.d 50181440437Smrg tmpdepfile2=$dir$base.d 50281440437Smrg tmpdepfile3=$dir$base.d 50381440437Smrg "$@" -MD 50481440437Smrg fi 50581440437Smrg 50681440437Smrg stat=$? 50781440437Smrg if test $stat -ne 0; then 50881440437Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50981440437Smrg exit $stat 51081440437Smrg fi 51181440437Smrg 51281440437Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51381440437Smrg do 51481440437Smrg test -f "$tmpdepfile" && break 51581440437Smrg done 51681440437Smrg # Same post-processing that is required for AIX mode. 51781440437Smrg aix_post_process_depfile 51881440437Smrg ;; 51981440437Smrg 52081440437Smrgmsvc7) 52181440437Smrg if test "$libtool" = yes; then 52281440437Smrg showIncludes=-Wc,-showIncludes 52381440437Smrg else 52481440437Smrg showIncludes=-showIncludes 52581440437Smrg fi 52681440437Smrg "$@" $showIncludes > "$tmpdepfile" 52781440437Smrg stat=$? 52881440437Smrg grep -v '^Note: including file: ' "$tmpdepfile" 52981440437Smrg if test $stat -ne 0; then 53081440437Smrg rm -f "$tmpdepfile" 53181440437Smrg exit $stat 53281440437Smrg fi 53381440437Smrg rm -f "$depfile" 53481440437Smrg echo "$object : \\" > "$depfile" 53581440437Smrg # The first sed program below extracts the file names and escapes 53681440437Smrg # backslashes for cygpath. The second sed program outputs the file 53781440437Smrg # name when reading, but also accumulates all include files in the 53881440437Smrg # hold buffer in order to output them again at the end. This only 53981440437Smrg # works with sed implementations that can handle large buffers. 54081440437Smrg sed < "$tmpdepfile" -n ' 54181440437Smrg/^Note: including file: *\(.*\)/ { 54281440437Smrg s//\1/ 54381440437Smrg s/\\/\\\\/g 54481440437Smrg p 54581440437Smrg}' | $cygpath_u | sort -u | sed -n ' 54681440437Smrgs/ /\\ /g 54781440437Smrgs/\(.*\)/'"$tab"'\1 \\/p 54881440437Smrgs/.\(.*\) \\/\1:/ 54981440437SmrgH 55081440437Smrg$ { 55181440437Smrg s/.*/'"$tab"'/ 55281440437Smrg G 55381440437Smrg p 55481440437Smrg}' >> "$depfile" 55581440437Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55681440437Smrg rm -f "$tmpdepfile" 55781440437Smrg ;; 55881440437Smrg 55981440437Smrgmsvc7msys) 56081440437Smrg # This case exists only to let depend.m4 do its work. It works by 56181440437Smrg # looking at the text of this script. This case will never be run, 56281440437Smrg # since it is checked for above. 56381440437Smrg exit 1 56481440437Smrg ;; 56564ce7165Smrg 56664ce7165Smrg#nosideeffect) 56764ce7165Smrg # This comment above is used by automake to tell side-effect 56864ce7165Smrg # dependency tracking mechanisms from slower ones. 56964ce7165Smrg 57064ce7165Smrgdashmstdout) 57164ce7165Smrg # Important note: in order to support this mode, a compiler *must* 57264ce7165Smrg # always write the preprocessed file to stdout, regardless of -o. 57364ce7165Smrg "$@" || exit $? 57464ce7165Smrg 57564ce7165Smrg # Remove the call to Libtool. 57664ce7165Smrg if test "$libtool" = yes; then 577fb23d3a8Smrg while test "X$1" != 'X--mode=compile'; do 57864ce7165Smrg shift 57964ce7165Smrg done 58064ce7165Smrg shift 58164ce7165Smrg fi 58264ce7165Smrg 58381440437Smrg # Remove '-o $object'. 58464ce7165Smrg IFS=" " 58564ce7165Smrg for arg 58664ce7165Smrg do 58764ce7165Smrg case $arg in 58864ce7165Smrg -o) 58964ce7165Smrg shift 59064ce7165Smrg ;; 59164ce7165Smrg $object) 59264ce7165Smrg shift 59364ce7165Smrg ;; 59464ce7165Smrg *) 59564ce7165Smrg set fnord "$@" "$arg" 59664ce7165Smrg shift # fnord 59764ce7165Smrg shift # $arg 59864ce7165Smrg ;; 59964ce7165Smrg esac 60064ce7165Smrg done 60164ce7165Smrg 60264ce7165Smrg test -z "$dashmflag" && dashmflag=-M 60381440437Smrg # Require at least two characters before searching for ':' 60464ce7165Smrg # in the target name. This is to cope with DOS-style filenames: 60581440437Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60664ce7165Smrg "$@" $dashmflag | 60781440437Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60864ce7165Smrg rm -f "$depfile" 60964ce7165Smrg cat < "$tmpdepfile" > "$depfile" 61081440437Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61181440437Smrg # correctly. Breaking it into two sed invocations is a workaround. 61281440437Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61381440437Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61481440437Smrg | sed -e 's/$/ :/' >> "$depfile" 61564ce7165Smrg rm -f "$tmpdepfile" 61664ce7165Smrg ;; 61764ce7165Smrg 61864ce7165SmrgdashXmstdout) 61964ce7165Smrg # This case only exists to satisfy depend.m4. It is never actually 62064ce7165Smrg # run, as this mode is specially recognized in the preamble. 62164ce7165Smrg exit 1 62264ce7165Smrg ;; 62364ce7165Smrg 62464ce7165Smrgmakedepend) 62564ce7165Smrg "$@" || exit $? 62664ce7165Smrg # Remove any Libtool call 62764ce7165Smrg if test "$libtool" = yes; then 628fb23d3a8Smrg while test "X$1" != 'X--mode=compile'; do 62964ce7165Smrg shift 63064ce7165Smrg done 63164ce7165Smrg shift 63264ce7165Smrg fi 63364ce7165Smrg # X makedepend 63464ce7165Smrg shift 635fb23d3a8Smrg cleared=no eat=no 636fb23d3a8Smrg for arg 637fb23d3a8Smrg do 63864ce7165Smrg case $cleared in 63964ce7165Smrg no) 64064ce7165Smrg set ""; shift 64164ce7165Smrg cleared=yes ;; 64264ce7165Smrg esac 643fb23d3a8Smrg if test $eat = yes; then 644fb23d3a8Smrg eat=no 645fb23d3a8Smrg continue 646fb23d3a8Smrg fi 64764ce7165Smrg case "$arg" in 64864ce7165Smrg -D*|-I*) 64964ce7165Smrg set fnord "$@" "$arg"; shift ;; 65064ce7165Smrg # Strip any option that makedepend may not understand. Remove 65164ce7165Smrg # the object too, otherwise makedepend will parse it as a source file. 652fb23d3a8Smrg -arch) 653fb23d3a8Smrg eat=yes ;; 65464ce7165Smrg -*|$object) 65564ce7165Smrg ;; 65664ce7165Smrg *) 65764ce7165Smrg set fnord "$@" "$arg"; shift ;; 65864ce7165Smrg esac 65964ce7165Smrg done 660fb23d3a8Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66164ce7165Smrg touch "$tmpdepfile" 66264ce7165Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66364ce7165Smrg rm -f "$depfile" 66481440437Smrg # makedepend may prepend the VPATH from the source file name to the object. 66581440437Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66681440437Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66781440437Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66881440437Smrg # correctly. Breaking it into two sed invocations is a workaround. 66981440437Smrg sed '1,2d' "$tmpdepfile" \ 67081440437Smrg | tr ' ' "$nl" \ 67181440437Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67281440437Smrg | sed -e 's/$/ :/' >> "$depfile" 67364ce7165Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67464ce7165Smrg ;; 67564ce7165Smrg 67664ce7165Smrgcpp) 67764ce7165Smrg # Important note: in order to support this mode, a compiler *must* 67864ce7165Smrg # always write the preprocessed file to stdout. 67964ce7165Smrg "$@" || exit $? 68064ce7165Smrg 68164ce7165Smrg # Remove the call to Libtool. 68264ce7165Smrg if test "$libtool" = yes; then 683fb23d3a8Smrg while test "X$1" != 'X--mode=compile'; do 68464ce7165Smrg shift 68564ce7165Smrg done 68664ce7165Smrg shift 68764ce7165Smrg fi 68864ce7165Smrg 68981440437Smrg # Remove '-o $object'. 69064ce7165Smrg IFS=" " 69164ce7165Smrg for arg 69264ce7165Smrg do 69364ce7165Smrg case $arg in 69464ce7165Smrg -o) 69564ce7165Smrg shift 69664ce7165Smrg ;; 69764ce7165Smrg $object) 69864ce7165Smrg shift 69964ce7165Smrg ;; 70064ce7165Smrg *) 70164ce7165Smrg set fnord "$@" "$arg" 70264ce7165Smrg shift # fnord 70364ce7165Smrg shift # $arg 70464ce7165Smrg ;; 70564ce7165Smrg esac 70664ce7165Smrg done 70764ce7165Smrg 70881440437Smrg "$@" -E \ 70981440437Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71081440437Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71181440437Smrg | sed '$ s: \\$::' > "$tmpdepfile" 71264ce7165Smrg rm -f "$depfile" 71364ce7165Smrg echo "$object : \\" > "$depfile" 71464ce7165Smrg cat < "$tmpdepfile" >> "$depfile" 71564ce7165Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71664ce7165Smrg rm -f "$tmpdepfile" 71764ce7165Smrg ;; 71864ce7165Smrg 71964ce7165Smrgmsvisualcpp) 72064ce7165Smrg # Important note: in order to support this mode, a compiler *must* 721fb23d3a8Smrg # always write the preprocessed file to stdout. 72264ce7165Smrg "$@" || exit $? 723fb23d3a8Smrg 724fb23d3a8Smrg # Remove the call to Libtool. 725fb23d3a8Smrg if test "$libtool" = yes; then 726fb23d3a8Smrg while test "X$1" != 'X--mode=compile'; do 727fb23d3a8Smrg shift 728fb23d3a8Smrg done 729fb23d3a8Smrg shift 730fb23d3a8Smrg fi 731fb23d3a8Smrg 73264ce7165Smrg IFS=" " 73364ce7165Smrg for arg 73464ce7165Smrg do 73564ce7165Smrg case "$arg" in 736fb23d3a8Smrg -o) 737fb23d3a8Smrg shift 738fb23d3a8Smrg ;; 739fb23d3a8Smrg $object) 740fb23d3a8Smrg shift 741fb23d3a8Smrg ;; 74264ce7165Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74381440437Smrg set fnord "$@" 74481440437Smrg shift 74581440437Smrg shift 74681440437Smrg ;; 74764ce7165Smrg *) 74881440437Smrg set fnord "$@" "$arg" 74981440437Smrg shift 75081440437Smrg shift 75181440437Smrg ;; 75264ce7165Smrg esac 75364ce7165Smrg done 754fb23d3a8Smrg "$@" -E 2>/dev/null | 755fb23d3a8Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75664ce7165Smrg rm -f "$depfile" 75764ce7165Smrg echo "$object : \\" > "$depfile" 75881440437Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75981440437Smrg echo "$tab" >> "$depfile" 760fb23d3a8Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76164ce7165Smrg rm -f "$tmpdepfile" 76264ce7165Smrg ;; 76364ce7165Smrg 764fb23d3a8Smrgmsvcmsys) 765fb23d3a8Smrg # This case exists only to let depend.m4 do its work. It works by 766fb23d3a8Smrg # looking at the text of this script. This case will never be run, 767fb23d3a8Smrg # since it is checked for above. 768fb23d3a8Smrg exit 1 769fb23d3a8Smrg ;; 770fb23d3a8Smrg 77164ce7165Smrgnone) 77264ce7165Smrg exec "$@" 77364ce7165Smrg ;; 77464ce7165Smrg 77564ce7165Smrg*) 77664ce7165Smrg echo "Unknown depmode $depmode" 1>&2 77764ce7165Smrg exit 1 77864ce7165Smrg ;; 77964ce7165Smrgesac 78064ce7165Smrg 78164ce7165Smrgexit 0 78264ce7165Smrg 78364ce7165Smrg# Local Variables: 78464ce7165Smrg# mode: shell-script 78564ce7165Smrg# sh-indentation: 2 786b71ad168Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 78764ce7165Smrg# time-stamp-start: "scriptversion=" 78864ce7165Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789b71ad168Smrg# time-stamp-time-zone: "UTC0" 790fb23d3a8Smrg# time-stamp-end: "; # UTC" 79164ce7165Smrg# End: 792