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