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