1f80a6dcdSmrg#! /bin/sh
2f80a6dcdSmrg# depcomp - compile a program generating dependencies as side-effects
365912f00Smrg
48c7c3c7eSmrgscriptversion=2018-03-07.03; # UTC
565912f00Smrg
68c7c3c7eSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
7f80a6dcdSmrg
8f80a6dcdSmrg# This program is free software; you can redistribute it and/or modify
9f80a6dcdSmrg# it under the terms of the GNU General Public License as published by
10f80a6dcdSmrg# the Free Software Foundation; either version 2, or (at your option)
11f80a6dcdSmrg# any later version.
12f80a6dcdSmrg
13f80a6dcdSmrg# This program is distributed in the hope that it will be useful,
14f80a6dcdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15f80a6dcdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16f80a6dcdSmrg# GNU General Public License for more details.
17f80a6dcdSmrg
18f80a6dcdSmrg# You should have received a copy of the GNU General Public License
198c7c3c7eSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20f80a6dcdSmrg
21f80a6dcdSmrg# As a special exception to the GNU General Public License, if you
22f80a6dcdSmrg# distribute this file as part of a program that contains a
23f80a6dcdSmrg# configuration script generated by Autoconf, you may include it under
24f80a6dcdSmrg# the same distribution terms that you use for the rest of that program.
25f80a6dcdSmrg
26f80a6dcdSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27f80a6dcdSmrg
2865912f00Smrgcase $1 in
2965912f00Smrg  '')
30c166fba9Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31c166fba9Smrg    exit 1;
32c166fba9Smrg    ;;
3365912f00Smrg  -h | --h*)
3465912f00Smrg    cat <<\EOF
3565912f00SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3665912f00Smrg
3765912f00SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3865912f00Smrgas side-effects.
3965912f00Smrg
4065912f00SmrgEnvironment variables:
4165912f00Smrg  depmode     Dependency tracking mode.
42c166fba9Smrg  source      Source file read by 'PROGRAMS ARGS'.
43c166fba9Smrg  object      Object file output by 'PROGRAMS ARGS'.
4465912f00Smrg  DEPDIR      directory where to store dependencies.
4565912f00Smrg  depfile     Dependency file to output.
4665912f00Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4765912f00Smrg  libtool     Whether libtool is used (yes/no).
4865912f00Smrg
4965912f00SmrgReport bugs to <bug-automake@gnu.org>.
5065912f00SmrgEOF
5165912f00Smrg    exit $?
5265912f00Smrg    ;;
5365912f00Smrg  -v | --v*)
5465912f00Smrg    echo "depcomp $scriptversion"
5565912f00Smrg    exit $?
5665912f00Smrg    ;;
5765912f00Smrgesac
5865912f00Smrg
59c166fba9Smrg# Get the directory component of the given path, and save it in the
60c166fba9Smrg# global variables '$dir'.  Note that this directory component will
61c166fba9Smrg# be either empty or ending with a '/' character.  This is deliberate.
62c166fba9Smrgset_dir_from ()
63c166fba9Smrg{
64c166fba9Smrg  case $1 in
65c166fba9Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66c166fba9Smrg      *) dir=;;
67c166fba9Smrg  esac
68c166fba9Smrg}
69c166fba9Smrg
70c166fba9Smrg# Get the suffix-stripped basename of the given path, and save it the
71c166fba9Smrg# global variable '$base'.
72c166fba9Smrgset_base_from ()
73c166fba9Smrg{
74c166fba9Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75c166fba9Smrg}
76c166fba9Smrg
77c166fba9Smrg# If no dependency file was actually created by the compiler invocation,
78c166fba9Smrg# we still have to create a dummy depfile, to avoid errors with the
79c166fba9Smrg# Makefile "include basename.Plo" scheme.
80c166fba9Smrgmake_dummy_depfile ()
81c166fba9Smrg{
82c166fba9Smrg  echo "#dummy" > "$depfile"
83c166fba9Smrg}
84c166fba9Smrg
85c166fba9Smrg# Factor out some common post-processing of the generated depfile.
86c166fba9Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87c166fba9Smrgaix_post_process_depfile ()
88c166fba9Smrg{
89c166fba9Smrg  # If the compiler actually managed to produce a dependency file,
90c166fba9Smrg  # post-process it.
91c166fba9Smrg  if test -f "$tmpdepfile"; then
92c166fba9Smrg    # Each line is of the form 'foo.o: dependency.h'.
93c166fba9Smrg    # Do two passes, one to just change these to
94c166fba9Smrg    #   $object: dependency.h
95c166fba9Smrg    # and one to simply output
96c166fba9Smrg    #   dependency.h:
97c166fba9Smrg    # which is needed to avoid the deleted-header problem.
98c166fba9Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99c166fba9Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100c166fba9Smrg    } > "$depfile"
101c166fba9Smrg    rm -f "$tmpdepfile"
102c166fba9Smrg  else
103c166fba9Smrg    make_dummy_depfile
104c166fba9Smrg  fi
105c166fba9Smrg}
106c166fba9Smrg
107c166fba9Smrg# A tabulation character.
108c166fba9Smrgtab='	'
109c166fba9Smrg# A newline character.
110c166fba9Smrgnl='
111c166fba9Smrg'
112c166fba9Smrg# Character ranges might be problematic outside the C locale.
113c166fba9Smrg# These definitions help.
114c166fba9Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115c166fba9Smrglower=abcdefghijklmnopqrstuvwxyz
116c166fba9Smrgdigits=0123456789
117c166fba9Smrgalpha=${upper}${lower}
118c166fba9Smrg
119f80a6dcdSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120f80a6dcdSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121f80a6dcdSmrg  exit 1
122f80a6dcdSmrgfi
123f80a6dcdSmrg
12465912f00Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12565912f00Smrgdepfile=${depfile-`echo "$object" |
12665912f00Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127f80a6dcdSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128f80a6dcdSmrg
129f80a6dcdSmrgrm -f "$tmpdepfile"
130f80a6dcdSmrg
131c166fba9Smrg# Avoid interferences from the environment.
132c166fba9Smrggccflag= dashmflag=
133c166fba9Smrg
134f80a6dcdSmrg# Some modes work just like other modes, but use different flags.  We
135f80a6dcdSmrg# parameterize here, but still list the modes in the big case below,
136f80a6dcdSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137f80a6dcdSmrg# here, because this file can only contain one case statement.
138f80a6dcdSmrgif test "$depmode" = hp; then
139f80a6dcdSmrg  # HP compiler uses -M and no extra arg.
140f80a6dcdSmrg  gccflag=-M
141f80a6dcdSmrg  depmode=gcc
142f80a6dcdSmrgfi
143f80a6dcdSmrg
144f80a6dcdSmrgif test "$depmode" = dashXmstdout; then
145c166fba9Smrg  # This is just like dashmstdout with a different argument.
146c166fba9Smrg  dashmflag=-xM
147c166fba9Smrg  depmode=dashmstdout
148f80a6dcdSmrgfi
149f80a6dcdSmrg
15065912f00Smrgcygpath_u="cygpath -u -f -"
15165912f00Smrgif test "$depmode" = msvcmsys; then
152c166fba9Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153c166fba9Smrg  # Just convert the backslash-escaped backslashes to single forward
154c166fba9Smrg  # slashes to satisfy depend.m4
155c166fba9Smrg  cygpath_u='sed s,\\\\,/,g'
156c166fba9Smrg  depmode=msvisualcpp
15765912f00Smrgfi
15865912f00Smrg
15965912f00Smrgif test "$depmode" = msvc7msys; then
160c166fba9Smrg  # This is just like msvc7 but w/o cygpath translation.
161c166fba9Smrg  # Just convert the backslash-escaped backslashes to single forward
162c166fba9Smrg  # slashes to satisfy depend.m4
163c166fba9Smrg  cygpath_u='sed s,\\\\,/,g'
164c166fba9Smrg  depmode=msvc7
165c166fba9Smrgfi
166c166fba9Smrg
167c166fba9Smrgif test "$depmode" = xlc; then
168c166fba9Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169c166fba9Smrg  gccflag=-qmakedep=gcc,-MF
170c166fba9Smrg  depmode=gcc
17165912f00Smrgfi
17265912f00Smrg
173f80a6dcdSmrgcase "$depmode" in
174f80a6dcdSmrggcc3)
175f80a6dcdSmrg## gcc 3 implements dependency tracking that does exactly what
176f80a6dcdSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177f80a6dcdSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
17865912f00Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
17965912f00Smrg## the command line argument order; so add the flags where they
18065912f00Smrg## appear in depend2.am.  Note that the slowdown incurred here
18165912f00Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18265912f00Smrg  for arg
18365912f00Smrg  do
18465912f00Smrg    case $arg in
18565912f00Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18665912f00Smrg    *)  set fnord "$@" "$arg" ;;
18765912f00Smrg    esac
18865912f00Smrg    shift # fnord
18965912f00Smrg    shift # $arg
19065912f00Smrg  done
19165912f00Smrg  "$@"
192f80a6dcdSmrg  stat=$?
193c166fba9Smrg  if test $stat -ne 0; then
194f80a6dcdSmrg    rm -f "$tmpdepfile"
195f80a6dcdSmrg    exit $stat
196f80a6dcdSmrg  fi
197f80a6dcdSmrg  mv "$tmpdepfile" "$depfile"
198f80a6dcdSmrg  ;;
199f80a6dcdSmrg
200f80a6dcdSmrggcc)
201c166fba9Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202c166fba9Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203c166fba9Smrg## (see the conditional assignment to $gccflag above).
204f80a6dcdSmrg## There are various ways to get dependency output from gcc.  Here's
205f80a6dcdSmrg## why we pick this rather obscure method:
206f80a6dcdSmrg## - Don't want to use -MD because we'd like the dependencies to end
207f80a6dcdSmrg##   up in a subdir.  Having to rename by hand is ugly.
208f80a6dcdSmrg##   (We might end up doing this anyway to support other compilers.)
209f80a6dcdSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210c166fba9Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211c166fba9Smrg##   supported by the other compilers which use the 'gcc' depmode.
212f80a6dcdSmrg## - Using -M directly means running the compiler twice (even worse
213f80a6dcdSmrg##   than renaming).
214f80a6dcdSmrg  if test -z "$gccflag"; then
215f80a6dcdSmrg    gccflag=-MD,
216f80a6dcdSmrg  fi
217f80a6dcdSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
218f80a6dcdSmrg  stat=$?
219c166fba9Smrg  if test $stat -ne 0; then
220f80a6dcdSmrg    rm -f "$tmpdepfile"
221f80a6dcdSmrg    exit $stat
222f80a6dcdSmrg  fi
223f80a6dcdSmrg  rm -f "$depfile"
224f80a6dcdSmrg  echo "$object : \\" > "$depfile"
225c166fba9Smrg  # The second -e expression handles DOS-style file names with drive
226c166fba9Smrg  # letters.
227f80a6dcdSmrg  sed -e 's/^[^:]*: / /' \
228f80a6dcdSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229c166fba9Smrg## This next piece of magic avoids the "deleted header file" problem.
230f80a6dcdSmrg## The problem is that when a header file which appears in a .P file
231f80a6dcdSmrg## is deleted, the dependency causes make to die (because there is
232f80a6dcdSmrg## typically no way to rebuild the header).  We avoid this by adding
233f80a6dcdSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234f80a6dcdSmrg## this for us directly.
235c166fba9Smrg## Some versions of gcc put a space before the ':'.  On the theory
236f80a6dcdSmrg## that the space means something, we add a space to the output as
23765912f00Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23865912f00Smrg## to the object.  Take care to not repeat it in the output.
239f80a6dcdSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
240f80a6dcdSmrg## correctly.  Breaking it into two sed invocations is a workaround.
241c166fba9Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242c166fba9Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243c166fba9Smrg    | sed -e 's/$/ :/' >> "$depfile"
244f80a6dcdSmrg  rm -f "$tmpdepfile"
245f80a6dcdSmrg  ;;
246f80a6dcdSmrg
247f80a6dcdSmrghp)
248f80a6dcdSmrg  # This case exists only to let depend.m4 do its work.  It works by
249f80a6dcdSmrg  # looking at the text of this script.  This case will never be run,
250f80a6dcdSmrg  # since it is checked for above.
251f80a6dcdSmrg  exit 1
252f80a6dcdSmrg  ;;
253f80a6dcdSmrg
254f80a6dcdSmrgsgi)
255f80a6dcdSmrg  if test "$libtool" = yes; then
256f80a6dcdSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257f80a6dcdSmrg  else
258f80a6dcdSmrg    "$@" -MDupdate "$tmpdepfile"
259f80a6dcdSmrg  fi
260f80a6dcdSmrg  stat=$?
261c166fba9Smrg  if test $stat -ne 0; then
262f80a6dcdSmrg    rm -f "$tmpdepfile"
263f80a6dcdSmrg    exit $stat
264f80a6dcdSmrg  fi
265f80a6dcdSmrg  rm -f "$depfile"
266f80a6dcdSmrg
267f80a6dcdSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268f80a6dcdSmrg    echo "$object : \\" > "$depfile"
269f80a6dcdSmrg    # Clip off the initial element (the dependent).  Don't try to be
270f80a6dcdSmrg    # clever and replace this with sed code, as IRIX sed won't handle
271f80a6dcdSmrg    # lines with more than a fixed number of characters (4096 in
272f80a6dcdSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273c166fba9Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274f80a6dcdSmrg    # dependency line.
275c166fba9Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276c166fba9Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277c166fba9Smrg      | tr "$nl" ' ' >> "$depfile"
27865912f00Smrg    echo >> "$depfile"
279f80a6dcdSmrg    # The second pass generates a dummy entry for each header file.
280c166fba9Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281c166fba9Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282c166fba9Smrg      >> "$depfile"
283f80a6dcdSmrg  else
284c166fba9Smrg    make_dummy_depfile
285f80a6dcdSmrg  fi
286f80a6dcdSmrg  rm -f "$tmpdepfile"
287f80a6dcdSmrg  ;;
288f80a6dcdSmrg
289c166fba9Smrgxlc)
290c166fba9Smrg  # This case exists only to let depend.m4 do its work.  It works by
291c166fba9Smrg  # looking at the text of this script.  This case will never be run,
292c166fba9Smrg  # since it is checked for above.
293c166fba9Smrg  exit 1
294c166fba9Smrg  ;;
295c166fba9Smrg
296f80a6dcdSmrgaix)
297f80a6dcdSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
298f80a6dcdSmrg  # in a .u file.  In older versions, this file always lives in the
299c166fba9Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300f80a6dcdSmrg  # start of each line; $object doesn't have directory information.
301f80a6dcdSmrg  # Version 6 uses the directory in both cases.
302c166fba9Smrg  set_dir_from "$object"
303c166fba9Smrg  set_base_from "$object"
304f80a6dcdSmrg  if test "$libtool" = yes; then
30565912f00Smrg    tmpdepfile1=$dir$base.u
30665912f00Smrg    tmpdepfile2=$base.u
30765912f00Smrg    tmpdepfile3=$dir.libs/$base.u
308f80a6dcdSmrg    "$@" -Wc,-M
309f80a6dcdSmrg  else
31065912f00Smrg    tmpdepfile1=$dir$base.u
31165912f00Smrg    tmpdepfile2=$dir$base.u
31265912f00Smrg    tmpdepfile3=$dir$base.u
313f80a6dcdSmrg    "$@" -M
314f80a6dcdSmrg  fi
315f80a6dcdSmrg  stat=$?
316c166fba9Smrg  if test $stat -ne 0; then
31765912f00Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318f80a6dcdSmrg    exit $stat
319f80a6dcdSmrg  fi
320f80a6dcdSmrg
32165912f00Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32265912f00Smrg  do
32365912f00Smrg    test -f "$tmpdepfile" && break
32465912f00Smrg  done
325c166fba9Smrg  aix_post_process_depfile
326c166fba9Smrg  ;;
327c166fba9Smrg
328c166fba9Smrgtcc)
329c166fba9Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330c166fba9Smrg  # FIXME: That version still under development at the moment of writing.
331c166fba9Smrg  #        Make that this statement remains true also for stable, released
332c166fba9Smrg  #        versions.
333c166fba9Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334c166fba9Smrg  # trailing '\', as in:
335c166fba9Smrg  #
336c166fba9Smrg  #   foo.o : \
337c166fba9Smrg  #    foo.c \
338c166fba9Smrg  #    foo.h \
339c166fba9Smrg  #
340c166fba9Smrg  # It will put a trailing '\' even on the last line, and will use leading
341c166fba9Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342c166fba9Smrg  # "Emit spaces for -MD").
343c166fba9Smrg  "$@" -MD -MF "$tmpdepfile"
344c166fba9Smrg  stat=$?
345c166fba9Smrg  if test $stat -ne 0; then
346c166fba9Smrg    rm -f "$tmpdepfile"
347c166fba9Smrg    exit $stat
348f80a6dcdSmrg  fi
349c166fba9Smrg  rm -f "$depfile"
350c166fba9Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351c166fba9Smrg  # We have to change lines of the first kind to '$object: \'.
352c166fba9Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353c166fba9Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354c166fba9Smrg  # dummy dependency, to avoid the deleted-header problem.
355c166fba9Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356f80a6dcdSmrg  rm -f "$tmpdepfile"
357f80a6dcdSmrg  ;;
358f80a6dcdSmrg
359c166fba9Smrg## The order of this option in the case statement is important, since the
360c166fba9Smrg## shell code in configure will try each of these formats in the order
361c166fba9Smrg## listed in this file.  A plain '-MD' option would be understood by many
362c166fba9Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363c166fba9Smrgpgcc)
364c166fba9Smrg  # Portland's C compiler understands '-MD'.
365c166fba9Smrg  # Will always output deps to 'file.d' where file is the root name of the
366c166fba9Smrg  # source file under compilation, even if file resides in a subdirectory.
367c166fba9Smrg  # The object file name does not affect the name of the '.d' file.
368c166fba9Smrg  # pgcc 10.2 will output
369f80a6dcdSmrg  #    foo.o: sub/foo.c sub/foo.h
370c166fba9Smrg  # and will wrap long lines using '\' :
371f80a6dcdSmrg  #    foo.o: sub/foo.c ... \
372f80a6dcdSmrg  #     sub/foo.h ... \
373f80a6dcdSmrg  #     ...
374c166fba9Smrg  set_dir_from "$object"
375c166fba9Smrg  # Use the source, not the object, to determine the base name, since
376c166fba9Smrg  # that's sadly what pgcc will do too.
377c166fba9Smrg  set_base_from "$source"
378c166fba9Smrg  tmpdepfile=$base.d
379c166fba9Smrg
380c166fba9Smrg  # For projects that build the same source file twice into different object
381c166fba9Smrg  # files, the pgcc approach of using the *source* file root name can cause
382c166fba9Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383c166fba9Smrg  # the same $tmpdepfile.
384c166fba9Smrg  lockdir=$base.d-lock
385c166fba9Smrg  trap "
386c166fba9Smrg    echo '$0: caught signal, cleaning up...' >&2
387c166fba9Smrg    rmdir '$lockdir'
388c166fba9Smrg    exit 1
389c166fba9Smrg  " 1 2 13 15
390c166fba9Smrg  numtries=100
391c166fba9Smrg  i=$numtries
392c166fba9Smrg  while test $i -gt 0; do
393c166fba9Smrg    # mkdir is a portable test-and-set.
394c166fba9Smrg    if mkdir "$lockdir" 2>/dev/null; then
395c166fba9Smrg      # This process acquired the lock.
396c166fba9Smrg      "$@" -MD
397c166fba9Smrg      stat=$?
398c166fba9Smrg      # Release the lock.
399c166fba9Smrg      rmdir "$lockdir"
400c166fba9Smrg      break
401c166fba9Smrg    else
402c166fba9Smrg      # If the lock is being held by a different process, wait
403c166fba9Smrg      # until the winning process is done or we timeout.
404c166fba9Smrg      while test -d "$lockdir" && test $i -gt 0; do
405c166fba9Smrg        sleep 1
406c166fba9Smrg        i=`expr $i - 1`
407c166fba9Smrg      done
408c166fba9Smrg    fi
409c166fba9Smrg    i=`expr $i - 1`
410c166fba9Smrg  done
411c166fba9Smrg  trap - 1 2 13 15
412c166fba9Smrg  if test $i -le 0; then
413c166fba9Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414c166fba9Smrg    echo "$0: check lockdir '$lockdir'" >&2
415c166fba9Smrg    exit 1
416c166fba9Smrg  fi
417f80a6dcdSmrg
418c166fba9Smrg  if test $stat -ne 0; then
419f80a6dcdSmrg    rm -f "$tmpdepfile"
420f80a6dcdSmrg    exit $stat
421f80a6dcdSmrg  fi
422f80a6dcdSmrg  rm -f "$depfile"
423f80a6dcdSmrg  # Each line is of the form `foo.o: dependent.h',
424f80a6dcdSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425f80a6dcdSmrg  # Do two passes, one to just change these to
426f80a6dcdSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427f80a6dcdSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428f80a6dcdSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429f80a6dcdSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
430c166fba9Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431c166fba9Smrg    | sed -e 's/$/ :/' >> "$depfile"
432f80a6dcdSmrg  rm -f "$tmpdepfile"
433f80a6dcdSmrg  ;;
434f80a6dcdSmrg
43565912f00Smrghp2)
43665912f00Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43765912f00Smrg  # compilers, which have integrated preprocessors.  The correct option
43865912f00Smrg  # to use with these is +Maked; it writes dependencies to a file named
43965912f00Smrg  # 'foo.d', which lands next to the object file, wherever that
44065912f00Smrg  # happens to be.
44165912f00Smrg  # Much of this is similar to the tru64 case; see comments there.
442c166fba9Smrg  set_dir_from  "$object"
443c166fba9Smrg  set_base_from "$object"
44465912f00Smrg  if test "$libtool" = yes; then
44565912f00Smrg    tmpdepfile1=$dir$base.d
44665912f00Smrg    tmpdepfile2=$dir.libs/$base.d
44765912f00Smrg    "$@" -Wc,+Maked
44865912f00Smrg  else
44965912f00Smrg    tmpdepfile1=$dir$base.d
45065912f00Smrg    tmpdepfile2=$dir$base.d
45165912f00Smrg    "$@" +Maked
45265912f00Smrg  fi
45365912f00Smrg  stat=$?
454c166fba9Smrg  if test $stat -ne 0; then
45565912f00Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
45665912f00Smrg     exit $stat
45765912f00Smrg  fi
45865912f00Smrg
45965912f00Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46065912f00Smrg  do
46165912f00Smrg    test -f "$tmpdepfile" && break
46265912f00Smrg  done
46365912f00Smrg  if test -f "$tmpdepfile"; then
464c166fba9Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465c166fba9Smrg    # Add 'dependent.h:' lines.
46665912f00Smrg    sed -ne '2,${
467c166fba9Smrg               s/^ *//
468c166fba9Smrg               s/ \\*$//
469c166fba9Smrg               s/$/:/
470c166fba9Smrg               p
471c166fba9Smrg             }' "$tmpdepfile" >> "$depfile"
47265912f00Smrg  else
473c166fba9Smrg    make_dummy_depfile
47465912f00Smrg  fi
47565912f00Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
47665912f00Smrg  ;;
47765912f00Smrg
478f80a6dcdSmrgtru64)
479c166fba9Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480c166fba9Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481c166fba9Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482c166fba9Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483c166fba9Smrg  # Subdirectories are respected.
484c166fba9Smrg  set_dir_from  "$object"
485c166fba9Smrg  set_base_from "$object"
486c166fba9Smrg
487c166fba9Smrg  if test "$libtool" = yes; then
488c166fba9Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489c166fba9Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490c166fba9Smrg    # in $dir$base.o.d.  We have to check for both files, because
491c166fba9Smrg    # one of the two compilations can be disabled.  We should prefer
492c166fba9Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493c166fba9Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494c166fba9Smrg    # the former would cause a distcleancheck panic.
495c166fba9Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496c166fba9Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497c166fba9Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498c166fba9Smrg    "$@" -Wc,-MD
499c166fba9Smrg  else
500c166fba9Smrg    tmpdepfile1=$dir$base.d
501c166fba9Smrg    tmpdepfile2=$dir$base.d
502c166fba9Smrg    tmpdepfile3=$dir$base.d
503c166fba9Smrg    "$@" -MD
504c166fba9Smrg  fi
505c166fba9Smrg
506c166fba9Smrg  stat=$?
507c166fba9Smrg  if test $stat -ne 0; then
508c166fba9Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509c166fba9Smrg    exit $stat
510c166fba9Smrg  fi
511c166fba9Smrg
512c166fba9Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513c166fba9Smrg  do
514c166fba9Smrg    test -f "$tmpdepfile" && break
515c166fba9Smrg  done
516c166fba9Smrg  # Same post-processing that is required for AIX mode.
517c166fba9Smrg  aix_post_process_depfile
518c166fba9Smrg  ;;
519f80a6dcdSmrg
52065912f00Smrgmsvc7)
52165912f00Smrg  if test "$libtool" = yes; then
52265912f00Smrg    showIncludes=-Wc,-showIncludes
52365912f00Smrg  else
52465912f00Smrg    showIncludes=-showIncludes
52565912f00Smrg  fi
52665912f00Smrg  "$@" $showIncludes > "$tmpdepfile"
52765912f00Smrg  stat=$?
52865912f00Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529c166fba9Smrg  if test $stat -ne 0; then
53065912f00Smrg    rm -f "$tmpdepfile"
53165912f00Smrg    exit $stat
53265912f00Smrg  fi
53365912f00Smrg  rm -f "$depfile"
53465912f00Smrg  echo "$object : \\" > "$depfile"
53565912f00Smrg  # The first sed program below extracts the file names and escapes
53665912f00Smrg  # backslashes for cygpath.  The second sed program outputs the file
53765912f00Smrg  # name when reading, but also accumulates all include files in the
53865912f00Smrg  # hold buffer in order to output them again at the end.  This only
53965912f00Smrg  # works with sed implementations that can handle large buffers.
54065912f00Smrg  sed < "$tmpdepfile" -n '
54165912f00Smrg/^Note: including file:  *\(.*\)/ {
54265912f00Smrg  s//\1/
54365912f00Smrg  s/\\/\\\\/g
54465912f00Smrg  p
54565912f00Smrg}' | $cygpath_u | sort -u | sed -n '
54665912f00Smrgs/ /\\ /g
547c166fba9Smrgs/\(.*\)/'"$tab"'\1 \\/p
54865912f00Smrgs/.\(.*\) \\/\1:/
54965912f00SmrgH
55065912f00Smrg$ {
551c166fba9Smrg  s/.*/'"$tab"'/
55265912f00Smrg  G
55365912f00Smrg  p
55465912f00Smrg}' >> "$depfile"
555c166fba9Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55665912f00Smrg  rm -f "$tmpdepfile"
55765912f00Smrg  ;;
55865912f00Smrg
55965912f00Smrgmsvc7msys)
56065912f00Smrg  # This case exists only to let depend.m4 do its work.  It works by
56165912f00Smrg  # looking at the text of this script.  This case will never be run,
56265912f00Smrg  # since it is checked for above.
56365912f00Smrg  exit 1
56465912f00Smrg  ;;
56565912f00Smrg
566f80a6dcdSmrg#nosideeffect)
567f80a6dcdSmrg  # This comment above is used by automake to tell side-effect
568f80a6dcdSmrg  # dependency tracking mechanisms from slower ones.
569f80a6dcdSmrg
570f80a6dcdSmrgdashmstdout)
571f80a6dcdSmrg  # Important note: in order to support this mode, a compiler *must*
572f80a6dcdSmrg  # always write the preprocessed file to stdout, regardless of -o.
573f80a6dcdSmrg  "$@" || exit $?
574f80a6dcdSmrg
575f80a6dcdSmrg  # Remove the call to Libtool.
576f80a6dcdSmrg  if test "$libtool" = yes; then
57765912f00Smrg    while test "X$1" != 'X--mode=compile'; do
578f80a6dcdSmrg      shift
579f80a6dcdSmrg    done
580f80a6dcdSmrg    shift
581f80a6dcdSmrg  fi
582f80a6dcdSmrg
583c166fba9Smrg  # Remove '-o $object'.
584f80a6dcdSmrg  IFS=" "
585f80a6dcdSmrg  for arg
586f80a6dcdSmrg  do
587f80a6dcdSmrg    case $arg in
588f80a6dcdSmrg    -o)
589f80a6dcdSmrg      shift
590f80a6dcdSmrg      ;;
591f80a6dcdSmrg    $object)
592f80a6dcdSmrg      shift
593f80a6dcdSmrg      ;;
594f80a6dcdSmrg    *)
595f80a6dcdSmrg      set fnord "$@" "$arg"
596f80a6dcdSmrg      shift # fnord
597f80a6dcdSmrg      shift # $arg
598f80a6dcdSmrg      ;;
599f80a6dcdSmrg    esac
600f80a6dcdSmrg  done
601f80a6dcdSmrg
602f80a6dcdSmrg  test -z "$dashmflag" && dashmflag=-M
603c166fba9Smrg  # Require at least two characters before searching for ':'
604f80a6dcdSmrg  # in the target name.  This is to cope with DOS-style filenames:
605c166fba9Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606f80a6dcdSmrg  "$@" $dashmflag |
607c166fba9Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608f80a6dcdSmrg  rm -f "$depfile"
609f80a6dcdSmrg  cat < "$tmpdepfile" > "$depfile"
610c166fba9Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611c166fba9Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612c166fba9Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613c166fba9Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614c166fba9Smrg    | sed -e 's/$/ :/' >> "$depfile"
615f80a6dcdSmrg  rm -f "$tmpdepfile"
616f80a6dcdSmrg  ;;
617f80a6dcdSmrg
618f80a6dcdSmrgdashXmstdout)
619f80a6dcdSmrg  # This case only exists to satisfy depend.m4.  It is never actually
620f80a6dcdSmrg  # run, as this mode is specially recognized in the preamble.
621f80a6dcdSmrg  exit 1
622f80a6dcdSmrg  ;;
623f80a6dcdSmrg
624f80a6dcdSmrgmakedepend)
625f80a6dcdSmrg  "$@" || exit $?
626f80a6dcdSmrg  # Remove any Libtool call
627f80a6dcdSmrg  if test "$libtool" = yes; then
62865912f00Smrg    while test "X$1" != 'X--mode=compile'; do
629f80a6dcdSmrg      shift
630f80a6dcdSmrg    done
631f80a6dcdSmrg    shift
632f80a6dcdSmrg  fi
633f80a6dcdSmrg  # X makedepend
634f80a6dcdSmrg  shift
63565912f00Smrg  cleared=no eat=no
63665912f00Smrg  for arg
63765912f00Smrg  do
638f80a6dcdSmrg    case $cleared in
639f80a6dcdSmrg    no)
640f80a6dcdSmrg      set ""; shift
641f80a6dcdSmrg      cleared=yes ;;
642f80a6dcdSmrg    esac
64365912f00Smrg    if test $eat = yes; then
64465912f00Smrg      eat=no
64565912f00Smrg      continue
64665912f00Smrg    fi
647f80a6dcdSmrg    case "$arg" in
648f80a6dcdSmrg    -D*|-I*)
649f80a6dcdSmrg      set fnord "$@" "$arg"; shift ;;
650f80a6dcdSmrg    # Strip any option that makedepend may not understand.  Remove
651f80a6dcdSmrg    # the object too, otherwise makedepend will parse it as a source file.
65265912f00Smrg    -arch)
65365912f00Smrg      eat=yes ;;
654f80a6dcdSmrg    -*|$object)
655f80a6dcdSmrg      ;;
656f80a6dcdSmrg    *)
657f80a6dcdSmrg      set fnord "$@" "$arg"; shift ;;
658f80a6dcdSmrg    esac
659f80a6dcdSmrg  done
66065912f00Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661f80a6dcdSmrg  touch "$tmpdepfile"
662f80a6dcdSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663f80a6dcdSmrg  rm -f "$depfile"
66465912f00Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66565912f00Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66665912f00Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667c166fba9Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668c166fba9Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669c166fba9Smrg  sed '1,2d' "$tmpdepfile" \
670c166fba9Smrg    | tr ' ' "$nl" \
671c166fba9Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672c166fba9Smrg    | sed -e 's/$/ :/' >> "$depfile"
673f80a6dcdSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674f80a6dcdSmrg  ;;
675f80a6dcdSmrg
676f80a6dcdSmrgcpp)
677f80a6dcdSmrg  # Important note: in order to support this mode, a compiler *must*
678f80a6dcdSmrg  # always write the preprocessed file to stdout.
679f80a6dcdSmrg  "$@" || exit $?
680f80a6dcdSmrg
681f80a6dcdSmrg  # Remove the call to Libtool.
682f80a6dcdSmrg  if test "$libtool" = yes; then
68365912f00Smrg    while test "X$1" != 'X--mode=compile'; do
684f80a6dcdSmrg      shift
685f80a6dcdSmrg    done
686f80a6dcdSmrg    shift
687f80a6dcdSmrg  fi
688f80a6dcdSmrg
689c166fba9Smrg  # Remove '-o $object'.
690f80a6dcdSmrg  IFS=" "
691f80a6dcdSmrg  for arg
692f80a6dcdSmrg  do
693f80a6dcdSmrg    case $arg in
694f80a6dcdSmrg    -o)
695f80a6dcdSmrg      shift
696f80a6dcdSmrg      ;;
697f80a6dcdSmrg    $object)
698f80a6dcdSmrg      shift
699f80a6dcdSmrg      ;;
700f80a6dcdSmrg    *)
701f80a6dcdSmrg      set fnord "$@" "$arg"
702f80a6dcdSmrg      shift # fnord
703f80a6dcdSmrg      shift # $arg
704f80a6dcdSmrg      ;;
705f80a6dcdSmrg    esac
706f80a6dcdSmrg  done
707f80a6dcdSmrg
708c166fba9Smrg  "$@" -E \
709c166fba9Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710c166fba9Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711c166fba9Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712f80a6dcdSmrg  rm -f "$depfile"
713f80a6dcdSmrg  echo "$object : \\" > "$depfile"
714f80a6dcdSmrg  cat < "$tmpdepfile" >> "$depfile"
715f80a6dcdSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716f80a6dcdSmrg  rm -f "$tmpdepfile"
717f80a6dcdSmrg  ;;
718f80a6dcdSmrg
719f80a6dcdSmrgmsvisualcpp)
720f80a6dcdSmrg  # Important note: in order to support this mode, a compiler *must*
72165912f00Smrg  # always write the preprocessed file to stdout.
722f80a6dcdSmrg  "$@" || exit $?
72365912f00Smrg
72465912f00Smrg  # Remove the call to Libtool.
72565912f00Smrg  if test "$libtool" = yes; then
72665912f00Smrg    while test "X$1" != 'X--mode=compile'; do
72765912f00Smrg      shift
72865912f00Smrg    done
72965912f00Smrg    shift
73065912f00Smrg  fi
73165912f00Smrg
732f80a6dcdSmrg  IFS=" "
733f80a6dcdSmrg  for arg
734f80a6dcdSmrg  do
735f80a6dcdSmrg    case "$arg" in
73665912f00Smrg    -o)
73765912f00Smrg      shift
73865912f00Smrg      ;;
73965912f00Smrg    $object)
74065912f00Smrg      shift
74165912f00Smrg      ;;
742f80a6dcdSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743c166fba9Smrg        set fnord "$@"
744c166fba9Smrg        shift
745c166fba9Smrg        shift
746c166fba9Smrg        ;;
747f80a6dcdSmrg    *)
748c166fba9Smrg        set fnord "$@" "$arg"
749c166fba9Smrg        shift
750c166fba9Smrg        shift
751c166fba9Smrg        ;;
752f80a6dcdSmrg    esac
753f80a6dcdSmrg  done
75465912f00Smrg  "$@" -E 2>/dev/null |
75565912f00Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756f80a6dcdSmrg  rm -f "$depfile"
757f80a6dcdSmrg  echo "$object : \\" > "$depfile"
758c166fba9Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759c166fba9Smrg  echo "$tab" >> "$depfile"
76065912f00Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761f80a6dcdSmrg  rm -f "$tmpdepfile"
762f80a6dcdSmrg  ;;
763f80a6dcdSmrg
76465912f00Smrgmsvcmsys)
76565912f00Smrg  # This case exists only to let depend.m4 do its work.  It works by
76665912f00Smrg  # looking at the text of this script.  This case will never be run,
76765912f00Smrg  # since it is checked for above.
76865912f00Smrg  exit 1
76965912f00Smrg  ;;
77065912f00Smrg
771f80a6dcdSmrgnone)
772f80a6dcdSmrg  exec "$@"
773f80a6dcdSmrg  ;;
774f80a6dcdSmrg
775f80a6dcdSmrg*)
776f80a6dcdSmrg  echo "Unknown depmode $depmode" 1>&2
777f80a6dcdSmrg  exit 1
778f80a6dcdSmrg  ;;
779f80a6dcdSmrgesac
780f80a6dcdSmrg
781f80a6dcdSmrgexit 0
78265912f00Smrg
78365912f00Smrg# Local Variables:
78465912f00Smrg# mode: shell-script
78565912f00Smrg# sh-indentation: 2
7868c7c3c7eSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
78765912f00Smrg# time-stamp-start: "scriptversion="
78865912f00Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7898c7c3c7eSmrg# time-stamp-time-zone: "UTC0"
79065912f00Smrg# time-stamp-end: "; # UTC"
79165912f00Smrg# End:
792