bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bison: new module


From: Bruno Haible
Subject: bison: new module
Date: Fri, 01 May 2020 18:21:50 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; )

The 'parse-datetime' module has a reasonable configure check for Bison,
specifying the minimum version of Bison that is required for the particular
.y file.

This patch moves the support to a module 'bison', that can be used in other
gnulib modules or GNU packages as well. It is defined based on
<https://lists.gnu.org/archive/html/bug-autoconf/2018-12/msg00001.html>.

The macro gl_PROG_BISON could be renamed to AC_PROG_BISON when incorporated
in GNU Autoconf.

It would be useful to remove the need for the third parameter, since it
could be implied from the second parameter. I don't have time to do this
now; volunteers welcome!


2020-05-01  Bruno Haible  <address@hidden>

        bison: New module.
        * m4/bison.m4 (gl_PROG_BISON): New macro, extracted from
        m4/parse-datetime.m4.
        * m4/parse-datetime.m4 (gl_PARSE_DATETIME): Invoke gl_PROG_BISON.
        * modules/bison: New file.
        * modules/parse-datetime (Files): Remove m4/bison.m4.
        (Depends-on): Add bison.

diff --git a/m4/bison.m4 b/m4/bison.m4
index 6326cd5..5802a5c 100644
--- a/m4/bison.m4
+++ b/m4/bison.m4
@@ -1,13 +1,75 @@
-# serial 7
+# serial 8
 
