glr2.cc: put glr_state_set and glr_stack_item in unnamed namespace
[bison.git] / configure.ac
blob7f6133ebf228823ea7227308cd36c6c2696bb0e4
1 # Configure template for GNU Bison.                   -*-Autoconf-*-
3 # Copyright (C) 2001-2015, 2018-2021 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 AC_PREREQ([2.71])
19 m4_pattern_forbid([^_?(gl_[A-Z]|AX_|BISON_)])
20 m4_pattern_allow([^BISON_USE_NLS$])
22 AC_INIT([GNU Bison],
23         m4_esyscmd([build-aux/git-version-gen .tarball-version]),
24         [bug-bison@gnu.org],
25         [],
26         [https://www.gnu.org/software/bison/])
27 AC_SUBST([PACKAGE_COPYRIGHT_YEAR], [2021])
28 AC_DEFINE_UNQUOTED([PACKAGE_COPYRIGHT_YEAR], [$PACKAGE_COPYRIGHT_YEAR],
29                    [The copyright year for this package])
31 AC_CONFIG_AUX_DIR([build-aux])
32 AC_CONFIG_MACRO_DIR([m4])
34 # When we move to Automake 1.16, simplify examples/c/reccalc/local.mk.
35 # Our CI build the packages on Bionic, which has only Automake 1.15.
37 # We want gnits strictness only when rolling a stable release.  For
38 # release candidates, we use version strings like 2.4.3_rc1, but gnits
39 # doesn't like that, so we let the underscore disable gnits.  Between
40 # releases, we want to be able run make dist without being required to
41 # add a bogus NEWS entry.  In that case, the version string
42 # automatically contains a dash, which we also let disable gnits.
43 AM_INIT_AUTOMAKE([1.15 dist-lzip dist-xz nostdinc
44                  color-tests parallel-tests
45                  silent-rules]
46                  m4_bmatch(m4_defn([AC_PACKAGE_VERSION]), [[-_]],
47                            [gnu], [gnits]))
48 AM_SILENT_RULES([yes])
49 AC_CONFIG_HEADERS([lib/config.h:lib/config.in.h])
51 # Checks for the compiler.
52 AC_PROG_CC
53 AC_PROG_CXX
55 # Gnulib (early checks).
56 gl_EARLY
58 # We want ostream_printf and hyperlink support.
59 gl_LIBTEXTSTYLE_OPTIONAL([0.20.5])
61 # Gnulib uses '#pragma GCC diagnostic push' to silence some
62 # warnings, but older gcc doesn't support this.
63 AC_CACHE_CHECK([whether pragma GCC diagnostic push works],
64   [lv_cv_gcc_pragma_push_works], [
65   save_CFLAGS=$CFLAGS
66   CFLAGS='-Wunknown-pragmas -Werror'
67   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
68     #pragma GCC diagnostic push
69     #pragma GCC diagnostic pop
70   ]])],
71   [lv_cv_gcc_pragma_push_works=yes],
72   [lv_cv_gcc_pragma_push_works=no])
73   CFLAGS=$save_CFLAGS])
75 AC_LANG_PUSH([C++])
76 gl_WARN_ADD([-fno-exceptions], [NO_EXCEPTIONS_CXXFLAGS])
77 BISON_CXXSTD([98])
78 BISON_CXXSTD([03])
79 BISON_CXXSTD([11])
80 BISON_CXXSTD([14])
81 BISON_CXXSTD([17])
82 BISON_CXXSTD([20])
83 BISON_CXXSTD([2b])
84 AM_CONDITIONAL([ENABLE_CXX11], [test x"$CXX11_CXXFLAGS" != x])
85 AM_CONDITIONAL([ENABLE_CXX14], [test x"$CXX14_CXXFLAGS" != x])
86 AC_LANG_POP([C++])
88 AC_ARG_ENABLE([gcc-warnings],
89 [  --enable-gcc-warnings   turn on lots of GCC warnings (not recommended).
90                            Also, issue synclines from the examples/ to
91                            the corresponding source in the Texinfo doc.],
92 [case $enable_gcc_warnings in
93    yes|no) ;;
94    *)  AC_MSG_ERROR([invalid value for --gcc-warnings: $enable_gcc_warnings]);;
95  esac],
96               [enable_gcc_warnings=no])
97 AM_CONDITIONAL([ENABLE_GCC_WARNINGS], [test "$enable_gcc_warnings" = yes])
98 if test "$enable_gcc_warnings" = yes; then
99   # -Wno-tautological-constant-out-of-range-compare for Clang 3.3 and
100   # 3.4 on GNU/Linux that choke on intprops.h's INT_MULTIPLY_WRAPV,
101   # etc.
102   #
103   # ICC: -wr188
104   #
105   # 1669  warnings warnings_default =
106   # ../src/complain.c(318): error #188: enumerated type mixed with another type
107   # 1670      Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother;
108   # 1671      ^
109   # 1672
110   # 1673../src/complain.c(393): error #188: enumerated type mixed with another type
111   # 1674          warnings w = 1 << wbit;
112   # 1675                       ^
113   #
114   # ICC: -wr3179
115   #
116   # char const *usefulness
117   #   = rule_useless_in_grammar_p (&rules[r]) ? "useless-in-grammar"
118   #   : rule_useless_in_parser_p (&rules[r])  ? "useless-in-parser"
119   #   :                                         "useful";
120   #
121   # gives
122   #
123   # error #3179: deprecated conversion of string literal to char* (should be const char*)
124   #
125   # ICC: -wr2259 (that's in C, in spite of what the error messages which seems to be about C++).
126   # error #2259: non-pointer conversion from "int" to "yybool={signed char}" may lose significant bits
127   #   yybool yynormal YY_ATTRIBUTE_UNUSED = yystackp->yysplitPoint == YY_NULLPTR;
128   #                                         ^
129   warn_common='-Wall -Wextra
130     -Wcast-align -Wchar-subscripts
131     -fparse-all-comments -Wdocumentation
132     -Wformat -Wimplicit-fallthrough -Wmismatched-dealloc -Wnull-dereference
133     -Wno-sign-compare -Wno-tautological-constant-out-of-range-compare
134     -Wpointer-arith -Wshadow -Wstrict-aliasing
135     -Wwrite-strings
136     -wr188 -wr2259 -wr3179'
137   warn_c='-Wbad-function-cast
138     -Wmissing-prototypes
139     -Wstrict-prototypes'
140   warn_cxx='-Wextra-semi -Wnoexcept -Wold-style-cast -Wundefined-func-template
141     -Wweak-vtables'
142   # Warnings for the test suite only.
143   #
144   # -fno-color-diagnostics: Clang's use of colors in the error
145   # messages is confusing the tests looking at the compiler's output
146   # (e.g., synclines.at).
147   #
148   # -Wno-keyword-macro: We use the "#define private public" dirty
149   # trick in the test suite to check some private implementation
150   # details for lalr1.cc.
151   warn_tests='-Wundef -pedantic -Wconversion
152     -Wdeprecated -Wsign-compare -Wsign-conversion
153     -Wtautological-constant-out-of-range-compare
154     -fno-color-diagnostics
155     -Wno-keyword-macro'
158   AC_LANG_PUSH([C])
159   # Clang supports many of GCC's -W options, but only issues warnings
160   # on the ones it does not recognize.  In that case, gl_WARN_ADD
161   # thinks the option is supported, and unknown options are then added
162   # to CFLAGS.  But then, when -Werror is added in the test suite for
163   # instance, the warning about the unknown option turns into an
164   # error.
165   #
166   # This should be addressed by gnulib's gl_WARN_ADD, but in the
167   # meanwhile, turn warnings about unknown options into errors in
168   # CFLAGS, and restore CFLAGS after the tests.
169   save_CFLAGS=$CFLAGS
170   gl_WARN_ADD([-Werror=unknown-warning-option], [CFLAGS])
171   # Accept this warning only if it is not too touchy (e.g., clang 3.3
172   # and 3.4).
173   gl_WARN_ADD([-Wunreachable-code], [WARN_CFLAGS],
174               [AC_LANG_PROGRAM([],
175               [[if (sizeof (long) < sizeof (int)) return 1;]])])
176   for i in $warn_common $warn_c;
177   do
178     gl_WARN_ADD([$i], [WARN_CFLAGS])
179   done
180   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
182   # Warnings for the test suite, and maybe for bison if GCC is modern
183   # enough.
184   test $lv_cv_gcc_pragma_push_works = yes &&
185     AS_VAR_APPEND([WARN_CFLAGS], [" $WARN_CFLAGS_TEST"])
187   # Warnings for the test suite only.
188   for i in $warn_tests -Wincompatible-pointer-types;
189   do
190     gl_WARN_ADD([$i], [WARN_CFLAGS_TEST])
191   done
192   CFLAGS=$save_CFLAGS
193   AC_LANG_POP([C])
196   AC_LANG_PUSH([C++])
197   save_CXXFLAGS=$CXXFLAGS
198   gl_WARN_ADD([-Werror=unknown-warning-option], [CXXFLAGS])
199   for i in $warn_common $warn_cxx;
200   do
201     gl_WARN_ADD([$i], [WARN_CXXFLAGS])
202   done
203   # Accept this warning only if it is not too touchy (e.g., clang 3.3
204   # and 3.4).
205   gl_WARN_ADD([-Wunreachable-code], [WARN_CXXFLAGS],
206               [AC_LANG_PROGRAM([],
207               [[if (sizeof (long) < sizeof (int)) return 1;]])])
208   gl_WARN_ADD([-Wzero-as-null-pointer-constant], [WARN_CXXFLAGS],
209               [AC_LANG_PROGRAM([], [nullptr])])
210   # Before GCC6, the pragmas don't work well enough to neutralize
211   # this warning.
212   gl_WARN_ADD([-Wuseless-cast], [WARN_CXXFLAGS],
213               [AC_LANG_PROGRAM([], [
214               #if defined __GNUC__ && ! defined __ICC && ! defined __clang__ && __GNUC__ < 6
215               syntax error
216               #endif
217               ])])
218   gl_WARN_ADD([-Werror], [WERROR_CXXFLAGS])
219   # Warnings for the test suite only.
220   for i in $warn_tests;
221   do
222     gl_WARN_ADD([$i], [WARN_CXXFLAGS_TEST])
223   done
224   # Too many compilers complain about Flex generated code.
225   gl_WARN_ADD([-Wno-error], [FLEX_SCANNER_CXXFLAGS])
226   # Clang++ deprecates compiling C.
227   gl_WARN_ADD([-Wno-deprecated], [WNO_DEPRECATED_CXXFLAGS])
228   CXXFLAGS=$save_CXXFLAGS
229   AC_LANG_POP([C++])
233 BISON_TEST_FOR_WORKING_C_COMPILER
234 BISON_C_COMPILER_POSIXLY_CORRECT
235 BISON_TEST_FOR_WORKING_CXX_COMPILER
236 BISON_CXX_COMPILER_POSIXLY_CORRECT
238 # D.
239 AC_CHECK_PROGS([DC], [dmd])
240 AC_CHECK_PROGS([DCFLAGS], [-g])
241 AM_CONDITIONAL([ENABLE_D], [test x"$DC" != x])
243 # Java.
244 gt_JAVACOMP([1.7], [1.7])
245 gt_JAVAEXEC
246 AM_CONDITIONAL([ENABLE_JAVA], [test x"$CONF_JAVAC" != x && test x"$CONF_JAVA" != x])
249 AC_ARG_ENABLE([yacc],
250   [AS_HELP_STRING([--disable-yacc],
251      [do not build a yacc command or an -ly library])],
252   , [enable_yacc=yes])
253 AM_CONDITIONAL([ENABLE_YACC], [test "$enable_yacc" = yes])
254 AC_CONFIG_FILES([src/yacc], [chmod +x src/yacc])
256 # Checks for programs.
257 AM_MISSING_PROG([DOT], [dot])
258 AC_PROG_LEX
259 if ! "$LEX_IS_FLEX" || test "X$LEX" = X:; then
260   AC_MSG_WARN([bypassing lex because flex is required])
261   LEX=:
263 AM_CONDITIONAL([FLEX_WORKS], [$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT])
264 AM_CONDITIONAL([FLEX_CXX_WORKS],
265   [$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT && test $bison_cv_cxx_works = yes])
266 AC_PROG_YACC
267 AC_PROG_RANLIB
268 AC_PROG_GNU_M4
269 AC_DEFINE_UNQUOTED([M4], ["$M4"], [Define to the GNU M4 executable name.])
270 AC_DEFINE_UNQUOTED([M4_GNU_OPTION], ["$M4_GNU"], [Define to "-g" if GNU M4
271 supports -g, otherwise to "".])
272 AC_PATH_PROG([PERL], [perl])
273 AM_MISSING_PROG([HELP2MAN], [help2man])
274 AC_PATH_PROG([XSLTPROC], [xsltproc])
275 AC_SUBST([XSLTPROC])
277 # Checks for header files.
278 AC_CHECK_HEADERS_ONCE([locale.h])
280 # Checks for compiler characteristics.
281 AC_C_INLINE
283 # Gnulib (later checks).  Putting them here rather than right after
284 # gl_EARLY avoids some redundant checks.
285 gl_INIT
287 # Checks for library functions.
288 AC_CHECK_FUNCS_ONCE([setlocale])
290 # Gettext.
291 # We use gnulib, which is only guaranteed to work properly with the
292 # latest Gettext.
293 AM_GNU_GETTEXT([external], [need-ngettext])
294 AM_GNU_GETTEXT_VERSION([0.19])
295 BISON_I18N
296 AC_CONFIG_FILES([gnulib-po/Makefile.in])
298 # Internationalized parsers.
299 AC_CONFIG_FILES([runtime-po/Makefile.in])
300 # Autoconf macros for packages using internationalized parsers.
301 aclocaldir='${datadir}/aclocal'
302 AC_SUBST([aclocaldir])
304 # Create the benchmark script.
305 AC_CONFIG_FILES([etc/bench.pl], [chmod +x etc/bench.pl])
307 # Initialize the test suite.
308 AC_CONFIG_TESTDIR(tests)
309 AC_CONFIG_FILES([tests/atlocal])
310 AC_CONFIG_FILES([tests/bison], [chmod +x tests/bison])
312 AC_CHECK_PROGS([VALGRIND], [valgrind])
313 # Use something simpler that $host_os to select our suppression file.
314 uname=`uname`
315 case $VALGRIND:$uname in
316   '':*) ;;
317   *:Darwin)
318     # See README-hacking.md.
319     VALGRIND=;;
320   *:*)
321     suppfile=build-aux/$uname.valgrind
322     if test -f "$srcdir/$suppfile"; then
323       AC_SUBST([VALGRIND_OPTS_SUPPRESSION],
324                ["--suppressions=\$(abs_top_srcdir)/$suppfile"])
325     fi
326     ;;
327 esac
328 AC_MSG_CHECKING([Valgrind suppression file])
329 AC_MSG_RESULT([$suppfile])
331 # Whether we cannot run the compiled bison.
332 AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
334 # Build bistromathic if we have the lib and both readline/readline.h
335 # and readline/history.h.
336 AM_CONDITIONAL([ENABLE_BISTROMATHIC],
337 [test "$gl_cv_lib_readline" != no &&
338   test "$ac_cv_header_readline_readline_h" = yes &&
339   test "$ac_cv_header_readline_history_h" = yes])
341 AM_MISSING_PROG([AUTOM4TE], [autom4te])
342 # Needed by tests/atlocal.in.
343 AC_SUBST([GCC])
345 AC_CONFIG_FILES([Makefile
346                  po/Makefile.in
347                  doc/yacc.1])
349 # Fix LIBOBJS to give the Makefile the right file names.  Otherwise
350 # compilation works, but with unexpected file names, so clean rules don't
351 # remove the actual files and distcheck fails.
352 AC_CONFIG_COMMANDS_PRE([
353   case $am__api_version in
354     1.14*|1.15*) gl_LIBOBJS=`echo "$gl_LIBOBJS" | sed -e 's, lib/, lib/lib_libbison_a-,g'`;;
355     *)           gl_LIBOBJS=`echo "$gl_LIBOBJS" | sed -e 's, lib/, lib/libbison_a-,g'`;;
356   esac
359 AC_OUTPUT