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