depcomp revision aef24d58
1c9e2be55Smrg#! /bin/sh
2c9e2be55Smrg# depcomp - compile a program generating dependencies as side-effects
3e2264b6dSmrg
4aef24d58Smrgscriptversion=2013-05-30.07; # UTC
5e2264b6dSmrg
6aef24d58Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc.
7c9e2be55Smrg
8c9e2be55Smrg# This program is free software; you can redistribute it and/or modify
9c9e2be55Smrg# it under the terms of the GNU General Public License as published by
10c9e2be55Smrg# the Free Software Foundation; either version 2, or (at your option)
11c9e2be55Smrg# any later version.
12c9e2be55Smrg
13c9e2be55Smrg# This program is distributed in the hope that it will be useful,
14c9e2be55Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15c9e2be55Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c9e2be55Smrg# GNU General Public License for more details.
17c9e2be55Smrg
18c9e2be55Smrg# You should have received a copy of the GNU General Public License
19e2264b6dSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20c9e2be55Smrg
21c9e2be55Smrg# As a special exception to the GNU General Public License, if you
22c9e2be55Smrg# distribute this file as part of a program that contains a
23c9e2be55Smrg# configuration script generated by Autoconf, you may include it under
24c9e2be55Smrg# the same distribution terms that you use for the rest of that program.
25c9e2be55Smrg
26c9e2be55Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27c9e2be55Smrg
28e2264b6dSmrgcase $1 in
29e2264b6dSmrg  '')
30aef24d58Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31aef24d58Smrg    exit 1;
32aef24d58Smrg    ;;
33e2264b6dSmrg  -h | --h*)
34e2264b6dSmrg    cat <<\EOF
35e2264b6dSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36e2264b6dSmrg
37e2264b6dSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38e2264b6dSmrgas side-effects.
39e2264b6dSmrg
40e2264b6dSmrgEnvironment variables:
41e2264b6dSmrg  depmode     Dependency tracking mode.
42aef24d58Smrg  source      Source file read by 'PROGRAMS ARGS'.
43aef24d58Smrg  object      Object file output by 'PROGRAMS ARGS'.
44e2264b6dSmrg  DEPDIR      directory where to store dependencies.
45e2264b6dSmrg  depfile     Dependency file to output.
46aef24d58Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47e2264b6dSmrg  libtool     Whether libtool is used (yes/no).
48e2264b6dSmrg
49e2264b6dSmrgReport bugs to <bug-automake@gnu.org>.
50e2264b6dSmrgEOF
51e2264b6dSmrg    exit $?
52e2264b6dSmrg    ;;
53e2264b6dSmrg  -v | --v*)
54e2264b6dSmrg    echo "depcomp $scriptversion"
55e2264b6dSmrg    exit $?
56e2264b6dSmrg    ;;
57e2264b6dSmrgesac
58e2264b6dSmrg
59aef24d58Smrg# Get the directory component of the given path, and save it in the
60aef24d58Smrg# global variables '$dir'.  Note that this directory component will
61aef24d58Smrg# be either empty or ending with a '/' character.  This is deliberate.
62aef24d58Smrgset_dir_from ()
63aef24d58Smrg{
64aef24d58Smrg  case $1 in
65aef24d58Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66aef24d58Smrg      *) dir=;;
67aef24d58Smrg  esac
68aef24d58Smrg}
69aef24d58Smrg
70aef24d58Smrg# Get the suffix-stripped basename of the given path, and save it the
71aef24d58Smrg# global variable '$base'.
72aef24d58Smrgset_base_from ()
73aef24d58Smrg{
74aef24d58Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75aef24d58Smrg}
76aef24d58Smrg
77aef24d58Smrg# If no dependency file was actually created by the compiler invocation,
78aef24d58Smrg# we still have to create a dummy depfile, to avoid errors with the
79aef24d58Smrg# Makefile "include basename.Plo" scheme.
80aef24d58Smrgmake_dummy_depfile ()
81aef24d58Smrg{
82aef24d58Smrg  echo "#dummy" > "$depfile"
83aef24d58Smrg}
84aef24d58Smrg
85aef24d58Smrg# Factor out some common post-processing of the generated depfile.
86aef24d58Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87aef24d58Smrgaix_post_process_depfile ()
88aef24d58Smrg{
89aef24d58Smrg  # If the compiler actually managed to produce a dependency file,
90aef24d58Smrg  # post-process it.
91aef24d58Smrg  if test -f "$tmpdepfile"; then
92aef24d58Smrg    # Each line is of the form 'foo.o: dependency.h'.
93aef24d58Smrg    # Do two passes, one to just change these to
94aef24d58Smrg    #   $object: dependency.h
95aef24d58Smrg    # and one to simply output
96aef24d58Smrg    #   dependency.h:
97aef24d58Smrg    # which is needed to avoid the deleted-header problem.
98aef24d58Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99aef24d58Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100aef24d58Smrg    } > "$depfile"
101aef24d58Smrg    rm -f "$tmpdepfile"
102aef24d58Smrg  else
103aef24d58Smrg    make_dummy_depfile
104aef24d58Smrg  fi
105aef24d58Smrg}
106aef24d58Smrg
107aef24d58Smrg# A tabulation character.
108aef24d58Smrgtab='	'
109aef24d58Smrg# A newline character.
110aef24d58Smrgnl='
111aef24d58Smrg'
112aef24d58Smrg# Character ranges might be problematic outside the C locale.
113aef24d58Smrg# These definitions help.
114aef24d58Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115aef24d58Smrglower=abcdefghijklmnopqrstuvwxyz
116aef24d58Smrgdigits=0123456789
117aef24d58Smrgalpha=${upper}${lower}
118aef24d58Smrg
119c9e2be55Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120c9e2be55Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121c9e2be55Smrg  exit 1
122c9e2be55Smrgfi
123c9e2be55Smrg
124e2264b6dSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125e2264b6dSmrgdepfile=${depfile-`echo "$object" |
126e2264b6dSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127c9e2be55Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128c9e2be55Smrg
129c9e2be55Smrgrm -f "$tmpdepfile"
130c9e2be55Smrg
131aef24d58Smrg# Avoid interferences from the environment.
132aef24d58Smrggccflag= dashmflag=
133aef24d58Smrg
134c9e2be55Smrg# Some modes work just like other modes, but use different flags.  We
135c9e2be55Smrg# parameterize here, but still list the modes in the big case below,
136c9e2be55Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137c9e2be55Smrg# here, because this file can only contain one case statement.
138c9e2be55Smrgif test "$depmode" = hp; then
139c9e2be55Smrg  # HP compiler uses -M and no extra arg.
140c9e2be55Smrg  gccflag=-M
141c9e2be55Smrg  depmode=gcc
142c9e2be55Smrgfi
143c9e2be55Smrg
144c9e2be55Smrgif test "$depmode" = dashXmstdout; then
145aef24d58Smrg  # This is just like dashmstdout with a different argument.
146aef24d58Smrg  dashmflag=-xM
147aef24d58Smrg  depmode=dashmstdout
148c9e2be55Smrgfi
149c9e2be55Smrg
150e2264b6dSmrgcygpath_u="cygpath -u -f -"
151e2264b6dSmrgif test "$depmode" = msvcmsys; then
152aef24d58Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153aef24d58Smrg  # Just convert the backslash-escaped backslashes to single forward
154aef24d58Smrg  # slashes to satisfy depend.m4
155aef24d58Smrg  cygpath_u='sed s,\\\\,/,g'
156aef24d58Smrg  depmode=msvisualcpp
157aef24d58Smrgfi
158aef24d58Smrg
159aef24d58Smrgif test "$depmode" = msvc7msys; then
160aef24d58Smrg  # This is just like msvc7 but w/o cygpath translation.
161aef24d58Smrg  # Just convert the backslash-escaped backslashes to single forward
162aef24d58Smrg  # slashes to satisfy depend.m4
163aef24d58Smrg  cygpath_u='sed s,\\\\,/,g'
164aef24d58Smrg  depmode=msvc7
165aef24d58Smrgfi
166aef24d58Smrg
167aef24d58Smrgif test "$depmode" = xlc; then
168aef24d58Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169aef24d58Smrg  gccflag=-qmakedep=gcc,-MF
170aef24d58Smrg  depmode=gcc
171e2264b6dSmrgfi
172e2264b6dSmrg
173c9e2be55Smrgcase "$depmode" in
174c9e2be55Smrggcc3)
175c9e2be55Smrg## gcc 3 implements dependency tracking that does exactly what
176c9e2be55Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177c9e2be55Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178e2264b6dSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179e2264b6dSmrg## the command line argument order; so add the flags where they
180e2264b6dSmrg## appear in depend2.am.  Note that the slowdown incurred here
181e2264b6dSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182e2264b6dSmrg  for arg
183e2264b6dSmrg  do
184e2264b6dSmrg    case $arg in
185e2264b6dSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186e2264b6dSmrg    *)  set fnord "$@" "$arg" ;;
187e2264b6dSmrg    esac
188e2264b6dSmrg    shift # fnord
189e2264b6dSmrg    shift # $arg
190e2264b6dSmrg  done
191e2264b6dSmrg  "$@"
192c9e2be55Smrg  stat=$?
193aef24d58Smrg  if test $stat -ne 0; then
194c9e2be55Smrg    rm -f "$tmpdepfile"
195c9e2be55Smrg    exit $stat
196c9e2be55Smrg  fi
197c9e2be55Smrg  mv "$tmpdepfile" "$depfile"
198c9e2be55Smrg  ;;
199c9e2be55Smrg
200c9e2be55Smrggcc)
201aef24d58Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202aef24d58Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203aef24d58Smrg## (see the conditional assignment to $gccflag above).
204c9e2be55Smrg## There are various ways to get dependency output from gcc.  Here's
205c9e2be55Smrg## why we pick this rather obscure method:
206c9e2be55Smrg## - Don't want to use -MD because we'd like the dependencies to end
207c9e2be55Smrg##   up in a subdir.  Having to rename by hand is ugly.
208c9e2be55Smrg##   (We might end up doing this anyway to support other compilers.)
209c9e2be55Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210aef24d58Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211aef24d58Smrg##   supported by the other compilers which use the 'gcc' depmode.
212c9e2be55Smrg## - Using -M directly means running the compiler twice (even worse
213c9e2be55Smrg##   than renaming).
214c9e2be55Smrg  if test -z "$gccflag"; then
215c9e2be55Smrg    gccflag=-MD,
216c9e2be55Smrg  fi
217c9e2be55Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218c9e2be55Smrg  stat=$?
219aef24d58Smrg  if test $stat -ne 0; then
220c9e2be55Smrg    rm -f "$tmpdepfile"
221c9e2be55Smrg    exit $stat
222c9e2be55Smrg  fi
223c9e2be55Smrg  rm -f "$depfile"
224c9e2be55Smrg  echo "$object : \\" > "$depfile"
225aef24d58Smrg  # The second -e expression handles DOS-style file names with drive
226aef24d58Smrg  # letters.
227c9e2be55Smrg  sed -e 's/^[^:]*: / /' \
228c9e2be55Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229aef24d58Smrg## This next piece of magic avoids the "deleted header file" problem.
230c9e2be55Smrg## The problem is that when a header file which appears in a .P file
231c9e2be55Smrg## is deleted, the dependency causes make to die (because there is
232c9e2be55Smrg## typically no way to rebuild the header).  We avoid this by adding
233c9e2be55Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234c9e2be55Smrg## this for us directly.
235aef24d58Smrg## Some versions of gcc put a space before the ':'.  On the theory
236c9e2be55Smrg## that the space means something, we add a space to the output as
237aef24d58Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238aef24d58Smrg## to the object.  Take care to not repeat it in the output.
239c9e2be55Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240c9e2be55Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241aef24d58Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242aef24d58Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243aef24d58Smrg    | sed -e 's/$/ :/' >> "$depfile"
244c9e2be55Smrg  rm -f "$tmpdepfile"
245c9e2be55Smrg  ;;
246c9e2be55Smrg
247c9e2be55Smrghp)
248c9e2be55Smrg  # This case exists only to let depend.m4 do its work.  It works by
249c9e2be55Smrg  # looking at the text of this script.  This case will never be run,
250c9e2be55Smrg  # since it is checked for above.
251c9e2be55Smrg  exit 1
252c9e2be55Smrg  ;;
253c9e2be55Smrg
254c9e2be55Smrgsgi)
255c9e2be55Smrg  if test "$libtool" = yes; then
256c9e2be55Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257c9e2be55Smrg  else
258c9e2be55Smrg    "$@" -MDupdate "$tmpdepfile"
259c9e2be55Smrg  fi
260c9e2be55Smrg  stat=$?
261aef24d58Smrg  if test $stat -ne 0; then
262c9e2be55Smrg    rm -f "$tmpdepfile"
263c9e2be55Smrg    exit $stat
264c9e2be55Smrg  fi
265c9e2be55Smrg  rm -f "$depfile"
266c9e2be55Smrg
267c9e2be55Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268c9e2be55Smrg    echo "$object : \\" > "$depfile"
269c9e2be55Smrg    # Clip off the initial element (the dependent).  Don't try to be
270c9e2be55Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271c9e2be55Smrg    # lines with more than a fixed number of characters (4096 in
272c9e2be55Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273aef24d58Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274c9e2be55Smrg    # dependency line.
275aef24d58Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276aef24d58Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277aef24d58Smrg      | tr "$nl" ' ' >> "$depfile"
278e2264b6dSmrg    echo >> "$depfile"
279c9e2be55Smrg    # The second pass generates a dummy entry for each header file.
280aef24d58Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281aef24d58Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282aef24d58Smrg      >> "$depfile"
283c9e2be55Smrg  else
284aef24d58Smrg    make_dummy_depfile
285c9e2be55Smrg  fi
286c9e2be55Smrg  rm -f "$tmpdepfile"
287c9e2be55Smrg  ;;
288c9e2be55Smrg
289aef24d58Smrgxlc)
290aef24d58Smrg  # This case exists only to let depend.m4 do its work.  It works by
291aef24d58Smrg  # looking at the text of this script.  This case will never be run,
292aef24d58Smrg  # since it is checked for above.
293aef24d58Smrg  exit 1
294aef24d58Smrg  ;;
295aef24d58Smrg
296c9e2be55Smrgaix)
297c9e2be55Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298c9e2be55Smrg  # in a .u file.  In older versions, this file always lives in the
299aef24d58Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300c9e2be55Smrg  # start of each line; $object doesn't have directory information.
301c9e2be55Smrg  # Version 6 uses the directory in both cases.
302aef24d58Smrg  set_dir_from "$object"
303aef24d58Smrg  set_base_from "$object"
304c9e2be55Smrg  if test "$libtool" = yes; then
305e2264b6dSmrg    tmpdepfile1=$dir$base.u
306e2264b6dSmrg    tmpdepfile2=$base.u
307e2264b6dSmrg    tmpdepfile3=$dir.libs/$base.u
308c9e2be55Smrg    "$@" -Wc,-M
309c9e2be55Smrg  else
310e2264b6dSmrg    tmpdepfile1=$dir$base.u
311e2264b6dSmrg    tmpdepfile2=$dir$base.u
312e2264b6dSmrg    tmpdepfile3=$dir$base.u
313c9e2be55Smrg    "$@" -M
314c9e2be55Smrg  fi
315c9e2be55Smrg  stat=$?
316aef24d58Smrg  if test $stat -ne 0; then
317e2264b6dSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318c9e2be55Smrg    exit $stat
319c9e2be55Smrg  fi
320c9e2be55Smrg
321e2264b6dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322e2264b6dSmrg  do
323e2264b6dSmrg    test -f "$tmpdepfile" && break
324e2264b6dSmrg  done
325aef24d58Smrg  aix_post_process_depfile
326aef24d58Smrg  ;;
327aef24d58Smrg
328aef24d58Smrgtcc)
329aef24d58Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330aef24d58Smrg  # FIXME: That version still under development at the moment of writing.
331aef24d58Smrg  #        Make that this statement remains true also for stable, released
332aef24d58Smrg  #        versions.
333aef24d58Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334aef24d58Smrg  # trailing '\', as in:
335aef24d58Smrg  #
336aef24d58Smrg  #   foo.o : \
337aef24d58Smrg  #    foo.c \
338aef24d58Smrg  #    foo.h \
339aef24d58Smrg  #
340aef24d58Smrg  # It will put a trailing '\' even on the last line, and will use leading
341aef24d58Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342aef24d58Smrg  # "Emit spaces for -MD").
343aef24d58Smrg  "$@" -MD -MF "$tmpdepfile"
344aef24d58Smrg  stat=$?
345aef24d58Smrg  if test $stat -ne 0; then
346aef24d58Smrg    rm -f "$tmpdepfile"
347aef24d58Smrg    exit $stat
348c9e2be55Smrg  fi
349aef24d58Smrg  rm -f "$depfile"
350aef24d58Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351aef24d58Smrg  # We have to change lines of the first kind to '$object: \'.
352aef24d58Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353aef24d58Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354aef24d58Smrg  # dummy dependency, to avoid the deleted-header problem.
355aef24d58Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356c9e2be55Smrg  rm -f "$tmpdepfile"
357c9e2be55Smrg  ;;
358c9e2be55Smrg
359aef24d58Smrg## The order of this option in the case statement is important, since the
360aef24d58Smrg## shell code in configure will try each of these formats in the order
361aef24d58Smrg## listed in this file.  A plain '-MD' option would be understood by many
362aef24d58Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363aef24d58Smrgpgcc)
364aef24d58Smrg  # Portland's C compiler understands '-MD'.
365aef24d58Smrg  # Will always output deps to 'file.d' where file is the root name of the
366aef24d58Smrg  # source file under compilation, even if file resides in a subdirectory.
367aef24d58Smrg  # The object file name does not affect the name of the '.d' file.
368aef24d58Smrg  # pgcc 10.2 will output
369c9e2be55Smrg  #    foo.o: sub/foo.c sub/foo.h
370aef24d58Smrg  # and will wrap long lines using '\' :
371c9e2be55Smrg  #    foo.o: sub/foo.c ... \
372c9e2be55Smrg  #     sub/foo.h ... \
373c9e2be55Smrg  #     ...
374aef24d58Smrg  set_dir_from "$object"
375aef24d58Smrg  # Use the source, not the object, to determine the base name, since
376aef24d58Smrg  # that's sadly what pgcc will do too.
377aef24d58Smrg  set_base_from "$source"
378aef24d58Smrg  tmpdepfile=$base.d
379aef24d58Smrg
380aef24d58Smrg  # For projects that build the same source file twice into different object
381aef24d58Smrg  # files, the pgcc approach of using the *source* file root name can cause
382aef24d58Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383aef24d58Smrg  # the same $tmpdepfile.
384aef24d58Smrg  lockdir=$base.d-lock
385aef24d58Smrg  trap "
386aef24d58Smrg    echo '$0: caught signal, cleaning up...' >&2
387aef24d58Smrg    rmdir '$lockdir'
388aef24d58Smrg    exit 1
389aef24d58Smrg  " 1 2 13 15
390aef24d58Smrg  numtries=100
391aef24d58Smrg  i=$numtries
392aef24d58Smrg  while test $i -gt 0; do
393aef24d58Smrg    # mkdir is a portable test-and-set.
394aef24d58Smrg    if mkdir "$lockdir" 2>/dev/null; then
395aef24d58Smrg      # This process acquired the lock.
396aef24d58Smrg      "$@" -MD
397aef24d58Smrg      stat=$?
398aef24d58Smrg      # Release the lock.
399aef24d58Smrg      rmdir "$lockdir"
400aef24d58Smrg      break
401aef24d58Smrg    else
402aef24d58Smrg      # If the lock is being held by a different process, wait
403aef24d58Smrg      # until the winning process is done or we timeout.
404aef24d58Smrg      while test -d "$lockdir" && test $i -gt 0; do
405aef24d58Smrg        sleep 1
406aef24d58Smrg        i=`expr $i - 1`
407aef24d58Smrg      done
408aef24d58Smrg    fi
409aef24d58Smrg    i=`expr $i - 1`
410aef24d58Smrg  done
411aef24d58Smrg  trap - 1 2 13 15
412aef24d58Smrg  if test $i -le 0; then
413aef24d58Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414aef24d58Smrg    echo "$0: check lockdir '$lockdir'" >&2
415aef24d58Smrg    exit 1
416aef24d58Smrg  fi
417c9e2be55Smrg
418aef24d58Smrg  if test $stat -ne 0; then
419c9e2be55Smrg    rm -f "$tmpdepfile"
420c9e2be55Smrg    exit $stat
421c9e2be55Smrg  fi
422c9e2be55Smrg  rm -f "$depfile"
423c9e2be55Smrg  # Each line is of the form `foo.o: dependent.h',
424c9e2be55Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425c9e2be55Smrg  # Do two passes, one to just change these to
426c9e2be55Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427c9e2be55Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428c9e2be55Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429c9e2be55Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430aef24d58Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431aef24d58Smrg    | sed -e 's/$/ :/' >> "$depfile"
432c9e2be55Smrg  rm -f "$tmpdepfile"
433c9e2be55Smrg  ;;
434c9e2be55Smrg
435e2264b6dSmrghp2)
436e2264b6dSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437e2264b6dSmrg  # compilers, which have integrated preprocessors.  The correct option
438e2264b6dSmrg  # to use with these is +Maked; it writes dependencies to a file named
439e2264b6dSmrg  # 'foo.d', which lands next to the object file, wherever that
440e2264b6dSmrg  # happens to be.
441e2264b6dSmrg  # Much of this is similar to the tru64 case; see comments there.
442aef24d58Smrg  set_dir_from  "$object"
443aef24d58Smrg  set_base_from "$object"
444e2264b6dSmrg  if test "$libtool" = yes; then
445e2264b6dSmrg    tmpdepfile1=$dir$base.d
446e2264b6dSmrg    tmpdepfile2=$dir.libs/$base.d
447e2264b6dSmrg    "$@" -Wc,+Maked
448e2264b6dSmrg  else
449e2264b6dSmrg    tmpdepfile1=$dir$base.d
450e2264b6dSmrg    tmpdepfile2=$dir$base.d
451e2264b6dSmrg    "$@" +Maked
452e2264b6dSmrg  fi
453e2264b6dSmrg  stat=$?
454aef24d58Smrg  if test $stat -ne 0; then
455e2264b6dSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456e2264b6dSmrg     exit $stat
457e2264b6dSmrg  fi
458e2264b6dSmrg
459e2264b6dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460e2264b6dSmrg  do
461e2264b6dSmrg    test -f "$tmpdepfile" && break
462e2264b6dSmrg  done
463e2264b6dSmrg  if test -f "$tmpdepfile"; then
464aef24d58Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465aef24d58Smrg    # Add 'dependent.h:' lines.
466e2264b6dSmrg    sed -ne '2,${
467aef24d58Smrg               s/^ *//
468aef24d58Smrg               s/ \\*$//
469aef24d58Smrg               s/$/:/
470aef24d58Smrg               p
471aef24d58Smrg             }' "$tmpdepfile" >> "$depfile"
472e2264b6dSmrg  else
473aef24d58Smrg    make_dummy_depfile
474e2264b6dSmrg  fi
475e2264b6dSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476e2264b6dSmrg  ;;
477e2264b6dSmrg
478c9e2be55Smrgtru64)
479aef24d58Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480aef24d58Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481aef24d58Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482aef24d58Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483aef24d58Smrg  # Subdirectories are respected.
484aef24d58Smrg  set_dir_from  "$object"
485aef24d58Smrg  set_base_from "$object"
486aef24d58Smrg
487aef24d58Smrg  if test "$libtool" = yes; then
488aef24d58Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489aef24d58Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490aef24d58Smrg    # in $dir$base.o.d.  We have to check for both files, because
491aef24d58Smrg    # one of the two compilations can be disabled.  We should prefer
492aef24d58Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493aef24d58Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494aef24d58Smrg    # the former would cause a distcleancheck panic.
495aef24d58Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496aef24d58Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497aef24d58Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498aef24d58Smrg    "$@" -Wc,-MD
499aef24d58Smrg  else
500aef24d58Smrg    tmpdepfile1=$dir$base.d
501aef24d58Smrg    tmpdepfile2=$dir$base.d
502aef24d58Smrg    tmpdepfile3=$dir$base.d
503aef24d58Smrg    "$@" -MD
504aef24d58Smrg  fi
505aef24d58Smrg
506aef24d58Smrg  stat=$?
507aef24d58Smrg  if test $stat -ne 0; then
508aef24d58Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509aef24d58Smrg    exit $stat
510aef24d58Smrg  fi
511aef24d58Smrg
512aef24d58Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513aef24d58Smrg  do
514aef24d58Smrg    test -f "$tmpdepfile" && break
515aef24d58Smrg  done
516aef24d58Smrg  # Same post-processing that is required for AIX mode.
517aef24d58Smrg  aix_post_process_depfile
518aef24d58Smrg  ;;
519aef24d58Smrg
520aef24d58Smrgmsvc7)
521aef24d58Smrg  if test "$libtool" = yes; then
522aef24d58Smrg    showIncludes=-Wc,-showIncludes
523aef24d58Smrg  else
524aef24d58Smrg    showIncludes=-showIncludes
525aef24d58Smrg  fi
526aef24d58Smrg  "$@" $showIncludes > "$tmpdepfile"
527aef24d58Smrg  stat=$?
528aef24d58Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529aef24d58Smrg  if test $stat -ne 0; then
530aef24d58Smrg    rm -f "$tmpdepfile"
531aef24d58Smrg    exit $stat
532aef24d58Smrg  fi
533aef24d58Smrg  rm -f "$depfile"
534aef24d58Smrg  echo "$object : \\" > "$depfile"
535aef24d58Smrg  # The first sed program below extracts the file names and escapes
536aef24d58Smrg  # backslashes for cygpath.  The second sed program outputs the file
537aef24d58Smrg  # name when reading, but also accumulates all include files in the
538aef24d58Smrg  # hold buffer in order to output them again at the end.  This only
539aef24d58Smrg  # works with sed implementations that can handle large buffers.
540aef24d58Smrg  sed < "$tmpdepfile" -n '
541aef24d58Smrg/^Note: including file:  *\(.*\)/ {
542aef24d58Smrg  s//\1/
543aef24d58Smrg  s/\\/\\\\/g
544aef24d58Smrg  p
545aef24d58Smrg}' | $cygpath_u | sort -u | sed -n '
546aef24d58Smrgs/ /\\ /g
547aef24d58Smrgs/\(.*\)/'"$tab"'\1 \\/p
548aef24d58Smrgs/.\(.*\) \\/\1:/
549aef24d58SmrgH
550aef24d58Smrg$ {
551aef24d58Smrg  s/.*/'"$tab"'/
552aef24d58Smrg  G
553aef24d58Smrg  p
554aef24d58Smrg}' >> "$depfile"
555aef24d58Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556aef24d58Smrg  rm -f "$tmpdepfile"
557aef24d58Smrg  ;;
558aef24d58Smrg
559aef24d58Smrgmsvc7msys)
560aef24d58Smrg  # This case exists only to let depend.m4 do its work.  It works by
561aef24d58Smrg  # looking at the text of this script.  This case will never be run,
562aef24d58Smrg  # since it is checked for above.
563aef24d58Smrg  exit 1
564aef24d58Smrg  ;;
565c9e2be55Smrg
566c9e2be55Smrg#nosideeffect)
567c9e2be55Smrg  # This comment above is used by automake to tell side-effect
568c9e2be55Smrg  # dependency tracking mechanisms from slower ones.
569c9e2be55Smrg
570c9e2be55Smrgdashmstdout)
571c9e2be55Smrg  # Important note: in order to support this mode, a compiler *must*
572c9e2be55Smrg  # always write the preprocessed file to stdout, regardless of -o.
573c9e2be55Smrg  "$@" || exit $?
574c9e2be55Smrg
575c9e2be55Smrg  # Remove the call to Libtool.
576c9e2be55Smrg  if test "$libtool" = yes; then
577e2264b6dSmrg    while test "X$1" != 'X--mode=compile'; do
578c9e2be55Smrg      shift
579c9e2be55Smrg    done
580c9e2be55Smrg    shift
581c9e2be55Smrg  fi
582c9e2be55Smrg
583aef24d58Smrg  # Remove '-o $object'.
584c9e2be55Smrg  IFS=" "
585c9e2be55Smrg  for arg
586c9e2be55Smrg  do
587c9e2be55Smrg    case $arg in
588c9e2be55Smrg    -o)
589c9e2be55Smrg      shift
590c9e2be55Smrg      ;;
591c9e2be55Smrg    $object)
592c9e2be55Smrg      shift
593c9e2be55Smrg      ;;
594c9e2be55Smrg    *)
595c9e2be55Smrg      set fnord "$@" "$arg"
596c9e2be55Smrg      shift # fnord
597c9e2be55Smrg      shift # $arg
598c9e2be55Smrg      ;;
599c9e2be55Smrg    esac
600c9e2be55Smrg  done
601c9e2be55Smrg
602c9e2be55Smrg  test -z "$dashmflag" && dashmflag=-M
603aef24d58Smrg  # Require at least two characters before searching for ':'
604c9e2be55Smrg  # in the target name.  This is to cope with DOS-style filenames:
605aef24d58Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606c9e2be55Smrg  "$@" $dashmflag |
607aef24d58Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608c9e2be55Smrg  rm -f "$depfile"
609c9e2be55Smrg  cat < "$tmpdepfile" > "$depfile"
610aef24d58Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611aef24d58Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612aef24d58Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613aef24d58Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614aef24d58Smrg    | sed -e 's/$/ :/' >> "$depfile"
615c9e2be55Smrg  rm -f "$tmpdepfile"
616c9e2be55Smrg  ;;
617c9e2be55Smrg
618c9e2be55SmrgdashXmstdout)
619c9e2be55Smrg  # This case only exists to satisfy depend.m4.  It is never actually
620c9e2be55Smrg  # run, as this mode is specially recognized in the preamble.
621c9e2be55Smrg  exit 1
622c9e2be55Smrg  ;;
623c9e2be55Smrg
624c9e2be55Smrgmakedepend)
625c9e2be55Smrg  "$@" || exit $?
626c9e2be55Smrg  # Remove any Libtool call
627c9e2be55Smrg  if test "$libtool" = yes; then
628e2264b6dSmrg    while test "X$1" != 'X--mode=compile'; do
629c9e2be55Smrg      shift
630c9e2be55Smrg    done
631c9e2be55Smrg    shift
632c9e2be55Smrg  fi
633c9e2be55Smrg  # X makedepend
634c9e2be55Smrg  shift
635e2264b6dSmrg  cleared=no eat=no
636e2264b6dSmrg  for arg
637e2264b6dSmrg  do
638c9e2be55Smrg    case $cleared in
639c9e2be55Smrg    no)
640c9e2be55Smrg      set ""; shift
641c9e2be55Smrg      cleared=yes ;;
642c9e2be55Smrg    esac
643e2264b6dSmrg    if test $eat = yes; then
644e2264b6dSmrg      eat=no
645e2264b6dSmrg      continue
646e2264b6dSmrg    fi
647c9e2be55Smrg    case "$arg" in
648c9e2be55Smrg    -D*|-I*)
649c9e2be55Smrg      set fnord "$@" "$arg"; shift ;;
650c9e2be55Smrg    # Strip any option that makedepend may not understand.  Remove
651c9e2be55Smrg    # the object too, otherwise makedepend will parse it as a source file.
652e2264b6dSmrg    -arch)
653e2264b6dSmrg      eat=yes ;;
654c9e2be55Smrg    -*|$object)
655c9e2be55Smrg      ;;
656c9e2be55Smrg    *)
657c9e2be55Smrg      set fnord "$@" "$arg"; shift ;;
658c9e2be55Smrg    esac
659c9e2be55Smrg  done
660e2264b6dSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661c9e2be55Smrg  touch "$tmpdepfile"
662c9e2be55Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663c9e2be55Smrg  rm -f "$depfile"
664aef24d58Smrg  # makedepend may prepend the VPATH from the source file name to the object.
665aef24d58Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666aef24d58Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667aef24d58Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668aef24d58Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669aef24d58Smrg  sed '1,2d' "$tmpdepfile" \
670aef24d58Smrg    | tr ' ' "$nl" \
671aef24d58Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672aef24d58Smrg    | sed -e 's/$/ :/' >> "$depfile"
673c9e2be55Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674c9e2be55Smrg  ;;
675c9e2be55Smrg
676c9e2be55Smrgcpp)
677c9e2be55Smrg  # Important note: in order to support this mode, a compiler *must*
678c9e2be55Smrg  # always write the preprocessed file to stdout.
679c9e2be55Smrg  "$@" || exit $?
680c9e2be55Smrg
681c9e2be55Smrg  # Remove the call to Libtool.
682c9e2be55Smrg  if test "$libtool" = yes; then
683e2264b6dSmrg    while test "X$1" != 'X--mode=compile'; do
684c9e2be55Smrg      shift
685c9e2be55Smrg    done
686c9e2be55Smrg    shift
687c9e2be55Smrg  fi
688c9e2be55Smrg
689aef24d58Smrg  # Remove '-o $object'.
690c9e2be55Smrg  IFS=" "
691c9e2be55Smrg  for arg
692c9e2be55Smrg  do
693c9e2be55Smrg    case $arg in
694c9e2be55Smrg    -o)
695c9e2be55Smrg      shift
696c9e2be55Smrg      ;;
697c9e2be55Smrg    $object)
698c9e2be55Smrg      shift
699c9e2be55Smrg      ;;
700c9e2be55Smrg    *)
701c9e2be55Smrg      set fnord "$@" "$arg"
702c9e2be55Smrg      shift # fnord
703c9e2be55Smrg      shift # $arg
704c9e2be55Smrg      ;;
705c9e2be55Smrg    esac
706c9e2be55Smrg  done
707c9e2be55Smrg
708aef24d58Smrg  "$@" -E \
709aef24d58Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710aef24d58Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711aef24d58Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712c9e2be55Smrg  rm -f "$depfile"
713c9e2be55Smrg  echo "$object : \\" > "$depfile"
714c9e2be55Smrg  cat < "$tmpdepfile" >> "$depfile"
715c9e2be55Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716c9e2be55Smrg  rm -f "$tmpdepfile"
717c9e2be55Smrg  ;;
718c9e2be55Smrg
719c9e2be55Smrgmsvisualcpp)
720c9e2be55Smrg  # Important note: in order to support this mode, a compiler *must*
721e2264b6dSmrg  # always write the preprocessed file to stdout.
722c9e2be55Smrg  "$@" || exit $?
723e2264b6dSmrg
724e2264b6dSmrg  # Remove the call to Libtool.
725e2264b6dSmrg  if test "$libtool" = yes; then
726e2264b6dSmrg    while test "X$1" != 'X--mode=compile'; do
727e2264b6dSmrg      shift
728e2264b6dSmrg    done
729e2264b6dSmrg    shift
730e2264b6dSmrg  fi
731e2264b6dSmrg
732c9e2be55Smrg  IFS=" "
733c9e2be55Smrg  for arg
734c9e2be55Smrg  do
735c9e2be55Smrg    case "$arg" in
736e2264b6dSmrg    -o)
737e2264b6dSmrg      shift
738e2264b6dSmrg      ;;
739e2264b6dSmrg    $object)
740e2264b6dSmrg      shift
741e2264b6dSmrg      ;;
742c9e2be55Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743aef24d58Smrg        set fnord "$@"
744aef24d58Smrg        shift
745aef24d58Smrg        shift
746aef24d58Smrg        ;;
747c9e2be55Smrg    *)
748aef24d58Smrg        set fnord "$@" "$arg"
749aef24d58Smrg        shift
750aef24d58Smrg        shift
751aef24d58Smrg        ;;
752c9e2be55Smrg    esac
753c9e2be55Smrg  done
754e2264b6dSmrg  "$@" -E 2>/dev/null |
755e2264b6dSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756c9e2be55Smrg  rm -f "$depfile"
757c9e2be55Smrg  echo "$object : \\" > "$depfile"
758aef24d58Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759aef24d58Smrg  echo "$tab" >> "$depfile"
760e2264b6dSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761c9e2be55Smrg  rm -f "$tmpdepfile"
762c9e2be55Smrg  ;;
763c9e2be55Smrg
764e2264b6dSmrgmsvcmsys)
765e2264b6dSmrg  # This case exists only to let depend.m4 do its work.  It works by
766e2264b6dSmrg  # looking at the text of this script.  This case will never be run,
767e2264b6dSmrg  # since it is checked for above.
768e2264b6dSmrg  exit 1
769e2264b6dSmrg  ;;
770e2264b6dSmrg
771c9e2be55Smrgnone)
772c9e2be55Smrg  exec "$@"
773c9e2be55Smrg  ;;
774c9e2be55Smrg
775c9e2be55Smrg*)
776c9e2be55Smrg  echo "Unknown depmode $depmode" 1>&2
777c9e2be55Smrg  exit 1
778c9e2be55Smrg  ;;
779c9e2be55Smrgesac
780c9e2be55Smrg
781c9e2be55Smrgexit 0
782e2264b6dSmrg
783e2264b6dSmrg# Local Variables:
784e2264b6dSmrg# mode: shell-script
785e2264b6dSmrg# sh-indentation: 2
786e2264b6dSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
787e2264b6dSmrg# time-stamp-start: "scriptversion="
788e2264b6dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789e2264b6dSmrg# time-stamp-time-zone: "UTC"
790e2264b6dSmrg# time-stamp-end: "; # UTC"
791e2264b6dSmrg# End:
792