155de1df9Smrg#! /bin/sh
255de1df9Smrg# depcomp - compile a program generating dependencies as side-effects
355de1df9Smrg
416e5c272Smrgscriptversion=2018-03-07.03; # UTC
555de1df9Smrg
616e5c272Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
755de1df9Smrg
855de1df9Smrg# This program is free software; you can redistribute it and/or modify
955de1df9Smrg# it under the terms of the GNU General Public License as published by
1055de1df9Smrg# the Free Software Foundation; either version 2, or (at your option)
1155de1df9Smrg# any later version.
1255de1df9Smrg
1355de1df9Smrg# This program is distributed in the hope that it will be useful,
1455de1df9Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1555de1df9Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1655de1df9Smrg# GNU General Public License for more details.
1755de1df9Smrg
1855de1df9Smrg# You should have received a copy of the GNU General Public License
1916e5c272Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2055de1df9Smrg
2155de1df9Smrg# As a special exception to the GNU General Public License, if you
2255de1df9Smrg# distribute this file as part of a program that contains a
2355de1df9Smrg# configuration script generated by Autoconf, you may include it under
2455de1df9Smrg# the same distribution terms that you use for the rest of that program.
2555de1df9Smrg
2655de1df9Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2755de1df9Smrg
2855de1df9Smrgcase $1 in
2955de1df9Smrg  '')
3016e5c272Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3116e5c272Smrg    exit 1;
3216e5c272Smrg    ;;
3355de1df9Smrg  -h | --h*)
3455de1df9Smrg    cat <<\EOF
3555de1df9SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3655de1df9Smrg
3755de1df9SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3855de1df9Smrgas side-effects.
3955de1df9Smrg
4055de1df9SmrgEnvironment variables:
4155de1df9Smrg  depmode     Dependency tracking mode.
4216e5c272Smrg  source      Source file read by 'PROGRAMS ARGS'.
4316e5c272Smrg  object      Object file output by 'PROGRAMS ARGS'.
4455de1df9Smrg  DEPDIR      directory where to store dependencies.
4555de1df9Smrg  depfile     Dependency file to output.
4616e5c272Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4755de1df9Smrg  libtool     Whether libtool is used (yes/no).
4855de1df9Smrg
4955de1df9SmrgReport bugs to <bug-automake@gnu.org>.
5055de1df9SmrgEOF
5155de1df9Smrg    exit $?
5255de1df9Smrg    ;;
5355de1df9Smrg  -v | --v*)
5455de1df9Smrg    echo "depcomp $scriptversion"
5555de1df9Smrg    exit $?
5655de1df9Smrg    ;;
5755de1df9Smrgesac
5855de1df9Smrg
5916e5c272Smrg# Get the directory component of the given path, and save it in the
6016e5c272Smrg# global variables '$dir'.  Note that this directory component will
6116e5c272Smrg# be either empty or ending with a '/' character.  This is deliberate.
6216e5c272Smrgset_dir_from ()
6316e5c272Smrg{
6416e5c272Smrg  case $1 in
6516e5c272Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6616e5c272Smrg      *) dir=;;
6716e5c272Smrg  esac
6816e5c272Smrg}
6916e5c272Smrg
7016e5c272Smrg# Get the suffix-stripped basename of the given path, and save it the
7116e5c272Smrg# global variable '$base'.
7216e5c272Smrgset_base_from ()
7316e5c272Smrg{
7416e5c272Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7516e5c272Smrg}
7616e5c272Smrg
7716e5c272Smrg# If no dependency file was actually created by the compiler invocation,
7816e5c272Smrg# we still have to create a dummy depfile, to avoid errors with the
7916e5c272Smrg# Makefile "include basename.Plo" scheme.
8016e5c272Smrgmake_dummy_depfile ()
8116e5c272Smrg{
8216e5c272Smrg  echo "#dummy" > "$depfile"
8316e5c272Smrg}
8416e5c272Smrg
8516e5c272Smrg# Factor out some common post-processing of the generated depfile.
8616e5c272Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8716e5c272Smrgaix_post_process_depfile ()
8816e5c272Smrg{
8916e5c272Smrg  # If the compiler actually managed to produce a dependency file,
9016e5c272Smrg  # post-process it.
9116e5c272Smrg  if test -f "$tmpdepfile"; then
9216e5c272Smrg    # Each line is of the form 'foo.o: dependency.h'.
9316e5c272Smrg    # Do two passes, one to just change these to
9416e5c272Smrg    #   $object: dependency.h
9516e5c272Smrg    # and one to simply output
9616e5c272Smrg    #   dependency.h:
9716e5c272Smrg    # which is needed to avoid the deleted-header problem.
9816e5c272Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9916e5c272Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10016e5c272Smrg    } > "$depfile"
10116e5c272Smrg    rm -f "$tmpdepfile"
10216e5c272Smrg  else
10316e5c272Smrg    make_dummy_depfile
10416e5c272Smrg  fi
10516e5c272Smrg}
10616e5c272Smrg
10716e5c272Smrg# A tabulation character.
10816e5c272Smrgtab='	'
10916e5c272Smrg# A newline character.
11016e5c272Smrgnl='
11116e5c272Smrg'
11216e5c272Smrg# Character ranges might be problematic outside the C locale.
11316e5c272Smrg# These definitions help.
11416e5c272Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11516e5c272Smrglower=abcdefghijklmnopqrstuvwxyz
11616e5c272Smrgdigits=0123456789
11716e5c272Smrgalpha=${upper}${lower}
11816e5c272Smrg
11955de1df9Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12055de1df9Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12155de1df9Smrg  exit 1
12255de1df9Smrgfi
12355de1df9Smrg
12455de1df9Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12555de1df9Smrgdepfile=${depfile-`echo "$object" |
12655de1df9Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12755de1df9Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12855de1df9Smrg
12955de1df9Smrgrm -f "$tmpdepfile"
13055de1df9Smrg
13116e5c272Smrg# Avoid interferences from the environment.
13216e5c272Smrggccflag= dashmflag=
13316e5c272Smrg
13455de1df9Smrg# Some modes work just like other modes, but use different flags.  We
13555de1df9Smrg# parameterize here, but still list the modes in the big case below,
13655de1df9Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13755de1df9Smrg# here, because this file can only contain one case statement.
13855de1df9Smrgif test "$depmode" = hp; then
13955de1df9Smrg  # HP compiler uses -M and no extra arg.
14055de1df9Smrg  gccflag=-M
14155de1df9Smrg  depmode=gcc
14255de1df9Smrgfi
14355de1df9Smrg
14455de1df9Smrgif test "$depmode" = dashXmstdout; then
14516e5c272Smrg  # This is just like dashmstdout with a different argument.
14616e5c272Smrg  dashmflag=-xM
14716e5c272Smrg  depmode=dashmstdout
14855de1df9Smrgfi
14955de1df9Smrg
15055de1df9Smrgcygpath_u="cygpath -u -f -"
15155de1df9Smrgif test "$depmode" = msvcmsys; then
15216e5c272Smrg  # This is just like msvisualcpp but w/o cygpath translation.
15316e5c272Smrg  # Just convert the backslash-escaped backslashes to single forward
15416e5c272Smrg  # slashes to satisfy depend.m4
15516e5c272Smrg  cygpath_u='sed s,\\\\,/,g'
15616e5c272Smrg  depmode=msvisualcpp
15716e5c272Smrgfi
15816e5c272Smrg
15916e5c272Smrgif test "$depmode" = msvc7msys; then
16016e5c272Smrg  # This is just like msvc7 but w/o cygpath translation.
16116e5c272Smrg  # Just convert the backslash-escaped backslashes to single forward
16216e5c272Smrg  # slashes to satisfy depend.m4
16316e5c272Smrg  cygpath_u='sed s,\\\\,/,g'
16416e5c272Smrg  depmode=msvc7
16516e5c272Smrgfi
16616e5c272Smrg
16716e5c272Smrgif test "$depmode" = xlc; then
16816e5c272Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16916e5c272Smrg  gccflag=-qmakedep=gcc,-MF
17016e5c272Smrg  depmode=gcc
17155de1df9Smrgfi
17255de1df9Smrg
17355de1df9Smrgcase "$depmode" in
17455de1df9Smrggcc3)
17555de1df9Smrg## gcc 3 implements dependency tracking that does exactly what
17655de1df9Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17755de1df9Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
17855de1df9Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
17955de1df9Smrg## the command line argument order; so add the flags where they
18055de1df9Smrg## appear in depend2.am.  Note that the slowdown incurred here
18155de1df9Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18255de1df9Smrg  for arg
18355de1df9Smrg  do
18455de1df9Smrg    case $arg in
18555de1df9Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18655de1df9Smrg    *)  set fnord "$@" "$arg" ;;
18755de1df9Smrg    esac
18855de1df9Smrg    shift # fnord
18955de1df9Smrg    shift # $arg
19055de1df9Smrg  done
19155de1df9Smrg  "$@"
19255de1df9Smrg  stat=$?
19316e5c272Smrg  if test $stat -ne 0; then
19455de1df9Smrg    rm -f "$tmpdepfile"
19555de1df9Smrg    exit $stat
19655de1df9Smrg  fi
19755de1df9Smrg  mv "$tmpdepfile" "$depfile"
19855de1df9Smrg  ;;
19955de1df9Smrg
20055de1df9Smrggcc)
20116e5c272Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20216e5c272Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20316e5c272Smrg## (see the conditional assignment to $gccflag above).
20455de1df9Smrg## There are various ways to get dependency output from gcc.  Here's
20555de1df9Smrg## why we pick this rather obscure method:
20655de1df9Smrg## - Don't want to use -MD because we'd like the dependencies to end
20755de1df9Smrg##   up in a subdir.  Having to rename by hand is ugly.
20855de1df9Smrg##   (We might end up doing this anyway to support other compilers.)
20955de1df9Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21016e5c272Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21116e5c272Smrg##   supported by the other compilers which use the 'gcc' depmode.
21255de1df9Smrg## - Using -M directly means running the compiler twice (even worse
21355de1df9Smrg##   than renaming).
21455de1df9Smrg  if test -z "$gccflag"; then
21555de1df9Smrg    gccflag=-MD,
21655de1df9Smrg  fi
21755de1df9Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21855de1df9Smrg  stat=$?
21916e5c272Smrg  if test $stat -ne 0; then
22055de1df9Smrg    rm -f "$tmpdepfile"
22155de1df9Smrg    exit $stat
22255de1df9Smrg  fi
22355de1df9Smrg  rm -f "$depfile"
22455de1df9Smrg  echo "$object : \\" > "$depfile"
22516e5c272Smrg  # The second -e expression handles DOS-style file names with drive
22616e5c272Smrg  # letters.
22755de1df9Smrg  sed -e 's/^[^:]*: / /' \
22855de1df9Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22916e5c272Smrg## This next piece of magic avoids the "deleted header file" problem.
23055de1df9Smrg## The problem is that when a header file which appears in a .P file
23155de1df9Smrg## is deleted, the dependency causes make to die (because there is
23255de1df9Smrg## typically no way to rebuild the header).  We avoid this by adding
23355de1df9Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23455de1df9Smrg## this for us directly.
23516e5c272Smrg## Some versions of gcc put a space before the ':'.  On the theory
23655de1df9Smrg## that the space means something, we add a space to the output as
23716e5c272Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23816e5c272Smrg## to the object.  Take care to not repeat it in the output.
23955de1df9Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24055de1df9Smrg## correctly.  Breaking it into two sed invocations is a workaround.
24116e5c272Smrg  tr ' ' "$nl" < "$tmpdepfile" \
24216e5c272Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24316e5c272Smrg    | sed -e 's/$/ :/' >> "$depfile"
24455de1df9Smrg  rm -f "$tmpdepfile"
24555de1df9Smrg  ;;
24655de1df9Smrg
24755de1df9Smrghp)
24855de1df9Smrg  # This case exists only to let depend.m4 do its work.  It works by
24955de1df9Smrg  # looking at the text of this script.  This case will never be run,
25055de1df9Smrg  # since it is checked for above.
25155de1df9Smrg  exit 1
25255de1df9Smrg  ;;
25355de1df9Smrg
25455de1df9Smrgsgi)
25555de1df9Smrg  if test "$libtool" = yes; then
25655de1df9Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25755de1df9Smrg  else
25855de1df9Smrg    "$@" -MDupdate "$tmpdepfile"
25955de1df9Smrg  fi
26055de1df9Smrg  stat=$?
26116e5c272Smrg  if test $stat -ne 0; then
26255de1df9Smrg    rm -f "$tmpdepfile"
26355de1df9Smrg    exit $stat
26455de1df9Smrg  fi
26555de1df9Smrg  rm -f "$depfile"
26655de1df9Smrg
26755de1df9Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26855de1df9Smrg    echo "$object : \\" > "$depfile"
26955de1df9Smrg    # Clip off the initial element (the dependent).  Don't try to be
27055de1df9Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27155de1df9Smrg    # lines with more than a fixed number of characters (4096 in
27255de1df9Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27316e5c272Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27455de1df9Smrg    # dependency line.
27516e5c272Smrg    tr ' ' "$nl" < "$tmpdepfile" \
27616e5c272Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27716e5c272Smrg      | tr "$nl" ' ' >> "$depfile"
27855de1df9Smrg    echo >> "$depfile"
27955de1df9Smrg    # The second pass generates a dummy entry for each header file.
28016e5c272Smrg    tr ' ' "$nl" < "$tmpdepfile" \
28116e5c272Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28216e5c272Smrg      >> "$depfile"
28355de1df9Smrg  else
28416e5c272Smrg    make_dummy_depfile
28555de1df9Smrg  fi
28655de1df9Smrg  rm -f "$tmpdepfile"
28755de1df9Smrg  ;;
28855de1df9Smrg
28916e5c272Smrgxlc)
29016e5c272Smrg  # This case exists only to let depend.m4 do its work.  It works by
29116e5c272Smrg  # looking at the text of this script.  This case will never be run,
29216e5c272Smrg  # since it is checked for above.
29316e5c272Smrg  exit 1
29416e5c272Smrg  ;;
29516e5c272Smrg
29655de1df9Smrgaix)
29755de1df9Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29855de1df9Smrg  # in a .u file.  In older versions, this file always lives in the
29916e5c272Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30055de1df9Smrg  # start of each line; $object doesn't have directory information.
30155de1df9Smrg  # Version 6 uses the directory in both cases.
30216e5c272Smrg  set_dir_from "$object"
30316e5c272Smrg  set_base_from "$object"
30455de1df9Smrg  if test "$libtool" = yes; then
30555de1df9Smrg    tmpdepfile1=$dir$base.u
30655de1df9Smrg    tmpdepfile2=$base.u
30755de1df9Smrg    tmpdepfile3=$dir.libs/$base.u
30855de1df9Smrg    "$@" -Wc,-M
30955de1df9Smrg  else
31055de1df9Smrg    tmpdepfile1=$dir$base.u
31155de1df9Smrg    tmpdepfile2=$dir$base.u
31255de1df9Smrg    tmpdepfile3=$dir$base.u
31355de1df9Smrg    "$@" -M
31455de1df9Smrg  fi
31555de1df9Smrg  stat=$?
31616e5c272Smrg  if test $stat -ne 0; then
31755de1df9Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31855de1df9Smrg    exit $stat
31955de1df9Smrg  fi
32055de1df9Smrg
32155de1df9Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32255de1df9Smrg  do
32355de1df9Smrg    test -f "$tmpdepfile" && break
32455de1df9Smrg  done
32516e5c272Smrg  aix_post_process_depfile
32616e5c272Smrg  ;;
32716e5c272Smrg
32816e5c272Smrgtcc)
32916e5c272Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33016e5c272Smrg  # FIXME: That version still under development at the moment of writing.
33116e5c272Smrg  #        Make that this statement remains true also for stable, released
33216e5c272Smrg  #        versions.
33316e5c272Smrg  # It will wrap lines (doesn't matter whether long or short) with a
33416e5c272Smrg  # trailing '\', as in:
33516e5c272Smrg  #
33616e5c272Smrg  #   foo.o : \
33716e5c272Smrg  #    foo.c \
33816e5c272Smrg  #    foo.h \
33916e5c272Smrg  #
34016e5c272Smrg  # It will put a trailing '\' even on the last line, and will use leading
34116e5c272Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34216e5c272Smrg  # "Emit spaces for -MD").
34316e5c272Smrg  "$@" -MD -MF "$tmpdepfile"
34416e5c272Smrg  stat=$?
34516e5c272Smrg  if test $stat -ne 0; then
34616e5c272Smrg    rm -f "$tmpdepfile"
34716e5c272Smrg    exit $stat
34855de1df9Smrg  fi
34916e5c272Smrg  rm -f "$depfile"
35016e5c272Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35116e5c272Smrg  # We have to change lines of the first kind to '$object: \'.
35216e5c272Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35316e5c272Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35416e5c272Smrg  # dummy dependency, to avoid the deleted-header problem.
35516e5c272Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35655de1df9Smrg  rm -f "$tmpdepfile"
35755de1df9Smrg  ;;
35855de1df9Smrg
35916e5c272Smrg## The order of this option in the case statement is important, since the
36016e5c272Smrg## shell code in configure will try each of these formats in the order
36116e5c272Smrg## listed in this file.  A plain '-MD' option would be understood by many
36216e5c272Smrg## compilers, so we must ensure this comes after the gcc and icc options.
36316e5c272Smrgpgcc)
36416e5c272Smrg  # Portland's C compiler understands '-MD'.
36516e5c272Smrg  # Will always output deps to 'file.d' where file is the root name of the
36616e5c272Smrg  # source file under compilation, even if file resides in a subdirectory.
36716e5c272Smrg  # The object file name does not affect the name of the '.d' file.
36816e5c272Smrg  # pgcc 10.2 will output
36955de1df9Smrg  #    foo.o: sub/foo.c sub/foo.h
37016e5c272Smrg  # and will wrap long lines using '\' :
37155de1df9Smrg  #    foo.o: sub/foo.c ... \
37255de1df9Smrg  #     sub/foo.h ... \
37355de1df9Smrg  #     ...
37416e5c272Smrg  set_dir_from "$object"
37516e5c272Smrg  # Use the source, not the object, to determine the base name, since
37616e5c272Smrg  # that's sadly what pgcc will do too.
37716e5c272Smrg  set_base_from "$source"
37816e5c272Smrg  tmpdepfile=$base.d
37916e5c272Smrg
38016e5c272Smrg  # For projects that build the same source file twice into different object
38116e5c272Smrg  # files, the pgcc approach of using the *source* file root name can cause
38216e5c272Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38316e5c272Smrg  # the same $tmpdepfile.
38416e5c272Smrg  lockdir=$base.d-lock
38516e5c272Smrg  trap "
38616e5c272Smrg    echo '$0: caught signal, cleaning up...' >&2
38716e5c272Smrg    rmdir '$lockdir'
38816e5c272Smrg    exit 1
38916e5c272Smrg  " 1 2 13 15
39016e5c272Smrg  numtries=100
39116e5c272Smrg  i=$numtries
39216e5c272Smrg  while test $i -gt 0; do
39316e5c272Smrg    # mkdir is a portable test-and-set.
39416e5c272Smrg    if mkdir "$lockdir" 2>/dev/null; then
39516e5c272Smrg      # This process acquired the lock.
39616e5c272Smrg      "$@" -MD
39716e5c272Smrg      stat=$?
39816e5c272Smrg      # Release the lock.
39916e5c272Smrg      rmdir "$lockdir"
40016e5c272Smrg      break
40116e5c272Smrg    else
40216e5c272Smrg      # If the lock is being held by a different process, wait
40316e5c272Smrg      # until the winning process is done or we timeout.
40416e5c272Smrg      while test -d "$lockdir" && test $i -gt 0; do
40516e5c272Smrg        sleep 1
40616e5c272Smrg        i=`expr $i - 1`
40716e5c272Smrg      done
40816e5c272Smrg    fi
40916e5c272Smrg    i=`expr $i - 1`
41016e5c272Smrg  done
41116e5c272Smrg  trap - 1 2 13 15
41216e5c272Smrg  if test $i -le 0; then
41316e5c272Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41416e5c272Smrg    echo "$0: check lockdir '$lockdir'" >&2
41516e5c272Smrg    exit 1
41616e5c272Smrg  fi
41755de1df9Smrg
41816e5c272Smrg  if test $stat -ne 0; then
41955de1df9Smrg    rm -f "$tmpdepfile"
42055de1df9Smrg    exit $stat
42155de1df9Smrg  fi
42255de1df9Smrg  rm -f "$depfile"
42355de1df9Smrg  # Each line is of the form `foo.o: dependent.h',
42455de1df9Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42555de1df9Smrg  # Do two passes, one to just change these to
42655de1df9Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42755de1df9Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42855de1df9Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42955de1df9Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
43016e5c272Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43116e5c272Smrg    | sed -e 's/$/ :/' >> "$depfile"
43255de1df9Smrg  rm -f "$tmpdepfile"
43355de1df9Smrg  ;;
43455de1df9Smrg
43555de1df9Smrghp2)
43655de1df9Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43755de1df9Smrg  # compilers, which have integrated preprocessors.  The correct option
43855de1df9Smrg  # to use with these is +Maked; it writes dependencies to a file named
43955de1df9Smrg  # 'foo.d', which lands next to the object file, wherever that
44055de1df9Smrg  # happens to be.
44155de1df9Smrg  # Much of this is similar to the tru64 case; see comments there.
44216e5c272Smrg  set_dir_from  "$object"
44316e5c272Smrg  set_base_from "$object"
44455de1df9Smrg  if test "$libtool" = yes; then
44555de1df9Smrg    tmpdepfile1=$dir$base.d
44655de1df9Smrg    tmpdepfile2=$dir.libs/$base.d
44755de1df9Smrg    "$@" -Wc,+Maked
44855de1df9Smrg  else
44955de1df9Smrg    tmpdepfile1=$dir$base.d
45055de1df9Smrg    tmpdepfile2=$dir$base.d
45155de1df9Smrg    "$@" +Maked
45255de1df9Smrg  fi
45355de1df9Smrg  stat=$?
45416e5c272Smrg  if test $stat -ne 0; then
45555de1df9Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
45655de1df9Smrg     exit $stat
45755de1df9Smrg  fi
45855de1df9Smrg
45955de1df9Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46055de1df9Smrg  do
46155de1df9Smrg    test -f "$tmpdepfile" && break
46255de1df9Smrg  done
46355de1df9Smrg  if test -f "$tmpdepfile"; then
46416e5c272Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46516e5c272Smrg    # Add 'dependent.h:' lines.
46655de1df9Smrg    sed -ne '2,${
46716e5c272Smrg               s/^ *//
46816e5c272Smrg               s/ \\*$//
46916e5c272Smrg               s/$/:/
47016e5c272Smrg               p
47116e5c272Smrg             }' "$tmpdepfile" >> "$depfile"
47255de1df9Smrg  else
47316e5c272Smrg    make_dummy_depfile
47455de1df9Smrg  fi
47555de1df9Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
47655de1df9Smrg  ;;
47755de1df9Smrg
47855de1df9Smrgtru64)
47916e5c272Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48016e5c272Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48116e5c272Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48216e5c272Smrg  # dependencies in 'foo.d' instead, so we check for that too.
48316e5c272Smrg  # Subdirectories are respected.
48416e5c272Smrg  set_dir_from  "$object"
48516e5c272Smrg  set_base_from "$object"
48616e5c272Smrg
48716e5c272Smrg  if test "$libtool" = yes; then
48816e5c272Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48916e5c272Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49016e5c272Smrg    # in $dir$base.o.d.  We have to check for both files, because
49116e5c272Smrg    # one of the two compilations can be disabled.  We should prefer
49216e5c272Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49316e5c272Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
49416e5c272Smrg    # the former would cause a distcleancheck panic.
49516e5c272Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49616e5c272Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49716e5c272Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49816e5c272Smrg    "$@" -Wc,-MD
49916e5c272Smrg  else
50016e5c272Smrg    tmpdepfile1=$dir$base.d
50116e5c272Smrg    tmpdepfile2=$dir$base.d
50216e5c272Smrg    tmpdepfile3=$dir$base.d
50316e5c272Smrg    "$@" -MD
50416e5c272Smrg  fi
50516e5c272Smrg
50616e5c272Smrg  stat=$?
50716e5c272Smrg  if test $stat -ne 0; then
50816e5c272Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50916e5c272Smrg    exit $stat
51016e5c272Smrg  fi
51116e5c272Smrg
51216e5c272Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51316e5c272Smrg  do
51416e5c272Smrg    test -f "$tmpdepfile" && break
51516e5c272Smrg  done
51616e5c272Smrg  # Same post-processing that is required for AIX mode.
51716e5c272Smrg  aix_post_process_depfile
51816e5c272Smrg  ;;
51916e5c272Smrg
52016e5c272Smrgmsvc7)
52116e5c272Smrg  if test "$libtool" = yes; then
52216e5c272Smrg    showIncludes=-Wc,-showIncludes
52316e5c272Smrg  else
52416e5c272Smrg    showIncludes=-showIncludes
52516e5c272Smrg  fi
52616e5c272Smrg  "$@" $showIncludes > "$tmpdepfile"
52716e5c272Smrg  stat=$?
52816e5c272Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
52916e5c272Smrg  if test $stat -ne 0; then
53016e5c272Smrg    rm -f "$tmpdepfile"
53116e5c272Smrg    exit $stat
53216e5c272Smrg  fi
53316e5c272Smrg  rm -f "$depfile"
53416e5c272Smrg  echo "$object : \\" > "$depfile"
53516e5c272Smrg  # The first sed program below extracts the file names and escapes
53616e5c272Smrg  # backslashes for cygpath.  The second sed program outputs the file
53716e5c272Smrg  # name when reading, but also accumulates all include files in the
53816e5c272Smrg  # hold buffer in order to output them again at the end.  This only
53916e5c272Smrg  # works with sed implementations that can handle large buffers.
54016e5c272Smrg  sed < "$tmpdepfile" -n '
54116e5c272Smrg/^Note: including file:  *\(.*\)/ {
54216e5c272Smrg  s//\1/
54316e5c272Smrg  s/\\/\\\\/g
54416e5c272Smrg  p
54516e5c272Smrg}' | $cygpath_u | sort -u | sed -n '
54616e5c272Smrgs/ /\\ /g
54716e5c272Smrgs/\(.*\)/'"$tab"'\1 \\/p
54816e5c272Smrgs/.\(.*\) \\/\1:/
54916e5c272SmrgH
55016e5c272Smrg$ {
55116e5c272Smrg  s/.*/'"$tab"'/
55216e5c272Smrg  G
55316e5c272Smrg  p
55416e5c272Smrg}' >> "$depfile"
55516e5c272Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55616e5c272Smrg  rm -f "$tmpdepfile"
55716e5c272Smrg  ;;
55816e5c272Smrg
55916e5c272Smrgmsvc7msys)
56016e5c272Smrg  # This case exists only to let depend.m4 do its work.  It works by
56116e5c272Smrg  # looking at the text of this script.  This case will never be run,
56216e5c272Smrg  # since it is checked for above.
56316e5c272Smrg  exit 1
56416e5c272Smrg  ;;
56555de1df9Smrg
56655de1df9Smrg#nosideeffect)
56755de1df9Smrg  # This comment above is used by automake to tell side-effect
56855de1df9Smrg  # dependency tracking mechanisms from slower ones.
56955de1df9Smrg
57055de1df9Smrgdashmstdout)
57155de1df9Smrg  # Important note: in order to support this mode, a compiler *must*
57255de1df9Smrg  # always write the preprocessed file to stdout, regardless of -o.
57355de1df9Smrg  "$@" || exit $?
57455de1df9Smrg
57555de1df9Smrg  # Remove the call to Libtool.
57655de1df9Smrg  if test "$libtool" = yes; then
57755de1df9Smrg    while test "X$1" != 'X--mode=compile'; do
57855de1df9Smrg      shift
57955de1df9Smrg    done
58055de1df9Smrg    shift
58155de1df9Smrg  fi
58255de1df9Smrg
58316e5c272Smrg  # Remove '-o $object'.
58455de1df9Smrg  IFS=" "
58555de1df9Smrg  for arg
58655de1df9Smrg  do
58755de1df9Smrg    case $arg in
58855de1df9Smrg    -o)
58955de1df9Smrg      shift
59055de1df9Smrg      ;;
59155de1df9Smrg    $object)
59255de1df9Smrg      shift
59355de1df9Smrg      ;;
59455de1df9Smrg    *)
59555de1df9Smrg      set fnord "$@" "$arg"
59655de1df9Smrg      shift # fnord
59755de1df9Smrg      shift # $arg
59855de1df9Smrg      ;;
59955de1df9Smrg    esac
60055de1df9Smrg  done
60155de1df9Smrg
60255de1df9Smrg  test -z "$dashmflag" && dashmflag=-M
60316e5c272Smrg  # Require at least two characters before searching for ':'
60455de1df9Smrg  # in the target name.  This is to cope with DOS-style filenames:
60516e5c272Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60655de1df9Smrg  "$@" $dashmflag |
60716e5c272Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60855de1df9Smrg  rm -f "$depfile"
60955de1df9Smrg  cat < "$tmpdepfile" > "$depfile"
61016e5c272Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61116e5c272Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
61216e5c272Smrg  tr ' ' "$nl" < "$tmpdepfile" \
61316e5c272Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61416e5c272Smrg    | sed -e 's/$/ :/' >> "$depfile"
61555de1df9Smrg  rm -f "$tmpdepfile"
61655de1df9Smrg  ;;
61755de1df9Smrg
61855de1df9SmrgdashXmstdout)
61955de1df9Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62055de1df9Smrg  # run, as this mode is specially recognized in the preamble.
62155de1df9Smrg  exit 1
62255de1df9Smrg  ;;
62355de1df9Smrg
62455de1df9Smrgmakedepend)
62555de1df9Smrg  "$@" || exit $?
62655de1df9Smrg  # Remove any Libtool call
62755de1df9Smrg  if test "$libtool" = yes; then
62855de1df9Smrg    while test "X$1" != 'X--mode=compile'; do
62955de1df9Smrg      shift
63055de1df9Smrg    done
63155de1df9Smrg    shift
63255de1df9Smrg  fi
63355de1df9Smrg  # X makedepend
63455de1df9Smrg  shift
63555de1df9Smrg  cleared=no eat=no
63655de1df9Smrg  for arg
63755de1df9Smrg  do
63855de1df9Smrg    case $cleared in
63955de1df9Smrg    no)
64055de1df9Smrg      set ""; shift
64155de1df9Smrg      cleared=yes ;;
64255de1df9Smrg    esac
64355de1df9Smrg    if test $eat = yes; then
64455de1df9Smrg      eat=no
64555de1df9Smrg      continue
64655de1df9Smrg    fi
64755de1df9Smrg    case "$arg" in
64855de1df9Smrg    -D*|-I*)
64955de1df9Smrg      set fnord "$@" "$arg"; shift ;;
65055de1df9Smrg    # Strip any option that makedepend may not understand.  Remove
65155de1df9Smrg    # the object too, otherwise makedepend will parse it as a source file.
65255de1df9Smrg    -arch)
65355de1df9Smrg      eat=yes ;;
65455de1df9Smrg    -*|$object)
65555de1df9Smrg      ;;
65655de1df9Smrg    *)
65755de1df9Smrg      set fnord "$@" "$arg"; shift ;;
65855de1df9Smrg    esac
65955de1df9Smrg  done
66055de1df9Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66155de1df9Smrg  touch "$tmpdepfile"
66255de1df9Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66355de1df9Smrg  rm -f "$depfile"
66416e5c272Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66516e5c272Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66616e5c272Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66716e5c272Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66816e5c272Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
66916e5c272Smrg  sed '1,2d' "$tmpdepfile" \
67016e5c272Smrg    | tr ' ' "$nl" \
67116e5c272Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67216e5c272Smrg    | sed -e 's/$/ :/' >> "$depfile"
67355de1df9Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67455de1df9Smrg  ;;
67555de1df9Smrg
67655de1df9Smrgcpp)
67755de1df9Smrg  # Important note: in order to support this mode, a compiler *must*
67855de1df9Smrg  # always write the preprocessed file to stdout.
67955de1df9Smrg  "$@" || exit $?
68055de1df9Smrg
68155de1df9Smrg  # Remove the call to Libtool.
68255de1df9Smrg  if test "$libtool" = yes; then
68355de1df9Smrg    while test "X$1" != 'X--mode=compile'; do
68455de1df9Smrg      shift
68555de1df9Smrg    done
68655de1df9Smrg    shift
68755de1df9Smrg  fi
68855de1df9Smrg
68916e5c272Smrg  # Remove '-o $object'.
69055de1df9Smrg  IFS=" "
69155de1df9Smrg  for arg
69255de1df9Smrg  do
69355de1df9Smrg    case $arg in
69455de1df9Smrg    -o)
69555de1df9Smrg      shift
69655de1df9Smrg      ;;
69755de1df9Smrg    $object)
69855de1df9Smrg      shift
69955de1df9Smrg      ;;
70055de1df9Smrg    *)
70155de1df9Smrg      set fnord "$@" "$arg"
70255de1df9Smrg      shift # fnord
70355de1df9Smrg      shift # $arg
70455de1df9Smrg      ;;
70555de1df9Smrg    esac
70655de1df9Smrg  done
70755de1df9Smrg
70816e5c272Smrg  "$@" -E \
70916e5c272Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71016e5c272Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71116e5c272Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71255de1df9Smrg  rm -f "$depfile"
71355de1df9Smrg  echo "$object : \\" > "$depfile"
71455de1df9Smrg  cat < "$tmpdepfile" >> "$depfile"
71555de1df9Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71655de1df9Smrg  rm -f "$tmpdepfile"
71755de1df9Smrg  ;;
71855de1df9Smrg
71955de1df9Smrgmsvisualcpp)
72055de1df9Smrg  # Important note: in order to support this mode, a compiler *must*
72155de1df9Smrg  # always write the preprocessed file to stdout.
72255de1df9Smrg  "$@" || exit $?
72355de1df9Smrg
72455de1df9Smrg  # Remove the call to Libtool.
72555de1df9Smrg  if test "$libtool" = yes; then
72655de1df9Smrg    while test "X$1" != 'X--mode=compile'; do
72755de1df9Smrg      shift
72855de1df9Smrg    done
72955de1df9Smrg    shift
73055de1df9Smrg  fi
73155de1df9Smrg
73255de1df9Smrg  IFS=" "
73355de1df9Smrg  for arg
73455de1df9Smrg  do
73555de1df9Smrg    case "$arg" in
73655de1df9Smrg    -o)
73755de1df9Smrg      shift
73855de1df9Smrg      ;;
73955de1df9Smrg    $object)
74055de1df9Smrg      shift
74155de1df9Smrg      ;;
74255de1df9Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74316e5c272Smrg        set fnord "$@"
74416e5c272Smrg        shift
74516e5c272Smrg        shift
74616e5c272Smrg        ;;
74755de1df9Smrg    *)
74816e5c272Smrg        set fnord "$@" "$arg"
74916e5c272Smrg        shift
75016e5c272Smrg        shift
75116e5c272Smrg        ;;
75255de1df9Smrg    esac
75355de1df9Smrg  done
75455de1df9Smrg  "$@" -E 2>/dev/null |
75555de1df9Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75655de1df9Smrg  rm -f "$depfile"
75755de1df9Smrg  echo "$object : \\" > "$depfile"
75816e5c272Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75916e5c272Smrg  echo "$tab" >> "$depfile"
76055de1df9Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76155de1df9Smrg  rm -f "$tmpdepfile"
76255de1df9Smrg  ;;
76355de1df9Smrg
76455de1df9Smrgmsvcmsys)
76555de1df9Smrg  # This case exists only to let depend.m4 do its work.  It works by
76655de1df9Smrg  # looking at the text of this script.  This case will never be run,
76755de1df9Smrg  # since it is checked for above.
76855de1df9Smrg  exit 1
76955de1df9Smrg  ;;
77055de1df9Smrg
77155de1df9Smrgnone)
77255de1df9Smrg  exec "$@"
77355de1df9Smrg  ;;
77455de1df9Smrg
77555de1df9Smrg*)
77655de1df9Smrg  echo "Unknown depmode $depmode" 1>&2
77755de1df9Smrg  exit 1
77855de1df9Smrg  ;;
77955de1df9Smrgesac
78055de1df9Smrg
78155de1df9Smrgexit 0
78255de1df9Smrg
78355de1df9Smrg# Local Variables:
78455de1df9Smrg# mode: shell-script
78555de1df9Smrg# sh-indentation: 2
78616e5c272Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
78755de1df9Smrg# time-stamp-start: "scriptversion="
78855de1df9Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
78916e5c272Smrg# time-stamp-time-zone: "UTC0"
79055de1df9Smrg# time-stamp-end: "; # UTC"
79155de1df9Smrg# End:
792