1ea148d1dSmrg#! /bin/sh 243f32c10Smrg# depcomp - compile a program generating dependencies as side-effects 343f32c10Smrg 4d3173433Smrgscriptversion=2024-06-19.01; # UTC 543f32c10Smrg 6d3173433Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 743f32c10Smrg 843f32c10Smrg# This program is free software; you can redistribute it and/or modify 943f32c10Smrg# it under the terms of the GNU General Public License as published by 1043f32c10Smrg# the Free Software Foundation; either version 2, or (at your option) 1143f32c10Smrg# any later version. 1243f32c10Smrg 1343f32c10Smrg# This program is distributed in the hope that it will be useful, 1443f32c10Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1543f32c10Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1643f32c10Smrg# GNU General Public License for more details. 1743f32c10Smrg 1843f32c10Smrg# You should have received a copy of the GNU General Public License 19ea148d1dSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2043f32c10Smrg 2143f32c10Smrg# As a special exception to the GNU General Public License, if you 2243f32c10Smrg# distribute this file as part of a program that contains a 2343f32c10Smrg# configuration script generated by Autoconf, you may include it under 2443f32c10Smrg# the same distribution terms that you use for the rest of that program. 2543f32c10Smrg 2643f32c10Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2743f32c10Smrg 2843f32c10Smrgcase $1 in 2943f32c10Smrg '') 306ef05171Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 316ef05171Smrg exit 1; 326ef05171Smrg ;; 3343f32c10Smrg -h | --h*) 3443f32c10Smrg cat <<\EOF 3543f32c10SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3643f32c10Smrg 3743f32c10SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3843f32c10Smrgas side-effects. 3943f32c10Smrg 4043f32c10SmrgEnvironment variables: 4143f32c10Smrg depmode Dependency tracking mode. 426ef05171Smrg source Source file read by 'PROGRAMS ARGS'. 436ef05171Smrg object Object file output by 'PROGRAMS ARGS'. 4443f32c10Smrg DEPDIR directory where to store dependencies. 4543f32c10Smrg depfile Dependency file to output. 466ef05171Smrg tmpdepfile Temporary file to use when outputting dependencies. 4743f32c10Smrg libtool Whether libtool is used (yes/no). 4843f32c10Smrg 4943f32c10SmrgReport bugs to <bug-automake@gnu.org>. 50d3173433SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 51d3173433SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 5243f32c10SmrgEOF 5343f32c10Smrg exit $? 5443f32c10Smrg ;; 5543f32c10Smrg -v | --v*) 56d3173433Smrg echo "depcomp (GNU Automake) $scriptversion" 5743f32c10Smrg exit $? 5843f32c10Smrg ;; 5943f32c10Smrgesac 6043f32c10Smrg 616ef05171Smrg# Get the directory component of the given path, and save it in the 626ef05171Smrg# global variables '$dir'. Note that this directory component will 636ef05171Smrg# be either empty or ending with a '/' character. This is deliberate. 646ef05171Smrgset_dir_from () 656ef05171Smrg{ 666ef05171Smrg case $1 in 676ef05171Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 686ef05171Smrg *) dir=;; 696ef05171Smrg esac 706ef05171Smrg} 716ef05171Smrg 726ef05171Smrg# Get the suffix-stripped basename of the given path, and save it the 736ef05171Smrg# global variable '$base'. 746ef05171Smrgset_base_from () 756ef05171Smrg{ 766ef05171Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 776ef05171Smrg} 786ef05171Smrg 796ef05171Smrg# If no dependency file was actually created by the compiler invocation, 806ef05171Smrg# we still have to create a dummy depfile, to avoid errors with the 816ef05171Smrg# Makefile "include basename.Plo" scheme. 826ef05171Smrgmake_dummy_depfile () 836ef05171Smrg{ 846ef05171Smrg echo "#dummy" > "$depfile" 856ef05171Smrg} 866ef05171Smrg 876ef05171Smrg# Factor out some common post-processing of the generated depfile. 886ef05171Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 896ef05171Smrgaix_post_process_depfile () 906ef05171Smrg{ 916ef05171Smrg # If the compiler actually managed to produce a dependency file, 926ef05171Smrg # post-process it. 936ef05171Smrg if test -f "$tmpdepfile"; then 946ef05171Smrg # Each line is of the form 'foo.o: dependency.h'. 956ef05171Smrg # Do two passes, one to just change these to 966ef05171Smrg # $object: dependency.h 976ef05171Smrg # and one to simply output 986ef05171Smrg # dependency.h: 996ef05171Smrg # which is needed to avoid the deleted-header problem. 1006ef05171Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 1016ef05171Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1026ef05171Smrg } > "$depfile" 1036ef05171Smrg rm -f "$tmpdepfile" 1046ef05171Smrg else 1056ef05171Smrg make_dummy_depfile 1066ef05171Smrg fi 1076ef05171Smrg} 1086ef05171Smrg 1096ef05171Smrg# A tabulation character. 1106ef05171Smrgtab=' ' 1116ef05171Smrg# A newline character. 1126ef05171Smrgnl=' 1136ef05171Smrg' 1146ef05171Smrg# Character ranges might be problematic outside the C locale. 1156ef05171Smrg# These definitions help. 1166ef05171Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1176ef05171Smrglower=abcdefghijklmnopqrstuvwxyz 1186ef05171Smrgalpha=${upper}${lower} 1196ef05171Smrg 12043f32c10Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12143f32c10Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12243f32c10Smrg exit 1 12343f32c10Smrgfi 12443f32c10Smrg 12543f32c10Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12643f32c10Smrgdepfile=${depfile-`echo "$object" | 12743f32c10Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12843f32c10Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12943f32c10Smrg 13043f32c10Smrgrm -f "$tmpdepfile" 13143f32c10Smrg 132d3173433Smrg# Avoid interference from the environment. 1336ef05171Smrggccflag= dashmflag= 1346ef05171Smrg 13543f32c10Smrg# Some modes work just like other modes, but use different flags. We 13643f32c10Smrg# parameterize here, but still list the modes in the big case below, 13743f32c10Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13843f32c10Smrg# here, because this file can only contain one case statement. 13943f32c10Smrgif test "$depmode" = hp; then 14043f32c10Smrg # HP compiler uses -M and no extra arg. 14143f32c10Smrg gccflag=-M 14243f32c10Smrg depmode=gcc 14343f32c10Smrgfi 14443f32c10Smrg 14543f32c10Smrgif test "$depmode" = dashXmstdout; then 1466ef05171Smrg # This is just like dashmstdout with a different argument. 1476ef05171Smrg dashmflag=-xM 1486ef05171Smrg depmode=dashmstdout 1496ef05171Smrgfi 1506ef05171Smrg 1516ef05171Smrgcygpath_u="cygpath -u -f -" 1526ef05171Smrgif test "$depmode" = msvcmsys; then 1536ef05171Smrg # This is just like msvisualcpp but w/o cygpath translation. 1546ef05171Smrg # Just convert the backslash-escaped backslashes to single forward 1556ef05171Smrg # slashes to satisfy depend.m4 1566ef05171Smrg cygpath_u='sed s,\\\\,/,g' 1576ef05171Smrg depmode=msvisualcpp 1586ef05171Smrgfi 1596ef05171Smrg 1606ef05171Smrgif test "$depmode" = msvc7msys; then 1616ef05171Smrg # This is just like msvc7 but w/o cygpath translation. 1626ef05171Smrg # Just convert the backslash-escaped backslashes to single forward 1636ef05171Smrg # slashes to satisfy depend.m4 1646ef05171Smrg cygpath_u='sed s,\\\\,/,g' 1656ef05171Smrg depmode=msvc7 1666ef05171Smrgfi 1676ef05171Smrg 1686ef05171Smrgif test "$depmode" = xlc; then 1696ef05171Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1706ef05171Smrg gccflag=-qmakedep=gcc,-MF 1716ef05171Smrg depmode=gcc 17243f32c10Smrgfi 17343f32c10Smrg 17443f32c10Smrgcase "$depmode" in 17543f32c10Smrggcc3) 17643f32c10Smrg## gcc 3 implements dependency tracking that does exactly what 17743f32c10Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17843f32c10Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 17943f32c10Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 18043f32c10Smrg## the command line argument order; so add the flags where they 18143f32c10Smrg## appear in depend2.am. Note that the slowdown incurred here 18243f32c10Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 18343f32c10Smrg for arg 18443f32c10Smrg do 18543f32c10Smrg case $arg in 18643f32c10Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 18743f32c10Smrg *) set fnord "$@" "$arg" ;; 18843f32c10Smrg esac 18943f32c10Smrg shift # fnord 19043f32c10Smrg shift # $arg 19143f32c10Smrg done 19243f32c10Smrg "$@" 19343f32c10Smrg stat=$? 1946ef05171Smrg if test $stat -ne 0; then 19543f32c10Smrg rm -f "$tmpdepfile" 19643f32c10Smrg exit $stat 19743f32c10Smrg fi 19843f32c10Smrg mv "$tmpdepfile" "$depfile" 19943f32c10Smrg ;; 20043f32c10Smrg 20143f32c10Smrggcc) 202d3173433Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 203d3173433Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 2046ef05171Smrg## (see the conditional assignment to $gccflag above). 20543f32c10Smrg## There are various ways to get dependency output from gcc. Here's 20643f32c10Smrg## why we pick this rather obscure method: 20743f32c10Smrg## - Don't want to use -MD because we'd like the dependencies to end 20843f32c10Smrg## up in a subdir. Having to rename by hand is ugly. 20943f32c10Smrg## (We might end up doing this anyway to support other compilers.) 21043f32c10Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2116ef05171Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2126ef05171Smrg## supported by the other compilers which use the 'gcc' depmode. 21343f32c10Smrg## - Using -M directly means running the compiler twice (even worse 21443f32c10Smrg## than renaming). 21543f32c10Smrg if test -z "$gccflag"; then 21643f32c10Smrg gccflag=-MD, 21743f32c10Smrg fi 21843f32c10Smrg "$@" -Wp,"$gccflag$tmpdepfile" 21943f32c10Smrg stat=$? 2206ef05171Smrg if test $stat -ne 0; then 22143f32c10Smrg rm -f "$tmpdepfile" 22243f32c10Smrg exit $stat 22343f32c10Smrg fi 22443f32c10Smrg rm -f "$depfile" 22543f32c10Smrg echo "$object : \\" > "$depfile" 2266ef05171Smrg # The second -e expression handles DOS-style file names with drive 2276ef05171Smrg # letters. 22843f32c10Smrg sed -e 's/^[^:]*: / /' \ 22943f32c10Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2306ef05171Smrg## This next piece of magic avoids the "deleted header file" problem. 23143f32c10Smrg## The problem is that when a header file which appears in a .P file 23243f32c10Smrg## is deleted, the dependency causes make to die (because there is 23343f32c10Smrg## typically no way to rebuild the header). We avoid this by adding 23443f32c10Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 23543f32c10Smrg## this for us directly. 2366ef05171Smrg## Some versions of gcc put a space before the ':'. On the theory 23743f32c10Smrg## that the space means something, we add a space to the output as 2386ef05171Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 2396ef05171Smrg## to the object. Take care to not repeat it in the output. 24043f32c10Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 24143f32c10Smrg## correctly. Breaking it into two sed invocations is a workaround. 2426ef05171Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2436ef05171Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2446ef05171Smrg | sed -e 's/$/ :/' >> "$depfile" 24543f32c10Smrg rm -f "$tmpdepfile" 24643f32c10Smrg ;; 24743f32c10Smrg 24843f32c10Smrghp) 24943f32c10Smrg # This case exists only to let depend.m4 do its work. It works by 25043f32c10Smrg # looking at the text of this script. This case will never be run, 25143f32c10Smrg # since it is checked for above. 25243f32c10Smrg exit 1 25343f32c10Smrg ;; 25443f32c10Smrg 25543f32c10Smrgsgi) 25643f32c10Smrg if test "$libtool" = yes; then 25743f32c10Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25843f32c10Smrg else 25943f32c10Smrg "$@" -MDupdate "$tmpdepfile" 26043f32c10Smrg fi 26143f32c10Smrg stat=$? 2626ef05171Smrg if test $stat -ne 0; then 26343f32c10Smrg rm -f "$tmpdepfile" 26443f32c10Smrg exit $stat 26543f32c10Smrg fi 26643f32c10Smrg rm -f "$depfile" 26743f32c10Smrg 26843f32c10Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26943f32c10Smrg echo "$object : \\" > "$depfile" 27043f32c10Smrg # Clip off the initial element (the dependent). Don't try to be 27143f32c10Smrg # clever and replace this with sed code, as IRIX sed won't handle 27243f32c10Smrg # lines with more than a fixed number of characters (4096 in 27343f32c10Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2746ef05171Smrg # the IRIX cc adds comments like '#:fec' to the end of the 27543f32c10Smrg # dependency line. 2766ef05171Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2776ef05171Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2786ef05171Smrg | tr "$nl" ' ' >> "$depfile" 2796ef05171Smrg echo >> "$depfile" 28043f32c10Smrg # The second pass generates a dummy entry for each header file. 2816ef05171Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2826ef05171Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2836ef05171Smrg >> "$depfile" 28443f32c10Smrg else 2856ef05171Smrg make_dummy_depfile 28643f32c10Smrg fi 28743f32c10Smrg rm -f "$tmpdepfile" 28843f32c10Smrg ;; 28943f32c10Smrg 2906ef05171Smrgxlc) 2916ef05171Smrg # This case exists only to let depend.m4 do its work. It works by 2926ef05171Smrg # looking at the text of this script. This case will never be run, 2936ef05171Smrg # since it is checked for above. 2946ef05171Smrg exit 1 2956ef05171Smrg ;; 2966ef05171Smrg 29743f32c10Smrgaix) 29843f32c10Smrg # The C for AIX Compiler uses -M and outputs the dependencies 29943f32c10Smrg # in a .u file. In older versions, this file always lives in the 3006ef05171Smrg # current directory. Also, the AIX compiler puts '$object:' at the 30143f32c10Smrg # start of each line; $object doesn't have directory information. 30243f32c10Smrg # Version 6 uses the directory in both cases. 3036ef05171Smrg set_dir_from "$object" 3046ef05171Smrg set_base_from "$object" 30543f32c10Smrg if test "$libtool" = yes; then 30643f32c10Smrg tmpdepfile1=$dir$base.u 30743f32c10Smrg tmpdepfile2=$base.u 30843f32c10Smrg tmpdepfile3=$dir.libs/$base.u 30943f32c10Smrg "$@" -Wc,-M 31043f32c10Smrg else 31143f32c10Smrg tmpdepfile1=$dir$base.u 31243f32c10Smrg tmpdepfile2=$dir$base.u 31343f32c10Smrg tmpdepfile3=$dir$base.u 31443f32c10Smrg "$@" -M 31543f32c10Smrg fi 31643f32c10Smrg stat=$? 3176ef05171Smrg if test $stat -ne 0; then 31843f32c10Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31943f32c10Smrg exit $stat 32043f32c10Smrg fi 32143f32c10Smrg 32243f32c10Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32343f32c10Smrg do 32443f32c10Smrg test -f "$tmpdepfile" && break 32543f32c10Smrg done 3266ef05171Smrg aix_post_process_depfile 3276ef05171Smrg ;; 3286ef05171Smrg 3296ef05171Smrgtcc) 3306ef05171Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3316ef05171Smrg # FIXME: That version still under development at the moment of writing. 3326ef05171Smrg # Make that this statement remains true also for stable, released 3336ef05171Smrg # versions. 3346ef05171Smrg # It will wrap lines (doesn't matter whether long or short) with a 3356ef05171Smrg # trailing '\', as in: 3366ef05171Smrg # 3376ef05171Smrg # foo.o : \ 3386ef05171Smrg # foo.c \ 3396ef05171Smrg # foo.h \ 3406ef05171Smrg # 3416ef05171Smrg # It will put a trailing '\' even on the last line, and will use leading 3426ef05171Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3436ef05171Smrg # "Emit spaces for -MD"). 3446ef05171Smrg "$@" -MD -MF "$tmpdepfile" 3456ef05171Smrg stat=$? 3466ef05171Smrg if test $stat -ne 0; then 3476ef05171Smrg rm -f "$tmpdepfile" 3486ef05171Smrg exit $stat 34943f32c10Smrg fi 3506ef05171Smrg rm -f "$depfile" 3516ef05171Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3526ef05171Smrg # We have to change lines of the first kind to '$object: \'. 3536ef05171Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3546ef05171Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3556ef05171Smrg # dummy dependency, to avoid the deleted-header problem. 3566ef05171Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35743f32c10Smrg rm -f "$tmpdepfile" 35843f32c10Smrg ;; 35943f32c10Smrg 3606ef05171Smrg## The order of this option in the case statement is important, since the 3616ef05171Smrg## shell code in configure will try each of these formats in the order 3626ef05171Smrg## listed in this file. A plain '-MD' option would be understood by many 3636ef05171Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3646ef05171Smrgpgcc) 3656ef05171Smrg # Portland's C compiler understands '-MD'. 3666ef05171Smrg # Will always output deps to 'file.d' where file is the root name of the 3676ef05171Smrg # source file under compilation, even if file resides in a subdirectory. 3686ef05171Smrg # The object file name does not affect the name of the '.d' file. 3696ef05171Smrg # pgcc 10.2 will output 37043f32c10Smrg # foo.o: sub/foo.c sub/foo.h 3716ef05171Smrg # and will wrap long lines using '\' : 37243f32c10Smrg # foo.o: sub/foo.c ... \ 37343f32c10Smrg # sub/foo.h ... \ 37443f32c10Smrg # ... 3756ef05171Smrg set_dir_from "$object" 3766ef05171Smrg # Use the source, not the object, to determine the base name, since 3776ef05171Smrg # that's sadly what pgcc will do too. 3786ef05171Smrg set_base_from "$source" 3796ef05171Smrg tmpdepfile=$base.d 3806ef05171Smrg 3816ef05171Smrg # For projects that build the same source file twice into different object 3826ef05171Smrg # files, the pgcc approach of using the *source* file root name can cause 3836ef05171Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3846ef05171Smrg # the same $tmpdepfile. 3856ef05171Smrg lockdir=$base.d-lock 3866ef05171Smrg trap " 3876ef05171Smrg echo '$0: caught signal, cleaning up...' >&2 3886ef05171Smrg rmdir '$lockdir' 3896ef05171Smrg exit 1 3906ef05171Smrg " 1 2 13 15 3916ef05171Smrg numtries=100 3926ef05171Smrg i=$numtries 3936ef05171Smrg while test $i -gt 0; do 3946ef05171Smrg # mkdir is a portable test-and-set. 3956ef05171Smrg if mkdir "$lockdir" 2>/dev/null; then 3966ef05171Smrg # This process acquired the lock. 3976ef05171Smrg "$@" -MD 3986ef05171Smrg stat=$? 3996ef05171Smrg # Release the lock. 4006ef05171Smrg rmdir "$lockdir" 4016ef05171Smrg break 4026ef05171Smrg else 4036ef05171Smrg # If the lock is being held by a different process, wait 4046ef05171Smrg # until the winning process is done or we timeout. 4056ef05171Smrg while test -d "$lockdir" && test $i -gt 0; do 4066ef05171Smrg sleep 1 4076ef05171Smrg i=`expr $i - 1` 4086ef05171Smrg done 4096ef05171Smrg fi 4106ef05171Smrg i=`expr $i - 1` 4116ef05171Smrg done 4126ef05171Smrg trap - 1 2 13 15 4136ef05171Smrg if test $i -le 0; then 4146ef05171Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4156ef05171Smrg echo "$0: check lockdir '$lockdir'" >&2 4166ef05171Smrg exit 1 4176ef05171Smrg fi 41843f32c10Smrg 4196ef05171Smrg if test $stat -ne 0; then 42043f32c10Smrg rm -f "$tmpdepfile" 42143f32c10Smrg exit $stat 42243f32c10Smrg fi 42343f32c10Smrg rm -f "$depfile" 42443f32c10Smrg # Each line is of the form `foo.o: dependent.h', 42543f32c10Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42643f32c10Smrg # Do two passes, one to just change these to 42743f32c10Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 42843f32c10Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42943f32c10Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 43043f32c10Smrg # correctly. Breaking it into two sed invocations is a workaround. 4316ef05171Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4326ef05171Smrg | sed -e 's/$/ :/' >> "$depfile" 43343f32c10Smrg rm -f "$tmpdepfile" 43443f32c10Smrg ;; 43543f32c10Smrg 43643f32c10Smrghp2) 43743f32c10Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 43843f32c10Smrg # compilers, which have integrated preprocessors. The correct option 43943f32c10Smrg # to use with these is +Maked; it writes dependencies to a file named 44043f32c10Smrg # 'foo.d', which lands next to the object file, wherever that 44143f32c10Smrg # happens to be. 44243f32c10Smrg # Much of this is similar to the tru64 case; see comments there. 4436ef05171Smrg set_dir_from "$object" 4446ef05171Smrg set_base_from "$object" 44543f32c10Smrg if test "$libtool" = yes; then 44643f32c10Smrg tmpdepfile1=$dir$base.d 44743f32c10Smrg tmpdepfile2=$dir.libs/$base.d 44843f32c10Smrg "$@" -Wc,+Maked 44943f32c10Smrg else 45043f32c10Smrg tmpdepfile1=$dir$base.d 45143f32c10Smrg tmpdepfile2=$dir$base.d 45243f32c10Smrg "$@" +Maked 45343f32c10Smrg fi 45443f32c10Smrg stat=$? 4556ef05171Smrg if test $stat -ne 0; then 45643f32c10Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 45743f32c10Smrg exit $stat 45843f32c10Smrg fi 45943f32c10Smrg 46043f32c10Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 46143f32c10Smrg do 46243f32c10Smrg test -f "$tmpdepfile" && break 46343f32c10Smrg done 46443f32c10Smrg if test -f "$tmpdepfile"; then 4656ef05171Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4666ef05171Smrg # Add 'dependent.h:' lines. 4676ef05171Smrg sed -ne '2,${ 4686ef05171Smrg s/^ *// 4696ef05171Smrg s/ \\*$// 4706ef05171Smrg s/$/:/ 4716ef05171Smrg p 4726ef05171Smrg }' "$tmpdepfile" >> "$depfile" 47343f32c10Smrg else 4746ef05171Smrg make_dummy_depfile 47543f32c10Smrg fi 47643f32c10Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 47743f32c10Smrg ;; 47843f32c10Smrg 47943f32c10Smrgtru64) 4806ef05171Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4816ef05171Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4826ef05171Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4836ef05171Smrg # dependencies in 'foo.d' instead, so we check for that too. 4846ef05171Smrg # Subdirectories are respected. 4856ef05171Smrg set_dir_from "$object" 4866ef05171Smrg set_base_from "$object" 4876ef05171Smrg 4886ef05171Smrg if test "$libtool" = yes; then 4896ef05171Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4906ef05171Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4916ef05171Smrg # in $dir$base.o.d. We have to check for both files, because 4926ef05171Smrg # one of the two compilations can be disabled. We should prefer 4936ef05171Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4946ef05171Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4956ef05171Smrg # the former would cause a distcleancheck panic. 4966ef05171Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4976ef05171Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4986ef05171Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4996ef05171Smrg "$@" -Wc,-MD 5006ef05171Smrg else 5016ef05171Smrg tmpdepfile1=$dir$base.d 5026ef05171Smrg tmpdepfile2=$dir$base.d 5036ef05171Smrg tmpdepfile3=$dir$base.d 5046ef05171Smrg "$@" -MD 5056ef05171Smrg fi 5066ef05171Smrg 5076ef05171Smrg stat=$? 5086ef05171Smrg if test $stat -ne 0; then 5096ef05171Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5106ef05171Smrg exit $stat 5116ef05171Smrg fi 5126ef05171Smrg 5136ef05171Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5146ef05171Smrg do 5156ef05171Smrg test -f "$tmpdepfile" && break 5166ef05171Smrg done 5176ef05171Smrg # Same post-processing that is required for AIX mode. 5186ef05171Smrg aix_post_process_depfile 5196ef05171Smrg ;; 5206ef05171Smrg 5216ef05171Smrgmsvc7) 5226ef05171Smrg if test "$libtool" = yes; then 5236ef05171Smrg showIncludes=-Wc,-showIncludes 5246ef05171Smrg else 5256ef05171Smrg showIncludes=-showIncludes 5266ef05171Smrg fi 5276ef05171Smrg "$@" $showIncludes > "$tmpdepfile" 5286ef05171Smrg stat=$? 5296ef05171Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5306ef05171Smrg if test $stat -ne 0; then 5316ef05171Smrg rm -f "$tmpdepfile" 5326ef05171Smrg exit $stat 5336ef05171Smrg fi 5346ef05171Smrg rm -f "$depfile" 5356ef05171Smrg echo "$object : \\" > "$depfile" 5366ef05171Smrg # The first sed program below extracts the file names and escapes 5376ef05171Smrg # backslashes for cygpath. The second sed program outputs the file 5386ef05171Smrg # name when reading, but also accumulates all include files in the 5396ef05171Smrg # hold buffer in order to output them again at the end. This only 5406ef05171Smrg # works with sed implementations that can handle large buffers. 5416ef05171Smrg sed < "$tmpdepfile" -n ' 5426ef05171Smrg/^Note: including file: *\(.*\)/ { 5436ef05171Smrg s//\1/ 5446ef05171Smrg s/\\/\\\\/g 5456ef05171Smrg p 5466ef05171Smrg}' | $cygpath_u | sort -u | sed -n ' 5476ef05171Smrgs/ /\\ /g 5486ef05171Smrgs/\(.*\)/'"$tab"'\1 \\/p 5496ef05171Smrgs/.\(.*\) \\/\1:/ 5506ef05171SmrgH 5516ef05171Smrg$ { 5526ef05171Smrg s/.*/'"$tab"'/ 5536ef05171Smrg G 5546ef05171Smrg p 5556ef05171Smrg}' >> "$depfile" 5566ef05171Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5576ef05171Smrg rm -f "$tmpdepfile" 5586ef05171Smrg ;; 5596ef05171Smrg 5606ef05171Smrgmsvc7msys) 5616ef05171Smrg # This case exists only to let depend.m4 do its work. It works by 5626ef05171Smrg # looking at the text of this script. This case will never be run, 5636ef05171Smrg # since it is checked for above. 5646ef05171Smrg exit 1 5656ef05171Smrg ;; 56643f32c10Smrg 56743f32c10Smrg#nosideeffect) 56843f32c10Smrg # This comment above is used by automake to tell side-effect 56943f32c10Smrg # dependency tracking mechanisms from slower ones. 57043f32c10Smrg 57143f32c10Smrgdashmstdout) 57243f32c10Smrg # Important note: in order to support this mode, a compiler *must* 57343f32c10Smrg # always write the preprocessed file to stdout, regardless of -o. 57443f32c10Smrg "$@" || exit $? 57543f32c10Smrg 57643f32c10Smrg # Remove the call to Libtool. 57743f32c10Smrg if test "$libtool" = yes; then 5786ef05171Smrg while test "X$1" != 'X--mode=compile'; do 57943f32c10Smrg shift 58043f32c10Smrg done 58143f32c10Smrg shift 58243f32c10Smrg fi 58343f32c10Smrg 5846ef05171Smrg # Remove '-o $object'. 58543f32c10Smrg IFS=" " 58643f32c10Smrg for arg 58743f32c10Smrg do 58843f32c10Smrg case $arg in 58943f32c10Smrg -o) 59043f32c10Smrg shift 59143f32c10Smrg ;; 59243f32c10Smrg $object) 59343f32c10Smrg shift 59443f32c10Smrg ;; 59543f32c10Smrg *) 59643f32c10Smrg set fnord "$@" "$arg" 59743f32c10Smrg shift # fnord 59843f32c10Smrg shift # $arg 59943f32c10Smrg ;; 60043f32c10Smrg esac 60143f32c10Smrg done 60243f32c10Smrg 60343f32c10Smrg test -z "$dashmflag" && dashmflag=-M 6046ef05171Smrg # Require at least two characters before searching for ':' 60543f32c10Smrg # in the target name. This is to cope with DOS-style filenames: 6066ef05171Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60743f32c10Smrg "$@" $dashmflag | 6086ef05171Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60943f32c10Smrg rm -f "$depfile" 61043f32c10Smrg cat < "$tmpdepfile" > "$depfile" 6116ef05171Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6126ef05171Smrg # correctly. Breaking it into two sed invocations is a workaround. 6136ef05171Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6146ef05171Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6156ef05171Smrg | sed -e 's/$/ :/' >> "$depfile" 61643f32c10Smrg rm -f "$tmpdepfile" 61743f32c10Smrg ;; 61843f32c10Smrg 61943f32c10SmrgdashXmstdout) 62043f32c10Smrg # This case only exists to satisfy depend.m4. It is never actually 62143f32c10Smrg # run, as this mode is specially recognized in the preamble. 62243f32c10Smrg exit 1 62343f32c10Smrg ;; 62443f32c10Smrg 62543f32c10Smrgmakedepend) 62643f32c10Smrg "$@" || exit $? 62743f32c10Smrg # Remove any Libtool call 62843f32c10Smrg if test "$libtool" = yes; then 6296ef05171Smrg while test "X$1" != 'X--mode=compile'; do 63043f32c10Smrg shift 63143f32c10Smrg done 63243f32c10Smrg shift 63343f32c10Smrg fi 63443f32c10Smrg # X makedepend 63543f32c10Smrg shift 6366ef05171Smrg cleared=no eat=no 6376ef05171Smrg for arg 6386ef05171Smrg do 63943f32c10Smrg case $cleared in 64043f32c10Smrg no) 64143f32c10Smrg set ""; shift 64243f32c10Smrg cleared=yes ;; 64343f32c10Smrg esac 6446ef05171Smrg if test $eat = yes; then 6456ef05171Smrg eat=no 6466ef05171Smrg continue 6476ef05171Smrg fi 64843f32c10Smrg case "$arg" in 64943f32c10Smrg -D*|-I*) 65043f32c10Smrg set fnord "$@" "$arg"; shift ;; 65143f32c10Smrg # Strip any option that makedepend may not understand. Remove 65243f32c10Smrg # the object too, otherwise makedepend will parse it as a source file. 6536ef05171Smrg -arch) 6546ef05171Smrg eat=yes ;; 65543f32c10Smrg -*|$object) 65643f32c10Smrg ;; 65743f32c10Smrg *) 65843f32c10Smrg set fnord "$@" "$arg"; shift ;; 65943f32c10Smrg esac 66043f32c10Smrg done 6616ef05171Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66243f32c10Smrg touch "$tmpdepfile" 66343f32c10Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66443f32c10Smrg rm -f "$depfile" 6656ef05171Smrg # makedepend may prepend the VPATH from the source file name to the object. 6666ef05171Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 6676ef05171Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6686ef05171Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6696ef05171Smrg # correctly. Breaking it into two sed invocations is a workaround. 6706ef05171Smrg sed '1,2d' "$tmpdepfile" \ 6716ef05171Smrg | tr ' ' "$nl" \ 6726ef05171Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6736ef05171Smrg | sed -e 's/$/ :/' >> "$depfile" 67443f32c10Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67543f32c10Smrg ;; 67643f32c10Smrg 67743f32c10Smrgcpp) 67843f32c10Smrg # Important note: in order to support this mode, a compiler *must* 67943f32c10Smrg # always write the preprocessed file to stdout. 68043f32c10Smrg "$@" || exit $? 68143f32c10Smrg 68243f32c10Smrg # Remove the call to Libtool. 68343f32c10Smrg if test "$libtool" = yes; then 6846ef05171Smrg while test "X$1" != 'X--mode=compile'; do 68543f32c10Smrg shift 68643f32c10Smrg done 68743f32c10Smrg shift 68843f32c10Smrg fi 68943f32c10Smrg 6906ef05171Smrg # Remove '-o $object'. 69143f32c10Smrg IFS=" " 69243f32c10Smrg for arg 69343f32c10Smrg do 69443f32c10Smrg case $arg in 69543f32c10Smrg -o) 69643f32c10Smrg shift 69743f32c10Smrg ;; 69843f32c10Smrg $object) 69943f32c10Smrg shift 70043f32c10Smrg ;; 70143f32c10Smrg *) 70243f32c10Smrg set fnord "$@" "$arg" 70343f32c10Smrg shift # fnord 70443f32c10Smrg shift # $arg 70543f32c10Smrg ;; 70643f32c10Smrg esac 70743f32c10Smrg done 70843f32c10Smrg 7096ef05171Smrg "$@" -E \ 7106ef05171Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7116ef05171Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7126ef05171Smrg | sed '$ s: \\$::' > "$tmpdepfile" 71343f32c10Smrg rm -f "$depfile" 71443f32c10Smrg echo "$object : \\" > "$depfile" 71543f32c10Smrg cat < "$tmpdepfile" >> "$depfile" 71643f32c10Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71743f32c10Smrg rm -f "$tmpdepfile" 71843f32c10Smrg ;; 71943f32c10Smrg 72043f32c10Smrgmsvisualcpp) 72143f32c10Smrg # Important note: in order to support this mode, a compiler *must* 7226ef05171Smrg # always write the preprocessed file to stdout. 72343f32c10Smrg "$@" || exit $? 7246ef05171Smrg 7256ef05171Smrg # Remove the call to Libtool. 7266ef05171Smrg if test "$libtool" = yes; then 7276ef05171Smrg while test "X$1" != 'X--mode=compile'; do 7286ef05171Smrg shift 7296ef05171Smrg done 7306ef05171Smrg shift 7316ef05171Smrg fi 7326ef05171Smrg 73343f32c10Smrg IFS=" " 73443f32c10Smrg for arg 73543f32c10Smrg do 73643f32c10Smrg case "$arg" in 7376ef05171Smrg -o) 7386ef05171Smrg shift 7396ef05171Smrg ;; 7406ef05171Smrg $object) 7416ef05171Smrg shift 7426ef05171Smrg ;; 74343f32c10Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7446ef05171Smrg set fnord "$@" 7456ef05171Smrg shift 7466ef05171Smrg shift 7476ef05171Smrg ;; 74843f32c10Smrg *) 7496ef05171Smrg set fnord "$@" "$arg" 7506ef05171Smrg shift 7516ef05171Smrg shift 7526ef05171Smrg ;; 75343f32c10Smrg esac 75443f32c10Smrg done 7556ef05171Smrg "$@" -E 2>/dev/null | 7566ef05171Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75743f32c10Smrg rm -f "$depfile" 75843f32c10Smrg echo "$object : \\" > "$depfile" 7596ef05171Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7606ef05171Smrg echo "$tab" >> "$depfile" 7616ef05171Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76243f32c10Smrg rm -f "$tmpdepfile" 76343f32c10Smrg ;; 76443f32c10Smrg 7656ef05171Smrgmsvcmsys) 7666ef05171Smrg # This case exists only to let depend.m4 do its work. It works by 7676ef05171Smrg # looking at the text of this script. This case will never be run, 7686ef05171Smrg # since it is checked for above. 7696ef05171Smrg exit 1 7706ef05171Smrg ;; 7716ef05171Smrg 77243f32c10Smrgnone) 77343f32c10Smrg exec "$@" 77443f32c10Smrg ;; 77543f32c10Smrg 77643f32c10Smrg*) 77743f32c10Smrg echo "Unknown depmode $depmode" 1>&2 77843f32c10Smrg exit 1 77943f32c10Smrg ;; 78043f32c10Smrgesac 78143f32c10Smrg 78243f32c10Smrgexit 0 78343f32c10Smrg 78443f32c10Smrg# Local Variables: 78543f32c10Smrg# mode: shell-script 78643f32c10Smrg# sh-indentation: 2 787ea148d1dSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 78843f32c10Smrg# time-stamp-start: "scriptversion=" 78943f32c10Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7906ef05171Smrg# time-stamp-time-zone: "UTC0" 7916ef05171Smrg# time-stamp-end: "; # UTC" 79243f32c10Smrg# End: 793