195b296d0Smrg#! /bin/sh
295b296d0Smrg# depcomp - compile a program generating dependencies as side-effects
395b296d0Smrg
4d87a3195Smrgscriptversion=2018-03-07.03; # UTC
595b296d0Smrg
6d87a3195Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
795b296d0Smrg
895b296d0Smrg# This program is free software; you can redistribute it and/or modify
995b296d0Smrg# it under the terms of the GNU General Public License as published by
1095b296d0Smrg# the Free Software Foundation; either version 2, or (at your option)
1195b296d0Smrg# any later version.
1295b296d0Smrg
1395b296d0Smrg# This program is distributed in the hope that it will be useful,
1495b296d0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1595b296d0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1695b296d0Smrg# GNU General Public License for more details.
1795b296d0Smrg
1895b296d0Smrg# You should have received a copy of the GNU General Public License
19d87a3195Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2095b296d0Smrg
2195b296d0Smrg# As a special exception to the GNU General Public License, if you
2295b296d0Smrg# distribute this file as part of a program that contains a
2395b296d0Smrg# configuration script generated by Autoconf, you may include it under
2495b296d0Smrg# the same distribution terms that you use for the rest of that program.
2595b296d0Smrg
2695b296d0Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2795b296d0Smrg
2895b296d0Smrgcase $1 in
2995b296d0Smrg  '')
30eca46af7Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31eca46af7Smrg    exit 1;
32eca46af7Smrg    ;;
3395b296d0Smrg  -h | --h*)
3495b296d0Smrg    cat <<\EOF
3595b296d0SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3695b296d0Smrg
3795b296d0SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3895b296d0Smrgas side-effects.
3995b296d0Smrg
4095b296d0SmrgEnvironment variables:
4195b296d0Smrg  depmode     Dependency tracking mode.
42eca46af7Smrg  source      Source file read by 'PROGRAMS ARGS'.
43eca46af7Smrg  object      Object file output by 'PROGRAMS ARGS'.
4495b296d0Smrg  DEPDIR      directory where to store dependencies.
4595b296d0Smrg  depfile     Dependency file to output.
46eca46af7Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4795b296d0Smrg  libtool     Whether libtool is used (yes/no).
4895b296d0Smrg
4995b296d0SmrgReport bugs to <bug-automake@gnu.org>.
5095b296d0SmrgEOF
5195b296d0Smrg    exit $?
5295b296d0Smrg    ;;
5395b296d0Smrg  -v | --v*)
5495b296d0Smrg    echo "depcomp $scriptversion"
5595b296d0Smrg    exit $?
5695b296d0Smrg    ;;
5795b296d0Smrgesac
5895b296d0Smrg
59eca46af7Smrg# Get the directory component of the given path, and save it in the
60eca46af7Smrg# global variables '$dir'.  Note that this directory component will
61eca46af7Smrg# be either empty or ending with a '/' character.  This is deliberate.
62eca46af7Smrgset_dir_from ()
63eca46af7Smrg{
64eca46af7Smrg  case $1 in
65eca46af7Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66eca46af7Smrg      *) dir=;;
67eca46af7Smrg  esac
68eca46af7Smrg}
69eca46af7Smrg
70eca46af7Smrg# Get the suffix-stripped basename of the given path, and save it the
71eca46af7Smrg# global variable '$base'.
72eca46af7Smrgset_base_from ()
73eca46af7Smrg{
74eca46af7Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75eca46af7Smrg}
76eca46af7Smrg
77eca46af7Smrg# If no dependency file was actually created by the compiler invocation,
78eca46af7Smrg# we still have to create a dummy depfile, to avoid errors with the
79eca46af7Smrg# Makefile "include basename.Plo" scheme.
80eca46af7Smrgmake_dummy_depfile ()
81eca46af7Smrg{
82eca46af7Smrg  echo "#dummy" > "$depfile"
83eca46af7Smrg}
84eca46af7Smrg
85eca46af7Smrg# Factor out some common post-processing of the generated depfile.
86eca46af7Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87eca46af7Smrgaix_post_process_depfile ()
88eca46af7Smrg{
89eca46af7Smrg  # If the compiler actually managed to produce a dependency file,
90eca46af7Smrg  # post-process it.
91eca46af7Smrg  if test -f "$tmpdepfile"; then
92eca46af7Smrg    # Each line is of the form 'foo.o: dependency.h'.
93eca46af7Smrg    # Do two passes, one to just change these to
94eca46af7Smrg    #   $object: dependency.h
95eca46af7Smrg    # and one to simply output
96eca46af7Smrg    #   dependency.h:
97eca46af7Smrg    # which is needed to avoid the deleted-header problem.
98eca46af7Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99eca46af7Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100eca46af7Smrg    } > "$depfile"
101eca46af7Smrg    rm -f "$tmpdepfile"
102eca46af7Smrg  else
103eca46af7Smrg    make_dummy_depfile
104eca46af7Smrg  fi
105eca46af7Smrg}
106eca46af7Smrg
107eca46af7Smrg# A tabulation character.
108eca46af7Smrgtab='	'
109eca46af7Smrg# A newline character.
110eca46af7Smrgnl='
111eca46af7Smrg'
112eca46af7Smrg# Character ranges might be problematic outside the C locale.
113eca46af7Smrg# These definitions help.
114eca46af7Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115eca46af7Smrglower=abcdefghijklmnopqrstuvwxyz
116eca46af7Smrgdigits=0123456789
117eca46af7Smrgalpha=${upper}${lower}
118eca46af7Smrg
11995b296d0Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12095b296d0Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12195b296d0Smrg  exit 1
12295b296d0Smrgfi
12395b296d0Smrg
12495b296d0Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12595b296d0Smrgdepfile=${depfile-`echo "$object" |
12695b296d0Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12795b296d0Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12895b296d0Smrg
12995b296d0Smrgrm -f "$tmpdepfile"
13095b296d0Smrg
131eca46af7Smrg# Avoid interferences from the environment.
132eca46af7Smrggccflag= dashmflag=
133eca46af7Smrg
13495b296d0Smrg# Some modes work just like other modes, but use different flags.  We
13595b296d0Smrg# parameterize here, but still list the modes in the big case below,
13695b296d0Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13795b296d0Smrg# here, because this file can only contain one case statement.
13895b296d0Smrgif test "$depmode" = hp; then
13995b296d0Smrg  # HP compiler uses -M and no extra arg.
14095b296d0Smrg  gccflag=-M
14195b296d0Smrg  depmode=gcc
14295b296d0Smrgfi
14395b296d0Smrg
14495b296d0Smrgif test "$depmode" = dashXmstdout; then
145eca46af7Smrg  # This is just like dashmstdout with a different argument.
146eca46af7Smrg  dashmflag=-xM
147eca46af7Smrg  depmode=dashmstdout
14895b296d0Smrgfi
14995b296d0Smrg
15014330f12Smrgcygpath_u="cygpath -u -f -"
15114330f12Smrgif test "$depmode" = msvcmsys; then
152eca46af7Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153eca46af7Smrg  # Just convert the backslash-escaped backslashes to single forward
154eca46af7Smrg  # slashes to satisfy depend.m4
155eca46af7Smrg  cygpath_u='sed s,\\\\,/,g'
156eca46af7Smrg  depmode=msvisualcpp
157eca46af7Smrgfi
158eca46af7Smrg
159eca46af7Smrgif test "$depmode" = msvc7msys; then
160eca46af7Smrg  # This is just like msvc7 but w/o cygpath translation.
161eca46af7Smrg  # Just convert the backslash-escaped backslashes to single forward
162eca46af7Smrg  # slashes to satisfy depend.m4
163eca46af7Smrg  cygpath_u='sed s,\\\\,/,g'
164eca46af7Smrg  depmode=msvc7
165eca46af7Smrgfi
166eca46af7Smrg
167eca46af7Smrgif test "$depmode" = xlc; then
168eca46af7Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169eca46af7Smrg  gccflag=-qmakedep=gcc,-MF
170eca46af7Smrg  depmode=gcc
17114330f12Smrgfi
17214330f12Smrg
17395b296d0Smrgcase "$depmode" in
17495b296d0Smrggcc3)
17595b296d0Smrg## gcc 3 implements dependency tracking that does exactly what
17695b296d0Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17795b296d0Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178ff89ac2bSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179ff89ac2bSmrg## the command line argument order; so add the flags where they
180ff89ac2bSmrg## appear in depend2.am.  Note that the slowdown incurred here
181ff89ac2bSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182ff89ac2bSmrg  for arg
183ff89ac2bSmrg  do
184ff89ac2bSmrg    case $arg in
185ff89ac2bSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186ff89ac2bSmrg    *)  set fnord "$@" "$arg" ;;
187ff89ac2bSmrg    esac
188ff89ac2bSmrg    shift # fnord
189ff89ac2bSmrg    shift # $arg
190ff89ac2bSmrg  done
191ff89ac2bSmrg  "$@"
19295b296d0Smrg  stat=$?
193eca46af7Smrg  if test $stat -ne 0; then
19495b296d0Smrg    rm -f "$tmpdepfile"
19595b296d0Smrg    exit $stat
19695b296d0Smrg  fi
19795b296d0Smrg  mv "$tmpdepfile" "$depfile"
19895b296d0Smrg  ;;
19995b296d0Smrg
20095b296d0Smrggcc)
201eca46af7Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202eca46af7Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203eca46af7Smrg## (see the conditional assignment to $gccflag above).
20495b296d0Smrg## There are various ways to get dependency output from gcc.  Here's
20595b296d0Smrg## why we pick this rather obscure method:
20695b296d0Smrg## - Don't want to use -MD because we'd like the dependencies to end
20795b296d0Smrg##   up in a subdir.  Having to rename by hand is ugly.
20895b296d0Smrg##   (We might end up doing this anyway to support other compilers.)
20995b296d0Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210eca46af7Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211eca46af7Smrg##   supported by the other compilers which use the 'gcc' depmode.
21295b296d0Smrg## - Using -M directly means running the compiler twice (even worse
21395b296d0Smrg##   than renaming).
21495b296d0Smrg  if test -z "$gccflag"; then
21595b296d0Smrg    gccflag=-MD,
21695b296d0Smrg  fi
21795b296d0Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21895b296d0Smrg  stat=$?
219eca46af7Smrg  if test $stat -ne 0; then
22095b296d0Smrg    rm -f "$tmpdepfile"
22195b296d0Smrg    exit $stat
22295b296d0Smrg  fi
22395b296d0Smrg  rm -f "$depfile"
22495b296d0Smrg  echo "$object : \\" > "$depfile"
225eca46af7Smrg  # The second -e expression handles DOS-style file names with drive
226eca46af7Smrg  # letters.
22795b296d0Smrg  sed -e 's/^[^:]*: / /' \
22895b296d0Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229eca46af7Smrg## This next piece of magic avoids the "deleted header file" problem.
23095b296d0Smrg## The problem is that when a header file which appears in a .P file
23195b296d0Smrg## is deleted, the dependency causes make to die (because there is
23295b296d0Smrg## typically no way to rebuild the header).  We avoid this by adding
23395b296d0Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23495b296d0Smrg## this for us directly.
235eca46af7Smrg## Some versions of gcc put a space before the ':'.  On the theory
23695b296d0Smrg## that the space means something, we add a space to the output as
237eca46af7Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238eca46af7Smrg## to the object.  Take care to not repeat it in the output.
23995b296d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24095b296d0Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241eca46af7Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242eca46af7Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243eca46af7Smrg    | sed -e 's/$/ :/' >> "$depfile"
24495b296d0Smrg  rm -f "$tmpdepfile"
24595b296d0Smrg  ;;
24695b296d0Smrg
24795b296d0Smrghp)
24895b296d0Smrg  # This case exists only to let depend.m4 do its work.  It works by
24995b296d0Smrg  # looking at the text of this script.  This case will never be run,
25095b296d0Smrg  # since it is checked for above.
25195b296d0Smrg  exit 1
25295b296d0Smrg  ;;
25395b296d0Smrg
25495b296d0Smrgsgi)
25595b296d0Smrg  if test "$libtool" = yes; then
25695b296d0Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25795b296d0Smrg  else
25895b296d0Smrg    "$@" -MDupdate "$tmpdepfile"
25995b296d0Smrg  fi
26095b296d0Smrg  stat=$?
261eca46af7Smrg  if test $stat -ne 0; then
26295b296d0Smrg    rm -f "$tmpdepfile"
26395b296d0Smrg    exit $stat
26495b296d0Smrg  fi
26595b296d0Smrg  rm -f "$depfile"
26695b296d0Smrg
26795b296d0Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26895b296d0Smrg    echo "$object : \\" > "$depfile"
26995b296d0Smrg    # Clip off the initial element (the dependent).  Don't try to be
27095b296d0Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27195b296d0Smrg    # lines with more than a fixed number of characters (4096 in
27295b296d0Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273eca46af7Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27495b296d0Smrg    # dependency line.
275eca46af7Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276eca46af7Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277eca46af7Smrg      | tr "$nl" ' ' >> "$depfile"
27814330f12Smrg    echo >> "$depfile"
27995b296d0Smrg    # The second pass generates a dummy entry for each header file.
280eca46af7Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281eca46af7Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282eca46af7Smrg      >> "$depfile"
28395b296d0Smrg  else
284eca46af7Smrg    make_dummy_depfile
28595b296d0Smrg  fi
28695b296d0Smrg  rm -f "$tmpdepfile"
28795b296d0Smrg  ;;
28895b296d0Smrg
289eca46af7Smrgxlc)
290eca46af7Smrg  # This case exists only to let depend.m4 do its work.  It works by
291eca46af7Smrg  # looking at the text of this script.  This case will never be run,
292eca46af7Smrg  # since it is checked for above.
293eca46af7Smrg  exit 1
294eca46af7Smrg  ;;
295eca46af7Smrg
29695b296d0Smrgaix)
29795b296d0Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29895b296d0Smrg  # in a .u file.  In older versions, this file always lives in the
299eca46af7Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30095b296d0Smrg  # start of each line; $object doesn't have directory information.
30195b296d0Smrg  # Version 6 uses the directory in both cases.
302eca46af7Smrg  set_dir_from "$object"
303eca46af7Smrg  set_base_from "$object"
30495b296d0Smrg  if test "$libtool" = yes; then
305ff89ac2bSmrg    tmpdepfile1=$dir$base.u
306ff89ac2bSmrg    tmpdepfile2=$base.u
307ff89ac2bSmrg    tmpdepfile3=$dir.libs/$base.u
30895b296d0Smrg    "$@" -Wc,-M
30995b296d0Smrg  else
310ff89ac2bSmrg    tmpdepfile1=$dir$base.u
311ff89ac2bSmrg    tmpdepfile2=$dir$base.u
312ff89ac2bSmrg    tmpdepfile3=$dir$base.u
31395b296d0Smrg    "$@" -M
31495b296d0Smrg  fi
31595b296d0Smrg  stat=$?
316eca46af7Smrg  if test $stat -ne 0; then
317ff89ac2bSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31895b296d0Smrg    exit $stat
31995b296d0Smrg  fi
32095b296d0Smrg
321ff89ac2bSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322ff89ac2bSmrg  do
323ff89ac2bSmrg    test -f "$tmpdepfile" && break
324ff89ac2bSmrg  done
325eca46af7Smrg  aix_post_process_depfile
326eca46af7Smrg  ;;
327eca46af7Smrg
328eca46af7Smrgtcc)
329eca46af7Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330eca46af7Smrg  # FIXME: That version still under development at the moment of writing.
331eca46af7Smrg  #        Make that this statement remains true also for stable, released
332eca46af7Smrg  #        versions.
333eca46af7Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334eca46af7Smrg  # trailing '\', as in:
335eca46af7Smrg  #
336eca46af7Smrg  #   foo.o : \
337eca46af7Smrg  #    foo.c \
338eca46af7Smrg  #    foo.h \
339eca46af7Smrg  #
340eca46af7Smrg  # It will put a trailing '\' even on the last line, and will use leading
341eca46af7Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342eca46af7Smrg  # "Emit spaces for -MD").
343eca46af7Smrg  "$@" -MD -MF "$tmpdepfile"
344eca46af7Smrg  stat=$?
345eca46af7Smrg  if test $stat -ne 0; then
346eca46af7Smrg    rm -f "$tmpdepfile"
347eca46af7Smrg    exit $stat
34895b296d0Smrg  fi
349eca46af7Smrg  rm -f "$depfile"
350eca46af7Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351eca46af7Smrg  # We have to change lines of the first kind to '$object: \'.
352eca46af7Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353eca46af7Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354eca46af7Smrg  # dummy dependency, to avoid the deleted-header problem.
355eca46af7Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35695b296d0Smrg  rm -f "$tmpdepfile"
35795b296d0Smrg  ;;
35895b296d0Smrg
359eca46af7Smrg## The order of this option in the case statement is important, since the
360eca46af7Smrg## shell code in configure will try each of these formats in the order
361eca46af7Smrg## listed in this file.  A plain '-MD' option would be understood by many
362eca46af7Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363eca46af7Smrgpgcc)
364eca46af7Smrg  # Portland's C compiler understands '-MD'.
365eca46af7Smrg  # Will always output deps to 'file.d' where file is the root name of the
366eca46af7Smrg  # source file under compilation, even if file resides in a subdirectory.
367eca46af7Smrg  # The object file name does not affect the name of the '.d' file.
368eca46af7Smrg  # pgcc 10.2 will output
36995b296d0Smrg  #    foo.o: sub/foo.c sub/foo.h
370eca46af7Smrg  # and will wrap long lines using '\' :
37195b296d0Smrg  #    foo.o: sub/foo.c ... \
37295b296d0Smrg  #     sub/foo.h ... \
37395b296d0Smrg  #     ...
374eca46af7Smrg  set_dir_from "$object"
375eca46af7Smrg  # Use the source, not the object, to determine the base name, since
376eca46af7Smrg  # that's sadly what pgcc will do too.
377eca46af7Smrg  set_base_from "$source"
378eca46af7Smrg  tmpdepfile=$base.d
379eca46af7Smrg
380eca46af7Smrg  # For projects that build the same source file twice into different object
381eca46af7Smrg  # files, the pgcc approach of using the *source* file root name can cause
382eca46af7Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383eca46af7Smrg  # the same $tmpdepfile.
384eca46af7Smrg  lockdir=$base.d-lock
385eca46af7Smrg  trap "
386eca46af7Smrg    echo '$0: caught signal, cleaning up...' >&2
387eca46af7Smrg    rmdir '$lockdir'
388eca46af7Smrg    exit 1
389eca46af7Smrg  " 1 2 13 15
390eca46af7Smrg  numtries=100
391eca46af7Smrg  i=$numtries
392eca46af7Smrg  while test $i -gt 0; do
393eca46af7Smrg    # mkdir is a portable test-and-set.
394eca46af7Smrg    if mkdir "$lockdir" 2>/dev/null; then
395eca46af7Smrg      # This process acquired the lock.
396eca46af7Smrg      "$@" -MD
397eca46af7Smrg      stat=$?
398eca46af7Smrg      # Release the lock.
399eca46af7Smrg      rmdir "$lockdir"
400eca46af7Smrg      break
401eca46af7Smrg    else
402eca46af7Smrg      # If the lock is being held by a different process, wait
403eca46af7Smrg      # until the winning process is done or we timeout.
404eca46af7Smrg      while test -d "$lockdir" && test $i -gt 0; do
405eca46af7Smrg        sleep 1
406eca46af7Smrg        i=`expr $i - 1`
407eca46af7Smrg      done
408eca46af7Smrg    fi
409eca46af7Smrg    i=`expr $i - 1`
410eca46af7Smrg  done
411eca46af7Smrg  trap - 1 2 13 15
412eca46af7Smrg  if test $i -le 0; then
413eca46af7Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414eca46af7Smrg    echo "$0: check lockdir '$lockdir'" >&2
415eca46af7Smrg    exit 1
416eca46af7Smrg  fi
41795b296d0Smrg
418eca46af7Smrg  if test $stat -ne 0; then
41995b296d0Smrg    rm -f "$tmpdepfile"
42095b296d0Smrg    exit $stat
42195b296d0Smrg  fi
42295b296d0Smrg  rm -f "$depfile"
42395b296d0Smrg  # Each line is of the form `foo.o: dependent.h',
42495b296d0Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42595b296d0Smrg  # Do two passes, one to just change these to
42695b296d0Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42795b296d0Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42895b296d0Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42995b296d0Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430eca46af7Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431eca46af7Smrg    | sed -e 's/$/ :/' >> "$depfile"
43295b296d0Smrg  rm -f "$tmpdepfile"
43395b296d0Smrg  ;;
43495b296d0Smrg
435ff89ac2bSmrghp2)
436ff89ac2bSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437ff89ac2bSmrg  # compilers, which have integrated preprocessors.  The correct option
438ff89ac2bSmrg  # to use with these is +Maked; it writes dependencies to a file named
439ff89ac2bSmrg  # 'foo.d', which lands next to the object file, wherever that
440ff89ac2bSmrg  # happens to be.
441ff89ac2bSmrg  # Much of this is similar to the tru64 case; see comments there.
442eca46af7Smrg  set_dir_from  "$object"
443eca46af7Smrg  set_base_from "$object"
444ff89ac2bSmrg  if test "$libtool" = yes; then
445ff89ac2bSmrg    tmpdepfile1=$dir$base.d
446ff89ac2bSmrg    tmpdepfile2=$dir.libs/$base.d
447ff89ac2bSmrg    "$@" -Wc,+Maked
448ff89ac2bSmrg  else
449ff89ac2bSmrg    tmpdepfile1=$dir$base.d
450ff89ac2bSmrg    tmpdepfile2=$dir$base.d
451ff89ac2bSmrg    "$@" +Maked
452ff89ac2bSmrg  fi
453ff89ac2bSmrg  stat=$?
454eca46af7Smrg  if test $stat -ne 0; then
455ff89ac2bSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456ff89ac2bSmrg     exit $stat
457ff89ac2bSmrg  fi
458ff89ac2bSmrg
459ff89ac2bSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460ff89ac2bSmrg  do
461ff89ac2bSmrg    test -f "$tmpdepfile" && break
462ff89ac2bSmrg  done
463ff89ac2bSmrg  if test -f "$tmpdepfile"; then
464eca46af7Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465eca46af7Smrg    # Add 'dependent.h:' lines.
46614330f12Smrg    sed -ne '2,${
467eca46af7Smrg               s/^ *//
468eca46af7Smrg               s/ \\*$//
469eca46af7Smrg               s/$/:/
470eca46af7Smrg               p
471eca46af7Smrg             }' "$tmpdepfile" >> "$depfile"
472ff89ac2bSmrg  else
473eca46af7Smrg    make_dummy_depfile
474ff89ac2bSmrg  fi
475ff89ac2bSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476ff89ac2bSmrg  ;;
477ff89ac2bSmrg
47895b296d0Smrgtru64)
479eca46af7Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480eca46af7Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481eca46af7Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482eca46af7Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483eca46af7Smrg  # Subdirectories are respected.
484eca46af7Smrg  set_dir_from  "$object"
485eca46af7Smrg  set_base_from "$object"
486eca46af7Smrg
487eca46af7Smrg  if test "$libtool" = yes; then
488eca46af7Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489eca46af7Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490eca46af7Smrg    # in $dir$base.o.d.  We have to check for both files, because
491eca46af7Smrg    # one of the two compilations can be disabled.  We should prefer
492eca46af7Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493eca46af7Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494eca46af7Smrg    # the former would cause a distcleancheck panic.
495eca46af7Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496eca46af7Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497eca46af7Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498eca46af7Smrg    "$@" -Wc,-MD
499eca46af7Smrg  else
500eca46af7Smrg    tmpdepfile1=$dir$base.d
501eca46af7Smrg    tmpdepfile2=$dir$base.d
502eca46af7Smrg    tmpdepfile3=$dir$base.d
503eca46af7Smrg    "$@" -MD
504eca46af7Smrg  fi
505eca46af7Smrg
506eca46af7Smrg  stat=$?
507eca46af7Smrg  if test $stat -ne 0; then
508eca46af7Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509eca46af7Smrg    exit $stat
510eca46af7Smrg  fi
511eca46af7Smrg
512eca46af7Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513eca46af7Smrg  do
514eca46af7Smrg    test -f "$tmpdepfile" && break
515eca46af7Smrg  done
516eca46af7Smrg  # Same post-processing that is required for AIX mode.
517eca46af7Smrg  aix_post_process_depfile
518eca46af7Smrg  ;;
519eca46af7Smrg
520eca46af7Smrgmsvc7)
521eca46af7Smrg  if test "$libtool" = yes; then
522eca46af7Smrg    showIncludes=-Wc,-showIncludes
523eca46af7Smrg  else
524eca46af7Smrg    showIncludes=-showIncludes
525eca46af7Smrg  fi
526eca46af7Smrg  "$@" $showIncludes > "$tmpdepfile"
527eca46af7Smrg  stat=$?
528eca46af7Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529eca46af7Smrg  if test $stat -ne 0; then
530eca46af7Smrg    rm -f "$tmpdepfile"
531eca46af7Smrg    exit $stat
532eca46af7Smrg  fi
533eca46af7Smrg  rm -f "$depfile"
534eca46af7Smrg  echo "$object : \\" > "$depfile"
535eca46af7Smrg  # The first sed program below extracts the file names and escapes
536eca46af7Smrg  # backslashes for cygpath.  The second sed program outputs the file
537eca46af7Smrg  # name when reading, but also accumulates all include files in the
538eca46af7Smrg  # hold buffer in order to output them again at the end.  This only
539eca46af7Smrg  # works with sed implementations that can handle large buffers.
540eca46af7Smrg  sed < "$tmpdepfile" -n '
541eca46af7Smrg/^Note: including file:  *\(.*\)/ {
542eca46af7Smrg  s//\1/
543eca46af7Smrg  s/\\/\\\\/g
544eca46af7Smrg  p
545eca46af7Smrg}' | $cygpath_u | sort -u | sed -n '
546eca46af7Smrgs/ /\\ /g
547eca46af7Smrgs/\(.*\)/'"$tab"'\1 \\/p
548eca46af7Smrgs/.\(.*\) \\/\1:/
549eca46af7SmrgH
550eca46af7Smrg$ {
551eca46af7Smrg  s/.*/'"$tab"'/
552eca46af7Smrg  G
553eca46af7Smrg  p
554eca46af7Smrg}' >> "$depfile"
555eca46af7Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556eca46af7Smrg  rm -f "$tmpdepfile"
557eca46af7Smrg  ;;
558eca46af7Smrg
559eca46af7Smrgmsvc7msys)
560eca46af7Smrg  # This case exists only to let depend.m4 do its work.  It works by
561eca46af7Smrg  # looking at the text of this script.  This case will never be run,
562eca46af7Smrg  # since it is checked for above.
563eca46af7Smrg  exit 1
564eca46af7Smrg  ;;
56595b296d0Smrg
56695b296d0Smrg#nosideeffect)
56795b296d0Smrg  # This comment above is used by automake to tell side-effect
56895b296d0Smrg  # dependency tracking mechanisms from slower ones.
56995b296d0Smrg
57095b296d0Smrgdashmstdout)
57195b296d0Smrg  # Important note: in order to support this mode, a compiler *must*
57295b296d0Smrg  # always write the preprocessed file to stdout, regardless of -o.
57395b296d0Smrg  "$@" || exit $?
57495b296d0Smrg
57595b296d0Smrg  # Remove the call to Libtool.
57695b296d0Smrg  if test "$libtool" = yes; then
57714330f12Smrg    while test "X$1" != 'X--mode=compile'; do
57895b296d0Smrg      shift
57995b296d0Smrg    done
58095b296d0Smrg    shift
58195b296d0Smrg  fi
58295b296d0Smrg
583eca46af7Smrg  # Remove '-o $object'.
58495b296d0Smrg  IFS=" "
58595b296d0Smrg  for arg
58695b296d0Smrg  do
58795b296d0Smrg    case $arg in
58895b296d0Smrg    -o)
58995b296d0Smrg      shift
59095b296d0Smrg      ;;
59195b296d0Smrg    $object)
59295b296d0Smrg      shift
59395b296d0Smrg      ;;
59495b296d0Smrg    *)
59595b296d0Smrg      set fnord "$@" "$arg"
59695b296d0Smrg      shift # fnord
59795b296d0Smrg      shift # $arg
59895b296d0Smrg      ;;
59995b296d0Smrg    esac
60095b296d0Smrg  done
60195b296d0Smrg
60295b296d0Smrg  test -z "$dashmflag" && dashmflag=-M
603eca46af7Smrg  # Require at least two characters before searching for ':'
60495b296d0Smrg  # in the target name.  This is to cope with DOS-style filenames:
605eca46af7Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60695b296d0Smrg  "$@" $dashmflag |
607eca46af7Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60895b296d0Smrg  rm -f "$depfile"
60995b296d0Smrg  cat < "$tmpdepfile" > "$depfile"
610eca46af7Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611eca46af7Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612eca46af7Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613eca46af7Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614eca46af7Smrg    | sed -e 's/$/ :/' >> "$depfile"
61595b296d0Smrg  rm -f "$tmpdepfile"
61695b296d0Smrg  ;;
61795b296d0Smrg
61895b296d0SmrgdashXmstdout)
61995b296d0Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62095b296d0Smrg  # run, as this mode is specially recognized in the preamble.
62195b296d0Smrg  exit 1
62295b296d0Smrg  ;;
62395b296d0Smrg
62495b296d0Smrgmakedepend)
62595b296d0Smrg  "$@" || exit $?
62695b296d0Smrg  # Remove any Libtool call
62795b296d0Smrg  if test "$libtool" = yes; then
62814330f12Smrg    while test "X$1" != 'X--mode=compile'; do
62995b296d0Smrg      shift
63095b296d0Smrg    done
63195b296d0Smrg    shift
63295b296d0Smrg  fi
63395b296d0Smrg  # X makedepend
63495b296d0Smrg  shift
63514330f12Smrg  cleared=no eat=no
63614330f12Smrg  for arg
63714330f12Smrg  do
63895b296d0Smrg    case $cleared in
63995b296d0Smrg    no)
64095b296d0Smrg      set ""; shift
64195b296d0Smrg      cleared=yes ;;
64295b296d0Smrg    esac
64314330f12Smrg    if test $eat = yes; then
64414330f12Smrg      eat=no
64514330f12Smrg      continue
64614330f12Smrg    fi
64795b296d0Smrg    case "$arg" in
64895b296d0Smrg    -D*|-I*)
64995b296d0Smrg      set fnord "$@" "$arg"; shift ;;
65095b296d0Smrg    # Strip any option that makedepend may not understand.  Remove
65195b296d0Smrg    # the object too, otherwise makedepend will parse it as a source file.
65214330f12Smrg    -arch)
65314330f12Smrg      eat=yes ;;
65495b296d0Smrg    -*|$object)
65595b296d0Smrg      ;;
65695b296d0Smrg    *)
65795b296d0Smrg      set fnord "$@" "$arg"; shift ;;
65895b296d0Smrg    esac
65995b296d0Smrg  done
66014330f12Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66195b296d0Smrg  touch "$tmpdepfile"
66295b296d0Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66395b296d0Smrg  rm -f "$depfile"
664eca46af7Smrg  # makedepend may prepend the VPATH from the source file name to the object.
665eca46af7Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666eca46af7Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667eca46af7Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668eca46af7Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669eca46af7Smrg  sed '1,2d' "$tmpdepfile" \
670eca46af7Smrg    | tr ' ' "$nl" \
671eca46af7Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672eca46af7Smrg    | sed -e 's/$/ :/' >> "$depfile"
67395b296d0Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67495b296d0Smrg  ;;
67595b296d0Smrg
67695b296d0Smrgcpp)
67795b296d0Smrg  # Important note: in order to support this mode, a compiler *must*
67895b296d0Smrg  # always write the preprocessed file to stdout.
67995b296d0Smrg  "$@" || exit $?
68095b296d0Smrg
68195b296d0Smrg  # Remove the call to Libtool.
68295b296d0Smrg  if test "$libtool" = yes; then
68314330f12Smrg    while test "X$1" != 'X--mode=compile'; do
68495b296d0Smrg      shift
68595b296d0Smrg    done
68695b296d0Smrg    shift
68795b296d0Smrg  fi
68895b296d0Smrg
689eca46af7Smrg  # Remove '-o $object'.
69095b296d0Smrg  IFS=" "
69195b296d0Smrg  for arg
69295b296d0Smrg  do
69395b296d0Smrg    case $arg in
69495b296d0Smrg    -o)
69595b296d0Smrg      shift
69695b296d0Smrg      ;;
69795b296d0Smrg    $object)
69895b296d0Smrg      shift
69995b296d0Smrg      ;;
70095b296d0Smrg    *)
70195b296d0Smrg      set fnord "$@" "$arg"
70295b296d0Smrg      shift # fnord
70395b296d0Smrg      shift # $arg
70495b296d0Smrg      ;;
70595b296d0Smrg    esac
70695b296d0Smrg  done
70795b296d0Smrg
708eca46af7Smrg  "$@" -E \
709eca46af7Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710eca46af7Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711eca46af7Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71295b296d0Smrg  rm -f "$depfile"
71395b296d0Smrg  echo "$object : \\" > "$depfile"
71495b296d0Smrg  cat < "$tmpdepfile" >> "$depfile"
71595b296d0Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71695b296d0Smrg  rm -f "$tmpdepfile"
71795b296d0Smrg  ;;
71895b296d0Smrg
71995b296d0Smrgmsvisualcpp)
72095b296d0Smrg  # Important note: in order to support this mode, a compiler *must*
72114330f12Smrg  # always write the preprocessed file to stdout.
72295b296d0Smrg  "$@" || exit $?
72314330f12Smrg
72414330f12Smrg  # Remove the call to Libtool.
72514330f12Smrg  if test "$libtool" = yes; then
72614330f12Smrg    while test "X$1" != 'X--mode=compile'; do
72714330f12Smrg      shift
72814330f12Smrg    done
72914330f12Smrg    shift
73014330f12Smrg  fi
73114330f12Smrg
73295b296d0Smrg  IFS=" "
73395b296d0Smrg  for arg
73495b296d0Smrg  do
73595b296d0Smrg    case "$arg" in
73614330f12Smrg    -o)
73714330f12Smrg      shift
73814330f12Smrg      ;;
73914330f12Smrg    $object)
74014330f12Smrg      shift
74114330f12Smrg      ;;
74295b296d0Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743eca46af7Smrg        set fnord "$@"
744eca46af7Smrg        shift
745eca46af7Smrg        shift
746eca46af7Smrg        ;;
74795b296d0Smrg    *)
748eca46af7Smrg        set fnord "$@" "$arg"
749eca46af7Smrg        shift
750eca46af7Smrg        shift
751eca46af7Smrg        ;;
75295b296d0Smrg    esac
75395b296d0Smrg  done
75414330f12Smrg  "$@" -E 2>/dev/null |
75514330f12Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75695b296d0Smrg  rm -f "$depfile"
75795b296d0Smrg  echo "$object : \\" > "$depfile"
758eca46af7Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759eca46af7Smrg  echo "$tab" >> "$depfile"
76014330f12Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76195b296d0Smrg  rm -f "$tmpdepfile"
76295b296d0Smrg  ;;
76395b296d0Smrg
76414330f12Smrgmsvcmsys)
76514330f12Smrg  # This case exists only to let depend.m4 do its work.  It works by
76614330f12Smrg  # looking at the text of this script.  This case will never be run,
76714330f12Smrg  # since it is checked for above.
76814330f12Smrg  exit 1
76914330f12Smrg  ;;
77014330f12Smrg
77195b296d0Smrgnone)
77295b296d0Smrg  exec "$@"
77395b296d0Smrg  ;;
77495b296d0Smrg
77595b296d0Smrg*)
77695b296d0Smrg  echo "Unknown depmode $depmode" 1>&2
77795b296d0Smrg  exit 1
77895b296d0Smrg  ;;
77995b296d0Smrgesac
78095b296d0Smrg
78195b296d0Smrgexit 0
78295b296d0Smrg
78395b296d0Smrg# Local Variables:
78495b296d0Smrg# mode: shell-script
78595b296d0Smrg# sh-indentation: 2
786d87a3195Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
78795b296d0Smrg# time-stamp-start: "scriptversion="
78895b296d0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789d87a3195Smrg# time-stamp-time-zone: "UTC0"
79014330f12Smrg# time-stamp-end: "; # UTC"
79195b296d0Smrg# End:
792