1 dnl Copyright © 2021 Nick Bowler
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software, you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
7 dnl DX_PROG_BISON([min-version], [action-if-found], [action-if-not-found])
9 dnl Search PATH for a reasonably modern GNU Bison of at least the given
10 dnl minimum version, which may be empty to accept any version. Here,
11 dnl "reasonably modern" means it supports the %code construct and (if
12 dnl a version is specified), the %require construct.
14 dnl If found, the BISON variable (which is substituted by AC_SUBST) is
15 dnl set with the result, and action-if-found is executed. Otherwise,
16 dnl action-if-not-found is executed if nonempty, else configure will
17 dnl exit with a fatal error.
18 AC_DEFUN([DX_PROG_BISON],
19 [AC_ARG_VAR([BISON], [GNU Bison command])dnl
20 AC_ARG_VAR([BISONFLAGS], [Additional options to pass to Bison])dnl
21 cat >conftest.y <<'EOF'
22 m4_ifnblank([$1], [%require "$1"
24 /* SUPPORTS_CODE_TOP_WITNESS */
27 /* SUPPORTS_CODE_REQUIRES_WITNESS */
30 int yylex(void) { return 0; }
31 void yyerror(const char *msg) { }
36 int main(void) { return yyparse(); }
38 AC_CACHE_CHECK([for bison], [ac_cv_path_BISON],
40 AC_PATH_PROGS_FEATURE_CHECK([BISON], [bison],
41 [_DX_BISON_DO_TEST([$ac_path_BISON],
42 [DX_BASENAME([bison_relcmd], ["$ac_path_BISON"])
43 bison_bypath=`{ command -v "$bison_relcmd"; } 2>/dev/null` #''
44 ac_cv_path_BISON=$ac_path_BISON
45 test x"$bison_bypath" = x"$ac_path_BISON" && ac_cv_path_BISON=$bison_relcmd
47 dx_cv_bison_works=yes])], [ac_cv_path_BISON=no dx_cv_bison_found=false])])
48 AS_IF([$dx_cv_bison_found],
49 [BISON=$ac_cv_path_BISON
50 AC_CACHE_CHECK([whether $BISON works and is m4_ifnblank([$1],
51 [at least version $1], [reasonably modern])],
53 [_DX_BISON_DO_TEST([$BISON], [dx_cv_bison_works=yes], [dx_cv_bison_works=no])])])
54 AS_IF([test x"$dx_cv_bison_works" = x"yes"],
55 [$2], [m4_default([$3], [AC_MSG_FAILURE(
56 [GNU bison m4_ifnblank([$1], [version at least $1 ])is required.
58 The latest version may be found at <https://www.gnu.org/software/bison/>.
60 rm -f conftest.tab.[[ch]] conftest.y y.tab.[[ch]]
63 AC_DEFUN([_DX_BISON_DO_TEST], [rm -f conftest.tab.[[ch]] y.tab.[[ch]]
64 AS_IF([DX_RUN_LOG([$1 --file-prefix=conftest --defines conftest.y])],
65 [AC_LINK_IFELSE([AC_LANG_SOURCE([[#include "conftest.tab.c"]])],
66 [AS_IF([DX_RUN_LOG([grep SUPPORTS_CODE_TOP_WITNESS conftest.tab.c]) &&
67 DX_RUN_LOG([grep SUPPORTS_CODE_REQUIRES_WITNESS conftest.tab.h])],
68 [$2], [$3])], [$3])], [$3])])