depcomp revision bdc460c5
114c0a534Smrg#! /bin/sh
214c0a534Smrg# depcomp - compile a program generating dependencies as side-effects
314c0a534Smrg
4bdc460c5Smrgscriptversion=2018-03-07.03; # UTC
514c0a534Smrg
6bdc460c5Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
714c0a534Smrg
814c0a534Smrg# This program is free software; you can redistribute it and/or modify
914c0a534Smrg# it under the terms of the GNU General Public License as published by
1014c0a534Smrg# the Free Software Foundation; either version 2, or (at your option)
1114c0a534Smrg# any later version.
1214c0a534Smrg
1314c0a534Smrg# This program is distributed in the hope that it will be useful,
1414c0a534Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1514c0a534Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1614c0a534Smrg# GNU General Public License for more details.
1714c0a534Smrg
1814c0a534Smrg# You should have received a copy of the GNU General Public License
19bdc460c5Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2014c0a534Smrg
2114c0a534Smrg# As a special exception to the GNU General Public License, if you
2214c0a534Smrg# distribute this file as part of a program that contains a
2314c0a534Smrg# configuration script generated by Autoconf, you may include it under
2414c0a534Smrg# the same distribution terms that you use for the rest of that program.
2514c0a534Smrg
2614c0a534Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2714c0a534Smrg
2814c0a534Smrgcase $1 in
2914c0a534Smrg  '')
3024047306Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3124047306Smrg    exit 1;
3224047306Smrg    ;;
3314c0a534Smrg  -h | --h*)
3414c0a534Smrg    cat <<\EOF
3514c0a534SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3614c0a534Smrg
3714c0a534SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3814c0a534Smrgas side-effects.
3914c0a534Smrg
4014c0a534SmrgEnvironment variables:
4114c0a534Smrg  depmode     Dependency tracking mode.
4224047306Smrg  source      Source file read by 'PROGRAMS ARGS'.
4324047306Smrg  object      Object file output by 'PROGRAMS ARGS'.
4414c0a534Smrg  DEPDIR      directory where to store dependencies.
4514c0a534Smrg  depfile     Dependency file to output.
4624047306Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4714c0a534Smrg  libtool     Whether libtool is used (yes/no).
4814c0a534Smrg
4914c0a534SmrgReport bugs to <bug-automake@gnu.org>.
5014c0a534SmrgEOF
5114c0a534Smrg    exit $?
5214c0a534Smrg    ;;
5314c0a534Smrg  -v | --v*)
5414c0a534Smrg    echo "depcomp $scriptversion"
5514c0a534Smrg    exit $?
5614c0a534Smrg    ;;
5714c0a534Smrgesac
5814c0a534Smrg
5924047306Smrg# Get the directory component of the given path, and save it in the
6024047306Smrg# global variables '$dir'.  Note that this directory component will
6124047306Smrg# be either empty or ending with a '/' character.  This is deliberate.
6224047306Smrgset_dir_from ()
6324047306Smrg{
6424047306Smrg  case $1 in
6524047306Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6624047306Smrg      *) dir=;;
6724047306Smrg  esac
6824047306Smrg}
6924047306Smrg
7024047306Smrg# Get the suffix-stripped basename of the given path, and save it the
7124047306Smrg# global variable '$base'.
7224047306Smrgset_base_from ()
7324047306Smrg{
7424047306Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7524047306Smrg}
7624047306Smrg
7724047306Smrg# If no dependency file was actually created by the compiler invocation,
7824047306Smrg# we still have to create a dummy depfile, to avoid errors with the
7924047306Smrg# Makefile "include basename.Plo" scheme.
8024047306Smrgmake_dummy_depfile ()
8124047306Smrg{
8224047306Smrg  echo "#dummy" > "$depfile"
8324047306Smrg}
8424047306Smrg
8524047306Smrg# Factor out some common post-processing of the generated depfile.
8624047306Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8724047306Smrgaix_post_process_depfile ()
8824047306Smrg{
8924047306Smrg  # If the compiler actually managed to produce a dependency file,
9024047306Smrg  # post-process it.
9124047306Smrg  if test -f "$tmpdepfile"; then
9224047306Smrg    # Each line is of the form 'foo.o: dependency.h'.
9324047306Smrg    # Do two passes, one to just change these to
9424047306Smrg    #   $object: dependency.h
9524047306Smrg    # and one to simply output
9624047306Smrg    #   dependency.h:
9724047306Smrg    # which is needed to avoid the deleted-header problem.
9824047306Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9924047306Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10024047306Smrg    } > "$depfile"
10124047306Smrg    rm -f "$tmpdepfile"
10224047306Smrg  else
10324047306Smrg    make_dummy_depfile
10424047306Smrg  fi
10524047306Smrg}
10624047306Smrg
10724047306Smrg# A tabulation character.
10824047306Smrgtab='	'
10924047306Smrg# A newline character.
11024047306Smrgnl='
11124047306Smrg'
11224047306Smrg# Character ranges might be problematic outside the C locale.
11324047306Smrg# These definitions help.
11424047306Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11524047306Smrglower=abcdefghijklmnopqrstuvwxyz
11624047306Smrgdigits=0123456789
11724047306Smrgalpha=${upper}${lower}
11824047306Smrg
11914c0a534Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12014c0a534Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12114c0a534Smrg  exit 1
12214c0a534Smrgfi
12314c0a534Smrg
12414c0a534Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12514c0a534Smrgdepfile=${depfile-`echo "$object" |
12614c0a534Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12714c0a534Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12814c0a534Smrg
12914c0a534Smrgrm -f "$tmpdepfile"
13014c0a534Smrg
13124047306Smrg# Avoid interferences from the environment.
13224047306Smrggccflag= dashmflag=
13324047306Smrg
13414c0a534Smrg# Some modes work just like other modes, but use different flags.  We
13514c0a534Smrg# parameterize here, but still list the modes in the big case below,
13614c0a534Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13714c0a534Smrg# here, because this file can only contain one case statement.
13814c0a534Smrgif test "$depmode" = hp; then
13914c0a534Smrg  # HP compiler uses -M and no extra arg.
14014c0a534Smrg  gccflag=-M
14114c0a534Smrg  depmode=gcc
14214c0a534Smrgfi
14314c0a534Smrg
14414c0a534Smrgif test "$depmode" = dashXmstdout; then
14524047306Smrg  # This is just like dashmstdout with a different argument.
14624047306Smrg  dashmflag=-xM
14724047306Smrg  depmode=dashmstdout
14814c0a534Smrgfi
14914c0a534Smrg
150bf2eeab3Smrgcygpath_u="cygpath -u -f -"
151bf2eeab3Smrgif test "$depmode" = msvcmsys; then
15224047306Smrg  # This is just like msvisualcpp but w/o cygpath translation.
15324047306Smrg  # Just convert the backslash-escaped backslashes to single forward
15424047306Smrg  # slashes to satisfy depend.m4
15524047306Smrg  cygpath_u='sed s,\\\\,/,g'
15624047306Smrg  depmode=msvisualcpp
15724047306Smrgfi
15824047306Smrg
15924047306Smrgif test "$depmode" = msvc7msys; then
16024047306Smrg  # This is just like msvc7 but w/o cygpath translation.
16124047306Smrg  # Just convert the backslash-escaped backslashes to single forward
16224047306Smrg  # slashes to satisfy depend.m4
16324047306Smrg  cygpath_u='sed s,\\\\,/,g'
16424047306Smrg  depmode=msvc7
16524047306Smrgfi
16624047306Smrg
16724047306Smrgif test "$depmode" = xlc; then
16824047306Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16924047306Smrg  gccflag=-qmakedep=gcc,-MF
17024047306Smrg  depmode=gcc
171bf2eeab3Smrgfi
172bf2eeab3Smrg
17314c0a534Smrgcase "$depmode" in
17414c0a534Smrggcc3)
17514c0a534Smrg## gcc 3 implements dependency tracking that does exactly what
17614c0a534Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17714c0a534Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178bf2eeab3Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179bf2eeab3Smrg## the command line argument order; so add the flags where they
180bf2eeab3Smrg## appear in depend2.am.  Note that the slowdown incurred here
181bf2eeab3Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182bf2eeab3Smrg  for arg
183bf2eeab3Smrg  do
184bf2eeab3Smrg    case $arg in
185bf2eeab3Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186bf2eeab3Smrg    *)  set fnord "$@" "$arg" ;;
187bf2eeab3Smrg    esac
188bf2eeab3Smrg    shift # fnord
189bf2eeab3Smrg    shift # $arg
190bf2eeab3Smrg  done
191bf2eeab3Smrg  "$@"
19214c0a534Smrg  stat=$?
19324047306Smrg  if test $stat -ne 0; then
19414c0a534Smrg    rm -f "$tmpdepfile"
19514c0a534Smrg    exit $stat
19614c0a534Smrg  fi
19714c0a534Smrg  mv "$tmpdepfile" "$depfile"
19814c0a534Smrg  ;;
19914c0a534Smrg
20014c0a534Smrggcc)
20124047306Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20224047306Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20324047306Smrg## (see the conditional assignment to $gccflag above).
20414c0a534Smrg## There are various ways to get dependency output from gcc.  Here's
20514c0a534Smrg## why we pick this rather obscure method:
20614c0a534Smrg## - Don't want to use -MD because we'd like the dependencies to end
20714c0a534Smrg##   up in a subdir.  Having to rename by hand is ugly.
20814c0a534Smrg##   (We might end up doing this anyway to support other compilers.)
20914c0a534Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21024047306Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21124047306Smrg##   supported by the other compilers which use the 'gcc' depmode.
21214c0a534Smrg## - Using -M directly means running the compiler twice (even worse
21314c0a534Smrg##   than renaming).
21414c0a534Smrg  if test -z "$gccflag"; then
21514c0a534Smrg    gccflag=-MD,
21614c0a534Smrg  fi
21714c0a534Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21814c0a534Smrg  stat=$?
21924047306Smrg  if test $stat -ne 0; then
22014c0a534Smrg    rm -f "$tmpdepfile"
22114c0a534Smrg    exit $stat
22214c0a534Smrg  fi
22314c0a534Smrg  rm -f "$depfile"
22414c0a534Smrg  echo "$object : \\" > "$depfile"
22524047306Smrg  # The second -e expression handles DOS-style file names with drive
22624047306Smrg  # letters.
22714c0a534Smrg  sed -e 's/^[^:]*: / /' \
22814c0a534Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22924047306Smrg## This next piece of magic avoids the "deleted header file" problem.
23014c0a534Smrg## The problem is that when a header file which appears in a .P file
23114c0a534Smrg## is deleted, the dependency causes make to die (because there is
23214c0a534Smrg## typically no way to rebuild the header).  We avoid this by adding
23314c0a534Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23414c0a534Smrg## this for us directly.
23524047306Smrg## Some versions of gcc put a space before the ':'.  On the theory
23614c0a534Smrg## that the space means something, we add a space to the output as
23724047306Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23824047306Smrg## to the object.  Take care to not repeat it in the output.
23914c0a534Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24014c0a534Smrg## correctly.  Breaking it into two sed invocations is a workaround.
24124047306Smrg  tr ' ' "$nl" < "$tmpdepfile" \
24224047306Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24324047306Smrg    | sed -e 's/$/ :/' >> "$depfile"
24414c0a534Smrg  rm -f "$tmpdepfile"
24514c0a534Smrg  ;;
24614c0a534Smrg
24714c0a534Smrghp)
24814c0a534Smrg  # This case exists only to let depend.m4 do its work.  It works by
24914c0a534Smrg  # looking at the text of this script.  This case will never be run,
25014c0a534Smrg  # since it is checked for above.
25114c0a534Smrg  exit 1
25214c0a534Smrg  ;;
25314c0a534Smrg
25414c0a534Smrgsgi)
25514c0a534Smrg  if test "$libtool" = yes; then
25614c0a534Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25714c0a534Smrg  else
25814c0a534Smrg    "$@" -MDupdate "$tmpdepfile"
25914c0a534Smrg  fi
26014c0a534Smrg  stat=$?
26124047306Smrg  if test $stat -ne 0; then
26214c0a534Smrg    rm -f "$tmpdepfile"
26314c0a534Smrg    exit $stat
26414c0a534Smrg  fi
26514c0a534Smrg  rm -f "$depfile"
26614c0a534Smrg
26714c0a534Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26814c0a534Smrg    echo "$object : \\" > "$depfile"
26914c0a534Smrg    # Clip off the initial element (the dependent).  Don't try to be
27014c0a534Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27114c0a534Smrg    # lines with more than a fixed number of characters (4096 in
27214c0a534Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27324047306Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27414c0a534Smrg    # dependency line.
27524047306Smrg    tr ' ' "$nl" < "$tmpdepfile" \
27624047306Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27724047306Smrg      | tr "$nl" ' ' >> "$depfile"
278bf2eeab3Smrg    echo >> "$depfile"
27914c0a534Smrg    # The second pass generates a dummy entry for each header file.
28024047306Smrg    tr ' ' "$nl" < "$tmpdepfile" \
28124047306Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28224047306Smrg      >> "$depfile"
28314c0a534Smrg  else
28424047306Smrg    make_dummy_depfile
28514c0a534Smrg  fi
28614c0a534Smrg  rm -f "$tmpdepfile"
28714c0a534Smrg  ;;
28814c0a534Smrg
28924047306Smrgxlc)
29024047306Smrg  # This case exists only to let depend.m4 do its work.  It works by
29124047306Smrg  # looking at the text of this script.  This case will never be run,
29224047306Smrg  # since it is checked for above.
29324047306Smrg  exit 1
29424047306Smrg  ;;
29524047306Smrg
29614c0a534Smrgaix)
29714c0a534Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29814c0a534Smrg  # in a .u file.  In older versions, this file always lives in the
29924047306Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30014c0a534Smrg  # start of each line; $object doesn't have directory information.
30114c0a534Smrg  # Version 6 uses the directory in both cases.
30224047306Smrg  set_dir_from "$object"
30324047306Smrg  set_base_from "$object"
30414c0a534Smrg  if test "$libtool" = yes; then
305bf2eeab3Smrg    tmpdepfile1=$dir$base.u
306bf2eeab3Smrg    tmpdepfile2=$base.u
307bf2eeab3Smrg    tmpdepfile3=$dir.libs/$base.u
30814c0a534Smrg    "$@" -Wc,-M
30914c0a534Smrg  else
310bf2eeab3Smrg    tmpdepfile1=$dir$base.u
311bf2eeab3Smrg    tmpdepfile2=$dir$base.u
312bf2eeab3Smrg    tmpdepfile3=$dir$base.u
31314c0a534Smrg    "$@" -M
31414c0a534Smrg  fi
31514c0a534Smrg  stat=$?
31624047306Smrg  if test $stat -ne 0; then
317bf2eeab3Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31814c0a534Smrg    exit $stat
31914c0a534Smrg  fi
32014c0a534Smrg
321bf2eeab3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322bf2eeab3Smrg  do
323bf2eeab3Smrg    test -f "$tmpdepfile" && break
324bf2eeab3Smrg  done
32524047306Smrg  aix_post_process_depfile
32624047306Smrg  ;;
32724047306Smrg
32824047306Smrgtcc)
32924047306Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33024047306Smrg  # FIXME: That version still under development at the moment of writing.
33124047306Smrg  #        Make that this statement remains true also for stable, released
33224047306Smrg  #        versions.
33324047306Smrg  # It will wrap lines (doesn't matter whether long or short) with a
33424047306Smrg  # trailing '\', as in:
33524047306Smrg  #
33624047306Smrg  #   foo.o : \
33724047306Smrg  #    foo.c \
33824047306Smrg  #    foo.h \
33924047306Smrg  #
34024047306Smrg  # It will put a trailing '\' even on the last line, and will use leading
34124047306Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34224047306Smrg  # "Emit spaces for -MD").
34324047306Smrg  "$@" -MD -MF "$tmpdepfile"
34424047306Smrg  stat=$?
34524047306Smrg  if test $stat -ne 0; then
34624047306Smrg    rm -f "$tmpdepfile"
34724047306Smrg    exit $stat
34814c0a534Smrg  fi
34924047306Smrg  rm -f "$depfile"
35024047306Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35124047306Smrg  # We have to change lines of the first kind to '$object: \'.
35224047306Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35324047306Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35424047306Smrg  # dummy dependency, to avoid the deleted-header problem.
35524047306Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35614c0a534Smrg  rm -f "$tmpdepfile"
35714c0a534Smrg  ;;
35814c0a534Smrg
35924047306Smrg## The order of this option in the case statement is important, since the
36024047306Smrg## shell code in configure will try each of these formats in the order
36124047306Smrg## listed in this file.  A plain '-MD' option would be understood by many
36224047306Smrg## compilers, so we must ensure this comes after the gcc and icc options.
36324047306Smrgpgcc)
36424047306Smrg  # Portland's C compiler understands '-MD'.
36524047306Smrg  # Will always output deps to 'file.d' where file is the root name of the
36624047306Smrg  # source file under compilation, even if file resides in a subdirectory.
36724047306Smrg  # The object file name does not affect the name of the '.d' file.
36824047306Smrg  # pgcc 10.2 will output
36914c0a534Smrg  #    foo.o: sub/foo.c sub/foo.h
37024047306Smrg  # and will wrap long lines using '\' :
37114c0a534Smrg  #    foo.o: sub/foo.c ... \
37214c0a534Smrg  #     sub/foo.h ... \
37314c0a534Smrg  #     ...
37424047306Smrg  set_dir_from "$object"
37524047306Smrg  # Use the source, not the object, to determine the base name, since
37624047306Smrg  # that's sadly what pgcc will do too.
37724047306Smrg  set_base_from "$source"
37824047306Smrg  tmpdepfile=$base.d
37924047306Smrg
38024047306Smrg  # For projects that build the same source file twice into different object
38124047306Smrg  # files, the pgcc approach of using the *source* file root name can cause
38224047306Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38324047306Smrg  # the same $tmpdepfile.
38424047306Smrg  lockdir=$base.d-lock
38524047306Smrg  trap "
38624047306Smrg    echo '$0: caught signal, cleaning up...' >&2
38724047306Smrg    rmdir '$lockdir'
38824047306Smrg    exit 1
38924047306Smrg  " 1 2 13 15
39024047306Smrg  numtries=100
39124047306Smrg  i=$numtries
39224047306Smrg  while test $i -gt 0; do
39324047306Smrg    # mkdir is a portable test-and-set.
39424047306Smrg    if mkdir "$lockdir" 2>/dev/null; then
39524047306Smrg      # This process acquired the lock.
39624047306Smrg      "$@" -MD
39724047306Smrg      stat=$?
39824047306Smrg      # Release the lock.
39924047306Smrg      rmdir "$lockdir"
40024047306Smrg      break
40124047306Smrg    else
40224047306Smrg      # If the lock is being held by a different process, wait
40324047306Smrg      # until the winning process is done or we timeout.
40424047306Smrg      while test -d "$lockdir" && test $i -gt 0; do
40524047306Smrg        sleep 1
40624047306Smrg        i=`expr $i - 1`
40724047306Smrg      done
40824047306Smrg    fi
40924047306Smrg    i=`expr $i - 1`
41024047306Smrg  done
41124047306Smrg  trap - 1 2 13 15
41224047306Smrg  if test $i -le 0; then
41324047306Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41424047306Smrg    echo "$0: check lockdir '$lockdir'" >&2
41524047306Smrg    exit 1
41624047306Smrg  fi
41714c0a534Smrg
41824047306Smrg  if test $stat -ne 0; then
41914c0a534Smrg    rm -f "$tmpdepfile"
42014c0a534Smrg    exit $stat
42114c0a534Smrg  fi
42214c0a534Smrg  rm -f "$depfile"
42314c0a534Smrg  # Each line is of the form `foo.o: dependent.h',
42414c0a534Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42514c0a534Smrg  # Do two passes, one to just change these to
42614c0a534Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42714c0a534Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42814c0a534Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42914c0a534Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
43024047306Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43124047306Smrg    | sed -e 's/$/ :/' >> "$depfile"
43214c0a534Smrg  rm -f "$tmpdepfile"
43314c0a534Smrg  ;;
43414c0a534Smrg
435bf2eeab3Smrghp2)
436bf2eeab3Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437bf2eeab3Smrg  # compilers, which have integrated preprocessors.  The correct option
438bf2eeab3Smrg  # to use with these is +Maked; it writes dependencies to a file named
439bf2eeab3Smrg  # 'foo.d', which lands next to the object file, wherever that
440bf2eeab3Smrg  # happens to be.
441bf2eeab3Smrg  # Much of this is similar to the tru64 case; see comments there.
44224047306Smrg  set_dir_from  "$object"
44324047306Smrg  set_base_from "$object"
444bf2eeab3Smrg  if test "$libtool" = yes; then
445bf2eeab3Smrg    tmpdepfile1=$dir$base.d
446bf2eeab3Smrg    tmpdepfile2=$dir.libs/$base.d
447bf2eeab3Smrg    "$@" -Wc,+Maked
448bf2eeab3Smrg  else
449bf2eeab3Smrg    tmpdepfile1=$dir$base.d
450bf2eeab3Smrg    tmpdepfile2=$dir$base.d
451bf2eeab3Smrg    "$@" +Maked
452bf2eeab3Smrg  fi
453bf2eeab3Smrg  stat=$?
45424047306Smrg  if test $stat -ne 0; then
455bf2eeab3Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456bf2eeab3Smrg     exit $stat
457bf2eeab3Smrg  fi
458bf2eeab3Smrg
459bf2eeab3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460bf2eeab3Smrg  do
461bf2eeab3Smrg    test -f "$tmpdepfile" && break
462bf2eeab3Smrg  done
463bf2eeab3Smrg  if test -f "$tmpdepfile"; then
46424047306Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46524047306Smrg    # Add 'dependent.h:' lines.
466bf2eeab3Smrg    sed -ne '2,${
46724047306Smrg               s/^ *//
46824047306Smrg               s/ \\*$//
46924047306Smrg               s/$/:/
47024047306Smrg               p
47124047306Smrg             }' "$tmpdepfile" >> "$depfile"
472bf2eeab3Smrg  else
47324047306Smrg    make_dummy_depfile
474bf2eeab3Smrg  fi
475bf2eeab3Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476bf2eeab3Smrg  ;;
477bf2eeab3Smrg
47814c0a534Smrgtru64)
47924047306Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48024047306Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48124047306Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48224047306Smrg  # dependencies in 'foo.d' instead, so we check for that too.
48324047306Smrg  # Subdirectories are respected.
48424047306Smrg  set_dir_from  "$object"
48524047306Smrg  set_base_from "$object"
48624047306Smrg
48724047306Smrg  if test "$libtool" = yes; then
48824047306Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48924047306Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49024047306Smrg    # in $dir$base.o.d.  We have to check for both files, because
49124047306Smrg    # one of the two compilations can be disabled.  We should prefer
49224047306Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49324047306Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
49424047306Smrg    # the former would cause a distcleancheck panic.
49524047306Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49624047306Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49724047306Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49824047306Smrg    "$@" -Wc,-MD
49924047306Smrg  else
50024047306Smrg    tmpdepfile1=$dir$base.d
50124047306Smrg    tmpdepfile2=$dir$base.d
50224047306Smrg    tmpdepfile3=$dir$base.d
50324047306Smrg    "$@" -MD
50424047306Smrg  fi
50524047306Smrg
50624047306Smrg  stat=$?
50724047306Smrg  if test $stat -ne 0; then
50824047306Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50924047306Smrg    exit $stat
51024047306Smrg  fi
51124047306Smrg
51224047306Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51324047306Smrg  do
51424047306Smrg    test -f "$tmpdepfile" && break
51524047306Smrg  done
51624047306Smrg  # Same post-processing that is required for AIX mode.
51724047306Smrg  aix_post_process_depfile
51824047306Smrg  ;;
51924047306Smrg
52024047306Smrgmsvc7)
52124047306Smrg  if test "$libtool" = yes; then
52224047306Smrg    showIncludes=-Wc,-showIncludes
52324047306Smrg  else
52424047306Smrg    showIncludes=-showIncludes
52524047306Smrg  fi
52624047306Smrg  "$@" $showIncludes > "$tmpdepfile"
52724047306Smrg  stat=$?
52824047306Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
52924047306Smrg  if test $stat -ne 0; then
53024047306Smrg    rm -f "$tmpdepfile"
53124047306Smrg    exit $stat
53224047306Smrg  fi
53324047306Smrg  rm -f "$depfile"
53424047306Smrg  echo "$object : \\" > "$depfile"
53524047306Smrg  # The first sed program below extracts the file names and escapes
53624047306Smrg  # backslashes for cygpath.  The second sed program outputs the file
53724047306Smrg  # name when reading, but also accumulates all include files in the
53824047306Smrg  # hold buffer in order to output them again at the end.  This only
53924047306Smrg  # works with sed implementations that can handle large buffers.
54024047306Smrg  sed < "$tmpdepfile" -n '
54124047306Smrg/^Note: including file:  *\(.*\)/ {
54224047306Smrg  s//\1/
54324047306Smrg  s/\\/\\\\/g
54424047306Smrg  p
54524047306Smrg}' | $cygpath_u | sort -u | sed -n '
54624047306Smrgs/ /\\ /g
54724047306Smrgs/\(.*\)/'"$tab"'\1 \\/p
54824047306Smrgs/.\(.*\) \\/\1:/
54924047306SmrgH
55024047306Smrg$ {
55124047306Smrg  s/.*/'"$tab"'/
55224047306Smrg  G
55324047306Smrg  p
55424047306Smrg}' >> "$depfile"
55524047306Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55624047306Smrg  rm -f "$tmpdepfile"
55724047306Smrg  ;;
55824047306Smrg
55924047306Smrgmsvc7msys)
56024047306Smrg  # This case exists only to let depend.m4 do its work.  It works by
56124047306Smrg  # looking at the text of this script.  This case will never be run,
56224047306Smrg  # since it is checked for above.
56324047306Smrg  exit 1
56424047306Smrg  ;;
56514c0a534Smrg
56614c0a534Smrg#nosideeffect)
56714c0a534Smrg  # This comment above is used by automake to tell side-effect
56814c0a534Smrg  # dependency tracking mechanisms from slower ones.
56914c0a534Smrg
57014c0a534Smrgdashmstdout)
57114c0a534Smrg  # Important note: in order to support this mode, a compiler *must*
57214c0a534Smrg  # always write the preprocessed file to stdout, regardless of -o.
57314c0a534Smrg  "$@" || exit $?
57414c0a534Smrg
57514c0a534Smrg  # Remove the call to Libtool.
57614c0a534Smrg  if test "$libtool" = yes; then
577bf2eeab3Smrg    while test "X$1" != 'X--mode=compile'; do
57814c0a534Smrg      shift
57914c0a534Smrg    done
58014c0a534Smrg    shift
58114c0a534Smrg  fi
58214c0a534Smrg
58324047306Smrg  # Remove '-o $object'.
58414c0a534Smrg  IFS=" "
58514c0a534Smrg  for arg
58614c0a534Smrg  do
58714c0a534Smrg    case $arg in
58814c0a534Smrg    -o)
58914c0a534Smrg      shift
59014c0a534Smrg      ;;
59114c0a534Smrg    $object)
59214c0a534Smrg      shift
59314c0a534Smrg      ;;
59414c0a534Smrg    *)
59514c0a534Smrg      set fnord "$@" "$arg"
59614c0a534Smrg      shift # fnord
59714c0a534Smrg      shift # $arg
59814c0a534Smrg      ;;
59914c0a534Smrg    esac
60014c0a534Smrg  done
60114c0a534Smrg
60214c0a534Smrg  test -z "$dashmflag" && dashmflag=-M
60324047306Smrg  # Require at least two characters before searching for ':'
60414c0a534Smrg  # in the target name.  This is to cope with DOS-style filenames:
60524047306Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60614c0a534Smrg  "$@" $dashmflag |
60724047306Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60814c0a534Smrg  rm -f "$depfile"
60914c0a534Smrg  cat < "$tmpdepfile" > "$depfile"
61024047306Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61124047306Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
61224047306Smrg  tr ' ' "$nl" < "$tmpdepfile" \
61324047306Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61424047306Smrg    | sed -e 's/$/ :/' >> "$depfile"
61514c0a534Smrg  rm -f "$tmpdepfile"
61614c0a534Smrg  ;;
61714c0a534Smrg
61814c0a534SmrgdashXmstdout)
61914c0a534Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62014c0a534Smrg  # run, as this mode is specially recognized in the preamble.
62114c0a534Smrg  exit 1
62214c0a534Smrg  ;;
62314c0a534Smrg
62414c0a534Smrgmakedepend)
62514c0a534Smrg  "$@" || exit $?
62614c0a534Smrg  # Remove any Libtool call
62714c0a534Smrg  if test "$libtool" = yes; then
628bf2eeab3Smrg    while test "X$1" != 'X--mode=compile'; do
62914c0a534Smrg      shift
63014c0a534Smrg    done
63114c0a534Smrg    shift
63214c0a534Smrg  fi
63314c0a534Smrg  # X makedepend
63414c0a534Smrg  shift
635bf2eeab3Smrg  cleared=no eat=no
636bf2eeab3Smrg  for arg
637bf2eeab3Smrg  do
63814c0a534Smrg    case $cleared in
63914c0a534Smrg    no)
64014c0a534Smrg      set ""; shift
64114c0a534Smrg      cleared=yes ;;
64214c0a534Smrg    esac
643bf2eeab3Smrg    if test $eat = yes; then
644bf2eeab3Smrg      eat=no
645bf2eeab3Smrg      continue
646bf2eeab3Smrg    fi
64714c0a534Smrg    case "$arg" in
64814c0a534Smrg    -D*|-I*)
64914c0a534Smrg      set fnord "$@" "$arg"; shift ;;
65014c0a534Smrg    # Strip any option that makedepend may not understand.  Remove
65114c0a534Smrg    # the object too, otherwise makedepend will parse it as a source file.
652bf2eeab3Smrg    -arch)
653bf2eeab3Smrg      eat=yes ;;
65414c0a534Smrg    -*|$object)
65514c0a534Smrg      ;;
65614c0a534Smrg    *)
65714c0a534Smrg      set fnord "$@" "$arg"; shift ;;
65814c0a534Smrg    esac
65914c0a534Smrg  done
660bf2eeab3Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66114c0a534Smrg  touch "$tmpdepfile"
66214c0a534Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66314c0a534Smrg  rm -f "$depfile"
66424047306Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66524047306Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66624047306Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66724047306Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66824047306Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
66924047306Smrg  sed '1,2d' "$tmpdepfile" \
67024047306Smrg    | tr ' ' "$nl" \
67124047306Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67224047306Smrg    | sed -e 's/$/ :/' >> "$depfile"
67314c0a534Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67414c0a534Smrg  ;;
67514c0a534Smrg
67614c0a534Smrgcpp)
67714c0a534Smrg  # Important note: in order to support this mode, a compiler *must*
67814c0a534Smrg  # always write the preprocessed file to stdout.
67914c0a534Smrg  "$@" || exit $?
68014c0a534Smrg
68114c0a534Smrg  # Remove the call to Libtool.
68214c0a534Smrg  if test "$libtool" = yes; then
683bf2eeab3Smrg    while test "X$1" != 'X--mode=compile'; do
68414c0a534Smrg      shift
68514c0a534Smrg    done
68614c0a534Smrg    shift
68714c0a534Smrg  fi
68814c0a534Smrg
68924047306Smrg  # Remove '-o $object'.
69014c0a534Smrg  IFS=" "
69114c0a534Smrg  for arg
69214c0a534Smrg  do
69314c0a534Smrg    case $arg in
69414c0a534Smrg    -o)
69514c0a534Smrg      shift
69614c0a534Smrg      ;;
69714c0a534Smrg    $object)
69814c0a534Smrg      shift
69914c0a534Smrg      ;;
70014c0a534Smrg    *)
70114c0a534Smrg      set fnord "$@" "$arg"
70214c0a534Smrg      shift # fnord
70314c0a534Smrg      shift # $arg
70414c0a534Smrg      ;;
70514c0a534Smrg    esac
70614c0a534Smrg  done
70714c0a534Smrg
70824047306Smrg  "$@" -E \
70924047306Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71024047306Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71124047306Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71214c0a534Smrg  rm -f "$depfile"
71314c0a534Smrg  echo "$object : \\" > "$depfile"
71414c0a534Smrg  cat < "$tmpdepfile" >> "$depfile"
71514c0a534Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71614c0a534Smrg  rm -f "$tmpdepfile"
71714c0a534Smrg  ;;
71814c0a534Smrg
71914c0a534Smrgmsvisualcpp)
72014c0a534Smrg  # Important note: in order to support this mode, a compiler *must*
721bf2eeab3Smrg  # always write the preprocessed file to stdout.
72214c0a534Smrg  "$@" || exit $?
723bf2eeab3Smrg
724bf2eeab3Smrg  # Remove the call to Libtool.
725bf2eeab3Smrg  if test "$libtool" = yes; then
726bf2eeab3Smrg    while test "X$1" != 'X--mode=compile'; do
727bf2eeab3Smrg      shift
728bf2eeab3Smrg    done
729bf2eeab3Smrg    shift
730bf2eeab3Smrg  fi
731bf2eeab3Smrg
73214c0a534Smrg  IFS=" "
73314c0a534Smrg  for arg
73414c0a534Smrg  do
73514c0a534Smrg    case "$arg" in
736bf2eeab3Smrg    -o)
737bf2eeab3Smrg      shift
738bf2eeab3Smrg      ;;
739bf2eeab3Smrg    $object)
740bf2eeab3Smrg      shift
741bf2eeab3Smrg      ;;
74214c0a534Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74324047306Smrg        set fnord "$@"
74424047306Smrg        shift
74524047306Smrg        shift
74624047306Smrg        ;;
74714c0a534Smrg    *)
74824047306Smrg        set fnord "$@" "$arg"
74924047306Smrg        shift
75024047306Smrg        shift
75124047306Smrg        ;;
75214c0a534Smrg    esac
75314c0a534Smrg  done
754bf2eeab3Smrg  "$@" -E 2>/dev/null |
755bf2eeab3Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75614c0a534Smrg  rm -f "$depfile"
75714c0a534Smrg  echo "$object : \\" > "$depfile"
75824047306Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75924047306Smrg  echo "$tab" >> "$depfile"
760bf2eeab3Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76114c0a534Smrg  rm -f "$tmpdepfile"
76214c0a534Smrg  ;;
76314c0a534Smrg
764bf2eeab3Smrgmsvcmsys)
765bf2eeab3Smrg  # This case exists only to let depend.m4 do its work.  It works by
766bf2eeab3Smrg  # looking at the text of this script.  This case will never be run,
767bf2eeab3Smrg  # since it is checked for above.
768bf2eeab3Smrg  exit 1
769bf2eeab3Smrg  ;;
770bf2eeab3Smrg
77114c0a534Smrgnone)
77214c0a534Smrg  exec "$@"
77314c0a534Smrg  ;;
77414c0a534Smrg
77514c0a534Smrg*)
77614c0a534Smrg  echo "Unknown depmode $depmode" 1>&2
77714c0a534Smrg  exit 1
77814c0a534Smrg  ;;
77914c0a534Smrgesac
78014c0a534Smrg
78114c0a534Smrgexit 0
78214c0a534Smrg
78314c0a534Smrg# Local Variables:
78414c0a534Smrg# mode: shell-script
78514c0a534Smrg# sh-indentation: 2
786bdc460c5Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
78714c0a534Smrg# time-stamp-start: "scriptversion="
78814c0a534Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789bdc460c5Smrg# time-stamp-time-zone: "UTC0"
790bf2eeab3Smrg# time-stamp-end: "; # UTC"
79114c0a534Smrg# End:
792