Blame src/gl/m4/bison.m4

Packit Service 991b93
# serial 10
Packit aea12f
Packit Service 991b93
# Copyright (C) 2002-2006, 2008-2020 Free Software Foundation, Inc.
Packit aea12f
# This file is free software; the Free Software Foundation
Packit aea12f
# gives unlimited permission to copy and/or distribute it,
Packit aea12f
# with or without modifications, as long as this notice is preserved.
Packit aea12f
Packit Service 991b93
# There are two types of parser skeletons:
Packit Service 991b93
#
Packit Service 991b93
# * Those that can be used with any Yacc implementation, including bison.
Packit Service 991b93
#   For these, in the configure.ac, up to Autoconf 2.69, you could use
Packit Service 991b93
#     AC_PROG_YACC
Packit Service 991b93
#   In newer Autoconf versions, however, this macro is broken. See
Packit Service 991b93
#     https://lists.gnu.org/archive/html/autoconf-patches/2013-03/msg00000.html
Packit Service 991b93
#     https://lists.gnu.org/archive/html/bug-autoconf/2018-12/msg00001.html
Packit Service 991b93
#   In the Makefile.am you could use
Packit Service 991b93
#     $(SHELL) $(YLWRAP) $(srcdir)/foo.y \
Packit Service 991b93
#                        y.tab.c foo.c \
Packit Service 991b93
#                        y.tab.h foo.h \
Packit Service 991b93
#                        y.output foo.output \
Packit Service 991b93
#                        -- $(YACC) $(YFLAGS) $(AM_YFLAGS)
Packit Service 991b93
#   or similar.
Packit Service 991b93
#
Packit Service 991b93
# * Those that make use of Bison extensions. For example,
Packit Service 991b93
#     - %define api.pure   requires bison 2.7 or newer,
Packit Service 991b93
#     - %precedence        requires bison 3.0 or newer.
Packit Service 991b93
#   For these, in the configure.ac you will need an invocation of
Packit Service 991b93
#     gl_PROG_BISON([VARIABLE], [MIN_BISON_VERSION])
Packit Service 991b93
#   Example:
Packit Service 991b93
#     gl_PROG_BISON([PARSE_DATETIME_BISON], [2.4])
Packit Service 991b93
#   With this preparation, in the Makefile.am there are two ways to formulate
Packit Service 991b93
#   the invocation. Both are direct, without use of 'ylwrap'.
Packit Service 991b93
#   (a) You can invoke
Packit Service 991b93
#         $(VARIABLE) -d $(SOME_BISON_OPTIONS) --output foo.c $(srcdir)/foo.y
Packit Service 991b93
#       or similar.
Packit Service 991b93
#   (b) If you want the invocation to honor an YFLAGS=... parameter passed to
Packit Service 991b93
#       'configure' or an YFLAGS environment variable present at 'configure'
Packit Service 991b93
#       time, add an invocation of gl_BISON to the configure.ac, and write
Packit Service 991b93
#         $(VARIABLE) -d $(YFLAGS) $(AM_YFLAGS) $(srcdir)/foo.y
Packit Service 991b93
#       or similar.
Packit Service 991b93
Packit Service 991b93
# This macro defines the autoconf variable VARIABLE to 'bison' if the specified
Packit Service 991b93
# minimum version of bison is found in $PATH, or to ':' otherwise.
Packit Service 991b93
AC_DEFUN([gl_PROG_BISON],
Packit Service 991b93
[
Packit Service 991b93
  AC_CHECK_PROGS([$1], [bison])
Packit Service 991b93
  if test -z "$[$1]"; then
Packit Service 991b93
    ac_verc_fail=yes
Packit Service 991b93
  else
Packit Service 991b93
    cat >conftest.y <<_ACEOF
Packit Service 991b93
%require "$2"
Packit Service 991b93
%%
Packit Service 991b93
exp:
Packit Service 991b93
_ACEOF
Packit Service 991b93
    AC_MSG_CHECKING([for bison $2 or newer])
Packit Service 991b93
    ac_prog_version=`$$1 --version 2>&1 | sed -n 's/^.*GNU Bison.* \([[0-9]]*\.[[0-9.]]*\).*$/\1/p'`
Packit Service 991b93
    : ${ac_prog_version:='v. ?.??'}
Packit Service 991b93
    if $$1 conftest.y -o conftest.c 2>/dev/null; then
Packit Service 991b93
      ac_prog_version="$ac_prog_version, ok"
Packit Service 991b93
      ac_verc_fail=no
Packit Service 991b93
    else
Packit Service 991b93
      ac_prog_version="$ac_prog_version, bad"
Packit Service 991b93
      ac_verc_fail=yes
Packit Service 991b93
    fi
Packit Service 991b93
    rm -f conftest.y conftest.c
Packit Service 991b93
    AC_MSG_RESULT([$ac_prog_version])
Packit Service 991b93
  fi
Packit Service 991b93
  if test $ac_verc_fail = yes; then
Packit Service 991b93
    [$1]=:
Packit Service 991b93
  fi
Packit Service 991b93
  AC_SUBST([$1])
Packit Service 991b93
])
Packit Service 991b93
Packit Service 991b93
# This macro sets the autoconf variables YACC (for old-style yacc Makefile
Packit Service 991b93
# rules) and YFLAGS (to allow options to be passed as 'configure' time).
Packit aea12f
AC_DEFUN([gl_BISON],
Packit aea12f
[
Packit aea12f
  : ${YACC='bison -o y.tab.c'}
Packit aea12f
dnl
Packit aea12f
dnl Declaring YACC & YFLAGS precious will not be necessary after GNULIB
Packit aea12f
dnl requires an Autoconf greater than 2.59c, but it will probably still be
Packit aea12f
dnl useful to override the description of YACC in the --help output, re
Packit aea12f
dnl parse-datetime.y assuming 'bison -o y.tab.c'.
Packit aea12f
  AC_ARG_VAR([YACC],
Packit aea12f
[The "Yet Another C Compiler" implementation to use.  Defaults to
Packit aea12f
'bison -o y.tab.c'.  Values other than 'bison -o y.tab.c' will most likely
Packit aea12f
break on most systems.])dnl
Packit aea12f
  AC_ARG_VAR([YFLAGS],
Packit aea12f
[YFLAGS contains the list arguments that will be passed by default to Bison.
Packit aea12f
This script will default YFLAGS to the empty string to avoid a default value of
Packit aea12f
'-d' given by some make applications.])dnl
Packit aea12f
])