tests: avoid useless variables
[bison.git] / configure.ac
blob08ea7cdf92ef2fa20ba999d59c7fe172dfaf222f
1 # Configure template for GNU Bison.                   -*-Autoconf-*-
3 # Copyright (C) 2001-2015, 2018-2022 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], [2022])
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 # Gnulib uses '#pragma GCC diagnostic push' to silence some
59 # warnings, but older gcc doesn't support this.
60 AC_CACHE_CHECK([whether pragma GCC diagnostic push works],
61   [lv_cv_gcc_pragma_push_works], [
62   save_CFLAGS=$CFLAGS
63   CFLAGS='-Wunknown-pragmas -Werror'
64   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
65     #pragma GCC diagnostic push
66     #pragma GCC diagnostic pop
67   ]])],
68   [lv_cv_gcc_pragma_push_works=yes],
69   [lv_cv_gcc_pragma_push_works=no])
70   CFLAGS=$save_CFLAGS])
72 AC_LANG_PUSH([C++])
73 gl_WARN_ADD([-fno-exceptions], [NO_EXCEPTIONS_CXXFLAGS])
74 BISON_CXXSTD([98])
75 BISON_CXXSTD([03])
76 BISON_CXXSTD([11])
77 BISON_CXXSTD([14])
78 BISON_CXXSTD([17])
79 BISON_CXXSTD([20])
80 BISON_CXXSTD([2b])
81 AM_CONDITIONAL([ENABLE_CXX11], [test x"$CXX11_CXXFLAGS" != x])
82 AM_CONDITIONAL([ENABLE_CXX14], [test x"$CXX14_CXXFLAGS" != x])
83 AC_LANG_POP([C++])
85 AC_ARG_ENABLE([gcc-warnings],
86 [  --enable-gcc-warnings   turn on lots of GCC warnings (not recommended).
87                            Also, issue synclines from the examples/ to
88                            the corresponding source in the Texinfo doc.],
89 [case $enable_gcc_warnings in
90    yes|no) ;;
91    *)  AC_MSG_ERROR([invalid value for --gcc-warnings: $enable_gcc_warnings]);;
92  esac],
93               [enable_gcc_warnings=no])
94 AM_CONDITIONAL([ENABLE_GCC_WARNINGS], [test "$enable_gcc_warnings" = yes])
95 if test "$enable_gcc_warnings" = yes; then
96   # -Wno-tautological-constant-out-of-range-compare for Clang 3.3 and
97   # 3.4 on GNU/Linux that choke on intprops.h's INT_MULTIPLY_WRAPV,
98   # etc.
99   #
100   # ICC: -wr188
101   #
102   # 1669  warnings warnings_default =
103   # ../src/complain.c(318): error #188: enumerated type mixed with another type
104   # 1670      Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother;
105   # 1671      ^
106   # 1672
107   # 1673../src/complain.c(393): error #188: enumerated type mixed with another type
108   # 1674          warnings w = 1 << wbit;
109   # 1675                       ^
110   #
111   # ICC: -wr3179
112   #
113   # char const *usefulness
114   #   = rule_useless_in_grammar_p (&rules[r]) ? "useless-in-grammar"
115   #   : rule_useless_in_parser_p (&rules[r])  ? "useless-in-parser"
116   #   :                                         "useful";
117   #
118   # gives
119   #
120   # error #3179: deprecated conversion of string literal to char* (should be const char*)
121   #
122   # ICC: -wr2259 (that's in C, in spite of what the error messages which seems to be about C++).
123   # error #2259: non-pointer conversion from "int" to "yybool={signed char}" may lose significant bits
124   #   yybool yynormal YY_ATTRIBUTE_UNUSED = yystackp->yysplitPoint == YY_NULLPTR;
125   #                                         ^
126   warn_common='-Wall -Wextra
127     -Wcast-align -Wchar-subscripts
128     -fparse-all-comments -Wdocumentation
129     -Wformat -Wimplicit-fallthrough -Wmismatched-dealloc -Wnull-dereference
130     -Wno-sign-compare -Wno-tautological-constant-out-of-range-compare
131     -Wpointer-arith -Wshadow -Wstrict-aliasing
132     -Wunused-but-set-variable
133     -Wwrite-strings
134     -wr188 -wr2259 -wr3179'
135   warn_c='-Wbad-function-cast
136     -Wmissing-prototypes
137     -Wstrict-prototypes'
138   warn_cxx='-Wextra-semi -Wnoexcept -Wsubobject-linkage
139     -Wold-style-cast -Wundefined-func-template
140     -Wweak-vtables'
141   # Warnings for the test suite only.
142   #
143   # -fno-color-diagnostics: Clang's use of colors in the error
144   # messages is confusing the tests looking at the compiler's output
145   # (e.g., synclines.at).
146   #
147   # -Wno-keyword-macro: We use the "#define private public" dirty
148   # trick in the test suite to check some private implementation
149   # details for lalr1.cc.
150   warn_tests='-Wundef -pedantic -Wconversion
151     -Wdeprecated -Wsign-compare -Wsign-conversion
152     -Wtautological-constant-out-of-range-compare
153     -fno-color-diagnostics
154     -Wno-keyword-macro'
157   AC_LANG_PUSH([C])
158   # Clang supports many of GCC's -W options, but only issues warnings
159   # on the ones it does not recognize.  In that case, gl_WARN_ADD
160   # thinks the option is supported, and unknown options are then added
161   # to CFLAGS.  But then, when -Werror is added in the test suite for
162   # instance, the warning about the unknown option turns into an
163   # error.
164   #
165   # This should be addressed by gnulib's gl_WARN_ADD, but in the
166   # meanwhile, turn warnings about unknown options into errors in
167   # CFLAGS, and restore CFLAGS after the tests.
168   save_CFLAGS=$CFLAGS
169   gl_WARN_ADD([-Werror=unknown-warning-option], [CFLAGS])
170   # Accept this warning only if it is not too touchy (e.g., clang 3.3
171   # and 3.4).
172   gl_WARN_ADD([-Wunreachable-code], [WARN_CFLAGS],
173               [AC_LANG_PROGRAM([],
174               [[if (sizeof (long) < sizeof (int)) return 1;]])])
175   for i in $warn_common $warn_c;
176   do
177     gl_WARN_ADD([$i], [WARN_CFLAGS])
178   done
179   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
181   # Warnings for the test suite, and maybe for bison if GCC is modern
182   # enough.
183   test $lv_cv_gcc_pragma_push_works = yes &&
184     AS_VAR_APPEND([WARN_CFLAGS], [" $WARN_CFLAGS_TEST"])
186   # Warnings for the test suite only.
187   for i in $warn_tests -Wincompatible-pointer-types;
188   do
189     gl_WARN_ADD([$i], [WARN_CFLAGS_TEST])
190   done
191   CFLAGS=$save_CFLAGS
192   AC_LANG_POP([C])
195   AC_LANG_PUSH([C++])
196   save_CXXFLAGS=$CXXFLAGS
197   gl_WARN_ADD([-Werror=unknown-warning-option], [CXXFLAGS])
198   for i in $warn_common $warn_cxx;
199   do
200     gl_WARN_ADD([$i], [WARN_CXXFLAGS])
201   done
202   # Accept this warning only if it is not too touchy (e.g., clang 3.3
203   # and 3.4).
204   gl_WARN_ADD([-Wunreachable-code], [WARN_CXXFLAGS],
205               [AC_LANG_PROGRAM([],
206               [[if (sizeof (long) < sizeof (int)) return 1;]])])
207   gl_WARN_ADD([-Wzero-as-null-pointer-constant], [WARN_CXXFLAGS],
208               [AC_LANG_PROGRAM([], [nullptr])])
209   # Before GCC6, the pragmas don't work well enough to neutralize
210   # this warning.
211   gl_WARN_ADD([-Wuseless-cast], [WARN_CXXFLAGS],
212               [AC_LANG_PROGRAM([], [
213               #if defined __GNUC__ && ! defined __ICC && ! defined __clang__ && __GNUC__ < 6
214               syntax error
215               #endif
216               ])])
217   gl_WARN_ADD([-Werror], [WERROR_CXXFLAGS])
218   # Warnings for the test suite only.
219   for i in $warn_tests;
220   do
221     gl_WARN_ADD([$i], [WARN_CXXFLAGS_TEST])
222   done
223   # Too many compilers complain about Flex generated code.
224   gl_WARN_ADD([-Wno-error], [FLEX_SCANNER_CXXFLAGS])
225   # Clang++ deprecates compiling C.
226   gl_WARN_ADD([-Wno-deprecated], [WNO_DEPRECATED_CXXFLAGS])
227   CXXFLAGS=$save_CXXFLAGS
228   AC_LANG_POP([C++])
232 BISON_TEST_FOR_WORKING_C_COMPILER
233 BISON_C_COMPILER_POSIXLY_CORRECT
234 BISON_TEST_FOR_WORKING_CXX_COMPILER
235 BISON_CXX_COMPILER_POSIXLY_CORRECT
237 # D.
238 AC_CHECK_PROGS([DC], [dmd])
239 AC_CHECK_PROGS([DCFLAGS], [-g])
240 AM_CONDITIONAL([ENABLE_D], [test x"$DC" != x])
242 # Java.
243 gt_JAVACOMP([1.7], [1.7])
244 gt_JAVAEXEC
245 AM_CONDITIONAL([ENABLE_JAVA], [test x"$CONF_JAVAC" != x && test x"$CONF_JAVA" != x])
248 AC_ARG_ENABLE([yacc],
249   [AS_HELP_STRING([--disable-yacc],
250      [do not build a yacc command or an -ly library])],
251   , [enable_yacc=yes])
252 AM_CONDITIONAL([ENABLE_YACC], [test "$enable_yacc" = yes])
253 AC_CONFIG_FILES([src/yacc], [chmod +x src/yacc])
255 # Checks for programs.
256 AM_MISSING_PROG([DOT], [dot])
257 AC_PROG_LEX
258 if ! "$LEX_IS_FLEX" || test "X$LEX" = X:; then
259   AC_MSG_WARN([bypassing lex because flex is required])
260   LEX=:
262 AM_CONDITIONAL([FLEX_WORKS], [$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT])
263 AM_CONDITIONAL([FLEX_CXX_WORKS],
264   [$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT && test $bison_cv_cxx_works = yes])
265 AC_PROG_YACC
266 AC_PROG_RANLIB
267 AC_PROG_GNU_M4
268 AC_DEFINE_UNQUOTED([M4], ["$M4"], [Define to the GNU M4 executable name.])
269 AC_DEFINE_UNQUOTED([M4_GNU_OPTION], ["$M4_GNU"], [Define to "-g" if GNU M4
270 supports -g, otherwise to "".])
271 AC_PATH_PROG([PERL], [perl])
272 AM_MISSING_PROG([HELP2MAN], [help2man])
273 AC_PATH_PROG([XSLTPROC], [xsltproc])
274 AC_SUBST([XSLTPROC])
276 # Checks for header files.
277 AC_CHECK_HEADERS_ONCE([locale.h])
279 # Checks for compiler characteristics.
280 AC_C_INLINE
282 # Gnulib (later checks).  Putting them here rather than right after
283 # gl_EARLY avoids some redundant checks.
284 gl_INIT
286 # We want ostream_printf and hyperlink support.
287 gl_LIBTEXTSTYLE_OPTIONAL([0.20.5])
289 # Checks for library functions.
290 AC_CHECK_FUNCS_ONCE([setlocale])
292 # Gettext.
293 # We use gnulib, which is only guaranteed to work properly with the
294 # latest Gettext.
295 AM_GNU_GETTEXT([external], [need-ngettext])
296 AM_GNU_GETTEXT_VERSION([0.19])
297 BISON_I18N
298 AC_CONFIG_FILES([gnulib-po/Makefile.in])
300 # Internationalized parsers.
301 AC_CONFIG_FILES([runtime-po/Makefile.in])
302 # Autoconf macros for packages using internationalized parsers.
303 aclocaldir='${datadir}/aclocal'
304 AC_SUBST([aclocaldir])
306 # Create the benchmark script.
307 AC_CONFIG_FILES([etc/bench.pl], [chmod +x etc/bench.pl])
309 # Initialize the test suite.
310 AC_CONFIG_TESTDIR(tests)
311 AC_CONFIG_FILES([tests/atlocal])
312 AC_CONFIG_FILES([tests/bison], [chmod +x tests/bison])
314 AC_CHECK_PROGS([VALGRIND], [valgrind])
315 # Use something simpler that $host_os to select our suppression file.
316 uname=`uname`
317 case $VALGRIND:$uname in
318   '':*) ;;
319   *:Darwin)
320     # See README-hacking.md.
321     VALGRIND=;;
322   *:*)
323     suppfile=build-aux/$uname.valgrind
324     if test -f "$srcdir/$suppfile"; then
325       AC_SUBST([VALGRIND_OPTS_SUPPRESSION],
326                ["--suppressions=\$(abs_top_srcdir)/$suppfile"])
327     fi
328     ;;
329 esac
330 AC_MSG_CHECKING([Valgrind suppression file])
331 AC_MSG_RESULT([$suppfile])
333 # Whether we cannot run the compiled bison.
334 AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
336 # Build bistromathic if we have the lib and both readline/readline.h
337 # and readline/history.h.
338 AM_CONDITIONAL([ENABLE_BISTROMATHIC],
339 [test "$gl_cv_lib_readline" != no &&
340   test "$ac_cv_header_readline_readline_h" = yes &&
341   test "$ac_cv_header_readline_history_h" = yes])
343 AM_MISSING_PROG([AUTOM4TE], [autom4te])
344 # Needed by tests/atlocal.in.
345 AC_SUBST([GCC])
347 AC_CONFIG_FILES([Makefile
348                  po/Makefile.in
349                  doc/yacc.1])
351 # Fix LIBOBJS to give the Makefile the right file names.  Otherwise
352 # compilation works, but with unexpected file names, so clean rules don't
353 # remove the actual files and distcheck fails.
354 AC_CONFIG_COMMANDS_PRE([
355   case $am__api_version in
356     1.14*|1.15*) gl_LIBOBJS=`echo "$gl_LIBOBJS" | sed -e 's, lib/, lib/lib_libbison_a-,g'`;;
357     *)           gl_LIBOBJS=`echo "$gl_LIBOBJS" | sed -e 's, lib/, lib/libbison_a-,g'`;;
358   esac
361 AC_OUTPUT