114c0a534Smrg#! /bin/sh 214c0a534Smrg# depcomp - compile a program generating dependencies as side-effects 314c0a534Smrg 47015785aSmrgscriptversion=2024-06-19.01; # UTC 514c0a534Smrg 67015785aSmrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 714c0a534Smrg 814c0a534Smrg# This program is free software; you can redistribute it and/or modify 914c0a534Smrg# it under the terms of the GNU General Public License as published by 1014c0a534Smrg# the Free Software Foundation; either version 2, or (at your option) 1114c0a534Smrg# any later version. 1214c0a534Smrg 1314c0a534Smrg# This program is distributed in the hope that it will be useful, 1414c0a534Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1514c0a534Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1614c0a534Smrg# GNU General Public License for more details. 1714c0a534Smrg 1814c0a534Smrg# You should have received a copy of the GNU General Public License 19bdc460c5Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2014c0a534Smrg 2114c0a534Smrg# As a special exception to the GNU General Public License, if you 2214c0a534Smrg# distribute this file as part of a program that contains a 2314c0a534Smrg# configuration script generated by Autoconf, you may include it under 2414c0a534Smrg# the same distribution terms that you use for the rest of that program. 2514c0a534Smrg 2614c0a534Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 2714c0a534Smrg 2814c0a534Smrgcase $1 in 2914c0a534Smrg '') 3024047306Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3124047306Smrg exit 1; 3224047306Smrg ;; 3314c0a534Smrg -h | --h*) 3414c0a534Smrg cat <<\EOF 3514c0a534SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 3614c0a534Smrg 3714c0a534SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 3814c0a534Smrgas side-effects. 3914c0a534Smrg 4014c0a534SmrgEnvironment variables: 4114c0a534Smrg depmode Dependency tracking mode. 4224047306Smrg source Source file read by 'PROGRAMS ARGS'. 4324047306Smrg object Object file output by 'PROGRAMS ARGS'. 4414c0a534Smrg DEPDIR directory where to store dependencies. 4514c0a534Smrg depfile Dependency file to output. 4624047306Smrg tmpdepfile Temporary file to use when outputting dependencies. 4714c0a534Smrg libtool Whether libtool is used (yes/no). 4814c0a534Smrg 4914c0a534SmrgReport bugs to <bug-automake@gnu.org>. 507015785aSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 517015785aSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 5214c0a534SmrgEOF 5314c0a534Smrg exit $? 5414c0a534Smrg ;; 5514c0a534Smrg -v | --v*) 567015785aSmrg echo "depcomp (GNU Automake) $scriptversion" 5714c0a534Smrg exit $? 5814c0a534Smrg ;; 5914c0a534Smrgesac 6014c0a534Smrg 6124047306Smrg# Get the directory component of the given path, and save it in the 6224047306Smrg# global variables '$dir'. Note that this directory component will 6324047306Smrg# be either empty or ending with a '/' character. This is deliberate. 6424047306Smrgset_dir_from () 6524047306Smrg{ 6624047306Smrg case $1 in 6724047306Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6824047306Smrg *) dir=;; 6924047306Smrg esac 7024047306Smrg} 7124047306Smrg 7224047306Smrg# Get the suffix-stripped basename of the given path, and save it the 7324047306Smrg# global variable '$base'. 7424047306Smrgset_base_from () 7524047306Smrg{ 7624047306Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7724047306Smrg} 7824047306Smrg 7924047306Smrg# If no dependency file was actually created by the compiler invocation, 8024047306Smrg# we still have to create a dummy depfile, to avoid errors with the 8124047306Smrg# Makefile "include basename.Plo" scheme. 8224047306Smrgmake_dummy_depfile () 8324047306Smrg{ 8424047306Smrg echo "#dummy" > "$depfile" 8524047306Smrg} 8624047306Smrg 8724047306Smrg# Factor out some common post-processing of the generated depfile. 8824047306Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8924047306Smrgaix_post_process_depfile () 9024047306Smrg{ 9124047306Smrg # If the compiler actually managed to produce a dependency file, 9224047306Smrg # post-process it. 9324047306Smrg if test -f "$tmpdepfile"; then 9424047306Smrg # Each line is of the form 'foo.o: dependency.h'. 9524047306Smrg # Do two passes, one to just change these to 9624047306Smrg # $object: dependency.h 9724047306Smrg # and one to simply output 9824047306Smrg # dependency.h: 9924047306Smrg # which is needed to avoid the deleted-header problem. 10024047306Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 10124047306Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10224047306Smrg } > "$depfile" 10324047306Smrg rm -f "$tmpdepfile" 10424047306Smrg else 10524047306Smrg make_dummy_depfile 10624047306Smrg fi 10724047306Smrg} 10824047306Smrg 10924047306Smrg# A tabulation character. 11024047306Smrgtab=' ' 11124047306Smrg# A newline character. 11224047306Smrgnl=' 11324047306Smrg' 11424047306Smrg# Character ranges might be problematic outside the C locale. 11524047306Smrg# These definitions help. 11624047306Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11724047306Smrglower=abcdefghijklmnopqrstuvwxyz 11824047306Smrgalpha=${upper}${lower} 11924047306Smrg 12014c0a534Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 12114c0a534Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 12214c0a534Smrg exit 1 12314c0a534Smrgfi 12414c0a534Smrg 12514c0a534Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 12614c0a534Smrgdepfile=${depfile-`echo "$object" | 12714c0a534Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 12814c0a534Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 12914c0a534Smrg 13014c0a534Smrgrm -f "$tmpdepfile" 13114c0a534Smrg 1327015785aSmrg# Avoid interference from the environment. 13324047306Smrggccflag= dashmflag= 13424047306Smrg 13514c0a534Smrg# Some modes work just like other modes, but use different flags. We 13614c0a534Smrg# parameterize here, but still list the modes in the big case below, 13714c0a534Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 13814c0a534Smrg# here, because this file can only contain one case statement. 13914c0a534Smrgif test "$depmode" = hp; then 14014c0a534Smrg # HP compiler uses -M and no extra arg. 14114c0a534Smrg gccflag=-M 14214c0a534Smrg depmode=gcc 14314c0a534Smrgfi 14414c0a534Smrg 14514c0a534Smrgif test "$depmode" = dashXmstdout; then 14624047306Smrg # This is just like dashmstdout with a different argument. 14724047306Smrg dashmflag=-xM 14824047306Smrg depmode=dashmstdout 14914c0a534Smrgfi 15014c0a534Smrg 151bf2eeab3Smrgcygpath_u="cygpath -u -f -" 152bf2eeab3Smrgif test "$depmode" = msvcmsys; then 15324047306Smrg # This is just like msvisualcpp but w/o cygpath translation. 15424047306Smrg # Just convert the backslash-escaped backslashes to single forward 15524047306Smrg # slashes to satisfy depend.m4 15624047306Smrg cygpath_u='sed s,\\\\,/,g' 15724047306Smrg depmode=msvisualcpp 15824047306Smrgfi 15924047306Smrg 16024047306Smrgif test "$depmode" = msvc7msys; then 16124047306Smrg # This is just like msvc7 but w/o cygpath translation. 16224047306Smrg # Just convert the backslash-escaped backslashes to single forward 16324047306Smrg # slashes to satisfy depend.m4 16424047306Smrg cygpath_u='sed s,\\\\,/,g' 16524047306Smrg depmode=msvc7 16624047306Smrgfi 16724047306Smrg 16824047306Smrgif test "$depmode" = xlc; then 16924047306Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 17024047306Smrg gccflag=-qmakedep=gcc,-MF 17124047306Smrg depmode=gcc 172bf2eeab3Smrgfi 173bf2eeab3Smrg 17414c0a534Smrgcase "$depmode" in 17514c0a534Smrggcc3) 17614c0a534Smrg## gcc 3 implements dependency tracking that does exactly what 17714c0a534Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 17814c0a534Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 179bf2eeab3Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 180bf2eeab3Smrg## the command line argument order; so add the flags where they 181bf2eeab3Smrg## appear in depend2.am. Note that the slowdown incurred here 182bf2eeab3Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 183bf2eeab3Smrg for arg 184bf2eeab3Smrg do 185bf2eeab3Smrg case $arg in 186bf2eeab3Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 187bf2eeab3Smrg *) set fnord "$@" "$arg" ;; 188bf2eeab3Smrg esac 189bf2eeab3Smrg shift # fnord 190bf2eeab3Smrg shift # $arg 191bf2eeab3Smrg done 192bf2eeab3Smrg "$@" 19314c0a534Smrg stat=$? 19424047306Smrg if test $stat -ne 0; then 19514c0a534Smrg rm -f "$tmpdepfile" 19614c0a534Smrg exit $stat 19714c0a534Smrg fi 19814c0a534Smrg mv "$tmpdepfile" "$depfile" 19914c0a534Smrg ;; 20014c0a534Smrg 20114c0a534Smrggcc) 2027015785aSmrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 2037015785aSmrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 20424047306Smrg## (see the conditional assignment to $gccflag above). 20514c0a534Smrg## There are various ways to get dependency output from gcc. Here's 20614c0a534Smrg## why we pick this rather obscure method: 20714c0a534Smrg## - Don't want to use -MD because we'd like the dependencies to end 20814c0a534Smrg## up in a subdir. Having to rename by hand is ugly. 20914c0a534Smrg## (We might end up doing this anyway to support other compilers.) 21014c0a534Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21124047306Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21224047306Smrg## supported by the other compilers which use the 'gcc' depmode. 21314c0a534Smrg## - Using -M directly means running the compiler twice (even worse 21414c0a534Smrg## than renaming). 21514c0a534Smrg if test -z "$gccflag"; then 21614c0a534Smrg gccflag=-MD, 21714c0a534Smrg fi 21814c0a534Smrg "$@" -Wp,"$gccflag$tmpdepfile" 21914c0a534Smrg stat=$? 22024047306Smrg if test $stat -ne 0; then 22114c0a534Smrg rm -f "$tmpdepfile" 22214c0a534Smrg exit $stat 22314c0a534Smrg fi 22414c0a534Smrg rm -f "$depfile" 22514c0a534Smrg echo "$object : \\" > "$depfile" 22624047306Smrg # The second -e expression handles DOS-style file names with drive 22724047306Smrg # letters. 22814c0a534Smrg sed -e 's/^[^:]*: / /' \ 22914c0a534Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 23024047306Smrg## This next piece of magic avoids the "deleted header file" problem. 23114c0a534Smrg## The problem is that when a header file which appears in a .P file 23214c0a534Smrg## is deleted, the dependency causes make to die (because there is 23314c0a534Smrg## typically no way to rebuild the header). We avoid this by adding 23414c0a534Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 23514c0a534Smrg## this for us directly. 23624047306Smrg## Some versions of gcc put a space before the ':'. On the theory 23714c0a534Smrg## that the space means something, we add a space to the output as 23824047306Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23924047306Smrg## to the object. Take care to not repeat it in the output. 24014c0a534Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 24114c0a534Smrg## correctly. Breaking it into two sed invocations is a workaround. 24224047306Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24324047306Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24424047306Smrg | sed -e 's/$/ :/' >> "$depfile" 24514c0a534Smrg rm -f "$tmpdepfile" 24614c0a534Smrg ;; 24714c0a534Smrg 24814c0a534Smrghp) 24914c0a534Smrg # This case exists only to let depend.m4 do its work. It works by 25014c0a534Smrg # looking at the text of this script. This case will never be run, 25114c0a534Smrg # since it is checked for above. 25214c0a534Smrg exit 1 25314c0a534Smrg ;; 25414c0a534Smrg 25514c0a534Smrgsgi) 25614c0a534Smrg if test "$libtool" = yes; then 25714c0a534Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 25814c0a534Smrg else 25914c0a534Smrg "$@" -MDupdate "$tmpdepfile" 26014c0a534Smrg fi 26114c0a534Smrg stat=$? 26224047306Smrg if test $stat -ne 0; then 26314c0a534Smrg rm -f "$tmpdepfile" 26414c0a534Smrg exit $stat 26514c0a534Smrg fi 26614c0a534Smrg rm -f "$depfile" 26714c0a534Smrg 26814c0a534Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 26914c0a534Smrg echo "$object : \\" > "$depfile" 27014c0a534Smrg # Clip off the initial element (the dependent). Don't try to be 27114c0a534Smrg # clever and replace this with sed code, as IRIX sed won't handle 27214c0a534Smrg # lines with more than a fixed number of characters (4096 in 27314c0a534Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27424047306Smrg # the IRIX cc adds comments like '#:fec' to the end of the 27514c0a534Smrg # dependency line. 27624047306Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27724047306Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27824047306Smrg | tr "$nl" ' ' >> "$depfile" 279bf2eeab3Smrg echo >> "$depfile" 28014c0a534Smrg # The second pass generates a dummy entry for each header file. 28124047306Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28224047306Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28324047306Smrg >> "$depfile" 28414c0a534Smrg else 28524047306Smrg make_dummy_depfile 28614c0a534Smrg fi 28714c0a534Smrg rm -f "$tmpdepfile" 28814c0a534Smrg ;; 28914c0a534Smrg 29024047306Smrgxlc) 29124047306Smrg # This case exists only to let depend.m4 do its work. It works by 29224047306Smrg # looking at the text of this script. This case will never be run, 29324047306Smrg # since it is checked for above. 29424047306Smrg exit 1 29524047306Smrg ;; 29624047306Smrg 29714c0a534Smrgaix) 29814c0a534Smrg # The C for AIX Compiler uses -M and outputs the dependencies 29914c0a534Smrg # in a .u file. In older versions, this file always lives in the 30024047306Smrg # current directory. Also, the AIX compiler puts '$object:' at the 30114c0a534Smrg # start of each line; $object doesn't have directory information. 30214c0a534Smrg # Version 6 uses the directory in both cases. 30324047306Smrg set_dir_from "$object" 30424047306Smrg set_base_from "$object" 30514c0a534Smrg if test "$libtool" = yes; then 306bf2eeab3Smrg tmpdepfile1=$dir$base.u 307bf2eeab3Smrg tmpdepfile2=$base.u 308bf2eeab3Smrg tmpdepfile3=$dir.libs/$base.u 30914c0a534Smrg "$@" -Wc,-M 31014c0a534Smrg else 311bf2eeab3Smrg tmpdepfile1=$dir$base.u 312bf2eeab3Smrg tmpdepfile2=$dir$base.u 313bf2eeab3Smrg tmpdepfile3=$dir$base.u 31414c0a534Smrg "$@" -M 31514c0a534Smrg fi 31614c0a534Smrg stat=$? 31724047306Smrg if test $stat -ne 0; then 318bf2eeab3Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 31914c0a534Smrg exit $stat 32014c0a534Smrg fi 32114c0a534Smrg 322bf2eeab3Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 323bf2eeab3Smrg do 324bf2eeab3Smrg test -f "$tmpdepfile" && break 325bf2eeab3Smrg done 32624047306Smrg aix_post_process_depfile 32724047306Smrg ;; 32824047306Smrg 32924047306Smrgtcc) 33024047306Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33124047306Smrg # FIXME: That version still under development at the moment of writing. 33224047306Smrg # Make that this statement remains true also for stable, released 33324047306Smrg # versions. 33424047306Smrg # It will wrap lines (doesn't matter whether long or short) with a 33524047306Smrg # trailing '\', as in: 33624047306Smrg # 33724047306Smrg # foo.o : \ 33824047306Smrg # foo.c \ 33924047306Smrg # foo.h \ 34024047306Smrg # 34124047306Smrg # It will put a trailing '\' even on the last line, and will use leading 34224047306Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34324047306Smrg # "Emit spaces for -MD"). 34424047306Smrg "$@" -MD -MF "$tmpdepfile" 34524047306Smrg stat=$? 34624047306Smrg if test $stat -ne 0; then 34724047306Smrg rm -f "$tmpdepfile" 34824047306Smrg exit $stat 34914c0a534Smrg fi 35024047306Smrg rm -f "$depfile" 35124047306Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35224047306Smrg # We have to change lines of the first kind to '$object: \'. 35324047306Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35424047306Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35524047306Smrg # dummy dependency, to avoid the deleted-header problem. 35624047306Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 35714c0a534Smrg rm -f "$tmpdepfile" 35814c0a534Smrg ;; 35914c0a534Smrg 36024047306Smrg## The order of this option in the case statement is important, since the 36124047306Smrg## shell code in configure will try each of these formats in the order 36224047306Smrg## listed in this file. A plain '-MD' option would be understood by many 36324047306Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36424047306Smrgpgcc) 36524047306Smrg # Portland's C compiler understands '-MD'. 36624047306Smrg # Will always output deps to 'file.d' where file is the root name of the 36724047306Smrg # source file under compilation, even if file resides in a subdirectory. 36824047306Smrg # The object file name does not affect the name of the '.d' file. 36924047306Smrg # pgcc 10.2 will output 37014c0a534Smrg # foo.o: sub/foo.c sub/foo.h 37124047306Smrg # and will wrap long lines using '\' : 37214c0a534Smrg # foo.o: sub/foo.c ... \ 37314c0a534Smrg # sub/foo.h ... \ 37414c0a534Smrg # ... 37524047306Smrg set_dir_from "$object" 37624047306Smrg # Use the source, not the object, to determine the base name, since 37724047306Smrg # that's sadly what pgcc will do too. 37824047306Smrg set_base_from "$source" 37924047306Smrg tmpdepfile=$base.d 38024047306Smrg 38124047306Smrg # For projects that build the same source file twice into different object 38224047306Smrg # files, the pgcc approach of using the *source* file root name can cause 38324047306Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38424047306Smrg # the same $tmpdepfile. 38524047306Smrg lockdir=$base.d-lock 38624047306Smrg trap " 38724047306Smrg echo '$0: caught signal, cleaning up...' >&2 38824047306Smrg rmdir '$lockdir' 38924047306Smrg exit 1 39024047306Smrg " 1 2 13 15 39124047306Smrg numtries=100 39224047306Smrg i=$numtries 39324047306Smrg while test $i -gt 0; do 39424047306Smrg # mkdir is a portable test-and-set. 39524047306Smrg if mkdir "$lockdir" 2>/dev/null; then 39624047306Smrg # This process acquired the lock. 39724047306Smrg "$@" -MD 39824047306Smrg stat=$? 39924047306Smrg # Release the lock. 40024047306Smrg rmdir "$lockdir" 40124047306Smrg break 40224047306Smrg else 40324047306Smrg # If the lock is being held by a different process, wait 40424047306Smrg # until the winning process is done or we timeout. 40524047306Smrg while test -d "$lockdir" && test $i -gt 0; do 40624047306Smrg sleep 1 40724047306Smrg i=`expr $i - 1` 40824047306Smrg done 40924047306Smrg fi 41024047306Smrg i=`expr $i - 1` 41124047306Smrg done 41224047306Smrg trap - 1 2 13 15 41324047306Smrg if test $i -le 0; then 41424047306Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41524047306Smrg echo "$0: check lockdir '$lockdir'" >&2 41624047306Smrg exit 1 41724047306Smrg fi 41814c0a534Smrg 41924047306Smrg if test $stat -ne 0; then 42014c0a534Smrg rm -f "$tmpdepfile" 42114c0a534Smrg exit $stat 42214c0a534Smrg fi 42314c0a534Smrg rm -f "$depfile" 42414c0a534Smrg # Each line is of the form `foo.o: dependent.h', 42514c0a534Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 42614c0a534Smrg # Do two passes, one to just change these to 42714c0a534Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 42814c0a534Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 42914c0a534Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 43014c0a534Smrg # correctly. Breaking it into two sed invocations is a workaround. 43124047306Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43224047306Smrg | sed -e 's/$/ :/' >> "$depfile" 43314c0a534Smrg rm -f "$tmpdepfile" 43414c0a534Smrg ;; 43514c0a534Smrg 436bf2eeab3Smrghp2) 437bf2eeab3Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 438bf2eeab3Smrg # compilers, which have integrated preprocessors. The correct option 439bf2eeab3Smrg # to use with these is +Maked; it writes dependencies to a file named 440bf2eeab3Smrg # 'foo.d', which lands next to the object file, wherever that 441bf2eeab3Smrg # happens to be. 442bf2eeab3Smrg # Much of this is similar to the tru64 case; see comments there. 44324047306Smrg set_dir_from "$object" 44424047306Smrg set_base_from "$object" 445bf2eeab3Smrg if test "$libtool" = yes; then 446bf2eeab3Smrg tmpdepfile1=$dir$base.d 447bf2eeab3Smrg tmpdepfile2=$dir.libs/$base.d 448bf2eeab3Smrg "$@" -Wc,+Maked 449bf2eeab3Smrg else 450bf2eeab3Smrg tmpdepfile1=$dir$base.d 451bf2eeab3Smrg tmpdepfile2=$dir$base.d 452bf2eeab3Smrg "$@" +Maked 453bf2eeab3Smrg fi 454bf2eeab3Smrg stat=$? 45524047306Smrg if test $stat -ne 0; then 456bf2eeab3Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 457bf2eeab3Smrg exit $stat 458bf2eeab3Smrg fi 459bf2eeab3Smrg 460bf2eeab3Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 461bf2eeab3Smrg do 462bf2eeab3Smrg test -f "$tmpdepfile" && break 463bf2eeab3Smrg done 464bf2eeab3Smrg if test -f "$tmpdepfile"; then 46524047306Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46624047306Smrg # Add 'dependent.h:' lines. 467bf2eeab3Smrg sed -ne '2,${ 46824047306Smrg s/^ *// 46924047306Smrg s/ \\*$// 47024047306Smrg s/$/:/ 47124047306Smrg p 47224047306Smrg }' "$tmpdepfile" >> "$depfile" 473bf2eeab3Smrg else 47424047306Smrg make_dummy_depfile 475bf2eeab3Smrg fi 476bf2eeab3Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 477bf2eeab3Smrg ;; 478bf2eeab3Smrg 47914c0a534Smrgtru64) 48024047306Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48124047306Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48224047306Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48324047306Smrg # dependencies in 'foo.d' instead, so we check for that too. 48424047306Smrg # Subdirectories are respected. 48524047306Smrg set_dir_from "$object" 48624047306Smrg set_base_from "$object" 48724047306Smrg 48824047306Smrg if test "$libtool" = yes; then 48924047306Smrg # Libtool generates 2 separate objects for the 2 libraries. These 49024047306Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49124047306Smrg # in $dir$base.o.d. We have to check for both files, because 49224047306Smrg # one of the two compilations can be disabled. We should prefer 49324047306Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49424047306Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49524047306Smrg # the former would cause a distcleancheck panic. 49624047306Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49724047306Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49824047306Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49924047306Smrg "$@" -Wc,-MD 50024047306Smrg else 50124047306Smrg tmpdepfile1=$dir$base.d 50224047306Smrg tmpdepfile2=$dir$base.d 50324047306Smrg tmpdepfile3=$dir$base.d 50424047306Smrg "$@" -MD 50524047306Smrg fi 50624047306Smrg 50724047306Smrg stat=$? 50824047306Smrg if test $stat -ne 0; then 50924047306Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51024047306Smrg exit $stat 51124047306Smrg fi 51224047306Smrg 51324047306Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51424047306Smrg do 51524047306Smrg test -f "$tmpdepfile" && break 51624047306Smrg done 51724047306Smrg # Same post-processing that is required for AIX mode. 51824047306Smrg aix_post_process_depfile 51924047306Smrg ;; 52024047306Smrg 52124047306Smrgmsvc7) 52224047306Smrg if test "$libtool" = yes; then 52324047306Smrg showIncludes=-Wc,-showIncludes 52424047306Smrg else 52524047306Smrg showIncludes=-showIncludes 52624047306Smrg fi 52724047306Smrg "$@" $showIncludes > "$tmpdepfile" 52824047306Smrg stat=$? 52924047306Smrg grep -v '^Note: including file: ' "$tmpdepfile" 53024047306Smrg if test $stat -ne 0; then 53124047306Smrg rm -f "$tmpdepfile" 53224047306Smrg exit $stat 53324047306Smrg fi 53424047306Smrg rm -f "$depfile" 53524047306Smrg echo "$object : \\" > "$depfile" 53624047306Smrg # The first sed program below extracts the file names and escapes 53724047306Smrg # backslashes for cygpath. The second sed program outputs the file 53824047306Smrg # name when reading, but also accumulates all include files in the 53924047306Smrg # hold buffer in order to output them again at the end. This only 54024047306Smrg # works with sed implementations that can handle large buffers. 54124047306Smrg sed < "$tmpdepfile" -n ' 54224047306Smrg/^Note: including file: *\(.*\)/ { 54324047306Smrg s//\1/ 54424047306Smrg s/\\/\\\\/g 54524047306Smrg p 54624047306Smrg}' | $cygpath_u | sort -u | sed -n ' 54724047306Smrgs/ /\\ /g 54824047306Smrgs/\(.*\)/'"$tab"'\1 \\/p 54924047306Smrgs/.\(.*\) \\/\1:/ 55024047306SmrgH 55124047306Smrg$ { 55224047306Smrg s/.*/'"$tab"'/ 55324047306Smrg G 55424047306Smrg p 55524047306Smrg}' >> "$depfile" 55624047306Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55724047306Smrg rm -f "$tmpdepfile" 55824047306Smrg ;; 55924047306Smrg 56024047306Smrgmsvc7msys) 56124047306Smrg # This case exists only to let depend.m4 do its work. It works by 56224047306Smrg # looking at the text of this script. This case will never be run, 56324047306Smrg # since it is checked for above. 56424047306Smrg exit 1 56524047306Smrg ;; 56614c0a534Smrg 56714c0a534Smrg#nosideeffect) 56814c0a534Smrg # This comment above is used by automake to tell side-effect 56914c0a534Smrg # dependency tracking mechanisms from slower ones. 57014c0a534Smrg 57114c0a534Smrgdashmstdout) 57214c0a534Smrg # Important note: in order to support this mode, a compiler *must* 57314c0a534Smrg # always write the preprocessed file to stdout, regardless of -o. 57414c0a534Smrg "$@" || exit $? 57514c0a534Smrg 57614c0a534Smrg # Remove the call to Libtool. 57714c0a534Smrg if test "$libtool" = yes; then 578bf2eeab3Smrg while test "X$1" != 'X--mode=compile'; do 57914c0a534Smrg shift 58014c0a534Smrg done 58114c0a534Smrg shift 58214c0a534Smrg fi 58314c0a534Smrg 58424047306Smrg # Remove '-o $object'. 58514c0a534Smrg IFS=" " 58614c0a534Smrg for arg 58714c0a534Smrg do 58814c0a534Smrg case $arg in 58914c0a534Smrg -o) 59014c0a534Smrg shift 59114c0a534Smrg ;; 59214c0a534Smrg $object) 59314c0a534Smrg shift 59414c0a534Smrg ;; 59514c0a534Smrg *) 59614c0a534Smrg set fnord "$@" "$arg" 59714c0a534Smrg shift # fnord 59814c0a534Smrg shift # $arg 59914c0a534Smrg ;; 60014c0a534Smrg esac 60114c0a534Smrg done 60214c0a534Smrg 60314c0a534Smrg test -z "$dashmflag" && dashmflag=-M 60424047306Smrg # Require at least two characters before searching for ':' 60514c0a534Smrg # in the target name. This is to cope with DOS-style filenames: 60624047306Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 60714c0a534Smrg "$@" $dashmflag | 60824047306Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 60914c0a534Smrg rm -f "$depfile" 61014c0a534Smrg cat < "$tmpdepfile" > "$depfile" 61124047306Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61224047306Smrg # correctly. Breaking it into two sed invocations is a workaround. 61324047306Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61424047306Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61524047306Smrg | sed -e 's/$/ :/' >> "$depfile" 61614c0a534Smrg rm -f "$tmpdepfile" 61714c0a534Smrg ;; 61814c0a534Smrg 61914c0a534SmrgdashXmstdout) 62014c0a534Smrg # This case only exists to satisfy depend.m4. It is never actually 62114c0a534Smrg # run, as this mode is specially recognized in the preamble. 62214c0a534Smrg exit 1 62314c0a534Smrg ;; 62414c0a534Smrg 62514c0a534Smrgmakedepend) 62614c0a534Smrg "$@" || exit $? 62714c0a534Smrg # Remove any Libtool call 62814c0a534Smrg if test "$libtool" = yes; then 629bf2eeab3Smrg while test "X$1" != 'X--mode=compile'; do 63014c0a534Smrg shift 63114c0a534Smrg done 63214c0a534Smrg shift 63314c0a534Smrg fi 63414c0a534Smrg # X makedepend 63514c0a534Smrg shift 636bf2eeab3Smrg cleared=no eat=no 637bf2eeab3Smrg for arg 638bf2eeab3Smrg do 63914c0a534Smrg case $cleared in 64014c0a534Smrg no) 64114c0a534Smrg set ""; shift 64214c0a534Smrg cleared=yes ;; 64314c0a534Smrg esac 644bf2eeab3Smrg if test $eat = yes; then 645bf2eeab3Smrg eat=no 646bf2eeab3Smrg continue 647bf2eeab3Smrg fi 64814c0a534Smrg case "$arg" in 64914c0a534Smrg -D*|-I*) 65014c0a534Smrg set fnord "$@" "$arg"; shift ;; 65114c0a534Smrg # Strip any option that makedepend may not understand. Remove 65214c0a534Smrg # the object too, otherwise makedepend will parse it as a source file. 653bf2eeab3Smrg -arch) 654bf2eeab3Smrg eat=yes ;; 65514c0a534Smrg -*|$object) 65614c0a534Smrg ;; 65714c0a534Smrg *) 65814c0a534Smrg set fnord "$@" "$arg"; shift ;; 65914c0a534Smrg esac 66014c0a534Smrg done 661bf2eeab3Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 66214c0a534Smrg touch "$tmpdepfile" 66314c0a534Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 66414c0a534Smrg rm -f "$depfile" 66524047306Smrg # makedepend may prepend the VPATH from the source file name to the object. 66624047306Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66724047306Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66824047306Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66924047306Smrg # correctly. Breaking it into two sed invocations is a workaround. 67024047306Smrg sed '1,2d' "$tmpdepfile" \ 67124047306Smrg | tr ' ' "$nl" \ 67224047306Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67324047306Smrg | sed -e 's/$/ :/' >> "$depfile" 67414c0a534Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 67514c0a534Smrg ;; 67614c0a534Smrg 67714c0a534Smrgcpp) 67814c0a534Smrg # Important note: in order to support this mode, a compiler *must* 67914c0a534Smrg # always write the preprocessed file to stdout. 68014c0a534Smrg "$@" || exit $? 68114c0a534Smrg 68214c0a534Smrg # Remove the call to Libtool. 68314c0a534Smrg if test "$libtool" = yes; then 684bf2eeab3Smrg while test "X$1" != 'X--mode=compile'; do 68514c0a534Smrg shift 68614c0a534Smrg done 68714c0a534Smrg shift 68814c0a534Smrg fi 68914c0a534Smrg 69024047306Smrg # Remove '-o $object'. 69114c0a534Smrg IFS=" " 69214c0a534Smrg for arg 69314c0a534Smrg do 69414c0a534Smrg case $arg in 69514c0a534Smrg -o) 69614c0a534Smrg shift 69714c0a534Smrg ;; 69814c0a534Smrg $object) 69914c0a534Smrg shift 70014c0a534Smrg ;; 70114c0a534Smrg *) 70214c0a534Smrg set fnord "$@" "$arg" 70314c0a534Smrg shift # fnord 70414c0a534Smrg shift # $arg 70514c0a534Smrg ;; 70614c0a534Smrg esac 70714c0a534Smrg done 70814c0a534Smrg 70924047306Smrg "$@" -E \ 71024047306Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71124047306Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71224047306Smrg | sed '$ s: \\$::' > "$tmpdepfile" 71314c0a534Smrg rm -f "$depfile" 71414c0a534Smrg echo "$object : \\" > "$depfile" 71514c0a534Smrg cat < "$tmpdepfile" >> "$depfile" 71614c0a534Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 71714c0a534Smrg rm -f "$tmpdepfile" 71814c0a534Smrg ;; 71914c0a534Smrg 72014c0a534Smrgmsvisualcpp) 72114c0a534Smrg # Important note: in order to support this mode, a compiler *must* 722bf2eeab3Smrg # always write the preprocessed file to stdout. 72314c0a534Smrg "$@" || exit $? 724bf2eeab3Smrg 725bf2eeab3Smrg # Remove the call to Libtool. 726bf2eeab3Smrg if test "$libtool" = yes; then 727bf2eeab3Smrg while test "X$1" != 'X--mode=compile'; do 728bf2eeab3Smrg shift 729bf2eeab3Smrg done 730bf2eeab3Smrg shift 731bf2eeab3Smrg fi 732bf2eeab3Smrg 73314c0a534Smrg IFS=" " 73414c0a534Smrg for arg 73514c0a534Smrg do 73614c0a534Smrg case "$arg" in 737bf2eeab3Smrg -o) 738bf2eeab3Smrg shift 739bf2eeab3Smrg ;; 740bf2eeab3Smrg $object) 741bf2eeab3Smrg shift 742bf2eeab3Smrg ;; 74314c0a534Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74424047306Smrg set fnord "$@" 74524047306Smrg shift 74624047306Smrg shift 74724047306Smrg ;; 74814c0a534Smrg *) 74924047306Smrg set fnord "$@" "$arg" 75024047306Smrg shift 75124047306Smrg shift 75224047306Smrg ;; 75314c0a534Smrg esac 75414c0a534Smrg done 755bf2eeab3Smrg "$@" -E 2>/dev/null | 756bf2eeab3Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 75714c0a534Smrg rm -f "$depfile" 75814c0a534Smrg echo "$object : \\" > "$depfile" 75924047306Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 76024047306Smrg echo "$tab" >> "$depfile" 761bf2eeab3Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 76214c0a534Smrg rm -f "$tmpdepfile" 76314c0a534Smrg ;; 76414c0a534Smrg 765bf2eeab3Smrgmsvcmsys) 766bf2eeab3Smrg # This case exists only to let depend.m4 do its work. It works by 767bf2eeab3Smrg # looking at the text of this script. This case will never be run, 768bf2eeab3Smrg # since it is checked for above. 769bf2eeab3Smrg exit 1 770bf2eeab3Smrg ;; 771bf2eeab3Smrg 77214c0a534Smrgnone) 77314c0a534Smrg exec "$@" 77414c0a534Smrg ;; 77514c0a534Smrg 77614c0a534Smrg*) 77714c0a534Smrg echo "Unknown depmode $depmode" 1>&2 77814c0a534Smrg exit 1 77914c0a534Smrg ;; 78014c0a534Smrgesac 78114c0a534Smrg 78214c0a534Smrgexit 0 78314c0a534Smrg 78414c0a534Smrg# Local Variables: 78514c0a534Smrg# mode: shell-script 78614c0a534Smrg# sh-indentation: 2 787bdc460c5Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 78814c0a534Smrg# time-stamp-start: "scriptversion=" 78914c0a534Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 790bdc460c5Smrg# time-stamp-time-zone: "UTC0" 791bf2eeab3Smrg# time-stamp-end: "; # UTC" 79214c0a534Smrg# End: 793