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.
8 dnl Checks $BISON for various options that may be required for compatibility
9 dnl with multiple versions. Currently tested features:
11 dnl If bison supports --define (as an alias for %define in the source file),
12 dnl then dx_cv_bison_define_cmdline will be set to "yes". Otherwise, it will
15 dnl If bison supports the --define=api.header.include feature (and thus
16 dnl #includes the header in the parser rather than embedding its contents),
17 dnl then dx_cv_bison_api_header_include will be set to "yes". Otherwise, it
18 dnl will be set to "no".
20 dnl If bison gives spews warnings for %error-verbose and -Wno-deprecated
21 dnl suppresses those warnings, then dx_cv_bison_warn_no_deprecated will be
22 dnl set to "yes". Otherwise, it will be set to "no".
24 AC_DEFUN([DX_BISON_COMPAT],
25 [AC_REQUIRE([DX_PROG_BISON])dnl
26 AS_IF([test x"$dx_cv_bison_works" = x"yes"],
27 [# Older versions of bison accept --define as an abbreviation for --defines.
28 # This gives very bad results in the following configure test.
29 AC_CACHE_CHECK([whether $BISON supports --define],
30 [dx_cv_bison_define_cmdline], [dx_cv_bison_define_cmdline=no
31 cat >conftest.y <<'EOF'
33 int yylex(void) { return 0; }
34 void yyerror(const char *msg) { }
39 int main(void) { return yylval; }
42 rm -f conftest.tab.c conftest.x
43 $BISON --define=conftest.x conftest.y >&AS_MESSAGE_LOG_FD 2>&1
44 AS_IF([test ! -f conftest.x],
45 [AS_IF([$BISON conftest.y >&AS_MESSAGE_LOG_FD 2>&1],
46 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include "conftest.tab.c"]])],
47 [AS_IF([$BISON --define=api.pure conftest.y >&AS_MESSAGE_LOG_FD 2>&1],
48 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include "conftest.tab.c"]])],
49 [:], [dx_cv_bison_define_cmdline=yes])])])])])
52 AS_IF([test x"$dx_cv_bison_define_cmdline" != x"yes"],
53 [dx_cv_bison_api_header_include=no])
55 AC_CACHE_CHECK([whether $BISON supports api.header.include],
56 [dx_cv_bison_api_header_include], [dx_cv_bison_api_header_include=no
57 cat >conftest.y <<'EOF'
59 int yylex(void) { return 0; }
60 void yyerror(const char *msg) { }
65 rm -f conftest.[[123].[ch]]
69 [1], [$BISON -o conftest.1.c --defines=conftest.1.h conftest.y >&AS_MESSAGE_LOG_FD 2>&1|| break],
70 [2], [$BISON -o conftest.2.c --define=api.header.include='{"conftest.3.h"}' --defines=conftest.2.h conftest.y >&AS_MESSAGE_LOG_FD 2>&1 || break],
71 [3], [mv conftest.2.c conftest.3.c; mv conftest.2.h conftest.3.h])
72 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include "conftest.$dx_pass.c"]])],
73 [test $dx_pass -ne 2 || break], [test $dx_pass -eq 2 || break])
74 test $dx_pass -ne 3 || dx_cv_bison_api_header_include=yes
78 AC_CACHE_CHECK([whether $BISON wants -Wno-deprecated],
79 [dx_cv_bison_warn_no_deprecated], [dx_cv_bison_warn_no_deprecated=no
80 cat >conftest.y <<'EOF'
83 int yylex(void) { return 0; }
84 void yyerror(const char *msg) { }
89 AS_IF([$BISON -Werror conftest.y >&AS_MESSAGE_LOG_FD 2>&1], [],
90 [AS_IF([$BISON -Werror -Wno-deprecated conftest.y >&AS_MESSAGE_LOG_FD 2>&1],
91 [dx_cv_bison_warn_no_deprecated=yes])])
92 ])], [dx_cv_bison_define_cmdline=no
93 dx_cv_bison_api_header_include=no
94 dx_cv_bison_warn_no_deprecated=no])])