depcomp revision f6d57fde
17a0395d0Smrg#! /bin/sh 27a0395d0Smrg# depcomp - compile a program generating dependencies as side-effects 37a0395d0Smrg 4f6d57fdeSmrgscriptversion=2024-06-19.01; # UTC 57a0395d0Smrg 6f6d57fdeSmrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 77a0395d0Smrg 87a0395d0Smrg# This program is free software; you can redistribute it and/or modify 97a0395d0Smrg# it under the terms of the GNU General Public License as published by 107a0395d0Smrg# the Free Software Foundation; either version 2, or (at your option) 117a0395d0Smrg# any later version. 127a0395d0Smrg 137a0395d0Smrg# This program is distributed in the hope that it will be useful, 147a0395d0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 157a0395d0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 167a0395d0Smrg# GNU General Public License for more details. 177a0395d0Smrg 187a0395d0Smrg# You should have received a copy of the GNU General Public License 196c3c2bceSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 207a0395d0Smrg 217a0395d0Smrg# As a special exception to the GNU General Public License, if you 227a0395d0Smrg# distribute this file as part of a program that contains a 237a0395d0Smrg# configuration script generated by Autoconf, you may include it under 247a0395d0Smrg# the same distribution terms that you use for the rest of that program. 257a0395d0Smrg 267a0395d0Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 277a0395d0Smrg 287a0395d0Smrgcase $1 in 297a0395d0Smrg '') 309a011757Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 319a011757Smrg exit 1; 329a011757Smrg ;; 337a0395d0Smrg -h | --h*) 347a0395d0Smrg cat <<\EOF 357a0395d0SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 367a0395d0Smrg 377a0395d0SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 387a0395d0Smrgas side-effects. 397a0395d0Smrg 407a0395d0SmrgEnvironment variables: 417a0395d0Smrg depmode Dependency tracking mode. 428abc0ccfSmrg source Source file read by 'PROGRAMS ARGS'. 438abc0ccfSmrg object Object file output by 'PROGRAMS ARGS'. 447a0395d0Smrg DEPDIR directory where to store dependencies. 457a0395d0Smrg depfile Dependency file to output. 468abc0ccfSmrg tmpdepfile Temporary file to use when outputting dependencies. 477a0395d0Smrg libtool Whether libtool is used (yes/no). 487a0395d0Smrg 497a0395d0SmrgReport bugs to <bug-automake@gnu.org>. 50f6d57fdeSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 51f6d57fdeSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 527a0395d0SmrgEOF 537a0395d0Smrg exit $? 547a0395d0Smrg ;; 557a0395d0Smrg -v | --v*) 56f6d57fdeSmrg echo "depcomp (GNU Automake) $scriptversion" 577a0395d0Smrg exit $? 587a0395d0Smrg ;; 597a0395d0Smrgesac 607a0395d0Smrg 619a011757Smrg# Get the directory component of the given path, and save it in the 629a011757Smrg# global variables '$dir'. Note that this directory component will 639a011757Smrg# be either empty or ending with a '/' character. This is deliberate. 649a011757Smrgset_dir_from () 659a011757Smrg{ 669a011757Smrg case $1 in 679a011757Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 689a011757Smrg *) dir=;; 699a011757Smrg esac 709a011757Smrg} 719a011757Smrg 729a011757Smrg# Get the suffix-stripped basename of the given path, and save it the 739a011757Smrg# global variable '$base'. 749a011757Smrgset_base_from () 759a011757Smrg{ 769a011757Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 779a011757Smrg} 789a011757Smrg 799a011757Smrg# If no dependency file was actually created by the compiler invocation, 809a011757Smrg# we still have to create a dummy depfile, to avoid errors with the 819a011757Smrg# Makefile "include basename.Plo" scheme. 829a011757Smrgmake_dummy_depfile () 839a011757Smrg{ 849a011757Smrg echo "#dummy" > "$depfile" 859a011757Smrg} 869a011757Smrg 879a011757Smrg# Factor out some common post-processing of the generated depfile. 889a011757Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 899a011757Smrgaix_post_process_depfile () 909a011757Smrg{ 919a011757Smrg # If the compiler actually managed to produce a dependency file, 929a011757Smrg # post-process it. 939a011757Smrg if test -f "$tmpdepfile"; then 949a011757Smrg # Each line is of the form 'foo.o: dependency.h'. 959a011757Smrg # Do two passes, one to just change these to 969a011757Smrg # $object: dependency.h 979a011757Smrg # and one to simply output 989a011757Smrg # dependency.h: 999a011757Smrg # which is needed to avoid the deleted-header problem. 1009a011757Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 1019a011757Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1029a011757Smrg } > "$depfile" 1039a011757Smrg rm -f "$tmpdepfile" 1049a011757Smrg else 1059a011757Smrg make_dummy_depfile 1069a011757Smrg fi 1079a011757Smrg} 1089a011757Smrg 1098abc0ccfSmrg# A tabulation character. 1108abc0ccfSmrgtab=' ' 1118abc0ccfSmrg# A newline character. 1128abc0ccfSmrgnl=' 1138abc0ccfSmrg' 1149a011757Smrg# Character ranges might be problematic outside the C locale. 1159a011757Smrg# These definitions help. 1169a011757Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1179a011757Smrglower=abcdefghijklmnopqrstuvwxyz 1189a011757Smrgalpha=${upper}${lower} 1198abc0ccfSmrg 1207a0395d0Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1217a0395d0Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1227a0395d0Smrg exit 1 1237a0395d0Smrgfi 1247a0395d0Smrg 1257a0395d0Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1267a0395d0Smrgdepfile=${depfile-`echo "$object" | 1277a0395d0Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1287a0395d0Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1297a0395d0Smrg 1307a0395d0Smrgrm -f "$tmpdepfile" 1317a0395d0Smrg 132f6d57fdeSmrg# Avoid interference from the environment. 1339a011757Smrggccflag= dashmflag= 1349a011757Smrg 1357a0395d0Smrg# Some modes work just like other modes, but use different flags. We 1367a0395d0Smrg# parameterize here, but still list the modes in the big case below, 1377a0395d0Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1387a0395d0Smrg# here, because this file can only contain one case statement. 1397a0395d0Smrgif test "$depmode" = hp; then 1407a0395d0Smrg # HP compiler uses -M and no extra arg. 1417a0395d0Smrg gccflag=-M 1427a0395d0Smrg depmode=gcc 1437a0395d0Smrgfi 1447a0395d0Smrg 1457a0395d0Smrgif test "$depmode" = dashXmstdout; then 1469a011757Smrg # This is just like dashmstdout with a different argument. 1479a011757Smrg dashmflag=-xM 1489a011757Smrg depmode=dashmstdout 1497a0395d0Smrgfi 1507a0395d0Smrg 1517366012aSmrgcygpath_u="cygpath -u -f -" 1527366012aSmrgif test "$depmode" = msvcmsys; then 1539a011757Smrg # This is just like msvisualcpp but w/o cygpath translation. 1549a011757Smrg # Just convert the backslash-escaped backslashes to single forward 1559a011757Smrg # slashes to satisfy depend.m4 1569a011757Smrg cygpath_u='sed s,\\\\,/,g' 1579a011757Smrg depmode=msvisualcpp 1587366012aSmrgfi 1597366012aSmrg 1608abc0ccfSmrgif test "$depmode" = msvc7msys; then 1619a011757Smrg # This is just like msvc7 but w/o cygpath translation. 1629a011757Smrg # Just convert the backslash-escaped backslashes to single forward 1639a011757Smrg # slashes to satisfy depend.m4 1649a011757Smrg cygpath_u='sed s,\\\\,/,g' 1659a011757Smrg depmode=msvc7 1668abc0ccfSmrgfi 1678abc0ccfSmrg 1688abc0ccfSmrgif test "$depmode" = xlc; then 1699a011757Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1709a011757Smrg gccflag=-qmakedep=gcc,-MF 1719a011757Smrg depmode=gcc 1728abc0ccfSmrgfi 1738abc0ccfSmrg 1747a0395d0Smrgcase "$depmode" in 1757a0395d0Smrggcc3) 1767a0395d0Smrg## gcc 3 implements dependency tracking that does exactly what 1777a0395d0Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1787a0395d0Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1797a0395d0Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1807a0395d0Smrg## the command line argument order; so add the flags where they 1817a0395d0Smrg## appear in depend2.am. Note that the slowdown incurred here 1827a0395d0Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1837a0395d0Smrg for arg 1847a0395d0Smrg do 1857a0395d0Smrg case $arg in 1867a0395d0Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1877a0395d0Smrg *) set fnord "$@" "$arg" ;; 1887a0395d0Smrg esac 1897a0395d0Smrg shift # fnord 1907a0395d0Smrg shift # $arg 1917a0395d0Smrg done 1927a0395d0Smrg "$@" 1937a0395d0Smrg stat=$? 1949a011757Smrg if test $stat -ne 0; then 1957a0395d0Smrg rm -f "$tmpdepfile" 1967a0395d0Smrg exit $stat 1977a0395d0Smrg fi 1987a0395d0Smrg mv "$tmpdepfile" "$depfile" 1997a0395d0Smrg ;; 2007a0395d0Smrg 2017a0395d0Smrggcc) 202f6d57fdeSmrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 203f6d57fdeSmrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 2049a011757Smrg## (see the conditional assignment to $gccflag above). 2057a0395d0Smrg## There are various ways to get dependency output from gcc. Here's 2067a0395d0Smrg## why we pick this rather obscure method: 2077a0395d0Smrg## - Don't want to use -MD because we'd like the dependencies to end 2087a0395d0Smrg## up in a subdir. Having to rename by hand is ugly. 2097a0395d0Smrg## (We might end up doing this anyway to support other compilers.) 2107a0395d0Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2119a011757Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2129a011757Smrg## supported by the other compilers which use the 'gcc' depmode. 2137a0395d0Smrg## - Using -M directly means running the compiler twice (even worse 2147a0395d0Smrg## than renaming). 2157a0395d0Smrg if test -z "$gccflag"; then 2167a0395d0Smrg gccflag=-MD, 2177a0395d0Smrg fi 2187a0395d0Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2197a0395d0Smrg stat=$? 2209a011757Smrg if test $stat -ne 0; then 2217a0395d0Smrg rm -f "$tmpdepfile" 2227a0395d0Smrg exit $stat 2237a0395d0Smrg fi 2247a0395d0Smrg rm -f "$depfile" 2257a0395d0Smrg echo "$object : \\" > "$depfile" 2269a011757Smrg # The second -e expression handles DOS-style file names with drive 2279a011757Smrg # letters. 2287a0395d0Smrg sed -e 's/^[^:]*: / /' \ 2297a0395d0Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2308abc0ccfSmrg## This next piece of magic avoids the "deleted header file" problem. 2317a0395d0Smrg## The problem is that when a header file which appears in a .P file 2327a0395d0Smrg## is deleted, the dependency causes make to die (because there is 2337a0395d0Smrg## typically no way to rebuild the header). We avoid this by adding 2347a0395d0Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2357a0395d0Smrg## this for us directly. 2368abc0ccfSmrg## Some versions of gcc put a space before the ':'. On the theory 2377a0395d0Smrg## that the space means something, we add a space to the output as 2388abc0ccfSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 2398abc0ccfSmrg## to the object. Take care to not repeat it in the output. 2407a0395d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2417a0395d0Smrg## correctly. Breaking it into two sed invocations is a workaround. 2429a011757Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2439a011757Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2449a011757Smrg | sed -e 's/$/ :/' >> "$depfile" 2457a0395d0Smrg rm -f "$tmpdepfile" 2467a0395d0Smrg ;; 2477a0395d0Smrg 2487a0395d0Smrghp) 2497a0395d0Smrg # This case exists only to let depend.m4 do its work. It works by 2507a0395d0Smrg # looking at the text of this script. This case will never be run, 2517a0395d0Smrg # since it is checked for above. 2527a0395d0Smrg exit 1 2537a0395d0Smrg ;; 2547a0395d0Smrg 2557a0395d0Smrgsgi) 2567a0395d0Smrg if test "$libtool" = yes; then 2577a0395d0Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2587a0395d0Smrg else 2597a0395d0Smrg "$@" -MDupdate "$tmpdepfile" 2607a0395d0Smrg fi 2617a0395d0Smrg stat=$? 2629a011757Smrg if test $stat -ne 0; then 2637a0395d0Smrg rm -f "$tmpdepfile" 2647a0395d0Smrg exit $stat 2657a0395d0Smrg fi 2667a0395d0Smrg rm -f "$depfile" 2677a0395d0Smrg 2687a0395d0Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2697a0395d0Smrg echo "$object : \\" > "$depfile" 2707a0395d0Smrg # Clip off the initial element (the dependent). Don't try to be 2717a0395d0Smrg # clever and replace this with sed code, as IRIX sed won't handle 2727a0395d0Smrg # lines with more than a fixed number of characters (4096 in 2737a0395d0Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2748abc0ccfSmrg # the IRIX cc adds comments like '#:fec' to the end of the 2757a0395d0Smrg # dependency line. 2768abc0ccfSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2779a011757Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2789a011757Smrg | tr "$nl" ' ' >> "$depfile" 2797366012aSmrg echo >> "$depfile" 2807a0395d0Smrg # The second pass generates a dummy entry for each header file. 2818abc0ccfSmrg tr ' ' "$nl" < "$tmpdepfile" \ 2829a011757Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2839a011757Smrg >> "$depfile" 2847a0395d0Smrg else 2859a011757Smrg make_dummy_depfile 2867a0395d0Smrg fi 2877a0395d0Smrg rm -f "$tmpdepfile" 2887a0395d0Smrg ;; 2897a0395d0Smrg 2908abc0ccfSmrgxlc) 2918abc0ccfSmrg # This case exists only to let depend.m4 do its work. It works by 2928abc0ccfSmrg # looking at the text of this script. This case will never be run, 2938abc0ccfSmrg # since it is checked for above. 2948abc0ccfSmrg exit 1 2958abc0ccfSmrg ;; 2968abc0ccfSmrg 2977a0395d0Smrgaix) 2987a0395d0Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2997a0395d0Smrg # in a .u file. In older versions, this file always lives in the 3008abc0ccfSmrg # current directory. Also, the AIX compiler puts '$object:' at the 3017a0395d0Smrg # start of each line; $object doesn't have directory information. 3027a0395d0Smrg # Version 6 uses the directory in both cases. 3039a011757Smrg set_dir_from "$object" 3049a011757Smrg set_base_from "$object" 3057a0395d0Smrg if test "$libtool" = yes; then 3067a0395d0Smrg tmpdepfile1=$dir$base.u 3077a0395d0Smrg tmpdepfile2=$base.u 3087a0395d0Smrg tmpdepfile3=$dir.libs/$base.u 3097a0395d0Smrg "$@" -Wc,-M 3107a0395d0Smrg else 3117a0395d0Smrg tmpdepfile1=$dir$base.u 3127a0395d0Smrg tmpdepfile2=$dir$base.u 3137a0395d0Smrg tmpdepfile3=$dir$base.u 3147a0395d0Smrg "$@" -M 3157a0395d0Smrg fi 3167a0395d0Smrg stat=$? 3179a011757Smrg if test $stat -ne 0; then 3187a0395d0Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3197a0395d0Smrg exit $stat 3207a0395d0Smrg fi 3217a0395d0Smrg 3227a0395d0Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3237a0395d0Smrg do 3247a0395d0Smrg test -f "$tmpdepfile" && break 3257a0395d0Smrg done 3269a011757Smrg aix_post_process_depfile 3279a011757Smrg ;; 3289a011757Smrg 3299a011757Smrgtcc) 3309a011757Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3319a011757Smrg # FIXME: That version still under development at the moment of writing. 3329a011757Smrg # Make that this statement remains true also for stable, released 3339a011757Smrg # versions. 3349a011757Smrg # It will wrap lines (doesn't matter whether long or short) with a 3359a011757Smrg # trailing '\', as in: 3369a011757Smrg # 3379a011757Smrg # foo.o : \ 3389a011757Smrg # foo.c \ 3399a011757Smrg # foo.h \ 3409a011757Smrg # 3419a011757Smrg # It will put a trailing '\' even on the last line, and will use leading 3429a011757Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3439a011757Smrg # "Emit spaces for -MD"). 3449a011757Smrg "$@" -MD -MF "$tmpdepfile" 3459a011757Smrg stat=$? 3469a011757Smrg if test $stat -ne 0; then 3479a011757Smrg rm -f "$tmpdepfile" 3489a011757Smrg exit $stat 3497a0395d0Smrg fi 3509a011757Smrg rm -f "$depfile" 3519a011757Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3529a011757Smrg # We have to change lines of the first kind to '$object: \'. 3539a011757Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3549a011757Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3559a011757Smrg # dummy dependency, to avoid the deleted-header problem. 3569a011757Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3577a0395d0Smrg rm -f "$tmpdepfile" 3587a0395d0Smrg ;; 3597a0395d0Smrg 3609a011757Smrg## The order of this option in the case statement is important, since the 3619a011757Smrg## shell code in configure will try each of these formats in the order 3629a011757Smrg## listed in this file. A plain '-MD' option would be understood by many 3639a011757Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3649a011757Smrgpgcc) 3659a011757Smrg # Portland's C compiler understands '-MD'. 3669a011757Smrg # Will always output deps to 'file.d' where file is the root name of the 3679a011757Smrg # source file under compilation, even if file resides in a subdirectory. 3689a011757Smrg # The object file name does not affect the name of the '.d' file. 3699a011757Smrg # pgcc 10.2 will output 3707a0395d0Smrg # foo.o: sub/foo.c sub/foo.h 3719a011757Smrg # and will wrap long lines using '\' : 3727a0395d0Smrg # foo.o: sub/foo.c ... \ 3737a0395d0Smrg # sub/foo.h ... \ 3747a0395d0Smrg # ... 3759a011757Smrg set_dir_from "$object" 3769a011757Smrg # Use the source, not the object, to determine the base name, since 3779a011757Smrg # that's sadly what pgcc will do too. 3789a011757Smrg set_base_from "$source" 3799a011757Smrg tmpdepfile=$base.d 3809a011757Smrg 3819a011757Smrg # For projects that build the same source file twice into different object 3829a011757Smrg # files, the pgcc approach of using the *source* file root name can cause 3839a011757Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3849a011757Smrg # the same $tmpdepfile. 3859a011757Smrg lockdir=$base.d-lock 3869a011757Smrg trap " 3879a011757Smrg echo '$0: caught signal, cleaning up...' >&2 3889a011757Smrg rmdir '$lockdir' 3899a011757Smrg exit 1 3909a011757Smrg " 1 2 13 15 3919a011757Smrg numtries=100 3929a011757Smrg i=$numtries 3939a011757Smrg while test $i -gt 0; do 3949a011757Smrg # mkdir is a portable test-and-set. 3959a011757Smrg if mkdir "$lockdir" 2>/dev/null; then 3969a011757Smrg # This process acquired the lock. 3979a011757Smrg "$@" -MD 3989a011757Smrg stat=$? 3999a011757Smrg # Release the lock. 4009a011757Smrg rmdir "$lockdir" 4019a011757Smrg break 4029a011757Smrg else 4039a011757Smrg # If the lock is being held by a different process, wait 4049a011757Smrg # until the winning process is done or we timeout. 4059a011757Smrg while test -d "$lockdir" && test $i -gt 0; do 4069a011757Smrg sleep 1 4079a011757Smrg i=`expr $i - 1` 4089a011757Smrg done 4099a011757Smrg fi 4109a011757Smrg i=`expr $i - 1` 4119a011757Smrg done 4129a011757Smrg trap - 1 2 13 15 4139a011757Smrg if test $i -le 0; then 4149a011757Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4159a011757Smrg echo "$0: check lockdir '$lockdir'" >&2 4169a011757Smrg exit 1 4179a011757Smrg fi 4189a011757Smrg 4199a011757Smrg if test $stat -ne 0; then 4207a0395d0Smrg rm -f "$tmpdepfile" 4217a0395d0Smrg exit $stat 4227a0395d0Smrg fi 4237a0395d0Smrg rm -f "$depfile" 4249a011757Smrg # Each line is of the form `foo.o: dependent.h', 4259a011757Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4267a0395d0Smrg # Do two passes, one to just change these to 4279a011757Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4289a011757Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4299a011757Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4309a011757Smrg # correctly. Breaking it into two sed invocations is a workaround. 4319a011757Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4329a011757Smrg | sed -e 's/$/ :/' >> "$depfile" 4337a0395d0Smrg rm -f "$tmpdepfile" 4347a0395d0Smrg ;; 4357a0395d0Smrg 4367a0395d0Smrghp2) 4377a0395d0Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4387a0395d0Smrg # compilers, which have integrated preprocessors. The correct option 4397a0395d0Smrg # to use with these is +Maked; it writes dependencies to a file named 4407a0395d0Smrg # 'foo.d', which lands next to the object file, wherever that 4417a0395d0Smrg # happens to be. 4427a0395d0Smrg # Much of this is similar to the tru64 case; see comments there. 4439a011757Smrg set_dir_from "$object" 4449a011757Smrg set_base_from "$object" 4457a0395d0Smrg if test "$libtool" = yes; then 4467a0395d0Smrg tmpdepfile1=$dir$base.d 4477a0395d0Smrg tmpdepfile2=$dir.libs/$base.d 4487a0395d0Smrg "$@" -Wc,+Maked 4497a0395d0Smrg else 4507a0395d0Smrg tmpdepfile1=$dir$base.d 4517a0395d0Smrg tmpdepfile2=$dir$base.d 4527a0395d0Smrg "$@" +Maked 4537a0395d0Smrg fi 4547a0395d0Smrg stat=$? 4559a011757Smrg if test $stat -ne 0; then 4567a0395d0Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4577a0395d0Smrg exit $stat 4587a0395d0Smrg fi 4597a0395d0Smrg 4607a0395d0Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4617a0395d0Smrg do 4627a0395d0Smrg test -f "$tmpdepfile" && break 4637a0395d0Smrg done 4647a0395d0Smrg if test -f "$tmpdepfile"; then 4659a011757Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4668abc0ccfSmrg # Add 'dependent.h:' lines. 4677366012aSmrg sed -ne '2,${ 4689a011757Smrg s/^ *// 4699a011757Smrg s/ \\*$// 4709a011757Smrg s/$/:/ 4719a011757Smrg p 4729a011757Smrg }' "$tmpdepfile" >> "$depfile" 4737a0395d0Smrg else 4749a011757Smrg make_dummy_depfile 4757a0395d0Smrg fi 4767a0395d0Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4777a0395d0Smrg ;; 4787a0395d0Smrg 4797a0395d0Smrgtru64) 4809a011757Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4819a011757Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4829a011757Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4839a011757Smrg # dependencies in 'foo.d' instead, so we check for that too. 4849a011757Smrg # Subdirectories are respected. 4859a011757Smrg set_dir_from "$object" 4869a011757Smrg set_base_from "$object" 4879a011757Smrg 4889a011757Smrg if test "$libtool" = yes; then 4899a011757Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4909a011757Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4919a011757Smrg # in $dir$base.o.d. We have to check for both files, because 4929a011757Smrg # one of the two compilations can be disabled. We should prefer 4939a011757Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4949a011757Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4959a011757Smrg # the former would cause a distcleancheck panic. 4969a011757Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4979a011757Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4989a011757Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4999a011757Smrg "$@" -Wc,-MD 5009a011757Smrg else 5019a011757Smrg tmpdepfile1=$dir$base.d 5029a011757Smrg tmpdepfile2=$dir$base.d 5039a011757Smrg tmpdepfile3=$dir$base.d 5049a011757Smrg "$@" -MD 5059a011757Smrg fi 5069a011757Smrg 5079a011757Smrg stat=$? 5089a011757Smrg if test $stat -ne 0; then 5099a011757Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5109a011757Smrg exit $stat 5119a011757Smrg fi 5129a011757Smrg 5139a011757Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5149a011757Smrg do 5159a011757Smrg test -f "$tmpdepfile" && break 5169a011757Smrg done 5179a011757Smrg # Same post-processing that is required for AIX mode. 5189a011757Smrg aix_post_process_depfile 5199a011757Smrg ;; 5207a0395d0Smrg 5218abc0ccfSmrgmsvc7) 5228abc0ccfSmrg if test "$libtool" = yes; then 5238abc0ccfSmrg showIncludes=-Wc,-showIncludes 5248abc0ccfSmrg else 5258abc0ccfSmrg showIncludes=-showIncludes 5268abc0ccfSmrg fi 5278abc0ccfSmrg "$@" $showIncludes > "$tmpdepfile" 5288abc0ccfSmrg stat=$? 5298abc0ccfSmrg grep -v '^Note: including file: ' "$tmpdepfile" 5309a011757Smrg if test $stat -ne 0; then 5318abc0ccfSmrg rm -f "$tmpdepfile" 5328abc0ccfSmrg exit $stat 5338abc0ccfSmrg fi 5348abc0ccfSmrg rm -f "$depfile" 5358abc0ccfSmrg echo "$object : \\" > "$depfile" 5368abc0ccfSmrg # The first sed program below extracts the file names and escapes 5378abc0ccfSmrg # backslashes for cygpath. The second sed program outputs the file 5388abc0ccfSmrg # name when reading, but also accumulates all include files in the 5398abc0ccfSmrg # hold buffer in order to output them again at the end. This only 5408abc0ccfSmrg # works with sed implementations that can handle large buffers. 5418abc0ccfSmrg sed < "$tmpdepfile" -n ' 5428abc0ccfSmrg/^Note: including file: *\(.*\)/ { 5438abc0ccfSmrg s//\1/ 5448abc0ccfSmrg s/\\/\\\\/g 5458abc0ccfSmrg p 5468abc0ccfSmrg}' | $cygpath_u | sort -u | sed -n ' 5478abc0ccfSmrgs/ /\\ /g 5488abc0ccfSmrgs/\(.*\)/'"$tab"'\1 \\/p 5498abc0ccfSmrgs/.\(.*\) \\/\1:/ 5508abc0ccfSmrgH 5518abc0ccfSmrg$ { 5528abc0ccfSmrg s/.*/'"$tab"'/ 5538abc0ccfSmrg G 5548abc0ccfSmrg p 5558abc0ccfSmrg}' >> "$depfile" 5569a011757Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5578abc0ccfSmrg rm -f "$tmpdepfile" 5588abc0ccfSmrg ;; 5598abc0ccfSmrg 5608abc0ccfSmrgmsvc7msys) 5618abc0ccfSmrg # This case exists only to let depend.m4 do its work. It works by 5628abc0ccfSmrg # looking at the text of this script. This case will never be run, 5638abc0ccfSmrg # since it is checked for above. 5648abc0ccfSmrg exit 1 5658abc0ccfSmrg ;; 5668abc0ccfSmrg 5677a0395d0Smrg#nosideeffect) 5687a0395d0Smrg # This comment above is used by automake to tell side-effect 5697a0395d0Smrg # dependency tracking mechanisms from slower ones. 5707a0395d0Smrg 5717a0395d0Smrgdashmstdout) 5727a0395d0Smrg # Important note: in order to support this mode, a compiler *must* 5737a0395d0Smrg # always write the preprocessed file to stdout, regardless of -o. 5747a0395d0Smrg "$@" || exit $? 5757a0395d0Smrg 5767a0395d0Smrg # Remove the call to Libtool. 5777a0395d0Smrg if test "$libtool" = yes; then 5787366012aSmrg while test "X$1" != 'X--mode=compile'; do 5797a0395d0Smrg shift 5807a0395d0Smrg done 5817a0395d0Smrg shift 5827a0395d0Smrg fi 5837a0395d0Smrg 5848abc0ccfSmrg # Remove '-o $object'. 5857a0395d0Smrg IFS=" " 5867a0395d0Smrg for arg 5877a0395d0Smrg do 5887a0395d0Smrg case $arg in 5897a0395d0Smrg -o) 5907a0395d0Smrg shift 5917a0395d0Smrg ;; 5927a0395d0Smrg $object) 5937a0395d0Smrg shift 5947a0395d0Smrg ;; 5957a0395d0Smrg *) 5967a0395d0Smrg set fnord "$@" "$arg" 5977a0395d0Smrg shift # fnord 5987a0395d0Smrg shift # $arg 5997a0395d0Smrg ;; 6007a0395d0Smrg esac 6017a0395d0Smrg done 6027a0395d0Smrg 6037a0395d0Smrg test -z "$dashmflag" && dashmflag=-M 6048abc0ccfSmrg # Require at least two characters before searching for ':' 6057a0395d0Smrg # in the target name. This is to cope with DOS-style filenames: 6068abc0ccfSmrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6077a0395d0Smrg "$@" $dashmflag | 6089a011757Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6097a0395d0Smrg rm -f "$depfile" 6107a0395d0Smrg cat < "$tmpdepfile" > "$depfile" 6119a011757Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6129a011757Smrg # correctly. Breaking it into two sed invocations is a workaround. 6139a011757Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6149a011757Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6159a011757Smrg | sed -e 's/$/ :/' >> "$depfile" 6167a0395d0Smrg rm -f "$tmpdepfile" 6177a0395d0Smrg ;; 6187a0395d0Smrg 6197a0395d0SmrgdashXmstdout) 6207a0395d0Smrg # This case only exists to satisfy depend.m4. It is never actually 6217a0395d0Smrg # run, as this mode is specially recognized in the preamble. 6227a0395d0Smrg exit 1 6237a0395d0Smrg ;; 6247a0395d0Smrg 6257a0395d0Smrgmakedepend) 6267a0395d0Smrg "$@" || exit $? 6277a0395d0Smrg # Remove any Libtool call 6287a0395d0Smrg if test "$libtool" = yes; then 6297366012aSmrg while test "X$1" != 'X--mode=compile'; do 6307a0395d0Smrg shift 6317a0395d0Smrg done 6327a0395d0Smrg shift 6337a0395d0Smrg fi 6347a0395d0Smrg # X makedepend 6357a0395d0Smrg shift 6367366012aSmrg cleared=no eat=no 6377366012aSmrg for arg 6387366012aSmrg do 6397a0395d0Smrg case $cleared in 6407a0395d0Smrg no) 6417a0395d0Smrg set ""; shift 6427a0395d0Smrg cleared=yes ;; 6437a0395d0Smrg esac 6447366012aSmrg if test $eat = yes; then 6457366012aSmrg eat=no 6467366012aSmrg continue 6477366012aSmrg fi 6487a0395d0Smrg case "$arg" in 6497a0395d0Smrg -D*|-I*) 6507a0395d0Smrg set fnord "$@" "$arg"; shift ;; 6517a0395d0Smrg # Strip any option that makedepend may not understand. Remove 6527a0395d0Smrg # the object too, otherwise makedepend will parse it as a source file. 6537366012aSmrg -arch) 6547366012aSmrg eat=yes ;; 6557a0395d0Smrg -*|$object) 6567a0395d0Smrg ;; 6577a0395d0Smrg *) 6587a0395d0Smrg set fnord "$@" "$arg"; shift ;; 6597a0395d0Smrg esac 6607a0395d0Smrg done 6617366012aSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6627a0395d0Smrg touch "$tmpdepfile" 6637a0395d0Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6647a0395d0Smrg rm -f "$depfile" 6658abc0ccfSmrg # makedepend may prepend the VPATH from the source file name to the object. 6668abc0ccfSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 6678abc0ccfSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6689a011757Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6699a011757Smrg # correctly. Breaking it into two sed invocations is a workaround. 6709a011757Smrg sed '1,2d' "$tmpdepfile" \ 6719a011757Smrg | tr ' ' "$nl" \ 6729a011757Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6739a011757Smrg | sed -e 's/$/ :/' >> "$depfile" 6747a0395d0Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6757a0395d0Smrg ;; 6767a0395d0Smrg 6777a0395d0Smrgcpp) 6787a0395d0Smrg # Important note: in order to support this mode, a compiler *must* 6797a0395d0Smrg # always write the preprocessed file to stdout. 6807a0395d0Smrg "$@" || exit $? 6817a0395d0Smrg 6827a0395d0Smrg # Remove the call to Libtool. 6837a0395d0Smrg if test "$libtool" = yes; then 6847366012aSmrg while test "X$1" != 'X--mode=compile'; do 6857a0395d0Smrg shift 6867a0395d0Smrg done 6877a0395d0Smrg shift 6887a0395d0Smrg fi 6897a0395d0Smrg 6908abc0ccfSmrg # Remove '-o $object'. 6917a0395d0Smrg IFS=" " 6927a0395d0Smrg for arg 6937a0395d0Smrg do 6947a0395d0Smrg case $arg in 6957a0395d0Smrg -o) 6967a0395d0Smrg shift 6977a0395d0Smrg ;; 6987a0395d0Smrg $object) 6997a0395d0Smrg shift 7007a0395d0Smrg ;; 7017a0395d0Smrg *) 7027a0395d0Smrg set fnord "$@" "$arg" 7037a0395d0Smrg shift # fnord 7047a0395d0Smrg shift # $arg 7057a0395d0Smrg ;; 7067a0395d0Smrg esac 7077a0395d0Smrg done 7087a0395d0Smrg 7099a011757Smrg "$@" -E \ 7109a011757Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7119a011757Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7129a011757Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7137a0395d0Smrg rm -f "$depfile" 7147a0395d0Smrg echo "$object : \\" > "$depfile" 7157a0395d0Smrg cat < "$tmpdepfile" >> "$depfile" 7167a0395d0Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7177a0395d0Smrg rm -f "$tmpdepfile" 7187a0395d0Smrg ;; 7197a0395d0Smrg 7207a0395d0Smrgmsvisualcpp) 7217a0395d0Smrg # Important note: in order to support this mode, a compiler *must* 7227366012aSmrg # always write the preprocessed file to stdout. 7237a0395d0Smrg "$@" || exit $? 7247366012aSmrg 7257366012aSmrg # Remove the call to Libtool. 7267366012aSmrg if test "$libtool" = yes; then 7277366012aSmrg while test "X$1" != 'X--mode=compile'; do 7287366012aSmrg shift 7297366012aSmrg done 7307366012aSmrg shift 7317366012aSmrg fi 7327366012aSmrg 7337a0395d0Smrg IFS=" " 7347a0395d0Smrg for arg 7357a0395d0Smrg do 7367a0395d0Smrg case "$arg" in 7377366012aSmrg -o) 7387366012aSmrg shift 7397366012aSmrg ;; 7407366012aSmrg $object) 7417366012aSmrg shift 7427366012aSmrg ;; 7437a0395d0Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7449a011757Smrg set fnord "$@" 7459a011757Smrg shift 7469a011757Smrg shift 7479a011757Smrg ;; 7487a0395d0Smrg *) 7499a011757Smrg set fnord "$@" "$arg" 7509a011757Smrg shift 7519a011757Smrg shift 7529a011757Smrg ;; 7537a0395d0Smrg esac 7547a0395d0Smrg done 7557366012aSmrg "$@" -E 2>/dev/null | 7567366012aSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7577a0395d0Smrg rm -f "$depfile" 7587a0395d0Smrg echo "$object : \\" > "$depfile" 7598abc0ccfSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7608abc0ccfSmrg echo "$tab" >> "$depfile" 7617366012aSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7627a0395d0Smrg rm -f "$tmpdepfile" 7637a0395d0Smrg ;; 7647a0395d0Smrg 7657366012aSmrgmsvcmsys) 7667366012aSmrg # This case exists only to let depend.m4 do its work. It works by 7677366012aSmrg # looking at the text of this script. This case will never be run, 7687366012aSmrg # since it is checked for above. 7697366012aSmrg exit 1 7707366012aSmrg ;; 7717366012aSmrg 7727a0395d0Smrgnone) 7737a0395d0Smrg exec "$@" 7747a0395d0Smrg ;; 7757a0395d0Smrg 7767a0395d0Smrg*) 7777a0395d0Smrg echo "Unknown depmode $depmode" 1>&2 7787a0395d0Smrg exit 1 7797a0395d0Smrg ;; 7807a0395d0Smrgesac 7817a0395d0Smrg 7827a0395d0Smrgexit 0 7837a0395d0Smrg 7847a0395d0Smrg# Local Variables: 7857a0395d0Smrg# mode: shell-script 7867a0395d0Smrg# sh-indentation: 2 7876c3c2bceSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7887a0395d0Smrg# time-stamp-start: "scriptversion=" 7897a0395d0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7906c3c2bceSmrg# time-stamp-time-zone: "UTC0" 7917366012aSmrg# time-stamp-end: "; # UTC" 7927a0395d0Smrg# End: 793