| 1 |
# serial 10 |
| 2 |
|
| 3 |
# Copyright (C) 2002-2006, 2008-2023 Free Software Foundation, Inc. |
| 4 |
# This file is free software; the Free Software Foundation |
| 5 |
# gives unlimited permission to copy and/or distribute it, |
| 6 |
# with or without modifications, as long as this notice is preserved. |
| 7 |
|
| 8 |
# There are two types of parser skeletons: |
| 9 |
# |
| 10 |
# * Those that can be used with any Yacc implementation, including bison. |
| 11 |
# For these, in the configure.ac, up to Autoconf 2.69, you could use |
| 12 |
# AC_PROG_YACC |
| 13 |
# In newer Autoconf versions, however, this macro is broken. See |
| 14 |
# https://lists.gnu.org/archive/html/autoconf-patches/2013-03/msg00000.html |
| 15 |
# https://lists.gnu.org/archive/html/bug-autoconf/2018-12/msg00001.html |
| 16 |
# In the Makefile.am you could use |
| 17 |
# $(SHELL) $(YLWRAP) $(srcdir)/foo.y \ |
| 18 |
# y.tab.c foo.c \ |
| 19 |
# y.tab.h foo.h \ |
| 20 |
# y.output foo.output \ |
| 21 |
# -- $(YACC) $(YFLAGS) $(AM_YFLAGS) |
| 22 |
# or similar. |
| 23 |
# |
| 24 |
# * Those that make use of Bison extensions. For example, |
| 25 |
# - %define api.pure requires bison 2.7 or newer, |
| 26 |
# - %precedence requires bison 3.0 or newer. |
| 27 |
# For these, in the configure.ac you will need an invocation of |
| 28 |
# gl_PROG_BISON([VARIABLE], [MIN_BISON_VERSION]) |
| 29 |
# Example: |
| 30 |
# gl_PROG_BISON([PARSE_DATETIME_BISON], [2.4]) |
| 31 |
# With this preparation, in the Makefile.am there are two ways to formulate |
| 32 |
# the invocation. Both are direct, without use of 'ylwrap'. |
| 33 |
# (a) You can invoke |
| 34 |
# $(VARIABLE) -d $(SOME_BISON_OPTIONS) --output foo.c $(srcdir)/foo.y |
| 35 |
# or similar. |
| 36 |
# (b) If you want the invocation to honor an YFLAGS=... parameter passed to |
| 37 |
# 'configure' or an YFLAGS environment variable present at 'configure' |
| 38 |
# time, add an invocation of gl_BISON to the configure.ac, and write |
| 39 |
# $(VARIABLE) -d $(YFLAGS) $(AM_YFLAGS) $(srcdir)/foo.y |
| 40 |
# or similar. |
| 41 |
|
| 42 |
# This macro defines the autoconf variable VARIABLE to 'bison' if the specified |
| 43 |
# minimum version of bison is found in $PATH, or to ':' otherwise. |
| 44 |
AC_DEFUN([gl_PROG_BISON], |
| 45 |
[ |
| 46 |
AC_CHECK_PROGS([$1], [bison]) |
| 47 |
if test -z "$[$1]"; then |
| 48 |
ac_verc_fail=yes |
| 49 |
else |
| 50 |
cat >conftest.y <<_ACEOF |
| 51 |
%require "$2" |
| 52 |
%% |
| 53 |
exp: |
| 54 |
_ACEOF |
| 55 |
AC_MSG_CHECKING([for bison $2 or newer]) |
| 56 |
ac_prog_version=`$$1 --version 2>&1 | sed -n 's/^.*GNU Bison.* \([[0-9]]*\.[[0-9.]]*\).*$/\1/p'` |
| 57 |
: ${ac_prog_version:='v. ?.??'} |
| 58 |
if $$1 conftest.y -o conftest.c 2>/dev/null; then |
| 59 |
ac_prog_version="$ac_prog_version, ok" |
| 60 |
ac_verc_fail=no |
| 61 |
else |
| 62 |
ac_prog_version="$ac_prog_version, bad" |
| 63 |
ac_verc_fail=yes |
| 64 |
fi |
| 65 |
rm -f conftest.y conftest.c |
| 66 |
AC_MSG_RESULT([$ac_prog_version]) |
| 67 |
fi |
| 68 |
if test $ac_verc_fail = yes; then |
| 69 |
[$1]=: |
| 70 |
fi |
| 71 |
AC_SUBST([$1]) |
| 72 |
]) |
| 73 |
|
| 74 |
# This macro sets the autoconf variables YACC (for old-style yacc Makefile |
| 75 |
# rules) and YFLAGS (to allow options to be passed as 'configure' time). |
| 76 |
AC_DEFUN([gl_BISON], |
| 77 |
[ |
| 78 |
: ${YACC='bison -o y.tab.c'} |
| 79 |
dnl |
| 80 |
dnl Declaring YACC & YFLAGS precious will not be necessary after GNULIB |
| 81 |
dnl requires an Autoconf greater than 2.59c, but it will probably still be |
| 82 |
dnl useful to override the description of YACC in the --help output, re |
| 83 |
dnl parse-datetime.y assuming 'bison -o y.tab.c'. |
| 84 |
AC_ARG_VAR([YACC], |
| 85 |
[The "Yet Another C Compiler" implementation to use. Defaults to |
| 86 |
'bison -o y.tab.c'. Values other than 'bison -o y.tab.c' will most likely |
| 87 |
break on most systems.])dnl |
| 88 |
AC_ARG_VAR([YFLAGS], |
| 89 |
[YFLAGS contains the list arguments that will be passed by default to Bison. |
| 90 |
This script will default YFLAGS to the empty string to avoid a default value of |
| 91 |
'-d' given by some make applications.])dnl |
| 92 |
]) |