12007c8b2Snia#! /bin/sh
22007c8b2Snia# depcomp - compile a program generating dependencies as side-effects
32007c8b2Snia
42007c8b2Sniascriptversion=2013-05-30.07; # UTC
52007c8b2Snia
62007c8b2Snia# Copyright (C) 1999-2014 Free Software Foundation, Inc.
72007c8b2Snia
82007c8b2Snia# This program is free software; you can redistribute it and/or modify
92007c8b2Snia# it under the terms of the GNU General Public License as published by
102007c8b2Snia# the Free Software Foundation; either version 2, or (at your option)
112007c8b2Snia# any later version.
122007c8b2Snia
132007c8b2Snia# This program is distributed in the hope that it will be useful,
142007c8b2Snia# but WITHOUT ANY WARRANTY; without even the implied warranty of
152007c8b2Snia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162007c8b2Snia# GNU General Public License for more details.
172007c8b2Snia
182007c8b2Snia# You should have received a copy of the GNU General Public License
192007c8b2Snia# along with this program.  If not, see <http://www.gnu.org/licenses/>.
202007c8b2Snia
212007c8b2Snia# As a special exception to the GNU General Public License, if you
222007c8b2Snia# distribute this file as part of a program that contains a
232007c8b2Snia# configuration script generated by Autoconf, you may include it under
242007c8b2Snia# the same distribution terms that you use for the rest of that program.
252007c8b2Snia
262007c8b2Snia# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
272007c8b2Snia
282007c8b2Sniacase $1 in
292007c8b2Snia  '')
302007c8b2Snia    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
312007c8b2Snia    exit 1;
322007c8b2Snia    ;;
332007c8b2Snia  -h | --h*)
342007c8b2Snia    cat <<\EOF
352007c8b2SniaUsage: depcomp [--help] [--version] PROGRAM [ARGS]
362007c8b2Snia
372007c8b2SniaRun PROGRAMS ARGS to compile a file, generating dependencies
382007c8b2Sniaas side-effects.
392007c8b2Snia
402007c8b2SniaEnvironment variables:
412007c8b2Snia  depmode     Dependency tracking mode.
422007c8b2Snia  source      Source file read by 'PROGRAMS ARGS'.
432007c8b2Snia  object      Object file output by 'PROGRAMS ARGS'.
442007c8b2Snia  DEPDIR      directory where to store dependencies.
452007c8b2Snia  depfile     Dependency file to output.
462007c8b2Snia  tmpdepfile  Temporary file to use when outputting dependencies.
472007c8b2Snia  libtool     Whether libtool is used (yes/no).
482007c8b2Snia
492007c8b2SniaReport bugs to <bug-automake@gnu.org>.
502007c8b2SniaEOF
512007c8b2Snia    exit $?
522007c8b2Snia    ;;
532007c8b2Snia  -v | --v*)
542007c8b2Snia    echo "depcomp $scriptversion"
552007c8b2Snia    exit $?
562007c8b2Snia    ;;
572007c8b2Sniaesac
582007c8b2Snia
592007c8b2Snia# Get the directory component of the given path, and save it in the
602007c8b2Snia# global variables '$dir'.  Note that this directory component will
612007c8b2Snia# be either empty or ending with a '/' character.  This is deliberate.
622007c8b2Sniaset_dir_from ()
632007c8b2Snia{
642007c8b2Snia  case $1 in
652007c8b2Snia    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
662007c8b2Snia      *) dir=;;
672007c8b2Snia  esac
682007c8b2Snia}
692007c8b2Snia
702007c8b2Snia# Get the suffix-stripped basename of the given path, and save it the
712007c8b2Snia# global variable '$base'.
722007c8b2Sniaset_base_from ()
732007c8b2Snia{
742007c8b2Snia  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
752007c8b2Snia}
762007c8b2Snia
772007c8b2Snia# If no dependency file was actually created by the compiler invocation,
782007c8b2Snia# we still have to create a dummy depfile, to avoid errors with the
792007c8b2Snia# Makefile "include basename.Plo" scheme.
802007c8b2Sniamake_dummy_depfile ()
812007c8b2Snia{
822007c8b2Snia  echo "#dummy" > "$depfile"
832007c8b2Snia}
842007c8b2Snia
852007c8b2Snia# Factor out some common post-processing of the generated depfile.
862007c8b2Snia# Requires the auxiliary global variable '$tmpdepfile' to be set.
872007c8b2Sniaaix_post_process_depfile ()
882007c8b2Snia{
892007c8b2Snia  # If the compiler actually managed to produce a dependency file,
902007c8b2Snia  # post-process it.
912007c8b2Snia  if test -f "$tmpdepfile"; then
922007c8b2Snia    # Each line is of the form 'foo.o: dependency.h'.
932007c8b2Snia    # Do two passes, one to just change these to
942007c8b2Snia    #   $object: dependency.h
952007c8b2Snia    # and one to simply output
962007c8b2Snia    #   dependency.h:
972007c8b2Snia    # which is needed to avoid the deleted-header problem.
982007c8b2Snia    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
992007c8b2Snia      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1002007c8b2Snia    } > "$depfile"
1012007c8b2Snia    rm -f "$tmpdepfile"
1022007c8b2Snia  else
1032007c8b2Snia    make_dummy_depfile
1042007c8b2Snia  fi
1052007c8b2Snia}
1062007c8b2Snia
1072007c8b2Snia# A tabulation character.
1082007c8b2Sniatab='	'
1092007c8b2Snia# A newline character.
1102007c8b2Snianl='
1112007c8b2Snia'
1122007c8b2Snia# Character ranges might be problematic outside the C locale.
1132007c8b2Snia# These definitions help.
1142007c8b2Sniaupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1152007c8b2Snialower=abcdefghijklmnopqrstuvwxyz
1162007c8b2Sniadigits=0123456789
1172007c8b2Sniaalpha=${upper}${lower}
1182007c8b2Snia
1192007c8b2Sniaif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1202007c8b2Snia  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1212007c8b2Snia  exit 1
1222007c8b2Sniafi
1232007c8b2Snia
1242007c8b2Snia# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1252007c8b2Sniadepfile=${depfile-`echo "$object" |
1262007c8b2Snia  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1272007c8b2Sniatmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1282007c8b2Snia
1292007c8b2Sniarm -f "$tmpdepfile"
1302007c8b2Snia
1312007c8b2Snia# Avoid interferences from the environment.
1322007c8b2Sniagccflag= dashmflag=
1332007c8b2Snia
1342007c8b2Snia# Some modes work just like other modes, but use different flags.  We
1352007c8b2Snia# parameterize here, but still list the modes in the big case below,
1362007c8b2Snia# to make depend.m4 easier to write.  Note that we *cannot* use a case
1372007c8b2Snia# here, because this file can only contain one case statement.
1382007c8b2Sniaif test "$depmode" = hp; then
1392007c8b2Snia  # HP compiler uses -M and no extra arg.
1402007c8b2Snia  gccflag=-M
1412007c8b2Snia  depmode=gcc
1422007c8b2Sniafi
1432007c8b2Snia
1442007c8b2Sniaif test "$depmode" = dashXmstdout; then
1452007c8b2Snia  # This is just like dashmstdout with a different argument.
1462007c8b2Snia  dashmflag=-xM
1472007c8b2Snia  depmode=dashmstdout
1482007c8b2Sniafi
1492007c8b2Snia
1502007c8b2Sniacygpath_u="cygpath -u -f -"
1512007c8b2Sniaif test "$depmode" = msvcmsys; then
1522007c8b2Snia  # This is just like msvisualcpp but w/o cygpath translation.
1532007c8b2Snia  # Just convert the backslash-escaped backslashes to single forward
1542007c8b2Snia  # slashes to satisfy depend.m4
1552007c8b2Snia  cygpath_u='sed s,\\\\,/,g'
1562007c8b2Snia  depmode=msvisualcpp
1572007c8b2Sniafi
1582007c8b2Snia
1592007c8b2Sniaif test "$depmode" = msvc7msys; then
1602007c8b2Snia  # This is just like msvc7 but w/o cygpath translation.
1612007c8b2Snia  # Just convert the backslash-escaped backslashes to single forward
1622007c8b2Snia  # slashes to satisfy depend.m4
1632007c8b2Snia  cygpath_u='sed s,\\\\,/,g'
1642007c8b2Snia  depmode=msvc7
1652007c8b2Sniafi
1662007c8b2Snia
1672007c8b2Sniaif test "$depmode" = xlc; then
1682007c8b2Snia  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1692007c8b2Snia  gccflag=-qmakedep=gcc,-MF
1702007c8b2Snia  depmode=gcc
1712007c8b2Sniafi
1722007c8b2Snia
1732007c8b2Sniacase "$depmode" in
1742007c8b2Sniagcc3)
1752007c8b2Snia## gcc 3 implements dependency tracking that does exactly what
1762007c8b2Snia## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1772007c8b2Snia## it if -MD -MP comes after the -MF stuff.  Hmm.
1782007c8b2Snia## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1792007c8b2Snia## the command line argument order; so add the flags where they
1802007c8b2Snia## appear in depend2.am.  Note that the slowdown incurred here
1812007c8b2Snia## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1822007c8b2Snia  for arg
1832007c8b2Snia  do
1842007c8b2Snia    case $arg in
1852007c8b2Snia    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1862007c8b2Snia    *)  set fnord "$@" "$arg" ;;
1872007c8b2Snia    esac
1882007c8b2Snia    shift # fnord
1892007c8b2Snia    shift # $arg
1902007c8b2Snia  done
1912007c8b2Snia  "$@"
1922007c8b2Snia  stat=$?
1932007c8b2Snia  if test $stat -ne 0; then
1942007c8b2Snia    rm -f "$tmpdepfile"
1952007c8b2Snia    exit $stat
1962007c8b2Snia  fi
1972007c8b2Snia  mv "$tmpdepfile" "$depfile"
1982007c8b2Snia  ;;
1992007c8b2Snia
2002007c8b2Sniagcc)
2012007c8b2Snia## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2022007c8b2Snia## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2032007c8b2Snia## (see the conditional assignment to $gccflag above).
2042007c8b2Snia## There are various ways to get dependency output from gcc.  Here's
2052007c8b2Snia## why we pick this rather obscure method:
2062007c8b2Snia## - Don't want to use -MD because we'd like the dependencies to end
2072007c8b2Snia##   up in a subdir.  Having to rename by hand is ugly.
2082007c8b2Snia##   (We might end up doing this anyway to support other compilers.)
2092007c8b2Snia## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2102007c8b2Snia##   -MM, not -M (despite what the docs say).  Also, it might not be
2112007c8b2Snia##   supported by the other compilers which use the 'gcc' depmode.
2122007c8b2Snia## - Using -M directly means running the compiler twice (even worse
2132007c8b2Snia##   than renaming).
2142007c8b2Snia  if test -z "$gccflag"; then
2152007c8b2Snia    gccflag=-MD,
2162007c8b2Snia  fi
2172007c8b2Snia  "$@" -Wp,"$gccflag$tmpdepfile"
2182007c8b2Snia  stat=$?
2192007c8b2Snia  if test $stat -ne 0; then
2202007c8b2Snia    rm -f "$tmpdepfile"
2212007c8b2Snia    exit $stat
2222007c8b2Snia  fi
2232007c8b2Snia  rm -f "$depfile"
2242007c8b2Snia  echo "$object : \\" > "$depfile"
2252007c8b2Snia  # The second -e expression handles DOS-style file names with drive
2262007c8b2Snia  # letters.
2272007c8b2Snia  sed -e 's/^[^:]*: / /' \
2282007c8b2Snia      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2292007c8b2Snia## This next piece of magic avoids the "deleted header file" problem.
2302007c8b2Snia## The problem is that when a header file which appears in a .P file
2312007c8b2Snia## is deleted, the dependency causes make to die (because there is
2322007c8b2Snia## typically no way to rebuild the header).  We avoid this by adding
2332007c8b2Snia## dummy dependencies for each header file.  Too bad gcc doesn't do
2342007c8b2Snia## this for us directly.
2352007c8b2Snia## Some versions of gcc put a space before the ':'.  On the theory
2362007c8b2Snia## that the space means something, we add a space to the output as
2372007c8b2Snia## well.  hp depmode also adds that space, but also prefixes the VPATH
2382007c8b2Snia## to the object.  Take care to not repeat it in the output.
2392007c8b2Snia## Some versions of the HPUX 10.20 sed can't process this invocation
2402007c8b2Snia## correctly.  Breaking it into two sed invocations is a workaround.
2412007c8b2Snia  tr ' ' "$nl" < "$tmpdepfile" \
2422007c8b2Snia    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2432007c8b2Snia    | sed -e 's/$/ :/' >> "$depfile"
2442007c8b2Snia  rm -f "$tmpdepfile"
2452007c8b2Snia  ;;
2462007c8b2Snia
2472007c8b2Sniahp)
2482007c8b2Snia  # This case exists only to let depend.m4 do its work.  It works by
2492007c8b2Snia  # looking at the text of this script.  This case will never be run,
2502007c8b2Snia  # since it is checked for above.
2512007c8b2Snia  exit 1
2522007c8b2Snia  ;;
2532007c8b2Snia
2542007c8b2Sniasgi)
2552007c8b2Snia  if test "$libtool" = yes; then
2562007c8b2Snia    "$@" "-Wp,-MDupdate,$tmpdepfile"
2572007c8b2Snia  else
2582007c8b2Snia    "$@" -MDupdate "$tmpdepfile"
2592007c8b2Snia  fi
2602007c8b2Snia  stat=$?
2612007c8b2Snia  if test $stat -ne 0; then
2622007c8b2Snia    rm -f "$tmpdepfile"
2632007c8b2Snia    exit $stat
2642007c8b2Snia  fi
2652007c8b2Snia  rm -f "$depfile"
2662007c8b2Snia
2672007c8b2Snia  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2682007c8b2Snia    echo "$object : \\" > "$depfile"
2692007c8b2Snia    # Clip off the initial element (the dependent).  Don't try to be
2702007c8b2Snia    # clever and replace this with sed code, as IRIX sed won't handle
2712007c8b2Snia    # lines with more than a fixed number of characters (4096 in
2722007c8b2Snia    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2732007c8b2Snia    # the IRIX cc adds comments like '#:fec' to the end of the
2742007c8b2Snia    # dependency line.
2752007c8b2Snia    tr ' ' "$nl" < "$tmpdepfile" \
2762007c8b2Snia      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2772007c8b2Snia      | tr "$nl" ' ' >> "$depfile"
2782007c8b2Snia    echo >> "$depfile"
2792007c8b2Snia    # The second pass generates a dummy entry for each header file.
2802007c8b2Snia    tr ' ' "$nl" < "$tmpdepfile" \
2812007c8b2Snia      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2822007c8b2Snia      >> "$depfile"
2832007c8b2Snia  else
2842007c8b2Snia    make_dummy_depfile
2852007c8b2Snia  fi
2862007c8b2Snia  rm -f "$tmpdepfile"
2872007c8b2Snia  ;;
2882007c8b2Snia
2892007c8b2Sniaxlc)
2902007c8b2Snia  # This case exists only to let depend.m4 do its work.  It works by
2912007c8b2Snia  # looking at the text of this script.  This case will never be run,
2922007c8b2Snia  # since it is checked for above.
2932007c8b2Snia  exit 1
2942007c8b2Snia  ;;
2952007c8b2Snia
2962007c8b2Sniaaix)
2972007c8b2Snia  # The C for AIX Compiler uses -M and outputs the dependencies
2982007c8b2Snia  # in a .u file.  In older versions, this file always lives in the
2992007c8b2Snia  # current directory.  Also, the AIX compiler puts '$object:' at the
3002007c8b2Snia  # start of each line; $object doesn't have directory information.
3012007c8b2Snia  # Version 6 uses the directory in both cases.
3022007c8b2Snia  set_dir_from "$object"
3032007c8b2Snia  set_base_from "$object"
3042007c8b2Snia  if test "$libtool" = yes; then
3052007c8b2Snia    tmpdepfile1=$dir$base.u
3062007c8b2Snia    tmpdepfile2=$base.u
3072007c8b2Snia    tmpdepfile3=$dir.libs/$base.u
3082007c8b2Snia    "$@" -Wc,-M
3092007c8b2Snia  else
3102007c8b2Snia    tmpdepfile1=$dir$base.u
3112007c8b2Snia    tmpdepfile2=$dir$base.u
3122007c8b2Snia    tmpdepfile3=$dir$base.u
3132007c8b2Snia    "$@" -M
3142007c8b2Snia  fi
3152007c8b2Snia  stat=$?
3162007c8b2Snia  if test $stat -ne 0; then
3172007c8b2Snia    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3182007c8b2Snia    exit $stat
3192007c8b2Snia  fi
3202007c8b2Snia
3212007c8b2Snia  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3222007c8b2Snia  do
3232007c8b2Snia    test -f "$tmpdepfile" && break
3242007c8b2Snia  done
3252007c8b2Snia  aix_post_process_depfile
3262007c8b2Snia  ;;
3272007c8b2Snia
3282007c8b2Sniatcc)
3292007c8b2Snia  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3302007c8b2Snia  # FIXME: That version still under development at the moment of writing.
3312007c8b2Snia  #        Make that this statement remains true also for stable, released
3322007c8b2Snia  #        versions.
3332007c8b2Snia  # It will wrap lines (doesn't matter whether long or short) with a
3342007c8b2Snia  # trailing '\', as in:
3352007c8b2Snia  #
3362007c8b2Snia  #   foo.o : \
3372007c8b2Snia  #    foo.c \
3382007c8b2Snia  #    foo.h \
3392007c8b2Snia  #
3402007c8b2Snia  # It will put a trailing '\' even on the last line, and will use leading
3412007c8b2Snia  # spaces rather than leading tabs (at least since its commit 0394caf7
3422007c8b2Snia  # "Emit spaces for -MD").
3432007c8b2Snia  "$@" -MD -MF "$tmpdepfile"
3442007c8b2Snia  stat=$?
3452007c8b2Snia  if test $stat -ne 0; then
3462007c8b2Snia    rm -f "$tmpdepfile"
3472007c8b2Snia    exit $stat
3482007c8b2Snia  fi
3492007c8b2Snia  rm -f "$depfile"
3502007c8b2Snia  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3512007c8b2Snia  # We have to change lines of the first kind to '$object: \'.
3522007c8b2Snia  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3532007c8b2Snia  # And for each line of the second kind, we have to emit a 'dep.h:'
3542007c8b2Snia  # dummy dependency, to avoid the deleted-header problem.
3552007c8b2Snia  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3562007c8b2Snia  rm -f "$tmpdepfile"
3572007c8b2Snia  ;;
3582007c8b2Snia
3592007c8b2Snia## The order of this option in the case statement is important, since the
3602007c8b2Snia## shell code in configure will try each of these formats in the order
3612007c8b2Snia## listed in this file.  A plain '-MD' option would be understood by many
3622007c8b2Snia## compilers, so we must ensure this comes after the gcc and icc options.
3632007c8b2Sniapgcc)
3642007c8b2Snia  # Portland's C compiler understands '-MD'.
3652007c8b2Snia  # Will always output deps to 'file.d' where file is the root name of the
3662007c8b2Snia  # source file under compilation, even if file resides in a subdirectory.
3672007c8b2Snia  # The object file name does not affect the name of the '.d' file.
3682007c8b2Snia  # pgcc 10.2 will output
3692007c8b2Snia  #    foo.o: sub/foo.c sub/foo.h
3702007c8b2Snia  # and will wrap long lines using '\' :
3712007c8b2Snia  #    foo.o: sub/foo.c ... \
3722007c8b2Snia  #     sub/foo.h ... \
3732007c8b2Snia  #     ...
3742007c8b2Snia  set_dir_from "$object"
3752007c8b2Snia  # Use the source, not the object, to determine the base name, since
3762007c8b2Snia  # that's sadly what pgcc will do too.
3772007c8b2Snia  set_base_from "$source"
3782007c8b2Snia  tmpdepfile=$base.d
3792007c8b2Snia
3802007c8b2Snia  # For projects that build the same source file twice into different object
3812007c8b2Snia  # files, the pgcc approach of using the *source* file root name can cause
3822007c8b2Snia  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3832007c8b2Snia  # the same $tmpdepfile.
3842007c8b2Snia  lockdir=$base.d-lock
3852007c8b2Snia  trap "
3862007c8b2Snia    echo '$0: caught signal, cleaning up...' >&2
3872007c8b2Snia    rmdir '$lockdir'
3882007c8b2Snia    exit 1
3892007c8b2Snia  " 1 2 13 15
3902007c8b2Snia  numtries=100
3912007c8b2Snia  i=$numtries
3922007c8b2Snia  while test $i -gt 0; do
3932007c8b2Snia    # mkdir is a portable test-and-set.
3942007c8b2Snia    if mkdir "$lockdir" 2>/dev/null; then
3952007c8b2Snia      # This process acquired the lock.
3962007c8b2Snia      "$@" -MD
3972007c8b2Snia      stat=$?
3982007c8b2Snia      # Release the lock.
3992007c8b2Snia      rmdir "$lockdir"
4002007c8b2Snia      break
4012007c8b2Snia    else
4022007c8b2Snia      # If the lock is being held by a different process, wait
4032007c8b2Snia      # until the winning process is done or we timeout.
4042007c8b2Snia      while test -d "$lockdir" && test $i -gt 0; do
4052007c8b2Snia        sleep 1
4062007c8b2Snia        i=`expr $i - 1`
4072007c8b2Snia      done
4082007c8b2Snia    fi
4092007c8b2Snia    i=`expr $i - 1`
4102007c8b2Snia  done
4112007c8b2Snia  trap - 1 2 13 15
4122007c8b2Snia  if test $i -le 0; then
4132007c8b2Snia    echo "$0: failed to acquire lock after $numtries attempts" >&2
4142007c8b2Snia    echo "$0: check lockdir '$lockdir'" >&2
4152007c8b2Snia    exit 1
4162007c8b2Snia  fi
4172007c8b2Snia
4182007c8b2Snia  if test $stat -ne 0; then
4192007c8b2Snia    rm -f "$tmpdepfile"
4202007c8b2Snia    exit $stat
4212007c8b2Snia  fi
4222007c8b2Snia  rm -f "$depfile"
4232007c8b2Snia  # Each line is of the form `foo.o: dependent.h',
4242007c8b2Snia  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4252007c8b2Snia  # Do two passes, one to just change these to
4262007c8b2Snia  # `$object: dependent.h' and one to simply `dependent.h:'.
4272007c8b2Snia  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4282007c8b2Snia  # Some versions of the HPUX 10.20 sed can't process this invocation
4292007c8b2Snia  # correctly.  Breaking it into two sed invocations is a workaround.
4302007c8b2Snia  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4312007c8b2Snia    | sed -e 's/$/ :/' >> "$depfile"
4322007c8b2Snia  rm -f "$tmpdepfile"
4332007c8b2Snia  ;;
4342007c8b2Snia
4352007c8b2Sniahp2)
4362007c8b2Snia  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4372007c8b2Snia  # compilers, which have integrated preprocessors.  The correct option
4382007c8b2Snia  # to use with these is +Maked; it writes dependencies to a file named
4392007c8b2Snia  # 'foo.d', which lands next to the object file, wherever that
4402007c8b2Snia  # happens to be.
4412007c8b2Snia  # Much of this is similar to the tru64 case; see comments there.
4422007c8b2Snia  set_dir_from  "$object"
4432007c8b2Snia  set_base_from "$object"
4442007c8b2Snia  if test "$libtool" = yes; then
4452007c8b2Snia    tmpdepfile1=$dir$base.d
4462007c8b2Snia    tmpdepfile2=$dir.libs/$base.d
4472007c8b2Snia    "$@" -Wc,+Maked
4482007c8b2Snia  else
4492007c8b2Snia    tmpdepfile1=$dir$base.d
4502007c8b2Snia    tmpdepfile2=$dir$base.d
4512007c8b2Snia    "$@" +Maked
4522007c8b2Snia  fi
4532007c8b2Snia  stat=$?
4542007c8b2Snia  if test $stat -ne 0; then
4552007c8b2Snia     rm -f "$tmpdepfile1" "$tmpdepfile2"
4562007c8b2Snia     exit $stat
4572007c8b2Snia  fi
4582007c8b2Snia
4592007c8b2Snia  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4602007c8b2Snia  do
4612007c8b2Snia    test -f "$tmpdepfile" && break
4622007c8b2Snia  done
4632007c8b2Snia  if test -f "$tmpdepfile"; then
4642007c8b2Snia    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4652007c8b2Snia    # Add 'dependent.h:' lines.
4662007c8b2Snia    sed -ne '2,${
4672007c8b2Snia               s/^ *//
4682007c8b2Snia               s/ \\*$//
4692007c8b2Snia               s/$/:/
4702007c8b2Snia               p
4712007c8b2Snia             }' "$tmpdepfile" >> "$depfile"
4722007c8b2Snia  else
4732007c8b2Snia    make_dummy_depfile
4742007c8b2Snia  fi
4752007c8b2Snia  rm -f "$tmpdepfile" "$tmpdepfile2"
4762007c8b2Snia  ;;
4772007c8b2Snia
4782007c8b2Sniatru64)
4792007c8b2Snia  # The Tru64 compiler uses -MD to generate dependencies as a side
4802007c8b2Snia  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4812007c8b2Snia  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4822007c8b2Snia  # dependencies in 'foo.d' instead, so we check for that too.
4832007c8b2Snia  # Subdirectories are respected.
4842007c8b2Snia  set_dir_from  "$object"
4852007c8b2Snia  set_base_from "$object"
4862007c8b2Snia
4872007c8b2Snia  if test "$libtool" = yes; then
4882007c8b2Snia    # Libtool generates 2 separate objects for the 2 libraries.  These
4892007c8b2Snia    # two compilations output dependencies in $dir.libs/$base.o.d and
4902007c8b2Snia    # in $dir$base.o.d.  We have to check for both files, because
4912007c8b2Snia    # one of the two compilations can be disabled.  We should prefer
4922007c8b2Snia    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4932007c8b2Snia    # automatically cleaned when .libs/ is deleted, while ignoring
4942007c8b2Snia    # the former would cause a distcleancheck panic.
4952007c8b2Snia    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4962007c8b2Snia    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4972007c8b2Snia    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4982007c8b2Snia    "$@" -Wc,-MD
4992007c8b2Snia  else
5002007c8b2Snia    tmpdepfile1=$dir$base.d
5012007c8b2Snia    tmpdepfile2=$dir$base.d
5022007c8b2Snia    tmpdepfile3=$dir$base.d
5032007c8b2Snia    "$@" -MD
5042007c8b2Snia  fi
5052007c8b2Snia
5062007c8b2Snia  stat=$?
5072007c8b2Snia  if test $stat -ne 0; then
5082007c8b2Snia    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5092007c8b2Snia    exit $stat
5102007c8b2Snia  fi
5112007c8b2Snia
5122007c8b2Snia  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5132007c8b2Snia  do
5142007c8b2Snia    test -f "$tmpdepfile" && break
5152007c8b2Snia  done
5162007c8b2Snia  # Same post-processing that is required for AIX mode.
5172007c8b2Snia  aix_post_process_depfile
5182007c8b2Snia  ;;
5192007c8b2Snia
5202007c8b2Sniamsvc7)
5212007c8b2Snia  if test "$libtool" = yes; then
5222007c8b2Snia    showIncludes=-Wc,-showIncludes
5232007c8b2Snia  else
5242007c8b2Snia    showIncludes=-showIncludes
5252007c8b2Snia  fi
5262007c8b2Snia  "$@" $showIncludes > "$tmpdepfile"
5272007c8b2Snia  stat=$?
5282007c8b2Snia  grep -v '^Note: including file: ' "$tmpdepfile"
5292007c8b2Snia  if test $stat -ne 0; then
5302007c8b2Snia    rm -f "$tmpdepfile"
5312007c8b2Snia    exit $stat
5322007c8b2Snia  fi
5332007c8b2Snia  rm -f "$depfile"
5342007c8b2Snia  echo "$object : \\" > "$depfile"
5352007c8b2Snia  # The first sed program below extracts the file names and escapes
5362007c8b2Snia  # backslashes for cygpath.  The second sed program outputs the file
5372007c8b2Snia  # name when reading, but also accumulates all include files in the
5382007c8b2Snia  # hold buffer in order to output them again at the end.  This only
5392007c8b2Snia  # works with sed implementations that can handle large buffers.
5402007c8b2Snia  sed < "$tmpdepfile" -n '
5412007c8b2Snia/^Note: including file:  *\(.*\)/ {
5422007c8b2Snia  s//\1/
5432007c8b2Snia  s/\\/\\\\/g
5442007c8b2Snia  p
5452007c8b2Snia}' | $cygpath_u | sort -u | sed -n '
5462007c8b2Snias/ /\\ /g
5472007c8b2Snias/\(.*\)/'"$tab"'\1 \\/p
5482007c8b2Snias/.\(.*\) \\/\1:/
5492007c8b2SniaH
5502007c8b2Snia$ {
5512007c8b2Snia  s/.*/'"$tab"'/
5522007c8b2Snia  G
5532007c8b2Snia  p
5542007c8b2Snia}' >> "$depfile"
5552007c8b2Snia  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5562007c8b2Snia  rm -f "$tmpdepfile"
5572007c8b2Snia  ;;
5582007c8b2Snia
5592007c8b2Sniamsvc7msys)
5602007c8b2Snia  # This case exists only to let depend.m4 do its work.  It works by
5612007c8b2Snia  # looking at the text of this script.  This case will never be run,
5622007c8b2Snia  # since it is checked for above.
5632007c8b2Snia  exit 1
5642007c8b2Snia  ;;
5652007c8b2Snia
5662007c8b2Snia#nosideeffect)
5672007c8b2Snia  # This comment above is used by automake to tell side-effect
5682007c8b2Snia  # dependency tracking mechanisms from slower ones.
5692007c8b2Snia
5702007c8b2Sniadashmstdout)
5712007c8b2Snia  # Important note: in order to support this mode, a compiler *must*
5722007c8b2Snia  # always write the preprocessed file to stdout, regardless of -o.
5732007c8b2Snia  "$@" || exit $?
5742007c8b2Snia
5752007c8b2Snia  # Remove the call to Libtool.
5762007c8b2Snia  if test "$libtool" = yes; then
5772007c8b2Snia    while test "X$1" != 'X--mode=compile'; do
5782007c8b2Snia      shift
5792007c8b2Snia    done
5802007c8b2Snia    shift
5812007c8b2Snia  fi
5822007c8b2Snia
5832007c8b2Snia  # Remove '-o $object'.
5842007c8b2Snia  IFS=" "
5852007c8b2Snia  for arg
5862007c8b2Snia  do
5872007c8b2Snia    case $arg in
5882007c8b2Snia    -o)
5892007c8b2Snia      shift
5902007c8b2Snia      ;;
5912007c8b2Snia    $object)
5922007c8b2Snia      shift
5932007c8b2Snia      ;;
5942007c8b2Snia    *)
5952007c8b2Snia      set fnord "$@" "$arg"
5962007c8b2Snia      shift # fnord
5972007c8b2Snia      shift # $arg
5982007c8b2Snia      ;;
5992007c8b2Snia    esac
6002007c8b2Snia  done
6012007c8b2Snia
6022007c8b2Snia  test -z "$dashmflag" && dashmflag=-M
6032007c8b2Snia  # Require at least two characters before searching for ':'
6042007c8b2Snia  # in the target name.  This is to cope with DOS-style filenames:
6052007c8b2Snia  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6062007c8b2Snia  "$@" $dashmflag |
6072007c8b2Snia    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6082007c8b2Snia  rm -f "$depfile"
6092007c8b2Snia  cat < "$tmpdepfile" > "$depfile"
6102007c8b2Snia  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6112007c8b2Snia  # correctly.  Breaking it into two sed invocations is a workaround.
6122007c8b2Snia  tr ' ' "$nl" < "$tmpdepfile" \
6132007c8b2Snia    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6142007c8b2Snia    | sed -e 's/$/ :/' >> "$depfile"
6152007c8b2Snia  rm -f "$tmpdepfile"
6162007c8b2Snia  ;;
6172007c8b2Snia
6182007c8b2SniadashXmstdout)
6192007c8b2Snia  # This case only exists to satisfy depend.m4.  It is never actually
6202007c8b2Snia  # run, as this mode is specially recognized in the preamble.
6212007c8b2Snia  exit 1
6222007c8b2Snia  ;;
6232007c8b2Snia
6242007c8b2Sniamakedepend)
6252007c8b2Snia  "$@" || exit $?
6262007c8b2Snia  # Remove any Libtool call
6272007c8b2Snia  if test "$libtool" = yes; then
6282007c8b2Snia    while test "X$1" != 'X--mode=compile'; do
6292007c8b2Snia      shift
6302007c8b2Snia    done
6312007c8b2Snia    shift
6322007c8b2Snia  fi
6332007c8b2Snia  # X makedepend
6342007c8b2Snia  shift
6352007c8b2Snia  cleared=no eat=no
6362007c8b2Snia  for arg
6372007c8b2Snia  do
6382007c8b2Snia    case $cleared in
6392007c8b2Snia    no)
6402007c8b2Snia      set ""; shift
6412007c8b2Snia      cleared=yes ;;
6422007c8b2Snia    esac
6432007c8b2Snia    if test $eat = yes; then
6442007c8b2Snia      eat=no
6452007c8b2Snia      continue
6462007c8b2Snia    fi
6472007c8b2Snia    case "$arg" in
6482007c8b2Snia    -D*|-I*)
6492007c8b2Snia      set fnord "$@" "$arg"; shift ;;
6502007c8b2Snia    # Strip any option that makedepend may not understand.  Remove
6512007c8b2Snia    # the object too, otherwise makedepend will parse it as a source file.
6522007c8b2Snia    -arch)
6532007c8b2Snia      eat=yes ;;
6542007c8b2Snia    -*|$object)
6552007c8b2Snia      ;;
6562007c8b2Snia    *)
6572007c8b2Snia      set fnord "$@" "$arg"; shift ;;
6582007c8b2Snia    esac
6592007c8b2Snia  done
6602007c8b2Snia  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6612007c8b2Snia  touch "$tmpdepfile"
6622007c8b2Snia  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6632007c8b2Snia  rm -f "$depfile"
6642007c8b2Snia  # makedepend may prepend the VPATH from the source file name to the object.
6652007c8b2Snia  # No need to regex-escape $object, excess matching of '.' is harmless.
6662007c8b2Snia  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6672007c8b2Snia  # Some versions of the HPUX 10.20 sed can't process the last invocation
6682007c8b2Snia  # correctly.  Breaking it into two sed invocations is a workaround.
6692007c8b2Snia  sed '1,2d' "$tmpdepfile" \
6702007c8b2Snia    | tr ' ' "$nl" \
6712007c8b2Snia    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6722007c8b2Snia    | sed -e 's/$/ :/' >> "$depfile"
6732007c8b2Snia  rm -f "$tmpdepfile" "$tmpdepfile".bak
6742007c8b2Snia  ;;
6752007c8b2Snia
6762007c8b2Sniacpp)
6772007c8b2Snia  # Important note: in order to support this mode, a compiler *must*
6782007c8b2Snia  # always write the preprocessed file to stdout.
6792007c8b2Snia  "$@" || exit $?
6802007c8b2Snia
6812007c8b2Snia  # Remove the call to Libtool.
6822007c8b2Snia  if test "$libtool" = yes; then
6832007c8b2Snia    while test "X$1" != 'X--mode=compile'; do
6842007c8b2Snia      shift
6852007c8b2Snia    done
6862007c8b2Snia    shift
6872007c8b2Snia  fi
6882007c8b2Snia
6892007c8b2Snia  # Remove '-o $object'.
6902007c8b2Snia  IFS=" "
6912007c8b2Snia  for arg
6922007c8b2Snia  do
6932007c8b2Snia    case $arg in
6942007c8b2Snia    -o)
6952007c8b2Snia      shift
6962007c8b2Snia      ;;
6972007c8b2Snia    $object)
6982007c8b2Snia      shift
6992007c8b2Snia      ;;
7002007c8b2Snia    *)
7012007c8b2Snia      set fnord "$@" "$arg"
7022007c8b2Snia      shift # fnord
7032007c8b2Snia      shift # $arg
7042007c8b2Snia      ;;
7052007c8b2Snia    esac
7062007c8b2Snia  done
7072007c8b2Snia
7082007c8b2Snia  "$@" -E \
7092007c8b2Snia    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7102007c8b2Snia             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7112007c8b2Snia    | sed '$ s: \\$::' > "$tmpdepfile"
7122007c8b2Snia  rm -f "$depfile"
7132007c8b2Snia  echo "$object : \\" > "$depfile"
7142007c8b2Snia  cat < "$tmpdepfile" >> "$depfile"
7152007c8b2Snia  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7162007c8b2Snia  rm -f "$tmpdepfile"
7172007c8b2Snia  ;;
7182007c8b2Snia
7192007c8b2Sniamsvisualcpp)
7202007c8b2Snia  # Important note: in order to support this mode, a compiler *must*
7212007c8b2Snia  # always write the preprocessed file to stdout.
7222007c8b2Snia  "$@" || exit $?
7232007c8b2Snia
7242007c8b2Snia  # Remove the call to Libtool.
7252007c8b2Snia  if test "$libtool" = yes; then
7262007c8b2Snia    while test "X$1" != 'X--mode=compile'; do
7272007c8b2Snia      shift
7282007c8b2Snia    done
7292007c8b2Snia    shift
7302007c8b2Snia  fi
7312007c8b2Snia
7322007c8b2Snia  IFS=" "
7332007c8b2Snia  for arg
7342007c8b2Snia  do
7352007c8b2Snia    case "$arg" in
7362007c8b2Snia    -o)
7372007c8b2Snia      shift
7382007c8b2Snia      ;;
7392007c8b2Snia    $object)
7402007c8b2Snia      shift
7412007c8b2Snia      ;;
7422007c8b2Snia    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7432007c8b2Snia        set fnord "$@"
7442007c8b2Snia        shift
7452007c8b2Snia        shift
7462007c8b2Snia        ;;
7472007c8b2Snia    *)
7482007c8b2Snia        set fnord "$@" "$arg"
7492007c8b2Snia        shift
7502007c8b2Snia        shift
7512007c8b2Snia        ;;
7522007c8b2Snia    esac
7532007c8b2Snia  done
7542007c8b2Snia  "$@" -E 2>/dev/null |
7552007c8b2Snia  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7562007c8b2Snia  rm -f "$depfile"
7572007c8b2Snia  echo "$object : \\" > "$depfile"
7582007c8b2Snia  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7592007c8b2Snia  echo "$tab" >> "$depfile"
7602007c8b2Snia  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7612007c8b2Snia  rm -f "$tmpdepfile"
7622007c8b2Snia  ;;
7632007c8b2Snia
7642007c8b2Sniamsvcmsys)
7652007c8b2Snia  # This case exists only to let depend.m4 do its work.  It works by
7662007c8b2Snia  # looking at the text of this script.  This case will never be run,
7672007c8b2Snia  # since it is checked for above.
7682007c8b2Snia  exit 1
7692007c8b2Snia  ;;
7702007c8b2Snia
7712007c8b2Snianone)
7722007c8b2Snia  exec "$@"
7732007c8b2Snia  ;;
7742007c8b2Snia
7752007c8b2Snia*)
7762007c8b2Snia  echo "Unknown depmode $depmode" 1>&2
7772007c8b2Snia  exit 1
7782007c8b2Snia  ;;
7792007c8b2Sniaesac
7802007c8b2Snia
7812007c8b2Sniaexit 0
7822007c8b2Snia
7832007c8b2Snia# Local Variables:
7842007c8b2Snia# mode: shell-script
7852007c8b2Snia# sh-indentation: 2
7862007c8b2Snia# eval: (add-hook 'write-file-hooks 'time-stamp)
7872007c8b2Snia# time-stamp-start: "scriptversion="
7882007c8b2Snia# time-stamp-format: "%:y-%02m-%02d.%02H"
7892007c8b2Snia# time-stamp-time-zone: "UTC"
7902007c8b2Snia# time-stamp-end: "; # UTC"
7912007c8b2Snia# End:
792