depcomp revision 7ed541ca
172b4363aSmrg#! /bin/sh
272b4363aSmrg# depcomp - compile a program generating dependencies as side-effects
372b4363aSmrg
47ed541caSmrgscriptversion=2018-03-07.03; # UTC
572b4363aSmrg
67ed541caSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
772b4363aSmrg
872b4363aSmrg# This program is free software; you can redistribute it and/or modify
972b4363aSmrg# it under the terms of the GNU General Public License as published by
1072b4363aSmrg# the Free Software Foundation; either version 2, or (at your option)
1172b4363aSmrg# any later version.
1272b4363aSmrg
1372b4363aSmrg# This program is distributed in the hope that it will be useful,
1472b4363aSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1572b4363aSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1672b4363aSmrg# GNU General Public License for more details.
1772b4363aSmrg
1872b4363aSmrg# You should have received a copy of the GNU General Public License
197ed541caSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2072b4363aSmrg
2172b4363aSmrg# As a special exception to the GNU General Public License, if you
2272b4363aSmrg# distribute this file as part of a program that contains a
2372b4363aSmrg# configuration script generated by Autoconf, you may include it under
2472b4363aSmrg# the same distribution terms that you use for the rest of that program.
2572b4363aSmrg
2672b4363aSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2772b4363aSmrg
2872b4363aSmrgcase $1 in
2972b4363aSmrg  '')
3033dddc75Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3133dddc75Smrg    exit 1;
3233dddc75Smrg    ;;
3372b4363aSmrg  -h | --h*)
3472b4363aSmrg    cat <<\EOF
3572b4363aSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3672b4363aSmrg
3772b4363aSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3872b4363aSmrgas side-effects.
3972b4363aSmrg
4072b4363aSmrgEnvironment variables:
4172b4363aSmrg  depmode     Dependency tracking mode.
4233dddc75Smrg  source      Source file read by 'PROGRAMS ARGS'.
4333dddc75Smrg  object      Object file output by 'PROGRAMS ARGS'.
4472b4363aSmrg  DEPDIR      directory where to store dependencies.
4572b4363aSmrg  depfile     Dependency file to output.
4633dddc75Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4772b4363aSmrg  libtool     Whether libtool is used (yes/no).
4872b4363aSmrg
4972b4363aSmrgReport bugs to <bug-automake@gnu.org>.
5072b4363aSmrgEOF
5172b4363aSmrg    exit $?
5272b4363aSmrg    ;;
5372b4363aSmrg  -v | --v*)
5472b4363aSmrg    echo "depcomp $scriptversion"
5572b4363aSmrg    exit $?
5672b4363aSmrg    ;;
5772b4363aSmrgesac
5872b4363aSmrg
5933dddc75Smrg# Get the directory component of the given path, and save it in the
6033dddc75Smrg# global variables '$dir'.  Note that this directory component will
6133dddc75Smrg# be either empty or ending with a '/' character.  This is deliberate.
6233dddc75Smrgset_dir_from ()
6333dddc75Smrg{
6433dddc75Smrg  case $1 in
6533dddc75Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6633dddc75Smrg      *) dir=;;
6733dddc75Smrg  esac
6833dddc75Smrg}
6933dddc75Smrg
7033dddc75Smrg# Get the suffix-stripped basename of the given path, and save it the
7133dddc75Smrg# global variable '$base'.
7233dddc75Smrgset_base_from ()
7333dddc75Smrg{
7433dddc75Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7533dddc75Smrg}
7633dddc75Smrg
7733dddc75Smrg# If no dependency file was actually created by the compiler invocation,
7833dddc75Smrg# we still have to create a dummy depfile, to avoid errors with the
7933dddc75Smrg# Makefile "include basename.Plo" scheme.
8033dddc75Smrgmake_dummy_depfile ()
8133dddc75Smrg{
8233dddc75Smrg  echo "#dummy" > "$depfile"
8333dddc75Smrg}
8433dddc75Smrg
8533dddc75Smrg# Factor out some common post-processing of the generated depfile.
8633dddc75Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8733dddc75Smrgaix_post_process_depfile ()
8833dddc75Smrg{
8933dddc75Smrg  # If the compiler actually managed to produce a dependency file,
9033dddc75Smrg  # post-process it.
9133dddc75Smrg  if test -f "$tmpdepfile"; then
9233dddc75Smrg    # Each line is of the form 'foo.o: dependency.h'.
9333dddc75Smrg    # Do two passes, one to just change these to
9433dddc75Smrg    #   $object: dependency.h
9533dddc75Smrg    # and one to simply output
9633dddc75Smrg    #   dependency.h:
9733dddc75Smrg    # which is needed to avoid the deleted-header problem.
9833dddc75Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9933dddc75Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10033dddc75Smrg    } > "$depfile"
10133dddc75Smrg    rm -f "$tmpdepfile"
10233dddc75Smrg  else
10333dddc75Smrg    make_dummy_depfile
10433dddc75Smrg  fi
10533dddc75Smrg}
10633dddc75Smrg
10733dddc75Smrg# A tabulation character.
10833dddc75Smrgtab='	'
10933dddc75Smrg# A newline character.
11033dddc75Smrgnl='
11133dddc75Smrg'
11233dddc75Smrg# Character ranges might be problematic outside the C locale.
11333dddc75Smrg# These definitions help.
11433dddc75Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11533dddc75Smrglower=abcdefghijklmnopqrstuvwxyz
11633dddc75Smrgdigits=0123456789
11733dddc75Smrgalpha=${upper}${lower}
11833dddc75Smrg
11972b4363aSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12072b4363aSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12172b4363aSmrg  exit 1
12272b4363aSmrgfi
12372b4363aSmrg
12472b4363aSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12572b4363aSmrgdepfile=${depfile-`echo "$object" |
12672b4363aSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12772b4363aSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12872b4363aSmrg
12972b4363aSmrgrm -f "$tmpdepfile"
13072b4363aSmrg
13133dddc75Smrg# Avoid interferences from the environment.
13233dddc75Smrggccflag= dashmflag=
13333dddc75Smrg
13472b4363aSmrg# Some modes work just like other modes, but use different flags.  We
13572b4363aSmrg# parameterize here, but still list the modes in the big case below,
13672b4363aSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13772b4363aSmrg# here, because this file can only contain one case statement.
13872b4363aSmrgif test "$depmode" = hp; then
13972b4363aSmrg  # HP compiler uses -M and no extra arg.
14072b4363aSmrg  gccflag=-M
14172b4363aSmrg  depmode=gcc
14272b4363aSmrgfi
14372b4363aSmrg
14472b4363aSmrgif test "$depmode" = dashXmstdout; then
14533dddc75Smrg  # This is just like dashmstdout with a different argument.
14633dddc75Smrg  dashmflag=-xM
14733dddc75Smrg  depmode=dashmstdout
14872b4363aSmrgfi
14972b4363aSmrg
150dd77ae96Smrgcygpath_u="cygpath -u -f -"
151dd77ae96Smrgif test "$depmode" = msvcmsys; then
15233dddc75Smrg  # This is just like msvisualcpp but w/o cygpath translation.
15333dddc75Smrg  # Just convert the backslash-escaped backslashes to single forward
15433dddc75Smrg  # slashes to satisfy depend.m4
15533dddc75Smrg  cygpath_u='sed s,\\\\,/,g'
15633dddc75Smrg  depmode=msvisualcpp
15733dddc75Smrgfi
15833dddc75Smrg
15933dddc75Smrgif test "$depmode" = msvc7msys; then
16033dddc75Smrg  # This is just like msvc7 but w/o cygpath translation.
16133dddc75Smrg  # Just convert the backslash-escaped backslashes to single forward
16233dddc75Smrg  # slashes to satisfy depend.m4
16333dddc75Smrg  cygpath_u='sed s,\\\\,/,g'
16433dddc75Smrg  depmode=msvc7
16533dddc75Smrgfi
16633dddc75Smrg
16733dddc75Smrgif test "$depmode" = xlc; then
16833dddc75Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16933dddc75Smrg  gccflag=-qmakedep=gcc,-MF
17033dddc75Smrg  depmode=gcc
171dd77ae96Smrgfi
172dd77ae96Smrg
17372b4363aSmrgcase "$depmode" in
17472b4363aSmrggcc3)
17572b4363aSmrg## gcc 3 implements dependency tracking that does exactly what
17672b4363aSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17772b4363aSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
17872b4363aSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
17972b4363aSmrg## the command line argument order; so add the flags where they
18072b4363aSmrg## appear in depend2.am.  Note that the slowdown incurred here
18172b4363aSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18272b4363aSmrg  for arg
18372b4363aSmrg  do
18472b4363aSmrg    case $arg in
18572b4363aSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18672b4363aSmrg    *)  set fnord "$@" "$arg" ;;
18772b4363aSmrg    esac
18872b4363aSmrg    shift # fnord
18972b4363aSmrg    shift # $arg
19072b4363aSmrg  done
19172b4363aSmrg  "$@"
19272b4363aSmrg  stat=$?
19333dddc75Smrg  if test $stat -ne 0; then
19472b4363aSmrg    rm -f "$tmpdepfile"
19572b4363aSmrg    exit $stat
19672b4363aSmrg  fi
19772b4363aSmrg  mv "$tmpdepfile" "$depfile"
19872b4363aSmrg  ;;
19972b4363aSmrg
20072b4363aSmrggcc)
20133dddc75Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20233dddc75Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20333dddc75Smrg## (see the conditional assignment to $gccflag above).
20472b4363aSmrg## There are various ways to get dependency output from gcc.  Here's
20572b4363aSmrg## why we pick this rather obscure method:
20672b4363aSmrg## - Don't want to use -MD because we'd like the dependencies to end
20772b4363aSmrg##   up in a subdir.  Having to rename by hand is ugly.
20872b4363aSmrg##   (We might end up doing this anyway to support other compilers.)
20972b4363aSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21033dddc75Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21133dddc75Smrg##   supported by the other compilers which use the 'gcc' depmode.
21272b4363aSmrg## - Using -M directly means running the compiler twice (even worse
21372b4363aSmrg##   than renaming).
21472b4363aSmrg  if test -z "$gccflag"; then
21572b4363aSmrg    gccflag=-MD,
21672b4363aSmrg  fi
21772b4363aSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
21872b4363aSmrg  stat=$?
21933dddc75Smrg  if test $stat -ne 0; then
22072b4363aSmrg    rm -f "$tmpdepfile"
22172b4363aSmrg    exit $stat
22272b4363aSmrg  fi
22372b4363aSmrg  rm -f "$depfile"
22472b4363aSmrg  echo "$object : \\" > "$depfile"
22533dddc75Smrg  # The second -e expression handles DOS-style file names with drive
22633dddc75Smrg  # letters.
22772b4363aSmrg  sed -e 's/^[^:]*: / /' \
22872b4363aSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22933dddc75Smrg## This next piece of magic avoids the "deleted header file" problem.
23072b4363aSmrg## The problem is that when a header file which appears in a .P file
23172b4363aSmrg## is deleted, the dependency causes make to die (because there is
23272b4363aSmrg## typically no way to rebuild the header).  We avoid this by adding
23372b4363aSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23472b4363aSmrg## this for us directly.
23533dddc75Smrg## Some versions of gcc put a space before the ':'.  On the theory
23672b4363aSmrg## that the space means something, we add a space to the output as
23733dddc75Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23833dddc75Smrg## to the object.  Take care to not repeat it in the output.
23972b4363aSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
24072b4363aSmrg## correctly.  Breaking it into two sed invocations is a workaround.
24133dddc75Smrg  tr ' ' "$nl" < "$tmpdepfile" \
24233dddc75Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24333dddc75Smrg    | sed -e 's/$/ :/' >> "$depfile"
24472b4363aSmrg  rm -f "$tmpdepfile"
24572b4363aSmrg  ;;
24672b4363aSmrg
24772b4363aSmrghp)
24872b4363aSmrg  # This case exists only to let depend.m4 do its work.  It works by
24972b4363aSmrg  # looking at the text of this script.  This case will never be run,
25072b4363aSmrg  # since it is checked for above.
25172b4363aSmrg  exit 1
25272b4363aSmrg  ;;
25372b4363aSmrg
25472b4363aSmrgsgi)
25572b4363aSmrg  if test "$libtool" = yes; then
25672b4363aSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25772b4363aSmrg  else
25872b4363aSmrg    "$@" -MDupdate "$tmpdepfile"
25972b4363aSmrg  fi
26072b4363aSmrg  stat=$?
26133dddc75Smrg  if test $stat -ne 0; then
26272b4363aSmrg    rm -f "$tmpdepfile"
26372b4363aSmrg    exit $stat
26472b4363aSmrg  fi
26572b4363aSmrg  rm -f "$depfile"
26672b4363aSmrg
26772b4363aSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26872b4363aSmrg    echo "$object : \\" > "$depfile"
26972b4363aSmrg    # Clip off the initial element (the dependent).  Don't try to be
27072b4363aSmrg    # clever and replace this with sed code, as IRIX sed won't handle
27172b4363aSmrg    # lines with more than a fixed number of characters (4096 in
27272b4363aSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27333dddc75Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27472b4363aSmrg    # dependency line.
27533dddc75Smrg    tr ' ' "$nl" < "$tmpdepfile" \
27633dddc75Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27733dddc75Smrg      | tr "$nl" ' ' >> "$depfile"
278dd77ae96Smrg    echo >> "$depfile"
27972b4363aSmrg    # The second pass generates a dummy entry for each header file.
28033dddc75Smrg    tr ' ' "$nl" < "$tmpdepfile" \
28133dddc75Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28233dddc75Smrg      >> "$depfile"
28372b4363aSmrg  else
28433dddc75Smrg    make_dummy_depfile
28572b4363aSmrg  fi
28672b4363aSmrg  rm -f "$tmpdepfile"
28772b4363aSmrg  ;;
28872b4363aSmrg
28933dddc75Smrgxlc)
29033dddc75Smrg  # This case exists only to let depend.m4 do its work.  It works by
29133dddc75Smrg  # looking at the text of this script.  This case will never be run,
29233dddc75Smrg  # since it is checked for above.
29333dddc75Smrg  exit 1
29433dddc75Smrg  ;;
29533dddc75Smrg
29672b4363aSmrgaix)
29772b4363aSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
29872b4363aSmrg  # in a .u file.  In older versions, this file always lives in the
29933dddc75Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30072b4363aSmrg  # start of each line; $object doesn't have directory information.
30172b4363aSmrg  # Version 6 uses the directory in both cases.
30233dddc75Smrg  set_dir_from "$object"
30333dddc75Smrg  set_base_from "$object"
30472b4363aSmrg  if test "$libtool" = yes; then
305dd77ae96Smrg    tmpdepfile1=$dir$base.u
306dd77ae96Smrg    tmpdepfile2=$base.u
307dd77ae96Smrg    tmpdepfile3=$dir.libs/$base.u
30872b4363aSmrg    "$@" -Wc,-M
30972b4363aSmrg  else
310dd77ae96Smrg    tmpdepfile1=$dir$base.u
311dd77ae96Smrg    tmpdepfile2=$dir$base.u
312dd77ae96Smrg    tmpdepfile3=$dir$base.u
31372b4363aSmrg    "$@" -M
31472b4363aSmrg  fi
31572b4363aSmrg  stat=$?
31633dddc75Smrg  if test $stat -ne 0; then
317dd77ae96Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31872b4363aSmrg    exit $stat
31972b4363aSmrg  fi
32072b4363aSmrg
321dd77ae96Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322dd77ae96Smrg  do
323dd77ae96Smrg    test -f "$tmpdepfile" && break
324dd77ae96Smrg  done
32533dddc75Smrg  aix_post_process_depfile
32633dddc75Smrg  ;;
32733dddc75Smrg
32833dddc75Smrgtcc)
32933dddc75Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33033dddc75Smrg  # FIXME: That version still under development at the moment of writing.
33133dddc75Smrg  #        Make that this statement remains true also for stable, released
33233dddc75Smrg  #        versions.
33333dddc75Smrg  # It will wrap lines (doesn't matter whether long or short) with a
33433dddc75Smrg  # trailing '\', as in:
33533dddc75Smrg  #
33633dddc75Smrg  #   foo.o : \
33733dddc75Smrg  #    foo.c \
33833dddc75Smrg  #    foo.h \
33933dddc75Smrg  #
34033dddc75Smrg  # It will put a trailing '\' even on the last line, and will use leading
34133dddc75Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34233dddc75Smrg  # "Emit spaces for -MD").
34333dddc75Smrg  "$@" -MD -MF "$tmpdepfile"
34433dddc75Smrg  stat=$?
34533dddc75Smrg  if test $stat -ne 0; then
34633dddc75Smrg    rm -f "$tmpdepfile"
34733dddc75Smrg    exit $stat
34872b4363aSmrg  fi
34933dddc75Smrg  rm -f "$depfile"
35033dddc75Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35133dddc75Smrg  # We have to change lines of the first kind to '$object: \'.
35233dddc75Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35333dddc75Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35433dddc75Smrg  # dummy dependency, to avoid the deleted-header problem.
35533dddc75Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35672b4363aSmrg  rm -f "$tmpdepfile"
35772b4363aSmrg  ;;
35872b4363aSmrg
35933dddc75Smrg## The order of this option in the case statement is important, since the
36033dddc75Smrg## shell code in configure will try each of these formats in the order
36133dddc75Smrg## listed in this file.  A plain '-MD' option would be understood by many
36233dddc75Smrg## compilers, so we must ensure this comes after the gcc and icc options.
36333dddc75Smrgpgcc)
36433dddc75Smrg  # Portland's C compiler understands '-MD'.
36533dddc75Smrg  # Will always output deps to 'file.d' where file is the root name of the
36633dddc75Smrg  # source file under compilation, even if file resides in a subdirectory.
36733dddc75Smrg  # The object file name does not affect the name of the '.d' file.
36833dddc75Smrg  # pgcc 10.2 will output
36972b4363aSmrg  #    foo.o: sub/foo.c sub/foo.h
37033dddc75Smrg  # and will wrap long lines using '\' :
37172b4363aSmrg  #    foo.o: sub/foo.c ... \
37272b4363aSmrg  #     sub/foo.h ... \
37372b4363aSmrg  #     ...
37433dddc75Smrg  set_dir_from "$object"
37533dddc75Smrg  # Use the source, not the object, to determine the base name, since
37633dddc75Smrg  # that's sadly what pgcc will do too.
37733dddc75Smrg  set_base_from "$source"
37833dddc75Smrg  tmpdepfile=$base.d
37933dddc75Smrg
38033dddc75Smrg  # For projects that build the same source file twice into different object
38133dddc75Smrg  # files, the pgcc approach of using the *source* file root name can cause
38233dddc75Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38333dddc75Smrg  # the same $tmpdepfile.
38433dddc75Smrg  lockdir=$base.d-lock
38533dddc75Smrg  trap "
38633dddc75Smrg    echo '$0: caught signal, cleaning up...' >&2
38733dddc75Smrg    rmdir '$lockdir'
38833dddc75Smrg    exit 1
38933dddc75Smrg  " 1 2 13 15
39033dddc75Smrg  numtries=100
39133dddc75Smrg  i=$numtries
39233dddc75Smrg  while test $i -gt 0; do
39333dddc75Smrg    # mkdir is a portable test-and-set.
39433dddc75Smrg    if mkdir "$lockdir" 2>/dev/null; then
39533dddc75Smrg      # This process acquired the lock.
39633dddc75Smrg      "$@" -MD
39733dddc75Smrg      stat=$?
39833dddc75Smrg      # Release the lock.
39933dddc75Smrg      rmdir "$lockdir"
40033dddc75Smrg      break
40133dddc75Smrg    else
40233dddc75Smrg      # If the lock is being held by a different process, wait
40333dddc75Smrg      # until the winning process is done or we timeout.
40433dddc75Smrg      while test -d "$lockdir" && test $i -gt 0; do
40533dddc75Smrg        sleep 1
40633dddc75Smrg        i=`expr $i - 1`
40733dddc75Smrg      done
40833dddc75Smrg    fi
40933dddc75Smrg    i=`expr $i - 1`
41033dddc75Smrg  done
41133dddc75Smrg  trap - 1 2 13 15
41233dddc75Smrg  if test $i -le 0; then
41333dddc75Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41433dddc75Smrg    echo "$0: check lockdir '$lockdir'" >&2
41533dddc75Smrg    exit 1
41633dddc75Smrg  fi
41772b4363aSmrg
41833dddc75Smrg  if test $stat -ne 0; then
41972b4363aSmrg    rm -f "$tmpdepfile"
42072b4363aSmrg    exit $stat
42172b4363aSmrg  fi
42272b4363aSmrg  rm -f "$depfile"
42372b4363aSmrg  # Each line is of the form `foo.o: dependent.h',
42472b4363aSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42572b4363aSmrg  # Do two passes, one to just change these to
42672b4363aSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42772b4363aSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42872b4363aSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42972b4363aSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
43033dddc75Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43133dddc75Smrg    | sed -e 's/$/ :/' >> "$depfile"
43272b4363aSmrg  rm -f "$tmpdepfile"
43372b4363aSmrg  ;;
43472b4363aSmrg
43572b4363aSmrghp2)
43672b4363aSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43772b4363aSmrg  # compilers, which have integrated preprocessors.  The correct option
43872b4363aSmrg  # to use with these is +Maked; it writes dependencies to a file named
43972b4363aSmrg  # 'foo.d', which lands next to the object file, wherever that
44072b4363aSmrg  # happens to be.
44172b4363aSmrg  # Much of this is similar to the tru64 case; see comments there.
44233dddc75Smrg  set_dir_from  "$object"
44333dddc75Smrg  set_base_from "$object"
44472b4363aSmrg  if test "$libtool" = yes; then
44572b4363aSmrg    tmpdepfile1=$dir$base.d
44672b4363aSmrg    tmpdepfile2=$dir.libs/$base.d
44772b4363aSmrg    "$@" -Wc,+Maked
44872b4363aSmrg  else
44972b4363aSmrg    tmpdepfile1=$dir$base.d
45072b4363aSmrg    tmpdepfile2=$dir$base.d
45172b4363aSmrg    "$@" +Maked
45272b4363aSmrg  fi
45372b4363aSmrg  stat=$?
45433dddc75Smrg  if test $stat -ne 0; then
45572b4363aSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
45672b4363aSmrg     exit $stat
45772b4363aSmrg  fi
45872b4363aSmrg
45972b4363aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46072b4363aSmrg  do
46172b4363aSmrg    test -f "$tmpdepfile" && break
46272b4363aSmrg  done
46372b4363aSmrg  if test -f "$tmpdepfile"; then
46433dddc75Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46533dddc75Smrg    # Add 'dependent.h:' lines.
466dd77ae96Smrg    sed -ne '2,${
46733dddc75Smrg               s/^ *//
46833dddc75Smrg               s/ \\*$//
46933dddc75Smrg               s/$/:/
47033dddc75Smrg               p
47133dddc75Smrg             }' "$tmpdepfile" >> "$depfile"
47272b4363aSmrg  else
47333dddc75Smrg    make_dummy_depfile
47472b4363aSmrg  fi
47572b4363aSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
47672b4363aSmrg  ;;
47772b4363aSmrg
47872b4363aSmrgtru64)
47933dddc75Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48033dddc75Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48133dddc75Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48233dddc75Smrg  # dependencies in 'foo.d' instead, so we check for that too.
48333dddc75Smrg  # Subdirectories are respected.
48433dddc75Smrg  set_dir_from  "$object"
48533dddc75Smrg  set_base_from "$object"
48633dddc75Smrg
48733dddc75Smrg  if test "$libtool" = yes; then
48833dddc75Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48933dddc75Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49033dddc75Smrg    # in $dir$base.o.d.  We have to check for both files, because
49133dddc75Smrg    # one of the two compilations can be disabled.  We should prefer
49233dddc75Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49333dddc75Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
49433dddc75Smrg    # the former would cause a distcleancheck panic.
49533dddc75Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49633dddc75Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49733dddc75Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49833dddc75Smrg    "$@" -Wc,-MD
49933dddc75Smrg  else
50033dddc75Smrg    tmpdepfile1=$dir$base.d
50133dddc75Smrg    tmpdepfile2=$dir$base.d
50233dddc75Smrg    tmpdepfile3=$dir$base.d
50333dddc75Smrg    "$@" -MD
50433dddc75Smrg  fi
50533dddc75Smrg
50633dddc75Smrg  stat=$?
50733dddc75Smrg  if test $stat -ne 0; then
50833dddc75Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50933dddc75Smrg    exit $stat
51033dddc75Smrg  fi
51133dddc75Smrg
51233dddc75Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51333dddc75Smrg  do
51433dddc75Smrg    test -f "$tmpdepfile" && break
51533dddc75Smrg  done
51633dddc75Smrg  # Same post-processing that is required for AIX mode.
51733dddc75Smrg  aix_post_process_depfile
51833dddc75Smrg  ;;
51933dddc75Smrg
52033dddc75Smrgmsvc7)
52133dddc75Smrg  if test "$libtool" = yes; then
52233dddc75Smrg    showIncludes=-Wc,-showIncludes
52333dddc75Smrg  else
52433dddc75Smrg    showIncludes=-showIncludes
52533dddc75Smrg  fi
52633dddc75Smrg  "$@" $showIncludes > "$tmpdepfile"
52733dddc75Smrg  stat=$?
52833dddc75Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
52933dddc75Smrg  if test $stat -ne 0; then
53033dddc75Smrg    rm -f "$tmpdepfile"
53133dddc75Smrg    exit $stat
53233dddc75Smrg  fi
53333dddc75Smrg  rm -f "$depfile"
53433dddc75Smrg  echo "$object : \\" > "$depfile"
53533dddc75Smrg  # The first sed program below extracts the file names and escapes
53633dddc75Smrg  # backslashes for cygpath.  The second sed program outputs the file
53733dddc75Smrg  # name when reading, but also accumulates all include files in the
53833dddc75Smrg  # hold buffer in order to output them again at the end.  This only
53933dddc75Smrg  # works with sed implementations that can handle large buffers.
54033dddc75Smrg  sed < "$tmpdepfile" -n '
54133dddc75Smrg/^Note: including file:  *\(.*\)/ {
54233dddc75Smrg  s//\1/
54333dddc75Smrg  s/\\/\\\\/g
54433dddc75Smrg  p
54533dddc75Smrg}' | $cygpath_u | sort -u | sed -n '
54633dddc75Smrgs/ /\\ /g
54733dddc75Smrgs/\(.*\)/'"$tab"'\1 \\/p
54833dddc75Smrgs/.\(.*\) \\/\1:/
54933dddc75SmrgH
55033dddc75Smrg$ {
55133dddc75Smrg  s/.*/'"$tab"'/
55233dddc75Smrg  G
55333dddc75Smrg  p
55433dddc75Smrg}' >> "$depfile"
55533dddc75Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55633dddc75Smrg  rm -f "$tmpdepfile"
55733dddc75Smrg  ;;
55833dddc75Smrg
55933dddc75Smrgmsvc7msys)
56033dddc75Smrg  # This case exists only to let depend.m4 do its work.  It works by
56133dddc75Smrg  # looking at the text of this script.  This case will never be run,
56233dddc75Smrg  # since it is checked for above.
56333dddc75Smrg  exit 1
56433dddc75Smrg  ;;
56572b4363aSmrg
56672b4363aSmrg#nosideeffect)
56772b4363aSmrg  # This comment above is used by automake to tell side-effect
56872b4363aSmrg  # dependency tracking mechanisms from slower ones.
56972b4363aSmrg
57072b4363aSmrgdashmstdout)
57172b4363aSmrg  # Important note: in order to support this mode, a compiler *must*
57272b4363aSmrg  # always write the preprocessed file to stdout, regardless of -o.
57372b4363aSmrg  "$@" || exit $?
57472b4363aSmrg
57572b4363aSmrg  # Remove the call to Libtool.
57672b4363aSmrg  if test "$libtool" = yes; then
577dd77ae96Smrg    while test "X$1" != 'X--mode=compile'; do
57872b4363aSmrg      shift
57972b4363aSmrg    done
58072b4363aSmrg    shift
58172b4363aSmrg  fi
58272b4363aSmrg
58333dddc75Smrg  # Remove '-o $object'.
58472b4363aSmrg  IFS=" "
58572b4363aSmrg  for arg
58672b4363aSmrg  do
58772b4363aSmrg    case $arg in
58872b4363aSmrg    -o)
58972b4363aSmrg      shift
59072b4363aSmrg      ;;
59172b4363aSmrg    $object)
59272b4363aSmrg      shift
59372b4363aSmrg      ;;
59472b4363aSmrg    *)
59572b4363aSmrg      set fnord "$@" "$arg"
59672b4363aSmrg      shift # fnord
59772b4363aSmrg      shift # $arg
59872b4363aSmrg      ;;
59972b4363aSmrg    esac
60072b4363aSmrg  done
60172b4363aSmrg
60272b4363aSmrg  test -z "$dashmflag" && dashmflag=-M
60333dddc75Smrg  # Require at least two characters before searching for ':'
60472b4363aSmrg  # in the target name.  This is to cope with DOS-style filenames:
60533dddc75Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60672b4363aSmrg  "$@" $dashmflag |
60733dddc75Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60872b4363aSmrg  rm -f "$depfile"
60972b4363aSmrg  cat < "$tmpdepfile" > "$depfile"
61033dddc75Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61133dddc75Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
61233dddc75Smrg  tr ' ' "$nl" < "$tmpdepfile" \
61333dddc75Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61433dddc75Smrg    | sed -e 's/$/ :/' >> "$depfile"
61572b4363aSmrg  rm -f "$tmpdepfile"
61672b4363aSmrg  ;;
61772b4363aSmrg
61872b4363aSmrgdashXmstdout)
61972b4363aSmrg  # This case only exists to satisfy depend.m4.  It is never actually
62072b4363aSmrg  # run, as this mode is specially recognized in the preamble.
62172b4363aSmrg  exit 1
62272b4363aSmrg  ;;
62372b4363aSmrg
62472b4363aSmrgmakedepend)
62572b4363aSmrg  "$@" || exit $?
62672b4363aSmrg  # Remove any Libtool call
62772b4363aSmrg  if test "$libtool" = yes; then
628dd77ae96Smrg    while test "X$1" != 'X--mode=compile'; do
62972b4363aSmrg      shift
63072b4363aSmrg    done
63172b4363aSmrg    shift
63272b4363aSmrg  fi
63372b4363aSmrg  # X makedepend
63472b4363aSmrg  shift
635dd77ae96Smrg  cleared=no eat=no
636dd77ae96Smrg  for arg
637dd77ae96Smrg  do
63872b4363aSmrg    case $cleared in
63972b4363aSmrg    no)
64072b4363aSmrg      set ""; shift
64172b4363aSmrg      cleared=yes ;;
64272b4363aSmrg    esac
643dd77ae96Smrg    if test $eat = yes; then
644dd77ae96Smrg      eat=no
645dd77ae96Smrg      continue
646dd77ae96Smrg    fi
64772b4363aSmrg    case "$arg" in
64872b4363aSmrg    -D*|-I*)
64972b4363aSmrg      set fnord "$@" "$arg"; shift ;;
65072b4363aSmrg    # Strip any option that makedepend may not understand.  Remove
65172b4363aSmrg    # the object too, otherwise makedepend will parse it as a source file.
652dd77ae96Smrg    -arch)
653dd77ae96Smrg      eat=yes ;;
65472b4363aSmrg    -*|$object)
65572b4363aSmrg      ;;
65672b4363aSmrg    *)
65772b4363aSmrg      set fnord "$@" "$arg"; shift ;;
65872b4363aSmrg    esac
65972b4363aSmrg  done
660dd77ae96Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66172b4363aSmrg  touch "$tmpdepfile"
66272b4363aSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66372b4363aSmrg  rm -f "$depfile"
66433dddc75Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66533dddc75Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66633dddc75Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66733dddc75Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66833dddc75Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
66933dddc75Smrg  sed '1,2d' "$tmpdepfile" \
67033dddc75Smrg    | tr ' ' "$nl" \
67133dddc75Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67233dddc75Smrg    | sed -e 's/$/ :/' >> "$depfile"
67372b4363aSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67472b4363aSmrg  ;;
67572b4363aSmrg
67672b4363aSmrgcpp)
67772b4363aSmrg  # Important note: in order to support this mode, a compiler *must*
67872b4363aSmrg  # always write the preprocessed file to stdout.
67972b4363aSmrg  "$@" || exit $?
68072b4363aSmrg
68172b4363aSmrg  # Remove the call to Libtool.
68272b4363aSmrg  if test "$libtool" = yes; then
683dd77ae96Smrg    while test "X$1" != 'X--mode=compile'; do
68472b4363aSmrg      shift
68572b4363aSmrg    done
68672b4363aSmrg    shift
68772b4363aSmrg  fi
68872b4363aSmrg
68933dddc75Smrg  # Remove '-o $object'.
69072b4363aSmrg  IFS=" "
69172b4363aSmrg  for arg
69272b4363aSmrg  do
69372b4363aSmrg    case $arg in
69472b4363aSmrg    -o)
69572b4363aSmrg      shift
69672b4363aSmrg      ;;
69772b4363aSmrg    $object)
69872b4363aSmrg      shift
69972b4363aSmrg      ;;
70072b4363aSmrg    *)
70172b4363aSmrg      set fnord "$@" "$arg"
70272b4363aSmrg      shift # fnord
70372b4363aSmrg      shift # $arg
70472b4363aSmrg      ;;
70572b4363aSmrg    esac
70672b4363aSmrg  done
70772b4363aSmrg
70833dddc75Smrg  "$@" -E \
70933dddc75Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71033dddc75Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71133dddc75Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71272b4363aSmrg  rm -f "$depfile"
71372b4363aSmrg  echo "$object : \\" > "$depfile"
71472b4363aSmrg  cat < "$tmpdepfile" >> "$depfile"
71572b4363aSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71672b4363aSmrg  rm -f "$tmpdepfile"
71772b4363aSmrg  ;;
71872b4363aSmrg
71972b4363aSmrgmsvisualcpp)
72072b4363aSmrg  # Important note: in order to support this mode, a compiler *must*
721dd77ae96Smrg  # always write the preprocessed file to stdout.
72272b4363aSmrg  "$@" || exit $?
723dd77ae96Smrg
724dd77ae96Smrg  # Remove the call to Libtool.
725dd77ae96Smrg  if test "$libtool" = yes; then
726dd77ae96Smrg    while test "X$1" != 'X--mode=compile'; do
727dd77ae96Smrg      shift
728dd77ae96Smrg    done
729dd77ae96Smrg    shift
730dd77ae96Smrg  fi
731dd77ae96Smrg
73272b4363aSmrg  IFS=" "
73372b4363aSmrg  for arg
73472b4363aSmrg  do
73572b4363aSmrg    case "$arg" in
736dd77ae96Smrg    -o)
737dd77ae96Smrg      shift
738dd77ae96Smrg      ;;
739dd77ae96Smrg    $object)
740dd77ae96Smrg      shift
741dd77ae96Smrg      ;;
74272b4363aSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74333dddc75Smrg        set fnord "$@"
74433dddc75Smrg        shift
74533dddc75Smrg        shift
74633dddc75Smrg        ;;
74772b4363aSmrg    *)
74833dddc75Smrg        set fnord "$@" "$arg"
74933dddc75Smrg        shift
75033dddc75Smrg        shift
75133dddc75Smrg        ;;
75272b4363aSmrg    esac
75372b4363aSmrg  done
754dd77ae96Smrg  "$@" -E 2>/dev/null |
755dd77ae96Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75672b4363aSmrg  rm -f "$depfile"
75772b4363aSmrg  echo "$object : \\" > "$depfile"
75833dddc75Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75933dddc75Smrg  echo "$tab" >> "$depfile"
760dd77ae96Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76172b4363aSmrg  rm -f "$tmpdepfile"
76272b4363aSmrg  ;;
76372b4363aSmrg
764dd77ae96Smrgmsvcmsys)
765dd77ae96Smrg  # This case exists only to let depend.m4 do its work.  It works by
766dd77ae96Smrg  # looking at the text of this script.  This case will never be run,
767dd77ae96Smrg  # since it is checked for above.
768dd77ae96Smrg  exit 1
769dd77ae96Smrg  ;;
770dd77ae96Smrg
77172b4363aSmrgnone)
77272b4363aSmrg  exec "$@"
77372b4363aSmrg  ;;
77472b4363aSmrg
77572b4363aSmrg*)
77672b4363aSmrg  echo "Unknown depmode $depmode" 1>&2
77772b4363aSmrg  exit 1
77872b4363aSmrg  ;;
77972b4363aSmrgesac
78072b4363aSmrg
78172b4363aSmrgexit 0
78272b4363aSmrg
78372b4363aSmrg# Local Variables:
78472b4363aSmrg# mode: shell-script
78572b4363aSmrg# sh-indentation: 2
7867ed541caSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
78772b4363aSmrg# time-stamp-start: "scriptversion="
78872b4363aSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7897ed541caSmrg# time-stamp-time-zone: "UTC0"
790dd77ae96Smrg# time-stamp-end: "; # UTC"
79172b4363aSmrg# End:
792