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