176888252Smrg#! /bin/sh
276888252Smrg# depcomp - compile a program generating dependencies as side-effects
376888252Smrg
40814a2baSmrgscriptversion=2018-03-07.03; # UTC
576888252Smrg
60814a2baSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
776888252Smrg
876888252Smrg# This program is free software; you can redistribute it and/or modify
976888252Smrg# it under the terms of the GNU General Public License as published by
1076888252Smrg# the Free Software Foundation; either version 2, or (at your option)
1176888252Smrg# any later version.
1276888252Smrg
1376888252Smrg# This program is distributed in the hope that it will be useful,
1476888252Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1576888252Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1676888252Smrg# GNU General Public License for more details.
1776888252Smrg
1876888252Smrg# You should have received a copy of the GNU General Public License
190814a2baSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2076888252Smrg
2176888252Smrg# As a special exception to the GNU General Public License, if you
2276888252Smrg# distribute this file as part of a program that contains a
2376888252Smrg# configuration script generated by Autoconf, you may include it under
2476888252Smrg# the same distribution terms that you use for the rest of that program.
2576888252Smrg
2676888252Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2776888252Smrg
2876888252Smrgcase $1 in
2976888252Smrg  '')
309586ba5aSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
319586ba5aSmrg    exit 1;
329586ba5aSmrg    ;;
3376888252Smrg  -h | --h*)
3476888252Smrg    cat <<\EOF
3576888252SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3676888252Smrg
3776888252SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3876888252Smrgas side-effects.
3976888252Smrg
4076888252SmrgEnvironment variables:
4176888252Smrg  depmode     Dependency tracking mode.
429586ba5aSmrg  source      Source file read by 'PROGRAMS ARGS'.
439586ba5aSmrg  object      Object file output by 'PROGRAMS ARGS'.
4476888252Smrg  DEPDIR      directory where to store dependencies.
4576888252Smrg  depfile     Dependency file to output.
4663847c39Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4776888252Smrg  libtool     Whether libtool is used (yes/no).
4876888252Smrg
4976888252SmrgReport bugs to <bug-automake@gnu.org>.
5076888252SmrgEOF
5176888252Smrg    exit $?
5276888252Smrg    ;;
5376888252Smrg  -v | --v*)
5476888252Smrg    echo "depcomp $scriptversion"
5576888252Smrg    exit $?
5676888252Smrg    ;;
5776888252Smrgesac
5876888252Smrg
599586ba5aSmrg# Get the directory component of the given path, and save it in the
609586ba5aSmrg# global variables '$dir'.  Note that this directory component will
619586ba5aSmrg# be either empty or ending with a '/' character.  This is deliberate.
629586ba5aSmrgset_dir_from ()
639586ba5aSmrg{
649586ba5aSmrg  case $1 in
659586ba5aSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
669586ba5aSmrg      *) dir=;;
679586ba5aSmrg  esac
689586ba5aSmrg}
699586ba5aSmrg
709586ba5aSmrg# Get the suffix-stripped basename of the given path, and save it the
719586ba5aSmrg# global variable '$base'.
729586ba5aSmrgset_base_from ()
739586ba5aSmrg{
749586ba5aSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
759586ba5aSmrg}
769586ba5aSmrg
779586ba5aSmrg# If no dependency file was actually created by the compiler invocation,
789586ba5aSmrg# we still have to create a dummy depfile, to avoid errors with the
799586ba5aSmrg# Makefile "include basename.Plo" scheme.
809586ba5aSmrgmake_dummy_depfile ()
819586ba5aSmrg{
829586ba5aSmrg  echo "#dummy" > "$depfile"
839586ba5aSmrg}
849586ba5aSmrg
859586ba5aSmrg# Factor out some common post-processing of the generated depfile.
869586ba5aSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
879586ba5aSmrgaix_post_process_depfile ()
889586ba5aSmrg{
899586ba5aSmrg  # If the compiler actually managed to produce a dependency file,
909586ba5aSmrg  # post-process it.
919586ba5aSmrg  if test -f "$tmpdepfile"; then
929586ba5aSmrg    # Each line is of the form 'foo.o: dependency.h'.
939586ba5aSmrg    # Do two passes, one to just change these to
949586ba5aSmrg    #   $object: dependency.h
959586ba5aSmrg    # and one to simply output
969586ba5aSmrg    #   dependency.h:
979586ba5aSmrg    # which is needed to avoid the deleted-header problem.
989586ba5aSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
999586ba5aSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1009586ba5aSmrg    } > "$depfile"
1019586ba5aSmrg    rm -f "$tmpdepfile"
1029586ba5aSmrg  else
1039586ba5aSmrg    make_dummy_depfile
1049586ba5aSmrg  fi
1059586ba5aSmrg}
1069586ba5aSmrg
1079586ba5aSmrg# A tabulation character.
1089586ba5aSmrgtab='	'
1099586ba5aSmrg# A newline character.
1109586ba5aSmrgnl='
1119586ba5aSmrg'
1129586ba5aSmrg# Character ranges might be problematic outside the C locale.
1139586ba5aSmrg# These definitions help.
1149586ba5aSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1159586ba5aSmrglower=abcdefghijklmnopqrstuvwxyz
1169586ba5aSmrgdigits=0123456789
1179586ba5aSmrgalpha=${upper}${lower}
1189586ba5aSmrg
11976888252Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12076888252Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12176888252Smrg  exit 1
12276888252Smrgfi
12376888252Smrg
12476888252Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12576888252Smrgdepfile=${depfile-`echo "$object" |
12676888252Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12776888252Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12876888252Smrg
12976888252Smrgrm -f "$tmpdepfile"
13076888252Smrg
1319586ba5aSmrg# Avoid interferences from the environment.
1329586ba5aSmrggccflag= dashmflag=
1339586ba5aSmrg
13476888252Smrg# Some modes work just like other modes, but use different flags.  We
13576888252Smrg# parameterize here, but still list the modes in the big case below,
13676888252Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13776888252Smrg# here, because this file can only contain one case statement.
13876888252Smrgif test "$depmode" = hp; then
13976888252Smrg  # HP compiler uses -M and no extra arg.
14076888252Smrg  gccflag=-M
14176888252Smrg  depmode=gcc
14276888252Smrgfi
14376888252Smrg
14476888252Smrgif test "$depmode" = dashXmstdout; then
1459586ba5aSmrg  # This is just like dashmstdout with a different argument.
1469586ba5aSmrg  dashmflag=-xM
1479586ba5aSmrg  depmode=dashmstdout
14876888252Smrgfi
14976888252Smrg
150d8556812Smrgcygpath_u="cygpath -u -f -"
151d8556812Smrgif test "$depmode" = msvcmsys; then
1529586ba5aSmrg  # This is just like msvisualcpp but w/o cygpath translation.
1539586ba5aSmrg  # Just convert the backslash-escaped backslashes to single forward
1549586ba5aSmrg  # slashes to satisfy depend.m4
1559586ba5aSmrg  cygpath_u='sed s,\\\\,/,g'
1569586ba5aSmrg  depmode=msvisualcpp
157d8556812Smrgfi
158d8556812Smrg
15963847c39Smrgif test "$depmode" = msvc7msys; then
1609586ba5aSmrg  # This is just like msvc7 but w/o cygpath translation.
1619586ba5aSmrg  # Just convert the backslash-escaped backslashes to single forward
1629586ba5aSmrg  # slashes to satisfy depend.m4
1639586ba5aSmrg  cygpath_u='sed s,\\\\,/,g'
1649586ba5aSmrg  depmode=msvc7
1659586ba5aSmrgfi
1669586ba5aSmrg
1679586ba5aSmrgif test "$depmode" = xlc; then
1689586ba5aSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1699586ba5aSmrg  gccflag=-qmakedep=gcc,-MF
1709586ba5aSmrg  depmode=gcc
17163847c39Smrgfi
17263847c39Smrg
17376888252Smrgcase "$depmode" in
17476888252Smrggcc3)
17576888252Smrg## gcc 3 implements dependency tracking that does exactly what
17676888252Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17776888252Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1781ae1b5e8Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1791ae1b5e8Smrg## the command line argument order; so add the flags where they
1801ae1b5e8Smrg## appear in depend2.am.  Note that the slowdown incurred here
1811ae1b5e8Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1821ae1b5e8Smrg  for arg
1831ae1b5e8Smrg  do
1841ae1b5e8Smrg    case $arg in
1851ae1b5e8Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1861ae1b5e8Smrg    *)  set fnord "$@" "$arg" ;;
1871ae1b5e8Smrg    esac
1881ae1b5e8Smrg    shift # fnord
1891ae1b5e8Smrg    shift # $arg
1901ae1b5e8Smrg  done
1911ae1b5e8Smrg  "$@"
19276888252Smrg  stat=$?
1939586ba5aSmrg  if test $stat -ne 0; then
19476888252Smrg    rm -f "$tmpdepfile"
19576888252Smrg    exit $stat
19676888252Smrg  fi
19776888252Smrg  mv "$tmpdepfile" "$depfile"
19876888252Smrg  ;;
19976888252Smrg
20076888252Smrggcc)
2019586ba5aSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2029586ba5aSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2039586ba5aSmrg## (see the conditional assignment to $gccflag above).
20476888252Smrg## There are various ways to get dependency output from gcc.  Here's
20576888252Smrg## why we pick this rather obscure method:
20676888252Smrg## - Don't want to use -MD because we'd like the dependencies to end
20776888252Smrg##   up in a subdir.  Having to rename by hand is ugly.
20876888252Smrg##   (We might end up doing this anyway to support other compilers.)
20976888252Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2109586ba5aSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2119586ba5aSmrg##   supported by the other compilers which use the 'gcc' depmode.
21276888252Smrg## - Using -M directly means running the compiler twice (even worse
21376888252Smrg##   than renaming).
21476888252Smrg  if test -z "$gccflag"; then
21576888252Smrg    gccflag=-MD,
21676888252Smrg  fi
21776888252Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21876888252Smrg  stat=$?
2199586ba5aSmrg  if test $stat -ne 0; then
22076888252Smrg    rm -f "$tmpdepfile"
22176888252Smrg    exit $stat
22276888252Smrg  fi
22376888252Smrg  rm -f "$depfile"
22476888252Smrg  echo "$object : \\" > "$depfile"
2259586ba5aSmrg  # The second -e expression handles DOS-style file names with drive
2269586ba5aSmrg  # letters.
22776888252Smrg  sed -e 's/^[^:]*: / /' \
22876888252Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2299586ba5aSmrg## This next piece of magic avoids the "deleted header file" problem.
23076888252Smrg## The problem is that when a header file which appears in a .P file
23176888252Smrg## is deleted, the dependency causes make to die (because there is
23276888252Smrg## typically no way to rebuild the header).  We avoid this by adding
23376888252Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23476888252Smrg## this for us directly.
2359586ba5aSmrg## Some versions of gcc put a space before the ':'.  On the theory
23676888252Smrg## that the space means something, we add a space to the output as
23763847c39Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23863847c39Smrg## to the object.  Take care to not repeat it in the output.
23976888252Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24076888252Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2419586ba5aSmrg  tr ' ' "$nl" < "$tmpdepfile" \
2429586ba5aSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2439586ba5aSmrg    | sed -e 's/$/ :/' >> "$depfile"
24476888252Smrg  rm -f "$tmpdepfile"
24576888252Smrg  ;;
24676888252Smrg
24776888252Smrghp)
24876888252Smrg  # This case exists only to let depend.m4 do its work.  It works by
24976888252Smrg  # looking at the text of this script.  This case will never be run,
25076888252Smrg  # since it is checked for above.
25176888252Smrg  exit 1
25276888252Smrg  ;;
25376888252Smrg
25476888252Smrgsgi)
25576888252Smrg  if test "$libtool" = yes; then
25676888252Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25776888252Smrg  else
25876888252Smrg    "$@" -MDupdate "$tmpdepfile"
25976888252Smrg  fi
26076888252Smrg  stat=$?
2619586ba5aSmrg  if test $stat -ne 0; then
26276888252Smrg    rm -f "$tmpdepfile"
26376888252Smrg    exit $stat
26476888252Smrg  fi
26576888252Smrg  rm -f "$depfile"
26676888252Smrg
26776888252Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26876888252Smrg    echo "$object : \\" > "$depfile"
26976888252Smrg    # Clip off the initial element (the dependent).  Don't try to be
27076888252Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27176888252Smrg    # lines with more than a fixed number of characters (4096 in
27276888252Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2739586ba5aSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
27476888252Smrg    # dependency line.
2759586ba5aSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2769586ba5aSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2779586ba5aSmrg      | tr "$nl" ' ' >> "$depfile"
278d8556812Smrg    echo >> "$depfile"
27976888252Smrg    # The second pass generates a dummy entry for each header file.
2809586ba5aSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2819586ba5aSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2829586ba5aSmrg      >> "$depfile"
28376888252Smrg  else
2849586ba5aSmrg    make_dummy_depfile
28576888252Smrg  fi
28676888252Smrg  rm -f "$tmpdepfile"
28776888252Smrg  ;;
28876888252Smrg
2899586ba5aSmrgxlc)
2909586ba5aSmrg  # This case exists only to let depend.m4 do its work.  It works by
2919586ba5aSmrg  # looking at the text of this script.  This case will never be run,
2929586ba5aSmrg  # since it is checked for above.
2939586ba5aSmrg  exit 1
2949586ba5aSmrg  ;;
2959586ba5aSmrg
29676888252Smrgaix)
29776888252Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29876888252Smrg  # in a .u file.  In older versions, this file always lives in the
2999586ba5aSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30076888252Smrg  # start of each line; $object doesn't have directory information.
30176888252Smrg  # Version 6 uses the directory in both cases.
3029586ba5aSmrg  set_dir_from "$object"
3039586ba5aSmrg  set_base_from "$object"
30476888252Smrg  if test "$libtool" = yes; then
30586dafe34Smrg    tmpdepfile1=$dir$base.u
30686dafe34Smrg    tmpdepfile2=$base.u
30786dafe34Smrg    tmpdepfile3=$dir.libs/$base.u
30876888252Smrg    "$@" -Wc,-M
30976888252Smrg  else
31086dafe34Smrg    tmpdepfile1=$dir$base.u
31186dafe34Smrg    tmpdepfile2=$dir$base.u
31286dafe34Smrg    tmpdepfile3=$dir$base.u
31376888252Smrg    "$@" -M
31476888252Smrg  fi
31576888252Smrg  stat=$?
3169586ba5aSmrg  if test $stat -ne 0; then
31786dafe34Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31876888252Smrg    exit $stat
31976888252Smrg  fi
32076888252Smrg
32186dafe34Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32286dafe34Smrg  do
32386dafe34Smrg    test -f "$tmpdepfile" && break
32486dafe34Smrg  done
3259586ba5aSmrg  aix_post_process_depfile
3269586ba5aSmrg  ;;
3279586ba5aSmrg
3289586ba5aSmrgtcc)
3299586ba5aSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3309586ba5aSmrg  # FIXME: That version still under development at the moment of writing.
3319586ba5aSmrg  #        Make that this statement remains true also for stable, released
3329586ba5aSmrg  #        versions.
3339586ba5aSmrg  # It will wrap lines (doesn't matter whether long or short) with a
3349586ba5aSmrg  # trailing '\', as in:
3359586ba5aSmrg  #
3369586ba5aSmrg  #   foo.o : \
3379586ba5aSmrg  #    foo.c \
3389586ba5aSmrg  #    foo.h \
3399586ba5aSmrg  #
3409586ba5aSmrg  # It will put a trailing '\' even on the last line, and will use leading
3419586ba5aSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3429586ba5aSmrg  # "Emit spaces for -MD").
3439586ba5aSmrg  "$@" -MD -MF "$tmpdepfile"
3449586ba5aSmrg  stat=$?
3459586ba5aSmrg  if test $stat -ne 0; then
3469586ba5aSmrg    rm -f "$tmpdepfile"
3479586ba5aSmrg    exit $stat
34876888252Smrg  fi
3499586ba5aSmrg  rm -f "$depfile"
3509586ba5aSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3519586ba5aSmrg  # We have to change lines of the first kind to '$object: \'.
3529586ba5aSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3539586ba5aSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3549586ba5aSmrg  # dummy dependency, to avoid the deleted-header problem.
3559586ba5aSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35676888252Smrg  rm -f "$tmpdepfile"
35776888252Smrg  ;;
35876888252Smrg
3599586ba5aSmrg## The order of this option in the case statement is important, since the
3609586ba5aSmrg## shell code in configure will try each of these formats in the order
3619586ba5aSmrg## listed in this file.  A plain '-MD' option would be understood by many
3629586ba5aSmrg## compilers, so we must ensure this comes after the gcc and icc options.
3639586ba5aSmrgpgcc)
3649586ba5aSmrg  # Portland's C compiler understands '-MD'.
3659586ba5aSmrg  # Will always output deps to 'file.d' where file is the root name of the
3669586ba5aSmrg  # source file under compilation, even if file resides in a subdirectory.
3679586ba5aSmrg  # The object file name does not affect the name of the '.d' file.
3689586ba5aSmrg  # pgcc 10.2 will output
36976888252Smrg  #    foo.o: sub/foo.c sub/foo.h
3709586ba5aSmrg  # and will wrap long lines using '\' :
37176888252Smrg  #    foo.o: sub/foo.c ... \
37276888252Smrg  #     sub/foo.h ... \
37376888252Smrg  #     ...
3749586ba5aSmrg  set_dir_from "$object"
3759586ba5aSmrg  # Use the source, not the object, to determine the base name, since
3769586ba5aSmrg  # that's sadly what pgcc will do too.
3779586ba5aSmrg  set_base_from "$source"
3789586ba5aSmrg  tmpdepfile=$base.d
3799586ba5aSmrg
3809586ba5aSmrg  # For projects that build the same source file twice into different object
3819586ba5aSmrg  # files, the pgcc approach of using the *source* file root name can cause
3829586ba5aSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3839586ba5aSmrg  # the same $tmpdepfile.
3849586ba5aSmrg  lockdir=$base.d-lock
3859586ba5aSmrg  trap "
3869586ba5aSmrg    echo '$0: caught signal, cleaning up...' >&2
3879586ba5aSmrg    rmdir '$lockdir'
3889586ba5aSmrg    exit 1
3899586ba5aSmrg  " 1 2 13 15
3909586ba5aSmrg  numtries=100
3919586ba5aSmrg  i=$numtries
3929586ba5aSmrg  while test $i -gt 0; do
3939586ba5aSmrg    # mkdir is a portable test-and-set.
3949586ba5aSmrg    if mkdir "$lockdir" 2>/dev/null; then
3959586ba5aSmrg      # This process acquired the lock.
3969586ba5aSmrg      "$@" -MD
3979586ba5aSmrg      stat=$?
3989586ba5aSmrg      # Release the lock.
3999586ba5aSmrg      rmdir "$lockdir"
4009586ba5aSmrg      break
4019586ba5aSmrg    else
4029586ba5aSmrg      # If the lock is being held by a different process, wait
4039586ba5aSmrg      # until the winning process is done or we timeout.
4049586ba5aSmrg      while test -d "$lockdir" && test $i -gt 0; do
4059586ba5aSmrg        sleep 1
4069586ba5aSmrg        i=`expr $i - 1`
4079586ba5aSmrg      done
4089586ba5aSmrg    fi
4099586ba5aSmrg    i=`expr $i - 1`
4109586ba5aSmrg  done
4119586ba5aSmrg  trap - 1 2 13 15
4129586ba5aSmrg  if test $i -le 0; then
4139586ba5aSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4149586ba5aSmrg    echo "$0: check lockdir '$lockdir'" >&2
4159586ba5aSmrg    exit 1
4169586ba5aSmrg  fi
41776888252Smrg
4189586ba5aSmrg  if test $stat -ne 0; then
41976888252Smrg    rm -f "$tmpdepfile"
42076888252Smrg    exit $stat
42176888252Smrg  fi
42276888252Smrg  rm -f "$depfile"
42376888252Smrg  # Each line is of the form `foo.o: dependent.h',
42476888252Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42576888252Smrg  # Do two passes, one to just change these to
42676888252Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42776888252Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42876888252Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42976888252Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4309586ba5aSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4319586ba5aSmrg    | sed -e 's/$/ :/' >> "$depfile"
43276888252Smrg  rm -f "$tmpdepfile"
43376888252Smrg  ;;
43476888252Smrg
4351ae1b5e8Smrghp2)
4361ae1b5e8Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4371ae1b5e8Smrg  # compilers, which have integrated preprocessors.  The correct option
4381ae1b5e8Smrg  # to use with these is +Maked; it writes dependencies to a file named
4391ae1b5e8Smrg  # 'foo.d', which lands next to the object file, wherever that
4401ae1b5e8Smrg  # happens to be.
4411ae1b5e8Smrg  # Much of this is similar to the tru64 case; see comments there.
4429586ba5aSmrg  set_dir_from  "$object"
4439586ba5aSmrg  set_base_from "$object"
4441ae1b5e8Smrg  if test "$libtool" = yes; then
4451ae1b5e8Smrg    tmpdepfile1=$dir$base.d
4461ae1b5e8Smrg    tmpdepfile2=$dir.libs/$base.d
4471ae1b5e8Smrg    "$@" -Wc,+Maked
4481ae1b5e8Smrg  else
4491ae1b5e8Smrg    tmpdepfile1=$dir$base.d
4501ae1b5e8Smrg    tmpdepfile2=$dir$base.d
4511ae1b5e8Smrg    "$@" +Maked
4521ae1b5e8Smrg  fi
4531ae1b5e8Smrg  stat=$?
4549586ba5aSmrg  if test $stat -ne 0; then
4551ae1b5e8Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4561ae1b5e8Smrg     exit $stat
4571ae1b5e8Smrg  fi
4581ae1b5e8Smrg
4591ae1b5e8Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4601ae1b5e8Smrg  do
4611ae1b5e8Smrg    test -f "$tmpdepfile" && break
4621ae1b5e8Smrg  done
4631ae1b5e8Smrg  if test -f "$tmpdepfile"; then
4649586ba5aSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4659586ba5aSmrg    # Add 'dependent.h:' lines.
466d8556812Smrg    sed -ne '2,${
4679586ba5aSmrg               s/^ *//
4689586ba5aSmrg               s/ \\*$//
4699586ba5aSmrg               s/$/:/
4709586ba5aSmrg               p
4719586ba5aSmrg             }' "$tmpdepfile" >> "$depfile"
4721ae1b5e8Smrg  else
4739586ba5aSmrg    make_dummy_depfile
4741ae1b5e8Smrg  fi
4751ae1b5e8Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4761ae1b5e8Smrg  ;;
4771ae1b5e8Smrg
47876888252Smrgtru64)
4799586ba5aSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4809586ba5aSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4819586ba5aSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4829586ba5aSmrg  # dependencies in 'foo.d' instead, so we check for that too.
4839586ba5aSmrg  # Subdirectories are respected.
4849586ba5aSmrg  set_dir_from  "$object"
4859586ba5aSmrg  set_base_from "$object"
4869586ba5aSmrg
4879586ba5aSmrg  if test "$libtool" = yes; then
4889586ba5aSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4899586ba5aSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4909586ba5aSmrg    # in $dir$base.o.d.  We have to check for both files, because
4919586ba5aSmrg    # one of the two compilations can be disabled.  We should prefer
4929586ba5aSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4939586ba5aSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
4949586ba5aSmrg    # the former would cause a distcleancheck panic.
4959586ba5aSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4969586ba5aSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4979586ba5aSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4989586ba5aSmrg    "$@" -Wc,-MD
4999586ba5aSmrg  else
5009586ba5aSmrg    tmpdepfile1=$dir$base.d
5019586ba5aSmrg    tmpdepfile2=$dir$base.d
5029586ba5aSmrg    tmpdepfile3=$dir$base.d
5039586ba5aSmrg    "$@" -MD
5049586ba5aSmrg  fi
5059586ba5aSmrg
5069586ba5aSmrg  stat=$?
5079586ba5aSmrg  if test $stat -ne 0; then
5089586ba5aSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5099586ba5aSmrg    exit $stat
5109586ba5aSmrg  fi
5119586ba5aSmrg
5129586ba5aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5139586ba5aSmrg  do
5149586ba5aSmrg    test -f "$tmpdepfile" && break
5159586ba5aSmrg  done
5169586ba5aSmrg  # Same post-processing that is required for AIX mode.
5179586ba5aSmrg  aix_post_process_depfile
5189586ba5aSmrg  ;;
51976888252Smrg
52063847c39Smrgmsvc7)
52163847c39Smrg  if test "$libtool" = yes; then
52263847c39Smrg    showIncludes=-Wc,-showIncludes
52363847c39Smrg  else
52463847c39Smrg    showIncludes=-showIncludes
52563847c39Smrg  fi
52663847c39Smrg  "$@" $showIncludes > "$tmpdepfile"
52763847c39Smrg  stat=$?
52863847c39Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5299586ba5aSmrg  if test $stat -ne 0; then
53063847c39Smrg    rm -f "$tmpdepfile"
53163847c39Smrg    exit $stat
53263847c39Smrg  fi
53363847c39Smrg  rm -f "$depfile"
53463847c39Smrg  echo "$object : \\" > "$depfile"
53563847c39Smrg  # The first sed program below extracts the file names and escapes
53663847c39Smrg  # backslashes for cygpath.  The second sed program outputs the file
53763847c39Smrg  # name when reading, but also accumulates all include files in the
53863847c39Smrg  # hold buffer in order to output them again at the end.  This only
53963847c39Smrg  # works with sed implementations that can handle large buffers.
54063847c39Smrg  sed < "$tmpdepfile" -n '
54163847c39Smrg/^Note: including file:  *\(.*\)/ {
54263847c39Smrg  s//\1/
54363847c39Smrg  s/\\/\\\\/g
54463847c39Smrg  p
54563847c39Smrg}' | $cygpath_u | sort -u | sed -n '
54663847c39Smrgs/ /\\ /g
5479586ba5aSmrgs/\(.*\)/'"$tab"'\1 \\/p
54863847c39Smrgs/.\(.*\) \\/\1:/
54963847c39SmrgH
55063847c39Smrg$ {
5519586ba5aSmrg  s/.*/'"$tab"'/
55263847c39Smrg  G
55363847c39Smrg  p
55463847c39Smrg}' >> "$depfile"
5559586ba5aSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55663847c39Smrg  rm -f "$tmpdepfile"
55763847c39Smrg  ;;
55863847c39Smrg
55963847c39Smrgmsvc7msys)
56063847c39Smrg  # This case exists only to let depend.m4 do its work.  It works by
56163847c39Smrg  # looking at the text of this script.  This case will never be run,
56263847c39Smrg  # since it is checked for above.
56363847c39Smrg  exit 1
56463847c39Smrg  ;;
56563847c39Smrg
56676888252Smrg#nosideeffect)
56776888252Smrg  # This comment above is used by automake to tell side-effect
56876888252Smrg  # dependency tracking mechanisms from slower ones.
56976888252Smrg
57076888252Smrgdashmstdout)
57176888252Smrg  # Important note: in order to support this mode, a compiler *must*
57276888252Smrg  # always write the preprocessed file to stdout, regardless of -o.
57376888252Smrg  "$@" || exit $?
57476888252Smrg
57576888252Smrg  # Remove the call to Libtool.
57676888252Smrg  if test "$libtool" = yes; then
577d8556812Smrg    while test "X$1" != 'X--mode=compile'; do
57876888252Smrg      shift
57976888252Smrg    done
58076888252Smrg    shift
58176888252Smrg  fi
58276888252Smrg
5839586ba5aSmrg  # Remove '-o $object'.
58476888252Smrg  IFS=" "
58576888252Smrg  for arg
58676888252Smrg  do
58776888252Smrg    case $arg in
58876888252Smrg    -o)
58976888252Smrg      shift
59076888252Smrg      ;;
59176888252Smrg    $object)
59276888252Smrg      shift
59376888252Smrg      ;;
59476888252Smrg    *)
59576888252Smrg      set fnord "$@" "$arg"
59676888252Smrg      shift # fnord
59776888252Smrg      shift # $arg
59876888252Smrg      ;;
59976888252Smrg    esac
60076888252Smrg  done
60176888252Smrg
60276888252Smrg  test -z "$dashmflag" && dashmflag=-M
6039586ba5aSmrg  # Require at least two characters before searching for ':'
60476888252Smrg  # in the target name.  This is to cope with DOS-style filenames:
6059586ba5aSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60676888252Smrg  "$@" $dashmflag |
6079586ba5aSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60876888252Smrg  rm -f "$depfile"
60976888252Smrg  cat < "$tmpdepfile" > "$depfile"
6109586ba5aSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6119586ba5aSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6129586ba5aSmrg  tr ' ' "$nl" < "$tmpdepfile" \
6139586ba5aSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6149586ba5aSmrg    | sed -e 's/$/ :/' >> "$depfile"
61576888252Smrg  rm -f "$tmpdepfile"
61676888252Smrg  ;;
61776888252Smrg
61876888252SmrgdashXmstdout)
61976888252Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62076888252Smrg  # run, as this mode is specially recognized in the preamble.
62176888252Smrg  exit 1
62276888252Smrg  ;;
62376888252Smrg
62476888252Smrgmakedepend)
62576888252Smrg  "$@" || exit $?
62676888252Smrg  # Remove any Libtool call
62776888252Smrg  if test "$libtool" = yes; then
628d8556812Smrg    while test "X$1" != 'X--mode=compile'; do
62976888252Smrg      shift
63076888252Smrg    done
63176888252Smrg    shift
63276888252Smrg  fi
63376888252Smrg  # X makedepend
63476888252Smrg  shift
635d8556812Smrg  cleared=no eat=no
636d8556812Smrg  for arg
637d8556812Smrg  do
63876888252Smrg    case $cleared in
63976888252Smrg    no)
64076888252Smrg      set ""; shift
64176888252Smrg      cleared=yes ;;
64276888252Smrg    esac
643d8556812Smrg    if test $eat = yes; then
644d8556812Smrg      eat=no
645d8556812Smrg      continue
646d8556812Smrg    fi
64776888252Smrg    case "$arg" in
64876888252Smrg    -D*|-I*)
64976888252Smrg      set fnord "$@" "$arg"; shift ;;
65076888252Smrg    # Strip any option that makedepend may not understand.  Remove
65176888252Smrg    # the object too, otherwise makedepend will parse it as a source file.
652d8556812Smrg    -arch)
653d8556812Smrg      eat=yes ;;
65476888252Smrg    -*|$object)
65576888252Smrg      ;;
65676888252Smrg    *)
65776888252Smrg      set fnord "$@" "$arg"; shift ;;
65876888252Smrg    esac
65976888252Smrg  done
660d8556812Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66176888252Smrg  touch "$tmpdepfile"
66276888252Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66376888252Smrg  rm -f "$depfile"
66463847c39Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66563847c39Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66663847c39Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6679586ba5aSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6689586ba5aSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6699586ba5aSmrg  sed '1,2d' "$tmpdepfile" \
6709586ba5aSmrg    | tr ' ' "$nl" \
6719586ba5aSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6729586ba5aSmrg    | sed -e 's/$/ :/' >> "$depfile"
67376888252Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67476888252Smrg  ;;
67576888252Smrg
67676888252Smrgcpp)
67776888252Smrg  # Important note: in order to support this mode, a compiler *must*
67876888252Smrg  # always write the preprocessed file to stdout.
67976888252Smrg  "$@" || exit $?
68076888252Smrg
68176888252Smrg  # Remove the call to Libtool.
68276888252Smrg  if test "$libtool" = yes; then
683d8556812Smrg    while test "X$1" != 'X--mode=compile'; do
68476888252Smrg      shift
68576888252Smrg    done
68676888252Smrg    shift
68776888252Smrg  fi
68876888252Smrg
6899586ba5aSmrg  # Remove '-o $object'.
69076888252Smrg  IFS=" "
69176888252Smrg  for arg
69276888252Smrg  do
69376888252Smrg    case $arg in
69476888252Smrg    -o)
69576888252Smrg      shift
69676888252Smrg      ;;
69776888252Smrg    $object)
69876888252Smrg      shift
69976888252Smrg      ;;
70076888252Smrg    *)
70176888252Smrg      set fnord "$@" "$arg"
70276888252Smrg      shift # fnord
70376888252Smrg      shift # $arg
70476888252Smrg      ;;
70576888252Smrg    esac
70676888252Smrg  done
70776888252Smrg
7089586ba5aSmrg  "$@" -E \
7099586ba5aSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7109586ba5aSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7119586ba5aSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
71276888252Smrg  rm -f "$depfile"
71376888252Smrg  echo "$object : \\" > "$depfile"
71476888252Smrg  cat < "$tmpdepfile" >> "$depfile"
71576888252Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71676888252Smrg  rm -f "$tmpdepfile"
71776888252Smrg  ;;
71876888252Smrg
71976888252Smrgmsvisualcpp)
72076888252Smrg  # Important note: in order to support this mode, a compiler *must*
721d8556812Smrg  # always write the preprocessed file to stdout.
72276888252Smrg  "$@" || exit $?
723d8556812Smrg
724d8556812Smrg  # Remove the call to Libtool.
725d8556812Smrg  if test "$libtool" = yes; then
726d8556812Smrg    while test "X$1" != 'X--mode=compile'; do
727d8556812Smrg      shift
728d8556812Smrg    done
729d8556812Smrg    shift
730d8556812Smrg  fi
731d8556812Smrg
73276888252Smrg  IFS=" "
73376888252Smrg  for arg
73476888252Smrg  do
73576888252Smrg    case "$arg" in
736d8556812Smrg    -o)
737d8556812Smrg      shift
738d8556812Smrg      ;;
739d8556812Smrg    $object)
740d8556812Smrg      shift
741d8556812Smrg      ;;
74276888252Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7439586ba5aSmrg        set fnord "$@"
7449586ba5aSmrg        shift
7459586ba5aSmrg        shift
7469586ba5aSmrg        ;;
74776888252Smrg    *)
7489586ba5aSmrg        set fnord "$@" "$arg"
7499586ba5aSmrg        shift
7509586ba5aSmrg        shift
7519586ba5aSmrg        ;;
75276888252Smrg    esac
75376888252Smrg  done
754d8556812Smrg  "$@" -E 2>/dev/null |
755d8556812Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75676888252Smrg  rm -f "$depfile"
75776888252Smrg  echo "$object : \\" > "$depfile"
7589586ba5aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7599586ba5aSmrg  echo "$tab" >> "$depfile"
760d8556812Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76176888252Smrg  rm -f "$tmpdepfile"
76276888252Smrg  ;;
76376888252Smrg
764d8556812Smrgmsvcmsys)
765d8556812Smrg  # This case exists only to let depend.m4 do its work.  It works by
766d8556812Smrg  # looking at the text of this script.  This case will never be run,
767d8556812Smrg  # since it is checked for above.
768d8556812Smrg  exit 1
769d8556812Smrg  ;;
770d8556812Smrg
77176888252Smrgnone)
77276888252Smrg  exec "$@"
77376888252Smrg  ;;
77476888252Smrg
77576888252Smrg*)
77676888252Smrg  echo "Unknown depmode $depmode" 1>&2
77776888252Smrg  exit 1
77876888252Smrg  ;;
77976888252Smrgesac
78076888252Smrg
78176888252Smrgexit 0
78276888252Smrg
78376888252Smrg# Local Variables:
78476888252Smrg# mode: shell-script
78576888252Smrg# sh-indentation: 2
7860814a2baSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
78776888252Smrg# time-stamp-start: "scriptversion="
78876888252Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7890814a2baSmrg# time-stamp-time-zone: "UTC0"
790d8556812Smrg# time-stamp-end: "; # UTC"
79176888252Smrg# End:
792