depcomp revision 5dd5f640
1e9554658Smrg#! /bin/sh 2e9554658Smrg# depcomp - compile a program generating dependencies as side-effects 3e9554658Smrg 45dd5f640Smrgscriptversion=2013-05-30.07; # UTC 5e9554658Smrg 65dd5f640Smrg# Copyright (C) 1999-2013 Free Software Foundation, Inc. 7e9554658Smrg 8e9554658Smrg# This program is free software; you can redistribute it and/or modify 9e9554658Smrg# it under the terms of the GNU General Public License as published by 10e9554658Smrg# the Free Software Foundation; either version 2, or (at your option) 11e9554658Smrg# any later version. 12e9554658Smrg 13e9554658Smrg# This program is distributed in the hope that it will be useful, 14e9554658Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15e9554658Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16e9554658Smrg# GNU General Public License for more details. 17e9554658Smrg 18e9554658Smrg# You should have received a copy of the GNU General Public License 19c2b339b4Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20e9554658Smrg 21e9554658Smrg# As a special exception to the GNU General Public License, if you 22e9554658Smrg# distribute this file as part of a program that contains a 23e9554658Smrg# configuration script generated by Autoconf, you may include it under 24e9554658Smrg# the same distribution terms that you use for the rest of that program. 25e9554658Smrg 26e9554658Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27e9554658Smrg 28e9554658Smrgcase $1 in 29e9554658Smrg '') 305dd5f640Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 315dd5f640Smrg exit 1; 325dd5f640Smrg ;; 33e9554658Smrg -h | --h*) 34e9554658Smrg cat <<\EOF 35e9554658SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36e9554658Smrg 37e9554658SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38e9554658Smrgas side-effects. 39e9554658Smrg 40e9554658SmrgEnvironment variables: 41e9554658Smrg depmode Dependency tracking mode. 425dd5f640Smrg source Source file read by 'PROGRAMS ARGS'. 435dd5f640Smrg object Object file output by 'PROGRAMS ARGS'. 44e9554658Smrg DEPDIR directory where to store dependencies. 45e9554658Smrg depfile Dependency file to output. 465dd5f640Smrg tmpdepfile Temporary file to use when outputting dependencies. 47e9554658Smrg libtool Whether libtool is used (yes/no). 48e9554658Smrg 49e9554658SmrgReport bugs to <bug-automake@gnu.org>. 50e9554658SmrgEOF 51e9554658Smrg exit $? 52e9554658Smrg ;; 53e9554658Smrg -v | --v*) 54e9554658Smrg echo "depcomp $scriptversion" 55e9554658Smrg exit $? 56e9554658Smrg ;; 57e9554658Smrgesac 58e9554658Smrg 595dd5f640Smrg# Get the directory component of the given path, and save it in the 605dd5f640Smrg# global variables '$dir'. Note that this directory component will 615dd5f640Smrg# be either empty or ending with a '/' character. This is deliberate. 625dd5f640Smrgset_dir_from () 635dd5f640Smrg{ 645dd5f640Smrg case $1 in 655dd5f640Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 665dd5f640Smrg *) dir=;; 675dd5f640Smrg esac 685dd5f640Smrg} 695dd5f640Smrg 705dd5f640Smrg# Get the suffix-stripped basename of the given path, and save it the 715dd5f640Smrg# global variable '$base'. 725dd5f640Smrgset_base_from () 735dd5f640Smrg{ 745dd5f640Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 755dd5f640Smrg} 765dd5f640Smrg 775dd5f640Smrg# If no dependency file was actually created by the compiler invocation, 785dd5f640Smrg# we still have to create a dummy depfile, to avoid errors with the 795dd5f640Smrg# Makefile "include basename.Plo" scheme. 805dd5f640Smrgmake_dummy_depfile () 815dd5f640Smrg{ 825dd5f640Smrg echo "#dummy" > "$depfile" 835dd5f640Smrg} 845dd5f640Smrg 855dd5f640Smrg# Factor out some common post-processing of the generated depfile. 865dd5f640Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 875dd5f640Smrgaix_post_process_depfile () 885dd5f640Smrg{ 895dd5f640Smrg # If the compiler actually managed to produce a dependency file, 905dd5f640Smrg # post-process it. 915dd5f640Smrg if test -f "$tmpdepfile"; then 925dd5f640Smrg # Each line is of the form 'foo.o: dependency.h'. 935dd5f640Smrg # Do two passes, one to just change these to 945dd5f640Smrg # $object: dependency.h 955dd5f640Smrg # and one to simply output 965dd5f640Smrg # dependency.h: 975dd5f640Smrg # which is needed to avoid the deleted-header problem. 985dd5f640Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 995dd5f640Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1005dd5f640Smrg } > "$depfile" 1015dd5f640Smrg rm -f "$tmpdepfile" 1025dd5f640Smrg else 1035dd5f640Smrg make_dummy_depfile 1045dd5f640Smrg fi 1055dd5f640Smrg} 1065dd5f640Smrg 1075dd5f640Smrg# A tabulation character. 1085dd5f640Smrgtab=' ' 1095dd5f640Smrg# A newline character. 1105dd5f640Smrgnl=' 1115dd5f640Smrg' 1125dd5f640Smrg# Character ranges might be problematic outside the C locale. 1135dd5f640Smrg# These definitions help. 1145dd5f640Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1155dd5f640Smrglower=abcdefghijklmnopqrstuvwxyz 1165dd5f640Smrgdigits=0123456789 1175dd5f640Smrgalpha=${upper}${lower} 1185dd5f640Smrg 119e9554658Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120e9554658Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121e9554658Smrg exit 1 122e9554658Smrgfi 123e9554658Smrg 124e9554658Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125e9554658Smrgdepfile=${depfile-`echo "$object" | 126e9554658Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127e9554658Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128e9554658Smrg 129e9554658Smrgrm -f "$tmpdepfile" 130e9554658Smrg 1315dd5f640Smrg# Avoid interferences from the environment. 1325dd5f640Smrggccflag= dashmflag= 1335dd5f640Smrg 134e9554658Smrg# Some modes work just like other modes, but use different flags. We 135e9554658Smrg# parameterize here, but still list the modes in the big case below, 136e9554658Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137e9554658Smrg# here, because this file can only contain one case statement. 138e9554658Smrgif test "$depmode" = hp; then 139e9554658Smrg # HP compiler uses -M and no extra arg. 140e9554658Smrg gccflag=-M 141e9554658Smrg depmode=gcc 142e9554658Smrgfi 143e9554658Smrg 144e9554658Smrgif test "$depmode" = dashXmstdout; then 1455dd5f640Smrg # This is just like dashmstdout with a different argument. 1465dd5f640Smrg dashmflag=-xM 1475dd5f640Smrg depmode=dashmstdout 148e9554658Smrgfi 149e9554658Smrg 150c2b339b4Smrgcygpath_u="cygpath -u -f -" 151c2b339b4Smrgif test "$depmode" = msvcmsys; then 1525dd5f640Smrg # This is just like msvisualcpp but w/o cygpath translation. 1535dd5f640Smrg # Just convert the backslash-escaped backslashes to single forward 1545dd5f640Smrg # slashes to satisfy depend.m4 1555dd5f640Smrg cygpath_u='sed s,\\\\,/,g' 1565dd5f640Smrg depmode=msvisualcpp 1575dd5f640Smrgfi 1585dd5f640Smrg 1595dd5f640Smrgif test "$depmode" = msvc7msys; then 1605dd5f640Smrg # This is just like msvc7 but w/o cygpath translation. 1615dd5f640Smrg # Just convert the backslash-escaped backslashes to single forward 1625dd5f640Smrg # slashes to satisfy depend.m4 1635dd5f640Smrg cygpath_u='sed s,\\\\,/,g' 1645dd5f640Smrg depmode=msvc7 1655dd5f640Smrgfi 1665dd5f640Smrg 1675dd5f640Smrgif test "$depmode" = xlc; then 1685dd5f640Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1695dd5f640Smrg gccflag=-qmakedep=gcc,-MF 1705dd5f640Smrg depmode=gcc 171c2b339b4Smrgfi 172c2b339b4Smrg 173e9554658Smrgcase "$depmode" in 174e9554658Smrggcc3) 175e9554658Smrg## gcc 3 implements dependency tracking that does exactly what 176e9554658Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177e9554658Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178e9554658Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179e9554658Smrg## the command line argument order; so add the flags where they 180e9554658Smrg## appear in depend2.am. Note that the slowdown incurred here 181e9554658Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182e9554658Smrg for arg 183e9554658Smrg do 184e9554658Smrg case $arg in 185e9554658Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186e9554658Smrg *) set fnord "$@" "$arg" ;; 187e9554658Smrg esac 188e9554658Smrg shift # fnord 189e9554658Smrg shift # $arg 190e9554658Smrg done 191e9554658Smrg "$@" 192e9554658Smrg stat=$? 1935dd5f640Smrg if test $stat -ne 0; then 194e9554658Smrg rm -f "$tmpdepfile" 195e9554658Smrg exit $stat 196e9554658Smrg fi 197e9554658Smrg mv "$tmpdepfile" "$depfile" 198e9554658Smrg ;; 199e9554658Smrg 200e9554658Smrggcc) 2015dd5f640Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2025dd5f640Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2035dd5f640Smrg## (see the conditional assignment to $gccflag above). 204e9554658Smrg## There are various ways to get dependency output from gcc. Here's 205e9554658Smrg## why we pick this rather obscure method: 206e9554658Smrg## - Don't want to use -MD because we'd like the dependencies to end 207e9554658Smrg## up in a subdir. Having to rename by hand is ugly. 208e9554658Smrg## (We might end up doing this anyway to support other compilers.) 209e9554658Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2105dd5f640Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2115dd5f640Smrg## supported by the other compilers which use the 'gcc' depmode. 212e9554658Smrg## - Using -M directly means running the compiler twice (even worse 213e9554658Smrg## than renaming). 214e9554658Smrg if test -z "$gccflag"; then 215e9554658Smrg gccflag=-MD, 216e9554658Smrg fi 217e9554658Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218e9554658Smrg stat=$? 2195dd5f640Smrg if test $stat -ne 0; then 220e9554658Smrg rm -f "$tmpdepfile" 221e9554658Smrg exit $stat 222e9554658Smrg fi 223e9554658Smrg rm -f "$depfile" 224e9554658Smrg echo "$object : \\" > "$depfile" 2255dd5f640Smrg # The second -e expression handles DOS-style file names with drive 2265dd5f640Smrg # letters. 227e9554658Smrg sed -e 's/^[^:]*: / /' \ 228e9554658Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2295dd5f640Smrg## This next piece of magic avoids the "deleted header file" problem. 230e9554658Smrg## The problem is that when a header file which appears in a .P file 231e9554658Smrg## is deleted, the dependency causes make to die (because there is 232e9554658Smrg## typically no way to rebuild the header). We avoid this by adding 233e9554658Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234e9554658Smrg## this for us directly. 2355dd5f640Smrg## Some versions of gcc put a space before the ':'. On the theory 236e9554658Smrg## that the space means something, we add a space to the output as 2375dd5f640Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 2385dd5f640Smrg## to the object. Take care to not repeat it in the output. 239e9554658Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240e9554658Smrg## correctly. Breaking it into two sed invocations is a workaround. 2415dd5f640Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2425dd5f640Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2435dd5f640Smrg | sed -e 's/$/ :/' >> "$depfile" 244e9554658Smrg rm -f "$tmpdepfile" 245e9554658Smrg ;; 246e9554658Smrg 247e9554658Smrghp) 248e9554658Smrg # This case exists only to let depend.m4 do its work. It works by 249e9554658Smrg # looking at the text of this script. This case will never be run, 250e9554658Smrg # since it is checked for above. 251e9554658Smrg exit 1 252e9554658Smrg ;; 253e9554658Smrg 254e9554658Smrgsgi) 255e9554658Smrg if test "$libtool" = yes; then 256e9554658Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257e9554658Smrg else 258e9554658Smrg "$@" -MDupdate "$tmpdepfile" 259e9554658Smrg fi 260e9554658Smrg stat=$? 2615dd5f640Smrg if test $stat -ne 0; then 262e9554658Smrg rm -f "$tmpdepfile" 263e9554658Smrg exit $stat 264e9554658Smrg fi 265e9554658Smrg rm -f "$depfile" 266e9554658Smrg 267e9554658Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268e9554658Smrg echo "$object : \\" > "$depfile" 269e9554658Smrg # Clip off the initial element (the dependent). Don't try to be 270e9554658Smrg # clever and replace this with sed code, as IRIX sed won't handle 271e9554658Smrg # lines with more than a fixed number of characters (4096 in 272e9554658Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2735dd5f640Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274e9554658Smrg # dependency line. 2755dd5f640Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2765dd5f640Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2775dd5f640Smrg | tr "$nl" ' ' >> "$depfile" 278c2b339b4Smrg echo >> "$depfile" 279e9554658Smrg # The second pass generates a dummy entry for each header file. 2805dd5f640Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2815dd5f640Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2825dd5f640Smrg >> "$depfile" 283e9554658Smrg else 2845dd5f640Smrg make_dummy_depfile 285e9554658Smrg fi 286e9554658Smrg rm -f "$tmpdepfile" 287e9554658Smrg ;; 288e9554658Smrg 2895dd5f640Smrgxlc) 2905dd5f640Smrg # This case exists only to let depend.m4 do its work. It works by 2915dd5f640Smrg # looking at the text of this script. This case will never be run, 2925dd5f640Smrg # since it is checked for above. 2935dd5f640Smrg exit 1 2945dd5f640Smrg ;; 2955dd5f640Smrg 296e9554658Smrgaix) 297e9554658Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298e9554658Smrg # in a .u file. In older versions, this file always lives in the 2995dd5f640Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300e9554658Smrg # start of each line; $object doesn't have directory information. 301e9554658Smrg # Version 6 uses the directory in both cases. 3025dd5f640Smrg set_dir_from "$object" 3035dd5f640Smrg set_base_from "$object" 304e9554658Smrg if test "$libtool" = yes; then 305c2b339b4Smrg tmpdepfile1=$dir$base.u 306c2b339b4Smrg tmpdepfile2=$base.u 307c2b339b4Smrg tmpdepfile3=$dir.libs/$base.u 308e9554658Smrg "$@" -Wc,-M 309e9554658Smrg else 310c2b339b4Smrg tmpdepfile1=$dir$base.u 311c2b339b4Smrg tmpdepfile2=$dir$base.u 312c2b339b4Smrg tmpdepfile3=$dir$base.u 313e9554658Smrg "$@" -M 314e9554658Smrg fi 315e9554658Smrg stat=$? 3165dd5f640Smrg if test $stat -ne 0; then 317c2b339b4Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318e9554658Smrg exit $stat 319e9554658Smrg fi 320e9554658Smrg 321c2b339b4Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322c2b339b4Smrg do 323c2b339b4Smrg test -f "$tmpdepfile" && break 324c2b339b4Smrg done 3255dd5f640Smrg aix_post_process_depfile 3265dd5f640Smrg ;; 3275dd5f640Smrg 3285dd5f640Smrgtcc) 3295dd5f640Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3305dd5f640Smrg # FIXME: That version still under development at the moment of writing. 3315dd5f640Smrg # Make that this statement remains true also for stable, released 3325dd5f640Smrg # versions. 3335dd5f640Smrg # It will wrap lines (doesn't matter whether long or short) with a 3345dd5f640Smrg # trailing '\', as in: 3355dd5f640Smrg # 3365dd5f640Smrg # foo.o : \ 3375dd5f640Smrg # foo.c \ 3385dd5f640Smrg # foo.h \ 3395dd5f640Smrg # 3405dd5f640Smrg # It will put a trailing '\' even on the last line, and will use leading 3415dd5f640Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3425dd5f640Smrg # "Emit spaces for -MD"). 3435dd5f640Smrg "$@" -MD -MF "$tmpdepfile" 3445dd5f640Smrg stat=$? 3455dd5f640Smrg if test $stat -ne 0; then 3465dd5f640Smrg rm -f "$tmpdepfile" 3475dd5f640Smrg exit $stat 348e9554658Smrg fi 3495dd5f640Smrg rm -f "$depfile" 3505dd5f640Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3515dd5f640Smrg # We have to change lines of the first kind to '$object: \'. 3525dd5f640Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3535dd5f640Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3545dd5f640Smrg # dummy dependency, to avoid the deleted-header problem. 3555dd5f640Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356e9554658Smrg rm -f "$tmpdepfile" 357e9554658Smrg ;; 358e9554658Smrg 3595dd5f640Smrg## The order of this option in the case statement is important, since the 3605dd5f640Smrg## shell code in configure will try each of these formats in the order 3615dd5f640Smrg## listed in this file. A plain '-MD' option would be understood by many 3625dd5f640Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3635dd5f640Smrgpgcc) 3645dd5f640Smrg # Portland's C compiler understands '-MD'. 3655dd5f640Smrg # Will always output deps to 'file.d' where file is the root name of the 3665dd5f640Smrg # source file under compilation, even if file resides in a subdirectory. 3675dd5f640Smrg # The object file name does not affect the name of the '.d' file. 3685dd5f640Smrg # pgcc 10.2 will output 369e9554658Smrg # foo.o: sub/foo.c sub/foo.h 3705dd5f640Smrg # and will wrap long lines using '\' : 371e9554658Smrg # foo.o: sub/foo.c ... \ 372e9554658Smrg # sub/foo.h ... \ 373e9554658Smrg # ... 3745dd5f640Smrg set_dir_from "$object" 3755dd5f640Smrg # Use the source, not the object, to determine the base name, since 3765dd5f640Smrg # that's sadly what pgcc will do too. 3775dd5f640Smrg set_base_from "$source" 3785dd5f640Smrg tmpdepfile=$base.d 3795dd5f640Smrg 3805dd5f640Smrg # For projects that build the same source file twice into different object 3815dd5f640Smrg # files, the pgcc approach of using the *source* file root name can cause 3825dd5f640Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3835dd5f640Smrg # the same $tmpdepfile. 3845dd5f640Smrg lockdir=$base.d-lock 3855dd5f640Smrg trap " 3865dd5f640Smrg echo '$0: caught signal, cleaning up...' >&2 3875dd5f640Smrg rmdir '$lockdir' 3885dd5f640Smrg exit 1 3895dd5f640Smrg " 1 2 13 15 3905dd5f640Smrg numtries=100 3915dd5f640Smrg i=$numtries 3925dd5f640Smrg while test $i -gt 0; do 3935dd5f640Smrg # mkdir is a portable test-and-set. 3945dd5f640Smrg if mkdir "$lockdir" 2>/dev/null; then 3955dd5f640Smrg # This process acquired the lock. 3965dd5f640Smrg "$@" -MD 3975dd5f640Smrg stat=$? 3985dd5f640Smrg # Release the lock. 3995dd5f640Smrg rmdir "$lockdir" 4005dd5f640Smrg break 4015dd5f640Smrg else 4025dd5f640Smrg # If the lock is being held by a different process, wait 4035dd5f640Smrg # until the winning process is done or we timeout. 4045dd5f640Smrg while test -d "$lockdir" && test $i -gt 0; do 4055dd5f640Smrg sleep 1 4065dd5f640Smrg i=`expr $i - 1` 4075dd5f640Smrg done 4085dd5f640Smrg fi 4095dd5f640Smrg i=`expr $i - 1` 4105dd5f640Smrg done 4115dd5f640Smrg trap - 1 2 13 15 4125dd5f640Smrg if test $i -le 0; then 4135dd5f640Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4145dd5f640Smrg echo "$0: check lockdir '$lockdir'" >&2 4155dd5f640Smrg exit 1 4165dd5f640Smrg fi 417e9554658Smrg 4185dd5f640Smrg if test $stat -ne 0; then 419e9554658Smrg rm -f "$tmpdepfile" 420e9554658Smrg exit $stat 421e9554658Smrg fi 422e9554658Smrg rm -f "$depfile" 423e9554658Smrg # Each line is of the form `foo.o: dependent.h', 424e9554658Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425e9554658Smrg # Do two passes, one to just change these to 426e9554658Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427e9554658Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428e9554658Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429e9554658Smrg # correctly. Breaking it into two sed invocations is a workaround. 4305dd5f640Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4315dd5f640Smrg | sed -e 's/$/ :/' >> "$depfile" 432e9554658Smrg rm -f "$tmpdepfile" 433e9554658Smrg ;; 434e9554658Smrg 435e9554658Smrghp2) 436e9554658Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437e9554658Smrg # compilers, which have integrated preprocessors. The correct option 438e9554658Smrg # to use with these is +Maked; it writes dependencies to a file named 439e9554658Smrg # 'foo.d', which lands next to the object file, wherever that 440e9554658Smrg # happens to be. 441e9554658Smrg # Much of this is similar to the tru64 case; see comments there. 4425dd5f640Smrg set_dir_from "$object" 4435dd5f640Smrg set_base_from "$object" 444e9554658Smrg if test "$libtool" = yes; then 445e9554658Smrg tmpdepfile1=$dir$base.d 446e9554658Smrg tmpdepfile2=$dir.libs/$base.d 447e9554658Smrg "$@" -Wc,+Maked 448e9554658Smrg else 449e9554658Smrg tmpdepfile1=$dir$base.d 450e9554658Smrg tmpdepfile2=$dir$base.d 451e9554658Smrg "$@" +Maked 452e9554658Smrg fi 453e9554658Smrg stat=$? 4545dd5f640Smrg if test $stat -ne 0; then 455e9554658Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456e9554658Smrg exit $stat 457e9554658Smrg fi 458e9554658Smrg 459e9554658Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460e9554658Smrg do 461e9554658Smrg test -f "$tmpdepfile" && break 462e9554658Smrg done 463e9554658Smrg if test -f "$tmpdepfile"; then 4645dd5f640Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4655dd5f640Smrg # Add 'dependent.h:' lines. 466c2b339b4Smrg sed -ne '2,${ 4675dd5f640Smrg s/^ *// 4685dd5f640Smrg s/ \\*$// 4695dd5f640Smrg s/$/:/ 4705dd5f640Smrg p 4715dd5f640Smrg }' "$tmpdepfile" >> "$depfile" 472e9554658Smrg else 4735dd5f640Smrg make_dummy_depfile 474e9554658Smrg fi 475e9554658Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 476e9554658Smrg ;; 477e9554658Smrg 478e9554658Smrgtru64) 4795dd5f640Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4805dd5f640Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4815dd5f640Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4825dd5f640Smrg # dependencies in 'foo.d' instead, so we check for that too. 4835dd5f640Smrg # Subdirectories are respected. 4845dd5f640Smrg set_dir_from "$object" 4855dd5f640Smrg set_base_from "$object" 4865dd5f640Smrg 4875dd5f640Smrg if test "$libtool" = yes; then 4885dd5f640Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4895dd5f640Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4905dd5f640Smrg # in $dir$base.o.d. We have to check for both files, because 4915dd5f640Smrg # one of the two compilations can be disabled. We should prefer 4925dd5f640Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4935dd5f640Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4945dd5f640Smrg # the former would cause a distcleancheck panic. 4955dd5f640Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4965dd5f640Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4975dd5f640Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4985dd5f640Smrg "$@" -Wc,-MD 4995dd5f640Smrg else 5005dd5f640Smrg tmpdepfile1=$dir$base.d 5015dd5f640Smrg tmpdepfile2=$dir$base.d 5025dd5f640Smrg tmpdepfile3=$dir$base.d 5035dd5f640Smrg "$@" -MD 5045dd5f640Smrg fi 5055dd5f640Smrg 5065dd5f640Smrg stat=$? 5075dd5f640Smrg if test $stat -ne 0; then 5085dd5f640Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5095dd5f640Smrg exit $stat 5105dd5f640Smrg fi 5115dd5f640Smrg 5125dd5f640Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5135dd5f640Smrg do 5145dd5f640Smrg test -f "$tmpdepfile" && break 5155dd5f640Smrg done 5165dd5f640Smrg # Same post-processing that is required for AIX mode. 5175dd5f640Smrg aix_post_process_depfile 5185dd5f640Smrg ;; 5195dd5f640Smrg 5205dd5f640Smrgmsvc7) 5215dd5f640Smrg if test "$libtool" = yes; then 5225dd5f640Smrg showIncludes=-Wc,-showIncludes 5235dd5f640Smrg else 5245dd5f640Smrg showIncludes=-showIncludes 5255dd5f640Smrg fi 5265dd5f640Smrg "$@" $showIncludes > "$tmpdepfile" 5275dd5f640Smrg stat=$? 5285dd5f640Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5295dd5f640Smrg if test $stat -ne 0; then 5305dd5f640Smrg rm -f "$tmpdepfile" 5315dd5f640Smrg exit $stat 5325dd5f640Smrg fi 5335dd5f640Smrg rm -f "$depfile" 5345dd5f640Smrg echo "$object : \\" > "$depfile" 5355dd5f640Smrg # The first sed program below extracts the file names and escapes 5365dd5f640Smrg # backslashes for cygpath. The second sed program outputs the file 5375dd5f640Smrg # name when reading, but also accumulates all include files in the 5385dd5f640Smrg # hold buffer in order to output them again at the end. This only 5395dd5f640Smrg # works with sed implementations that can handle large buffers. 5405dd5f640Smrg sed < "$tmpdepfile" -n ' 5415dd5f640Smrg/^Note: including file: *\(.*\)/ { 5425dd5f640Smrg s//\1/ 5435dd5f640Smrg s/\\/\\\\/g 5445dd5f640Smrg p 5455dd5f640Smrg}' | $cygpath_u | sort -u | sed -n ' 5465dd5f640Smrgs/ /\\ /g 5475dd5f640Smrgs/\(.*\)/'"$tab"'\1 \\/p 5485dd5f640Smrgs/.\(.*\) \\/\1:/ 5495dd5f640SmrgH 5505dd5f640Smrg$ { 5515dd5f640Smrg s/.*/'"$tab"'/ 5525dd5f640Smrg G 5535dd5f640Smrg p 5545dd5f640Smrg}' >> "$depfile" 5555dd5f640Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5565dd5f640Smrg rm -f "$tmpdepfile" 5575dd5f640Smrg ;; 5585dd5f640Smrg 5595dd5f640Smrgmsvc7msys) 5605dd5f640Smrg # This case exists only to let depend.m4 do its work. It works by 5615dd5f640Smrg # looking at the text of this script. This case will never be run, 5625dd5f640Smrg # since it is checked for above. 5635dd5f640Smrg exit 1 5645dd5f640Smrg ;; 565e9554658Smrg 566e9554658Smrg#nosideeffect) 567e9554658Smrg # This comment above is used by automake to tell side-effect 568e9554658Smrg # dependency tracking mechanisms from slower ones. 569e9554658Smrg 570e9554658Smrgdashmstdout) 571e9554658Smrg # Important note: in order to support this mode, a compiler *must* 572e9554658Smrg # always write the preprocessed file to stdout, regardless of -o. 573e9554658Smrg "$@" || exit $? 574e9554658Smrg 575e9554658Smrg # Remove the call to Libtool. 576e9554658Smrg if test "$libtool" = yes; then 577c2b339b4Smrg while test "X$1" != 'X--mode=compile'; do 578e9554658Smrg shift 579e9554658Smrg done 580e9554658Smrg shift 581e9554658Smrg fi 582e9554658Smrg 5835dd5f640Smrg # Remove '-o $object'. 584e9554658Smrg IFS=" " 585e9554658Smrg for arg 586e9554658Smrg do 587e9554658Smrg case $arg in 588e9554658Smrg -o) 589e9554658Smrg shift 590e9554658Smrg ;; 591e9554658Smrg $object) 592e9554658Smrg shift 593e9554658Smrg ;; 594e9554658Smrg *) 595e9554658Smrg set fnord "$@" "$arg" 596e9554658Smrg shift # fnord 597e9554658Smrg shift # $arg 598e9554658Smrg ;; 599e9554658Smrg esac 600e9554658Smrg done 601e9554658Smrg 602e9554658Smrg test -z "$dashmflag" && dashmflag=-M 6035dd5f640Smrg # Require at least two characters before searching for ':' 604e9554658Smrg # in the target name. This is to cope with DOS-style filenames: 6055dd5f640Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606e9554658Smrg "$@" $dashmflag | 6075dd5f640Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608e9554658Smrg rm -f "$depfile" 609e9554658Smrg cat < "$tmpdepfile" > "$depfile" 6105dd5f640Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6115dd5f640Smrg # correctly. Breaking it into two sed invocations is a workaround. 6125dd5f640Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6135dd5f640Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6145dd5f640Smrg | sed -e 's/$/ :/' >> "$depfile" 615e9554658Smrg rm -f "$tmpdepfile" 616e9554658Smrg ;; 617e9554658Smrg 618e9554658SmrgdashXmstdout) 619e9554658Smrg # This case only exists to satisfy depend.m4. It is never actually 620e9554658Smrg # run, as this mode is specially recognized in the preamble. 621e9554658Smrg exit 1 622e9554658Smrg ;; 623e9554658Smrg 624e9554658Smrgmakedepend) 625e9554658Smrg "$@" || exit $? 626e9554658Smrg # Remove any Libtool call 627e9554658Smrg if test "$libtool" = yes; then 628c2b339b4Smrg while test "X$1" != 'X--mode=compile'; do 629e9554658Smrg shift 630e9554658Smrg done 631e9554658Smrg shift 632e9554658Smrg fi 633e9554658Smrg # X makedepend 634e9554658Smrg shift 635c2b339b4Smrg cleared=no eat=no 636c2b339b4Smrg for arg 637c2b339b4Smrg do 638e9554658Smrg case $cleared in 639e9554658Smrg no) 640e9554658Smrg set ""; shift 641e9554658Smrg cleared=yes ;; 642e9554658Smrg esac 643c2b339b4Smrg if test $eat = yes; then 644c2b339b4Smrg eat=no 645c2b339b4Smrg continue 646c2b339b4Smrg fi 647e9554658Smrg case "$arg" in 648e9554658Smrg -D*|-I*) 649e9554658Smrg set fnord "$@" "$arg"; shift ;; 650e9554658Smrg # Strip any option that makedepend may not understand. Remove 651e9554658Smrg # the object too, otherwise makedepend will parse it as a source file. 652c2b339b4Smrg -arch) 653c2b339b4Smrg eat=yes ;; 654e9554658Smrg -*|$object) 655e9554658Smrg ;; 656e9554658Smrg *) 657e9554658Smrg set fnord "$@" "$arg"; shift ;; 658e9554658Smrg esac 659e9554658Smrg done 660c2b339b4Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661e9554658Smrg touch "$tmpdepfile" 662e9554658Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663e9554658Smrg rm -f "$depfile" 6645dd5f640Smrg # makedepend may prepend the VPATH from the source file name to the object. 6655dd5f640Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 6665dd5f640Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6675dd5f640Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6685dd5f640Smrg # correctly. Breaking it into two sed invocations is a workaround. 6695dd5f640Smrg sed '1,2d' "$tmpdepfile" \ 6705dd5f640Smrg | tr ' ' "$nl" \ 6715dd5f640Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6725dd5f640Smrg | sed -e 's/$/ :/' >> "$depfile" 673e9554658Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674e9554658Smrg ;; 675e9554658Smrg 676e9554658Smrgcpp) 677e9554658Smrg # Important note: in order to support this mode, a compiler *must* 678e9554658Smrg # always write the preprocessed file to stdout. 679e9554658Smrg "$@" || exit $? 680e9554658Smrg 681e9554658Smrg # Remove the call to Libtool. 682e9554658Smrg if test "$libtool" = yes; then 683c2b339b4Smrg while test "X$1" != 'X--mode=compile'; do 684e9554658Smrg shift 685e9554658Smrg done 686e9554658Smrg shift 687e9554658Smrg fi 688e9554658Smrg 6895dd5f640Smrg # Remove '-o $object'. 690e9554658Smrg IFS=" " 691e9554658Smrg for arg 692e9554658Smrg do 693e9554658Smrg case $arg in 694e9554658Smrg -o) 695e9554658Smrg shift 696e9554658Smrg ;; 697e9554658Smrg $object) 698e9554658Smrg shift 699e9554658Smrg ;; 700e9554658Smrg *) 701e9554658Smrg set fnord "$@" "$arg" 702e9554658Smrg shift # fnord 703e9554658Smrg shift # $arg 704e9554658Smrg ;; 705e9554658Smrg esac 706e9554658Smrg done 707e9554658Smrg 7085dd5f640Smrg "$@" -E \ 7095dd5f640Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7105dd5f640Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7115dd5f640Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712e9554658Smrg rm -f "$depfile" 713e9554658Smrg echo "$object : \\" > "$depfile" 714e9554658Smrg cat < "$tmpdepfile" >> "$depfile" 715e9554658Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716e9554658Smrg rm -f "$tmpdepfile" 717e9554658Smrg ;; 718e9554658Smrg 719e9554658Smrgmsvisualcpp) 720e9554658Smrg # Important note: in order to support this mode, a compiler *must* 721c2b339b4Smrg # always write the preprocessed file to stdout. 722e9554658Smrg "$@" || exit $? 723c2b339b4Smrg 724c2b339b4Smrg # Remove the call to Libtool. 725c2b339b4Smrg if test "$libtool" = yes; then 726c2b339b4Smrg while test "X$1" != 'X--mode=compile'; do 727c2b339b4Smrg shift 728c2b339b4Smrg done 729c2b339b4Smrg shift 730c2b339b4Smrg fi 731c2b339b4Smrg 732e9554658Smrg IFS=" " 733e9554658Smrg for arg 734e9554658Smrg do 735e9554658Smrg case "$arg" in 736c2b339b4Smrg -o) 737c2b339b4Smrg shift 738c2b339b4Smrg ;; 739c2b339b4Smrg $object) 740c2b339b4Smrg shift 741c2b339b4Smrg ;; 742e9554658Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7435dd5f640Smrg set fnord "$@" 7445dd5f640Smrg shift 7455dd5f640Smrg shift 7465dd5f640Smrg ;; 747e9554658Smrg *) 7485dd5f640Smrg set fnord "$@" "$arg" 7495dd5f640Smrg shift 7505dd5f640Smrg shift 7515dd5f640Smrg ;; 752e9554658Smrg esac 753e9554658Smrg done 754c2b339b4Smrg "$@" -E 2>/dev/null | 755c2b339b4Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756e9554658Smrg rm -f "$depfile" 757e9554658Smrg echo "$object : \\" > "$depfile" 7585dd5f640Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7595dd5f640Smrg echo "$tab" >> "$depfile" 760c2b339b4Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761e9554658Smrg rm -f "$tmpdepfile" 762e9554658Smrg ;; 763e9554658Smrg 764c2b339b4Smrgmsvcmsys) 765c2b339b4Smrg # This case exists only to let depend.m4 do its work. It works by 766c2b339b4Smrg # looking at the text of this script. This case will never be run, 767c2b339b4Smrg # since it is checked for above. 768c2b339b4Smrg exit 1 769c2b339b4Smrg ;; 770c2b339b4Smrg 771e9554658Smrgnone) 772e9554658Smrg exec "$@" 773e9554658Smrg ;; 774e9554658Smrg 775e9554658Smrg*) 776e9554658Smrg echo "Unknown depmode $depmode" 1>&2 777e9554658Smrg exit 1 778e9554658Smrg ;; 779e9554658Smrgesac 780e9554658Smrg 781e9554658Smrgexit 0 782e9554658Smrg 783e9554658Smrg# Local Variables: 784e9554658Smrg# mode: shell-script 785e9554658Smrg# sh-indentation: 2 786e9554658Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 787e9554658Smrg# time-stamp-start: "scriptversion=" 788e9554658Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789c2b339b4Smrg# time-stamp-time-zone: "UTC" 790c2b339b4Smrg# time-stamp-end: "; # UTC" 791e9554658Smrg# End: 792