Blame depcomp

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