1428d7b3dSmrg#! /bin/sh
2428d7b3dSmrg# depcomp - compile a program generating dependencies as side-effects
3428d7b3dSmrg
4428d7b3dSmrgscriptversion=2013-05-30.07; # UTC
5428d7b3dSmrg
6428d7b3dSmrg# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7428d7b3dSmrg
8428d7b3dSmrg# This program is free software; you can redistribute it and/or modify
9428d7b3dSmrg# it under the terms of the GNU General Public License as published by
10428d7b3dSmrg# the Free Software Foundation; either version 2, or (at your option)
11428d7b3dSmrg# any later version.
12428d7b3dSmrg
13428d7b3dSmrg# This program is distributed in the hope that it will be useful,
14428d7b3dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15428d7b3dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16428d7b3dSmrg# GNU General Public License for more details.
17428d7b3dSmrg
18428d7b3dSmrg# You should have received a copy of the GNU General Public License
19428d7b3dSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20428d7b3dSmrg
21428d7b3dSmrg# As a special exception to the GNU General Public License, if you
22428d7b3dSmrg# distribute this file as part of a program that contains a
23428d7b3dSmrg# configuration script generated by Autoconf, you may include it under
24428d7b3dSmrg# the same distribution terms that you use for the rest of that program.
25428d7b3dSmrg
26428d7b3dSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27428d7b3dSmrg
28428d7b3dSmrgcase $1 in
29428d7b3dSmrg  '')
30428d7b3dSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31428d7b3dSmrg    exit 1;
32428d7b3dSmrg    ;;
33428d7b3dSmrg  -h | --h*)
34428d7b3dSmrg    cat <<\EOF
35428d7b3dSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36428d7b3dSmrg
37428d7b3dSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38428d7b3dSmrgas side-effects.
39428d7b3dSmrg
40428d7b3dSmrgEnvironment variables:
41428d7b3dSmrg  depmode     Dependency tracking mode.
42428d7b3dSmrg  source      Source file read by 'PROGRAMS ARGS'.
43428d7b3dSmrg  object      Object file output by 'PROGRAMS ARGS'.
44428d7b3dSmrg  DEPDIR      directory where to store dependencies.
45428d7b3dSmrg  depfile     Dependency file to output.
46428d7b3dSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
47428d7b3dSmrg  libtool     Whether libtool is used (yes/no).
48428d7b3dSmrg
49428d7b3dSmrgReport bugs to <bug-automake@gnu.org>.
50428d7b3dSmrgEOF
51428d7b3dSmrg    exit $?
52428d7b3dSmrg    ;;
53428d7b3dSmrg  -v | --v*)
54428d7b3dSmrg    echo "depcomp $scriptversion"
55428d7b3dSmrg    exit $?
56428d7b3dSmrg    ;;
57428d7b3dSmrgesac
58428d7b3dSmrg
59428d7b3dSmrg# Get the directory component of the given path, and save it in the
60428d7b3dSmrg# global variables '$dir'.  Note that this directory component will
61428d7b3dSmrg# be either empty or ending with a '/' character.  This is deliberate.
62428d7b3dSmrgset_dir_from ()
63428d7b3dSmrg{
64428d7b3dSmrg  case $1 in
65428d7b3dSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66428d7b3dSmrg      *) dir=;;
67428d7b3dSmrg  esac
68428d7b3dSmrg}
69428d7b3dSmrg
70428d7b3dSmrg# Get the suffix-stripped basename of the given path, and save it the
71428d7b3dSmrg# global variable '$base'.
72428d7b3dSmrgset_base_from ()
73428d7b3dSmrg{
74428d7b3dSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75428d7b3dSmrg}
76428d7b3dSmrg
77428d7b3dSmrg# If no dependency file was actually created by the compiler invocation,
78428d7b3dSmrg# we still have to create a dummy depfile, to avoid errors with the
79428d7b3dSmrg# Makefile "include basename.Plo" scheme.
80428d7b3dSmrgmake_dummy_depfile ()
81428d7b3dSmrg{
82428d7b3dSmrg  echo "#dummy" > "$depfile"
83428d7b3dSmrg}
84428d7b3dSmrg
85428d7b3dSmrg# Factor out some common post-processing of the generated depfile.
86428d7b3dSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87428d7b3dSmrgaix_post_process_depfile ()
88428d7b3dSmrg{
89428d7b3dSmrg  # If the compiler actually managed to produce a dependency file,
90428d7b3dSmrg  # post-process it.
91428d7b3dSmrg  if test -f "$tmpdepfile"; then
92428d7b3dSmrg    # Each line is of the form 'foo.o: dependency.h'.
93428d7b3dSmrg    # Do two passes, one to just change these to
94428d7b3dSmrg    #   $object: dependency.h
95428d7b3dSmrg    # and one to simply output
96428d7b3dSmrg    #   dependency.h:
97428d7b3dSmrg    # which is needed to avoid the deleted-header problem.
98428d7b3dSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99428d7b3dSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100428d7b3dSmrg    } > "$depfile"
101428d7b3dSmrg    rm -f "$tmpdepfile"
102428d7b3dSmrg  else
103428d7b3dSmrg    make_dummy_depfile
104428d7b3dSmrg  fi
105428d7b3dSmrg}
106428d7b3dSmrg
107428d7b3dSmrg# A tabulation character.
108428d7b3dSmrgtab='	'
109428d7b3dSmrg# A newline character.
110428d7b3dSmrgnl='
111428d7b3dSmrg'
112428d7b3dSmrg# Character ranges might be problematic outside the C locale.
113428d7b3dSmrg# These definitions help.
114428d7b3dSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115428d7b3dSmrglower=abcdefghijklmnopqrstuvwxyz
116428d7b3dSmrgdigits=0123456789
117428d7b3dSmrgalpha=${upper}${lower}
118428d7b3dSmrg
119428d7b3dSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120428d7b3dSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121428d7b3dSmrg  exit 1
122428d7b3dSmrgfi
123428d7b3dSmrg
124428d7b3dSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125428d7b3dSmrgdepfile=${depfile-`echo "$object" |
126428d7b3dSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127428d7b3dSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128428d7b3dSmrg
129428d7b3dSmrgrm -f "$tmpdepfile"
130428d7b3dSmrg
131428d7b3dSmrg# Avoid interferences from the environment.
132428d7b3dSmrggccflag= dashmflag=
133428d7b3dSmrg
134428d7b3dSmrg# Some modes work just like other modes, but use different flags.  We
135428d7b3dSmrg# parameterize here, but still list the modes in the big case below,
136428d7b3dSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137428d7b3dSmrg# here, because this file can only contain one case statement.
138428d7b3dSmrgif test "$depmode" = hp; then
139428d7b3dSmrg  # HP compiler uses -M and no extra arg.
140428d7b3dSmrg  gccflag=-M
141428d7b3dSmrg  depmode=gcc
142428d7b3dSmrgfi
143428d7b3dSmrg
144428d7b3dSmrgif test "$depmode" = dashXmstdout; then
145428d7b3dSmrg  # This is just like dashmstdout with a different argument.
146428d7b3dSmrg  dashmflag=-xM
147428d7b3dSmrg  depmode=dashmstdout
148428d7b3dSmrgfi
149428d7b3dSmrg
150428d7b3dSmrgcygpath_u="cygpath -u -f -"
151428d7b3dSmrgif test "$depmode" = msvcmsys; then
152428d7b3dSmrg  # This is just like msvisualcpp but w/o cygpath translation.
153428d7b3dSmrg  # Just convert the backslash-escaped backslashes to single forward
154428d7b3dSmrg  # slashes to satisfy depend.m4
155428d7b3dSmrg  cygpath_u='sed s,\\\\,/,g'
156428d7b3dSmrg  depmode=msvisualcpp
157428d7b3dSmrgfi
158428d7b3dSmrg
159428d7b3dSmrgif test "$depmode" = msvc7msys; then
160428d7b3dSmrg  # This is just like msvc7 but w/o cygpath translation.
161428d7b3dSmrg  # Just convert the backslash-escaped backslashes to single forward
162428d7b3dSmrg  # slashes to satisfy depend.m4
163428d7b3dSmrg  cygpath_u='sed s,\\\\,/,g'
164428d7b3dSmrg  depmode=msvc7
165428d7b3dSmrgfi
166428d7b3dSmrg
167428d7b3dSmrgif test "$depmode" = xlc; then
168428d7b3dSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169428d7b3dSmrg  gccflag=-qmakedep=gcc,-MF
170428d7b3dSmrg  depmode=gcc
171428d7b3dSmrgfi
172428d7b3dSmrg
173428d7b3dSmrgcase "$depmode" in
174428d7b3dSmrggcc3)
175428d7b3dSmrg## gcc 3 implements dependency tracking that does exactly what
176428d7b3dSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177428d7b3dSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178428d7b3dSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179428d7b3dSmrg## the command line argument order; so add the flags where they
180428d7b3dSmrg## appear in depend2.am.  Note that the slowdown incurred here
181428d7b3dSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182428d7b3dSmrg  for arg
183428d7b3dSmrg  do
184428d7b3dSmrg    case $arg in
185428d7b3dSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186428d7b3dSmrg    *)  set fnord "$@" "$arg" ;;
187428d7b3dSmrg    esac
188428d7b3dSmrg    shift # fnord
189428d7b3dSmrg    shift # $arg
190428d7b3dSmrg  done
191428d7b3dSmrg  "$@"
192428d7b3dSmrg  stat=$?
193428d7b3dSmrg  if test $stat -ne 0; then
194428d7b3dSmrg    rm -f "$tmpdepfile"
195428d7b3dSmrg    exit $stat
196428d7b3dSmrg  fi
197428d7b3dSmrg  mv "$tmpdepfile" "$depfile"
198428d7b3dSmrg  ;;
199428d7b3dSmrg
200428d7b3dSmrggcc)
201428d7b3dSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202428d7b3dSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203428d7b3dSmrg## (see the conditional assignment to $gccflag above).
204428d7b3dSmrg## There are various ways to get dependency output from gcc.  Here's
205428d7b3dSmrg## why we pick this rather obscure method:
206428d7b3dSmrg## - Don't want to use -MD because we'd like the dependencies to end
207428d7b3dSmrg##   up in a subdir.  Having to rename by hand is ugly.
208428d7b3dSmrg##   (We might end up doing this anyway to support other compilers.)
209428d7b3dSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210428d7b3dSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211428d7b3dSmrg##   supported by the other compilers which use the 'gcc' depmode.
212428d7b3dSmrg## - Using -M directly means running the compiler twice (even worse
213428d7b3dSmrg##   than renaming).
214428d7b3dSmrg  if test -z "$gccflag"; then
215428d7b3dSmrg    gccflag=-MD,
216428d7b3dSmrg  fi
217428d7b3dSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
218428d7b3dSmrg  stat=$?
219428d7b3dSmrg  if test $stat -ne 0; then
220428d7b3dSmrg    rm -f "$tmpdepfile"
221428d7b3dSmrg    exit $stat
222428d7b3dSmrg  fi
223428d7b3dSmrg  rm -f "$depfile"
224428d7b3dSmrg  echo "$object : \\" > "$depfile"
225428d7b3dSmrg  # The second -e expression handles DOS-style file names with drive
226428d7b3dSmrg  # letters.
227428d7b3dSmrg  sed -e 's/^[^:]*: / /' \
228428d7b3dSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229428d7b3dSmrg## This next piece of magic avoids the "deleted header file" problem.
230428d7b3dSmrg## The problem is that when a header file which appears in a .P file
231428d7b3dSmrg## is deleted, the dependency causes make to die (because there is
232428d7b3dSmrg## typically no way to rebuild the header).  We avoid this by adding
233428d7b3dSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234428d7b3dSmrg## this for us directly.
235428d7b3dSmrg## Some versions of gcc put a space before the ':'.  On the theory
236428d7b3dSmrg## that the space means something, we add a space to the output as
237428d7b3dSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238428d7b3dSmrg## to the object.  Take care to not repeat it in the output.
239428d7b3dSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
240428d7b3dSmrg## correctly.  Breaking it into two sed invocations is a workaround.
241428d7b3dSmrg  tr ' ' "$nl" < "$tmpdepfile" \
242428d7b3dSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243428d7b3dSmrg    | sed -e 's/$/ :/' >> "$depfile"
244428d7b3dSmrg  rm -f "$tmpdepfile"
245428d7b3dSmrg  ;;
246428d7b3dSmrg
247428d7b3dSmrghp)
248428d7b3dSmrg  # This case exists only to let depend.m4 do its work.  It works by
249428d7b3dSmrg  # looking at the text of this script.  This case will never be run,
250428d7b3dSmrg  # since it is checked for above.
251428d7b3dSmrg  exit 1
252428d7b3dSmrg  ;;
253428d7b3dSmrg
254428d7b3dSmrgsgi)
255428d7b3dSmrg  if test "$libtool" = yes; then
256428d7b3dSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257428d7b3dSmrg  else
258428d7b3dSmrg    "$@" -MDupdate "$tmpdepfile"
259428d7b3dSmrg  fi
260428d7b3dSmrg  stat=$?
261428d7b3dSmrg  if test $stat -ne 0; then
262428d7b3dSmrg    rm -f "$tmpdepfile"
263428d7b3dSmrg    exit $stat
264428d7b3dSmrg  fi
265428d7b3dSmrg  rm -f "$depfile"
266428d7b3dSmrg
267428d7b3dSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268428d7b3dSmrg    echo "$object : \\" > "$depfile"
269428d7b3dSmrg    # Clip off the initial element (the dependent).  Don't try to be
270428d7b3dSmrg    # clever and replace this with sed code, as IRIX sed won't handle
271428d7b3dSmrg    # lines with more than a fixed number of characters (4096 in
272428d7b3dSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273428d7b3dSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
274428d7b3dSmrg    # dependency line.
275428d7b3dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
276428d7b3dSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277428d7b3dSmrg      | tr "$nl" ' ' >> "$depfile"
278428d7b3dSmrg    echo >> "$depfile"
279428d7b3dSmrg    # The second pass generates a dummy entry for each header file.
280428d7b3dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
281428d7b3dSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282428d7b3dSmrg      >> "$depfile"
283428d7b3dSmrg  else
284428d7b3dSmrg    make_dummy_depfile
285428d7b3dSmrg  fi
286428d7b3dSmrg  rm -f "$tmpdepfile"
287428d7b3dSmrg  ;;
288428d7b3dSmrg
289428d7b3dSmrgxlc)
290428d7b3dSmrg  # This case exists only to let depend.m4 do its work.  It works by
291428d7b3dSmrg  # looking at the text of this script.  This case will never be run,
292428d7b3dSmrg  # since it is checked for above.
293428d7b3dSmrg  exit 1
294428d7b3dSmrg  ;;
295428d7b3dSmrg
296428d7b3dSmrgaix)
297428d7b3dSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
298428d7b3dSmrg  # in a .u file.  In older versions, this file always lives in the
299428d7b3dSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300428d7b3dSmrg  # start of each line; $object doesn't have directory information.
301428d7b3dSmrg  # Version 6 uses the directory in both cases.
302428d7b3dSmrg  set_dir_from "$object"
303428d7b3dSmrg  set_base_from "$object"
304428d7b3dSmrg  if test "$libtool" = yes; then
305428d7b3dSmrg    tmpdepfile1=$dir$base.u
306428d7b3dSmrg    tmpdepfile2=$base.u
307428d7b3dSmrg    tmpdepfile3=$dir.libs/$base.u
308428d7b3dSmrg    "$@" -Wc,-M
309428d7b3dSmrg  else
310428d7b3dSmrg    tmpdepfile1=$dir$base.u
311428d7b3dSmrg    tmpdepfile2=$dir$base.u
312428d7b3dSmrg    tmpdepfile3=$dir$base.u
313428d7b3dSmrg    "$@" -M
314428d7b3dSmrg  fi
315428d7b3dSmrg  stat=$?
316428d7b3dSmrg  if test $stat -ne 0; then
317428d7b3dSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318428d7b3dSmrg    exit $stat
319428d7b3dSmrg  fi
320428d7b3dSmrg
321428d7b3dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322428d7b3dSmrg  do
323428d7b3dSmrg    test -f "$tmpdepfile" && break
324428d7b3dSmrg  done
325428d7b3dSmrg  aix_post_process_depfile
326428d7b3dSmrg  ;;
327428d7b3dSmrg
328428d7b3dSmrgtcc)
329428d7b3dSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330428d7b3dSmrg  # FIXME: That version still under development at the moment of writing.
331428d7b3dSmrg  #        Make that this statement remains true also for stable, released
332428d7b3dSmrg  #        versions.
333428d7b3dSmrg  # It will wrap lines (doesn't matter whether long or short) with a
334428d7b3dSmrg  # trailing '\', as in:
335428d7b3dSmrg  #
336428d7b3dSmrg  #   foo.o : \
337428d7b3dSmrg  #    foo.c \
338428d7b3dSmrg  #    foo.h \
339428d7b3dSmrg  #
340428d7b3dSmrg  # It will put a trailing '\' even on the last line, and will use leading
341428d7b3dSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342428d7b3dSmrg  # "Emit spaces for -MD").
343428d7b3dSmrg  "$@" -MD -MF "$tmpdepfile"
344428d7b3dSmrg  stat=$?
345428d7b3dSmrg  if test $stat -ne 0; then
346428d7b3dSmrg    rm -f "$tmpdepfile"
347428d7b3dSmrg    exit $stat
348428d7b3dSmrg  fi
349428d7b3dSmrg  rm -f "$depfile"
350428d7b3dSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351428d7b3dSmrg  # We have to change lines of the first kind to '$object: \'.
352428d7b3dSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353428d7b3dSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354428d7b3dSmrg  # dummy dependency, to avoid the deleted-header problem.
355428d7b3dSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356428d7b3dSmrg  rm -f "$tmpdepfile"
357428d7b3dSmrg  ;;
358428d7b3dSmrg
359428d7b3dSmrg## The order of this option in the case statement is important, since the
360428d7b3dSmrg## shell code in configure will try each of these formats in the order
361428d7b3dSmrg## listed in this file.  A plain '-MD' option would be understood by many
362428d7b3dSmrg## compilers, so we must ensure this comes after the gcc and icc options.
363428d7b3dSmrgpgcc)
364428d7b3dSmrg  # Portland's C compiler understands '-MD'.
365428d7b3dSmrg  # Will always output deps to 'file.d' where file is the root name of the
366428d7b3dSmrg  # source file under compilation, even if file resides in a subdirectory.
367428d7b3dSmrg  # The object file name does not affect the name of the '.d' file.
368428d7b3dSmrg  # pgcc 10.2 will output
369428d7b3dSmrg  #    foo.o: sub/foo.c sub/foo.h
370428d7b3dSmrg  # and will wrap long lines using '\' :
371428d7b3dSmrg  #    foo.o: sub/foo.c ... \
372428d7b3dSmrg  #     sub/foo.h ... \
373428d7b3dSmrg  #     ...
374428d7b3dSmrg  set_dir_from "$object"
375428d7b3dSmrg  # Use the source, not the object, to determine the base name, since
376428d7b3dSmrg  # that's sadly what pgcc will do too.
377428d7b3dSmrg  set_base_from "$source"
378428d7b3dSmrg  tmpdepfile=$base.d
379428d7b3dSmrg
380428d7b3dSmrg  # For projects that build the same source file twice into different object
381428d7b3dSmrg  # files, the pgcc approach of using the *source* file root name can cause
382428d7b3dSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383428d7b3dSmrg  # the same $tmpdepfile.
384428d7b3dSmrg  lockdir=$base.d-lock
385428d7b3dSmrg  trap "
386428d7b3dSmrg    echo '$0: caught signal, cleaning up...' >&2
387428d7b3dSmrg    rmdir '$lockdir'
388428d7b3dSmrg    exit 1
389428d7b3dSmrg  " 1 2 13 15
390428d7b3dSmrg  numtries=100
391428d7b3dSmrg  i=$numtries
392428d7b3dSmrg  while test $i -gt 0; do
393428d7b3dSmrg    # mkdir is a portable test-and-set.
394428d7b3dSmrg    if mkdir "$lockdir" 2>/dev/null; then
395428d7b3dSmrg      # This process acquired the lock.
396428d7b3dSmrg      "$@" -MD
397428d7b3dSmrg      stat=$?
398428d7b3dSmrg      # Release the lock.
399428d7b3dSmrg      rmdir "$lockdir"
400428d7b3dSmrg      break
401428d7b3dSmrg    else
402428d7b3dSmrg      # If the lock is being held by a different process, wait
403428d7b3dSmrg      # until the winning process is done or we timeout.
404428d7b3dSmrg      while test -d "$lockdir" && test $i -gt 0; do
405428d7b3dSmrg        sleep 1
406428d7b3dSmrg        i=`expr $i - 1`
407428d7b3dSmrg      done
408428d7b3dSmrg    fi
409428d7b3dSmrg    i=`expr $i - 1`
410428d7b3dSmrg  done
411428d7b3dSmrg  trap - 1 2 13 15
412428d7b3dSmrg  if test $i -le 0; then
413428d7b3dSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414428d7b3dSmrg    echo "$0: check lockdir '$lockdir'" >&2
415428d7b3dSmrg    exit 1
416428d7b3dSmrg  fi
417428d7b3dSmrg
418428d7b3dSmrg  if test $stat -ne 0; then
419428d7b3dSmrg    rm -f "$tmpdepfile"
420428d7b3dSmrg    exit $stat
421428d7b3dSmrg  fi
422428d7b3dSmrg  rm -f "$depfile"
423428d7b3dSmrg  # Each line is of the form `foo.o: dependent.h',
424428d7b3dSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425428d7b3dSmrg  # Do two passes, one to just change these to
426428d7b3dSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427428d7b3dSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428428d7b3dSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429428d7b3dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
430428d7b3dSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431428d7b3dSmrg    | sed -e 's/$/ :/' >> "$depfile"
432428d7b3dSmrg  rm -f "$tmpdepfile"
433428d7b3dSmrg  ;;
434428d7b3dSmrg
435428d7b3dSmrghp2)
436428d7b3dSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437428d7b3dSmrg  # compilers, which have integrated preprocessors.  The correct option
438428d7b3dSmrg  # to use with these is +Maked; it writes dependencies to a file named
439428d7b3dSmrg  # 'foo.d', which lands next to the object file, wherever that
440428d7b3dSmrg  # happens to be.
441428d7b3dSmrg  # Much of this is similar to the tru64 case; see comments there.
442428d7b3dSmrg  set_dir_from  "$object"
443428d7b3dSmrg  set_base_from "$object"
444428d7b3dSmrg  if test "$libtool" = yes; then
445428d7b3dSmrg    tmpdepfile1=$dir$base.d
446428d7b3dSmrg    tmpdepfile2=$dir.libs/$base.d
447428d7b3dSmrg    "$@" -Wc,+Maked
448428d7b3dSmrg  else
449428d7b3dSmrg    tmpdepfile1=$dir$base.d
450428d7b3dSmrg    tmpdepfile2=$dir$base.d
451428d7b3dSmrg    "$@" +Maked
452428d7b3dSmrg  fi
453428d7b3dSmrg  stat=$?
454428d7b3dSmrg  if test $stat -ne 0; then
455428d7b3dSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456428d7b3dSmrg     exit $stat
457428d7b3dSmrg  fi
458428d7b3dSmrg
459428d7b3dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460428d7b3dSmrg  do
461428d7b3dSmrg    test -f "$tmpdepfile" && break
462428d7b3dSmrg  done
463428d7b3dSmrg  if test -f "$tmpdepfile"; then
464428d7b3dSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465428d7b3dSmrg    # Add 'dependent.h:' lines.
466428d7b3dSmrg    sed -ne '2,${
467428d7b3dSmrg               s/^ *//
468428d7b3dSmrg               s/ \\*$//
469428d7b3dSmrg               s/$/:/
470428d7b3dSmrg               p
471428d7b3dSmrg             }' "$tmpdepfile" >> "$depfile"
472428d7b3dSmrg  else
473428d7b3dSmrg    make_dummy_depfile
474428d7b3dSmrg  fi
475428d7b3dSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476428d7b3dSmrg  ;;
477428d7b3dSmrg
478428d7b3dSmrgtru64)
479428d7b3dSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480428d7b3dSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481428d7b3dSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482428d7b3dSmrg  # dependencies in 'foo.d' instead, so we check for that too.
483428d7b3dSmrg  # Subdirectories are respected.
484428d7b3dSmrg  set_dir_from  "$object"
485428d7b3dSmrg  set_base_from "$object"
486428d7b3dSmrg
487428d7b3dSmrg  if test "$libtool" = yes; then
488428d7b3dSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489428d7b3dSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490428d7b3dSmrg    # in $dir$base.o.d.  We have to check for both files, because
491428d7b3dSmrg    # one of the two compilations can be disabled.  We should prefer
492428d7b3dSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493428d7b3dSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
494428d7b3dSmrg    # the former would cause a distcleancheck panic.
495428d7b3dSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496428d7b3dSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497428d7b3dSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498428d7b3dSmrg    "$@" -Wc,-MD
499428d7b3dSmrg  else
500428d7b3dSmrg    tmpdepfile1=$dir$base.d
501428d7b3dSmrg    tmpdepfile2=$dir$base.d
502428d7b3dSmrg    tmpdepfile3=$dir$base.d
503428d7b3dSmrg    "$@" -MD
504428d7b3dSmrg  fi
505428d7b3dSmrg
506428d7b3dSmrg  stat=$?
507428d7b3dSmrg  if test $stat -ne 0; then
508428d7b3dSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509428d7b3dSmrg    exit $stat
510428d7b3dSmrg  fi
511428d7b3dSmrg
512428d7b3dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513428d7b3dSmrg  do
514428d7b3dSmrg    test -f "$tmpdepfile" && break
515428d7b3dSmrg  done
516428d7b3dSmrg  # Same post-processing that is required for AIX mode.
517428d7b3dSmrg  aix_post_process_depfile
518428d7b3dSmrg  ;;
519428d7b3dSmrg
520428d7b3dSmrgmsvc7)
521428d7b3dSmrg  if test "$libtool" = yes; then
522428d7b3dSmrg    showIncludes=-Wc,-showIncludes
523428d7b3dSmrg  else
524428d7b3dSmrg    showIncludes=-showIncludes
525428d7b3dSmrg  fi
526428d7b3dSmrg  "$@" $showIncludes > "$tmpdepfile"
527428d7b3dSmrg  stat=$?
528428d7b3dSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
529428d7b3dSmrg  if test $stat -ne 0; then
530428d7b3dSmrg    rm -f "$tmpdepfile"
531428d7b3dSmrg    exit $stat
532428d7b3dSmrg  fi
533428d7b3dSmrg  rm -f "$depfile"
534428d7b3dSmrg  echo "$object : \\" > "$depfile"
535428d7b3dSmrg  # The first sed program below extracts the file names and escapes
536428d7b3dSmrg  # backslashes for cygpath.  The second sed program outputs the file
537428d7b3dSmrg  # name when reading, but also accumulates all include files in the
538428d7b3dSmrg  # hold buffer in order to output them again at the end.  This only
539428d7b3dSmrg  # works with sed implementations that can handle large buffers.
540428d7b3dSmrg  sed < "$tmpdepfile" -n '
541428d7b3dSmrg/^Note: including file:  *\(.*\)/ {
542428d7b3dSmrg  s//\1/
543428d7b3dSmrg  s/\\/\\\\/g
544428d7b3dSmrg  p
545428d7b3dSmrg}' | $cygpath_u | sort -u | sed -n '
546428d7b3dSmrgs/ /\\ /g
547428d7b3dSmrgs/\(.*\)/'"$tab"'\1 \\/p
548428d7b3dSmrgs/.\(.*\) \\/\1:/
549428d7b3dSmrgH
550428d7b3dSmrg$ {
551428d7b3dSmrg  s/.*/'"$tab"'/
552428d7b3dSmrg  G
553428d7b3dSmrg  p
554428d7b3dSmrg}' >> "$depfile"
555428d7b3dSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556428d7b3dSmrg  rm -f "$tmpdepfile"
557428d7b3dSmrg  ;;
558428d7b3dSmrg
559428d7b3dSmrgmsvc7msys)
560428d7b3dSmrg  # This case exists only to let depend.m4 do its work.  It works by
561428d7b3dSmrg  # looking at the text of this script.  This case will never be run,
562428d7b3dSmrg  # since it is checked for above.
563428d7b3dSmrg  exit 1
564428d7b3dSmrg  ;;
565428d7b3dSmrg
566428d7b3dSmrg#nosideeffect)
567428d7b3dSmrg  # This comment above is used by automake to tell side-effect
568428d7b3dSmrg  # dependency tracking mechanisms from slower ones.
569428d7b3dSmrg
570428d7b3dSmrgdashmstdout)
571428d7b3dSmrg  # Important note: in order to support this mode, a compiler *must*
572428d7b3dSmrg  # always write the preprocessed file to stdout, regardless of -o.
573428d7b3dSmrg  "$@" || exit $?
574428d7b3dSmrg
575428d7b3dSmrg  # Remove the call to Libtool.
576428d7b3dSmrg  if test "$libtool" = yes; then
577428d7b3dSmrg    while test "X$1" != 'X--mode=compile'; do
578428d7b3dSmrg      shift
579428d7b3dSmrg    done
580428d7b3dSmrg    shift
581428d7b3dSmrg  fi
582428d7b3dSmrg
583428d7b3dSmrg  # Remove '-o $object'.
584428d7b3dSmrg  IFS=" "
585428d7b3dSmrg  for arg
586428d7b3dSmrg  do
587428d7b3dSmrg    case $arg in
588428d7b3dSmrg    -o)
589428d7b3dSmrg      shift
590428d7b3dSmrg      ;;
591428d7b3dSmrg    $object)
592428d7b3dSmrg      shift
593428d7b3dSmrg      ;;
594428d7b3dSmrg    *)
595428d7b3dSmrg      set fnord "$@" "$arg"
596428d7b3dSmrg      shift # fnord
597428d7b3dSmrg      shift # $arg
598428d7b3dSmrg      ;;
599428d7b3dSmrg    esac
600428d7b3dSmrg  done
601428d7b3dSmrg
602428d7b3dSmrg  test -z "$dashmflag" && dashmflag=-M
603428d7b3dSmrg  # Require at least two characters before searching for ':'
604428d7b3dSmrg  # in the target name.  This is to cope with DOS-style filenames:
605428d7b3dSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606428d7b3dSmrg  "$@" $dashmflag |
607428d7b3dSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608428d7b3dSmrg  rm -f "$depfile"
609428d7b3dSmrg  cat < "$tmpdepfile" > "$depfile"
610428d7b3dSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611428d7b3dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
612428d7b3dSmrg  tr ' ' "$nl" < "$tmpdepfile" \
613428d7b3dSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614428d7b3dSmrg    | sed -e 's/$/ :/' >> "$depfile"
615428d7b3dSmrg  rm -f "$tmpdepfile"
616428d7b3dSmrg  ;;
617428d7b3dSmrg
618428d7b3dSmrgdashXmstdout)
619428d7b3dSmrg  # This case only exists to satisfy depend.m4.  It is never actually
620428d7b3dSmrg  # run, as this mode is specially recognized in the preamble.
621428d7b3dSmrg  exit 1
622428d7b3dSmrg  ;;
623428d7b3dSmrg
624428d7b3dSmrgmakedepend)
625428d7b3dSmrg  "$@" || exit $?
626428d7b3dSmrg  # Remove any Libtool call
627428d7b3dSmrg  if test "$libtool" = yes; then
628428d7b3dSmrg    while test "X$1" != 'X--mode=compile'; do
629428d7b3dSmrg      shift
630428d7b3dSmrg    done
631428d7b3dSmrg    shift
632428d7b3dSmrg  fi
633428d7b3dSmrg  # X makedepend
634428d7b3dSmrg  shift
635428d7b3dSmrg  cleared=no eat=no
636428d7b3dSmrg  for arg
637428d7b3dSmrg  do
638428d7b3dSmrg    case $cleared in
639428d7b3dSmrg    no)
640428d7b3dSmrg      set ""; shift
641428d7b3dSmrg      cleared=yes ;;
642428d7b3dSmrg    esac
643428d7b3dSmrg    if test $eat = yes; then
644428d7b3dSmrg      eat=no
645428d7b3dSmrg      continue
646428d7b3dSmrg    fi
647428d7b3dSmrg    case "$arg" in
648428d7b3dSmrg    -D*|-I*)
649428d7b3dSmrg      set fnord "$@" "$arg"; shift ;;
650428d7b3dSmrg    # Strip any option that makedepend may not understand.  Remove
651428d7b3dSmrg    # the object too, otherwise makedepend will parse it as a source file.
652428d7b3dSmrg    -arch)
653428d7b3dSmrg      eat=yes ;;
654428d7b3dSmrg    -*|$object)
655428d7b3dSmrg      ;;
656428d7b3dSmrg    *)
657428d7b3dSmrg      set fnord "$@" "$arg"; shift ;;
658428d7b3dSmrg    esac
659428d7b3dSmrg  done
660428d7b3dSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661428d7b3dSmrg  touch "$tmpdepfile"
662428d7b3dSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663428d7b3dSmrg  rm -f "$depfile"
664428d7b3dSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665428d7b3dSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666428d7b3dSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667428d7b3dSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668428d7b3dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
669428d7b3dSmrg  sed '1,2d' "$tmpdepfile" \
670428d7b3dSmrg    | tr ' ' "$nl" \
671428d7b3dSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672428d7b3dSmrg    | sed -e 's/$/ :/' >> "$depfile"
673428d7b3dSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674428d7b3dSmrg  ;;
675428d7b3dSmrg
676428d7b3dSmrgcpp)
677428d7b3dSmrg  # Important note: in order to support this mode, a compiler *must*
678428d7b3dSmrg  # always write the preprocessed file to stdout.
679428d7b3dSmrg  "$@" || exit $?
680428d7b3dSmrg
681428d7b3dSmrg  # Remove the call to Libtool.
682428d7b3dSmrg  if test "$libtool" = yes; then
683428d7b3dSmrg    while test "X$1" != 'X--mode=compile'; do
684428d7b3dSmrg      shift
685428d7b3dSmrg    done
686428d7b3dSmrg    shift
687428d7b3dSmrg  fi
688428d7b3dSmrg
689428d7b3dSmrg  # Remove '-o $object'.
690428d7b3dSmrg  IFS=" "
691428d7b3dSmrg  for arg
692428d7b3dSmrg  do
693428d7b3dSmrg    case $arg in
694428d7b3dSmrg    -o)
695428d7b3dSmrg      shift
696428d7b3dSmrg      ;;
697428d7b3dSmrg    $object)
698428d7b3dSmrg      shift
699428d7b3dSmrg      ;;
700428d7b3dSmrg    *)
701428d7b3dSmrg      set fnord "$@" "$arg"
702428d7b3dSmrg      shift # fnord
703428d7b3dSmrg      shift # $arg
704428d7b3dSmrg      ;;
705428d7b3dSmrg    esac
706428d7b3dSmrg  done
707428d7b3dSmrg
708428d7b3dSmrg  "$@" -E \
709428d7b3dSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710428d7b3dSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711428d7b3dSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
712428d7b3dSmrg  rm -f "$depfile"
713428d7b3dSmrg  echo "$object : \\" > "$depfile"
714428d7b3dSmrg  cat < "$tmpdepfile" >> "$depfile"
715428d7b3dSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716428d7b3dSmrg  rm -f "$tmpdepfile"
717428d7b3dSmrg  ;;
718428d7b3dSmrg
719428d7b3dSmrgmsvisualcpp)
720428d7b3dSmrg  # Important note: in order to support this mode, a compiler *must*
721428d7b3dSmrg  # always write the preprocessed file to stdout.
722428d7b3dSmrg  "$@" || exit $?
723428d7b3dSmrg
724428d7b3dSmrg  # Remove the call to Libtool.
725428d7b3dSmrg  if test "$libtool" = yes; then
726428d7b3dSmrg    while test "X$1" != 'X--mode=compile'; do
727428d7b3dSmrg      shift
728428d7b3dSmrg    done
729428d7b3dSmrg    shift
730428d7b3dSmrg  fi
731428d7b3dSmrg
732428d7b3dSmrg  IFS=" "
733428d7b3dSmrg  for arg
734428d7b3dSmrg  do
735428d7b3dSmrg    case "$arg" in
736428d7b3dSmrg    -o)
737428d7b3dSmrg      shift
738428d7b3dSmrg      ;;
739428d7b3dSmrg    $object)
740428d7b3dSmrg      shift
741428d7b3dSmrg      ;;
742428d7b3dSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743428d7b3dSmrg        set fnord "$@"
744428d7b3dSmrg        shift
745428d7b3dSmrg        shift
746428d7b3dSmrg        ;;
747428d7b3dSmrg    *)
748428d7b3dSmrg        set fnord "$@" "$arg"
749428d7b3dSmrg        shift
750428d7b3dSmrg        shift
751428d7b3dSmrg        ;;
752428d7b3dSmrg    esac
753428d7b3dSmrg  done
754428d7b3dSmrg  "$@" -E 2>/dev/null |
755428d7b3dSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756428d7b3dSmrg  rm -f "$depfile"
757428d7b3dSmrg  echo "$object : \\" > "$depfile"
758428d7b3dSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759428d7b3dSmrg  echo "$tab" >> "$depfile"
760428d7b3dSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761428d7b3dSmrg  rm -f "$tmpdepfile"
762428d7b3dSmrg  ;;
763428d7b3dSmrg
764428d7b3dSmrgmsvcmsys)
765428d7b3dSmrg  # This case exists only to let depend.m4 do its work.  It works by
766428d7b3dSmrg  # looking at the text of this script.  This case will never be run,
767428d7b3dSmrg  # since it is checked for above.
768428d7b3dSmrg  exit 1
769428d7b3dSmrg  ;;
770428d7b3dSmrg
771428d7b3dSmrgnone)
772428d7b3dSmrg  exec "$@"
773428d7b3dSmrg  ;;
774428d7b3dSmrg
775428d7b3dSmrg*)
776428d7b3dSmrg  echo "Unknown depmode $depmode" 1>&2
777428d7b3dSmrg  exit 1
778428d7b3dSmrg  ;;
779428d7b3dSmrgesac
780428d7b3dSmrg
781428d7b3dSmrgexit 0
782428d7b3dSmrg
783428d7b3dSmrg# Local Variables:
784428d7b3dSmrg# mode: shell-script
785428d7b3dSmrg# sh-indentation: 2
786428d7b3dSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
787428d7b3dSmrg# time-stamp-start: "scriptversion="
788428d7b3dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789428d7b3dSmrg# time-stamp-time-zone: "UTC"
790428d7b3dSmrg# time-stamp-end: "; # UTC"
791428d7b3dSmrg# End:
792