1c43cc173Smrg#! /bin/sh
2c43cc173Smrg# depcomp - compile a program generating dependencies as side-effects
3c43cc173Smrg
44940c694Smrgscriptversion=2018-03-07.03; # UTC
5c43cc173Smrg
64e8f48c7Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
7c43cc173Smrg
8c43cc173Smrg# This program is free software; you can redistribute it and/or modify
9c43cc173Smrg# it under the terms of the GNU General Public License as published by
10c43cc173Smrg# the Free Software Foundation; either version 2, or (at your option)
11c43cc173Smrg# any later version.
12c43cc173Smrg
13c43cc173Smrg# This program is distributed in the hope that it will be useful,
14c43cc173Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15c43cc173Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c43cc173Smrg# GNU General Public License for more details.
17c43cc173Smrg
18c43cc173Smrg# You should have received a copy of the GNU General Public License
194940c694Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20c43cc173Smrg
21c43cc173Smrg# As a special exception to the GNU General Public License, if you
22c43cc173Smrg# distribute this file as part of a program that contains a
23c43cc173Smrg# configuration script generated by Autoconf, you may include it under
24c43cc173Smrg# the same distribution terms that you use for the rest of that program.
25c43cc173Smrg
26c43cc173Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27c43cc173Smrg
28c43cc173Smrgcase $1 in
29c43cc173Smrg  '')
3006c34b88Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3106c34b88Smrg    exit 1;
3206c34b88Smrg    ;;
33c43cc173Smrg  -h | --h*)
34c43cc173Smrg    cat <<\EOF
35c43cc173SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36c43cc173Smrg
37c43cc173SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38c43cc173Smrgas side-effects.
39c43cc173Smrg
40c43cc173SmrgEnvironment variables:
41c43cc173Smrg  depmode     Dependency tracking mode.
42f1ee322dSmrg  source      Source file read by 'PROGRAMS ARGS'.
43f1ee322dSmrg  object      Object file output by 'PROGRAMS ARGS'.
44c43cc173Smrg  DEPDIR      directory where to store dependencies.
45c43cc173Smrg  depfile     Dependency file to output.
46f1ee322dSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
47c43cc173Smrg  libtool     Whether libtool is used (yes/no).
48c43cc173Smrg
49c43cc173SmrgReport bugs to <bug-automake@gnu.org>.
50c43cc173SmrgEOF
51c43cc173Smrg    exit $?
52c43cc173Smrg    ;;
53c43cc173Smrg  -v | --v*)
54c43cc173Smrg    echo "depcomp $scriptversion"
55c43cc173Smrg    exit $?
56c43cc173Smrg    ;;
57c43cc173Smrgesac
58c43cc173Smrg
5906c34b88Smrg# Get the directory component of the given path, and save it in the
6006c34b88Smrg# global variables '$dir'.  Note that this directory component will
6106c34b88Smrg# be either empty or ending with a '/' character.  This is deliberate.
6206c34b88Smrgset_dir_from ()
6306c34b88Smrg{
6406c34b88Smrg  case $1 in
6506c34b88Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6606c34b88Smrg      *) dir=;;
6706c34b88Smrg  esac
6806c34b88Smrg}
6906c34b88Smrg
7006c34b88Smrg# Get the suffix-stripped basename of the given path, and save it the
7106c34b88Smrg# global variable '$base'.
7206c34b88Smrgset_base_from ()
7306c34b88Smrg{
7406c34b88Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7506c34b88Smrg}
7606c34b88Smrg
7706c34b88Smrg# If no dependency file was actually created by the compiler invocation,
7806c34b88Smrg# we still have to create a dummy depfile, to avoid errors with the
7906c34b88Smrg# Makefile "include basename.Plo" scheme.
8006c34b88Smrgmake_dummy_depfile ()
8106c34b88Smrg{
8206c34b88Smrg  echo "#dummy" > "$depfile"
8306c34b88Smrg}
8406c34b88Smrg
8506c34b88Smrg# Factor out some common post-processing of the generated depfile.
8606c34b88Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8706c34b88Smrgaix_post_process_depfile ()
8806c34b88Smrg{
8906c34b88Smrg  # If the compiler actually managed to produce a dependency file,
9006c34b88Smrg  # post-process it.
9106c34b88Smrg  if test -f "$tmpdepfile"; then
9206c34b88Smrg    # Each line is of the form 'foo.o: dependency.h'.
9306c34b88Smrg    # Do two passes, one to just change these to
9406c34b88Smrg    #   $object: dependency.h
9506c34b88Smrg    # and one to simply output
9606c34b88Smrg    #   dependency.h:
9706c34b88Smrg    # which is needed to avoid the deleted-header problem.
9806c34b88Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9906c34b88Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10006c34b88Smrg    } > "$depfile"
10106c34b88Smrg    rm -f "$tmpdepfile"
10206c34b88Smrg  else
10306c34b88Smrg    make_dummy_depfile
10406c34b88Smrg  fi
10506c34b88Smrg}
10606c34b88Smrg
107f1ee322dSmrg# A tabulation character.
108f1ee322dSmrgtab='	'
109f1ee322dSmrg# A newline character.
110f1ee322dSmrgnl='
111f1ee322dSmrg'
11206c34b88Smrg# Character ranges might be problematic outside the C locale.
11306c34b88Smrg# These definitions help.
11406c34b88Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11506c34b88Smrglower=abcdefghijklmnopqrstuvwxyz
11606c34b88Smrgdigits=0123456789
11706c34b88Smrgalpha=${upper}${lower}
118f1ee322dSmrg
119c43cc173Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120c43cc173Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121c43cc173Smrg  exit 1
122c43cc173Smrgfi
123c43cc173Smrg
124c43cc173Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125c43cc173Smrgdepfile=${depfile-`echo "$object" |
126c43cc173Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127c43cc173Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128c43cc173Smrg
129c43cc173Smrgrm -f "$tmpdepfile"
130c43cc173Smrg
13106c34b88Smrg# Avoid interferences from the environment.
13206c34b88Smrggccflag= dashmflag=
13306c34b88Smrg
134c43cc173Smrg# Some modes work just like other modes, but use different flags.  We
135c43cc173Smrg# parameterize here, but still list the modes in the big case below,
136c43cc173Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137c43cc173Smrg# here, because this file can only contain one case statement.
138c43cc173Smrgif test "$depmode" = hp; then
139c43cc173Smrg  # HP compiler uses -M and no extra arg.
140c43cc173Smrg  gccflag=-M
141c43cc173Smrg  depmode=gcc
142c43cc173Smrgfi
143c43cc173Smrg
144c43cc173Smrgif test "$depmode" = dashXmstdout; then
14506c34b88Smrg  # This is just like dashmstdout with a different argument.
14606c34b88Smrg  dashmflag=-xM
14706c34b88Smrg  depmode=dashmstdout
148c43cc173Smrgfi
149c43cc173Smrg
150c27c18e8Smrgcygpath_u="cygpath -u -f -"
151c27c18e8Smrgif test "$depmode" = msvcmsys; then
15206c34b88Smrg  # This is just like msvisualcpp but w/o cygpath translation.
15306c34b88Smrg  # Just convert the backslash-escaped backslashes to single forward
15406c34b88Smrg  # slashes to satisfy depend.m4
15506c34b88Smrg  cygpath_u='sed s,\\\\,/,g'
15606c34b88Smrg  depmode=msvisualcpp
157c27c18e8Smrgfi
158c27c18e8Smrg
159f1ee322dSmrgif test "$depmode" = msvc7msys; then
16006c34b88Smrg  # This is just like msvc7 but w/o cygpath translation.
16106c34b88Smrg  # Just convert the backslash-escaped backslashes to single forward
16206c34b88Smrg  # slashes to satisfy depend.m4
16306c34b88Smrg  cygpath_u='sed s,\\\\,/,g'
16406c34b88Smrg  depmode=msvc7
165f1ee322dSmrgfi
166f1ee322dSmrg
167f1ee322dSmrgif test "$depmode" = xlc; then
16806c34b88Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16906c34b88Smrg  gccflag=-qmakedep=gcc,-MF
17006c34b88Smrg  depmode=gcc
171f1ee322dSmrgfi
172f1ee322dSmrg
173c43cc173Smrgcase "$depmode" in
174c43cc173Smrggcc3)
175c43cc173Smrg## gcc 3 implements dependency tracking that does exactly what
176c43cc173Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177c43cc173Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178c43cc173Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179c43cc173Smrg## the command line argument order; so add the flags where they
180c43cc173Smrg## appear in depend2.am.  Note that the slowdown incurred here
181c43cc173Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182c43cc173Smrg  for arg
183c43cc173Smrg  do
184c43cc173Smrg    case $arg in
185c43cc173Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186c43cc173Smrg    *)  set fnord "$@" "$arg" ;;
187c43cc173Smrg    esac
188c43cc173Smrg    shift # fnord
189c43cc173Smrg    shift # $arg
190c43cc173Smrg  done
191c43cc173Smrg  "$@"
192c43cc173Smrg  stat=$?
19306c34b88Smrg  if test $stat -ne 0; then
194c43cc173Smrg    rm -f "$tmpdepfile"
195c43cc173Smrg    exit $stat
196c43cc173Smrg  fi
197c43cc173Smrg  mv "$tmpdepfile" "$depfile"
198c43cc173Smrg  ;;
199c43cc173Smrg
200c43cc173Smrggcc)
20106c34b88Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20206c34b88Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20306c34b88Smrg## (see the conditional assignment to $gccflag above).
204c43cc173Smrg## There are various ways to get dependency output from gcc.  Here's
205c43cc173Smrg## why we pick this rather obscure method:
206c43cc173Smrg## - Don't want to use -MD because we'd like the dependencies to end
207c43cc173Smrg##   up in a subdir.  Having to rename by hand is ugly.
208c43cc173Smrg##   (We might end up doing this anyway to support other compilers.)
209c43cc173Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21006c34b88Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21106c34b88Smrg##   supported by the other compilers which use the 'gcc' depmode.
212c43cc173Smrg## - Using -M directly means running the compiler twice (even worse
213c43cc173Smrg##   than renaming).
214c43cc173Smrg  if test -z "$gccflag"; then
215c43cc173Smrg    gccflag=-MD,
216c43cc173Smrg  fi
217c43cc173Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218c43cc173Smrg  stat=$?
21906c34b88Smrg  if test $stat -ne 0; then
220c43cc173Smrg    rm -f "$tmpdepfile"
221c43cc173Smrg    exit $stat
222c43cc173Smrg  fi
223c43cc173Smrg  rm -f "$depfile"
224c43cc173Smrg  echo "$object : \\" > "$depfile"
22506c34b88Smrg  # The second -e expression handles DOS-style file names with drive
22606c34b88Smrg  # letters.
227c43cc173Smrg  sed -e 's/^[^:]*: / /' \
228c43cc173Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229f1ee322dSmrg## This next piece of magic avoids the "deleted header file" problem.
230c43cc173Smrg## The problem is that when a header file which appears in a .P file
231c43cc173Smrg## is deleted, the dependency causes make to die (because there is
232c43cc173Smrg## typically no way to rebuild the header).  We avoid this by adding
233c43cc173Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234c43cc173Smrg## this for us directly.
235f1ee322dSmrg## Some versions of gcc put a space before the ':'.  On the theory
236c43cc173Smrg## that the space means something, we add a space to the output as
237f1ee322dSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238f1ee322dSmrg## to the object.  Take care to not repeat it in the output.
239c43cc173Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240c43cc173Smrg## correctly.  Breaking it into two sed invocations is a workaround.
24106c34b88Smrg  tr ' ' "$nl" < "$tmpdepfile" \
24206c34b88Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24306c34b88Smrg    | sed -e 's/$/ :/' >> "$depfile"
244c43cc173Smrg  rm -f "$tmpdepfile"
245c43cc173Smrg  ;;
246c43cc173Smrg
247c43cc173Smrghp)
248c43cc173Smrg  # This case exists only to let depend.m4 do its work.  It works by
249c43cc173Smrg  # looking at the text of this script.  This case will never be run,
250c43cc173Smrg  # since it is checked for above.
251c43cc173Smrg  exit 1
252c43cc173Smrg  ;;
253c43cc173Smrg
254c43cc173Smrgsgi)
255c43cc173Smrg  if test "$libtool" = yes; then
256c43cc173Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257c43cc173Smrg  else
258c43cc173Smrg    "$@" -MDupdate "$tmpdepfile"
259c43cc173Smrg  fi
260c43cc173Smrg  stat=$?
26106c34b88Smrg  if test $stat -ne 0; then
262c43cc173Smrg    rm -f "$tmpdepfile"
263c43cc173Smrg    exit $stat
264c43cc173Smrg  fi
265c43cc173Smrg  rm -f "$depfile"
266c43cc173Smrg
267c43cc173Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268c43cc173Smrg    echo "$object : \\" > "$depfile"
269c43cc173Smrg    # Clip off the initial element (the dependent).  Don't try to be
270c43cc173Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271c43cc173Smrg    # lines with more than a fixed number of characters (4096 in
272c43cc173Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273f1ee322dSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
274c43cc173Smrg    # dependency line.
275f1ee322dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
27606c34b88Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27706c34b88Smrg      | tr "$nl" ' ' >> "$depfile"
278c27c18e8Smrg    echo >> "$depfile"
279c43cc173Smrg    # The second pass generates a dummy entry for each header file.
280f1ee322dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
28106c34b88Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28206c34b88Smrg      >> "$depfile"
283c43cc173Smrg  else
28406c34b88Smrg    make_dummy_depfile
285c43cc173Smrg  fi
286c43cc173Smrg  rm -f "$tmpdepfile"
287c43cc173Smrg  ;;
288c43cc173Smrg
289f1ee322dSmrgxlc)
290f1ee322dSmrg  # This case exists only to let depend.m4 do its work.  It works by
291f1ee322dSmrg  # looking at the text of this script.  This case will never be run,
292f1ee322dSmrg  # since it is checked for above.
293f1ee322dSmrg  exit 1
294f1ee322dSmrg  ;;
295f1ee322dSmrg
296c43cc173Smrgaix)
297c43cc173Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298c43cc173Smrg  # in a .u file.  In older versions, this file always lives in the
299f1ee322dSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300c43cc173Smrg  # start of each line; $object doesn't have directory information.
301c43cc173Smrg  # Version 6 uses the directory in both cases.
30206c34b88Smrg  set_dir_from "$object"
30306c34b88Smrg  set_base_from "$object"
304c43cc173Smrg  if test "$libtool" = yes; then
305c27c18e8Smrg    tmpdepfile1=$dir$base.u
306c27c18e8Smrg    tmpdepfile2=$base.u
307c27c18e8Smrg    tmpdepfile3=$dir.libs/$base.u
308c43cc173Smrg    "$@" -Wc,-M
309c43cc173Smrg  else
310c27c18e8Smrg    tmpdepfile1=$dir$base.u
311c27c18e8Smrg    tmpdepfile2=$dir$base.u
312c27c18e8Smrg    tmpdepfile3=$dir$base.u
313c43cc173Smrg    "$@" -M
314c43cc173Smrg  fi
315c43cc173Smrg  stat=$?
31606c34b88Smrg  if test $stat -ne 0; then
317c27c18e8Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318c43cc173Smrg    exit $stat
319c43cc173Smrg  fi
320c43cc173Smrg
321c27c18e8Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322c27c18e8Smrg  do
323c27c18e8Smrg    test -f "$tmpdepfile" && break
324c27c18e8Smrg  done
32506c34b88Smrg  aix_post_process_depfile
32606c34b88Smrg  ;;
32706c34b88Smrg
32806c34b88Smrgtcc)
32906c34b88Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33006c34b88Smrg  # FIXME: That version still under development at the moment of writing.
33106c34b88Smrg  #        Make that this statement remains true also for stable, released
33206c34b88Smrg  #        versions.
33306c34b88Smrg  # It will wrap lines (doesn't matter whether long or short) with a
33406c34b88Smrg  # trailing '\', as in:
33506c34b88Smrg  #
33606c34b88Smrg  #   foo.o : \
33706c34b88Smrg  #    foo.c \
33806c34b88Smrg  #    foo.h \
33906c34b88Smrg  #
34006c34b88Smrg  # It will put a trailing '\' even on the last line, and will use leading
34106c34b88Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34206c34b88Smrg  # "Emit spaces for -MD").
34306c34b88Smrg  "$@" -MD -MF "$tmpdepfile"
34406c34b88Smrg  stat=$?
34506c34b88Smrg  if test $stat -ne 0; then
34606c34b88Smrg    rm -f "$tmpdepfile"
34706c34b88Smrg    exit $stat
348c43cc173Smrg  fi
34906c34b88Smrg  rm -f "$depfile"
35006c34b88Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35106c34b88Smrg  # We have to change lines of the first kind to '$object: \'.
35206c34b88Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35306c34b88Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35406c34b88Smrg  # dummy dependency, to avoid the deleted-header problem.
35506c34b88Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356c43cc173Smrg  rm -f "$tmpdepfile"
357c43cc173Smrg  ;;
358c43cc173Smrg
35906c34b88Smrg## The order of this option in the case statement is important, since the
36006c34b88Smrg## shell code in configure will try each of these formats in the order
36106c34b88Smrg## listed in this file.  A plain '-MD' option would be understood by many
36206c34b88Smrg## compilers, so we must ensure this comes after the gcc and icc options.
36306c34b88Smrgpgcc)
36406c34b88Smrg  # Portland's C compiler understands '-MD'.
36506c34b88Smrg  # Will always output deps to 'file.d' where file is the root name of the
36606c34b88Smrg  # source file under compilation, even if file resides in a subdirectory.
36706c34b88Smrg  # The object file name does not affect the name of the '.d' file.
36806c34b88Smrg  # pgcc 10.2 will output
369c43cc173Smrg  #    foo.o: sub/foo.c sub/foo.h
37006c34b88Smrg  # and will wrap long lines using '\' :
371c43cc173Smrg  #    foo.o: sub/foo.c ... \
372c43cc173Smrg  #     sub/foo.h ... \
373c43cc173Smrg  #     ...
37406c34b88Smrg  set_dir_from "$object"
37506c34b88Smrg  # Use the source, not the object, to determine the base name, since
37606c34b88Smrg  # that's sadly what pgcc will do too.
37706c34b88Smrg  set_base_from "$source"
37806c34b88Smrg  tmpdepfile=$base.d
37906c34b88Smrg
38006c34b88Smrg  # For projects that build the same source file twice into different object
38106c34b88Smrg  # files, the pgcc approach of using the *source* file root name can cause
38206c34b88Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38306c34b88Smrg  # the same $tmpdepfile.
38406c34b88Smrg  lockdir=$base.d-lock
38506c34b88Smrg  trap "
38606c34b88Smrg    echo '$0: caught signal, cleaning up...' >&2
38706c34b88Smrg    rmdir '$lockdir'
38806c34b88Smrg    exit 1
38906c34b88Smrg  " 1 2 13 15
39006c34b88Smrg  numtries=100
39106c34b88Smrg  i=$numtries
39206c34b88Smrg  while test $i -gt 0; do
39306c34b88Smrg    # mkdir is a portable test-and-set.
39406c34b88Smrg    if mkdir "$lockdir" 2>/dev/null; then
39506c34b88Smrg      # This process acquired the lock.
39606c34b88Smrg      "$@" -MD
39706c34b88Smrg      stat=$?
39806c34b88Smrg      # Release the lock.
39906c34b88Smrg      rmdir "$lockdir"
40006c34b88Smrg      break
40106c34b88Smrg    else
40206c34b88Smrg      # If the lock is being held by a different process, wait
40306c34b88Smrg      # until the winning process is done or we timeout.
40406c34b88Smrg      while test -d "$lockdir" && test $i -gt 0; do
40506c34b88Smrg        sleep 1
40606c34b88Smrg        i=`expr $i - 1`
40706c34b88Smrg      done
40806c34b88Smrg    fi
40906c34b88Smrg    i=`expr $i - 1`
41006c34b88Smrg  done
41106c34b88Smrg  trap - 1 2 13 15
41206c34b88Smrg  if test $i -le 0; then
41306c34b88Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41406c34b88Smrg    echo "$0: check lockdir '$lockdir'" >&2
41506c34b88Smrg    exit 1
41606c34b88Smrg  fi
41706c34b88Smrg
41806c34b88Smrg  if test $stat -ne 0; then
419c43cc173Smrg    rm -f "$tmpdepfile"
420c43cc173Smrg    exit $stat
421c43cc173Smrg  fi
422c43cc173Smrg  rm -f "$depfile"
42306c34b88Smrg  # Each line is of the form `foo.o: dependent.h',
42406c34b88Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425c43cc173Smrg  # Do two passes, one to just change these to
42606c34b88Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42706c34b88Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42806c34b88Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42906c34b88Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
43006c34b88Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43106c34b88Smrg    | sed -e 's/$/ :/' >> "$depfile"
432c43cc173Smrg  rm -f "$tmpdepfile"
433c43cc173Smrg  ;;
434c43cc173Smrg
435c43cc173Smrghp2)
436c43cc173Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437c43cc173Smrg  # compilers, which have integrated preprocessors.  The correct option
438c43cc173Smrg  # to use with these is +Maked; it writes dependencies to a file named
439c43cc173Smrg  # 'foo.d', which lands next to the object file, wherever that
440c43cc173Smrg  # happens to be.
441c43cc173Smrg  # Much of this is similar to the tru64 case; see comments there.
44206c34b88Smrg  set_dir_from  "$object"
44306c34b88Smrg  set_base_from "$object"
444c43cc173Smrg  if test "$libtool" = yes; then
445c43cc173Smrg    tmpdepfile1=$dir$base.d
446c43cc173Smrg    tmpdepfile2=$dir.libs/$base.d
447c43cc173Smrg    "$@" -Wc,+Maked
448c43cc173Smrg  else
449c43cc173Smrg    tmpdepfile1=$dir$base.d
450c43cc173Smrg    tmpdepfile2=$dir$base.d
451c43cc173Smrg    "$@" +Maked
452c43cc173Smrg  fi
453c43cc173Smrg  stat=$?
45406c34b88Smrg  if test $stat -ne 0; then
455c43cc173Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456c43cc173Smrg     exit $stat
457c43cc173Smrg  fi
458c43cc173Smrg
459c43cc173Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460c43cc173Smrg  do
461c43cc173Smrg    test -f "$tmpdepfile" && break
462c43cc173Smrg  done
463c43cc173Smrg  if test -f "$tmpdepfile"; then
46406c34b88Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465f1ee322dSmrg    # Add 'dependent.h:' lines.
466c27c18e8Smrg    sed -ne '2,${
46706c34b88Smrg               s/^ *//
46806c34b88Smrg               s/ \\*$//
46906c34b88Smrg               s/$/:/
47006c34b88Smrg               p
47106c34b88Smrg             }' "$tmpdepfile" >> "$depfile"
472c43cc173Smrg  else
47306c34b88Smrg    make_dummy_depfile
474c43cc173Smrg  fi
475c43cc173Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476c43cc173Smrg  ;;
477c43cc173Smrg
478c43cc173Smrgtru64)
47906c34b88Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48006c34b88Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48106c34b88Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48206c34b88Smrg  # dependencies in 'foo.d' instead, so we check for that too.
48306c34b88Smrg  # Subdirectories are respected.
48406c34b88Smrg  set_dir_from  "$object"
48506c34b88Smrg  set_base_from "$object"
48606c34b88Smrg
48706c34b88Smrg  if test "$libtool" = yes; then
48806c34b88Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48906c34b88Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49006c34b88Smrg    # in $dir$base.o.d.  We have to check for both files, because
49106c34b88Smrg    # one of the two compilations can be disabled.  We should prefer
49206c34b88Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49306c34b88Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
49406c34b88Smrg    # the former would cause a distcleancheck panic.
49506c34b88Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49606c34b88Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49706c34b88Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49806c34b88Smrg    "$@" -Wc,-MD
49906c34b88Smrg  else
50006c34b88Smrg    tmpdepfile1=$dir$base.d
50106c34b88Smrg    tmpdepfile2=$dir$base.d
50206c34b88Smrg    tmpdepfile3=$dir$base.d
50306c34b88Smrg    "$@" -MD
50406c34b88Smrg  fi
50506c34b88Smrg
50606c34b88Smrg  stat=$?
50706c34b88Smrg  if test $stat -ne 0; then
50806c34b88Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50906c34b88Smrg    exit $stat
51006c34b88Smrg  fi
51106c34b88Smrg
51206c34b88Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51306c34b88Smrg  do
51406c34b88Smrg    test -f "$tmpdepfile" && break
51506c34b88Smrg  done
51606c34b88Smrg  # Same post-processing that is required for AIX mode.
51706c34b88Smrg  aix_post_process_depfile
51806c34b88Smrg  ;;
519c43cc173Smrg
520f1ee322dSmrgmsvc7)
521f1ee322dSmrg  if test "$libtool" = yes; then
522f1ee322dSmrg    showIncludes=-Wc,-showIncludes
523f1ee322dSmrg  else
524f1ee322dSmrg    showIncludes=-showIncludes
525f1ee322dSmrg  fi
526f1ee322dSmrg  "$@" $showIncludes > "$tmpdepfile"
527f1ee322dSmrg  stat=$?
528f1ee322dSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
52906c34b88Smrg  if test $stat -ne 0; then
530f1ee322dSmrg    rm -f "$tmpdepfile"
531f1ee322dSmrg    exit $stat
532f1ee322dSmrg  fi
533f1ee322dSmrg  rm -f "$depfile"
534f1ee322dSmrg  echo "$object : \\" > "$depfile"
535f1ee322dSmrg  # The first sed program below extracts the file names and escapes
536f1ee322dSmrg  # backslashes for cygpath.  The second sed program outputs the file
537f1ee322dSmrg  # name when reading, but also accumulates all include files in the
538f1ee322dSmrg  # hold buffer in order to output them again at the end.  This only
539f1ee322dSmrg  # works with sed implementations that can handle large buffers.
540f1ee322dSmrg  sed < "$tmpdepfile" -n '
541f1ee322dSmrg/^Note: including file:  *\(.*\)/ {
542f1ee322dSmrg  s//\1/
543f1ee322dSmrg  s/\\/\\\\/g
544f1ee322dSmrg  p
545f1ee322dSmrg}' | $cygpath_u | sort -u | sed -n '
546f1ee322dSmrgs/ /\\ /g
547f1ee322dSmrgs/\(.*\)/'"$tab"'\1 \\/p
548f1ee322dSmrgs/.\(.*\) \\/\1:/
549f1ee322dSmrgH
550f1ee322dSmrg$ {
551f1ee322dSmrg  s/.*/'"$tab"'/
552f1ee322dSmrg  G
553f1ee322dSmrg  p
554f1ee322dSmrg}' >> "$depfile"
55544584a44Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556f1ee322dSmrg  rm -f "$tmpdepfile"
557f1ee322dSmrg  ;;
558f1ee322dSmrg
559f1ee322dSmrgmsvc7msys)
560f1ee322dSmrg  # This case exists only to let depend.m4 do its work.  It works by
561f1ee322dSmrg  # looking at the text of this script.  This case will never be run,
562f1ee322dSmrg  # since it is checked for above.
563f1ee322dSmrg  exit 1
564f1ee322dSmrg  ;;
565f1ee322dSmrg
566c43cc173Smrg#nosideeffect)
567c43cc173Smrg  # This comment above is used by automake to tell side-effect
568c43cc173Smrg  # dependency tracking mechanisms from slower ones.
569c43cc173Smrg
570c43cc173Smrgdashmstdout)
571c43cc173Smrg  # Important note: in order to support this mode, a compiler *must*
572c43cc173Smrg  # always write the preprocessed file to stdout, regardless of -o.
573c43cc173Smrg  "$@" || exit $?
574c43cc173Smrg
575c43cc173Smrg  # Remove the call to Libtool.
576c43cc173Smrg  if test "$libtool" = yes; then
577c27c18e8Smrg    while test "X$1" != 'X--mode=compile'; do
578c43cc173Smrg      shift
579c43cc173Smrg    done
580c43cc173Smrg    shift
581c43cc173Smrg  fi
582c43cc173Smrg
583f1ee322dSmrg  # Remove '-o $object'.
584c43cc173Smrg  IFS=" "
585c43cc173Smrg  for arg
586c43cc173Smrg  do
587c43cc173Smrg    case $arg in
588c43cc173Smrg    -o)
589c43cc173Smrg      shift
590c43cc173Smrg      ;;
591c43cc173Smrg    $object)
592c43cc173Smrg      shift
593c43cc173Smrg      ;;
594c43cc173Smrg    *)
595c43cc173Smrg      set fnord "$@" "$arg"
596c43cc173Smrg      shift # fnord
597c43cc173Smrg      shift # $arg
598c43cc173Smrg      ;;
599c43cc173Smrg    esac
600c43cc173Smrg  done
601c43cc173Smrg
602c43cc173Smrg  test -z "$dashmflag" && dashmflag=-M
603f1ee322dSmrg  # Require at least two characters before searching for ':'
604c43cc173Smrg  # in the target name.  This is to cope with DOS-style filenames:
605f1ee322dSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606c43cc173Smrg  "$@" $dashmflag |
60706c34b88Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608c43cc173Smrg  rm -f "$depfile"
609c43cc173Smrg  cat < "$tmpdepfile" > "$depfile"
61006c34b88Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61106c34b88Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
61206c34b88Smrg  tr ' ' "$nl" < "$tmpdepfile" \
61306c34b88Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61406c34b88Smrg    | sed -e 's/$/ :/' >> "$depfile"
615c43cc173Smrg  rm -f "$tmpdepfile"
616c43cc173Smrg  ;;
617c43cc173Smrg
618c43cc173SmrgdashXmstdout)
619c43cc173Smrg  # This case only exists to satisfy depend.m4.  It is never actually
620c43cc173Smrg  # run, as this mode is specially recognized in the preamble.
621c43cc173Smrg  exit 1
622c43cc173Smrg  ;;
623c43cc173Smrg
624c43cc173Smrgmakedepend)
625c43cc173Smrg  "$@" || exit $?
626c43cc173Smrg  # Remove any Libtool call
627c43cc173Smrg  if test "$libtool" = yes; then
628c27c18e8Smrg    while test "X$1" != 'X--mode=compile'; do
629c43cc173Smrg      shift
630c43cc173Smrg    done
631c43cc173Smrg    shift
632c43cc173Smrg  fi
633c43cc173Smrg  # X makedepend
634c43cc173Smrg  shift
635c27c18e8Smrg  cleared=no eat=no
636c27c18e8Smrg  for arg
637c27c18e8Smrg  do
638c43cc173Smrg    case $cleared in
639c43cc173Smrg    no)
640c43cc173Smrg      set ""; shift
641c43cc173Smrg      cleared=yes ;;
642c43cc173Smrg    esac
643c27c18e8Smrg    if test $eat = yes; then
644c27c18e8Smrg      eat=no
645c27c18e8Smrg      continue
646c27c18e8Smrg    fi
647c43cc173Smrg    case "$arg" in
648c43cc173Smrg    -D*|-I*)
649c43cc173Smrg      set fnord "$@" "$arg"; shift ;;
650c43cc173Smrg    # Strip any option that makedepend may not understand.  Remove
651c43cc173Smrg    # the object too, otherwise makedepend will parse it as a source file.
652c27c18e8Smrg    -arch)
653c27c18e8Smrg      eat=yes ;;
654c43cc173Smrg    -*|$object)
655c43cc173Smrg      ;;
656c43cc173Smrg    *)
657c43cc173Smrg      set fnord "$@" "$arg"; shift ;;
658c43cc173Smrg    esac
659c43cc173Smrg  done
660c27c18e8Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661c43cc173Smrg  touch "$tmpdepfile"
662c43cc173Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663c43cc173Smrg  rm -f "$depfile"
664f1ee322dSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665f1ee322dSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666f1ee322dSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66706c34b88Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66806c34b88Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
66906c34b88Smrg  sed '1,2d' "$tmpdepfile" \
67006c34b88Smrg    | tr ' ' "$nl" \
67106c34b88Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67206c34b88Smrg    | sed -e 's/$/ :/' >> "$depfile"
673c43cc173Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674c43cc173Smrg  ;;
675c43cc173Smrg
676c43cc173Smrgcpp)
677c43cc173Smrg  # Important note: in order to support this mode, a compiler *must*
678c43cc173Smrg  # always write the preprocessed file to stdout.
679c43cc173Smrg  "$@" || exit $?
680c43cc173Smrg
681c43cc173Smrg  # Remove the call to Libtool.
682c43cc173Smrg  if test "$libtool" = yes; then
683c27c18e8Smrg    while test "X$1" != 'X--mode=compile'; do
684c43cc173Smrg      shift
685c43cc173Smrg    done
686c43cc173Smrg    shift
687c43cc173Smrg  fi
688c43cc173Smrg
689f1ee322dSmrg  # Remove '-o $object'.
690c43cc173Smrg  IFS=" "
691c43cc173Smrg  for arg
692c43cc173Smrg  do
693c43cc173Smrg    case $arg in
694c43cc173Smrg    -o)
695c43cc173Smrg      shift
696c43cc173Smrg      ;;
697c43cc173Smrg    $object)
698c43cc173Smrg      shift
699c43cc173Smrg      ;;
700c43cc173Smrg    *)
701c43cc173Smrg      set fnord "$@" "$arg"
702c43cc173Smrg      shift # fnord
703c43cc173Smrg      shift # $arg
704c43cc173Smrg      ;;
705c43cc173Smrg    esac
706c43cc173Smrg  done
707c43cc173Smrg
70806c34b88Smrg  "$@" -E \
70906c34b88Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71006c34b88Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71106c34b88Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712c43cc173Smrg  rm -f "$depfile"
713c43cc173Smrg  echo "$object : \\" > "$depfile"
714c43cc173Smrg  cat < "$tmpdepfile" >> "$depfile"
715c43cc173Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716c43cc173Smrg  rm -f "$tmpdepfile"
717c43cc173Smrg  ;;
718c43cc173Smrg
719c43cc173Smrgmsvisualcpp)
720c43cc173Smrg  # Important note: in order to support this mode, a compiler *must*
721c27c18e8Smrg  # always write the preprocessed file to stdout.
722c43cc173Smrg  "$@" || exit $?
723c27c18e8Smrg
724c27c18e8Smrg  # Remove the call to Libtool.
725c27c18e8Smrg  if test "$libtool" = yes; then
726c27c18e8Smrg    while test "X$1" != 'X--mode=compile'; do
727c27c18e8Smrg      shift
728c27c18e8Smrg    done
729c27c18e8Smrg    shift
730c27c18e8Smrg  fi
731c27c18e8Smrg
732c43cc173Smrg  IFS=" "
733c43cc173Smrg  for arg
734c43cc173Smrg  do
735c43cc173Smrg    case "$arg" in
736c27c18e8Smrg    -o)
737c27c18e8Smrg      shift
738c27c18e8Smrg      ;;
739c27c18e8Smrg    $object)
740c27c18e8Smrg      shift
741c27c18e8Smrg      ;;
742c43cc173Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74306c34b88Smrg        set fnord "$@"
74406c34b88Smrg        shift
74506c34b88Smrg        shift
74606c34b88Smrg        ;;
747c43cc173Smrg    *)
74806c34b88Smrg        set fnord "$@" "$arg"
74906c34b88Smrg        shift
75006c34b88Smrg        shift
75106c34b88Smrg        ;;
752c43cc173Smrg    esac
753c43cc173Smrg  done
754c27c18e8Smrg  "$@" -E 2>/dev/null |
755c27c18e8Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756c43cc173Smrg  rm -f "$depfile"
757c43cc173Smrg  echo "$object : \\" > "$depfile"
758f1ee322dSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759f1ee322dSmrg  echo "$tab" >> "$depfile"
760c27c18e8Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761c43cc173Smrg  rm -f "$tmpdepfile"
762c43cc173Smrg  ;;
763c43cc173Smrg
764c27c18e8Smrgmsvcmsys)
765c27c18e8Smrg  # This case exists only to let depend.m4 do its work.  It works by
766c27c18e8Smrg  # looking at the text of this script.  This case will never be run,
767c27c18e8Smrg  # since it is checked for above.
768c27c18e8Smrg  exit 1
769c27c18e8Smrg  ;;
770c27c18e8Smrg
771c43cc173Smrgnone)
772c43cc173Smrg  exec "$@"
773c43cc173Smrg  ;;
774c43cc173Smrg
775c43cc173Smrg*)
776c43cc173Smrg  echo "Unknown depmode $depmode" 1>&2
777c43cc173Smrg  exit 1
778c43cc173Smrg  ;;
779c43cc173Smrgesac
780c43cc173Smrg
781c43cc173Smrgexit 0
782c43cc173Smrg
783c43cc173Smrg# Local Variables:
784c43cc173Smrg# mode: shell-script
785c43cc173Smrg# sh-indentation: 2
7864940c694Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
787c43cc173Smrg# time-stamp-start: "scriptversion="
788c43cc173Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7894940c694Smrg# time-stamp-time-zone: "UTC0"
790c27c18e8Smrg# time-stamp-end: "; # UTC"
791c43cc173Smrg# End:
792