]> git.draconx.ca Git - dxcommon.git/blob - m4/bison-compat.m4
DX_C_ALIGNAS: Work around bash-5 parsing bug.
[dxcommon.git] / m4 / bison-compat.m4
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.
5
6 dnl DX_BISON_COMPAT
7 dnl
8 dnl Checks $BISON for various options that may be required for compatibility
9 dnl with multiple versions.  Currently tested features:
10 dnl
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
13 dnl be set to "no".
14 dnl
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".
19 dnl
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".
23
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'
32 %{
33 int yylex(void) { return 0; }
34 void yyerror(const char *msg) { }
35 %}
36 %%
37 input:
38 %%
39 int main(void) { return yylval; }
40 EOF
41
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])])])])])
50 ])
51
52 AS_IF([test x"$dx_cv_bison_define_cmdline" != x"yes"],
53   [dx_cv_bison_api_header_include=no])
54
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'
58 %{
59 int yylex(void) { return 0; }
60 void yyerror(const char *msg) { }
61 %}
62 %%
63 input:
64 EOF
65 rm -f conftest.[[123].[ch]]
66 for dx_pass in 1 2 3
67 do
68   AS_CASE([$dx_pass],
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
75 done
76 ])
77
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'
81 %error-verbose
82 %{
83 int yylex(void) { return 0; }
84 void yyerror(const char *msg) { }
85 %}
86 %%
87 input:
88 EOF
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])])