depcomp revision 7322289d
11d54945dSmrg#! /bin/sh
21d54945dSmrg# depcomp - compile a program generating dependencies as side-effects
31d54945dSmrg
47322289dSmrgscriptversion=2013-05-30.07; # UTC
51d54945dSmrg
67322289dSmrg# Copyright (C) 1999-2014 Free Software Foundation, Inc.
71d54945dSmrg
81d54945dSmrg# This program is free software; you can redistribute it and/or modify
91d54945dSmrg# it under the terms of the GNU General Public License as published by
101d54945dSmrg# the Free Software Foundation; either version 2, or (at your option)
111d54945dSmrg# any later version.
121d54945dSmrg
131d54945dSmrg# This program is distributed in the hope that it will be useful,
141d54945dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
151d54945dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161d54945dSmrg# GNU General Public License for more details.
171d54945dSmrg
181d54945dSmrg# You should have received a copy of the GNU General Public License
19ec713c28Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
201d54945dSmrg
211d54945dSmrg# As a special exception to the GNU General Public License, if you
221d54945dSmrg# distribute this file as part of a program that contains a
231d54945dSmrg# configuration script generated by Autoconf, you may include it under
241d54945dSmrg# the same distribution terms that you use for the rest of that program.
251d54945dSmrg
261d54945dSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
271d54945dSmrg
281d54945dSmrgcase $1 in
291d54945dSmrg  '')
307322289dSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
317322289dSmrg    exit 1;
327322289dSmrg    ;;
331d54945dSmrg  -h | --h*)
341d54945dSmrg    cat <<\EOF
351d54945dSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
361d54945dSmrg
371d54945dSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
381d54945dSmrgas side-effects.
391d54945dSmrg
401d54945dSmrgEnvironment variables:
411d54945dSmrg  depmode     Dependency tracking mode.
427322289dSmrg  source      Source file read by 'PROGRAMS ARGS'.
437322289dSmrg  object      Object file output by 'PROGRAMS ARGS'.
441d54945dSmrg  DEPDIR      directory where to store dependencies.
451d54945dSmrg  depfile     Dependency file to output.
46d769e936Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
471d54945dSmrg  libtool     Whether libtool is used (yes/no).
481d54945dSmrg
491d54945dSmrgReport bugs to <bug-automake@gnu.org>.
501d54945dSmrgEOF
511d54945dSmrg    exit $?
521d54945dSmrg    ;;
531d54945dSmrg  -v | --v*)
541d54945dSmrg    echo "depcomp $scriptversion"
551d54945dSmrg    exit $?
561d54945dSmrg    ;;
571d54945dSmrgesac
581d54945dSmrg
597322289dSmrg# Get the directory component of the given path, and save it in the
607322289dSmrg# global variables '$dir'.  Note that this directory component will
617322289dSmrg# be either empty or ending with a '/' character.  This is deliberate.
627322289dSmrgset_dir_from ()
637322289dSmrg{
647322289dSmrg  case $1 in
657322289dSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
667322289dSmrg      *) dir=;;
677322289dSmrg  esac
687322289dSmrg}
697322289dSmrg
707322289dSmrg# Get the suffix-stripped basename of the given path, and save it the
717322289dSmrg# global variable '$base'.
727322289dSmrgset_base_from ()
737322289dSmrg{
747322289dSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
757322289dSmrg}
767322289dSmrg
777322289dSmrg# If no dependency file was actually created by the compiler invocation,
787322289dSmrg# we still have to create a dummy depfile, to avoid errors with the
797322289dSmrg# Makefile "include basename.Plo" scheme.
807322289dSmrgmake_dummy_depfile ()
817322289dSmrg{
827322289dSmrg  echo "#dummy" > "$depfile"
837322289dSmrg}
847322289dSmrg
857322289dSmrg# Factor out some common post-processing of the generated depfile.
867322289dSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
877322289dSmrgaix_post_process_depfile ()
887322289dSmrg{
897322289dSmrg  # If the compiler actually managed to produce a dependency file,
907322289dSmrg  # post-process it.
917322289dSmrg  if test -f "$tmpdepfile"; then
927322289dSmrg    # Each line is of the form 'foo.o: dependency.h'.
937322289dSmrg    # Do two passes, one to just change these to
947322289dSmrg    #   $object: dependency.h
957322289dSmrg    # and one to simply output
967322289dSmrg    #   dependency.h:
977322289dSmrg    # which is needed to avoid the deleted-header problem.
987322289dSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
997322289dSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1007322289dSmrg    } > "$depfile"
1017322289dSmrg    rm -f "$tmpdepfile"
1027322289dSmrg  else
1037322289dSmrg    make_dummy_depfile
1047322289dSmrg  fi
1057322289dSmrg}
1067322289dSmrg
1077322289dSmrg# A tabulation character.
1087322289dSmrgtab='	'
1097322289dSmrg# A newline character.
1107322289dSmrgnl='
1117322289dSmrg'
1127322289dSmrg# Character ranges might be problematic outside the C locale.
1137322289dSmrg# These definitions help.
1147322289dSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1157322289dSmrglower=abcdefghijklmnopqrstuvwxyz
1167322289dSmrgdigits=0123456789
1177322289dSmrgalpha=${upper}${lower}
1187322289dSmrg
1191d54945dSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1201d54945dSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1211d54945dSmrg  exit 1
1221d54945dSmrgfi
1231d54945dSmrg
1241d54945dSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1251d54945dSmrgdepfile=${depfile-`echo "$object" |
1261d54945dSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1271d54945dSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1281d54945dSmrg
1291d54945dSmrgrm -f "$tmpdepfile"
1301d54945dSmrg
1317322289dSmrg# Avoid interferences from the environment.
1327322289dSmrggccflag= dashmflag=
1337322289dSmrg
1341d54945dSmrg# Some modes work just like other modes, but use different flags.  We
1351d54945dSmrg# parameterize here, but still list the modes in the big case below,
1361d54945dSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1371d54945dSmrg# here, because this file can only contain one case statement.
1381d54945dSmrgif test "$depmode" = hp; then
1391d54945dSmrg  # HP compiler uses -M and no extra arg.
1401d54945dSmrg  gccflag=-M
1411d54945dSmrg  depmode=gcc
1421d54945dSmrgfi
1431d54945dSmrg
1441d54945dSmrgif test "$depmode" = dashXmstdout; then
1457322289dSmrg  # This is just like dashmstdout with a different argument.
1467322289dSmrg  dashmflag=-xM
1477322289dSmrg  depmode=dashmstdout
1481d54945dSmrgfi
1491d54945dSmrg
150ec713c28Smrgcygpath_u="cygpath -u -f -"
151ec713c28Smrgif test "$depmode" = msvcmsys; then
1527322289dSmrg  # This is just like msvisualcpp but w/o cygpath translation.
1537322289dSmrg  # Just convert the backslash-escaped backslashes to single forward
1547322289dSmrg  # slashes to satisfy depend.m4
1557322289dSmrg  cygpath_u='sed s,\\\\,/,g'
1567322289dSmrg  depmode=msvisualcpp
157ec713c28Smrgfi
158ec713c28Smrg
159d769e936Smrgif test "$depmode" = msvc7msys; then
1607322289dSmrg  # This is just like msvc7 but w/o cygpath translation.
1617322289dSmrg  # Just convert the backslash-escaped backslashes to single forward
1627322289dSmrg  # slashes to satisfy depend.m4
1637322289dSmrg  cygpath_u='sed s,\\\\,/,g'
1647322289dSmrg  depmode=msvc7
1657322289dSmrgfi
1667322289dSmrg
1677322289dSmrgif test "$depmode" = xlc; then
1687322289dSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1697322289dSmrg  gccflag=-qmakedep=gcc,-MF
1707322289dSmrg  depmode=gcc
171d769e936Smrgfi
172d769e936Smrg
1731d54945dSmrgcase "$depmode" in
1741d54945dSmrggcc3)
1751d54945dSmrg## gcc 3 implements dependency tracking that does exactly what
1761d54945dSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1771d54945dSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178ba85709eSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179ba85709eSmrg## the command line argument order; so add the flags where they
180ba85709eSmrg## appear in depend2.am.  Note that the slowdown incurred here
181ba85709eSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182ba85709eSmrg  for arg
183ba85709eSmrg  do
184ba85709eSmrg    case $arg in
185ba85709eSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186ba85709eSmrg    *)  set fnord "$@" "$arg" ;;
187ba85709eSmrg    esac
188ba85709eSmrg    shift # fnord
189ba85709eSmrg    shift # $arg
190ba85709eSmrg  done
191ba85709eSmrg  "$@"
1921d54945dSmrg  stat=$?
1937322289dSmrg  if test $stat -ne 0; then
1941d54945dSmrg    rm -f "$tmpdepfile"
1951d54945dSmrg    exit $stat
1961d54945dSmrg  fi
1971d54945dSmrg  mv "$tmpdepfile" "$depfile"
1981d54945dSmrg  ;;
1991d54945dSmrg
2001d54945dSmrggcc)
2017322289dSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2027322289dSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2037322289dSmrg## (see the conditional assignment to $gccflag above).
2041d54945dSmrg## There are various ways to get dependency output from gcc.  Here's
2051d54945dSmrg## why we pick this rather obscure method:
2061d54945dSmrg## - Don't want to use -MD because we'd like the dependencies to end
2071d54945dSmrg##   up in a subdir.  Having to rename by hand is ugly.
2081d54945dSmrg##   (We might end up doing this anyway to support other compilers.)
2091d54945dSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2107322289dSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2117322289dSmrg##   supported by the other compilers which use the 'gcc' depmode.
2121d54945dSmrg## - Using -M directly means running the compiler twice (even worse
2131d54945dSmrg##   than renaming).
2141d54945dSmrg  if test -z "$gccflag"; then
2151d54945dSmrg    gccflag=-MD,
2161d54945dSmrg  fi
2171d54945dSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
2181d54945dSmrg  stat=$?
2197322289dSmrg  if test $stat -ne 0; then
2201d54945dSmrg    rm -f "$tmpdepfile"
2211d54945dSmrg    exit $stat
2221d54945dSmrg  fi
2231d54945dSmrg  rm -f "$depfile"
2241d54945dSmrg  echo "$object : \\" > "$depfile"
2257322289dSmrg  # The second -e expression handles DOS-style file names with drive
2267322289dSmrg  # letters.
2271d54945dSmrg  sed -e 's/^[^:]*: / /' \
2281d54945dSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2297322289dSmrg## This next piece of magic avoids the "deleted header file" problem.
2301d54945dSmrg## The problem is that when a header file which appears in a .P file
2311d54945dSmrg## is deleted, the dependency causes make to die (because there is
2321d54945dSmrg## typically no way to rebuild the header).  We avoid this by adding
2331d54945dSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2341d54945dSmrg## this for us directly.
2357322289dSmrg## Some versions of gcc put a space before the ':'.  On the theory
2361d54945dSmrg## that the space means something, we add a space to the output as
237d769e936Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238d769e936Smrg## to the object.  Take care to not repeat it in the output.
2391d54945dSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
2401d54945dSmrg## correctly.  Breaking it into two sed invocations is a workaround.
2417322289dSmrg  tr ' ' "$nl" < "$tmpdepfile" \
2427322289dSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2437322289dSmrg    | sed -e 's/$/ :/' >> "$depfile"
2441d54945dSmrg  rm -f "$tmpdepfile"
2451d54945dSmrg  ;;
2461d54945dSmrg
2471d54945dSmrghp)
2481d54945dSmrg  # This case exists only to let depend.m4 do its work.  It works by
2491d54945dSmrg  # looking at the text of this script.  This case will never be run,
2501d54945dSmrg  # since it is checked for above.
2511d54945dSmrg  exit 1
2521d54945dSmrg  ;;
2531d54945dSmrg
2541d54945dSmrgsgi)
2551d54945dSmrg  if test "$libtool" = yes; then
2561d54945dSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2571d54945dSmrg  else
2581d54945dSmrg    "$@" -MDupdate "$tmpdepfile"
2591d54945dSmrg  fi
2601d54945dSmrg  stat=$?
2617322289dSmrg  if test $stat -ne 0; then
2621d54945dSmrg    rm -f "$tmpdepfile"
2631d54945dSmrg    exit $stat
2641d54945dSmrg  fi
2651d54945dSmrg  rm -f "$depfile"
2661d54945dSmrg
2671d54945dSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2681d54945dSmrg    echo "$object : \\" > "$depfile"
2691d54945dSmrg    # Clip off the initial element (the dependent).  Don't try to be
2701d54945dSmrg    # clever and replace this with sed code, as IRIX sed won't handle
2711d54945dSmrg    # lines with more than a fixed number of characters (4096 in
2721d54945dSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2737322289dSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
2741d54945dSmrg    # dependency line.
2757322289dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2767322289dSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2777322289dSmrg      | tr "$nl" ' ' >> "$depfile"
278ec713c28Smrg    echo >> "$depfile"
2791d54945dSmrg    # The second pass generates a dummy entry for each header file.
2807322289dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2817322289dSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2827322289dSmrg      >> "$depfile"
2831d54945dSmrg  else
2847322289dSmrg    make_dummy_depfile
2851d54945dSmrg  fi
2861d54945dSmrg  rm -f "$tmpdepfile"
2871d54945dSmrg  ;;
2881d54945dSmrg
2897322289dSmrgxlc)
2907322289dSmrg  # This case exists only to let depend.m4 do its work.  It works by
2917322289dSmrg  # looking at the text of this script.  This case will never be run,
2927322289dSmrg  # since it is checked for above.
2937322289dSmrg  exit 1
2947322289dSmrg  ;;
2957322289dSmrg
2961d54945dSmrgaix)
2971d54945dSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
2981d54945dSmrg  # in a .u file.  In older versions, this file always lives in the
2997322289dSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3001d54945dSmrg  # start of each line; $object doesn't have directory information.
3011d54945dSmrg  # Version 6 uses the directory in both cases.
3027322289dSmrg  set_dir_from "$object"
3037322289dSmrg  set_base_from "$object"
3041d54945dSmrg  if test "$libtool" = yes; then
305786a6f21Smrg    tmpdepfile1=$dir$base.u
306786a6f21Smrg    tmpdepfile2=$base.u
307786a6f21Smrg    tmpdepfile3=$dir.libs/$base.u
3081d54945dSmrg    "$@" -Wc,-M
3091d54945dSmrg  else
310786a6f21Smrg    tmpdepfile1=$dir$base.u
311786a6f21Smrg    tmpdepfile2=$dir$base.u
312786a6f21Smrg    tmpdepfile3=$dir$base.u
3131d54945dSmrg    "$@" -M
3141d54945dSmrg  fi
3151d54945dSmrg  stat=$?
3167322289dSmrg  if test $stat -ne 0; then
317786a6f21Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3181d54945dSmrg    exit $stat
3191d54945dSmrg  fi
3201d54945dSmrg
321786a6f21Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322786a6f21Smrg  do
323786a6f21Smrg    test -f "$tmpdepfile" && break
324786a6f21Smrg  done
3257322289dSmrg  aix_post_process_depfile
3267322289dSmrg  ;;
3277322289dSmrg
3287322289dSmrgtcc)
3297322289dSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3307322289dSmrg  # FIXME: That version still under development at the moment of writing.
3317322289dSmrg  #        Make that this statement remains true also for stable, released
3327322289dSmrg  #        versions.
3337322289dSmrg  # It will wrap lines (doesn't matter whether long or short) with a
3347322289dSmrg  # trailing '\', as in:
3357322289dSmrg  #
3367322289dSmrg  #   foo.o : \
3377322289dSmrg  #    foo.c \
3387322289dSmrg  #    foo.h \
3397322289dSmrg  #
3407322289dSmrg  # It will put a trailing '\' even on the last line, and will use leading
3417322289dSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3427322289dSmrg  # "Emit spaces for -MD").
3437322289dSmrg  "$@" -MD -MF "$tmpdepfile"
3447322289dSmrg  stat=$?
3457322289dSmrg  if test $stat -ne 0; then
3467322289dSmrg    rm -f "$tmpdepfile"
3477322289dSmrg    exit $stat
3481d54945dSmrg  fi
3497322289dSmrg  rm -f "$depfile"
3507322289dSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3517322289dSmrg  # We have to change lines of the first kind to '$object: \'.
3527322289dSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3537322289dSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3547322289dSmrg  # dummy dependency, to avoid the deleted-header problem.
3557322289dSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3561d54945dSmrg  rm -f "$tmpdepfile"
3571d54945dSmrg  ;;
3581d54945dSmrg
3597322289dSmrg## The order of this option in the case statement is important, since the
3607322289dSmrg## shell code in configure will try each of these formats in the order
3617322289dSmrg## listed in this file.  A plain '-MD' option would be understood by many
3627322289dSmrg## compilers, so we must ensure this comes after the gcc and icc options.
3637322289dSmrgpgcc)
3647322289dSmrg  # Portland's C compiler understands '-MD'.
3657322289dSmrg  # Will always output deps to 'file.d' where file is the root name of the
3667322289dSmrg  # source file under compilation, even if file resides in a subdirectory.
3677322289dSmrg  # The object file name does not affect the name of the '.d' file.
3687322289dSmrg  # pgcc 10.2 will output
3691d54945dSmrg  #    foo.o: sub/foo.c sub/foo.h
3707322289dSmrg  # and will wrap long lines using '\' :
3711d54945dSmrg  #    foo.o: sub/foo.c ... \
3721d54945dSmrg  #     sub/foo.h ... \
3731d54945dSmrg  #     ...
3747322289dSmrg  set_dir_from "$object"
3757322289dSmrg  # Use the source, not the object, to determine the base name, since
3767322289dSmrg  # that's sadly what pgcc will do too.
3777322289dSmrg  set_base_from "$source"
3787322289dSmrg  tmpdepfile=$base.d
3797322289dSmrg
3807322289dSmrg  # For projects that build the same source file twice into different object
3817322289dSmrg  # files, the pgcc approach of using the *source* file root name can cause
3827322289dSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3837322289dSmrg  # the same $tmpdepfile.
3847322289dSmrg  lockdir=$base.d-lock
3857322289dSmrg  trap "
3867322289dSmrg    echo '$0: caught signal, cleaning up...' >&2
3877322289dSmrg    rmdir '$lockdir'
3887322289dSmrg    exit 1
3897322289dSmrg  " 1 2 13 15
3907322289dSmrg  numtries=100
3917322289dSmrg  i=$numtries
3927322289dSmrg  while test $i -gt 0; do
3937322289dSmrg    # mkdir is a portable test-and-set.
3947322289dSmrg    if mkdir "$lockdir" 2>/dev/null; then
3957322289dSmrg      # This process acquired the lock.
3967322289dSmrg      "$@" -MD
3977322289dSmrg      stat=$?
3987322289dSmrg      # Release the lock.
3997322289dSmrg      rmdir "$lockdir"
4007322289dSmrg      break
4017322289dSmrg    else
4027322289dSmrg      # If the lock is being held by a different process, wait
4037322289dSmrg      # until the winning process is done or we timeout.
4047322289dSmrg      while test -d "$lockdir" && test $i -gt 0; do
4057322289dSmrg        sleep 1
4067322289dSmrg        i=`expr $i - 1`
4077322289dSmrg      done
4087322289dSmrg    fi
4097322289dSmrg    i=`expr $i - 1`
4107322289dSmrg  done
4117322289dSmrg  trap - 1 2 13 15
4127322289dSmrg  if test $i -le 0; then
4137322289dSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4147322289dSmrg    echo "$0: check lockdir '$lockdir'" >&2
4157322289dSmrg    exit 1
4167322289dSmrg  fi
4171d54945dSmrg
4187322289dSmrg  if test $stat -ne 0; then
4191d54945dSmrg    rm -f "$tmpdepfile"
4201d54945dSmrg    exit $stat
4211d54945dSmrg  fi
4221d54945dSmrg  rm -f "$depfile"
4231d54945dSmrg  # Each line is of the form `foo.o: dependent.h',
4241d54945dSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4251d54945dSmrg  # Do two passes, one to just change these to
4261d54945dSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4271d54945dSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4281d54945dSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4291d54945dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
4307322289dSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4317322289dSmrg    | sed -e 's/$/ :/' >> "$depfile"
4321d54945dSmrg  rm -f "$tmpdepfile"
4331d54945dSmrg  ;;
4341d54945dSmrg
435ba85709eSmrghp2)
436ba85709eSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437ba85709eSmrg  # compilers, which have integrated preprocessors.  The correct option
438ba85709eSmrg  # to use with these is +Maked; it writes dependencies to a file named
439ba85709eSmrg  # 'foo.d', which lands next to the object file, wherever that
440ba85709eSmrg  # happens to be.
441ba85709eSmrg  # Much of this is similar to the tru64 case; see comments there.
4427322289dSmrg  set_dir_from  "$object"
4437322289dSmrg  set_base_from "$object"
444ba85709eSmrg  if test "$libtool" = yes; then
445ba85709eSmrg    tmpdepfile1=$dir$base.d
446ba85709eSmrg    tmpdepfile2=$dir.libs/$base.d
447ba85709eSmrg    "$@" -Wc,+Maked
448ba85709eSmrg  else
449ba85709eSmrg    tmpdepfile1=$dir$base.d
450ba85709eSmrg    tmpdepfile2=$dir$base.d
451ba85709eSmrg    "$@" +Maked
452ba85709eSmrg  fi
453ba85709eSmrg  stat=$?
4547322289dSmrg  if test $stat -ne 0; then
455ba85709eSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456ba85709eSmrg     exit $stat
457ba85709eSmrg  fi
458ba85709eSmrg
459ba85709eSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460ba85709eSmrg  do
461ba85709eSmrg    test -f "$tmpdepfile" && break
462ba85709eSmrg  done
463ba85709eSmrg  if test -f "$tmpdepfile"; then
4647322289dSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4657322289dSmrg    # Add 'dependent.h:' lines.
466ec713c28Smrg    sed -ne '2,${
4677322289dSmrg               s/^ *//
4687322289dSmrg               s/ \\*$//
4697322289dSmrg               s/$/:/
4707322289dSmrg               p
4717322289dSmrg             }' "$tmpdepfile" >> "$depfile"
472ba85709eSmrg  else
4737322289dSmrg    make_dummy_depfile
474ba85709eSmrg  fi
475ba85709eSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476ba85709eSmrg  ;;
477ba85709eSmrg
4781d54945dSmrgtru64)
4797322289dSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4807322289dSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4817322289dSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4827322289dSmrg  # dependencies in 'foo.d' instead, so we check for that too.
4837322289dSmrg  # Subdirectories are respected.
4847322289dSmrg  set_dir_from  "$object"
4857322289dSmrg  set_base_from "$object"
4867322289dSmrg
4877322289dSmrg  if test "$libtool" = yes; then
4887322289dSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4897322289dSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4907322289dSmrg    # in $dir$base.o.d.  We have to check for both files, because
4917322289dSmrg    # one of the two compilations can be disabled.  We should prefer
4927322289dSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4937322289dSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
4947322289dSmrg    # the former would cause a distcleancheck panic.
4957322289dSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4967322289dSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4977322289dSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4987322289dSmrg    "$@" -Wc,-MD
4997322289dSmrg  else
5007322289dSmrg    tmpdepfile1=$dir$base.d
5017322289dSmrg    tmpdepfile2=$dir$base.d
5027322289dSmrg    tmpdepfile3=$dir$base.d
5037322289dSmrg    "$@" -MD
5047322289dSmrg  fi
5057322289dSmrg
5067322289dSmrg  stat=$?
5077322289dSmrg  if test $stat -ne 0; then
5087322289dSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5097322289dSmrg    exit $stat
5107322289dSmrg  fi
5117322289dSmrg
5127322289dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5137322289dSmrg  do
5147322289dSmrg    test -f "$tmpdepfile" && break
5157322289dSmrg  done
5167322289dSmrg  # Same post-processing that is required for AIX mode.
5177322289dSmrg  aix_post_process_depfile
5187322289dSmrg  ;;
5191d54945dSmrg
520d769e936Smrgmsvc7)
521d769e936Smrg  if test "$libtool" = yes; then
522d769e936Smrg    showIncludes=-Wc,-showIncludes
523d769e936Smrg  else
524d769e936Smrg    showIncludes=-showIncludes
525d769e936Smrg  fi
526d769e936Smrg  "$@" $showIncludes > "$tmpdepfile"
527d769e936Smrg  stat=$?
528d769e936Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5297322289dSmrg  if test $stat -ne 0; then
530d769e936Smrg    rm -f "$tmpdepfile"
531d769e936Smrg    exit $stat
532d769e936Smrg  fi
533d769e936Smrg  rm -f "$depfile"
534d769e936Smrg  echo "$object : \\" > "$depfile"
535d769e936Smrg  # The first sed program below extracts the file names and escapes
536d769e936Smrg  # backslashes for cygpath.  The second sed program outputs the file
537d769e936Smrg  # name when reading, but also accumulates all include files in the
538d769e936Smrg  # hold buffer in order to output them again at the end.  This only
539d769e936Smrg  # works with sed implementations that can handle large buffers.
540d769e936Smrg  sed < "$tmpdepfile" -n '
541d769e936Smrg/^Note: including file:  *\(.*\)/ {
542d769e936Smrg  s//\1/
543d769e936Smrg  s/\\/\\\\/g
544d769e936Smrg  p
545d769e936Smrg}' | $cygpath_u | sort -u | sed -n '
546d769e936Smrgs/ /\\ /g
5477322289dSmrgs/\(.*\)/'"$tab"'\1 \\/p
548d769e936Smrgs/.\(.*\) \\/\1:/
549d769e936SmrgH
550d769e936Smrg$ {
5517322289dSmrg  s/.*/'"$tab"'/
552d769e936Smrg  G
553d769e936Smrg  p
554d769e936Smrg}' >> "$depfile"
5557322289dSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556d769e936Smrg  rm -f "$tmpdepfile"
557d769e936Smrg  ;;
558d769e936Smrg
559d769e936Smrgmsvc7msys)
560d769e936Smrg  # This case exists only to let depend.m4 do its work.  It works by
561d769e936Smrg  # looking at the text of this script.  This case will never be run,
562d769e936Smrg  # since it is checked for above.
563d769e936Smrg  exit 1
564d769e936Smrg  ;;
565d769e936Smrg
5661d54945dSmrg#nosideeffect)
5671d54945dSmrg  # This comment above is used by automake to tell side-effect
5681d54945dSmrg  # dependency tracking mechanisms from slower ones.
5691d54945dSmrg
5701d54945dSmrgdashmstdout)
5711d54945dSmrg  # Important note: in order to support this mode, a compiler *must*
5721d54945dSmrg  # always write the preprocessed file to stdout, regardless of -o.
5731d54945dSmrg  "$@" || exit $?
5741d54945dSmrg
5751d54945dSmrg  # Remove the call to Libtool.
5761d54945dSmrg  if test "$libtool" = yes; then
577ec713c28Smrg    while test "X$1" != 'X--mode=compile'; do
5781d54945dSmrg      shift
5791d54945dSmrg    done
5801d54945dSmrg    shift
5811d54945dSmrg  fi
5821d54945dSmrg
5837322289dSmrg  # Remove '-o $object'.
5841d54945dSmrg  IFS=" "
5851d54945dSmrg  for arg
5861d54945dSmrg  do
5871d54945dSmrg    case $arg in
5881d54945dSmrg    -o)
5891d54945dSmrg      shift
5901d54945dSmrg      ;;
5911d54945dSmrg    $object)
5921d54945dSmrg      shift
5931d54945dSmrg      ;;
5941d54945dSmrg    *)
5951d54945dSmrg      set fnord "$@" "$arg"
5961d54945dSmrg      shift # fnord
5971d54945dSmrg      shift # $arg
5981d54945dSmrg      ;;
5991d54945dSmrg    esac
6001d54945dSmrg  done
6011d54945dSmrg
6021d54945dSmrg  test -z "$dashmflag" && dashmflag=-M
6037322289dSmrg  # Require at least two characters before searching for ':'
6041d54945dSmrg  # in the target name.  This is to cope with DOS-style filenames:
6057322289dSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6061d54945dSmrg  "$@" $dashmflag |
6077322289dSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6081d54945dSmrg  rm -f "$depfile"
6091d54945dSmrg  cat < "$tmpdepfile" > "$depfile"
6107322289dSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6117322289dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6127322289dSmrg  tr ' ' "$nl" < "$tmpdepfile" \
6137322289dSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6147322289dSmrg    | sed -e 's/$/ :/' >> "$depfile"
6151d54945dSmrg  rm -f "$tmpdepfile"
6161d54945dSmrg  ;;
6171d54945dSmrg
6181d54945dSmrgdashXmstdout)
6191d54945dSmrg  # This case only exists to satisfy depend.m4.  It is never actually
6201d54945dSmrg  # run, as this mode is specially recognized in the preamble.
6211d54945dSmrg  exit 1
6221d54945dSmrg  ;;
6231d54945dSmrg
6241d54945dSmrgmakedepend)
6251d54945dSmrg  "$@" || exit $?
6261d54945dSmrg  # Remove any Libtool call
6271d54945dSmrg  if test "$libtool" = yes; then
628ec713c28Smrg    while test "X$1" != 'X--mode=compile'; do
6291d54945dSmrg      shift
6301d54945dSmrg    done
6311d54945dSmrg    shift
6321d54945dSmrg  fi
6331d54945dSmrg  # X makedepend
6341d54945dSmrg  shift
635ec713c28Smrg  cleared=no eat=no
636ec713c28Smrg  for arg
637ec713c28Smrg  do
6381d54945dSmrg    case $cleared in
6391d54945dSmrg    no)
6401d54945dSmrg      set ""; shift
6411d54945dSmrg      cleared=yes ;;
6421d54945dSmrg    esac
643ec713c28Smrg    if test $eat = yes; then
644ec713c28Smrg      eat=no
645ec713c28Smrg      continue
646ec713c28Smrg    fi
6471d54945dSmrg    case "$arg" in
6481d54945dSmrg    -D*|-I*)
6491d54945dSmrg      set fnord "$@" "$arg"; shift ;;
6501d54945dSmrg    # Strip any option that makedepend may not understand.  Remove
6511d54945dSmrg    # the object too, otherwise makedepend will parse it as a source file.
652ec713c28Smrg    -arch)
653ec713c28Smrg      eat=yes ;;
6541d54945dSmrg    -*|$object)
6551d54945dSmrg      ;;
6561d54945dSmrg    *)
6571d54945dSmrg      set fnord "$@" "$arg"; shift ;;
6581d54945dSmrg    esac
6591d54945dSmrg  done
660ec713c28Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6611d54945dSmrg  touch "$tmpdepfile"
6621d54945dSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6631d54945dSmrg  rm -f "$depfile"
664d769e936Smrg  # makedepend may prepend the VPATH from the source file name to the object.
665d769e936Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666d769e936Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6677322289dSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6687322289dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6697322289dSmrg  sed '1,2d' "$tmpdepfile" \
6707322289dSmrg    | tr ' ' "$nl" \
6717322289dSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6727322289dSmrg    | sed -e 's/$/ :/' >> "$depfile"
6731d54945dSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6741d54945dSmrg  ;;
6751d54945dSmrg
6761d54945dSmrgcpp)
6771d54945dSmrg  # Important note: in order to support this mode, a compiler *must*
6781d54945dSmrg  # always write the preprocessed file to stdout.
6791d54945dSmrg  "$@" || exit $?
6801d54945dSmrg
6811d54945dSmrg  # Remove the call to Libtool.
6821d54945dSmrg  if test "$libtool" = yes; then
683ec713c28Smrg    while test "X$1" != 'X--mode=compile'; do
6841d54945dSmrg      shift
6851d54945dSmrg    done
6861d54945dSmrg    shift
6871d54945dSmrg  fi
6881d54945dSmrg
6897322289dSmrg  # Remove '-o $object'.
6901d54945dSmrg  IFS=" "
6911d54945dSmrg  for arg
6921d54945dSmrg  do
6931d54945dSmrg    case $arg in
6941d54945dSmrg    -o)
6951d54945dSmrg      shift
6961d54945dSmrg      ;;
6971d54945dSmrg    $object)
6981d54945dSmrg      shift
6991d54945dSmrg      ;;
7001d54945dSmrg    *)
7011d54945dSmrg      set fnord "$@" "$arg"
7021d54945dSmrg      shift # fnord
7031d54945dSmrg      shift # $arg
7041d54945dSmrg      ;;
7051d54945dSmrg    esac
7061d54945dSmrg  done
7071d54945dSmrg
7087322289dSmrg  "$@" -E \
7097322289dSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7107322289dSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7117322289dSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
7121d54945dSmrg  rm -f "$depfile"
7131d54945dSmrg  echo "$object : \\" > "$depfile"
7141d54945dSmrg  cat < "$tmpdepfile" >> "$depfile"
7151d54945dSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7161d54945dSmrg  rm -f "$tmpdepfile"
7171d54945dSmrg  ;;
7181d54945dSmrg
7191d54945dSmrgmsvisualcpp)
7201d54945dSmrg  # Important note: in order to support this mode, a compiler *must*
721ec713c28Smrg  # always write the preprocessed file to stdout.
7221d54945dSmrg  "$@" || exit $?
723ec713c28Smrg
724ec713c28Smrg  # Remove the call to Libtool.
725ec713c28Smrg  if test "$libtool" = yes; then
726ec713c28Smrg    while test "X$1" != 'X--mode=compile'; do
727ec713c28Smrg      shift
728ec713c28Smrg    done
729ec713c28Smrg    shift
730ec713c28Smrg  fi
731ec713c28Smrg
7321d54945dSmrg  IFS=" "
7331d54945dSmrg  for arg
7341d54945dSmrg  do
7351d54945dSmrg    case "$arg" in
736ec713c28Smrg    -o)
737ec713c28Smrg      shift
738ec713c28Smrg      ;;
739ec713c28Smrg    $object)
740ec713c28Smrg      shift
741ec713c28Smrg      ;;
7421d54945dSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7437322289dSmrg        set fnord "$@"
7447322289dSmrg        shift
7457322289dSmrg        shift
7467322289dSmrg        ;;
7471d54945dSmrg    *)
7487322289dSmrg        set fnord "$@" "$arg"
7497322289dSmrg        shift
7507322289dSmrg        shift
7517322289dSmrg        ;;
7521d54945dSmrg    esac
7531d54945dSmrg  done
754ec713c28Smrg  "$@" -E 2>/dev/null |
755ec713c28Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7561d54945dSmrg  rm -f "$depfile"
7571d54945dSmrg  echo "$object : \\" > "$depfile"
7587322289dSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7597322289dSmrg  echo "$tab" >> "$depfile"
760ec713c28Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7611d54945dSmrg  rm -f "$tmpdepfile"
7621d54945dSmrg  ;;
7631d54945dSmrg
764ec713c28Smrgmsvcmsys)
765ec713c28Smrg  # This case exists only to let depend.m4 do its work.  It works by
766ec713c28Smrg  # looking at the text of this script.  This case will never be run,
767ec713c28Smrg  # since it is checked for above.
768ec713c28Smrg  exit 1
769ec713c28Smrg  ;;
770ec713c28Smrg
7711d54945dSmrgnone)
7721d54945dSmrg  exec "$@"
7731d54945dSmrg  ;;
7741d54945dSmrg
7751d54945dSmrg*)
7761d54945dSmrg  echo "Unknown depmode $depmode" 1>&2
7771d54945dSmrg  exit 1
7781d54945dSmrg  ;;
7791d54945dSmrgesac
7801d54945dSmrg
7811d54945dSmrgexit 0
7821d54945dSmrg
7831d54945dSmrg# Local Variables:
7841d54945dSmrg# mode: shell-script
7851d54945dSmrg# sh-indentation: 2
7861d54945dSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
7871d54945dSmrg# time-stamp-start: "scriptversion="
7881d54945dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789ec713c28Smrg# time-stamp-time-zone: "UTC"
790ec713c28Smrg# time-stamp-end: "; # UTC"
7911d54945dSmrg# End:
792