depcomp revision fa2b3b63
129459361Smrg#! /bin/sh 229459361Smrg# depcomp - compile a program generating dependencies as side-effects 329459361Smrg 4fa2b3b63Smrgscriptversion=2016-01-11.22; # UTC 529459361Smrg 6fa2b3b63Smrg# Copyright (C) 1999-2017 Free Software Foundation, Inc. 729459361Smrg 829459361Smrg# This program is free software; you can redistribute it and/or modify 929459361Smrg# it under the terms of the GNU General Public License as published by 1029459361Smrg# the Free Software Foundation; either version 2, or (at your option) 1129459361Smrg# any later version. 1229459361Smrg 1329459361Smrg# This program is distributed in the hope that it will be useful, 1429459361Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1529459361Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1629459361Smrg# GNU General Public License for more details. 1729459361Smrg 1829459361Smrg# You should have received a copy of the GNU General Public License 1947202d7bSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 2029459361Smrg 2129459361Smrg# As a special exception to the GNU General Public License, if you 2229459361Smrg# distribute this file as part of a program that contains a 2329459361Smrg# configuration script generated by Autoconf, you may include it under 2429459361Smrg# the same distribution terms that you use for the rest of that program. 2529459361Smrg 2629459361Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2729459361Smrg 2829459361Smrgcase $1 in 2929459361Smrg '') 30fb4ebca8Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31fb4ebca8Smrg exit 1; 32fb4ebca8Smrg ;; 3329459361Smrg -h | --h*) 3429459361Smrg cat <<\EOF 3529459361SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3629459361Smrg 3729459361SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3829459361Smrgas side-effects. 3929459361Smrg 4029459361SmrgEnvironment variables: 4129459361Smrg depmode Dependency tracking mode. 42fb4ebca8Smrg source Source file read by 'PROGRAMS ARGS'. 43fb4ebca8Smrg object Object file output by 'PROGRAMS ARGS'. 4429459361Smrg DEPDIR directory where to store dependencies. 4529459361Smrg depfile Dependency file to output. 465dd2154eSmrg tmpdepfile Temporary file to use when outputting dependencies. 4729459361Smrg libtool Whether libtool is used (yes/no). 4829459361Smrg 4929459361SmrgReport bugs to <bug-automake@gnu.org>. 5029459361SmrgEOF 5129459361Smrg exit $? 5229459361Smrg ;; 5329459361Smrg -v | --v*) 5429459361Smrg echo "depcomp $scriptversion" 5529459361Smrg exit $? 5629459361Smrg ;; 5729459361Smrgesac 5829459361Smrg 59fb4ebca8Smrg# Get the directory component of the given path, and save it in the 60fb4ebca8Smrg# global variables '$dir'. Note that this directory component will 61fb4ebca8Smrg# be either empty or ending with a '/' character. This is deliberate. 62fb4ebca8Smrgset_dir_from () 63fb4ebca8Smrg{ 64fb4ebca8Smrg case $1 in 65fb4ebca8Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66fb4ebca8Smrg *) dir=;; 67fb4ebca8Smrg esac 68fb4ebca8Smrg} 69fb4ebca8Smrg 70fb4ebca8Smrg# Get the suffix-stripped basename of the given path, and save it the 71fb4ebca8Smrg# global variable '$base'. 72fb4ebca8Smrgset_base_from () 73fb4ebca8Smrg{ 74fb4ebca8Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75fb4ebca8Smrg} 76fb4ebca8Smrg 77fb4ebca8Smrg# If no dependency file was actually created by the compiler invocation, 78fb4ebca8Smrg# we still have to create a dummy depfile, to avoid errors with the 79fb4ebca8Smrg# Makefile "include basename.Plo" scheme. 80fb4ebca8Smrgmake_dummy_depfile () 81fb4ebca8Smrg{ 82fb4ebca8Smrg echo "#dummy" > "$depfile" 83fb4ebca8Smrg} 84fb4ebca8Smrg 85fb4ebca8Smrg# Factor out some common post-processing of the generated depfile. 86fb4ebca8Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87fb4ebca8Smrgaix_post_process_depfile () 88fb4ebca8Smrg{ 89fb4ebca8Smrg # If the compiler actually managed to produce a dependency file, 90fb4ebca8Smrg # post-process it. 91fb4ebca8Smrg if test -f "$tmpdepfile"; then 92fb4ebca8Smrg # Each line is of the form 'foo.o: dependency.h'. 93fb4ebca8Smrg # Do two passes, one to just change these to 94fb4ebca8Smrg # $object: dependency.h 95fb4ebca8Smrg # and one to simply output 96fb4ebca8Smrg # dependency.h: 97fb4ebca8Smrg # which is needed to avoid the deleted-header problem. 98fb4ebca8Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99fb4ebca8Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100fb4ebca8Smrg } > "$depfile" 101fb4ebca8Smrg rm -f "$tmpdepfile" 102fb4ebca8Smrg else 103fb4ebca8Smrg make_dummy_depfile 104fb4ebca8Smrg fi 105fb4ebca8Smrg} 106fb4ebca8Smrg 107fb4ebca8Smrg# A tabulation character. 108fb4ebca8Smrgtab=' ' 109fb4ebca8Smrg# A newline character. 110fb4ebca8Smrgnl=' 111fb4ebca8Smrg' 112fb4ebca8Smrg# Character ranges might be problematic outside the C locale. 113fb4ebca8Smrg# These definitions help. 114fb4ebca8Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115fb4ebca8Smrglower=abcdefghijklmnopqrstuvwxyz 116fb4ebca8Smrgdigits=0123456789 117fb4ebca8Smrgalpha=${upper}${lower} 118fb4ebca8Smrg 11929459361Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12029459361Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12129459361Smrg exit 1 12229459361Smrgfi 12329459361Smrg 12429459361Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12529459361Smrgdepfile=${depfile-`echo "$object" | 12629459361Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12729459361Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12829459361Smrg 12929459361Smrgrm -f "$tmpdepfile" 13029459361Smrg 131fb4ebca8Smrg# Avoid interferences from the environment. 132fb4ebca8Smrggccflag= dashmflag= 133fb4ebca8Smrg 13429459361Smrg# Some modes work just like other modes, but use different flags. We 13529459361Smrg# parameterize here, but still list the modes in the big case below, 13629459361Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13729459361Smrg# here, because this file can only contain one case statement. 13829459361Smrgif test "$depmode" = hp; then 13929459361Smrg # HP compiler uses -M and no extra arg. 14029459361Smrg gccflag=-M 14129459361Smrg depmode=gcc 14229459361Smrgfi 14329459361Smrg 14429459361Smrgif test "$depmode" = dashXmstdout; then 145fb4ebca8Smrg # This is just like dashmstdout with a different argument. 146fb4ebca8Smrg dashmflag=-xM 147fb4ebca8Smrg depmode=dashmstdout 14829459361Smrgfi 14929459361Smrg 15047202d7bSmrgcygpath_u="cygpath -u -f -" 15147202d7bSmrgif test "$depmode" = msvcmsys; then 152fb4ebca8Smrg # This is just like msvisualcpp but w/o cygpath translation. 153fb4ebca8Smrg # Just convert the backslash-escaped backslashes to single forward 154fb4ebca8Smrg # slashes to satisfy depend.m4 155fb4ebca8Smrg cygpath_u='sed s,\\\\,/,g' 156fb4ebca8Smrg depmode=msvisualcpp 15747202d7bSmrgfi 15847202d7bSmrg 1595dd2154eSmrgif test "$depmode" = msvc7msys; then 160fb4ebca8Smrg # This is just like msvc7 but w/o cygpath translation. 161fb4ebca8Smrg # Just convert the backslash-escaped backslashes to single forward 162fb4ebca8Smrg # slashes to satisfy depend.m4 163fb4ebca8Smrg cygpath_u='sed s,\\\\,/,g' 164fb4ebca8Smrg depmode=msvc7 165fb4ebca8Smrgfi 166fb4ebca8Smrg 167fb4ebca8Smrgif test "$depmode" = xlc; then 168fb4ebca8Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169fb4ebca8Smrg gccflag=-qmakedep=gcc,-MF 170fb4ebca8Smrg depmode=gcc 1715dd2154eSmrgfi 1725dd2154eSmrg 17329459361Smrgcase "$depmode" in 17429459361Smrggcc3) 17529459361Smrg## gcc 3 implements dependency tracking that does exactly what 17629459361Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17729459361Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 17847202d7bSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 17947202d7bSmrg## the command line argument order; so add the flags where they 18047202d7bSmrg## appear in depend2.am. Note that the slowdown incurred here 18147202d7bSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 18247202d7bSmrg for arg 18347202d7bSmrg do 18447202d7bSmrg case $arg in 18547202d7bSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 18647202d7bSmrg *) set fnord "$@" "$arg" ;; 18747202d7bSmrg esac 18847202d7bSmrg shift # fnord 18947202d7bSmrg shift # $arg 19047202d7bSmrg done 19147202d7bSmrg "$@" 19229459361Smrg stat=$? 193fb4ebca8Smrg if test $stat -ne 0; then 19429459361Smrg rm -f "$tmpdepfile" 19529459361Smrg exit $stat 19629459361Smrg fi 19729459361Smrg mv "$tmpdepfile" "$depfile" 19829459361Smrg ;; 19929459361Smrg 20029459361Smrggcc) 201fb4ebca8Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202fb4ebca8Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203fb4ebca8Smrg## (see the conditional assignment to $gccflag above). 20429459361Smrg## There are various ways to get dependency output from gcc. Here's 20529459361Smrg## why we pick this rather obscure method: 20629459361Smrg## - Don't want to use -MD because we'd like the dependencies to end 20729459361Smrg## up in a subdir. Having to rename by hand is ugly. 20829459361Smrg## (We might end up doing this anyway to support other compilers.) 20929459361Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210fb4ebca8Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211fb4ebca8Smrg## supported by the other compilers which use the 'gcc' depmode. 21229459361Smrg## - Using -M directly means running the compiler twice (even worse 21329459361Smrg## than renaming). 21429459361Smrg if test -z "$gccflag"; then 21529459361Smrg gccflag=-MD, 21629459361Smrg fi 21729459361Smrg "$@" -Wp,"$gccflag$tmpdepfile" 21829459361Smrg stat=$? 219fb4ebca8Smrg if test $stat -ne 0; then 22029459361Smrg rm -f "$tmpdepfile" 22129459361Smrg exit $stat 22229459361Smrg fi 22329459361Smrg rm -f "$depfile" 22429459361Smrg echo "$object : \\" > "$depfile" 225fb4ebca8Smrg # The second -e expression handles DOS-style file names with drive 226fb4ebca8Smrg # letters. 22729459361Smrg sed -e 's/^[^:]*: / /' \ 22829459361Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229fb4ebca8Smrg## This next piece of magic avoids the "deleted header file" problem. 23029459361Smrg## The problem is that when a header file which appears in a .P file 23129459361Smrg## is deleted, the dependency causes make to die (because there is 23229459361Smrg## typically no way to rebuild the header). We avoid this by adding 23329459361Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 23429459361Smrg## this for us directly. 235fb4ebca8Smrg## Some versions of gcc put a space before the ':'. On the theory 23629459361Smrg## that the space means something, we add a space to the output as 2375dd2154eSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 2385dd2154eSmrg## to the object. Take care to not repeat it in the output. 23929459361Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 24029459361Smrg## correctly. Breaking it into two sed invocations is a workaround. 241fb4ebca8Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242fb4ebca8Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243fb4ebca8Smrg | sed -e 's/$/ :/' >> "$depfile" 24429459361Smrg rm -f "$tmpdepfile" 24529459361Smrg ;; 24629459361Smrg 24729459361Smrghp) 24829459361Smrg # This case exists only to let depend.m4 do its work. It works by 24929459361Smrg # looking at the text of this script. This case will never be run, 25029459361Smrg # since it is checked for above. 25129459361Smrg exit 1 25229459361Smrg ;; 25329459361Smrg 25429459361Smrgsgi) 25529459361Smrg if test "$libtool" = yes; then 25629459361Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25729459361Smrg else 25829459361Smrg "$@" -MDupdate "$tmpdepfile" 25929459361Smrg fi 26029459361Smrg stat=$? 261fb4ebca8Smrg if test $stat -ne 0; then 26229459361Smrg rm -f "$tmpdepfile" 26329459361Smrg exit $stat 26429459361Smrg fi 26529459361Smrg rm -f "$depfile" 26629459361Smrg 26729459361Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26829459361Smrg echo "$object : \\" > "$depfile" 26929459361Smrg # Clip off the initial element (the dependent). Don't try to be 27029459361Smrg # clever and replace this with sed code, as IRIX sed won't handle 27129459361Smrg # lines with more than a fixed number of characters (4096 in 27229459361Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273fb4ebca8Smrg # the IRIX cc adds comments like '#:fec' to the end of the 27429459361Smrg # dependency line. 275fb4ebca8Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276fb4ebca8Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277fb4ebca8Smrg | tr "$nl" ' ' >> "$depfile" 27847202d7bSmrg echo >> "$depfile" 27929459361Smrg # The second pass generates a dummy entry for each header file. 280fb4ebca8Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281fb4ebca8Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282fb4ebca8Smrg >> "$depfile" 28329459361Smrg else 284fb4ebca8Smrg make_dummy_depfile 28529459361Smrg fi 28629459361Smrg rm -f "$tmpdepfile" 28729459361Smrg ;; 28829459361Smrg 289fb4ebca8Smrgxlc) 290fb4ebca8Smrg # This case exists only to let depend.m4 do its work. It works by 291fb4ebca8Smrg # looking at the text of this script. This case will never be run, 292fb4ebca8Smrg # since it is checked for above. 293fb4ebca8Smrg exit 1 294fb4ebca8Smrg ;; 295fb4ebca8Smrg 29629459361Smrgaix) 29729459361Smrg # The C for AIX Compiler uses -M and outputs the dependencies 29829459361Smrg # in a .u file. In older versions, this file always lives in the 299fb4ebca8Smrg # current directory. Also, the AIX compiler puts '$object:' at the 30029459361Smrg # start of each line; $object doesn't have directory information. 30129459361Smrg # Version 6 uses the directory in both cases. 302fb4ebca8Smrg set_dir_from "$object" 303fb4ebca8Smrg set_base_from "$object" 30429459361Smrg if test "$libtool" = yes; then 30547202d7bSmrg tmpdepfile1=$dir$base.u 30647202d7bSmrg tmpdepfile2=$base.u 30747202d7bSmrg tmpdepfile3=$dir.libs/$base.u 30829459361Smrg "$@" -Wc,-M 30929459361Smrg else 31047202d7bSmrg tmpdepfile1=$dir$base.u 31147202d7bSmrg tmpdepfile2=$dir$base.u 31247202d7bSmrg tmpdepfile3=$dir$base.u 31329459361Smrg "$@" -M 31429459361Smrg fi 31529459361Smrg stat=$? 316fb4ebca8Smrg if test $stat -ne 0; then 31747202d7bSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31829459361Smrg exit $stat 31929459361Smrg fi 32029459361Smrg 32147202d7bSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 32247202d7bSmrg do 32347202d7bSmrg test -f "$tmpdepfile" && break 32447202d7bSmrg done 325fb4ebca8Smrg aix_post_process_depfile 326fb4ebca8Smrg ;; 327fb4ebca8Smrg 328fb4ebca8Smrgtcc) 329fb4ebca8Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330fb4ebca8Smrg # FIXME: That version still under development at the moment of writing. 331fb4ebca8Smrg # Make that this statement remains true also for stable, released 332fb4ebca8Smrg # versions. 333fb4ebca8Smrg # It will wrap lines (doesn't matter whether long or short) with a 334fb4ebca8Smrg # trailing '\', as in: 335fb4ebca8Smrg # 336fb4ebca8Smrg # foo.o : \ 337fb4ebca8Smrg # foo.c \ 338fb4ebca8Smrg # foo.h \ 339fb4ebca8Smrg # 340fb4ebca8Smrg # It will put a trailing '\' even on the last line, and will use leading 341fb4ebca8Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342fb4ebca8Smrg # "Emit spaces for -MD"). 343fb4ebca8Smrg "$@" -MD -MF "$tmpdepfile" 344fb4ebca8Smrg stat=$? 345fb4ebca8Smrg if test $stat -ne 0; then 346fb4ebca8Smrg rm -f "$tmpdepfile" 347fb4ebca8Smrg exit $stat 34829459361Smrg fi 349fb4ebca8Smrg rm -f "$depfile" 350fb4ebca8Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351fb4ebca8Smrg # We have to change lines of the first kind to '$object: \'. 352fb4ebca8Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353fb4ebca8Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354fb4ebca8Smrg # dummy dependency, to avoid the deleted-header problem. 355fb4ebca8Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35629459361Smrg rm -f "$tmpdepfile" 35729459361Smrg ;; 35829459361Smrg 359fb4ebca8Smrg## The order of this option in the case statement is important, since the 360fb4ebca8Smrg## shell code in configure will try each of these formats in the order 361fb4ebca8Smrg## listed in this file. A plain '-MD' option would be understood by many 362fb4ebca8Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363fb4ebca8Smrgpgcc) 364fb4ebca8Smrg # Portland's C compiler understands '-MD'. 365fb4ebca8Smrg # Will always output deps to 'file.d' where file is the root name of the 366fb4ebca8Smrg # source file under compilation, even if file resides in a subdirectory. 367fb4ebca8Smrg # The object file name does not affect the name of the '.d' file. 368fb4ebca8Smrg # pgcc 10.2 will output 36929459361Smrg # foo.o: sub/foo.c sub/foo.h 370fb4ebca8Smrg # and will wrap long lines using '\' : 37129459361Smrg # foo.o: sub/foo.c ... \ 37229459361Smrg # sub/foo.h ... \ 37329459361Smrg # ... 374fb4ebca8Smrg set_dir_from "$object" 375fb4ebca8Smrg # Use the source, not the object, to determine the base name, since 376fb4ebca8Smrg # that's sadly what pgcc will do too. 377fb4ebca8Smrg set_base_from "$source" 378fb4ebca8Smrg tmpdepfile=$base.d 379fb4ebca8Smrg 380fb4ebca8Smrg # For projects that build the same source file twice into different object 381fb4ebca8Smrg # files, the pgcc approach of using the *source* file root name can cause 382fb4ebca8Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383fb4ebca8Smrg # the same $tmpdepfile. 384fb4ebca8Smrg lockdir=$base.d-lock 385fb4ebca8Smrg trap " 386fb4ebca8Smrg echo '$0: caught signal, cleaning up...' >&2 387fb4ebca8Smrg rmdir '$lockdir' 388fb4ebca8Smrg exit 1 389fb4ebca8Smrg " 1 2 13 15 390fb4ebca8Smrg numtries=100 391fb4ebca8Smrg i=$numtries 392fb4ebca8Smrg while test $i -gt 0; do 393fb4ebca8Smrg # mkdir is a portable test-and-set. 394fb4ebca8Smrg if mkdir "$lockdir" 2>/dev/null; then 395fb4ebca8Smrg # This process acquired the lock. 396fb4ebca8Smrg "$@" -MD 397fb4ebca8Smrg stat=$? 398fb4ebca8Smrg # Release the lock. 399fb4ebca8Smrg rmdir "$lockdir" 400fb4ebca8Smrg break 401fb4ebca8Smrg else 402fb4ebca8Smrg # If the lock is being held by a different process, wait 403fb4ebca8Smrg # until the winning process is done or we timeout. 404fb4ebca8Smrg while test -d "$lockdir" && test $i -gt 0; do 405fb4ebca8Smrg sleep 1 406fb4ebca8Smrg i=`expr $i - 1` 407fb4ebca8Smrg done 408fb4ebca8Smrg fi 409fb4ebca8Smrg i=`expr $i - 1` 410fb4ebca8Smrg done 411fb4ebca8Smrg trap - 1 2 13 15 412fb4ebca8Smrg if test $i -le 0; then 413fb4ebca8Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414fb4ebca8Smrg echo "$0: check lockdir '$lockdir'" >&2 415fb4ebca8Smrg exit 1 416fb4ebca8Smrg fi 41729459361Smrg 418fb4ebca8Smrg if test $stat -ne 0; then 41929459361Smrg rm -f "$tmpdepfile" 42029459361Smrg exit $stat 42129459361Smrg fi 42229459361Smrg rm -f "$depfile" 42329459361Smrg # Each line is of the form `foo.o: dependent.h', 42429459361Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42529459361Smrg # Do two passes, one to just change these to 42629459361Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 42729459361Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42829459361Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 42929459361Smrg # correctly. Breaking it into two sed invocations is a workaround. 430fb4ebca8Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431fb4ebca8Smrg | sed -e 's/$/ :/' >> "$depfile" 43229459361Smrg rm -f "$tmpdepfile" 43329459361Smrg ;; 43429459361Smrg 43547202d7bSmrghp2) 43647202d7bSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 43747202d7bSmrg # compilers, which have integrated preprocessors. The correct option 43847202d7bSmrg # to use with these is +Maked; it writes dependencies to a file named 43947202d7bSmrg # 'foo.d', which lands next to the object file, wherever that 44047202d7bSmrg # happens to be. 44147202d7bSmrg # Much of this is similar to the tru64 case; see comments there. 442fb4ebca8Smrg set_dir_from "$object" 443fb4ebca8Smrg set_base_from "$object" 44447202d7bSmrg if test "$libtool" = yes; then 44547202d7bSmrg tmpdepfile1=$dir$base.d 44647202d7bSmrg tmpdepfile2=$dir.libs/$base.d 44747202d7bSmrg "$@" -Wc,+Maked 44847202d7bSmrg else 44947202d7bSmrg tmpdepfile1=$dir$base.d 45047202d7bSmrg tmpdepfile2=$dir$base.d 45147202d7bSmrg "$@" +Maked 45247202d7bSmrg fi 45347202d7bSmrg stat=$? 454fb4ebca8Smrg if test $stat -ne 0; then 45547202d7bSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 45647202d7bSmrg exit $stat 45747202d7bSmrg fi 45847202d7bSmrg 45947202d7bSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 46047202d7bSmrg do 46147202d7bSmrg test -f "$tmpdepfile" && break 46247202d7bSmrg done 46347202d7bSmrg if test -f "$tmpdepfile"; then 464fb4ebca8Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465fb4ebca8Smrg # Add 'dependent.h:' lines. 46647202d7bSmrg sed -ne '2,${ 467fb4ebca8Smrg s/^ *// 468fb4ebca8Smrg s/ \\*$// 469fb4ebca8Smrg s/$/:/ 470fb4ebca8Smrg p 471fb4ebca8Smrg }' "$tmpdepfile" >> "$depfile" 47247202d7bSmrg else 473fb4ebca8Smrg make_dummy_depfile 47447202d7bSmrg fi 47547202d7bSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 47647202d7bSmrg ;; 47747202d7bSmrg 47829459361Smrgtru64) 479fb4ebca8Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480fb4ebca8Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481fb4ebca8Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482fb4ebca8Smrg # dependencies in 'foo.d' instead, so we check for that too. 483fb4ebca8Smrg # Subdirectories are respected. 484fb4ebca8Smrg set_dir_from "$object" 485fb4ebca8Smrg set_base_from "$object" 486fb4ebca8Smrg 487fb4ebca8Smrg if test "$libtool" = yes; then 488fb4ebca8Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489fb4ebca8Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490fb4ebca8Smrg # in $dir$base.o.d. We have to check for both files, because 491fb4ebca8Smrg # one of the two compilations can be disabled. We should prefer 492fb4ebca8Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493fb4ebca8Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494fb4ebca8Smrg # the former would cause a distcleancheck panic. 495fb4ebca8Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496fb4ebca8Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497fb4ebca8Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498fb4ebca8Smrg "$@" -Wc,-MD 499fb4ebca8Smrg else 500fb4ebca8Smrg tmpdepfile1=$dir$base.d 501fb4ebca8Smrg tmpdepfile2=$dir$base.d 502fb4ebca8Smrg tmpdepfile3=$dir$base.d 503fb4ebca8Smrg "$@" -MD 504fb4ebca8Smrg fi 505fb4ebca8Smrg 506fb4ebca8Smrg stat=$? 507fb4ebca8Smrg if test $stat -ne 0; then 508fb4ebca8Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509fb4ebca8Smrg exit $stat 510fb4ebca8Smrg fi 511fb4ebca8Smrg 512fb4ebca8Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513fb4ebca8Smrg do 514fb4ebca8Smrg test -f "$tmpdepfile" && break 515fb4ebca8Smrg done 516fb4ebca8Smrg # Same post-processing that is required for AIX mode. 517fb4ebca8Smrg aix_post_process_depfile 518fb4ebca8Smrg ;; 51929459361Smrg 5205dd2154eSmrgmsvc7) 5215dd2154eSmrg if test "$libtool" = yes; then 5225dd2154eSmrg showIncludes=-Wc,-showIncludes 5235dd2154eSmrg else 5245dd2154eSmrg showIncludes=-showIncludes 5255dd2154eSmrg fi 5265dd2154eSmrg "$@" $showIncludes > "$tmpdepfile" 5275dd2154eSmrg stat=$? 5285dd2154eSmrg grep -v '^Note: including file: ' "$tmpdepfile" 529fb4ebca8Smrg if test $stat -ne 0; then 5305dd2154eSmrg rm -f "$tmpdepfile" 5315dd2154eSmrg exit $stat 5325dd2154eSmrg fi 5335dd2154eSmrg rm -f "$depfile" 5345dd2154eSmrg echo "$object : \\" > "$depfile" 5355dd2154eSmrg # The first sed program below extracts the file names and escapes 5365dd2154eSmrg # backslashes for cygpath. The second sed program outputs the file 5375dd2154eSmrg # name when reading, but also accumulates all include files in the 5385dd2154eSmrg # hold buffer in order to output them again at the end. This only 5395dd2154eSmrg # works with sed implementations that can handle large buffers. 5405dd2154eSmrg sed < "$tmpdepfile" -n ' 5415dd2154eSmrg/^Note: including file: *\(.*\)/ { 5425dd2154eSmrg s//\1/ 5435dd2154eSmrg s/\\/\\\\/g 5445dd2154eSmrg p 5455dd2154eSmrg}' | $cygpath_u | sort -u | sed -n ' 5465dd2154eSmrgs/ /\\ /g 547fb4ebca8Smrgs/\(.*\)/'"$tab"'\1 \\/p 5485dd2154eSmrgs/.\(.*\) \\/\1:/ 5495dd2154eSmrgH 5505dd2154eSmrg$ { 551fb4ebca8Smrg s/.*/'"$tab"'/ 5525dd2154eSmrg G 5535dd2154eSmrg p 5545dd2154eSmrg}' >> "$depfile" 555fb4ebca8Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5565dd2154eSmrg rm -f "$tmpdepfile" 5575dd2154eSmrg ;; 5585dd2154eSmrg 5595dd2154eSmrgmsvc7msys) 5605dd2154eSmrg # This case exists only to let depend.m4 do its work. It works by 5615dd2154eSmrg # looking at the text of this script. This case will never be run, 5625dd2154eSmrg # since it is checked for above. 5635dd2154eSmrg exit 1 5645dd2154eSmrg ;; 5655dd2154eSmrg 56629459361Smrg#nosideeffect) 56729459361Smrg # This comment above is used by automake to tell side-effect 56829459361Smrg # dependency tracking mechanisms from slower ones. 56929459361Smrg 57029459361Smrgdashmstdout) 57129459361Smrg # Important note: in order to support this mode, a compiler *must* 57229459361Smrg # always write the preprocessed file to stdout, regardless of -o. 57329459361Smrg "$@" || exit $? 57429459361Smrg 57529459361Smrg # Remove the call to Libtool. 57629459361Smrg if test "$libtool" = yes; then 57747202d7bSmrg while test "X$1" != 'X--mode=compile'; do 57829459361Smrg shift 57929459361Smrg done 58029459361Smrg shift 58129459361Smrg fi 58229459361Smrg 583fb4ebca8Smrg # Remove '-o $object'. 58429459361Smrg IFS=" " 58529459361Smrg for arg 58629459361Smrg do 58729459361Smrg case $arg in 58829459361Smrg -o) 58929459361Smrg shift 59029459361Smrg ;; 59129459361Smrg $object) 59229459361Smrg shift 59329459361Smrg ;; 59429459361Smrg *) 59529459361Smrg set fnord "$@" "$arg" 59629459361Smrg shift # fnord 59729459361Smrg shift # $arg 59829459361Smrg ;; 59929459361Smrg esac 60029459361Smrg done 60129459361Smrg 60229459361Smrg test -z "$dashmflag" && dashmflag=-M 603fb4ebca8Smrg # Require at least two characters before searching for ':' 60429459361Smrg # in the target name. This is to cope with DOS-style filenames: 605fb4ebca8Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60629459361Smrg "$@" $dashmflag | 607fb4ebca8Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60829459361Smrg rm -f "$depfile" 60929459361Smrg cat < "$tmpdepfile" > "$depfile" 610fb4ebca8Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611fb4ebca8Smrg # correctly. Breaking it into two sed invocations is a workaround. 612fb4ebca8Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613fb4ebca8Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614fb4ebca8Smrg | sed -e 's/$/ :/' >> "$depfile" 61529459361Smrg rm -f "$tmpdepfile" 61629459361Smrg ;; 61729459361Smrg 61829459361SmrgdashXmstdout) 61929459361Smrg # This case only exists to satisfy depend.m4. It is never actually 62029459361Smrg # run, as this mode is specially recognized in the preamble. 62129459361Smrg exit 1 62229459361Smrg ;; 62329459361Smrg 62429459361Smrgmakedepend) 62529459361Smrg "$@" || exit $? 62629459361Smrg # Remove any Libtool call 62729459361Smrg if test "$libtool" = yes; then 62847202d7bSmrg while test "X$1" != 'X--mode=compile'; do 62929459361Smrg shift 63029459361Smrg done 63129459361Smrg shift 63229459361Smrg fi 63329459361Smrg # X makedepend 63429459361Smrg shift 63547202d7bSmrg cleared=no eat=no 63647202d7bSmrg for arg 63747202d7bSmrg do 63829459361Smrg case $cleared in 63929459361Smrg no) 64029459361Smrg set ""; shift 64129459361Smrg cleared=yes ;; 64229459361Smrg esac 64347202d7bSmrg if test $eat = yes; then 64447202d7bSmrg eat=no 64547202d7bSmrg continue 64647202d7bSmrg fi 64729459361Smrg case "$arg" in 64829459361Smrg -D*|-I*) 64929459361Smrg set fnord "$@" "$arg"; shift ;; 65029459361Smrg # Strip any option that makedepend may not understand. Remove 65129459361Smrg # the object too, otherwise makedepend will parse it as a source file. 65247202d7bSmrg -arch) 65347202d7bSmrg eat=yes ;; 65429459361Smrg -*|$object) 65529459361Smrg ;; 65629459361Smrg *) 65729459361Smrg set fnord "$@" "$arg"; shift ;; 65829459361Smrg esac 65929459361Smrg done 66047202d7bSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66129459361Smrg touch "$tmpdepfile" 66229459361Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66329459361Smrg rm -f "$depfile" 6645dd2154eSmrg # makedepend may prepend the VPATH from the source file name to the object. 6655dd2154eSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 6665dd2154eSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667fb4ebca8Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668fb4ebca8Smrg # correctly. Breaking it into two sed invocations is a workaround. 669fb4ebca8Smrg sed '1,2d' "$tmpdepfile" \ 670fb4ebca8Smrg | tr ' ' "$nl" \ 671fb4ebca8Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672fb4ebca8Smrg | sed -e 's/$/ :/' >> "$depfile" 67329459361Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67429459361Smrg ;; 67529459361Smrg 67629459361Smrgcpp) 67729459361Smrg # Important note: in order to support this mode, a compiler *must* 67829459361Smrg # always write the preprocessed file to stdout. 67929459361Smrg "$@" || exit $? 68029459361Smrg 68129459361Smrg # Remove the call to Libtool. 68229459361Smrg if test "$libtool" = yes; then 68347202d7bSmrg while test "X$1" != 'X--mode=compile'; do 68429459361Smrg shift 68529459361Smrg done 68629459361Smrg shift 68729459361Smrg fi 68829459361Smrg 689fb4ebca8Smrg # Remove '-o $object'. 69029459361Smrg IFS=" " 69129459361Smrg for arg 69229459361Smrg do 69329459361Smrg case $arg in 69429459361Smrg -o) 69529459361Smrg shift 69629459361Smrg ;; 69729459361Smrg $object) 69829459361Smrg shift 69929459361Smrg ;; 70029459361Smrg *) 70129459361Smrg set fnord "$@" "$arg" 70229459361Smrg shift # fnord 70329459361Smrg shift # $arg 70429459361Smrg ;; 70529459361Smrg esac 70629459361Smrg done 70729459361Smrg 708fb4ebca8Smrg "$@" -E \ 709fb4ebca8Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710fb4ebca8Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711fb4ebca8Smrg | sed '$ s: \\$::' > "$tmpdepfile" 71229459361Smrg rm -f "$depfile" 71329459361Smrg echo "$object : \\" > "$depfile" 71429459361Smrg cat < "$tmpdepfile" >> "$depfile" 71529459361Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71629459361Smrg rm -f "$tmpdepfile" 71729459361Smrg ;; 71829459361Smrg 71929459361Smrgmsvisualcpp) 72029459361Smrg # Important note: in order to support this mode, a compiler *must* 72147202d7bSmrg # always write the preprocessed file to stdout. 72229459361Smrg "$@" || exit $? 72347202d7bSmrg 72447202d7bSmrg # Remove the call to Libtool. 72547202d7bSmrg if test "$libtool" = yes; then 72647202d7bSmrg while test "X$1" != 'X--mode=compile'; do 72747202d7bSmrg shift 72847202d7bSmrg done 72947202d7bSmrg shift 73047202d7bSmrg fi 73147202d7bSmrg 73229459361Smrg IFS=" " 73329459361Smrg for arg 73429459361Smrg do 73529459361Smrg case "$arg" in 73647202d7bSmrg -o) 73747202d7bSmrg shift 73847202d7bSmrg ;; 73947202d7bSmrg $object) 74047202d7bSmrg shift 74147202d7bSmrg ;; 74229459361Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743fb4ebca8Smrg set fnord "$@" 744fb4ebca8Smrg shift 745fb4ebca8Smrg shift 746fb4ebca8Smrg ;; 74729459361Smrg *) 748fb4ebca8Smrg set fnord "$@" "$arg" 749fb4ebca8Smrg shift 750fb4ebca8Smrg shift 751fb4ebca8Smrg ;; 75229459361Smrg esac 75329459361Smrg done 75447202d7bSmrg "$@" -E 2>/dev/null | 75547202d7bSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75629459361Smrg rm -f "$depfile" 75729459361Smrg echo "$object : \\" > "$depfile" 758fb4ebca8Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759fb4ebca8Smrg echo "$tab" >> "$depfile" 76047202d7bSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76129459361Smrg rm -f "$tmpdepfile" 76229459361Smrg ;; 76329459361Smrg 76447202d7bSmrgmsvcmsys) 76547202d7bSmrg # This case exists only to let depend.m4 do its work. It works by 76647202d7bSmrg # looking at the text of this script. This case will never be run, 76747202d7bSmrg # since it is checked for above. 76847202d7bSmrg exit 1 76947202d7bSmrg ;; 77047202d7bSmrg 77129459361Smrgnone) 77229459361Smrg exec "$@" 77329459361Smrg ;; 77429459361Smrg 77529459361Smrg*) 77629459361Smrg echo "Unknown depmode $depmode" 1>&2 77729459361Smrg exit 1 77829459361Smrg ;; 77929459361Smrgesac 78029459361Smrg 78129459361Smrgexit 0 78229459361Smrg 78329459361Smrg# Local Variables: 78429459361Smrg# mode: shell-script 78529459361Smrg# sh-indentation: 2 78629459361Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 78729459361Smrg# time-stamp-start: "scriptversion=" 78829459361Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789fa2b3b63Smrg# time-stamp-time-zone: "UTC0" 79047202d7bSmrg# time-stamp-end: "; # UTC" 79129459361Smrg# End: 792