depcomp revision ec318dbf
1bccedf53Smrg#! /bin/sh 2bccedf53Smrg# depcomp - compile a program generating dependencies as side-effects 37c5f6000Smrg 4ec318dbfSmrgscriptversion=2018-03-07.03; # UTC 57c5f6000Smrg 6ec318dbfSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7bccedf53Smrg 8bccedf53Smrg# This program is free software; you can redistribute it and/or modify 9bccedf53Smrg# it under the terms of the GNU General Public License as published by 10bccedf53Smrg# the Free Software Foundation; either version 2, or (at your option) 11bccedf53Smrg# any later version. 12bccedf53Smrg 13bccedf53Smrg# This program is distributed in the hope that it will be useful, 14bccedf53Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15bccedf53Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16bccedf53Smrg# GNU General Public License for more details. 17bccedf53Smrg 18bccedf53Smrg# You should have received a copy of the GNU General Public License 19ec318dbfSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20bccedf53Smrg 21bccedf53Smrg# As a special exception to the GNU General Public License, if you 22bccedf53Smrg# distribute this file as part of a program that contains a 23bccedf53Smrg# configuration script generated by Autoconf, you may include it under 24bccedf53Smrg# the same distribution terms that you use for the rest of that program. 25bccedf53Smrg 26bccedf53Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27bccedf53Smrg 287c5f6000Smrgcase $1 in 297c5f6000Smrg '') 3089afc689Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3189afc689Smrg exit 1; 3289afc689Smrg ;; 337c5f6000Smrg -h | --h*) 347c5f6000Smrg cat <<\EOF 357c5f6000SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 367c5f6000Smrg 377c5f6000SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 387c5f6000Smrgas side-effects. 397c5f6000Smrg 407c5f6000SmrgEnvironment variables: 417c5f6000Smrg depmode Dependency tracking mode. 4289afc689Smrg source Source file read by 'PROGRAMS ARGS'. 4389afc689Smrg object Object file output by 'PROGRAMS ARGS'. 447c5f6000Smrg DEPDIR directory where to store dependencies. 457c5f6000Smrg depfile Dependency file to output. 461b1389eeSmrg tmpdepfile Temporary file to use when outputting dependencies. 477c5f6000Smrg libtool Whether libtool is used (yes/no). 487c5f6000Smrg 497c5f6000SmrgReport bugs to <bug-automake@gnu.org>. 507c5f6000SmrgEOF 517c5f6000Smrg exit $? 527c5f6000Smrg ;; 537c5f6000Smrg -v | --v*) 547c5f6000Smrg echo "depcomp $scriptversion" 557c5f6000Smrg exit $? 567c5f6000Smrg ;; 577c5f6000Smrgesac 587c5f6000Smrg 5989afc689Smrg# Get the directory component of the given path, and save it in the 6089afc689Smrg# global variables '$dir'. Note that this directory component will 6189afc689Smrg# be either empty or ending with a '/' character. This is deliberate. 6289afc689Smrgset_dir_from () 6389afc689Smrg{ 6489afc689Smrg case $1 in 6589afc689Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6689afc689Smrg *) dir=;; 6789afc689Smrg esac 6889afc689Smrg} 6989afc689Smrg 7089afc689Smrg# Get the suffix-stripped basename of the given path, and save it the 7189afc689Smrg# global variable '$base'. 7289afc689Smrgset_base_from () 7389afc689Smrg{ 7489afc689Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7589afc689Smrg} 7689afc689Smrg 7789afc689Smrg# If no dependency file was actually created by the compiler invocation, 7889afc689Smrg# we still have to create a dummy depfile, to avoid errors with the 7989afc689Smrg# Makefile "include basename.Plo" scheme. 8089afc689Smrgmake_dummy_depfile () 8189afc689Smrg{ 8289afc689Smrg echo "#dummy" > "$depfile" 8389afc689Smrg} 8489afc689Smrg 8589afc689Smrg# Factor out some common post-processing of the generated depfile. 8689afc689Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8789afc689Smrgaix_post_process_depfile () 8889afc689Smrg{ 8989afc689Smrg # If the compiler actually managed to produce a dependency file, 9089afc689Smrg # post-process it. 9189afc689Smrg if test -f "$tmpdepfile"; then 9289afc689Smrg # Each line is of the form 'foo.o: dependency.h'. 9389afc689Smrg # Do two passes, one to just change these to 9489afc689Smrg # $object: dependency.h 9589afc689Smrg # and one to simply output 9689afc689Smrg # dependency.h: 9789afc689Smrg # which is needed to avoid the deleted-header problem. 9889afc689Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 9989afc689Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10089afc689Smrg } > "$depfile" 10189afc689Smrg rm -f "$tmpdepfile" 10289afc689Smrg else 10389afc689Smrg make_dummy_depfile 10489afc689Smrg fi 10589afc689Smrg} 10689afc689Smrg 10789afc689Smrg# A tabulation character. 10889afc689Smrgtab=' ' 10989afc689Smrg# A newline character. 11089afc689Smrgnl=' 11189afc689Smrg' 11289afc689Smrg# Character ranges might be problematic outside the C locale. 11389afc689Smrg# These definitions help. 11489afc689Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11589afc689Smrglower=abcdefghijklmnopqrstuvwxyz 11689afc689Smrgdigits=0123456789 11789afc689Smrgalpha=${upper}${lower} 11889afc689Smrg 119bccedf53Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120bccedf53Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121bccedf53Smrg exit 1 122bccedf53Smrgfi 123bccedf53Smrg 1247c5f6000Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1257c5f6000Smrgdepfile=${depfile-`echo "$object" | 1267c5f6000Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127bccedf53Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128bccedf53Smrg 129bccedf53Smrgrm -f "$tmpdepfile" 130bccedf53Smrg 13189afc689Smrg# Avoid interferences from the environment. 13289afc689Smrggccflag= dashmflag= 13389afc689Smrg 134bccedf53Smrg# Some modes work just like other modes, but use different flags. We 135bccedf53Smrg# parameterize here, but still list the modes in the big case below, 136bccedf53Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137bccedf53Smrg# here, because this file can only contain one case statement. 138bccedf53Smrgif test "$depmode" = hp; then 139bccedf53Smrg # HP compiler uses -M and no extra arg. 140bccedf53Smrg gccflag=-M 141bccedf53Smrg depmode=gcc 142bccedf53Smrgfi 143bccedf53Smrg 144bccedf53Smrgif test "$depmode" = dashXmstdout; then 14589afc689Smrg # This is just like dashmstdout with a different argument. 14689afc689Smrg dashmflag=-xM 14789afc689Smrg depmode=dashmstdout 148bccedf53Smrgfi 149bccedf53Smrg 1507c5f6000Smrgcygpath_u="cygpath -u -f -" 1517c5f6000Smrgif test "$depmode" = msvcmsys; then 15289afc689Smrg # This is just like msvisualcpp but w/o cygpath translation. 15389afc689Smrg # Just convert the backslash-escaped backslashes to single forward 15489afc689Smrg # slashes to satisfy depend.m4 15589afc689Smrg cygpath_u='sed s,\\\\,/,g' 15689afc689Smrg depmode=msvisualcpp 1577c5f6000Smrgfi 1587c5f6000Smrg 1591b1389eeSmrgif test "$depmode" = msvc7msys; then 16089afc689Smrg # This is just like msvc7 but w/o cygpath translation. 16189afc689Smrg # Just convert the backslash-escaped backslashes to single forward 16289afc689Smrg # slashes to satisfy depend.m4 16389afc689Smrg cygpath_u='sed s,\\\\,/,g' 16489afc689Smrg depmode=msvc7 16589afc689Smrgfi 16689afc689Smrg 16789afc689Smrgif test "$depmode" = xlc; then 16889afc689Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 16989afc689Smrg gccflag=-qmakedep=gcc,-MF 17089afc689Smrg depmode=gcc 1711b1389eeSmrgfi 1721b1389eeSmrg 173bccedf53Smrgcase "$depmode" in 174bccedf53Smrggcc3) 175bccedf53Smrg## gcc 3 implements dependency tracking that does exactly what 176bccedf53Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177bccedf53Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1787c5f6000Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1797c5f6000Smrg## the command line argument order; so add the flags where they 1807c5f6000Smrg## appear in depend2.am. Note that the slowdown incurred here 1817c5f6000Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1827c5f6000Smrg for arg 1837c5f6000Smrg do 1847c5f6000Smrg case $arg in 1857c5f6000Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1867c5f6000Smrg *) set fnord "$@" "$arg" ;; 1877c5f6000Smrg esac 1887c5f6000Smrg shift # fnord 1897c5f6000Smrg shift # $arg 1907c5f6000Smrg done 1917c5f6000Smrg "$@" 192bccedf53Smrg stat=$? 19389afc689Smrg if test $stat -ne 0; then 194bccedf53Smrg rm -f "$tmpdepfile" 195bccedf53Smrg exit $stat 196bccedf53Smrg fi 197bccedf53Smrg mv "$tmpdepfile" "$depfile" 198bccedf53Smrg ;; 199bccedf53Smrg 200bccedf53Smrggcc) 20189afc689Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 20289afc689Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 20389afc689Smrg## (see the conditional assignment to $gccflag above). 204bccedf53Smrg## There are various ways to get dependency output from gcc. Here's 205bccedf53Smrg## why we pick this rather obscure method: 206bccedf53Smrg## - Don't want to use -MD because we'd like the dependencies to end 207bccedf53Smrg## up in a subdir. Having to rename by hand is ugly. 208bccedf53Smrg## (We might end up doing this anyway to support other compilers.) 209bccedf53Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21089afc689Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21189afc689Smrg## supported by the other compilers which use the 'gcc' depmode. 212bccedf53Smrg## - Using -M directly means running the compiler twice (even worse 213bccedf53Smrg## than renaming). 214bccedf53Smrg if test -z "$gccflag"; then 215bccedf53Smrg gccflag=-MD, 216bccedf53Smrg fi 217bccedf53Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218bccedf53Smrg stat=$? 21989afc689Smrg if test $stat -ne 0; then 220bccedf53Smrg rm -f "$tmpdepfile" 221bccedf53Smrg exit $stat 222bccedf53Smrg fi 223bccedf53Smrg rm -f "$depfile" 224bccedf53Smrg echo "$object : \\" > "$depfile" 22589afc689Smrg # The second -e expression handles DOS-style file names with drive 22689afc689Smrg # letters. 227bccedf53Smrg sed -e 's/^[^:]*: / /' \ 228bccedf53Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 22989afc689Smrg## This next piece of magic avoids the "deleted header file" problem. 230bccedf53Smrg## The problem is that when a header file which appears in a .P file 231bccedf53Smrg## is deleted, the dependency causes make to die (because there is 232bccedf53Smrg## typically no way to rebuild the header). We avoid this by adding 233bccedf53Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234bccedf53Smrg## this for us directly. 23589afc689Smrg## Some versions of gcc put a space before the ':'. On the theory 236bccedf53Smrg## that the space means something, we add a space to the output as 2371b1389eeSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 2381b1389eeSmrg## to the object. Take care to not repeat it in the output. 239bccedf53Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240bccedf53Smrg## correctly. Breaking it into two sed invocations is a workaround. 24189afc689Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24289afc689Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24389afc689Smrg | sed -e 's/$/ :/' >> "$depfile" 244bccedf53Smrg rm -f "$tmpdepfile" 245bccedf53Smrg ;; 246bccedf53Smrg 247bccedf53Smrghp) 248bccedf53Smrg # This case exists only to let depend.m4 do its work. It works by 249bccedf53Smrg # looking at the text of this script. This case will never be run, 250bccedf53Smrg # since it is checked for above. 251bccedf53Smrg exit 1 252bccedf53Smrg ;; 253bccedf53Smrg 254bccedf53Smrgsgi) 255bccedf53Smrg if test "$libtool" = yes; then 256bccedf53Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257bccedf53Smrg else 258bccedf53Smrg "$@" -MDupdate "$tmpdepfile" 259bccedf53Smrg fi 260bccedf53Smrg stat=$? 26189afc689Smrg if test $stat -ne 0; then 262bccedf53Smrg rm -f "$tmpdepfile" 263bccedf53Smrg exit $stat 264bccedf53Smrg fi 265bccedf53Smrg rm -f "$depfile" 266bccedf53Smrg 267bccedf53Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268bccedf53Smrg echo "$object : \\" > "$depfile" 269bccedf53Smrg # Clip off the initial element (the dependent). Don't try to be 270bccedf53Smrg # clever and replace this with sed code, as IRIX sed won't handle 271bccedf53Smrg # lines with more than a fixed number of characters (4096 in 272bccedf53Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27389afc689Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274bccedf53Smrg # dependency line. 27589afc689Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27689afc689Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27789afc689Smrg | tr "$nl" ' ' >> "$depfile" 2787c5f6000Smrg echo >> "$depfile" 279bccedf53Smrg # The second pass generates a dummy entry for each header file. 28089afc689Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28189afc689Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28289afc689Smrg >> "$depfile" 283bccedf53Smrg else 28489afc689Smrg make_dummy_depfile 285bccedf53Smrg fi 286bccedf53Smrg rm -f "$tmpdepfile" 287bccedf53Smrg ;; 288bccedf53Smrg 28989afc689Smrgxlc) 29089afc689Smrg # This case exists only to let depend.m4 do its work. It works by 29189afc689Smrg # looking at the text of this script. This case will never be run, 29289afc689Smrg # since it is checked for above. 29389afc689Smrg exit 1 29489afc689Smrg ;; 29589afc689Smrg 296bccedf53Smrgaix) 297bccedf53Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298bccedf53Smrg # in a .u file. In older versions, this file always lives in the 29989afc689Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300bccedf53Smrg # start of each line; $object doesn't have directory information. 301bccedf53Smrg # Version 6 uses the directory in both cases. 30289afc689Smrg set_dir_from "$object" 30389afc689Smrg set_base_from "$object" 304bccedf53Smrg if test "$libtool" = yes; then 3057c5f6000Smrg tmpdepfile1=$dir$base.u 3067c5f6000Smrg tmpdepfile2=$base.u 3077c5f6000Smrg tmpdepfile3=$dir.libs/$base.u 308bccedf53Smrg "$@" -Wc,-M 309bccedf53Smrg else 3107c5f6000Smrg tmpdepfile1=$dir$base.u 3117c5f6000Smrg tmpdepfile2=$dir$base.u 3127c5f6000Smrg tmpdepfile3=$dir$base.u 313bccedf53Smrg "$@" -M 314bccedf53Smrg fi 315bccedf53Smrg stat=$? 31689afc689Smrg if test $stat -ne 0; then 3177c5f6000Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318bccedf53Smrg exit $stat 319bccedf53Smrg fi 320bccedf53Smrg 3217c5f6000Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3227c5f6000Smrg do 3237c5f6000Smrg test -f "$tmpdepfile" && break 3247c5f6000Smrg done 32589afc689Smrg aix_post_process_depfile 32689afc689Smrg ;; 32789afc689Smrg 32889afc689Smrgtcc) 32989afc689Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33089afc689Smrg # FIXME: That version still under development at the moment of writing. 33189afc689Smrg # Make that this statement remains true also for stable, released 33289afc689Smrg # versions. 33389afc689Smrg # It will wrap lines (doesn't matter whether long or short) with a 33489afc689Smrg # trailing '\', as in: 33589afc689Smrg # 33689afc689Smrg # foo.o : \ 33789afc689Smrg # foo.c \ 33889afc689Smrg # foo.h \ 33989afc689Smrg # 34089afc689Smrg # It will put a trailing '\' even on the last line, and will use leading 34189afc689Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34289afc689Smrg # "Emit spaces for -MD"). 34389afc689Smrg "$@" -MD -MF "$tmpdepfile" 34489afc689Smrg stat=$? 34589afc689Smrg if test $stat -ne 0; then 34689afc689Smrg rm -f "$tmpdepfile" 34789afc689Smrg exit $stat 348bccedf53Smrg fi 34989afc689Smrg rm -f "$depfile" 35089afc689Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35189afc689Smrg # We have to change lines of the first kind to '$object: \'. 35289afc689Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35389afc689Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35489afc689Smrg # dummy dependency, to avoid the deleted-header problem. 35589afc689Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356bccedf53Smrg rm -f "$tmpdepfile" 357bccedf53Smrg ;; 358bccedf53Smrg 35989afc689Smrg## The order of this option in the case statement is important, since the 36089afc689Smrg## shell code in configure will try each of these formats in the order 36189afc689Smrg## listed in this file. A plain '-MD' option would be understood by many 36289afc689Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36389afc689Smrgpgcc) 36489afc689Smrg # Portland's C compiler understands '-MD'. 36589afc689Smrg # Will always output deps to 'file.d' where file is the root name of the 36689afc689Smrg # source file under compilation, even if file resides in a subdirectory. 36789afc689Smrg # The object file name does not affect the name of the '.d' file. 36889afc689Smrg # pgcc 10.2 will output 369bccedf53Smrg # foo.o: sub/foo.c sub/foo.h 37089afc689Smrg # and will wrap long lines using '\' : 371bccedf53Smrg # foo.o: sub/foo.c ... \ 372bccedf53Smrg # sub/foo.h ... \ 373bccedf53Smrg # ... 37489afc689Smrg set_dir_from "$object" 37589afc689Smrg # Use the source, not the object, to determine the base name, since 37689afc689Smrg # that's sadly what pgcc will do too. 37789afc689Smrg set_base_from "$source" 37889afc689Smrg tmpdepfile=$base.d 37989afc689Smrg 38089afc689Smrg # For projects that build the same source file twice into different object 38189afc689Smrg # files, the pgcc approach of using the *source* file root name can cause 38289afc689Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38389afc689Smrg # the same $tmpdepfile. 38489afc689Smrg lockdir=$base.d-lock 38589afc689Smrg trap " 38689afc689Smrg echo '$0: caught signal, cleaning up...' >&2 38789afc689Smrg rmdir '$lockdir' 38889afc689Smrg exit 1 38989afc689Smrg " 1 2 13 15 39089afc689Smrg numtries=100 39189afc689Smrg i=$numtries 39289afc689Smrg while test $i -gt 0; do 39389afc689Smrg # mkdir is a portable test-and-set. 39489afc689Smrg if mkdir "$lockdir" 2>/dev/null; then 39589afc689Smrg # This process acquired the lock. 39689afc689Smrg "$@" -MD 39789afc689Smrg stat=$? 39889afc689Smrg # Release the lock. 39989afc689Smrg rmdir "$lockdir" 40089afc689Smrg break 40189afc689Smrg else 40289afc689Smrg # If the lock is being held by a different process, wait 40389afc689Smrg # until the winning process is done or we timeout. 40489afc689Smrg while test -d "$lockdir" && test $i -gt 0; do 40589afc689Smrg sleep 1 40689afc689Smrg i=`expr $i - 1` 40789afc689Smrg done 40889afc689Smrg fi 40989afc689Smrg i=`expr $i - 1` 41089afc689Smrg done 41189afc689Smrg trap - 1 2 13 15 41289afc689Smrg if test $i -le 0; then 41389afc689Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41489afc689Smrg echo "$0: check lockdir '$lockdir'" >&2 41589afc689Smrg exit 1 41689afc689Smrg fi 417bccedf53Smrg 41889afc689Smrg if test $stat -ne 0; then 419bccedf53Smrg rm -f "$tmpdepfile" 420bccedf53Smrg exit $stat 421bccedf53Smrg fi 422bccedf53Smrg rm -f "$depfile" 423bccedf53Smrg # Each line is of the form `foo.o: dependent.h', 424bccedf53Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425bccedf53Smrg # Do two passes, one to just change these to 426bccedf53Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427bccedf53Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428bccedf53Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429bccedf53Smrg # correctly. Breaking it into two sed invocations is a workaround. 43089afc689Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43189afc689Smrg | sed -e 's/$/ :/' >> "$depfile" 432bccedf53Smrg rm -f "$tmpdepfile" 433bccedf53Smrg ;; 434bccedf53Smrg 4357c5f6000Smrghp2) 4367c5f6000Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4377c5f6000Smrg # compilers, which have integrated preprocessors. The correct option 4387c5f6000Smrg # to use with these is +Maked; it writes dependencies to a file named 4397c5f6000Smrg # 'foo.d', which lands next to the object file, wherever that 4407c5f6000Smrg # happens to be. 4417c5f6000Smrg # Much of this is similar to the tru64 case; see comments there. 44289afc689Smrg set_dir_from "$object" 44389afc689Smrg set_base_from "$object" 4447c5f6000Smrg if test "$libtool" = yes; then 4457c5f6000Smrg tmpdepfile1=$dir$base.d 4467c5f6000Smrg tmpdepfile2=$dir.libs/$base.d 4477c5f6000Smrg "$@" -Wc,+Maked 4487c5f6000Smrg else 4497c5f6000Smrg tmpdepfile1=$dir$base.d 4507c5f6000Smrg tmpdepfile2=$dir$base.d 4517c5f6000Smrg "$@" +Maked 4527c5f6000Smrg fi 4537c5f6000Smrg stat=$? 45489afc689Smrg if test $stat -ne 0; then 4557c5f6000Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4567c5f6000Smrg exit $stat 4577c5f6000Smrg fi 4587c5f6000Smrg 4597c5f6000Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4607c5f6000Smrg do 4617c5f6000Smrg test -f "$tmpdepfile" && break 4627c5f6000Smrg done 4637c5f6000Smrg if test -f "$tmpdepfile"; then 46489afc689Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46589afc689Smrg # Add 'dependent.h:' lines. 4667c5f6000Smrg sed -ne '2,${ 46789afc689Smrg s/^ *// 46889afc689Smrg s/ \\*$// 46989afc689Smrg s/$/:/ 47089afc689Smrg p 47189afc689Smrg }' "$tmpdepfile" >> "$depfile" 4727c5f6000Smrg else 47389afc689Smrg make_dummy_depfile 4747c5f6000Smrg fi 4757c5f6000Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4767c5f6000Smrg ;; 4777c5f6000Smrg 478bccedf53Smrgtru64) 47989afc689Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48089afc689Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48189afc689Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48289afc689Smrg # dependencies in 'foo.d' instead, so we check for that too. 48389afc689Smrg # Subdirectories are respected. 48489afc689Smrg set_dir_from "$object" 48589afc689Smrg set_base_from "$object" 48689afc689Smrg 48789afc689Smrg if test "$libtool" = yes; then 48889afc689Smrg # Libtool generates 2 separate objects for the 2 libraries. These 48989afc689Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49089afc689Smrg # in $dir$base.o.d. We have to check for both files, because 49189afc689Smrg # one of the two compilations can be disabled. We should prefer 49289afc689Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49389afc689Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49489afc689Smrg # the former would cause a distcleancheck panic. 49589afc689Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49689afc689Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49789afc689Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49889afc689Smrg "$@" -Wc,-MD 49989afc689Smrg else 50089afc689Smrg tmpdepfile1=$dir$base.d 50189afc689Smrg tmpdepfile2=$dir$base.d 50289afc689Smrg tmpdepfile3=$dir$base.d 50389afc689Smrg "$@" -MD 50489afc689Smrg fi 50589afc689Smrg 50689afc689Smrg stat=$? 50789afc689Smrg if test $stat -ne 0; then 50889afc689Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 50989afc689Smrg exit $stat 51089afc689Smrg fi 51189afc689Smrg 51289afc689Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51389afc689Smrg do 51489afc689Smrg test -f "$tmpdepfile" && break 51589afc689Smrg done 51689afc689Smrg # Same post-processing that is required for AIX mode. 51789afc689Smrg aix_post_process_depfile 51889afc689Smrg ;; 519bccedf53Smrg 5201b1389eeSmrgmsvc7) 5211b1389eeSmrg if test "$libtool" = yes; then 5221b1389eeSmrg showIncludes=-Wc,-showIncludes 5231b1389eeSmrg else 5241b1389eeSmrg showIncludes=-showIncludes 5251b1389eeSmrg fi 5261b1389eeSmrg "$@" $showIncludes > "$tmpdepfile" 5271b1389eeSmrg stat=$? 5281b1389eeSmrg grep -v '^Note: including file: ' "$tmpdepfile" 52989afc689Smrg if test $stat -ne 0; then 5301b1389eeSmrg rm -f "$tmpdepfile" 5311b1389eeSmrg exit $stat 5321b1389eeSmrg fi 5331b1389eeSmrg rm -f "$depfile" 5341b1389eeSmrg echo "$object : \\" > "$depfile" 5351b1389eeSmrg # The first sed program below extracts the file names and escapes 5361b1389eeSmrg # backslashes for cygpath. The second sed program outputs the file 5371b1389eeSmrg # name when reading, but also accumulates all include files in the 5381b1389eeSmrg # hold buffer in order to output them again at the end. This only 5391b1389eeSmrg # works with sed implementations that can handle large buffers. 5401b1389eeSmrg sed < "$tmpdepfile" -n ' 5411b1389eeSmrg/^Note: including file: *\(.*\)/ { 5421b1389eeSmrg s//\1/ 5431b1389eeSmrg s/\\/\\\\/g 5441b1389eeSmrg p 5451b1389eeSmrg}' | $cygpath_u | sort -u | sed -n ' 5461b1389eeSmrgs/ /\\ /g 54789afc689Smrgs/\(.*\)/'"$tab"'\1 \\/p 5481b1389eeSmrgs/.\(.*\) \\/\1:/ 5491b1389eeSmrgH 5501b1389eeSmrg$ { 55189afc689Smrg s/.*/'"$tab"'/ 5521b1389eeSmrg G 5531b1389eeSmrg p 5541b1389eeSmrg}' >> "$depfile" 55589afc689Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5561b1389eeSmrg rm -f "$tmpdepfile" 5571b1389eeSmrg ;; 5581b1389eeSmrg 5591b1389eeSmrgmsvc7msys) 5601b1389eeSmrg # This case exists only to let depend.m4 do its work. It works by 5611b1389eeSmrg # looking at the text of this script. This case will never be run, 5621b1389eeSmrg # since it is checked for above. 5631b1389eeSmrg exit 1 5641b1389eeSmrg ;; 5651b1389eeSmrg 566bccedf53Smrg#nosideeffect) 567bccedf53Smrg # This comment above is used by automake to tell side-effect 568bccedf53Smrg # dependency tracking mechanisms from slower ones. 569bccedf53Smrg 570bccedf53Smrgdashmstdout) 571bccedf53Smrg # Important note: in order to support this mode, a compiler *must* 572bccedf53Smrg # always write the preprocessed file to stdout, regardless of -o. 573bccedf53Smrg "$@" || exit $? 574bccedf53Smrg 575bccedf53Smrg # Remove the call to Libtool. 576bccedf53Smrg if test "$libtool" = yes; then 5777c5f6000Smrg while test "X$1" != 'X--mode=compile'; do 578bccedf53Smrg shift 579bccedf53Smrg done 580bccedf53Smrg shift 581bccedf53Smrg fi 582bccedf53Smrg 58389afc689Smrg # Remove '-o $object'. 584bccedf53Smrg IFS=" " 585bccedf53Smrg for arg 586bccedf53Smrg do 587bccedf53Smrg case $arg in 588bccedf53Smrg -o) 589bccedf53Smrg shift 590bccedf53Smrg ;; 591bccedf53Smrg $object) 592bccedf53Smrg shift 593bccedf53Smrg ;; 594bccedf53Smrg *) 595bccedf53Smrg set fnord "$@" "$arg" 596bccedf53Smrg shift # fnord 597bccedf53Smrg shift # $arg 598bccedf53Smrg ;; 599bccedf53Smrg esac 600bccedf53Smrg done 601bccedf53Smrg 602bccedf53Smrg test -z "$dashmflag" && dashmflag=-M 60389afc689Smrg # Require at least two characters before searching for ':' 604bccedf53Smrg # in the target name. This is to cope with DOS-style filenames: 60589afc689Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606bccedf53Smrg "$@" $dashmflag | 60789afc689Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608bccedf53Smrg rm -f "$depfile" 609bccedf53Smrg cat < "$tmpdepfile" > "$depfile" 61089afc689Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61189afc689Smrg # correctly. Breaking it into two sed invocations is a workaround. 61289afc689Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61389afc689Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61489afc689Smrg | sed -e 's/$/ :/' >> "$depfile" 615bccedf53Smrg rm -f "$tmpdepfile" 616bccedf53Smrg ;; 617bccedf53Smrg 618bccedf53SmrgdashXmstdout) 619bccedf53Smrg # This case only exists to satisfy depend.m4. It is never actually 620bccedf53Smrg # run, as this mode is specially recognized in the preamble. 621bccedf53Smrg exit 1 622bccedf53Smrg ;; 623bccedf53Smrg 624bccedf53Smrgmakedepend) 625bccedf53Smrg "$@" || exit $? 626bccedf53Smrg # Remove any Libtool call 627bccedf53Smrg if test "$libtool" = yes; then 6287c5f6000Smrg while test "X$1" != 'X--mode=compile'; do 629bccedf53Smrg shift 630bccedf53Smrg done 631bccedf53Smrg shift 632bccedf53Smrg fi 633bccedf53Smrg # X makedepend 634bccedf53Smrg shift 6357c5f6000Smrg cleared=no eat=no 6367c5f6000Smrg for arg 6377c5f6000Smrg do 638bccedf53Smrg case $cleared in 639bccedf53Smrg no) 640bccedf53Smrg set ""; shift 641bccedf53Smrg cleared=yes ;; 642bccedf53Smrg esac 6437c5f6000Smrg if test $eat = yes; then 6447c5f6000Smrg eat=no 6457c5f6000Smrg continue 6467c5f6000Smrg fi 647bccedf53Smrg case "$arg" in 648bccedf53Smrg -D*|-I*) 649bccedf53Smrg set fnord "$@" "$arg"; shift ;; 650bccedf53Smrg # Strip any option that makedepend may not understand. Remove 651bccedf53Smrg # the object too, otherwise makedepend will parse it as a source file. 6527c5f6000Smrg -arch) 6537c5f6000Smrg eat=yes ;; 654bccedf53Smrg -*|$object) 655bccedf53Smrg ;; 656bccedf53Smrg *) 657bccedf53Smrg set fnord "$@" "$arg"; shift ;; 658bccedf53Smrg esac 659bccedf53Smrg done 6607c5f6000Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661bccedf53Smrg touch "$tmpdepfile" 662bccedf53Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663bccedf53Smrg rm -f "$depfile" 6641b1389eeSmrg # makedepend may prepend the VPATH from the source file name to the object. 6651b1389eeSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 6661b1389eeSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66789afc689Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66889afc689Smrg # correctly. Breaking it into two sed invocations is a workaround. 66989afc689Smrg sed '1,2d' "$tmpdepfile" \ 67089afc689Smrg | tr ' ' "$nl" \ 67189afc689Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67289afc689Smrg | sed -e 's/$/ :/' >> "$depfile" 673bccedf53Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674bccedf53Smrg ;; 675bccedf53Smrg 676bccedf53Smrgcpp) 677bccedf53Smrg # Important note: in order to support this mode, a compiler *must* 678bccedf53Smrg # always write the preprocessed file to stdout. 679bccedf53Smrg "$@" || exit $? 680bccedf53Smrg 681bccedf53Smrg # Remove the call to Libtool. 682bccedf53Smrg if test "$libtool" = yes; then 6837c5f6000Smrg while test "X$1" != 'X--mode=compile'; do 684bccedf53Smrg shift 685bccedf53Smrg done 686bccedf53Smrg shift 687bccedf53Smrg fi 688bccedf53Smrg 68989afc689Smrg # Remove '-o $object'. 690bccedf53Smrg IFS=" " 691bccedf53Smrg for arg 692bccedf53Smrg do 693bccedf53Smrg case $arg in 694bccedf53Smrg -o) 695bccedf53Smrg shift 696bccedf53Smrg ;; 697bccedf53Smrg $object) 698bccedf53Smrg shift 699bccedf53Smrg ;; 700bccedf53Smrg *) 701bccedf53Smrg set fnord "$@" "$arg" 702bccedf53Smrg shift # fnord 703bccedf53Smrg shift # $arg 704bccedf53Smrg ;; 705bccedf53Smrg esac 706bccedf53Smrg done 707bccedf53Smrg 70889afc689Smrg "$@" -E \ 70989afc689Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71089afc689Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71189afc689Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712bccedf53Smrg rm -f "$depfile" 713bccedf53Smrg echo "$object : \\" > "$depfile" 714bccedf53Smrg cat < "$tmpdepfile" >> "$depfile" 715bccedf53Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716bccedf53Smrg rm -f "$tmpdepfile" 717bccedf53Smrg ;; 718bccedf53Smrg 719bccedf53Smrgmsvisualcpp) 720bccedf53Smrg # Important note: in order to support this mode, a compiler *must* 7217c5f6000Smrg # always write the preprocessed file to stdout. 722bccedf53Smrg "$@" || exit $? 7237c5f6000Smrg 7247c5f6000Smrg # Remove the call to Libtool. 7257c5f6000Smrg if test "$libtool" = yes; then 7267c5f6000Smrg while test "X$1" != 'X--mode=compile'; do 7277c5f6000Smrg shift 7287c5f6000Smrg done 7297c5f6000Smrg shift 7307c5f6000Smrg fi 7317c5f6000Smrg 732bccedf53Smrg IFS=" " 733bccedf53Smrg for arg 734bccedf53Smrg do 735bccedf53Smrg case "$arg" in 7367c5f6000Smrg -o) 7377c5f6000Smrg shift 7387c5f6000Smrg ;; 7397c5f6000Smrg $object) 7407c5f6000Smrg shift 7417c5f6000Smrg ;; 742bccedf53Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74389afc689Smrg set fnord "$@" 74489afc689Smrg shift 74589afc689Smrg shift 74689afc689Smrg ;; 747bccedf53Smrg *) 74889afc689Smrg set fnord "$@" "$arg" 74989afc689Smrg shift 75089afc689Smrg shift 75189afc689Smrg ;; 752bccedf53Smrg esac 753bccedf53Smrg done 7547c5f6000Smrg "$@" -E 2>/dev/null | 7557c5f6000Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756bccedf53Smrg rm -f "$depfile" 757bccedf53Smrg echo "$object : \\" > "$depfile" 75889afc689Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 75989afc689Smrg echo "$tab" >> "$depfile" 7607c5f6000Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761bccedf53Smrg rm -f "$tmpdepfile" 762bccedf53Smrg ;; 763bccedf53Smrg 7647c5f6000Smrgmsvcmsys) 7657c5f6000Smrg # This case exists only to let depend.m4 do its work. It works by 7667c5f6000Smrg # looking at the text of this script. This case will never be run, 7677c5f6000Smrg # since it is checked for above. 7687c5f6000Smrg exit 1 7697c5f6000Smrg ;; 7707c5f6000Smrg 771bccedf53Smrgnone) 772bccedf53Smrg exec "$@" 773bccedf53Smrg ;; 774bccedf53Smrg 775bccedf53Smrg*) 776bccedf53Smrg echo "Unknown depmode $depmode" 1>&2 777bccedf53Smrg exit 1 778bccedf53Smrg ;; 779bccedf53Smrgesac 780bccedf53Smrg 781bccedf53Smrgexit 0 7827c5f6000Smrg 7837c5f6000Smrg# Local Variables: 7847c5f6000Smrg# mode: shell-script 7857c5f6000Smrg# sh-indentation: 2 786ec318dbfSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7877c5f6000Smrg# time-stamp-start: "scriptversion=" 7887c5f6000Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789ec318dbfSmrg# time-stamp-time-zone: "UTC0" 7907c5f6000Smrg# time-stamp-end: "; # UTC" 7917c5f6000Smrg# End: 792