ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# depcomp - compile a program generating dependencies as side-effects
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Copyright (C) 1999-2017 Free Software Foundation, Inc.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# This program is free software; you can redistribute it and/or modify
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# it under the terms of the GNU General Public License as published by
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# the Free Software Foundation; either version 2, or (at your option)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# any later version.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# This program is distributed in the hope that it will be useful,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# but WITHOUT ANY WARRANTY; without even the implied warranty of
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# GNU General Public License for more details.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# You should have received a copy of the GNU General Public License
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# along with this program. If not, see <http://www.gnu.org/licenses/>.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# As a special exception to the GNU General Public License, if you
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# distribute this file as part of a program that contains a
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# configuration script generated by Autoconf, you may include it under
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# the same distribution terms that you use for the rest of that program.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews echo "$0: No command. Try '$0 --help' for more information." 1>&2
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntRun PROGRAMS ARGS to compile a file, generating dependencies
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt tmpdepfile Temporary file to use when outputting dependencies.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "depcomp $scriptversion"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Get the directory component of the given path, and save it in the
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# global variables '$dir'. Note that this directory component will
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# be either empty or ending with a '/' character. This is deliberate.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Get the suffix-stripped basename of the given path, and save it the
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# global variable '$base'.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# If no dependency file was actually created by the compiler invocation,
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# we still have to create a dummy depfile, to avoid errors with the
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Makefile "include basename.Plo" scheme.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Factor out some common post-processing of the generated depfile.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Requires the auxiliary global variable '$tmpdepfile' to be set.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # If the compiler actually managed to produce a dependency file,
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Each line is of the form 'foo.o: dependency.h'.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # which is needed to avoid the deleted-header problem.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt# A tabulation character.
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt# A newline character.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Character ranges might be problematic outside the C locale.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# These definitions help.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntif test -z "$depmode" || test -z "$source" || test -z "$object"; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "depcomp: Variables source, object and depmode must be set" 1>&2
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunttmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Avoid interferences from the environment.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Some modes work just like other modes, but use different flags. We
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# parameterize here, but still list the modes in the big case below,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# to make depend.m4 easier to write. Note that we *cannot* use a case
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# here, because this file can only contain one case statement.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # HP compiler uses -M and no extra arg.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # This is just like dashmstdout with a different argument.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # This is just like msvisualcpp but w/o cygpath translation.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Just convert the backslash-escaped backslashes to single forward
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # slashes to satisfy depend.m4
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # This is just like msvc7 but w/o cygpath translation.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Just convert the backslash-escaped backslashes to single forward
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # slashes to satisfy depend.m4
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## gcc 3 implements dependency tracking that does exactly what
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## we want. Yay! Note: for some reason libtool 1.4 doesn't like
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## it if -MD -MP comes after the -MF stuff. Hmm.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## Unfortunately, FreeBSD c89 acceptance of flags depends upon
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## the command line argument order; so add the flags where they
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## appear in depend2.am. Note that the slowdown incurred here
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## affects only configure: in makefiles, %FASTDEP% shortcuts this.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt shift # fnord
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt shift # $arg
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews## (see the conditional assignment to $gccflag above).
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## There are various ways to get dependency output from gcc. Here's
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## why we pick this rather obscure method:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## - Don't want to use -MD because we'd like the dependencies to end
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## up in a subdir. Having to rename by hand is ugly.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## (We might end up doing this anyway to support other compilers.)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews## -MM, not -M (despite what the docs say). Also, it might not be
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews## supported by the other compilers which use the 'gcc' depmode.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## - Using -M directly means running the compiler twice (even worse
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## than renaming).
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if test -z "$gccflag"; then
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # The second -e expression handles DOS-style file names with drive
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt## This next piece of magic avoids the "deleted header file" problem.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## The problem is that when a header file which appears in a .P file
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## is deleted, the dependency causes make to die (because there is
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## typically no way to rebuild the header). We avoid this by adding
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## dummy dependencies for each header file. Too bad gcc doesn't do
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## this for us directly.
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt## Some versions of gcc put a space before the ':'. On the theory
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## that the space means something, we add a space to the output as
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt## well. hp depmode also adds that space, but also prefixes the VPATH
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt## to the object. Take care to not repeat it in the output.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## Some versions of the HPUX 10.20 sed can't process this invocation
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## correctly. Breaking it into two sed invocations is a workaround.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # This case exists only to let depend.m4 do its work. It works by
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # looking at the text of this script. This case will never be run,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # since it is checked for above.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "$@" "-Wp,-MDupdate,$tmpdepfile"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Clip off the initial element (the dependent). Don't try to be
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # clever and replace this with sed code, as IRIX sed won't handle
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # lines with more than a fixed number of characters (4096 in
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # the IRIX cc adds comments like '#:fec' to the end of the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # dependency line.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # The second pass generates a dummy entry for each header file.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # This case exists only to let depend.m4 do its work. It works by
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # looking at the text of this script. This case will never be run,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # since it is checked for above.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # The C for AIX Compiler uses -M and outputs the dependencies
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # in a .u file. In older versions, this file always lives in the
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # current directory. Also, the AIX compiler puts '$object:' at the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # start of each line; $object doesn't have directory information.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Version 6 uses the directory in both cases.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt test -f "$tmpdepfile" && break
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # FIXME: That version still under development at the moment of writing.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Make that this statement remains true also for stable, released
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # It will wrap lines (doesn't matter whether long or short) with a
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # trailing '\', as in:
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # It will put a trailing '\' even on the last line, and will use leading
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # spaces rather than leading tabs (at least since its commit 0394caf7
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # "Emit spaces for -MD").
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # We have to change lines of the first kind to '$object: \'.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # And for each line of the second kind, we have to emit a 'dep.h:'
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # dummy dependency, to avoid the deleted-header problem.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews## The order of this option in the case statement is important, since the
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews## shell code in configure will try each of these formats in the order
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews## listed in this file. A plain '-MD' option would be understood by many
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews## compilers, so we must ensure this comes after the gcc and icc options.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Portland's C compiler understands '-MD'.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Will always output deps to 'file.d' where file is the root name of the
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # source file under compilation, even if file resides in a subdirectory.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # The object file name does not affect the name of the '.d' file.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # pgcc 10.2 will output
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # and will wrap long lines using '\' :
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Use the source, not the object, to determine the base name, since
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # that's sadly what pgcc will do too.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # For projects that build the same source file twice into different object
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # files, the pgcc approach of using the *source* file root name can cause
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # problems in parallel builds. Use a locking strategy to avoid stomping on
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # the same $tmpdepfile.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews echo '$0: caught signal, cleaning up...' >&2
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # mkdir is a portable test-and-set.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # This process acquired the lock.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Release the lock.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # If the lock is being held by a different process, wait
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # until the winning process is done or we timeout.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews echo "$0: failed to acquire lock after $numtries attempts" >&2
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Each line is of the form `foo.o: dependent.h',
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Do two passes, one to just change these to
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # `$object: dependent.h' and one to simply `dependent.h:'.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Some versions of the HPUX 10.20 sed can't process this invocation
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # correctly. Breaking it into two sed invocations is a workaround.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # The "hp" stanza above does not work with aCC (C++) and HP's ia64
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # compilers, which have integrated preprocessors. The correct option
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # to use with these is +Maked; it writes dependencies to a file named
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # 'foo.d', which lands next to the object file, wherever that
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # happens to be.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Much of this is similar to the tru64 case; see comments there.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt test -f "$tmpdepfile" && break
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if test -f "$tmpdepfile"; then
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # Add 'dependent.h:' lines.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # The Tru64 compiler uses -MD to generate dependencies as a side
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # dependencies in 'foo.d' instead, so we check for that too.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Subdirectories are respected.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Libtool generates 2 separate objects for the 2 libraries. These
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # two compilations output dependencies in $dir.libs/$base.o.d and
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # in $dir$base.o.d. We have to check for both files, because
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # one of the two compilations can be disabled. We should prefer
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # automatically cleaned when .libs/ is deleted, while ignoring
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # the former would cause a distcleancheck panic.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews test -f "$tmpdepfile" && break
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Same post-processing that is required for AIX mode.
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # The first sed program below extracts the file names and escapes
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # backslashes for cygpath. The second sed program outputs the file
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # name when reading, but also accumulates all include files in the
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # hold buffer in order to output them again at the end. This only
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # works with sed implementations that can handle large buffers.
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt/^Note: including file: *\(.*\)/ {
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunts/.\(.*\) \\/\1:/
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews echo >> "$depfile" # make sure the fragment doesn't end with a backslash
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # This case exists only to let depend.m4 do its work. It works by
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # looking at the text of this script. This case will never be run,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # since it is checked for above.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#nosideeffect)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # This comment above is used by automake to tell side-effect
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # dependency tracking mechanisms from slower ones.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Important note: in order to support this mode, a compiler *must*
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # always write the preprocessed file to stdout, regardless of -o.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "$@" || exit $?
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Remove the call to Libtool.
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # Remove '-o $object'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt shift # fnord
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt shift # $arg
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # Require at least two characters before searching for ':'
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # in the target name. This is to cope with DOS-style filenames:
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Some versions of the HPUX 10.20 sed can't process this sed invocation
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # correctly. Breaking it into two sed invocations is a workaround.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # This case only exists to satisfy depend.m4. It is never actually
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # run, as this mode is specially recognized in the preamble.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "$@" || exit $?
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Remove any Libtool call
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # X makedepend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt set ""; shift
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Strip any option that makedepend may not understand. Remove
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # the object too, otherwise makedepend will parse it as a source file.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # makedepend may prepend the VPATH from the source file name to the object.
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # No need to regex-escape $object, excess matching of '.' is harmless.
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # Some versions of the HPUX 10.20 sed can't process the last invocation
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews # correctly. Breaking it into two sed invocations is a workaround.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Important note: in order to support this mode, a compiler *must*
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # always write the preprocessed file to stdout.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "$@" || exit $?
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Remove the call to Libtool.
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt # Remove '-o $object'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt shift # fnord
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt shift # $arg
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Important note: in order to support this mode, a compiler *must*
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # always write the preprocessed file to stdout.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "$@" || exit $?
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Remove the call to Libtool.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # This case exists only to let depend.m4 do its work. It works by
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # looking at the text of this script. This case will never be run,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # since it is checked for above.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Local Variables:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# mode: shell-script
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# sh-indentation: 2
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# eval: (add-hook 'write-file-hooks 'time-stamp)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# time-stamp-start: "scriptversion="
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# time-stamp-format: "%:y-%02m-%02d.%02H"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# time-stamp-time-zone: "UTC0"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# time-stamp-end: "; # UTC"