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