bison.m4 3.6 KB

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