depcomp revision e53c48bf
1fd7d9bd3Smrg#! /bin/sh
2fd7d9bd3Smrg# depcomp - compile a program generating dependencies as side-effects
3350952b9Smrg
4e53c48bfSmrgscriptversion=2018-03-07.03; # UTC
5350952b9Smrg
6e53c48bfSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
7fd7d9bd3Smrg
8fd7d9bd3Smrg# This program is free software; you can redistribute it and/or modify
9fd7d9bd3Smrg# it under the terms of the GNU General Public License as published by
10fd7d9bd3Smrg# the Free Software Foundation; either version 2, or (at your option)
11fd7d9bd3Smrg# any later version.
12fd7d9bd3Smrg
13fd7d9bd3Smrg# This program is distributed in the hope that it will be useful,
14fd7d9bd3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15fd7d9bd3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16fd7d9bd3Smrg# GNU General Public License for more details.
17fd7d9bd3Smrg
18fd7d9bd3Smrg# You should have received a copy of the GNU General Public License
19e53c48bfSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20fd7d9bd3Smrg
21fd7d9bd3Smrg# As a special exception to the GNU General Public License, if you
22fd7d9bd3Smrg# distribute this file as part of a program that contains a
23fd7d9bd3Smrg# configuration script generated by Autoconf, you may include it under
24fd7d9bd3Smrg# the same distribution terms that you use for the rest of that program.
25fd7d9bd3Smrg
26fd7d9bd3Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27fd7d9bd3Smrg
28350952b9Smrgcase $1 in
29350952b9Smrg  '')
30a9ba4257Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31a9ba4257Smrg    exit 1;
32a9ba4257Smrg    ;;
33350952b9Smrg  -h | --h*)
34350952b9Smrg    cat <<\EOF
35350952b9SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36350952b9Smrg
37350952b9SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38350952b9Smrgas side-effects.
39350952b9Smrg
40350952b9SmrgEnvironment variables:
41350952b9Smrg  depmode     Dependency tracking mode.
42a9ba4257Smrg  source      Source file read by 'PROGRAMS ARGS'.
43a9ba4257Smrg  object      Object file output by 'PROGRAMS ARGS'.
44350952b9Smrg  DEPDIR      directory where to store dependencies.
45350952b9Smrg  depfile     Dependency file to output.
46a85aecdfSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
47350952b9Smrg  libtool     Whether libtool is used (yes/no).
48350952b9Smrg
49350952b9SmrgReport bugs to <bug-automake@gnu.org>.
50350952b9SmrgEOF
51350952b9Smrg    exit $?
52350952b9Smrg    ;;
53350952b9Smrg  -v | --v*)
54350952b9Smrg    echo "depcomp $scriptversion"
55350952b9Smrg    exit $?
56350952b9Smrg    ;;
57350952b9Smrgesac
58350952b9Smrg
59a9ba4257Smrg# Get the directory component of the given path, and save it in the
60a9ba4257Smrg# global variables '$dir'.  Note that this directory component will
61a9ba4257Smrg# be either empty or ending with a '/' character.  This is deliberate.
62a9ba4257Smrgset_dir_from ()
63a9ba4257Smrg{
64a9ba4257Smrg  case $1 in
65a9ba4257Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66a9ba4257Smrg      *) dir=;;
67a9ba4257Smrg  esac
68a9ba4257Smrg}
69a9ba4257Smrg
70a9ba4257Smrg# Get the suffix-stripped basename of the given path, and save it the
71a9ba4257Smrg# global variable '$base'.
72a9ba4257Smrgset_base_from ()
73a9ba4257Smrg{
74a9ba4257Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75a9ba4257Smrg}
76a9ba4257Smrg
77a9ba4257Smrg# If no dependency file was actually created by the compiler invocation,
78a9ba4257Smrg# we still have to create a dummy depfile, to avoid errors with the
79a9ba4257Smrg# Makefile "include basename.Plo" scheme.
80a9ba4257Smrgmake_dummy_depfile ()
81a9ba4257Smrg{
82a9ba4257Smrg  echo "#dummy" > "$depfile"
83a9ba4257Smrg}
84a9ba4257Smrg
85a9ba4257Smrg# Factor out some common post-processing of the generated depfile.
86a9ba4257Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87a9ba4257Smrgaix_post_process_depfile ()
88a9ba4257Smrg{
89a9ba4257Smrg  # If the compiler actually managed to produce a dependency file,
90a9ba4257Smrg  # post-process it.
91a9ba4257Smrg  if test -f "$tmpdepfile"; then
92a9ba4257Smrg    # Each line is of the form 'foo.o: dependency.h'.
93a9ba4257Smrg    # Do two passes, one to just change these to
94a9ba4257Smrg    #   $object: dependency.h
95a9ba4257Smrg    # and one to simply output
96a9ba4257Smrg    #   dependency.h:
97a9ba4257Smrg    # which is needed to avoid the deleted-header problem.
98a9ba4257Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99a9ba4257Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100a9ba4257Smrg    } > "$depfile"
101a9ba4257Smrg    rm -f "$tmpdepfile"
102a9ba4257Smrg  else
103a9ba4257Smrg    make_dummy_depfile
104a9ba4257Smrg  fi
105a9ba4257Smrg}
106a9ba4257Smrg
107a9ba4257Smrg# A tabulation character.
108a9ba4257Smrgtab='	'
109a9ba4257Smrg# A newline character.
110a9ba4257Smrgnl='
111a9ba4257Smrg'
112a9ba4257Smrg# Character ranges might be problematic outside the C locale.
113a9ba4257Smrg# These definitions help.
114a9ba4257Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115a9ba4257Smrglower=abcdefghijklmnopqrstuvwxyz
116a9ba4257Smrgdigits=0123456789
117a9ba4257Smrgalpha=${upper}${lower}
118a9ba4257Smrg
119fd7d9bd3Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120fd7d9bd3Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121fd7d9bd3Smrg  exit 1
122fd7d9bd3Smrgfi
123fd7d9bd3Smrg
124350952b9Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125350952b9Smrgdepfile=${depfile-`echo "$object" |
126350952b9Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127fd7d9bd3Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128fd7d9bd3Smrg
129fd7d9bd3Smrgrm -f "$tmpdepfile"
130fd7d9bd3Smrg
131a9ba4257Smrg# Avoid interferences from the environment.
132a9ba4257Smrggccflag= dashmflag=
133a9ba4257Smrg
134fd7d9bd3Smrg# Some modes work just like other modes, but use different flags.  We
135fd7d9bd3Smrg# parameterize here, but still list the modes in the big case below,
136fd7d9bd3Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137fd7d9bd3Smrg# here, because this file can only contain one case statement.
138fd7d9bd3Smrgif test "$depmode" = hp; then
139fd7d9bd3Smrg  # HP compiler uses -M and no extra arg.
140fd7d9bd3Smrg  gccflag=-M
141fd7d9bd3Smrg  depmode=gcc
142fd7d9bd3Smrgfi
143fd7d9bd3Smrg
144fd7d9bd3Smrgif test "$depmode" = dashXmstdout; then
145a9ba4257Smrg  # This is just like dashmstdout with a different argument.
146a9ba4257Smrg  dashmflag=-xM
147a9ba4257Smrg  depmode=dashmstdout
148fd7d9bd3Smrgfi
149fd7d9bd3Smrg
150350952b9Smrgcygpath_u="cygpath -u -f -"
151350952b9Smrgif test "$depmode" = msvcmsys; then
152a9ba4257Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153a9ba4257Smrg  # Just convert the backslash-escaped backslashes to single forward
154a9ba4257Smrg  # slashes to satisfy depend.m4
155a9ba4257Smrg  cygpath_u='sed s,\\\\,/,g'
156a9ba4257Smrg  depmode=msvisualcpp
157350952b9Smrgfi
158350952b9Smrg
159a85aecdfSmrgif test "$depmode" = msvc7msys; then
160a9ba4257Smrg  # This is just like msvc7 but w/o cygpath translation.
161a9ba4257Smrg  # Just convert the backslash-escaped backslashes to single forward
162a9ba4257Smrg  # slashes to satisfy depend.m4
163a9ba4257Smrg  cygpath_u='sed s,\\\\,/,g'
164a9ba4257Smrg  depmode=msvc7
165a9ba4257Smrgfi
166a9ba4257Smrg
167a9ba4257Smrgif test "$depmode" = xlc; then
168a9ba4257Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169a9ba4257Smrg  gccflag=-qmakedep=gcc,-MF
170a9ba4257Smrg  depmode=gcc
171a85aecdfSmrgfi
172a85aecdfSmrg
173fd7d9bd3Smrgcase "$depmode" in
174fd7d9bd3Smrggcc3)
175fd7d9bd3Smrg## gcc 3 implements dependency tracking that does exactly what
176fd7d9bd3Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177fd7d9bd3Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178350952b9Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179350952b9Smrg## the command line argument order; so add the flags where they
180350952b9Smrg## appear in depend2.am.  Note that the slowdown incurred here
181350952b9Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182350952b9Smrg  for arg
183350952b9Smrg  do
184350952b9Smrg    case $arg in
185350952b9Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186350952b9Smrg    *)  set fnord "$@" "$arg" ;;
187350952b9Smrg    esac
188350952b9Smrg    shift # fnord
189350952b9Smrg    shift # $arg
190350952b9Smrg  done
191350952b9Smrg  "$@"
192fd7d9bd3Smrg  stat=$?
193a9ba4257Smrg  if test $stat -ne 0; then
194fd7d9bd3Smrg    rm -f "$tmpdepfile"
195fd7d9bd3Smrg    exit $stat
196fd7d9bd3Smrg  fi
197fd7d9bd3Smrg  mv "$tmpdepfile" "$depfile"
198fd7d9bd3Smrg  ;;
199fd7d9bd3Smrg
200fd7d9bd3Smrggcc)
201a9ba4257Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202a9ba4257Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203a9ba4257Smrg## (see the conditional assignment to $gccflag above).
204fd7d9bd3Smrg## There are various ways to get dependency output from gcc.  Here's
205fd7d9bd3Smrg## why we pick this rather obscure method:
206fd7d9bd3Smrg## - Don't want to use -MD because we'd like the dependencies to end
207fd7d9bd3Smrg##   up in a subdir.  Having to rename by hand is ugly.
208fd7d9bd3Smrg##   (We might end up doing this anyway to support other compilers.)
209fd7d9bd3Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210a9ba4257Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211a9ba4257Smrg##   supported by the other compilers which use the 'gcc' depmode.
212fd7d9bd3Smrg## - Using -M directly means running the compiler twice (even worse
213fd7d9bd3Smrg##   than renaming).
214fd7d9bd3Smrg  if test -z "$gccflag"; then
215fd7d9bd3Smrg    gccflag=-MD,
216fd7d9bd3Smrg  fi
217fd7d9bd3Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218fd7d9bd3Smrg  stat=$?
219a9ba4257Smrg  if test $stat -ne 0; then
220fd7d9bd3Smrg    rm -f "$tmpdepfile"
221fd7d9bd3Smrg    exit $stat
222fd7d9bd3Smrg  fi
223fd7d9bd3Smrg  rm -f "$depfile"
224fd7d9bd3Smrg  echo "$object : \\" > "$depfile"
225a9ba4257Smrg  # The second -e expression handles DOS-style file names with drive
226a9ba4257Smrg  # letters.
227fd7d9bd3Smrg  sed -e 's/^[^:]*: / /' \
228fd7d9bd3Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229a9ba4257Smrg## This next piece of magic avoids the "deleted header file" problem.
230fd7d9bd3Smrg## The problem is that when a header file which appears in a .P file
231fd7d9bd3Smrg## is deleted, the dependency causes make to die (because there is
232fd7d9bd3Smrg## typically no way to rebuild the header).  We avoid this by adding
233fd7d9bd3Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234fd7d9bd3Smrg## this for us directly.
235a9ba4257Smrg## Some versions of gcc put a space before the ':'.  On the theory
236fd7d9bd3Smrg## that the space means something, we add a space to the output as
237a85aecdfSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238a85aecdfSmrg## to the object.  Take care to not repeat it in the output.
239fd7d9bd3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240fd7d9bd3Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241a9ba4257Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242a9ba4257Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243a9ba4257Smrg    | sed -e 's/$/ :/' >> "$depfile"
244fd7d9bd3Smrg  rm -f "$tmpdepfile"
245fd7d9bd3Smrg  ;;
246fd7d9bd3Smrg
247fd7d9bd3Smrghp)
248fd7d9bd3Smrg  # This case exists only to let depend.m4 do its work.  It works by
249fd7d9bd3Smrg  # looking at the text of this script.  This case will never be run,
250fd7d9bd3Smrg  # since it is checked for above.
251fd7d9bd3Smrg  exit 1
252fd7d9bd3Smrg  ;;
253fd7d9bd3Smrg
254fd7d9bd3Smrgsgi)
255fd7d9bd3Smrg  if test "$libtool" = yes; then
256fd7d9bd3Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257fd7d9bd3Smrg  else
258fd7d9bd3Smrg    "$@" -MDupdate "$tmpdepfile"
259fd7d9bd3Smrg  fi
260fd7d9bd3Smrg  stat=$?
261a9ba4257Smrg  if test $stat -ne 0; then
262fd7d9bd3Smrg    rm -f "$tmpdepfile"
263fd7d9bd3Smrg    exit $stat
264fd7d9bd3Smrg  fi
265fd7d9bd3Smrg  rm -f "$depfile"
266fd7d9bd3Smrg
267fd7d9bd3Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268fd7d9bd3Smrg    echo "$object : \\" > "$depfile"
269fd7d9bd3Smrg    # Clip off the initial element (the dependent).  Don't try to be
270fd7d9bd3Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271fd7d9bd3Smrg    # lines with more than a fixed number of characters (4096 in
272fd7d9bd3Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273a9ba4257Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274fd7d9bd3Smrg    # dependency line.
275a9ba4257Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276a9ba4257Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277a9ba4257Smrg      | tr "$nl" ' ' >> "$depfile"
278350952b9Smrg    echo >> "$depfile"
279fd7d9bd3Smrg    # The second pass generates a dummy entry for each header file.
280a9ba4257Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281a9ba4257Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282a9ba4257Smrg      >> "$depfile"
283fd7d9bd3Smrg  else
284a9ba4257Smrg    make_dummy_depfile
285fd7d9bd3Smrg  fi
286fd7d9bd3Smrg  rm -f "$tmpdepfile"
287fd7d9bd3Smrg  ;;
288fd7d9bd3Smrg
289a9ba4257Smrgxlc)
290a9ba4257Smrg  # This case exists only to let depend.m4 do its work.  It works by
291a9ba4257Smrg  # looking at the text of this script.  This case will never be run,
292a9ba4257Smrg  # since it is checked for above.
293a9ba4257Smrg  exit 1
294a9ba4257Smrg  ;;
295a9ba4257Smrg
296fd7d9bd3Smrgaix)
297fd7d9bd3Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298fd7d9bd3Smrg  # in a .u file.  In older versions, this file always lives in the
299a9ba4257Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300fd7d9bd3Smrg  # start of each line; $object doesn't have directory information.
301fd7d9bd3Smrg  # Version 6 uses the directory in both cases.
302a9ba4257Smrg  set_dir_from "$object"
303a9ba4257Smrg  set_base_from "$object"
304fd7d9bd3Smrg  if test "$libtool" = yes; then
305350952b9Smrg    tmpdepfile1=$dir$base.u
306350952b9Smrg    tmpdepfile2=$base.u
307350952b9Smrg    tmpdepfile3=$dir.libs/$base.u
308fd7d9bd3Smrg    "$@" -Wc,-M
309fd7d9bd3Smrg  else
310350952b9Smrg    tmpdepfile1=$dir$base.u
311350952b9Smrg    tmpdepfile2=$dir$base.u
312350952b9Smrg    tmpdepfile3=$dir$base.u
313fd7d9bd3Smrg    "$@" -M
314fd7d9bd3Smrg  fi
315fd7d9bd3Smrg  stat=$?
316a9ba4257Smrg  if test $stat -ne 0; then
317350952b9Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318fd7d9bd3Smrg    exit $stat
319fd7d9bd3Smrg  fi
320fd7d9bd3Smrg
321350952b9Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322350952b9Smrg  do
323350952b9Smrg    test -f "$tmpdepfile" && break
324350952b9Smrg  done
325a9ba4257Smrg  aix_post_process_depfile
326a9ba4257Smrg  ;;
327a9ba4257Smrg
328a9ba4257Smrgtcc)
329a9ba4257Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330a9ba4257Smrg  # FIXME: That version still under development at the moment of writing.
331a9ba4257Smrg  #        Make that this statement remains true also for stable, released
332a9ba4257Smrg  #        versions.
333a9ba4257Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334a9ba4257Smrg  # trailing '\', as in:
335a9ba4257Smrg  #
336a9ba4257Smrg  #   foo.o : \
337a9ba4257Smrg  #    foo.c \
338a9ba4257Smrg  #    foo.h \
339a9ba4257Smrg  #
340a9ba4257Smrg  # It will put a trailing '\' even on the last line, and will use leading
341a9ba4257Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342a9ba4257Smrg  # "Emit spaces for -MD").
343a9ba4257Smrg  "$@" -MD -MF "$tmpdepfile"
344a9ba4257Smrg  stat=$?
345a9ba4257Smrg  if test $stat -ne 0; then
346a9ba4257Smrg    rm -f "$tmpdepfile"
347a9ba4257Smrg    exit $stat
348fd7d9bd3Smrg  fi
349a9ba4257Smrg  rm -f "$depfile"
350a9ba4257Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351a9ba4257Smrg  # We have to change lines of the first kind to '$object: \'.
352a9ba4257Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353a9ba4257Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354a9ba4257Smrg  # dummy dependency, to avoid the deleted-header problem.
355a9ba4257Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356fd7d9bd3Smrg  rm -f "$tmpdepfile"
357fd7d9bd3Smrg  ;;
358fd7d9bd3Smrg
359a9ba4257Smrg## The order of this option in the case statement is important, since the
360a9ba4257Smrg## shell code in configure will try each of these formats in the order
361a9ba4257Smrg## listed in this file.  A plain '-MD' option would be understood by many
362a9ba4257Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363a9ba4257Smrgpgcc)
364a9ba4257Smrg  # Portland's C compiler understands '-MD'.
365a9ba4257Smrg  # Will always output deps to 'file.d' where file is the root name of the
366a9ba4257Smrg  # source file under compilation, even if file resides in a subdirectory.
367a9ba4257Smrg  # The object file name does not affect the name of the '.d' file.
368a9ba4257Smrg  # pgcc 10.2 will output
369fd7d9bd3Smrg  #    foo.o: sub/foo.c sub/foo.h
370a9ba4257Smrg  # and will wrap long lines using '\' :
371fd7d9bd3Smrg  #    foo.o: sub/foo.c ... \
372fd7d9bd3Smrg  #     sub/foo.h ... \
373fd7d9bd3Smrg  #     ...
374a9ba4257Smrg  set_dir_from "$object"
375a9ba4257Smrg  # Use the source, not the object, to determine the base name, since
376a9ba4257Smrg  # that's sadly what pgcc will do too.
377a9ba4257Smrg  set_base_from "$source"
378a9ba4257Smrg  tmpdepfile=$base.d
379a9ba4257Smrg
380a9ba4257Smrg  # For projects that build the same source file twice into different object
381a9ba4257Smrg  # files, the pgcc approach of using the *source* file root name can cause
382a9ba4257Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383a9ba4257Smrg  # the same $tmpdepfile.
384a9ba4257Smrg  lockdir=$base.d-lock
385a9ba4257Smrg  trap "
386a9ba4257Smrg    echo '$0: caught signal, cleaning up...' >&2
387a9ba4257Smrg    rmdir '$lockdir'
388a9ba4257Smrg    exit 1
389a9ba4257Smrg  " 1 2 13 15
390a9ba4257Smrg  numtries=100
391a9ba4257Smrg  i=$numtries
392a9ba4257Smrg  while test $i -gt 0; do
393a9ba4257Smrg    # mkdir is a portable test-and-set.
394a9ba4257Smrg    if mkdir "$lockdir" 2>/dev/null; then
395a9ba4257Smrg      # This process acquired the lock.
396a9ba4257Smrg      "$@" -MD
397a9ba4257Smrg      stat=$?
398a9ba4257Smrg      # Release the lock.
399a9ba4257Smrg      rmdir "$lockdir"
400a9ba4257Smrg      break
401a9ba4257Smrg    else
402a9ba4257Smrg      # If the lock is being held by a different process, wait
403a9ba4257Smrg      # until the winning process is done or we timeout.
404a9ba4257Smrg      while test -d "$lockdir" && test $i -gt 0; do
405a9ba4257Smrg        sleep 1
406a9ba4257Smrg        i=`expr $i - 1`
407a9ba4257Smrg      done
408a9ba4257Smrg    fi
409a9ba4257Smrg    i=`expr $i - 1`
410a9ba4257Smrg  done
411a9ba4257Smrg  trap - 1 2 13 15
412a9ba4257Smrg  if test $i -le 0; then
413a9ba4257Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414a9ba4257Smrg    echo "$0: check lockdir '$lockdir'" >&2
415a9ba4257Smrg    exit 1
416a9ba4257Smrg  fi
417fd7d9bd3Smrg
418a9ba4257Smrg  if test $stat -ne 0; then
419fd7d9bd3Smrg    rm -f "$tmpdepfile"
420fd7d9bd3Smrg    exit $stat
421fd7d9bd3Smrg  fi
422fd7d9bd3Smrg  rm -f "$depfile"
423fd7d9bd3Smrg  # Each line is of the form `foo.o: dependent.h',
424fd7d9bd3Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425fd7d9bd3Smrg  # Do two passes, one to just change these to
426fd7d9bd3Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427fd7d9bd3Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428fd7d9bd3Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429fd7d9bd3Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430a9ba4257Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431a9ba4257Smrg    | sed -e 's/$/ :/' >> "$depfile"
432fd7d9bd3Smrg  rm -f "$tmpdepfile"
433fd7d9bd3Smrg  ;;
434fd7d9bd3Smrg
435350952b9Smrghp2)
436350952b9Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437350952b9Smrg  # compilers, which have integrated preprocessors.  The correct option
438350952b9Smrg  # to use with these is +Maked; it writes dependencies to a file named
439350952b9Smrg  # 'foo.d', which lands next to the object file, wherever that
440350952b9Smrg  # happens to be.
441350952b9Smrg  # Much of this is similar to the tru64 case; see comments there.
442a9ba4257Smrg  set_dir_from  "$object"
443a9ba4257Smrg  set_base_from "$object"
444350952b9Smrg  if test "$libtool" = yes; then
445350952b9Smrg    tmpdepfile1=$dir$base.d
446350952b9Smrg    tmpdepfile2=$dir.libs/$base.d
447350952b9Smrg    "$@" -Wc,+Maked
448350952b9Smrg  else
449350952b9Smrg    tmpdepfile1=$dir$base.d
450350952b9Smrg    tmpdepfile2=$dir$base.d
451350952b9Smrg    "$@" +Maked
452350952b9Smrg  fi
453350952b9Smrg  stat=$?
454a9ba4257Smrg  if test $stat -ne 0; then
455350952b9Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456350952b9Smrg     exit $stat
457350952b9Smrg  fi
458350952b9Smrg
459350952b9Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460350952b9Smrg  do
461350952b9Smrg    test -f "$tmpdepfile" && break
462350952b9Smrg  done
463350952b9Smrg  if test -f "$tmpdepfile"; then
464a9ba4257Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465a9ba4257Smrg    # Add 'dependent.h:' lines.
466350952b9Smrg    sed -ne '2,${
467a9ba4257Smrg               s/^ *//
468a9ba4257Smrg               s/ \\*$//
469a9ba4257Smrg               s/$/:/
470a9ba4257Smrg               p
471a9ba4257Smrg             }' "$tmpdepfile" >> "$depfile"
472350952b9Smrg  else
473a9ba4257Smrg    make_dummy_depfile
474350952b9Smrg  fi
475350952b9Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476350952b9Smrg  ;;
477350952b9Smrg
478fd7d9bd3Smrgtru64)
479a9ba4257Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480a9ba4257Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481a9ba4257Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482a9ba4257Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483a9ba4257Smrg  # Subdirectories are respected.
484a9ba4257Smrg  set_dir_from  "$object"
485a9ba4257Smrg  set_base_from "$object"
486a9ba4257Smrg
487a9ba4257Smrg  if test "$libtool" = yes; then
488a9ba4257Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489a9ba4257Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490a9ba4257Smrg    # in $dir$base.o.d.  We have to check for both files, because
491a9ba4257Smrg    # one of the two compilations can be disabled.  We should prefer
492a9ba4257Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493a9ba4257Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494a9ba4257Smrg    # the former would cause a distcleancheck panic.
495a9ba4257Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496a9ba4257Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497a9ba4257Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498a9ba4257Smrg    "$@" -Wc,-MD
499a9ba4257Smrg  else
500a9ba4257Smrg    tmpdepfile1=$dir$base.d
501a9ba4257Smrg    tmpdepfile2=$dir$base.d
502a9ba4257Smrg    tmpdepfile3=$dir$base.d
503a9ba4257Smrg    "$@" -MD
504a9ba4257Smrg  fi
505a9ba4257Smrg
506a9ba4257Smrg  stat=$?
507a9ba4257Smrg  if test $stat -ne 0; then
508a9ba4257Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509a9ba4257Smrg    exit $stat
510a9ba4257Smrg  fi
511a9ba4257Smrg
512a9ba4257Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513a9ba4257Smrg  do
514a9ba4257Smrg    test -f "$tmpdepfile" && break
515a9ba4257Smrg  done
516a9ba4257Smrg  # Same post-processing that is required for AIX mode.
517a9ba4257Smrg  aix_post_process_depfile
518a9ba4257Smrg  ;;
519fd7d9bd3Smrg
520a85aecdfSmrgmsvc7)
521a85aecdfSmrg  if test "$libtool" = yes; then
522a85aecdfSmrg    showIncludes=-Wc,-showIncludes
523a85aecdfSmrg  else
524a85aecdfSmrg    showIncludes=-showIncludes
525a85aecdfSmrg  fi
526a85aecdfSmrg  "$@" $showIncludes > "$tmpdepfile"
527a85aecdfSmrg  stat=$?
528a85aecdfSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
529a9ba4257Smrg  if test $stat -ne 0; then
530a85aecdfSmrg    rm -f "$tmpdepfile"
531a85aecdfSmrg    exit $stat
532a85aecdfSmrg  fi
533a85aecdfSmrg  rm -f "$depfile"
534a85aecdfSmrg  echo "$object : \\" > "$depfile"
535a85aecdfSmrg  # The first sed program below extracts the file names and escapes
536a85aecdfSmrg  # backslashes for cygpath.  The second sed program outputs the file
537a85aecdfSmrg  # name when reading, but also accumulates all include files in the
538a85aecdfSmrg  # hold buffer in order to output them again at the end.  This only
539a85aecdfSmrg  # works with sed implementations that can handle large buffers.
540a85aecdfSmrg  sed < "$tmpdepfile" -n '
541a85aecdfSmrg/^Note: including file:  *\(.*\)/ {
542a85aecdfSmrg  s//\1/
543a85aecdfSmrg  s/\\/\\\\/g
544a85aecdfSmrg  p
545a85aecdfSmrg}' | $cygpath_u | sort -u | sed -n '
546a85aecdfSmrgs/ /\\ /g
547a9ba4257Smrgs/\(.*\)/'"$tab"'\1 \\/p
548a85aecdfSmrgs/.\(.*\) \\/\1:/
549a85aecdfSmrgH
550a85aecdfSmrg$ {
551a9ba4257Smrg  s/.*/'"$tab"'/
552a85aecdfSmrg  G
553a85aecdfSmrg  p
554a85aecdfSmrg}' >> "$depfile"
555a9ba4257Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556a85aecdfSmrg  rm -f "$tmpdepfile"
557a85aecdfSmrg  ;;
558a85aecdfSmrg
559a85aecdfSmrgmsvc7msys)
560a85aecdfSmrg  # This case exists only to let depend.m4 do its work.  It works by
561a85aecdfSmrg  # looking at the text of this script.  This case will never be run,
562a85aecdfSmrg  # since it is checked for above.
563a85aecdfSmrg  exit 1
564a85aecdfSmrg  ;;
565a85aecdfSmrg
566fd7d9bd3Smrg#nosideeffect)
567fd7d9bd3Smrg  # This comment above is used by automake to tell side-effect
568fd7d9bd3Smrg  # dependency tracking mechanisms from slower ones.
569fd7d9bd3Smrg
570fd7d9bd3Smrgdashmstdout)
571fd7d9bd3Smrg  # Important note: in order to support this mode, a compiler *must*
572fd7d9bd3Smrg  # always write the preprocessed file to stdout, regardless of -o.
573fd7d9bd3Smrg  "$@" || exit $?
574fd7d9bd3Smrg
575fd7d9bd3Smrg  # Remove the call to Libtool.
576fd7d9bd3Smrg  if test "$libtool" = yes; then
577350952b9Smrg    while test "X$1" != 'X--mode=compile'; do
578fd7d9bd3Smrg      shift
579fd7d9bd3Smrg    done
580fd7d9bd3Smrg    shift
581fd7d9bd3Smrg  fi
582fd7d9bd3Smrg
583a9ba4257Smrg  # Remove '-o $object'.
584fd7d9bd3Smrg  IFS=" "
585fd7d9bd3Smrg  for arg
586fd7d9bd3Smrg  do
587fd7d9bd3Smrg    case $arg in
588fd7d9bd3Smrg    -o)
589fd7d9bd3Smrg      shift
590fd7d9bd3Smrg      ;;
591fd7d9bd3Smrg    $object)
592fd7d9bd3Smrg      shift
593fd7d9bd3Smrg      ;;
594fd7d9bd3Smrg    *)
595fd7d9bd3Smrg      set fnord "$@" "$arg"
596fd7d9bd3Smrg      shift # fnord
597fd7d9bd3Smrg      shift # $arg
598fd7d9bd3Smrg      ;;
599fd7d9bd3Smrg    esac
600fd7d9bd3Smrg  done
601fd7d9bd3Smrg
602fd7d9bd3Smrg  test -z "$dashmflag" && dashmflag=-M
603a9ba4257Smrg  # Require at least two characters before searching for ':'
604fd7d9bd3Smrg  # in the target name.  This is to cope with DOS-style filenames:
605a9ba4257Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606fd7d9bd3Smrg  "$@" $dashmflag |
607a9ba4257Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608fd7d9bd3Smrg  rm -f "$depfile"
609fd7d9bd3Smrg  cat < "$tmpdepfile" > "$depfile"
610a9ba4257Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611a9ba4257Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612a9ba4257Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613a9ba4257Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614a9ba4257Smrg    | sed -e 's/$/ :/' >> "$depfile"
615fd7d9bd3Smrg  rm -f "$tmpdepfile"
616fd7d9bd3Smrg  ;;
617fd7d9bd3Smrg
618fd7d9bd3SmrgdashXmstdout)
619fd7d9bd3Smrg  # This case only exists to satisfy depend.m4.  It is never actually
620fd7d9bd3Smrg  # run, as this mode is specially recognized in the preamble.
621fd7d9bd3Smrg  exit 1
622fd7d9bd3Smrg  ;;
623fd7d9bd3Smrg
624fd7d9bd3Smrgmakedepend)
625fd7d9bd3Smrg  "$@" || exit $?
626fd7d9bd3Smrg  # Remove any Libtool call
627fd7d9bd3Smrg  if test "$libtool" = yes; then
628350952b9Smrg    while test "X$1" != 'X--mode=compile'; do
629fd7d9bd3Smrg      shift
630fd7d9bd3Smrg    done
631fd7d9bd3Smrg    shift
632fd7d9bd3Smrg  fi
633fd7d9bd3Smrg  # X makedepend
634fd7d9bd3Smrg  shift
635350952b9Smrg  cleared=no eat=no
636350952b9Smrg  for arg
637350952b9Smrg  do
638fd7d9bd3Smrg    case $cleared in
639fd7d9bd3Smrg    no)
640fd7d9bd3Smrg      set ""; shift
641fd7d9bd3Smrg      cleared=yes ;;
642fd7d9bd3Smrg    esac
643350952b9Smrg    if test $eat = yes; then
644350952b9Smrg      eat=no
645350952b9Smrg      continue
646350952b9Smrg    fi
647fd7d9bd3Smrg    case "$arg" in
648fd7d9bd3Smrg    -D*|-I*)
649fd7d9bd3Smrg      set fnord "$@" "$arg"; shift ;;
650fd7d9bd3Smrg    # Strip any option that makedepend may not understand.  Remove
651fd7d9bd3Smrg    # the object too, otherwise makedepend will parse it as a source file.
652350952b9Smrg    -arch)
653350952b9Smrg      eat=yes ;;
654fd7d9bd3Smrg    -*|$object)
655fd7d9bd3Smrg      ;;
656fd7d9bd3Smrg    *)
657fd7d9bd3Smrg      set fnord "$@" "$arg"; shift ;;
658fd7d9bd3Smrg    esac
659fd7d9bd3Smrg  done
660350952b9Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661fd7d9bd3Smrg  touch "$tmpdepfile"
662fd7d9bd3Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663fd7d9bd3Smrg  rm -f "$depfile"
664a85aecdfSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665a85aecdfSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666a85aecdfSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667a9ba4257Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668a9ba4257Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669a9ba4257Smrg  sed '1,2d' "$tmpdepfile" \
670a9ba4257Smrg    | tr ' ' "$nl" \
671a9ba4257Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672a9ba4257Smrg    | sed -e 's/$/ :/' >> "$depfile"
673fd7d9bd3Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674fd7d9bd3Smrg  ;;
675fd7d9bd3Smrg
676fd7d9bd3Smrgcpp)
677fd7d9bd3Smrg  # Important note: in order to support this mode, a compiler *must*
678fd7d9bd3Smrg  # always write the preprocessed file to stdout.
679fd7d9bd3Smrg  "$@" || exit $?
680fd7d9bd3Smrg
681fd7d9bd3Smrg  # Remove the call to Libtool.
682fd7d9bd3Smrg  if test "$libtool" = yes; then
683350952b9Smrg    while test "X$1" != 'X--mode=compile'; do
684fd7d9bd3Smrg      shift
685fd7d9bd3Smrg    done
686fd7d9bd3Smrg    shift
687fd7d9bd3Smrg  fi
688fd7d9bd3Smrg
689a9ba4257Smrg  # Remove '-o $object'.
690fd7d9bd3Smrg  IFS=" "
691fd7d9bd3Smrg  for arg
692fd7d9bd3Smrg  do
693fd7d9bd3Smrg    case $arg in
694fd7d9bd3Smrg    -o)
695fd7d9bd3Smrg      shift
696fd7d9bd3Smrg      ;;
697fd7d9bd3Smrg    $object)
698fd7d9bd3Smrg      shift
699fd7d9bd3Smrg      ;;
700fd7d9bd3Smrg    *)
701fd7d9bd3Smrg      set fnord "$@" "$arg"
702fd7d9bd3Smrg      shift # fnord
703fd7d9bd3Smrg      shift # $arg
704fd7d9bd3Smrg      ;;
705fd7d9bd3Smrg    esac
706fd7d9bd3Smrg  done
707fd7d9bd3Smrg
708a9ba4257Smrg  "$@" -E \
709a9ba4257Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710a9ba4257Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711a9ba4257Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712fd7d9bd3Smrg  rm -f "$depfile"
713fd7d9bd3Smrg  echo "$object : \\" > "$depfile"
714fd7d9bd3Smrg  cat < "$tmpdepfile" >> "$depfile"
715fd7d9bd3Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716fd7d9bd3Smrg  rm -f "$tmpdepfile"
717fd7d9bd3Smrg  ;;
718fd7d9bd3Smrg
719fd7d9bd3Smrgmsvisualcpp)
720fd7d9bd3Smrg  # Important note: in order to support this mode, a compiler *must*
721350952b9Smrg  # always write the preprocessed file to stdout.
722fd7d9bd3Smrg  "$@" || exit $?
723350952b9Smrg
724350952b9Smrg  # Remove the call to Libtool.
725350952b9Smrg  if test "$libtool" = yes; then
726350952b9Smrg    while test "X$1" != 'X--mode=compile'; do
727350952b9Smrg      shift
728350952b9Smrg    done
729350952b9Smrg    shift
730350952b9Smrg  fi
731350952b9Smrg
732fd7d9bd3Smrg  IFS=" "
733fd7d9bd3Smrg  for arg
734fd7d9bd3Smrg  do
735fd7d9bd3Smrg    case "$arg" in
736350952b9Smrg    -o)
737350952b9Smrg      shift
738350952b9Smrg      ;;
739350952b9Smrg    $object)
740350952b9Smrg      shift
741350952b9Smrg      ;;
742fd7d9bd3Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743a9ba4257Smrg        set fnord "$@"
744a9ba4257Smrg        shift
745a9ba4257Smrg        shift
746a9ba4257Smrg        ;;
747fd7d9bd3Smrg    *)
748a9ba4257Smrg        set fnord "$@" "$arg"
749a9ba4257Smrg        shift
750a9ba4257Smrg        shift
751a9ba4257Smrg        ;;
752fd7d9bd3Smrg    esac
753fd7d9bd3Smrg  done
754350952b9Smrg  "$@" -E 2>/dev/null |
755350952b9Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756fd7d9bd3Smrg  rm -f "$depfile"
757fd7d9bd3Smrg  echo "$object : \\" > "$depfile"
758a9ba4257Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759a9ba4257Smrg  echo "$tab" >> "$depfile"
760350952b9Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761fd7d9bd3Smrg  rm -f "$tmpdepfile"
762fd7d9bd3Smrg  ;;
763fd7d9bd3Smrg
764350952b9Smrgmsvcmsys)
765350952b9Smrg  # This case exists only to let depend.m4 do its work.  It works by
766350952b9Smrg  # looking at the text of this script.  This case will never be run,
767350952b9Smrg  # since it is checked for above.
768350952b9Smrg  exit 1
769350952b9Smrg  ;;
770350952b9Smrg
771fd7d9bd3Smrgnone)
772fd7d9bd3Smrg  exec "$@"
773fd7d9bd3Smrg  ;;
774fd7d9bd3Smrg
775fd7d9bd3Smrg*)
776fd7d9bd3Smrg  echo "Unknown depmode $depmode" 1>&2
777fd7d9bd3Smrg  exit 1
778fd7d9bd3Smrg  ;;
779fd7d9bd3Smrgesac
780fd7d9bd3Smrg
781fd7d9bd3Smrgexit 0
782350952b9Smrg
783350952b9Smrg# Local Variables:
784350952b9Smrg# mode: shell-script
785350952b9Smrg# sh-indentation: 2
786e53c48bfSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
787350952b9Smrg# time-stamp-start: "scriptversion="
788350952b9Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789e53c48bfSmrg# time-stamp-time-zone: "UTC0"
790350952b9Smrg# time-stamp-end: "; # UTC"
791350952b9Smrg# End:
792