172b676d7Smrg#! /bin/sh
272b676d7Smrg# depcomp - compile a program generating dependencies as side-effects
372b676d7Smrg
474fcc364Smrgscriptversion=2016-01-11.22; # UTC
572b676d7Smrg
674fcc364Smrg# Copyright (C) 1999-2017 Free Software Foundation, Inc.
772b676d7Smrg
872b676d7Smrg# This program is free software; you can redistribute it and/or modify
972b676d7Smrg# it under the terms of the GNU General Public License as published by
1072b676d7Smrg# the Free Software Foundation; either version 2, or (at your option)
1172b676d7Smrg# any later version.
1272b676d7Smrg
1372b676d7Smrg# This program is distributed in the hope that it will be useful,
1472b676d7Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1572b676d7Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1672b676d7Smrg# GNU General Public License for more details.
1772b676d7Smrg
1872b676d7Smrg# You should have received a copy of the GNU General Public License
1974c14cd6Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2072b676d7Smrg
2172b676d7Smrg# As a special exception to the GNU General Public License, if you
2272b676d7Smrg# distribute this file as part of a program that contains a
2372b676d7Smrg# configuration script generated by Autoconf, you may include it under
2472b676d7Smrg# the same distribution terms that you use for the rest of that program.
2572b676d7Smrg
2672b676d7Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2772b676d7Smrg
2872b676d7Smrgcase $1 in
2972b676d7Smrg  '')
3093d9adc1Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3193d9adc1Smrg    exit 1;
3293d9adc1Smrg    ;;
3372b676d7Smrg  -h | --h*)
3472b676d7Smrg    cat <<\EOF
3572b676d7SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3672b676d7Smrg
3772b676d7SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3872b676d7Smrgas side-effects.
3972b676d7Smrg
4072b676d7SmrgEnvironment variables:
4172b676d7Smrg  depmode     Dependency tracking mode.
4293d9adc1Smrg  source      Source file read by 'PROGRAMS ARGS'.
4393d9adc1Smrg  object      Object file output by 'PROGRAMS ARGS'.
4472b676d7Smrg  DEPDIR      directory where to store dependencies.
4572b676d7Smrg  depfile     Dependency file to output.
4693d9adc1Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4772b676d7Smrg  libtool     Whether libtool is used (yes/no).
4872b676d7Smrg
4972b676d7SmrgReport bugs to <bug-automake@gnu.org>.
5072b676d7SmrgEOF
5172b676d7Smrg    exit $?
5272b676d7Smrg    ;;
5372b676d7Smrg  -v | --v*)
5472b676d7Smrg    echo "depcomp $scriptversion"
5572b676d7Smrg    exit $?
5672b676d7Smrg    ;;
5772b676d7Smrgesac
5872b676d7Smrg
5993d9adc1Smrg# Get the directory component of the given path, and save it in the
6093d9adc1Smrg# global variables '$dir'.  Note that this directory component will
6193d9adc1Smrg# be either empty or ending with a '/' character.  This is deliberate.
6293d9adc1Smrgset_dir_from ()
6393d9adc1Smrg{
6493d9adc1Smrg  case $1 in
6593d9adc1Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6693d9adc1Smrg      *) dir=;;
6793d9adc1Smrg  esac
6893d9adc1Smrg}
6993d9adc1Smrg
7093d9adc1Smrg# Get the suffix-stripped basename of the given path, and save it the
7193d9adc1Smrg# global variable '$base'.
7293d9adc1Smrgset_base_from ()
7393d9adc1Smrg{
7493d9adc1Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7593d9adc1Smrg}
7693d9adc1Smrg
7793d9adc1Smrg# If no dependency file was actually created by the compiler invocation,
7893d9adc1Smrg# we still have to create a dummy depfile, to avoid errors with the
7993d9adc1Smrg# Makefile "include basename.Plo" scheme.
8093d9adc1Smrgmake_dummy_depfile ()
8193d9adc1Smrg{
8293d9adc1Smrg  echo "#dummy" > "$depfile"
8393d9adc1Smrg}
8493d9adc1Smrg
8593d9adc1Smrg# Factor out some common post-processing of the generated depfile.
8693d9adc1Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8793d9adc1Smrgaix_post_process_depfile ()
8893d9adc1Smrg{
8993d9adc1Smrg  # If the compiler actually managed to produce a dependency file,
9093d9adc1Smrg  # post-process it.
9193d9adc1Smrg  if test -f "$tmpdepfile"; then
9293d9adc1Smrg    # Each line is of the form 'foo.o: dependency.h'.
9393d9adc1Smrg    # Do two passes, one to just change these to
9493d9adc1Smrg    #   $object: dependency.h
9593d9adc1Smrg    # and one to simply output
9693d9adc1Smrg    #   dependency.h:
9793d9adc1Smrg    # which is needed to avoid the deleted-header problem.
9893d9adc1Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9993d9adc1Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10093d9adc1Smrg    } > "$depfile"
10193d9adc1Smrg    rm -f "$tmpdepfile"
10293d9adc1Smrg  else
10393d9adc1Smrg    make_dummy_depfile
10493d9adc1Smrg  fi
10593d9adc1Smrg}
10693d9adc1Smrg
10793d9adc1Smrg# A tabulation character.
10893d9adc1Smrgtab='	'
10993d9adc1Smrg# A newline character.
11093d9adc1Smrgnl='
11193d9adc1Smrg'
11293d9adc1Smrg# Character ranges might be problematic outside the C locale.
11393d9adc1Smrg# These definitions help.
11493d9adc1Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11593d9adc1Smrglower=abcdefghijklmnopqrstuvwxyz
11693d9adc1Smrgdigits=0123456789
11793d9adc1Smrgalpha=${upper}${lower}
11893d9adc1Smrg
11972b676d7Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12072b676d7Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12172b676d7Smrg  exit 1
12272b676d7Smrgfi
12372b676d7Smrg
12472b676d7Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12572b676d7Smrgdepfile=${depfile-`echo "$object" |
12672b676d7Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12772b676d7Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12872b676d7Smrg
12972b676d7Smrgrm -f "$tmpdepfile"
13072b676d7Smrg
13193d9adc1Smrg# Avoid interferences from the environment.
13293d9adc1Smrggccflag= dashmflag=
13393d9adc1Smrg
13472b676d7Smrg# Some modes work just like other modes, but use different flags.  We
13572b676d7Smrg# parameterize here, but still list the modes in the big case below,
13672b676d7Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13772b676d7Smrg# here, because this file can only contain one case statement.
13872b676d7Smrgif test "$depmode" = hp; then
13972b676d7Smrg  # HP compiler uses -M and no extra arg.
14072b676d7Smrg  gccflag=-M
14172b676d7Smrg  depmode=gcc
14272b676d7Smrgfi
14372b676d7Smrg
14472b676d7Smrgif test "$depmode" = dashXmstdout; then
14593d9adc1Smrg  # This is just like dashmstdout with a different argument.
14693d9adc1Smrg  dashmflag=-xM
14793d9adc1Smrg  depmode=dashmstdout
14872b676d7Smrgfi
14972b676d7Smrg
15074c14cd6Smrgcygpath_u="cygpath -u -f -"
15174c14cd6Smrgif test "$depmode" = msvcmsys; then
15293d9adc1Smrg  # This is just like msvisualcpp but w/o cygpath translation.
15393d9adc1Smrg  # Just convert the backslash-escaped backslashes to single forward
15493d9adc1Smrg  # slashes to satisfy depend.m4
15593d9adc1Smrg  cygpath_u='sed s,\\\\,/,g'
15693d9adc1Smrg  depmode=msvisualcpp
15793d9adc1Smrgfi
15893d9adc1Smrg
15993d9adc1Smrgif test "$depmode" = msvc7msys; then
16093d9adc1Smrg  # This is just like msvc7 but w/o cygpath translation.
16193d9adc1Smrg  # Just convert the backslash-escaped backslashes to single forward
16293d9adc1Smrg  # slashes to satisfy depend.m4
16393d9adc1Smrg  cygpath_u='sed s,\\\\,/,g'
16493d9adc1Smrg  depmode=msvc7
16593d9adc1Smrgfi
16693d9adc1Smrg
16793d9adc1Smrgif test "$depmode" = xlc; then
16893d9adc1Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16993d9adc1Smrg  gccflag=-qmakedep=gcc,-MF
17093d9adc1Smrg  depmode=gcc
17174c14cd6Smrgfi
17274c14cd6Smrg
17372b676d7Smrgcase "$depmode" in
17472b676d7Smrggcc3)
17572b676d7Smrg## gcc 3 implements dependency tracking that does exactly what
17672b676d7Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17772b676d7Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1781fd23544Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1791fd23544Smrg## the command line argument order; so add the flags where they
1801fd23544Smrg## appear in depend2.am.  Note that the slowdown incurred here
1811fd23544Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1821fd23544Smrg  for arg
1831fd23544Smrg  do
1841fd23544Smrg    case $arg in
1851fd23544Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1861fd23544Smrg    *)  set fnord "$@" "$arg" ;;
1871fd23544Smrg    esac
1881fd23544Smrg    shift # fnord
1891fd23544Smrg    shift # $arg
1901fd23544Smrg  done
1911fd23544Smrg  "$@"
19272b676d7Smrg  stat=$?
19393d9adc1Smrg  if test $stat -ne 0; then
19472b676d7Smrg    rm -f "$tmpdepfile"
19572b676d7Smrg    exit $stat
19672b676d7Smrg  fi
19772b676d7Smrg  mv "$tmpdepfile" "$depfile"
19872b676d7Smrg  ;;
19972b676d7Smrg
20072b676d7Smrggcc)
20193d9adc1Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20293d9adc1Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20393d9adc1Smrg## (see the conditional assignment to $gccflag above).
20472b676d7Smrg## There are various ways to get dependency output from gcc.  Here's
20572b676d7Smrg## why we pick this rather obscure method:
20672b676d7Smrg## - Don't want to use -MD because we'd like the dependencies to end
20772b676d7Smrg##   up in a subdir.  Having to rename by hand is ugly.
20872b676d7Smrg##   (We might end up doing this anyway to support other compilers.)
20972b676d7Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21093d9adc1Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21193d9adc1Smrg##   supported by the other compilers which use the 'gcc' depmode.
21272b676d7Smrg## - Using -M directly means running the compiler twice (even worse
21372b676d7Smrg##   than renaming).
21472b676d7Smrg  if test -z "$gccflag"; then
21572b676d7Smrg    gccflag=-MD,
21672b676d7Smrg  fi
21772b676d7Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21872b676d7Smrg  stat=$?
21993d9adc1Smrg  if test $stat -ne 0; then
22072b676d7Smrg    rm -f "$tmpdepfile"
22172b676d7Smrg    exit $stat
22272b676d7Smrg  fi
22372b676d7Smrg  rm -f "$depfile"
22472b676d7Smrg  echo "$object : \\" > "$depfile"
22593d9adc1Smrg  # The second -e expression handles DOS-style file names with drive
22693d9adc1Smrg  # letters.
22772b676d7Smrg  sed -e 's/^[^:]*: / /' \
22872b676d7Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22993d9adc1Smrg## This next piece of magic avoids the "deleted header file" problem.
23072b676d7Smrg## The problem is that when a header file which appears in a .P file
23172b676d7Smrg## is deleted, the dependency causes make to die (because there is
23272b676d7Smrg## typically no way to rebuild the header).  We avoid this by adding
23372b676d7Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23472b676d7Smrg## this for us directly.
23593d9adc1Smrg## Some versions of gcc put a space before the ':'.  On the theory
23672b676d7Smrg## that the space means something, we add a space to the output as
23793d9adc1Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23893d9adc1Smrg## to the object.  Take care to not repeat it in the output.
23972b676d7Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24072b676d7Smrg## correctly.  Breaking it into two sed invocations is a workaround.
24193d9adc1Smrg  tr ' ' "$nl" < "$tmpdepfile" \
24293d9adc1Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24393d9adc1Smrg    | sed -e 's/$/ :/' >> "$depfile"
24472b676d7Smrg  rm -f "$tmpdepfile"
24572b676d7Smrg  ;;
24672b676d7Smrg
24772b676d7Smrghp)
24872b676d7Smrg  # This case exists only to let depend.m4 do its work.  It works by
24972b676d7Smrg  # looking at the text of this script.  This case will never be run,
25072b676d7Smrg  # since it is checked for above.
25172b676d7Smrg  exit 1
25272b676d7Smrg  ;;
25372b676d7Smrg
25472b676d7Smrgsgi)
25572b676d7Smrg  if test "$libtool" = yes; then
25672b676d7Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25772b676d7Smrg  else
25872b676d7Smrg    "$@" -MDupdate "$tmpdepfile"
25972b676d7Smrg  fi
26072b676d7Smrg  stat=$?
26193d9adc1Smrg  if test $stat -ne 0; then
26272b676d7Smrg    rm -f "$tmpdepfile"
26372b676d7Smrg    exit $stat
26472b676d7Smrg  fi
26572b676d7Smrg  rm -f "$depfile"
26672b676d7Smrg
26772b676d7Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26872b676d7Smrg    echo "$object : \\" > "$depfile"
26972b676d7Smrg    # Clip off the initial element (the dependent).  Don't try to be
27072b676d7Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27172b676d7Smrg    # lines with more than a fixed number of characters (4096 in
27272b676d7Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27393d9adc1Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27472b676d7Smrg    # dependency line.
27593d9adc1Smrg    tr ' ' "$nl" < "$tmpdepfile" \
27693d9adc1Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27793d9adc1Smrg      | tr "$nl" ' ' >> "$depfile"
27874c14cd6Smrg    echo >> "$depfile"
27972b676d7Smrg    # The second pass generates a dummy entry for each header file.
28093d9adc1Smrg    tr ' ' "$nl" < "$tmpdepfile" \
28193d9adc1Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28293d9adc1Smrg      >> "$depfile"
28372b676d7Smrg  else
28493d9adc1Smrg    make_dummy_depfile
28572b676d7Smrg  fi
28672b676d7Smrg  rm -f "$tmpdepfile"
28772b676d7Smrg  ;;
28872b676d7Smrg
28993d9adc1Smrgxlc)
29093d9adc1Smrg  # This case exists only to let depend.m4 do its work.  It works by
29193d9adc1Smrg  # looking at the text of this script.  This case will never be run,
29293d9adc1Smrg  # since it is checked for above.
29393d9adc1Smrg  exit 1
29493d9adc1Smrg  ;;
29593d9adc1Smrg
29672b676d7Smrgaix)
29772b676d7Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29872b676d7Smrg  # in a .u file.  In older versions, this file always lives in the
29993d9adc1Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30072b676d7Smrg  # start of each line; $object doesn't have directory information.
30172b676d7Smrg  # Version 6 uses the directory in both cases.
30293d9adc1Smrg  set_dir_from "$object"
30393d9adc1Smrg  set_base_from "$object"
30472b676d7Smrg  if test "$libtool" = yes; then
3051fd23544Smrg    tmpdepfile1=$dir$base.u
3061fd23544Smrg    tmpdepfile2=$base.u
3071fd23544Smrg    tmpdepfile3=$dir.libs/$base.u
30872b676d7Smrg    "$@" -Wc,-M
30972b676d7Smrg  else
3101fd23544Smrg    tmpdepfile1=$dir$base.u
3111fd23544Smrg    tmpdepfile2=$dir$base.u
3121fd23544Smrg    tmpdepfile3=$dir$base.u
31372b676d7Smrg    "$@" -M
31472b676d7Smrg  fi
31572b676d7Smrg  stat=$?
31693d9adc1Smrg  if test $stat -ne 0; then
3171fd23544Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31872b676d7Smrg    exit $stat
31972b676d7Smrg  fi
32072b676d7Smrg
3211fd23544Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3221fd23544Smrg  do
3231fd23544Smrg    test -f "$tmpdepfile" && break
3241fd23544Smrg  done
32593d9adc1Smrg  aix_post_process_depfile
32693d9adc1Smrg  ;;
32793d9adc1Smrg
32893d9adc1Smrgtcc)
32993d9adc1Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33093d9adc1Smrg  # FIXME: That version still under development at the moment of writing.
33193d9adc1Smrg  #        Make that this statement remains true also for stable, released
33293d9adc1Smrg  #        versions.
33393d9adc1Smrg  # It will wrap lines (doesn't matter whether long or short) with a
33493d9adc1Smrg  # trailing '\', as in:
33593d9adc1Smrg  #
33693d9adc1Smrg  #   foo.o : \
33793d9adc1Smrg  #    foo.c \
33893d9adc1Smrg  #    foo.h \
33993d9adc1Smrg  #
34093d9adc1Smrg  # It will put a trailing '\' even on the last line, and will use leading
34193d9adc1Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34293d9adc1Smrg  # "Emit spaces for -MD").
34393d9adc1Smrg  "$@" -MD -MF "$tmpdepfile"
34493d9adc1Smrg  stat=$?
34593d9adc1Smrg  if test $stat -ne 0; then
34693d9adc1Smrg    rm -f "$tmpdepfile"
34793d9adc1Smrg    exit $stat
34872b676d7Smrg  fi
34993d9adc1Smrg  rm -f "$depfile"
35093d9adc1Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35193d9adc1Smrg  # We have to change lines of the first kind to '$object: \'.
35293d9adc1Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35393d9adc1Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35493d9adc1Smrg  # dummy dependency, to avoid the deleted-header problem.
35593d9adc1Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35672b676d7Smrg  rm -f "$tmpdepfile"
35772b676d7Smrg  ;;
35872b676d7Smrg
35993d9adc1Smrg## The order of this option in the case statement is important, since the
36093d9adc1Smrg## shell code in configure will try each of these formats in the order
36193d9adc1Smrg## listed in this file.  A plain '-MD' option would be understood by many
36293d9adc1Smrg## compilers, so we must ensure this comes after the gcc and icc options.
36393d9adc1Smrgpgcc)
36493d9adc1Smrg  # Portland's C compiler understands '-MD'.
36593d9adc1Smrg  # Will always output deps to 'file.d' where file is the root name of the
36693d9adc1Smrg  # source file under compilation, even if file resides in a subdirectory.
36793d9adc1Smrg  # The object file name does not affect the name of the '.d' file.
36893d9adc1Smrg  # pgcc 10.2 will output
36972b676d7Smrg  #    foo.o: sub/foo.c sub/foo.h
37093d9adc1Smrg  # and will wrap long lines using '\' :
37172b676d7Smrg  #    foo.o: sub/foo.c ... \
37272b676d7Smrg  #     sub/foo.h ... \
37372b676d7Smrg  #     ...
37493d9adc1Smrg  set_dir_from "$object"
37593d9adc1Smrg  # Use the source, not the object, to determine the base name, since
37693d9adc1Smrg  # that's sadly what pgcc will do too.
37793d9adc1Smrg  set_base_from "$source"
37893d9adc1Smrg  tmpdepfile=$base.d
37993d9adc1Smrg
38093d9adc1Smrg  # For projects that build the same source file twice into different object
38193d9adc1Smrg  # files, the pgcc approach of using the *source* file root name can cause
38293d9adc1Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38393d9adc1Smrg  # the same $tmpdepfile.
38493d9adc1Smrg  lockdir=$base.d-lock
38593d9adc1Smrg  trap "
38693d9adc1Smrg    echo '$0: caught signal, cleaning up...' >&2
38793d9adc1Smrg    rmdir '$lockdir'
38893d9adc1Smrg    exit 1
38993d9adc1Smrg  " 1 2 13 15
39093d9adc1Smrg  numtries=100
39193d9adc1Smrg  i=$numtries
39293d9adc1Smrg  while test $i -gt 0; do
39393d9adc1Smrg    # mkdir is a portable test-and-set.
39493d9adc1Smrg    if mkdir "$lockdir" 2>/dev/null; then
39593d9adc1Smrg      # This process acquired the lock.
39693d9adc1Smrg      "$@" -MD
39793d9adc1Smrg      stat=$?
39893d9adc1Smrg      # Release the lock.
39993d9adc1Smrg      rmdir "$lockdir"
40093d9adc1Smrg      break
40193d9adc1Smrg    else
40293d9adc1Smrg      # If the lock is being held by a different process, wait
40393d9adc1Smrg      # until the winning process is done or we timeout.
40493d9adc1Smrg      while test -d "$lockdir" && test $i -gt 0; do
40593d9adc1Smrg        sleep 1
40693d9adc1Smrg        i=`expr $i - 1`
40793d9adc1Smrg      done
40893d9adc1Smrg    fi
40993d9adc1Smrg    i=`expr $i - 1`
41093d9adc1Smrg  done
41193d9adc1Smrg  trap - 1 2 13 15
41293d9adc1Smrg  if test $i -le 0; then
41393d9adc1Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41493d9adc1Smrg    echo "$0: check lockdir '$lockdir'" >&2
41593d9adc1Smrg    exit 1
41693d9adc1Smrg  fi
41772b676d7Smrg
41893d9adc1Smrg  if test $stat -ne 0; then
41972b676d7Smrg    rm -f "$tmpdepfile"
42072b676d7Smrg    exit $stat
42172b676d7Smrg  fi
42272b676d7Smrg  rm -f "$depfile"
42372b676d7Smrg  # Each line is of the form `foo.o: dependent.h',
42472b676d7Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42572b676d7Smrg  # Do two passes, one to just change these to
42672b676d7Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42772b676d7Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42872b676d7Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42972b676d7Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
43093d9adc1Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43193d9adc1Smrg    | sed -e 's/$/ :/' >> "$depfile"
43272b676d7Smrg  rm -f "$tmpdepfile"
43372b676d7Smrg  ;;
43472b676d7Smrg
4351fd23544Smrghp2)
4361fd23544Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4371fd23544Smrg  # compilers, which have integrated preprocessors.  The correct option
4381fd23544Smrg  # to use with these is +Maked; it writes dependencies to a file named
4391fd23544Smrg  # 'foo.d', which lands next to the object file, wherever that
4401fd23544Smrg  # happens to be.
4411fd23544Smrg  # Much of this is similar to the tru64 case; see comments there.
44293d9adc1Smrg  set_dir_from  "$object"
44393d9adc1Smrg  set_base_from "$object"
4441fd23544Smrg  if test "$libtool" = yes; then
4451fd23544Smrg    tmpdepfile1=$dir$base.d
4461fd23544Smrg    tmpdepfile2=$dir.libs/$base.d
4471fd23544Smrg    "$@" -Wc,+Maked
4481fd23544Smrg  else
4491fd23544Smrg    tmpdepfile1=$dir$base.d
4501fd23544Smrg    tmpdepfile2=$dir$base.d
4511fd23544Smrg    "$@" +Maked
4521fd23544Smrg  fi
4531fd23544Smrg  stat=$?
45493d9adc1Smrg  if test $stat -ne 0; then
4551fd23544Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4561fd23544Smrg     exit $stat
4571fd23544Smrg  fi
4581fd23544Smrg
4591fd23544Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4601fd23544Smrg  do
4611fd23544Smrg    test -f "$tmpdepfile" && break
4621fd23544Smrg  done
4631fd23544Smrg  if test -f "$tmpdepfile"; then
46493d9adc1Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46593d9adc1Smrg    # Add 'dependent.h:' lines.
46674c14cd6Smrg    sed -ne '2,${
46793d9adc1Smrg               s/^ *//
46893d9adc1Smrg               s/ \\*$//
46993d9adc1Smrg               s/$/:/
47093d9adc1Smrg               p
47193d9adc1Smrg             }' "$tmpdepfile" >> "$depfile"
4721fd23544Smrg  else
47393d9adc1Smrg    make_dummy_depfile
4741fd23544Smrg  fi
4751fd23544Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4761fd23544Smrg  ;;
4771fd23544Smrg
47872b676d7Smrgtru64)
47993d9adc1Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48093d9adc1Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48193d9adc1Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48293d9adc1Smrg  # dependencies in 'foo.d' instead, so we check for that too.
48393d9adc1Smrg  # Subdirectories are respected.
48493d9adc1Smrg  set_dir_from  "$object"
48593d9adc1Smrg  set_base_from "$object"
48693d9adc1Smrg
48793d9adc1Smrg  if test "$libtool" = yes; then
48893d9adc1Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48993d9adc1Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49093d9adc1Smrg    # in $dir$base.o.d.  We have to check for both files, because
49193d9adc1Smrg    # one of the two compilations can be disabled.  We should prefer
49293d9adc1Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49393d9adc1Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
49493d9adc1Smrg    # the former would cause a distcleancheck panic.
49593d9adc1Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49693d9adc1Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49793d9adc1Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49893d9adc1Smrg    "$@" -Wc,-MD
49993d9adc1Smrg  else
50093d9adc1Smrg    tmpdepfile1=$dir$base.d
50193d9adc1Smrg    tmpdepfile2=$dir$base.d
50293d9adc1Smrg    tmpdepfile3=$dir$base.d
50393d9adc1Smrg    "$@" -MD
50493d9adc1Smrg  fi
50593d9adc1Smrg
50693d9adc1Smrg  stat=$?
50793d9adc1Smrg  if test $stat -ne 0; then
50893d9adc1Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50993d9adc1Smrg    exit $stat
51093d9adc1Smrg  fi
51193d9adc1Smrg
51293d9adc1Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51393d9adc1Smrg  do
51493d9adc1Smrg    test -f "$tmpdepfile" && break
51593d9adc1Smrg  done
51693d9adc1Smrg  # Same post-processing that is required for AIX mode.
51793d9adc1Smrg  aix_post_process_depfile
51893d9adc1Smrg  ;;
51993d9adc1Smrg
52093d9adc1Smrgmsvc7)
52193d9adc1Smrg  if test "$libtool" = yes; then
52293d9adc1Smrg    showIncludes=-Wc,-showIncludes
52393d9adc1Smrg  else
52493d9adc1Smrg    showIncludes=-showIncludes
52593d9adc1Smrg  fi
52693d9adc1Smrg  "$@" $showIncludes > "$tmpdepfile"
52793d9adc1Smrg  stat=$?
52893d9adc1Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
52993d9adc1Smrg  if test $stat -ne 0; then
53093d9adc1Smrg    rm -f "$tmpdepfile"
53193d9adc1Smrg    exit $stat
53293d9adc1Smrg  fi
53393d9adc1Smrg  rm -f "$depfile"
53493d9adc1Smrg  echo "$object : \\" > "$depfile"
53593d9adc1Smrg  # The first sed program below extracts the file names and escapes
53693d9adc1Smrg  # backslashes for cygpath.  The second sed program outputs the file
53793d9adc1Smrg  # name when reading, but also accumulates all include files in the
53893d9adc1Smrg  # hold buffer in order to output them again at the end.  This only
53993d9adc1Smrg  # works with sed implementations that can handle large buffers.
54093d9adc1Smrg  sed < "$tmpdepfile" -n '
54193d9adc1Smrg/^Note: including file:  *\(.*\)/ {
54293d9adc1Smrg  s//\1/
54393d9adc1Smrg  s/\\/\\\\/g
54493d9adc1Smrg  p
54593d9adc1Smrg}' | $cygpath_u | sort -u | sed -n '
54693d9adc1Smrgs/ /\\ /g
54793d9adc1Smrgs/\(.*\)/'"$tab"'\1 \\/p
54893d9adc1Smrgs/.\(.*\) \\/\1:/
54993d9adc1SmrgH
55093d9adc1Smrg$ {
55193d9adc1Smrg  s/.*/'"$tab"'/
55293d9adc1Smrg  G
55393d9adc1Smrg  p
55493d9adc1Smrg}' >> "$depfile"
55593d9adc1Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55693d9adc1Smrg  rm -f "$tmpdepfile"
55793d9adc1Smrg  ;;
55893d9adc1Smrg
55993d9adc1Smrgmsvc7msys)
56093d9adc1Smrg  # This case exists only to let depend.m4 do its work.  It works by
56193d9adc1Smrg  # looking at the text of this script.  This case will never be run,
56293d9adc1Smrg  # since it is checked for above.
56393d9adc1Smrg  exit 1
56493d9adc1Smrg  ;;
56572b676d7Smrg
56672b676d7Smrg#nosideeffect)
56772b676d7Smrg  # This comment above is used by automake to tell side-effect
56872b676d7Smrg  # dependency tracking mechanisms from slower ones.
56972b676d7Smrg
57072b676d7Smrgdashmstdout)
57172b676d7Smrg  # Important note: in order to support this mode, a compiler *must*
57272b676d7Smrg  # always write the preprocessed file to stdout, regardless of -o.
57372b676d7Smrg  "$@" || exit $?
57472b676d7Smrg
57572b676d7Smrg  # Remove the call to Libtool.
57672b676d7Smrg  if test "$libtool" = yes; then
57774c14cd6Smrg    while test "X$1" != 'X--mode=compile'; do
57872b676d7Smrg      shift
57972b676d7Smrg    done
58072b676d7Smrg    shift
58172b676d7Smrg  fi
58272b676d7Smrg
58393d9adc1Smrg  # Remove '-o $object'.
58472b676d7Smrg  IFS=" "
58572b676d7Smrg  for arg
58672b676d7Smrg  do
58772b676d7Smrg    case $arg in
58872b676d7Smrg    -o)
58972b676d7Smrg      shift
59072b676d7Smrg      ;;
59172b676d7Smrg    $object)
59272b676d7Smrg      shift
59372b676d7Smrg      ;;
59472b676d7Smrg    *)
59572b676d7Smrg      set fnord "$@" "$arg"
59672b676d7Smrg      shift # fnord
59772b676d7Smrg      shift # $arg
59872b676d7Smrg      ;;
59972b676d7Smrg    esac
60072b676d7Smrg  done
60172b676d7Smrg
60272b676d7Smrg  test -z "$dashmflag" && dashmflag=-M
60393d9adc1Smrg  # Require at least two characters before searching for ':'
60472b676d7Smrg  # in the target name.  This is to cope with DOS-style filenames:
60593d9adc1Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60672b676d7Smrg  "$@" $dashmflag |
60793d9adc1Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60872b676d7Smrg  rm -f "$depfile"
60972b676d7Smrg  cat < "$tmpdepfile" > "$depfile"
61093d9adc1Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61193d9adc1Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
61293d9adc1Smrg  tr ' ' "$nl" < "$tmpdepfile" \
61393d9adc1Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61493d9adc1Smrg    | sed -e 's/$/ :/' >> "$depfile"
61572b676d7Smrg  rm -f "$tmpdepfile"
61672b676d7Smrg  ;;
61772b676d7Smrg
61872b676d7SmrgdashXmstdout)
61972b676d7Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62072b676d7Smrg  # run, as this mode is specially recognized in the preamble.
62172b676d7Smrg  exit 1
62272b676d7Smrg  ;;
62372b676d7Smrg
62472b676d7Smrgmakedepend)
62572b676d7Smrg  "$@" || exit $?
62672b676d7Smrg  # Remove any Libtool call
62772b676d7Smrg  if test "$libtool" = yes; then
62874c14cd6Smrg    while test "X$1" != 'X--mode=compile'; do
62972b676d7Smrg      shift
63072b676d7Smrg    done
63172b676d7Smrg    shift
63272b676d7Smrg  fi
63372b676d7Smrg  # X makedepend
63472b676d7Smrg  shift
63574c14cd6Smrg  cleared=no eat=no
63674c14cd6Smrg  for arg
63774c14cd6Smrg  do
63872b676d7Smrg    case $cleared in
63972b676d7Smrg    no)
64072b676d7Smrg      set ""; shift
64172b676d7Smrg      cleared=yes ;;
64272b676d7Smrg    esac
64374c14cd6Smrg    if test $eat = yes; then
64474c14cd6Smrg      eat=no
64574c14cd6Smrg      continue
64674c14cd6Smrg    fi
64772b676d7Smrg    case "$arg" in
64872b676d7Smrg    -D*|-I*)
64972b676d7Smrg      set fnord "$@" "$arg"; shift ;;
65072b676d7Smrg    # Strip any option that makedepend may not understand.  Remove
65172b676d7Smrg    # the object too, otherwise makedepend will parse it as a source file.
65274c14cd6Smrg    -arch)
65374c14cd6Smrg      eat=yes ;;
65472b676d7Smrg    -*|$object)
65572b676d7Smrg      ;;
65672b676d7Smrg    *)
65772b676d7Smrg      set fnord "$@" "$arg"; shift ;;
65872b676d7Smrg    esac
65972b676d7Smrg  done
66074c14cd6Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66172b676d7Smrg  touch "$tmpdepfile"
66272b676d7Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66372b676d7Smrg  rm -f "$depfile"
66493d9adc1Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66593d9adc1Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66693d9adc1Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66793d9adc1Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66893d9adc1Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
66993d9adc1Smrg  sed '1,2d' "$tmpdepfile" \
67093d9adc1Smrg    | tr ' ' "$nl" \
67193d9adc1Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67293d9adc1Smrg    | sed -e 's/$/ :/' >> "$depfile"
67372b676d7Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67472b676d7Smrg  ;;
67572b676d7Smrg
67672b676d7Smrgcpp)
67772b676d7Smrg  # Important note: in order to support this mode, a compiler *must*
67872b676d7Smrg  # always write the preprocessed file to stdout.
67972b676d7Smrg  "$@" || exit $?
68072b676d7Smrg
68172b676d7Smrg  # Remove the call to Libtool.
68272b676d7Smrg  if test "$libtool" = yes; then
68374c14cd6Smrg    while test "X$1" != 'X--mode=compile'; do
68472b676d7Smrg      shift
68572b676d7Smrg    done
68672b676d7Smrg    shift
68772b676d7Smrg  fi
68872b676d7Smrg
68993d9adc1Smrg  # Remove '-o $object'.
69072b676d7Smrg  IFS=" "
69172b676d7Smrg  for arg
69272b676d7Smrg  do
69372b676d7Smrg    case $arg in
69472b676d7Smrg    -o)
69572b676d7Smrg      shift
69672b676d7Smrg      ;;
69772b676d7Smrg    $object)
69872b676d7Smrg      shift
69972b676d7Smrg      ;;
70072b676d7Smrg    *)
70172b676d7Smrg      set fnord "$@" "$arg"
70272b676d7Smrg      shift # fnord
70372b676d7Smrg      shift # $arg
70472b676d7Smrg      ;;
70572b676d7Smrg    esac
70672b676d7Smrg  done
70772b676d7Smrg
70893d9adc1Smrg  "$@" -E \
70993d9adc1Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71093d9adc1Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71193d9adc1Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71272b676d7Smrg  rm -f "$depfile"
71372b676d7Smrg  echo "$object : \\" > "$depfile"
71472b676d7Smrg  cat < "$tmpdepfile" >> "$depfile"
71572b676d7Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71672b676d7Smrg  rm -f "$tmpdepfile"
71772b676d7Smrg  ;;
71872b676d7Smrg
71972b676d7Smrgmsvisualcpp)
72072b676d7Smrg  # Important note: in order to support this mode, a compiler *must*
72174c14cd6Smrg  # always write the preprocessed file to stdout.
72272b676d7Smrg  "$@" || exit $?
72374c14cd6Smrg
72474c14cd6Smrg  # Remove the call to Libtool.
72574c14cd6Smrg  if test "$libtool" = yes; then
72674c14cd6Smrg    while test "X$1" != 'X--mode=compile'; do
72774c14cd6Smrg      shift
72874c14cd6Smrg    done
72974c14cd6Smrg    shift
73074c14cd6Smrg  fi
73174c14cd6Smrg
73272b676d7Smrg  IFS=" "
73372b676d7Smrg  for arg
73472b676d7Smrg  do
73572b676d7Smrg    case "$arg" in
73674c14cd6Smrg    -o)
73774c14cd6Smrg      shift
73874c14cd6Smrg      ;;
73974c14cd6Smrg    $object)
74074c14cd6Smrg      shift
74174c14cd6Smrg      ;;
74272b676d7Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74393d9adc1Smrg        set fnord "$@"
74493d9adc1Smrg        shift
74593d9adc1Smrg        shift
74693d9adc1Smrg        ;;
74772b676d7Smrg    *)
74893d9adc1Smrg        set fnord "$@" "$arg"
74993d9adc1Smrg        shift
75093d9adc1Smrg        shift
75193d9adc1Smrg        ;;
75272b676d7Smrg    esac
75372b676d7Smrg  done
75474c14cd6Smrg  "$@" -E 2>/dev/null |
75574c14cd6Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75672b676d7Smrg  rm -f "$depfile"
75772b676d7Smrg  echo "$object : \\" > "$depfile"
75893d9adc1Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75993d9adc1Smrg  echo "$tab" >> "$depfile"
76074c14cd6Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76172b676d7Smrg  rm -f "$tmpdepfile"
76272b676d7Smrg  ;;
76372b676d7Smrg
76474c14cd6Smrgmsvcmsys)
76574c14cd6Smrg  # This case exists only to let depend.m4 do its work.  It works by
76674c14cd6Smrg  # looking at the text of this script.  This case will never be run,
76774c14cd6Smrg  # since it is checked for above.
76874c14cd6Smrg  exit 1
76974c14cd6Smrg  ;;
77074c14cd6Smrg
77172b676d7Smrgnone)
77272b676d7Smrg  exec "$@"
77372b676d7Smrg  ;;
77472b676d7Smrg
77572b676d7Smrg*)
77672b676d7Smrg  echo "Unknown depmode $depmode" 1>&2
77772b676d7Smrg  exit 1
77872b676d7Smrg  ;;
77972b676d7Smrgesac
78072b676d7Smrg
78172b676d7Smrgexit 0
78272b676d7Smrg
78372b676d7Smrg# Local Variables:
78472b676d7Smrg# mode: shell-script
78572b676d7Smrg# sh-indentation: 2
78672b676d7Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
78772b676d7Smrg# time-stamp-start: "scriptversion="
78872b676d7Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
78974fcc364Smrg# time-stamp-time-zone: "UTC0"
79074c14cd6Smrg# time-stamp-end: "; # UTC"
79172b676d7Smrg# End:
792