-# Copyright (C) 2002, 2005, 2009-2020 Free Software Foundation, Inc.
+# Copyright (C) 2002-2006, 2008-2020 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# There are two types of parser skeletons:
+#
+# * Those that can be used with any Yacc implementation, including bison.
+#   For these, in the configure.ac, up to Autoconf 2.69, you could use
+#     AC_PROG_YACC
+#   In newer Autoconf versions, however, this macro is broken. See
+#     https://lists.gnu.org/archive/html/autoconf-patches/2013-03/msg00000.html
+#     https://lists.gnu.org/archive/html/bug-autoconf/2018-12/msg00001.html
+#   In the Makefile.am you could use
+#     $(SHELL) $(YLWRAP) $(srcdir)/foo.y \
+#                        y.tab.c foo.c \
+#                        y.tab.h foo.h \
+#                        y.output foo.output \
+#                        -- $(YACC) $(YFLAGS) $(AM_YFLAGS)
+#   or similar.
+#
+# * Those that make use of Bison extensions. For example,
+#     - %define api.pure   requires bison 2.7 or newer,
+#     - %precedence        requires bison 3.0 or newer.
+#   For these, in the configure.ac you will need an invocation of
+#     gl_PROG_BISON([VARIABLE], [MIN_BISON_VERSION], 
[BISON_VERSIONS_TO_EXCLUDE])
+#   Example:
+#     gl_PROG_BISON([PARSE_DATETIME_BISON], [2.4], [1.* | 2.[0-3] | 2.[0-3].*])
+#   With this preparation, in the Makefile.am there are two ways to formulate
+#   the invocation. Both are direct, without use of 'ylwrap'.
+#   (a) You can invoke
+#         $(VARIABLE) -d $(SOME_BISON_OPTIONS) --output foo.c $(srcdir)/foo.y
+#       or similar.
+#   (b) If you want the invocation to honor an YFLAGS=... parameter passed to
+#       'configure' or an YFLAGS environment variable present at 'configure'
+#       time, add an invocation of gl_BISON to the configure.ac, and write
+#         $(VARIABLE) -d $(YFLAGS) $(AM_YFLAGS) $(srcdir)/foo.y
+#       or similar.
+
+# This macro defines the autoconf variable VARIABLE to 'bison' if the specified
+# minimum version of bison is found in $PATH, or to ':' otherwise.
+AC_DEFUN([gl_PROG_BISON],
+[
+  AC_CHECK_PROGS([$1], [bison])
+  if test -z "$[$1]"; then
+    ac_verc_fail=yes
+  else
+    dnl Found it, now check the version.
+    AC_MSG_CHECKING([version of bison])
+changequote(<<,>>)dnl
+    ac_prog_version=`$<<$1>> --version 2>&1 | sed -n 's/^.*GNU Bison.* 
\([0-9]*\.[0-9.]*\).*$/\1/p'`
+    case $ac_prog_version in
+      '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
+      <<$3>>)
+         ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
+      *) ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
+    esac
+changequote([,])dnl
+    AC_MSG_RESULT([$ac_prog_version])
+  fi
+  if test $ac_verc_fail = yes; then
+    [$1]=:
+  fi
+  AC_SUBST([$1])
+])
+
+# This macro sets the autoconf variables YACC (for old-style yacc Makefile
+# rules) and YFLAGS (to allow options to be passed as 'configure' time).
 AC_DEFUN([gl_BISON],
 [
-  # parse-datetime.y works with bison only.
   : ${YACC='bison -o y.tab.c'}
 dnl
 dnl Declaring YACC & YFLAGS precious will not be necessary after GNULIB
diff --git a/m4/parse-datetime.m4 b/m4/parse-datetime.m4
index 52a10aa..0849b82 100644
--- a/m4/parse-datetime.m4
+++ b/m4/parse-datetime.m4
@@ -1,4 +1,4 @@
-# parse-datetime.m4 serial 24
+# parse-datetime.m4 serial 25
 dnl Copyright (C) 2002-2006, 2008-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -35,27 +35,7 @@ AC_DEFUN([gl_PARSE_DATETIME],
   dnl the files or have a broken "make" program, hence the parse-datetime.c
   dnl rule will sometimes fire. To avoid an error, defines PARSE_DATETIME_BISON
   dnl to ":" if it is not present or too old.
-  AC_CHECK_PROGS([PARSE_DATETIME_BISON], [bison])
-  if test -z "$PARSE_DATETIME_BISON"; then
-    ac_verc_fail=yes
-  else
-    dnl Found it, now check the version.
-    AC_MSG_CHECKING([version of bison])
-changequote(<<,>>)dnl
-    ac_prog_version=`$PARSE_DATETIME_BISON --version 2>&1 | sed -n 's/^.*GNU 
Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
-    case $ac_prog_version in
-      '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
-      1.* | 2.[0-3] | 2.[0-3].*)
-changequote([,])dnl
-         ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
-      *) ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
-    esac
-    AC_MSG_RESULT([$ac_prog_version])
-  fi
-  if test $ac_verc_fail = yes; then
-    PARSE_DATETIME_BISON=:
-  fi
-  AC_SUBST([PARSE_DATETIME_BISON])
+  gl_PROG_BISON([PARSE_DATETIME_BISON], [2.4], [1.* | 2.[0-3] | 2.[0-3].*])
 
   dnl Prerequisites of lib/parse-datetime.h.
   AC_REQUIRE([AM_STDBOOL_H])
diff --git a/modules/bison b/modules/bison
new file mode 100644
index 0000000..126c5ec
--- /dev/null
+++ b/modules/bison
@@ -0,0 +1,21 @@
+Description:
+Building bison-generated parsers.
+
+Files:
+m4/bison.m4
+
+Depends-on:
+
+configure.ac:
+# See the comments in bison.m4.
+
+Makefile.am:
+# See the comments in bison.m4.
+
+Include:
+
+License:
+GPLed build tool
+
+Maintainer:
+all
diff --git a/modules/parse-datetime b/modules/parse-datetime
index 5ef3264..7571e06 100644
--- a/modules/parse-datetime
+++ b/modules/parse-datetime
@@ -5,11 +5,11 @@ Files:
 doc/parse-datetime.texi
 lib/parse-datetime.h
 lib/parse-datetime.y
-m4/bison.m4
 m4/tm_gmtoff.m4
 m4/parse-datetime.m4
 
 Depends-on:
+bison
 c-ctype
 stdbool
 gettime




reply via email to

[Prev in Thread] Current Thread [Next in Thread]