configure: Enable GCC warnings to report use of C2x features.
[pspp] / acinclude.m4
1 dnl Copyright (C) 2005, 2006, 2007, 2009, 2014, 2015, 2021 Free Software Foundation, Inc.
2 dnl This file is free software; the Free Software Foundation
3 dnl gives unlimited permission to copy and/or distribute it,
4 dnl with or without modifications, as long as this notice is preserved.
5
6 dnl Prerequisites.
7
8 dnl Summarize all the missing prerequisites at the end of the run to
9 dnl increase user-friendliness.
10 AC_DEFUN([PSPP_REQUIRED_PREREQ],
11   [AC_MSG_WARN([You must install $1 before building PSPP.])
12 pspp_required_prereqs="$pspp_required_prereqs
13         $1"])
14 AC_DEFUN([PSPP_OPTIONAL_PREREQ], [pspp_optional_prereqs="$pspp_optional_prereqs
15         $1"])
16 AC_DEFUN([PSPP_CHECK_PREREQS],
17 [
18   if test "$pspp_optional_prereqs" != ""; then
19     AC_MSG_WARN([The following optional packages are not installed.
20 You may wish to install them to obtain additional functionality:$pspp_optional_prereqs])
21 fi
22   if test "$pspp_required_prereqs" != ""; then
23     AC_MSG_ERROR([The following required packages are not installed.
24 You must install them before PSPP can be built:$pspp_required_prereqs])
25 fi
26 ])
27
28
29 dnl Check that a new enough version of Perl is available.
30 AC_DEFUN([PSPP_PERL],
31 [
32   AC_PATH_PROG([PERL], perl, no)
33   AC_SUBST([PERL])dnl
34   if test "$PERL" != no && $PERL -e 'require 5.005_03;'; then :; else
35     PSPP_REQUIRED_PREREQ([Perl 5.005_03 (or later)])
36   fi
37
38   # The PSPP autobuilder appends a build number to the PSPP version number,
39   # e.g. "0.7.2-build40".  But Perl won't parse version numbers that contain
40   # anything other than digits and periods, so "-build" causes an error.  So we
41   # define $(VERSION_FOR_PERL) that drops everything from the hyphen onward.
42   VERSION_FOR_PERL=`echo "$VERSION" | sed 's/-.*//'`
43   AC_SUBST([VERSION_FOR_PERL])
44 ])
45
46 dnl Check that Python 2 or 3 is available.
47 AC_DEFUN([PSPP_PYTHON],
48   [AC_ARG_VAR([PYTHON], [Python 2 or 3 interpreter])
49    AC_CHECK_PROGS([PYTHON], [python python2 python3], [none])])
50
51 dnl PSPP_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
52 dnl Check whether the given C compiler OPTION is accepted.
53 dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
54 AC_DEFUN([PSPP_CHECK_CC_OPTION],
55 [
56   m4_define([pspp_cv_name], [pspp_cv_[]m4_translit([$1], [-], [_])])dnl
57   AC_CACHE_CHECK([whether $CC accepts $1], [pspp_cv_name],
58     [pspp_save_CFLAGS="$CFLAGS"
59      CFLAGS="$CFLAGS $1"
60      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [pspp_cv_name[]=yes], [pspp_cv_name[]=no])
61      CFLAGS="$pspp_save_CFLAGS"])
62   if test $pspp_cv_name = yes; then
63     m4_if([$2], [], [;], [$2])
64   else
65     m4_if([$3], [], [:], [$3])
66   fi
67 ])
68
69 # PSPP_ENABLE_OPTION comes from Open vSwitch:
70 # ----------------------------------------------------------------------
71 # Copyright (c) 2007-2017 Nicira, Inc.
72 #
73 # Licensed under the Apache License, Version 2.0 (the "License");
74 # you may not use this file except in compliance with the License.
75 # You may obtain a copy of the License at:
76 #
77 #     http://www.apache.org/licenses/LICENSE-2.0
78 #
79 # Unless required by applicable law or agreed to in writing, software
80 # distributed under the License is distributed on an "AS IS" BASIS,
81 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
82 # See the License for the specific language governing permissions and
83 # limitations under the License.
84 dnl PSPP_ENABLE_OPTION([OPTION])
85 dnl Check whether the given C compiler OPTION is accepted.
86 dnl If so, add it to WARNING_FLAGS.
87 dnl Example: PSPP_ENABLE_OPTION([-Wdeclaration-after-statement])
88 AC_DEFUN([PSPP_ENABLE_OPTION],
89   [PSPP_CHECK_CC_OPTION([$1], [WARNING_FLAGS="$WARNING_FLAGS $1"])
90    AC_SUBST([WARNING_FLAGS])])
91 # ----------------------------------------------------------------------
92
93 dnl Check for readline and history libraries.
94
95 dnl Modified for PSPP, based on readline.m4 serial 3 from
96 dnl gnulib, which was written by Simon Josefsson, with help from Bruno
97 dnl Haible and Oskar Liljeblad.
98
99 AC_DEFUN([PSPP_READLINE],
100 [
101   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
102   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
103   AC_REQUIRE([AC_LIB_RPATH])
104
105   dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
106   dnl INCREADLINE accordingly.
107   AC_LIB_LINKFLAGS_BODY([readline])
108   AC_LIB_LINKFLAGS_BODY([history])
109
110   dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
111   dnl because if the user has installed libreadline and not disabled its use
112   dnl via --without-libreadline-prefix, he wants to use it. The AC_LINK_IFELSE
113   dnl will then succeed.
114   am_save_CPPFLAGS="$CPPFLAGS"
115   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE $INCHISTORY])
116
117   AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
118     gl_cv_lib_readline=no
119     am_save_LIBS="$LIBS"
120     dnl On some systems, -lreadline doesn't link without an additional
121     dnl -lncurses or -ltermcap.
122     dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
123     dnl by design and obsolete since 1994. Try -lcurses last, because
124     dnl libcurses is unusable on some old Unices.
125     for extra_lib in "" ncurses termcap curses; do
126       LIBS="$am_save_LIBS $LIBREADLINE $LIBHISTORY"
127       if test -n "$extra_lib"; then
128         LIBS="$LIBS -l$extra_lib"
129       fi
130       AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
131 #include <readline/readline.h>
132 #include <readline/history.h>]], [[readline((char*)0); add_history((char*)0);]])],[gl_cv_lib_readline=yes],[])
133       if test "$gl_cv_lib_readline" = yes; then
134         if test -n "$extra_lib"; then
135           LIBREADLINE="$LIBREADLINE $LIBHISTORY -l$extra_lib"
136           LTLIBREADLINE="$LTLIBREADLINE $LTLIBHISTORY -l$extra_lib"
137         fi
138         break
139       fi
140     done
141     LIBS="$am_save_LIBS"
142   ])
143
144   if test "$gl_cv_lib_readline" = yes; then
145     AC_DEFINE([HAVE_READLINE], 1, [Define if you have the readline library.])
146     AC_MSG_CHECKING([how to link with libreadline])
147     AC_MSG_RESULT([$LIBREADLINE])
148     AC_SEARCH_LIBS([rl_echo_signal_char], [readline],
149         AC_DEFINE([HAVE_RL_ECHO_SIGNAL_CHAR], 1, [Define if the readline library provides rl_echo_signal_char.]),[],[$LIBREADLINE])
150     AC_SEARCH_LIBS([rl_outstream], [readline],
151         AC_DEFINE([HAVE_RL_OUTSTREAM], 1, [Define if the readline library provides rl_outstream.]),[],[$LIBREADLINE])
152   else
153     dnl If $LIBREADLINE didn't lead to a usable library, we don't
154     dnl need $INCREADLINE either.
155     CPPFLAGS="$am_save_CPPFLAGS"
156     LIBREADLINE=
157     LTLIBREADLINE=
158     LIBHISTORY=
159     LTLIBHISTORY=
160     PSPP_OPTIONAL_PREREQ([libreadline (which may itself require libncurses or libtermcap)])
161   fi
162   AC_SUBST(LIBREADLINE)
163   AC_SUBST(LTLIBREADLINE)
164 ])
165
166 dnl Check for LC_PAPER, _NL_PAPER_WIDTH, _NL_PAPER_HEIGHT.
167 AC_DEFUN([PSPP_LC_PAPER],
168 [AC_CACHE_CHECK(for LC_PAPER, pspp_cv_lc_paper, [
169     pspp_cv_lc_paper=no
170     AC_COMPILE_IFELSE(
171       [AC_LANG_PROGRAM(
172         [#include <locale.h>
173 #include <langinfo.h>
174 ],
175         [(void) LC_PAPER; (void) _NL_PAPER_WIDTH; (void) _NL_PAPER_HEIGHT])],
176       [pspp_cv_lc_paper=yes])
177   ])
178   if test "$pspp_cv_lc_paper" = yes; then
179     AC_DEFINE([HAVE_LC_PAPER], 1, [Define if you have LC_PAPER.])
180   fi
181 ])
182
183
184 # PSPP_LINK2_IFELSE(SOURCE1, SOURCE2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
185 # -------------------------------------------------------------
186 # Based on AC_LINK_IFELSE, but tries to link both SOURCE1 and SOURCE2
187 # into a program.
188 #
189 # Test that resulting file is executable; see the problem reported by mwoehlke
190 # in <http://lists.gnu.org/archive/html/bug-coreutils/2006-10/msg00048.html>.
191 # But skip the test when cross-compiling, to prevent problems like the one
192 # reported by Chris Johns in
193 # <http://lists.gnu.org/archive/html/autoconf/2007-03/msg00085.html>.
194 #
195 m4_define([PSPP_LINK2_IFELSE],
196 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
197 mv conftest.$ac_ext conftest1.$ac_ext
198 m4_ifvaln([$2], [AC_LANG_CONFTEST([$2])])dnl
199 mv conftest.$ac_ext conftest2.$ac_ext
200 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
201 pspp_link2='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest1.$ac_ext conftest2.$ac_ext $LIBS >&5'
202 AS_IF([_AC_DO_STDERR($pspp_link2) && {
203          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
204          test ! -s conftest.err
205        } && test -s conftest$ac_exeext && {
206          test "$cross_compiling" = yes ||
207          AS_TEST_X([conftest$ac_exeext])
208        }],
209       [$3],
210       [echo "$as_me: failed source file 1 of 2 was:" >&5
211 sed 's/^/| /' conftest1.$ac_ext >&5
212 echo "$as_me: failed source file 2 of 2 was:" >&5
213 sed 's/^/| /' conftest2.$ac_ext >&5
214         $4])
215 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
216 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
217 dnl as it would interfere with the next link command.
218 rm -rf conftest.dSYM conftest1.dSYM conftest2.dSYM
219 rm -f core conftest.err conftest1.err conftest2.err
220 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest*_ipa8_conftest*.oo
221 rm -f conftest$ac_exeext
222 rm -f m4_ifval([$1], [conftest1.$ac_ext]) m4_ifval([$2], [conftest1.$ac_ext])[]dnl
223 ])# PSPP_LINK2_IFELSE
224
225 # GSL uses "extern inline" without determining whether the compiler uses
226 # GCC inline rules or C99 inline rules.  If it uses the latter then GSL
227 # will be broken without passing -fgnu89-inline to GCC.
228 AC_DEFUN([PSPP_GSL_NEEDS_FGNU89_INLINE],
229 [# GSL only uses "inline" at all if HAVE_INLINE is defined as a macro.
230  # In turn, gnulib's gl_INLINE is one macro that does that.  We need to
231  # make sure that it has run by the time we run this test, otherwise we'll
232  # get a false result.
233  AC_REQUIRE([gl_INLINE])
234  PSPP_CHECK_CC_OPTION(
235    [-fgnu89-inline],
236    [AC_CACHE_CHECK([whether GSL needs -fgnu89-inline to link],
237                     pspp_cv_gsl_needs_fgnu89_inline, [
238                     PSPP_LINK2_IFELSE(
239                       [AC_LANG_PROGRAM([#include <gsl/gsl_math.h>
240                                        ], [GSL_MAX_INT(1,2);])],
241                       [AC_LANG_SOURCE([#include <gsl/gsl_math.h>
242                                        void x (void) {}])],
243                       [pspp_cv_gsl_needs_fgnu89_inline=no],
244                       [pspp_cv_gsl_needs_fgnu89_inline=yes])])
245      if test "$pspp_cv_gsl_needs_fgnu89_inline" = "yes"; then
246          CFLAGS="$CFLAGS -fgnu89-inline"
247      fi])
248 ])
249
250 AC_DEFUN([PSPP_CHECK_CLICKSEQUENCE],
251   [AC_REQUIRE([AM_INIT_AUTOMAKE])  # Defines MAKEINFO
252    AC_CACHE_CHECK([whether makeinfo supports @clicksequence],
253      [pspp_cv_have_clicksequence],
254      [cat > conftest.texi  <<EOF
255 @setfilename conftest.info
256 @clicksequence{File @click{} Open}
257 EOF
258       echo "configure:__oline__: running $MAKEINFO conftest.texi >&AS_MESSAGE_LOG_FD" >&AS_MESSAGE_LOG_FD
259       eval "$MAKEINFO conftest.texi >&AS_MESSAGE_LOG_FD 2>&1"
260       retval=$?
261       echo "configure:__oline__: \$? = $retval" >&AS_MESSAGE_LOG_FD
262       if test $retval = 0; then
263         pspp_cv_have_clicksequence=yes
264       else
265         pspp_cv_have_clicksequence=no
266       fi
267       rm -f conftest.texi conftest.info])
268    if test $pspp_cv_have_clicksequence = no; then
269        AC_MSG_ERROR([$MAKEINFO does not support @clicksequence.
270 Please install a newer or working version, or point the MAKEINFO variable
271 to one that is already installed.])
272    fi])
273
274 dnl Texinfo 4.13 generates broken DocBook XML.  Probably other old
275 dnl versions do too, but that's the one that causes problems.
276 AC_DEFUN([PSPP_CHECK_MAKEINFO_DOCBOOK_XML],
277   [AC_REQUIRE([AM_INIT_AUTOMAKE])  # Defines MAKEINFO
278    AC_CACHE_CHECK(
279      [whether makeinfo generates broken DocBook XML],
280      [pspp_cv_broken_docbook_xml],
281      [AS_CASE(
282         [$(eval "$MAKEINFO --version | head -1")],
283         [*texinfo*4.13*], [pspp_cv_broken_docbook_xml=yes],
284         [*texinfo*], [pspp_cv_broken_docbook_xml=no],
285         [*], [pspp_cv_broken_docbook_xml=yes])])
286    AM_CONDITIONAL(
287      [BROKEN_DOCBOOK_XML], [test "$pspp_cv_broken_docbook_xml" = yes])])
288
289 # The following comes from Open vSwitch:
290 # ----------------------------------------------------------------------
291 # Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
292 #
293 # Licensed under the Apache License, Version 2.0 (the "License");
294 # you may not use this file except in compliance with the License.
295 # You may obtain a copy of the License at:
296 #
297 #     http://www.apache.org/licenses/LICENSE-2.0
298 #
299 # Unless required by applicable law or agreed to in writing, software
300 # distributed under the License is distributed on an "AS IS" BASIS,
301 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
302 # See the License for the specific language governing permissions and
303 # limitations under the License.
304
305 dnl PSPP_ENABLE_WERROR
306 AC_DEFUN([PSPP_ENABLE_WERROR],
307   [AC_ARG_ENABLE(
308      [Werror],
309      [AC_HELP_STRING([--enable-Werror], [Add -Werror to CFLAGS])],
310      [], [enable_Werror=no])
311    AC_CONFIG_COMMANDS_PRE(
312      [if test "X$enable_Werror" = Xyes; then
313         CFLAGS="$CFLAGS -Werror -Wno-error=deprecated-declarations"
314         # gnulib needs this, for now:
315         CFLAGS="$CFLAGS -Wno-error=attributes"
316       fi])])
317
318 # The following comes from Open vSwitch:
319 # ----------------------------------------------------------------------
320 # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
321 #
322 # Licensed under the Apache License, Version 2.0 (the "License");
323 # you may not use this file except in compliance with the License.
324 # You may obtain a copy of the License at:
325 #
326 #     http://www.apache.org/licenses/LICENSE-2.0
327 #
328 # Unless required by applicable law or agreed to in writing, software
329 # distributed under the License is distributed on an "AS IS" BASIS,
330 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
331 # See the License for the specific language governing permissions and
332 # limitations under the License.
333
334 dnl Checks for dot.
335 AC_DEFUN([PSPP_CHECK_DOT],
336   [AC_CACHE_CHECK(
337     [for dot],
338     [pspp_cv_dot],
339     [dnl "dot" writes -V output to stderr:
340      if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
341        pspp_cv_dot=yes
342      else
343        pspp_cv_dot=no
344      fi])
345    AM_CONDITIONAL([HAVE_DOT], [test "$pspp_cv_dot" = yes])])
346
347
348 dnl Check that xgettext is sufficiently recent
349 dnl Before calling this macro, AC_CHECK_PROGS([XGETTEXT], [xgettext]) should have been called,
350 dnl which sets the ac_cv_prog_XGETTEXT cache variable.
351 AC_DEFUN([PSPP_CHECK_XGETTEXT],
352  [AC_CACHE_CHECK([whether gettext is sufficiently recent],
353    [pspp_cv_progrecent_xgettext],
354    [pspp_cv_progrecent_xgettext=maybe
355     ver=`$ac_cv_prog_XGETTEXT --version | sed -n -e '/xgettext/s/[[^0-9]]*\([[0-9\.]][[0-9\.]]*\).*/\1/p'`
356     case $ver in # (
357       *.*.*) ;; # (
358       *.*) ver="$ver.0" ;;
359     esac
360     majmin=`echo $ver | sed -e 's/\.[[0-9]]*$//'`
361     major=`echo $majmin | sed -e 's/\.[[0-9]]*$//'`
362     minor=`echo $majmin | sed -e 's/^[[0-9]]*\.//'`
363     if test "$major" -lt 0; then
364       pspp_cv_progrecent_xgettext=no;
365     elif test "$minor" -lt 20; then
366       pspp_cv_progrecent_xgettext=no
367     else
368       pspp_cv_progrecent_xgettext=yes
369     fi])])