1e23ec014Smrg#! /bin/sh
205b261ecSmrg# depcomp - compile a program generating dependencies as side-effects
305b261ecSmrg
454b5899cSmrgscriptversion=2024-06-19.01; # UTC
505b261ecSmrg
654b5899cSmrg# Copyright (C) 1999-2024 Free Software Foundation, Inc.
705b261ecSmrg
805b261ecSmrg# This program is free software; you can redistribute it and/or modify
905b261ecSmrg# it under the terms of the GNU General Public License as published by
1005b261ecSmrg# the Free Software Foundation; either version 2, or (at your option)
1105b261ecSmrg# any later version.
1205b261ecSmrg
1305b261ecSmrg# This program is distributed in the hope that it will be useful,
1405b261ecSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1505b261ecSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1605b261ecSmrg# GNU General Public License for more details.
1705b261ecSmrg
1805b261ecSmrg# You should have received a copy of the GNU General Public License
19e23ec014Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2005b261ecSmrg
2105b261ecSmrg# As a special exception to the GNU General Public License, if you
2205b261ecSmrg# distribute this file as part of a program that contains a
2305b261ecSmrg# configuration script generated by Autoconf, you may include it under
2405b261ecSmrg# the same distribution terms that you use for the rest of that program.
2505b261ecSmrg
2605b261ecSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2705b261ecSmrg
2805b261ecSmrgcase $1 in
2905b261ecSmrg  '')
3035c4bbdfSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3135c4bbdfSmrg    exit 1;
3235c4bbdfSmrg    ;;
3305b261ecSmrg  -h | --h*)
3405b261ecSmrg    cat <<\EOF
3505b261ecSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3605b261ecSmrg
3705b261ecSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3805b261ecSmrgas side-effects.
3905b261ecSmrg
4005b261ecSmrgEnvironment variables:
4105b261ecSmrg  depmode     Dependency tracking mode.
4235c4bbdfSmrg  source      Source file read by 'PROGRAMS ARGS'.
4335c4bbdfSmrg  object      Object file output by 'PROGRAMS ARGS'.
4405b261ecSmrg  DEPDIR      directory where to store dependencies.
4505b261ecSmrg  depfile     Dependency file to output.
4635c4bbdfSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
4705b261ecSmrg  libtool     Whether libtool is used (yes/no).
4805b261ecSmrg
4905b261ecSmrgReport bugs to <bug-automake@gnu.org>.
5054b5899cSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
5154b5899cSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>.
5205b261ecSmrgEOF
5305b261ecSmrg    exit $?
5405b261ecSmrg    ;;
5505b261ecSmrg  -v | --v*)
5654b5899cSmrg    echo "depcomp (GNU Automake) $scriptversion"
5705b261ecSmrg    exit $?
5805b261ecSmrg    ;;
5905b261ecSmrgesac
6005b261ecSmrg
6135c4bbdfSmrg# Get the directory component of the given path, and save it in the
6235c4bbdfSmrg# global variables '$dir'.  Note that this directory component will
6335c4bbdfSmrg# be either empty or ending with a '/' character.  This is deliberate.
6435c4bbdfSmrgset_dir_from ()
6535c4bbdfSmrg{
6635c4bbdfSmrg  case $1 in
6735c4bbdfSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6835c4bbdfSmrg      *) dir=;;
6935c4bbdfSmrg  esac
7035c4bbdfSmrg}
7135c4bbdfSmrg
7235c4bbdfSmrg# Get the suffix-stripped basename of the given path, and save it the
7335c4bbdfSmrg# global variable '$base'.
7435c4bbdfSmrgset_base_from ()
7535c4bbdfSmrg{
7635c4bbdfSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7735c4bbdfSmrg}
7835c4bbdfSmrg
7935c4bbdfSmrg# If no dependency file was actually created by the compiler invocation,
8035c4bbdfSmrg# we still have to create a dummy depfile, to avoid errors with the
8135c4bbdfSmrg# Makefile "include basename.Plo" scheme.
8235c4bbdfSmrgmake_dummy_depfile ()
8335c4bbdfSmrg{
8435c4bbdfSmrg  echo "#dummy" > "$depfile"
8535c4bbdfSmrg}
8635c4bbdfSmrg
8735c4bbdfSmrg# Factor out some common post-processing of the generated depfile.
8835c4bbdfSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8935c4bbdfSmrgaix_post_process_depfile ()
9035c4bbdfSmrg{
9135c4bbdfSmrg  # If the compiler actually managed to produce a dependency file,
9235c4bbdfSmrg  # post-process it.
9335c4bbdfSmrg  if test -f "$tmpdepfile"; then
9435c4bbdfSmrg    # Each line is of the form 'foo.o: dependency.h'.
9535c4bbdfSmrg    # Do two passes, one to just change these to
9635c4bbdfSmrg    #   $object: dependency.h
9735c4bbdfSmrg    # and one to simply output
9835c4bbdfSmrg    #   dependency.h:
9935c4bbdfSmrg    # which is needed to avoid the deleted-header problem.
10035c4bbdfSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
10135c4bbdfSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10235c4bbdfSmrg    } > "$depfile"
10335c4bbdfSmrg    rm -f "$tmpdepfile"
10435c4bbdfSmrg  else
10535c4bbdfSmrg    make_dummy_depfile
10635c4bbdfSmrg  fi
10735c4bbdfSmrg}
10835c4bbdfSmrg
10935c4bbdfSmrg# A tabulation character.
11035c4bbdfSmrgtab='	'
11135c4bbdfSmrg# A newline character.
11235c4bbdfSmrgnl='
11335c4bbdfSmrg'
11435c4bbdfSmrg# Character ranges might be problematic outside the C locale.
11535c4bbdfSmrg# These definitions help.
11635c4bbdfSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11735c4bbdfSmrglower=abcdefghijklmnopqrstuvwxyz
11835c4bbdfSmrgalpha=${upper}${lower}
11935c4bbdfSmrg
12005b261ecSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12105b261ecSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12205b261ecSmrg  exit 1
12305b261ecSmrgfi
12405b261ecSmrg
12505b261ecSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12605b261ecSmrgdepfile=${depfile-`echo "$object" |
12705b261ecSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12805b261ecSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12905b261ecSmrg
13005b261ecSmrgrm -f "$tmpdepfile"
13105b261ecSmrg
13254b5899cSmrg# Avoid interference from the environment.
13335c4bbdfSmrggccflag= dashmflag=
13435c4bbdfSmrg
13505b261ecSmrg# Some modes work just like other modes, but use different flags.  We
13605b261ecSmrg# parameterize here, but still list the modes in the big case below,
13705b261ecSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13805b261ecSmrg# here, because this file can only contain one case statement.
13905b261ecSmrgif test "$depmode" = hp; then
14005b261ecSmrg  # HP compiler uses -M and no extra arg.
14105b261ecSmrg  gccflag=-M
14205b261ecSmrg  depmode=gcc
14305b261ecSmrgfi
14405b261ecSmrg
14505b261ecSmrgif test "$depmode" = dashXmstdout; then
14635c4bbdfSmrg  # This is just like dashmstdout with a different argument.
14735c4bbdfSmrg  dashmflag=-xM
14835c4bbdfSmrg  depmode=dashmstdout
14935c4bbdfSmrgfi
15035c4bbdfSmrg
15135c4bbdfSmrgcygpath_u="cygpath -u -f -"
15235c4bbdfSmrgif test "$depmode" = msvcmsys; then
15335c4bbdfSmrg  # This is just like msvisualcpp but w/o cygpath translation.
15435c4bbdfSmrg  # Just convert the backslash-escaped backslashes to single forward
15535c4bbdfSmrg  # slashes to satisfy depend.m4
15635c4bbdfSmrg  cygpath_u='sed s,\\\\,/,g'
15735c4bbdfSmrg  depmode=msvisualcpp
15835c4bbdfSmrgfi
15935c4bbdfSmrg
16035c4bbdfSmrgif test "$depmode" = msvc7msys; then
16135c4bbdfSmrg  # This is just like msvc7 but w/o cygpath translation.
16235c4bbdfSmrg  # Just convert the backslash-escaped backslashes to single forward
16335c4bbdfSmrg  # slashes to satisfy depend.m4
16435c4bbdfSmrg  cygpath_u='sed s,\\\\,/,g'
16535c4bbdfSmrg  depmode=msvc7
16635c4bbdfSmrgfi
16735c4bbdfSmrg
16835c4bbdfSmrgif test "$depmode" = xlc; then
16935c4bbdfSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
17035c4bbdfSmrg  gccflag=-qmakedep=gcc,-MF
17135c4bbdfSmrg  depmode=gcc
17205b261ecSmrgfi
17305b261ecSmrg
17405b261ecSmrgcase "$depmode" in
17505b261ecSmrggcc3)
17605b261ecSmrg## gcc 3 implements dependency tracking that does exactly what
17705b261ecSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17805b261ecSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
17905b261ecSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
18005b261ecSmrg## the command line argument order; so add the flags where they
18105b261ecSmrg## appear in depend2.am.  Note that the slowdown incurred here
18205b261ecSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18305b261ecSmrg  for arg
18405b261ecSmrg  do
18505b261ecSmrg    case $arg in
18605b261ecSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18705b261ecSmrg    *)  set fnord "$@" "$arg" ;;
18805b261ecSmrg    esac
18905b261ecSmrg    shift # fnord
19005b261ecSmrg    shift # $arg
19105b261ecSmrg  done
19205b261ecSmrg  "$@"
19305b261ecSmrg  stat=$?
19435c4bbdfSmrg  if test $stat -ne 0; then
19505b261ecSmrg    rm -f "$tmpdepfile"
19605b261ecSmrg    exit $stat
19705b261ecSmrg  fi
19805b261ecSmrg  mv "$tmpdepfile" "$depfile"
19905b261ecSmrg  ;;
20005b261ecSmrg
20105b261ecSmrggcc)
20254b5899cSmrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers.
20354b5899cSmrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler.
20435c4bbdfSmrg## (see the conditional assignment to $gccflag above).
20505b261ecSmrg## There are various ways to get dependency output from gcc.  Here's
20605b261ecSmrg## why we pick this rather obscure method:
20705b261ecSmrg## - Don't want to use -MD because we'd like the dependencies to end
20805b261ecSmrg##   up in a subdir.  Having to rename by hand is ugly.
20905b261ecSmrg##   (We might end up doing this anyway to support other compilers.)
21005b261ecSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21135c4bbdfSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21235c4bbdfSmrg##   supported by the other compilers which use the 'gcc' depmode.
21305b261ecSmrg## - Using -M directly means running the compiler twice (even worse
21405b261ecSmrg##   than renaming).
21505b261ecSmrg  if test -z "$gccflag"; then
21605b261ecSmrg    gccflag=-MD,
21705b261ecSmrg  fi
21805b261ecSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
21905b261ecSmrg  stat=$?
22035c4bbdfSmrg  if test $stat -ne 0; then
22105b261ecSmrg    rm -f "$tmpdepfile"
22205b261ecSmrg    exit $stat
22305b261ecSmrg  fi
22405b261ecSmrg  rm -f "$depfile"
22505b261ecSmrg  echo "$object : \\" > "$depfile"
22635c4bbdfSmrg  # The second -e expression handles DOS-style file names with drive
22735c4bbdfSmrg  # letters.
22805b261ecSmrg  sed -e 's/^[^:]*: / /' \
22905b261ecSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
23035c4bbdfSmrg## This next piece of magic avoids the "deleted header file" problem.
23105b261ecSmrg## The problem is that when a header file which appears in a .P file
23205b261ecSmrg## is deleted, the dependency causes make to die (because there is
23305b261ecSmrg## typically no way to rebuild the header).  We avoid this by adding
23405b261ecSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23505b261ecSmrg## this for us directly.
23635c4bbdfSmrg## Some versions of gcc put a space before the ':'.  On the theory
23705b261ecSmrg## that the space means something, we add a space to the output as
23835c4bbdfSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23935c4bbdfSmrg## to the object.  Take care to not repeat it in the output.
24005b261ecSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
24105b261ecSmrg## correctly.  Breaking it into two sed invocations is a workaround.
24235c4bbdfSmrg  tr ' ' "$nl" < "$tmpdepfile" \
24335c4bbdfSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24435c4bbdfSmrg    | sed -e 's/$/ :/' >> "$depfile"
24505b261ecSmrg  rm -f "$tmpdepfile"
24605b261ecSmrg  ;;
24705b261ecSmrg
24805b261ecSmrghp)
24905b261ecSmrg  # This case exists only to let depend.m4 do its work.  It works by
25005b261ecSmrg  # looking at the text of this script.  This case will never be run,
25105b261ecSmrg  # since it is checked for above.
25205b261ecSmrg  exit 1
25305b261ecSmrg  ;;
25405b261ecSmrg
25505b261ecSmrgsgi)
25605b261ecSmrg  if test "$libtool" = yes; then
25705b261ecSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25805b261ecSmrg  else
25905b261ecSmrg    "$@" -MDupdate "$tmpdepfile"
26005b261ecSmrg  fi
26105b261ecSmrg  stat=$?
26235c4bbdfSmrg  if test $stat -ne 0; then
26305b261ecSmrg    rm -f "$tmpdepfile"
26405b261ecSmrg    exit $stat
26505b261ecSmrg  fi
26605b261ecSmrg  rm -f "$depfile"
26705b261ecSmrg
26805b261ecSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26905b261ecSmrg    echo "$object : \\" > "$depfile"
27005b261ecSmrg    # Clip off the initial element (the dependent).  Don't try to be
27105b261ecSmrg    # clever and replace this with sed code, as IRIX sed won't handle
27205b261ecSmrg    # lines with more than a fixed number of characters (4096 in
27305b261ecSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27435c4bbdfSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
27505b261ecSmrg    # dependency line.
27635c4bbdfSmrg    tr ' ' "$nl" < "$tmpdepfile" \
27735c4bbdfSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27835c4bbdfSmrg      | tr "$nl" ' ' >> "$depfile"
27935c4bbdfSmrg    echo >> "$depfile"
28005b261ecSmrg    # The second pass generates a dummy entry for each header file.
28135c4bbdfSmrg    tr ' ' "$nl" < "$tmpdepfile" \
28235c4bbdfSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28335c4bbdfSmrg      >> "$depfile"
28405b261ecSmrg  else
28535c4bbdfSmrg    make_dummy_depfile
28605b261ecSmrg  fi
28705b261ecSmrg  rm -f "$tmpdepfile"
28805b261ecSmrg  ;;
28905b261ecSmrg
29035c4bbdfSmrgxlc)
29135c4bbdfSmrg  # This case exists only to let depend.m4 do its work.  It works by
29235c4bbdfSmrg  # looking at the text of this script.  This case will never be run,
29335c4bbdfSmrg  # since it is checked for above.
29435c4bbdfSmrg  exit 1
29535c4bbdfSmrg  ;;
29635c4bbdfSmrg
29705b261ecSmrgaix)
29805b261ecSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
29905b261ecSmrg  # in a .u file.  In older versions, this file always lives in the
30035c4bbdfSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30105b261ecSmrg  # start of each line; $object doesn't have directory information.
30205b261ecSmrg  # Version 6 uses the directory in both cases.
30335c4bbdfSmrg  set_dir_from "$object"
30435c4bbdfSmrg  set_base_from "$object"
30505b261ecSmrg  if test "$libtool" = yes; then
30635c4bbdfSmrg    tmpdepfile1=$dir$base.u
30735c4bbdfSmrg    tmpdepfile2=$base.u
30835c4bbdfSmrg    tmpdepfile3=$dir.libs/$base.u
30905b261ecSmrg    "$@" -Wc,-M
31005b261ecSmrg  else
31135c4bbdfSmrg    tmpdepfile1=$dir$base.u
31235c4bbdfSmrg    tmpdepfile2=$dir$base.u
31335c4bbdfSmrg    tmpdepfile3=$dir$base.u
31405b261ecSmrg    "$@" -M
31505b261ecSmrg  fi
31605b261ecSmrg  stat=$?
31735c4bbdfSmrg  if test $stat -ne 0; then
31835c4bbdfSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31935c4bbdfSmrg    exit $stat
320475c125cSmrg  fi
321475c125cSmrg
32235c4bbdfSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32335c4bbdfSmrg  do
32435c4bbdfSmrg    test -f "$tmpdepfile" && break
32535c4bbdfSmrg  done
32635c4bbdfSmrg  aix_post_process_depfile
32735c4bbdfSmrg  ;;
32835c4bbdfSmrg
32935c4bbdfSmrgtcc)
33035c4bbdfSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33135c4bbdfSmrg  # FIXME: That version still under development at the moment of writing.
33235c4bbdfSmrg  #        Make that this statement remains true also for stable, released
33335c4bbdfSmrg  #        versions.
33435c4bbdfSmrg  # It will wrap lines (doesn't matter whether long or short) with a
33535c4bbdfSmrg  # trailing '\', as in:
33635c4bbdfSmrg  #
33735c4bbdfSmrg  #   foo.o : \
33835c4bbdfSmrg  #    foo.c \
33935c4bbdfSmrg  #    foo.h \
34035c4bbdfSmrg  #
34135c4bbdfSmrg  # It will put a trailing '\' even on the last line, and will use leading
34235c4bbdfSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34335c4bbdfSmrg  # "Emit spaces for -MD").
34435c4bbdfSmrg  "$@" -MD -MF "$tmpdepfile"
34535c4bbdfSmrg  stat=$?
34635c4bbdfSmrg  if test $stat -ne 0; then
347475c125cSmrg    rm -f "$tmpdepfile"
34805b261ecSmrg    exit $stat
34905b261ecSmrg  fi
35035c4bbdfSmrg  rm -f "$depfile"
35135c4bbdfSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35235c4bbdfSmrg  # We have to change lines of the first kind to '$object: \'.
35335c4bbdfSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35435c4bbdfSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35535c4bbdfSmrg  # dummy dependency, to avoid the deleted-header problem.
35635c4bbdfSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35705b261ecSmrg  rm -f "$tmpdepfile"
35805b261ecSmrg  ;;
35905b261ecSmrg
36035c4bbdfSmrg## The order of this option in the case statement is important, since the
36135c4bbdfSmrg## shell code in configure will try each of these formats in the order
36235c4bbdfSmrg## listed in this file.  A plain '-MD' option would be understood by many
36335c4bbdfSmrg## compilers, so we must ensure this comes after the gcc and icc options.
36435c4bbdfSmrgpgcc)
36535c4bbdfSmrg  # Portland's C compiler understands '-MD'.
36635c4bbdfSmrg  # Will always output deps to 'file.d' where file is the root name of the
36735c4bbdfSmrg  # source file under compilation, even if file resides in a subdirectory.
36835c4bbdfSmrg  # The object file name does not affect the name of the '.d' file.
36935c4bbdfSmrg  # pgcc 10.2 will output
37005b261ecSmrg  #    foo.o: sub/foo.c sub/foo.h
37135c4bbdfSmrg  # and will wrap long lines using '\' :
37205b261ecSmrg  #    foo.o: sub/foo.c ... \
37305b261ecSmrg  #     sub/foo.h ... \
37405b261ecSmrg  #     ...
37535c4bbdfSmrg  set_dir_from "$object"
37635c4bbdfSmrg  # Use the source, not the object, to determine the base name, since
37735c4bbdfSmrg  # that's sadly what pgcc will do too.
37835c4bbdfSmrg  set_base_from "$source"
37935c4bbdfSmrg  tmpdepfile=$base.d
38035c4bbdfSmrg
38135c4bbdfSmrg  # For projects that build the same source file twice into different object
38235c4bbdfSmrg  # files, the pgcc approach of using the *source* file root name can cause
38335c4bbdfSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38435c4bbdfSmrg  # the same $tmpdepfile.
38535c4bbdfSmrg  lockdir=$base.d-lock
38635c4bbdfSmrg  trap "
38735c4bbdfSmrg    echo '$0: caught signal, cleaning up...' >&2
38835c4bbdfSmrg    rmdir '$lockdir'
38935c4bbdfSmrg    exit 1
39035c4bbdfSmrg  " 1 2 13 15
39135c4bbdfSmrg  numtries=100
39235c4bbdfSmrg  i=$numtries
39335c4bbdfSmrg  while test $i -gt 0; do
39435c4bbdfSmrg    # mkdir is a portable test-and-set.
39535c4bbdfSmrg    if mkdir "$lockdir" 2>/dev/null; then
39635c4bbdfSmrg      # This process acquired the lock.
39735c4bbdfSmrg      "$@" -MD
39835c4bbdfSmrg      stat=$?
39935c4bbdfSmrg      # Release the lock.
40035c4bbdfSmrg      rmdir "$lockdir"
40135c4bbdfSmrg      break
40235c4bbdfSmrg    else
40335c4bbdfSmrg      # If the lock is being held by a different process, wait
40435c4bbdfSmrg      # until the winning process is done or we timeout.
40535c4bbdfSmrg      while test -d "$lockdir" && test $i -gt 0; do
40635c4bbdfSmrg        sleep 1
40735c4bbdfSmrg        i=`expr $i - 1`
40835c4bbdfSmrg      done
40935c4bbdfSmrg    fi
41035c4bbdfSmrg    i=`expr $i - 1`
41135c4bbdfSmrg  done
41235c4bbdfSmrg  trap - 1 2 13 15
41335c4bbdfSmrg  if test $i -le 0; then
41435c4bbdfSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41535c4bbdfSmrg    echo "$0: check lockdir '$lockdir'" >&2
41635c4bbdfSmrg    exit 1
41735c4bbdfSmrg  fi
41805b261ecSmrg
41935c4bbdfSmrg  if test $stat -ne 0; then
42005b261ecSmrg    rm -f "$tmpdepfile"
42105b261ecSmrg    exit $stat
42205b261ecSmrg  fi
42305b261ecSmrg  rm -f "$depfile"
42405b261ecSmrg  # Each line is of the form `foo.o: dependent.h',
42505b261ecSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42605b261ecSmrg  # Do two passes, one to just change these to
42705b261ecSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42805b261ecSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42905b261ecSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
43005b261ecSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
43135c4bbdfSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43235c4bbdfSmrg    | sed -e 's/$/ :/' >> "$depfile"
43305b261ecSmrg  rm -f "$tmpdepfile"
43405b261ecSmrg  ;;
43505b261ecSmrg
43605b261ecSmrghp2)
43705b261ecSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43805b261ecSmrg  # compilers, which have integrated preprocessors.  The correct option
43905b261ecSmrg  # to use with these is +Maked; it writes dependencies to a file named
44005b261ecSmrg  # 'foo.d', which lands next to the object file, wherever that
44105b261ecSmrg  # happens to be.
44205b261ecSmrg  # Much of this is similar to the tru64 case; see comments there.
44335c4bbdfSmrg  set_dir_from  "$object"
44435c4bbdfSmrg  set_base_from "$object"
44505b261ecSmrg  if test "$libtool" = yes; then
44605b261ecSmrg    tmpdepfile1=$dir$base.d
44705b261ecSmrg    tmpdepfile2=$dir.libs/$base.d
44805b261ecSmrg    "$@" -Wc,+Maked
44905b261ecSmrg  else
45005b261ecSmrg    tmpdepfile1=$dir$base.d
45105b261ecSmrg    tmpdepfile2=$dir$base.d
45205b261ecSmrg    "$@" +Maked
45305b261ecSmrg  fi
45405b261ecSmrg  stat=$?
45535c4bbdfSmrg  if test $stat -ne 0; then
45605b261ecSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
45705b261ecSmrg     exit $stat
45805b261ecSmrg  fi
45905b261ecSmrg
46005b261ecSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46105b261ecSmrg  do
46205b261ecSmrg    test -f "$tmpdepfile" && break
46305b261ecSmrg  done
46405b261ecSmrg  if test -f "$tmpdepfile"; then
46535c4bbdfSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46635c4bbdfSmrg    # Add 'dependent.h:' lines.
46735c4bbdfSmrg    sed -ne '2,${
46835c4bbdfSmrg               s/^ *//
46935c4bbdfSmrg               s/ \\*$//
47035c4bbdfSmrg               s/$/:/
47135c4bbdfSmrg               p
47235c4bbdfSmrg             }' "$tmpdepfile" >> "$depfile"
47305b261ecSmrg  else
47435c4bbdfSmrg    make_dummy_depfile
47505b261ecSmrg  fi
47605b261ecSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
47705b261ecSmrg  ;;
47805b261ecSmrg
47905b261ecSmrgtru64)
48035c4bbdfSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48135c4bbdfSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48235c4bbdfSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48335c4bbdfSmrg  # dependencies in 'foo.d' instead, so we check for that too.
48435c4bbdfSmrg  # Subdirectories are respected.
48535c4bbdfSmrg  set_dir_from  "$object"
48635c4bbdfSmrg  set_base_from "$object"
48735c4bbdfSmrg
48835c4bbdfSmrg  if test "$libtool" = yes; then
48935c4bbdfSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
49035c4bbdfSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49135c4bbdfSmrg    # in $dir$base.o.d.  We have to check for both files, because
49235c4bbdfSmrg    # one of the two compilations can be disabled.  We should prefer
49335c4bbdfSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49435c4bbdfSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
49535c4bbdfSmrg    # the former would cause a distcleancheck panic.
49635c4bbdfSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49735c4bbdfSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49835c4bbdfSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49935c4bbdfSmrg    "$@" -Wc,-MD
50035c4bbdfSmrg  else
50135c4bbdfSmrg    tmpdepfile1=$dir$base.d
50235c4bbdfSmrg    tmpdepfile2=$dir$base.d
50335c4bbdfSmrg    tmpdepfile3=$dir$base.d
50435c4bbdfSmrg    "$@" -MD
50535c4bbdfSmrg  fi
50635c4bbdfSmrg
50735c4bbdfSmrg  stat=$?
50835c4bbdfSmrg  if test $stat -ne 0; then
50935c4bbdfSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51035c4bbdfSmrg    exit $stat
51135c4bbdfSmrg  fi
51235c4bbdfSmrg
51335c4bbdfSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51435c4bbdfSmrg  do
51535c4bbdfSmrg    test -f "$tmpdepfile" && break
51635c4bbdfSmrg  done
51735c4bbdfSmrg  # Same post-processing that is required for AIX mode.
51835c4bbdfSmrg  aix_post_process_depfile
51935c4bbdfSmrg  ;;
52035c4bbdfSmrg
52135c4bbdfSmrgmsvc7)
52235c4bbdfSmrg  if test "$libtool" = yes; then
52335c4bbdfSmrg    showIncludes=-Wc,-showIncludes
52435c4bbdfSmrg  else
52535c4bbdfSmrg    showIncludes=-showIncludes
52635c4bbdfSmrg  fi
52735c4bbdfSmrg  "$@" $showIncludes > "$tmpdepfile"
52835c4bbdfSmrg  stat=$?
52935c4bbdfSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
53035c4bbdfSmrg  if test $stat -ne 0; then
53135c4bbdfSmrg    rm -f "$tmpdepfile"
53235c4bbdfSmrg    exit $stat
53335c4bbdfSmrg  fi
53435c4bbdfSmrg  rm -f "$depfile"
53535c4bbdfSmrg  echo "$object : \\" > "$depfile"
53635c4bbdfSmrg  # The first sed program below extracts the file names and escapes
53735c4bbdfSmrg  # backslashes for cygpath.  The second sed program outputs the file
53835c4bbdfSmrg  # name when reading, but also accumulates all include files in the
53935c4bbdfSmrg  # hold buffer in order to output them again at the end.  This only
54035c4bbdfSmrg  # works with sed implementations that can handle large buffers.
54135c4bbdfSmrg  sed < "$tmpdepfile" -n '
54235c4bbdfSmrg/^Note: including file:  *\(.*\)/ {
54335c4bbdfSmrg  s//\1/
54435c4bbdfSmrg  s/\\/\\\\/g
54535c4bbdfSmrg  p
54635c4bbdfSmrg}' | $cygpath_u | sort -u | sed -n '
54735c4bbdfSmrgs/ /\\ /g
54835c4bbdfSmrgs/\(.*\)/'"$tab"'\1 \\/p
54935c4bbdfSmrgs/.\(.*\) \\/\1:/
55035c4bbdfSmrgH
55135c4bbdfSmrg$ {
55235c4bbdfSmrg  s/.*/'"$tab"'/
55335c4bbdfSmrg  G
55435c4bbdfSmrg  p
55535c4bbdfSmrg}' >> "$depfile"
55635c4bbdfSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55735c4bbdfSmrg  rm -f "$tmpdepfile"
55835c4bbdfSmrg  ;;
55935c4bbdfSmrg
56035c4bbdfSmrgmsvc7msys)
56135c4bbdfSmrg  # This case exists only to let depend.m4 do its work.  It works by
56235c4bbdfSmrg  # looking at the text of this script.  This case will never be run,
56335c4bbdfSmrg  # since it is checked for above.
56435c4bbdfSmrg  exit 1
56535c4bbdfSmrg  ;;
56605b261ecSmrg
56705b261ecSmrg#nosideeffect)
56805b261ecSmrg  # This comment above is used by automake to tell side-effect
56905b261ecSmrg  # dependency tracking mechanisms from slower ones.
57005b261ecSmrg
57105b261ecSmrgdashmstdout)
57205b261ecSmrg  # Important note: in order to support this mode, a compiler *must*
57305b261ecSmrg  # always write the preprocessed file to stdout, regardless of -o.
57405b261ecSmrg  "$@" || exit $?
57505b261ecSmrg
57605b261ecSmrg  # Remove the call to Libtool.
57705b261ecSmrg  if test "$libtool" = yes; then
57835c4bbdfSmrg    while test "X$1" != 'X--mode=compile'; do
57905b261ecSmrg      shift
58005b261ecSmrg    done
58105b261ecSmrg    shift
58205b261ecSmrg  fi
58305b261ecSmrg
58435c4bbdfSmrg  # Remove '-o $object'.
58505b261ecSmrg  IFS=" "
58605b261ecSmrg  for arg
58705b261ecSmrg  do
58805b261ecSmrg    case $arg in
58905b261ecSmrg    -o)
59005b261ecSmrg      shift
59105b261ecSmrg      ;;
59205b261ecSmrg    $object)
59305b261ecSmrg      shift
59405b261ecSmrg      ;;
59505b261ecSmrg    *)
59605b261ecSmrg      set fnord "$@" "$arg"
59705b261ecSmrg      shift # fnord
59805b261ecSmrg      shift # $arg
59905b261ecSmrg      ;;
60005b261ecSmrg    esac
60105b261ecSmrg  done
60205b261ecSmrg
60305b261ecSmrg  test -z "$dashmflag" && dashmflag=-M
60435c4bbdfSmrg  # Require at least two characters before searching for ':'
60505b261ecSmrg  # in the target name.  This is to cope with DOS-style filenames:
60635c4bbdfSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60705b261ecSmrg  "$@" $dashmflag |
60835c4bbdfSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60905b261ecSmrg  rm -f "$depfile"
61005b261ecSmrg  cat < "$tmpdepfile" > "$depfile"
61135c4bbdfSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61235c4bbdfSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
61335c4bbdfSmrg  tr ' ' "$nl" < "$tmpdepfile" \
61435c4bbdfSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61535c4bbdfSmrg    | sed -e 's/$/ :/' >> "$depfile"
61605b261ecSmrg  rm -f "$tmpdepfile"
61705b261ecSmrg  ;;
61805b261ecSmrg
61905b261ecSmrgdashXmstdout)
62005b261ecSmrg  # This case only exists to satisfy depend.m4.  It is never actually
62105b261ecSmrg  # run, as this mode is specially recognized in the preamble.
62205b261ecSmrg  exit 1
62305b261ecSmrg  ;;
62405b261ecSmrg
62505b261ecSmrgmakedepend)
62605b261ecSmrg  "$@" || exit $?
62705b261ecSmrg  # Remove any Libtool call
62805b261ecSmrg  if test "$libtool" = yes; then
62935c4bbdfSmrg    while test "X$1" != 'X--mode=compile'; do
63005b261ecSmrg      shift
63105b261ecSmrg    done
63205b261ecSmrg    shift
63305b261ecSmrg  fi
63405b261ecSmrg  # X makedepend
63505b261ecSmrg  shift
63635c4bbdfSmrg  cleared=no eat=no
63735c4bbdfSmrg  for arg
63835c4bbdfSmrg  do
63905b261ecSmrg    case $cleared in
64005b261ecSmrg    no)
64105b261ecSmrg      set ""; shift
64205b261ecSmrg      cleared=yes ;;
64305b261ecSmrg    esac
64435c4bbdfSmrg    if test $eat = yes; then
64535c4bbdfSmrg      eat=no
64635c4bbdfSmrg      continue
64735c4bbdfSmrg    fi
64805b261ecSmrg    case "$arg" in
64905b261ecSmrg    -D*|-I*)
65005b261ecSmrg      set fnord "$@" "$arg"; shift ;;
65105b261ecSmrg    # Strip any option that makedepend may not understand.  Remove
65205b261ecSmrg    # the object too, otherwise makedepend will parse it as a source file.
65335c4bbdfSmrg    -arch)
65435c4bbdfSmrg      eat=yes ;;
65505b261ecSmrg    -*|$object)
65605b261ecSmrg      ;;
65705b261ecSmrg    *)
65805b261ecSmrg      set fnord "$@" "$arg"; shift ;;
65905b261ecSmrg    esac
66005b261ecSmrg  done
66135c4bbdfSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66205b261ecSmrg  touch "$tmpdepfile"
66305b261ecSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66405b261ecSmrg  rm -f "$depfile"
66535c4bbdfSmrg  # makedepend may prepend the VPATH from the source file name to the object.
66635c4bbdfSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66735c4bbdfSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66835c4bbdfSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66935c4bbdfSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
67035c4bbdfSmrg  sed '1,2d' "$tmpdepfile" \
67135c4bbdfSmrg    | tr ' ' "$nl" \
67235c4bbdfSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67335c4bbdfSmrg    | sed -e 's/$/ :/' >> "$depfile"
67405b261ecSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67505b261ecSmrg  ;;
67605b261ecSmrg
67705b261ecSmrgcpp)
67805b261ecSmrg  # Important note: in order to support this mode, a compiler *must*
67905b261ecSmrg  # always write the preprocessed file to stdout.
68005b261ecSmrg  "$@" || exit $?
68105b261ecSmrg
68205b261ecSmrg  # Remove the call to Libtool.
68305b261ecSmrg  if test "$libtool" = yes; then
68435c4bbdfSmrg    while test "X$1" != 'X--mode=compile'; do
68505b261ecSmrg      shift
68605b261ecSmrg    done
68705b261ecSmrg    shift
68805b261ecSmrg  fi
68905b261ecSmrg
69035c4bbdfSmrg  # Remove '-o $object'.
69105b261ecSmrg  IFS=" "
69205b261ecSmrg  for arg
69305b261ecSmrg  do
69405b261ecSmrg    case $arg in
69505b261ecSmrg    -o)
69605b261ecSmrg      shift
69705b261ecSmrg      ;;
69805b261ecSmrg    $object)
69905b261ecSmrg      shift
70005b261ecSmrg      ;;
70105b261ecSmrg    *)
70205b261ecSmrg      set fnord "$@" "$arg"
70305b261ecSmrg      shift # fnord
70405b261ecSmrg      shift # $arg
70505b261ecSmrg      ;;
70605b261ecSmrg    esac
70705b261ecSmrg  done
70805b261ecSmrg
70935c4bbdfSmrg  "$@" -E \
71035c4bbdfSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71135c4bbdfSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71235c4bbdfSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
71305b261ecSmrg  rm -f "$depfile"
71405b261ecSmrg  echo "$object : \\" > "$depfile"
71505b261ecSmrg  cat < "$tmpdepfile" >> "$depfile"
71605b261ecSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71705b261ecSmrg  rm -f "$tmpdepfile"
71805b261ecSmrg  ;;
71905b261ecSmrg
72005b261ecSmrgmsvisualcpp)
72105b261ecSmrg  # Important note: in order to support this mode, a compiler *must*
72235c4bbdfSmrg  # always write the preprocessed file to stdout.
72305b261ecSmrg  "$@" || exit $?
72435c4bbdfSmrg
72535c4bbdfSmrg  # Remove the call to Libtool.
72635c4bbdfSmrg  if test "$libtool" = yes; then
72735c4bbdfSmrg    while test "X$1" != 'X--mode=compile'; do
72835c4bbdfSmrg      shift
72935c4bbdfSmrg    done
73035c4bbdfSmrg    shift
73135c4bbdfSmrg  fi
73235c4bbdfSmrg
73305b261ecSmrg  IFS=" "
73405b261ecSmrg  for arg
73505b261ecSmrg  do
73605b261ecSmrg    case "$arg" in
73735c4bbdfSmrg    -o)
73835c4bbdfSmrg      shift
73935c4bbdfSmrg      ;;
74035c4bbdfSmrg    $object)
74135c4bbdfSmrg      shift
74235c4bbdfSmrg      ;;
74305b261ecSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74435c4bbdfSmrg        set fnord "$@"
74535c4bbdfSmrg        shift
74635c4bbdfSmrg        shift
74735c4bbdfSmrg        ;;
74805b261ecSmrg    *)
74935c4bbdfSmrg        set fnord "$@" "$arg"
75035c4bbdfSmrg        shift
75135c4bbdfSmrg        shift
75235c4bbdfSmrg        ;;
75305b261ecSmrg    esac
75405b261ecSmrg  done
75535c4bbdfSmrg  "$@" -E 2>/dev/null |
75635c4bbdfSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75705b261ecSmrg  rm -f "$depfile"
75805b261ecSmrg  echo "$object : \\" > "$depfile"
75935c4bbdfSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
76035c4bbdfSmrg  echo "$tab" >> "$depfile"
76135c4bbdfSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76205b261ecSmrg  rm -f "$tmpdepfile"
76305b261ecSmrg  ;;
76405b261ecSmrg
76535c4bbdfSmrgmsvcmsys)
76635c4bbdfSmrg  # This case exists only to let depend.m4 do its work.  It works by
76735c4bbdfSmrg  # looking at the text of this script.  This case will never be run,
76835c4bbdfSmrg  # since it is checked for above.
76935c4bbdfSmrg  exit 1
77035c4bbdfSmrg  ;;
77135c4bbdfSmrg
77205b261ecSmrgnone)
77305b261ecSmrg  exec "$@"
77405b261ecSmrg  ;;
77505b261ecSmrg
77605b261ecSmrg*)
77705b261ecSmrg  echo "Unknown depmode $depmode" 1>&2
77805b261ecSmrg  exit 1
77905b261ecSmrg  ;;
78005b261ecSmrgesac
78105b261ecSmrg
78205b261ecSmrgexit 0
78305b261ecSmrg
78405b261ecSmrg# Local Variables:
78505b261ecSmrg# mode: shell-script
78605b261ecSmrg# sh-indentation: 2
787e23ec014Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
78805b261ecSmrg# time-stamp-start: "scriptversion="
78905b261ecSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7901b5d61b8Smrg# time-stamp-time-zone: "UTC0"
79135c4bbdfSmrg# time-stamp-end: "; # UTC"
79205b261ecSmrg# End:
793