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