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