depcomp revision a32e9e42
12c393a42Smrg#! /bin/sh 22c393a42Smrg# depcomp - compile a program generating dependencies as side-effects 32c393a42Smrg 4a32e9e42Smrgscriptversion=2018-03-07.03; # UTC 52c393a42Smrg 6a32e9e42Smrg# Copyright (C) 1999-2018 Free Software Foundation, Inc. 72c393a42Smrg 82c393a42Smrg# This program is free software; you can redistribute it and/or modify 92c393a42Smrg# it under the terms of the GNU General Public License as published by 102c393a42Smrg# the Free Software Foundation; either version 2, or (at your option) 112c393a42Smrg# any later version. 122c393a42Smrg 132c393a42Smrg# This program is distributed in the hope that it will be useful, 142c393a42Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 152c393a42Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 162c393a42Smrg# GNU General Public License for more details. 172c393a42Smrg 182c393a42Smrg# You should have received a copy of the GNU General Public License 19a32e9e42Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 202c393a42Smrg 212c393a42Smrg# As a special exception to the GNU General Public License, if you 222c393a42Smrg# distribute this file as part of a program that contains a 232c393a42Smrg# configuration script generated by Autoconf, you may include it under 242c393a42Smrg# the same distribution terms that you use for the rest of that program. 252c393a42Smrg 262c393a42Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 272c393a42Smrg 282c393a42Smrgcase $1 in 292c393a42Smrg '') 306fc018e4Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 316fc018e4Smrg exit 1; 326fc018e4Smrg ;; 332c393a42Smrg -h | --h*) 342c393a42Smrg cat <<\EOF 352c393a42SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 362c393a42Smrg 372c393a42SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 382c393a42Smrgas side-effects. 392c393a42Smrg 402c393a42SmrgEnvironment variables: 412c393a42Smrg depmode Dependency tracking mode. 42ca08ab68Smrg source Source file read by 'PROGRAMS ARGS'. 43ca08ab68Smrg object Object file output by 'PROGRAMS ARGS'. 442c393a42Smrg DEPDIR directory where to store dependencies. 452c393a42Smrg depfile Dependency file to output. 46ca08ab68Smrg tmpdepfile Temporary file to use when outputting dependencies. 472c393a42Smrg libtool Whether libtool is used (yes/no). 482c393a42Smrg 492c393a42SmrgReport bugs to <bug-automake@gnu.org>. 502c393a42SmrgEOF 512c393a42Smrg exit $? 522c393a42Smrg ;; 532c393a42Smrg -v | --v*) 542c393a42Smrg echo "depcomp $scriptversion" 552c393a42Smrg exit $? 562c393a42Smrg ;; 572c393a42Smrgesac 582c393a42Smrg 596fc018e4Smrg# Get the directory component of the given path, and save it in the 606fc018e4Smrg# global variables '$dir'. Note that this directory component will 616fc018e4Smrg# be either empty or ending with a '/' character. This is deliberate. 626fc018e4Smrgset_dir_from () 636fc018e4Smrg{ 646fc018e4Smrg case $1 in 656fc018e4Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 666fc018e4Smrg *) dir=;; 676fc018e4Smrg esac 686fc018e4Smrg} 696fc018e4Smrg 706fc018e4Smrg# Get the suffix-stripped basename of the given path, and save it the 716fc018e4Smrg# global variable '$base'. 726fc018e4Smrgset_base_from () 736fc018e4Smrg{ 746fc018e4Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 756fc018e4Smrg} 766fc018e4Smrg 776fc018e4Smrg# If no dependency file was actually created by the compiler invocation, 786fc018e4Smrg# we still have to create a dummy depfile, to avoid errors with the 796fc018e4Smrg# Makefile "include basename.Plo" scheme. 806fc018e4Smrgmake_dummy_depfile () 816fc018e4Smrg{ 826fc018e4Smrg echo "#dummy" > "$depfile" 836fc018e4Smrg} 846fc018e4Smrg 856fc018e4Smrg# Factor out some common post-processing of the generated depfile. 866fc018e4Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 876fc018e4Smrgaix_post_process_depfile () 886fc018e4Smrg{ 896fc018e4Smrg # If the compiler actually managed to produce a dependency file, 906fc018e4Smrg # post-process it. 916fc018e4Smrg if test -f "$tmpdepfile"; then 926fc018e4Smrg # Each line is of the form 'foo.o: dependency.h'. 936fc018e4Smrg # Do two passes, one to just change these to 946fc018e4Smrg # $object: dependency.h 956fc018e4Smrg # and one to simply output 966fc018e4Smrg # dependency.h: 976fc018e4Smrg # which is needed to avoid the deleted-header problem. 986fc018e4Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 996fc018e4Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1006fc018e4Smrg } > "$depfile" 1016fc018e4Smrg rm -f "$tmpdepfile" 1026fc018e4Smrg else 1036fc018e4Smrg make_dummy_depfile 1046fc018e4Smrg fi 1056fc018e4Smrg} 1066fc018e4Smrg 107ca08ab68Smrg# A tabulation character. 108ca08ab68Smrgtab=' ' 109ca08ab68Smrg# A newline character. 110ca08ab68Smrgnl=' 111ca08ab68Smrg' 1126fc018e4Smrg# Character ranges might be problematic outside the C locale. 1136fc018e4Smrg# These definitions help. 1146fc018e4Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1156fc018e4Smrglower=abcdefghijklmnopqrstuvwxyz 1166fc018e4Smrgdigits=0123456789 1176fc018e4Smrgalpha=${upper}${lower} 118ca08ab68Smrg 1192c393a42Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1202c393a42Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1212c393a42Smrg exit 1 1222c393a42Smrgfi 1232c393a42Smrg 1242c393a42Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1252c393a42Smrgdepfile=${depfile-`echo "$object" | 1262c393a42Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1272c393a42Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1282c393a42Smrg 1292c393a42Smrgrm -f "$tmpdepfile" 1302c393a42Smrg 1316fc018e4Smrg# Avoid interferences from the environment. 1326fc018e4Smrggccflag= dashmflag= 1336fc018e4Smrg 1342c393a42Smrg# Some modes work just like other modes, but use different flags. We 1352c393a42Smrg# parameterize here, but still list the modes in the big case below, 1362c393a42Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1372c393a42Smrg# here, because this file can only contain one case statement. 1382c393a42Smrgif test "$depmode" = hp; then 1392c393a42Smrg # HP compiler uses -M and no extra arg. 1402c393a42Smrg gccflag=-M 1412c393a42Smrg depmode=gcc 1422c393a42Smrgfi 1432c393a42Smrg 1442c393a42Smrgif test "$depmode" = dashXmstdout; then 1456fc018e4Smrg # This is just like dashmstdout with a different argument. 1466fc018e4Smrg dashmflag=-xM 1476fc018e4Smrg depmode=dashmstdout 1482c393a42Smrgfi 1492c393a42Smrg 150a6844aabSmrgcygpath_u="cygpath -u -f -" 151a6844aabSmrgif test "$depmode" = msvcmsys; then 1526fc018e4Smrg # This is just like msvisualcpp but w/o cygpath translation. 1536fc018e4Smrg # Just convert the backslash-escaped backslashes to single forward 1546fc018e4Smrg # slashes to satisfy depend.m4 1556fc018e4Smrg cygpath_u='sed s,\\\\,/,g' 1566fc018e4Smrg depmode=msvisualcpp 157a6844aabSmrgfi 158a6844aabSmrg 159ca08ab68Smrgif test "$depmode" = msvc7msys; then 1606fc018e4Smrg # This is just like msvc7 but w/o cygpath translation. 1616fc018e4Smrg # Just convert the backslash-escaped backslashes to single forward 1626fc018e4Smrg # slashes to satisfy depend.m4 1636fc018e4Smrg cygpath_u='sed s,\\\\,/,g' 1646fc018e4Smrg depmode=msvc7 165ca08ab68Smrgfi 166ca08ab68Smrg 167ca08ab68Smrgif test "$depmode" = xlc; then 1686fc018e4Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1696fc018e4Smrg gccflag=-qmakedep=gcc,-MF 1706fc018e4Smrg depmode=gcc 171ca08ab68Smrgfi 172ca08ab68Smrg 1732c393a42Smrgcase "$depmode" in 1742c393a42Smrggcc3) 1752c393a42Smrg## gcc 3 implements dependency tracking that does exactly what 1762c393a42Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1772c393a42Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178a6844aabSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179a6844aabSmrg## the command line argument order; so add the flags where they 180a6844aabSmrg## appear in depend2.am. Note that the slowdown incurred here 181a6844aabSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182a6844aabSmrg for arg 183a6844aabSmrg do 184a6844aabSmrg case $arg in 185a6844aabSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186a6844aabSmrg *) set fnord "$@" "$arg" ;; 187a6844aabSmrg esac 188a6844aabSmrg shift # fnord 189a6844aabSmrg shift # $arg 190a6844aabSmrg done 191a6844aabSmrg "$@" 1922c393a42Smrg stat=$? 1936fc018e4Smrg if test $stat -ne 0; then 1942c393a42Smrg rm -f "$tmpdepfile" 1952c393a42Smrg exit $stat 1962c393a42Smrg fi 1972c393a42Smrg mv "$tmpdepfile" "$depfile" 1982c393a42Smrg ;; 1992c393a42Smrg 2002c393a42Smrggcc) 2016fc018e4Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2026fc018e4Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2036fc018e4Smrg## (see the conditional assignment to $gccflag above). 2042c393a42Smrg## There are various ways to get dependency output from gcc. Here's 2052c393a42Smrg## why we pick this rather obscure method: 2062c393a42Smrg## - Don't want to use -MD because we'd like the dependencies to end 2072c393a42Smrg## up in a subdir. Having to rename by hand is ugly. 2082c393a42Smrg## (We might end up doing this anyway to support other compilers.) 2092c393a42Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2106fc018e4Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2116fc018e4Smrg## supported by the other compilers which use the 'gcc' depmode. 2122c393a42Smrg## - Using -M directly means running the compiler twice (even worse 2132c393a42Smrg## than renaming). 2142c393a42Smrg if test -z "$gccflag"; then 2152c393a42Smrg gccflag=-MD, 2162c393a42Smrg fi 2172c393a42Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2182c393a42Smrg stat=$? 2196fc018e4Smrg if test $stat -ne 0; then 2202c393a42Smrg rm -f "$tmpdepfile" 2212c393a42Smrg exit $stat 2222c393a42Smrg fi 2232c393a42Smrg rm -f "$depfile" 2242c393a42Smrg echo "$object : \\" > "$depfile" 2256fc018e4Smrg # The second -e expression handles DOS-style file names with drive 2266fc018e4Smrg # letters. 2272c393a42Smrg sed -e 's/^[^:]*: / /' \ 2282c393a42Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229ca08ab68Smrg## This next piece of magic avoids the "deleted header file" problem. 2302c393a42Smrg## The problem is that when a header file which appears in a .P file 2312c393a42Smrg## is deleted, the dependency causes make to die (because there is 2322c393a42Smrg## typically no way to rebuild the header). We avoid this by adding 2332c393a42Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2342c393a42Smrg## this for us directly. 235ca08ab68Smrg## Some versions of gcc put a space before the ':'. On the theory 2362c393a42Smrg## that the space means something, we add a space to the output as 237ca08ab68Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238ca08ab68Smrg## to the object. Take care to not repeat it in the output. 2392c393a42Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2402c393a42Smrg## correctly. Breaking it into two sed invocations is a workaround. 2416fc018e4Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2426fc018e4Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2436fc018e4Smrg | sed -e 's/$/ :/' >> "$depfile" 2442c393a42Smrg rm -f "$tmpdepfile" 2452c393a42Smrg ;; 2462c393a42Smrg 2472c393a42Smrghp) 2482c393a42Smrg # This case exists only to let depend.m4 do its work. It works by 2492c393a42Smrg # looking at the text of this script. This case will never be run, 2502c393a42Smrg # since it is checked for above. 2512c393a42Smrg exit 1 2522c393a42Smrg ;; 2532c393a42Smrg 2542c393a42Smrgsgi) 2552c393a42Smrg if test "$libtool" = yes; then 2562c393a42Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2572c393a42Smrg else 2582c393a42Smrg "$@" -MDupdate "$tmpdepfile" 2592c393a42Smrg fi 2602c393a42Smrg stat=$? 2616fc018e4Smrg if test $stat -ne 0; then 2622c393a42Smrg rm -f "$tmpdepfile" 2632c393a42Smrg exit $stat 2642c393a42Smrg fi 2652c393a42Smrg rm -f "$depfile" 2662c393a42Smrg 2672c393a42Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2682c393a42Smrg echo "$object : \\" > "$depfile" 2692c393a42Smrg # Clip off the initial element (the dependent). Don't try to be 2702c393a42Smrg # clever and replace this with sed code, as IRIX sed won't handle 2712c393a42Smrg # lines with more than a fixed number of characters (4096 in 2722c393a42Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273ca08ab68Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2742c393a42Smrg # dependency line. 275ca08ab68Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2766fc018e4Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2776fc018e4Smrg | tr "$nl" ' ' >> "$depfile" 278a6844aabSmrg echo >> "$depfile" 2792c393a42Smrg # The second pass generates a dummy entry for each header file. 280ca08ab68Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2816fc018e4Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2826fc018e4Smrg >> "$depfile" 2832c393a42Smrg else 2846fc018e4Smrg make_dummy_depfile 2852c393a42Smrg fi 2862c393a42Smrg rm -f "$tmpdepfile" 2872c393a42Smrg ;; 2882c393a42Smrg 289ca08ab68Smrgxlc) 290ca08ab68Smrg # This case exists only to let depend.m4 do its work. It works by 291ca08ab68Smrg # looking at the text of this script. This case will never be run, 292ca08ab68Smrg # since it is checked for above. 293ca08ab68Smrg exit 1 294ca08ab68Smrg ;; 295ca08ab68Smrg 2962c393a42Smrgaix) 2972c393a42Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2982c393a42Smrg # in a .u file. In older versions, this file always lives in the 299ca08ab68Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3002c393a42Smrg # start of each line; $object doesn't have directory information. 3012c393a42Smrg # Version 6 uses the directory in both cases. 3026fc018e4Smrg set_dir_from "$object" 3036fc018e4Smrg set_base_from "$object" 3042c393a42Smrg if test "$libtool" = yes; then 305a6844aabSmrg tmpdepfile1=$dir$base.u 306a6844aabSmrg tmpdepfile2=$base.u 307a6844aabSmrg tmpdepfile3=$dir.libs/$base.u 3082c393a42Smrg "$@" -Wc,-M 3092c393a42Smrg else 310a6844aabSmrg tmpdepfile1=$dir$base.u 311a6844aabSmrg tmpdepfile2=$dir$base.u 312a6844aabSmrg tmpdepfile3=$dir$base.u 3132c393a42Smrg "$@" -M 3142c393a42Smrg fi 3152c393a42Smrg stat=$? 3166fc018e4Smrg if test $stat -ne 0; then 317a6844aabSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3182c393a42Smrg exit $stat 3192c393a42Smrg fi 3202c393a42Smrg 321a6844aabSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322a6844aabSmrg do 323a6844aabSmrg test -f "$tmpdepfile" && break 324a6844aabSmrg done 3256fc018e4Smrg aix_post_process_depfile 3266fc018e4Smrg ;; 3276fc018e4Smrg 3286fc018e4Smrgtcc) 3296fc018e4Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3306fc018e4Smrg # FIXME: That version still under development at the moment of writing. 3316fc018e4Smrg # Make that this statement remains true also for stable, released 3326fc018e4Smrg # versions. 3336fc018e4Smrg # It will wrap lines (doesn't matter whether long or short) with a 3346fc018e4Smrg # trailing '\', as in: 3356fc018e4Smrg # 3366fc018e4Smrg # foo.o : \ 3376fc018e4Smrg # foo.c \ 3386fc018e4Smrg # foo.h \ 3396fc018e4Smrg # 3406fc018e4Smrg # It will put a trailing '\' even on the last line, and will use leading 3416fc018e4Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3426fc018e4Smrg # "Emit spaces for -MD"). 3436fc018e4Smrg "$@" -MD -MF "$tmpdepfile" 3446fc018e4Smrg stat=$? 3456fc018e4Smrg if test $stat -ne 0; then 3466fc018e4Smrg rm -f "$tmpdepfile" 3476fc018e4Smrg exit $stat 3482c393a42Smrg fi 3496fc018e4Smrg rm -f "$depfile" 3506fc018e4Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3516fc018e4Smrg # We have to change lines of the first kind to '$object: \'. 3526fc018e4Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3536fc018e4Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3546fc018e4Smrg # dummy dependency, to avoid the deleted-header problem. 3556fc018e4Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3562c393a42Smrg rm -f "$tmpdepfile" 3572c393a42Smrg ;; 3582c393a42Smrg 3596fc018e4Smrg## The order of this option in the case statement is important, since the 3606fc018e4Smrg## shell code in configure will try each of these formats in the order 3616fc018e4Smrg## listed in this file. A plain '-MD' option would be understood by many 3626fc018e4Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3636fc018e4Smrgpgcc) 3646fc018e4Smrg # Portland's C compiler understands '-MD'. 3656fc018e4Smrg # Will always output deps to 'file.d' where file is the root name of the 3666fc018e4Smrg # source file under compilation, even if file resides in a subdirectory. 3676fc018e4Smrg # The object file name does not affect the name of the '.d' file. 3686fc018e4Smrg # pgcc 10.2 will output 3692c393a42Smrg # foo.o: sub/foo.c sub/foo.h 3706fc018e4Smrg # and will wrap long lines using '\' : 3712c393a42Smrg # foo.o: sub/foo.c ... \ 3722c393a42Smrg # sub/foo.h ... \ 3732c393a42Smrg # ... 3746fc018e4Smrg set_dir_from "$object" 3756fc018e4Smrg # Use the source, not the object, to determine the base name, since 3766fc018e4Smrg # that's sadly what pgcc will do too. 3776fc018e4Smrg set_base_from "$source" 3786fc018e4Smrg tmpdepfile=$base.d 3796fc018e4Smrg 3806fc018e4Smrg # For projects that build the same source file twice into different object 3816fc018e4Smrg # files, the pgcc approach of using the *source* file root name can cause 3826fc018e4Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3836fc018e4Smrg # the same $tmpdepfile. 3846fc018e4Smrg lockdir=$base.d-lock 3856fc018e4Smrg trap " 3866fc018e4Smrg echo '$0: caught signal, cleaning up...' >&2 3876fc018e4Smrg rmdir '$lockdir' 3886fc018e4Smrg exit 1 3896fc018e4Smrg " 1 2 13 15 3906fc018e4Smrg numtries=100 3916fc018e4Smrg i=$numtries 3926fc018e4Smrg while test $i -gt 0; do 3936fc018e4Smrg # mkdir is a portable test-and-set. 3946fc018e4Smrg if mkdir "$lockdir" 2>/dev/null; then 3956fc018e4Smrg # This process acquired the lock. 3966fc018e4Smrg "$@" -MD 3976fc018e4Smrg stat=$? 3986fc018e4Smrg # Release the lock. 3996fc018e4Smrg rmdir "$lockdir" 4006fc018e4Smrg break 4016fc018e4Smrg else 4026fc018e4Smrg # If the lock is being held by a different process, wait 4036fc018e4Smrg # until the winning process is done or we timeout. 4046fc018e4Smrg while test -d "$lockdir" && test $i -gt 0; do 4056fc018e4Smrg sleep 1 4066fc018e4Smrg i=`expr $i - 1` 4076fc018e4Smrg done 4086fc018e4Smrg fi 4096fc018e4Smrg i=`expr $i - 1` 4106fc018e4Smrg done 4116fc018e4Smrg trap - 1 2 13 15 4126fc018e4Smrg if test $i -le 0; then 4136fc018e4Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4146fc018e4Smrg echo "$0: check lockdir '$lockdir'" >&2 4156fc018e4Smrg exit 1 4166fc018e4Smrg fi 4176fc018e4Smrg 4186fc018e4Smrg if test $stat -ne 0; then 4192c393a42Smrg rm -f "$tmpdepfile" 4202c393a42Smrg exit $stat 4212c393a42Smrg fi 4222c393a42Smrg rm -f "$depfile" 4236fc018e4Smrg # Each line is of the form `foo.o: dependent.h', 4246fc018e4Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4252c393a42Smrg # Do two passes, one to just change these to 4266fc018e4Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4276fc018e4Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4286fc018e4Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4296fc018e4Smrg # correctly. Breaking it into two sed invocations is a workaround. 4306fc018e4Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4316fc018e4Smrg | sed -e 's/$/ :/' >> "$depfile" 4322c393a42Smrg rm -f "$tmpdepfile" 4332c393a42Smrg ;; 4342c393a42Smrg 435a6844aabSmrghp2) 436a6844aabSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437a6844aabSmrg # compilers, which have integrated preprocessors. The correct option 438a6844aabSmrg # to use with these is +Maked; it writes dependencies to a file named 439a6844aabSmrg # 'foo.d', which lands next to the object file, wherever that 440a6844aabSmrg # happens to be. 441a6844aabSmrg # Much of this is similar to the tru64 case; see comments there. 4426fc018e4Smrg set_dir_from "$object" 4436fc018e4Smrg set_base_from "$object" 444a6844aabSmrg if test "$libtool" = yes; then 445a6844aabSmrg tmpdepfile1=$dir$base.d 446a6844aabSmrg tmpdepfile2=$dir.libs/$base.d 447a6844aabSmrg "$@" -Wc,+Maked 448a6844aabSmrg else 449a6844aabSmrg tmpdepfile1=$dir$base.d 450a6844aabSmrg tmpdepfile2=$dir$base.d 451a6844aabSmrg "$@" +Maked 452a6844aabSmrg fi 453a6844aabSmrg stat=$? 4546fc018e4Smrg if test $stat -ne 0; then 455a6844aabSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456a6844aabSmrg exit $stat 457a6844aabSmrg fi 458a6844aabSmrg 459a6844aabSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460a6844aabSmrg do 461a6844aabSmrg test -f "$tmpdepfile" && break 462a6844aabSmrg done 463a6844aabSmrg if test -f "$tmpdepfile"; then 4646fc018e4Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465ca08ab68Smrg # Add 'dependent.h:' lines. 466a6844aabSmrg sed -ne '2,${ 4676fc018e4Smrg s/^ *// 4686fc018e4Smrg s/ \\*$// 4696fc018e4Smrg s/$/:/ 4706fc018e4Smrg p 4716fc018e4Smrg }' "$tmpdepfile" >> "$depfile" 472a6844aabSmrg else 4736fc018e4Smrg make_dummy_depfile 474a6844aabSmrg fi 475a6844aabSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 476a6844aabSmrg ;; 477a6844aabSmrg 4782c393a42Smrgtru64) 4796fc018e4Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4806fc018e4Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4816fc018e4Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4826fc018e4Smrg # dependencies in 'foo.d' instead, so we check for that too. 4836fc018e4Smrg # Subdirectories are respected. 4846fc018e4Smrg set_dir_from "$object" 4856fc018e4Smrg set_base_from "$object" 4866fc018e4Smrg 4876fc018e4Smrg if test "$libtool" = yes; then 4886fc018e4Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4896fc018e4Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4906fc018e4Smrg # in $dir$base.o.d. We have to check for both files, because 4916fc018e4Smrg # one of the two compilations can be disabled. We should prefer 4926fc018e4Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4936fc018e4Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4946fc018e4Smrg # the former would cause a distcleancheck panic. 4956fc018e4Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4966fc018e4Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4976fc018e4Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4986fc018e4Smrg "$@" -Wc,-MD 4996fc018e4Smrg else 5006fc018e4Smrg tmpdepfile1=$dir$base.d 5016fc018e4Smrg tmpdepfile2=$dir$base.d 5026fc018e4Smrg tmpdepfile3=$dir$base.d 5036fc018e4Smrg "$@" -MD 5046fc018e4Smrg fi 5056fc018e4Smrg 5066fc018e4Smrg stat=$? 5076fc018e4Smrg if test $stat -ne 0; then 5086fc018e4Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5096fc018e4Smrg exit $stat 5106fc018e4Smrg fi 5116fc018e4Smrg 5126fc018e4Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5136fc018e4Smrg do 5146fc018e4Smrg test -f "$tmpdepfile" && break 5156fc018e4Smrg done 5166fc018e4Smrg # Same post-processing that is required for AIX mode. 5176fc018e4Smrg aix_post_process_depfile 5186fc018e4Smrg ;; 5192c393a42Smrg 520ca08ab68Smrgmsvc7) 521ca08ab68Smrg if test "$libtool" = yes; then 522ca08ab68Smrg showIncludes=-Wc,-showIncludes 523ca08ab68Smrg else 524ca08ab68Smrg showIncludes=-showIncludes 525ca08ab68Smrg fi 526ca08ab68Smrg "$@" $showIncludes > "$tmpdepfile" 527ca08ab68Smrg stat=$? 528ca08ab68Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5296fc018e4Smrg if test $stat -ne 0; then 530ca08ab68Smrg rm -f "$tmpdepfile" 531ca08ab68Smrg exit $stat 532ca08ab68Smrg fi 533ca08ab68Smrg rm -f "$depfile" 534ca08ab68Smrg echo "$object : \\" > "$depfile" 535ca08ab68Smrg # The first sed program below extracts the file names and escapes 536ca08ab68Smrg # backslashes for cygpath. The second sed program outputs the file 537ca08ab68Smrg # name when reading, but also accumulates all include files in the 538ca08ab68Smrg # hold buffer in order to output them again at the end. This only 539ca08ab68Smrg # works with sed implementations that can handle large buffers. 540ca08ab68Smrg sed < "$tmpdepfile" -n ' 541ca08ab68Smrg/^Note: including file: *\(.*\)/ { 542ca08ab68Smrg s//\1/ 543ca08ab68Smrg s/\\/\\\\/g 544ca08ab68Smrg p 545ca08ab68Smrg}' | $cygpath_u | sort -u | sed -n ' 546ca08ab68Smrgs/ /\\ /g 547ca08ab68Smrgs/\(.*\)/'"$tab"'\1 \\/p 548ca08ab68Smrgs/.\(.*\) \\/\1:/ 549ca08ab68SmrgH 550ca08ab68Smrg$ { 551ca08ab68Smrg s/.*/'"$tab"'/ 552ca08ab68Smrg G 553ca08ab68Smrg p 554ca08ab68Smrg}' >> "$depfile" 5556fc018e4Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556ca08ab68Smrg rm -f "$tmpdepfile" 557ca08ab68Smrg ;; 558ca08ab68Smrg 559ca08ab68Smrgmsvc7msys) 560ca08ab68Smrg # This case exists only to let depend.m4 do its work. It works by 561ca08ab68Smrg # looking at the text of this script. This case will never be run, 562ca08ab68Smrg # since it is checked for above. 563ca08ab68Smrg exit 1 564ca08ab68Smrg ;; 565ca08ab68Smrg 5662c393a42Smrg#nosideeffect) 5672c393a42Smrg # This comment above is used by automake to tell side-effect 5682c393a42Smrg # dependency tracking mechanisms from slower ones. 5692c393a42Smrg 5702c393a42Smrgdashmstdout) 5712c393a42Smrg # Important note: in order to support this mode, a compiler *must* 5722c393a42Smrg # always write the preprocessed file to stdout, regardless of -o. 5732c393a42Smrg "$@" || exit $? 5742c393a42Smrg 5752c393a42Smrg # Remove the call to Libtool. 5762c393a42Smrg if test "$libtool" = yes; then 577a6844aabSmrg while test "X$1" != 'X--mode=compile'; do 5782c393a42Smrg shift 5792c393a42Smrg done 5802c393a42Smrg shift 5812c393a42Smrg fi 5822c393a42Smrg 583ca08ab68Smrg # Remove '-o $object'. 5842c393a42Smrg IFS=" " 5852c393a42Smrg for arg 5862c393a42Smrg do 5872c393a42Smrg case $arg in 5882c393a42Smrg -o) 5892c393a42Smrg shift 5902c393a42Smrg ;; 5912c393a42Smrg $object) 5922c393a42Smrg shift 5932c393a42Smrg ;; 5942c393a42Smrg *) 5952c393a42Smrg set fnord "$@" "$arg" 5962c393a42Smrg shift # fnord 5972c393a42Smrg shift # $arg 5982c393a42Smrg ;; 5992c393a42Smrg esac 6002c393a42Smrg done 6012c393a42Smrg 6022c393a42Smrg test -z "$dashmflag" && dashmflag=-M 603ca08ab68Smrg # Require at least two characters before searching for ':' 6042c393a42Smrg # in the target name. This is to cope with DOS-style filenames: 605ca08ab68Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6062c393a42Smrg "$@" $dashmflag | 6076fc018e4Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6082c393a42Smrg rm -f "$depfile" 6092c393a42Smrg cat < "$tmpdepfile" > "$depfile" 6106fc018e4Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6116fc018e4Smrg # correctly. Breaking it into two sed invocations is a workaround. 6126fc018e4Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6136fc018e4Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6146fc018e4Smrg | sed -e 's/$/ :/' >> "$depfile" 6152c393a42Smrg rm -f "$tmpdepfile" 6162c393a42Smrg ;; 6172c393a42Smrg 6182c393a42SmrgdashXmstdout) 6192c393a42Smrg # This case only exists to satisfy depend.m4. It is never actually 6202c393a42Smrg # run, as this mode is specially recognized in the preamble. 6212c393a42Smrg exit 1 6222c393a42Smrg ;; 6232c393a42Smrg 6242c393a42Smrgmakedepend) 6252c393a42Smrg "$@" || exit $? 6262c393a42Smrg # Remove any Libtool call 6272c393a42Smrg if test "$libtool" = yes; then 628a6844aabSmrg while test "X$1" != 'X--mode=compile'; do 6292c393a42Smrg shift 6302c393a42Smrg done 6312c393a42Smrg shift 6322c393a42Smrg fi 6332c393a42Smrg # X makedepend 6342c393a42Smrg shift 635a6844aabSmrg cleared=no eat=no 636a6844aabSmrg for arg 637a6844aabSmrg do 6382c393a42Smrg case $cleared in 6392c393a42Smrg no) 6402c393a42Smrg set ""; shift 6412c393a42Smrg cleared=yes ;; 6422c393a42Smrg esac 643a6844aabSmrg if test $eat = yes; then 644a6844aabSmrg eat=no 645a6844aabSmrg continue 646a6844aabSmrg fi 6472c393a42Smrg case "$arg" in 6482c393a42Smrg -D*|-I*) 6492c393a42Smrg set fnord "$@" "$arg"; shift ;; 6502c393a42Smrg # Strip any option that makedepend may not understand. Remove 6512c393a42Smrg # the object too, otherwise makedepend will parse it as a source file. 652a6844aabSmrg -arch) 653a6844aabSmrg eat=yes ;; 6542c393a42Smrg -*|$object) 6552c393a42Smrg ;; 6562c393a42Smrg *) 6572c393a42Smrg set fnord "$@" "$arg"; shift ;; 6582c393a42Smrg esac 6592c393a42Smrg done 660a6844aabSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6612c393a42Smrg touch "$tmpdepfile" 6622c393a42Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6632c393a42Smrg rm -f "$depfile" 664ca08ab68Smrg # makedepend may prepend the VPATH from the source file name to the object. 665ca08ab68Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666ca08ab68Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6676fc018e4Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6686fc018e4Smrg # correctly. Breaking it into two sed invocations is a workaround. 6696fc018e4Smrg sed '1,2d' "$tmpdepfile" \ 6706fc018e4Smrg | tr ' ' "$nl" \ 6716fc018e4Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6726fc018e4Smrg | sed -e 's/$/ :/' >> "$depfile" 6732c393a42Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6742c393a42Smrg ;; 6752c393a42Smrg 6762c393a42Smrgcpp) 6772c393a42Smrg # Important note: in order to support this mode, a compiler *must* 6782c393a42Smrg # always write the preprocessed file to stdout. 6792c393a42Smrg "$@" || exit $? 6802c393a42Smrg 6812c393a42Smrg # Remove the call to Libtool. 6822c393a42Smrg if test "$libtool" = yes; then 683a6844aabSmrg while test "X$1" != 'X--mode=compile'; do 6842c393a42Smrg shift 6852c393a42Smrg done 6862c393a42Smrg shift 6872c393a42Smrg fi 6882c393a42Smrg 689ca08ab68Smrg # Remove '-o $object'. 6902c393a42Smrg IFS=" " 6912c393a42Smrg for arg 6922c393a42Smrg do 6932c393a42Smrg case $arg in 6942c393a42Smrg -o) 6952c393a42Smrg shift 6962c393a42Smrg ;; 6972c393a42Smrg $object) 6982c393a42Smrg shift 6992c393a42Smrg ;; 7002c393a42Smrg *) 7012c393a42Smrg set fnord "$@" "$arg" 7022c393a42Smrg shift # fnord 7032c393a42Smrg shift # $arg 7042c393a42Smrg ;; 7052c393a42Smrg esac 7062c393a42Smrg done 7072c393a42Smrg 7086fc018e4Smrg "$@" -E \ 7096fc018e4Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7106fc018e4Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7116fc018e4Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7122c393a42Smrg rm -f "$depfile" 7132c393a42Smrg echo "$object : \\" > "$depfile" 7142c393a42Smrg cat < "$tmpdepfile" >> "$depfile" 7152c393a42Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7162c393a42Smrg rm -f "$tmpdepfile" 7172c393a42Smrg ;; 7182c393a42Smrg 7192c393a42Smrgmsvisualcpp) 7202c393a42Smrg # Important note: in order to support this mode, a compiler *must* 721a6844aabSmrg # always write the preprocessed file to stdout. 7222c393a42Smrg "$@" || exit $? 723a6844aabSmrg 724a6844aabSmrg # Remove the call to Libtool. 725a6844aabSmrg if test "$libtool" = yes; then 726a6844aabSmrg while test "X$1" != 'X--mode=compile'; do 727a6844aabSmrg shift 728a6844aabSmrg done 729a6844aabSmrg shift 730a6844aabSmrg fi 731a6844aabSmrg 7322c393a42Smrg IFS=" " 7332c393a42Smrg for arg 7342c393a42Smrg do 7352c393a42Smrg case "$arg" in 736a6844aabSmrg -o) 737a6844aabSmrg shift 738a6844aabSmrg ;; 739a6844aabSmrg $object) 740a6844aabSmrg shift 741a6844aabSmrg ;; 7422c393a42Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7436fc018e4Smrg set fnord "$@" 7446fc018e4Smrg shift 7456fc018e4Smrg shift 7466fc018e4Smrg ;; 7472c393a42Smrg *) 7486fc018e4Smrg set fnord "$@" "$arg" 7496fc018e4Smrg shift 7506fc018e4Smrg shift 7516fc018e4Smrg ;; 7522c393a42Smrg esac 7532c393a42Smrg done 754a6844aabSmrg "$@" -E 2>/dev/null | 755a6844aabSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7562c393a42Smrg rm -f "$depfile" 7572c393a42Smrg echo "$object : \\" > "$depfile" 758ca08ab68Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759ca08ab68Smrg echo "$tab" >> "$depfile" 760a6844aabSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7612c393a42Smrg rm -f "$tmpdepfile" 7622c393a42Smrg ;; 7632c393a42Smrg 764a6844aabSmrgmsvcmsys) 765a6844aabSmrg # This case exists only to let depend.m4 do its work. It works by 766a6844aabSmrg # looking at the text of this script. This case will never be run, 767a6844aabSmrg # since it is checked for above. 768a6844aabSmrg exit 1 769a6844aabSmrg ;; 770a6844aabSmrg 7712c393a42Smrgnone) 7722c393a42Smrg exec "$@" 7732c393a42Smrg ;; 7742c393a42Smrg 7752c393a42Smrg*) 7762c393a42Smrg echo "Unknown depmode $depmode" 1>&2 7772c393a42Smrg exit 1 7782c393a42Smrg ;; 7792c393a42Smrgesac 7802c393a42Smrg 7812c393a42Smrgexit 0 7822c393a42Smrg 7832c393a42Smrg# Local Variables: 7842c393a42Smrg# mode: shell-script 7852c393a42Smrg# sh-indentation: 2 786a32e9e42Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 7872c393a42Smrg# time-stamp-start: "scriptversion=" 7882c393a42Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789a32e9e42Smrg# time-stamp-time-zone: "UTC0" 790a6844aabSmrg# time-stamp-end: "; # UTC" 7912c393a42Smrg# End: 792