Blame depcomp

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