1 dnl Copyright (C) 2005, 2006, 2007, 2009 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.
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
14 AC_DEFUN([PSPP_OPTIONAL_PREREQ], [pspp_optional_prereqs="$pspp_optional_prereqs
16 AC_DEFUN([PSPP_CHECK_PREREQS],
18 if test "$pspp_optional_prereqs" != ""; then
19 AC_MSG_WARN([The following optional prerequisites are not installed.
20 You may wish to install them to obtain additional functionality:$pspp_optional_prereqs])
22 if test "$pspp_required_prereqs" != ""; then
23 AC_MSG_ERROR([The following required prerequisites are not installed.
24 You must install them before PSPP can be built:$pspp_required_prereqs])
29 dnl Check that a new enough version of Perl is available.
32 AC_PATH_PROG([PERL], perl, no)
34 if test "$PERL" != no && $PERL -e 'require 5.005_03;'; then :; else
35 PSPP_REQUIRED_PREREQ([Perl 5.005_03 (or later)])
39 dnl PSPP_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
40 dnl Check whether the given C compiler OPTION is accepted.
41 dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
42 AC_DEFUN([PSPP_CHECK_CC_OPTION],
44 m4_define([pspp_cv_name], [pspp_cv_[]m4_translit([$1], [-], [_])])dnl
45 AC_CACHE_CHECK([whether $CC accepts $1], [pspp_cv_name],
46 [pspp_save_CFLAGS="$CFLAGS"
48 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [pspp_cv_name[]=yes], [pspp_cv_name[]=no])
49 CFLAGS="$pspp_save_CFLAGS"])
50 if test $pspp_cv_name = yes; then
51 m4_if([$2], [], [;], [$2])
53 m4_if([$3], [], [:], [$3])
57 dnl PSPP_ENABLE_OPTION([OPTION])
58 dnl Check whether the given C compiler OPTION is accepted.
59 dnl If so, add it to CFLAGS.
60 dnl Example: PSPP_ENABLE_OPTION([-Wdeclaration-after-statement])
61 AC_DEFUN([PSPP_ENABLE_OPTION],
62 [PSPP_CHECK_CC_OPTION([$1], [CFLAGS="$CFLAGS $1"])])
64 dnl Check for readline and history libraries.
66 dnl Modified for PSPP, based on readline.m4 serial 3 from
67 dnl gnulib, which was written by Simon Josefsson, with help from Bruno
68 dnl Haible and Oskar Liljeblad.
70 AC_DEFUN([PSPP_READLINE],
72 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
73 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
74 AC_REQUIRE([AC_LIB_RPATH])
76 dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
77 dnl INCREADLINE accordingly.
78 AC_LIB_LINKFLAGS_BODY([readline])
79 AC_LIB_LINKFLAGS_BODY([history])
81 dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
82 dnl because if the user has installed libreadline and not disabled its use
83 dnl via --without-libreadline-prefix, he wants to use it. The AC_LINK_IFELSE
84 dnl will then succeed.
85 am_save_CPPFLAGS="$CPPFLAGS"
86 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE $INCHISTORY])
88 AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
91 dnl On some systems, -lreadline doesn't link without an additional
92 dnl -lncurses or -ltermcap.
93 dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
94 dnl by design and obsolete since 1994. Try -lcurses last, because
95 dnl libcurses is unusable on some old Unices.
96 for extra_lib in "" ncurses termcap curses; do
97 LIBS="$am_save_LIBS $LIBREADLINE $LIBHISTORY"
98 if test -n "$extra_lib"; then
99 LIBS="$LIBS -l$extra_lib"
101 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
102 #include <readline/readline.h>
103 #include <readline/history.h>]], [[readline((char*)0); add_history((char*)0);]])],[gl_cv_lib_readline=yes],[])
104 if test "$gl_cv_lib_readline" = yes; then
105 if test -n "$extra_lib"; then
106 LIBREADLINE="$LIBREADLINE $LIBHISTORY -l$extra_lib"
107 LTLIBREADLINE="$LTLIBREADLINE $LTLIBHISTORY -l$extra_lib"
115 if test "$gl_cv_lib_readline" = yes; then
116 AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
117 AC_MSG_CHECKING([how to link with libreadline])
118 AC_MSG_RESULT([$LIBREADLINE])
120 dnl If $LIBREADLINE didn't lead to a usable library, we don't
121 dnl need $INCREADLINE either.
122 CPPFLAGS="$am_save_CPPFLAGS"
127 PSPP_OPTIONAL_PREREQ([libreadline (which may itself require libncurses or libtermcap)])
129 AC_SUBST(LIBREADLINE)
130 AC_SUBST(LTLIBREADLINE)
133 dnl Check for build tools. Adapted from bfd library.
135 AC_DEFUN([PSPP_CC_FOR_BUILD],
136 [# Put a plausible default for CC_FOR_BUILD in Makefile.
137 if test -z "$CC_FOR_BUILD"; then
138 if test "x$cross_compiling" = "xno"; then
144 AC_SUBST(CC_FOR_BUILD)
145 # Also set EXEEXT_FOR_BUILD.
146 if test "x$cross_compiling" = "xno"; then
147 EXEEXT_FOR_BUILD='$(EXEEXT)'
149 AC_CACHE_CHECK([for build system executable suffix], pspp_cv_build_exeext,
151 echo 'int main () { return 0; }' > conftest.c
152 pspp_cv_build_exeext=
153 ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
154 for file in conftest.*; do
156 *.c | *.o | *.obj | *.ilk | *.pdb) ;; # (
157 *) pspp_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
161 test x"${pspp_cv_build_exeext}" = x && pspp_cv_build_exeext=no])
163 test x"${pspp_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${pspp_cv_build_exeex
166 AC_SUBST(EXEEXT_FOR_BUILD)])
168 dnl Check for LC_PAPER, _NL_PAPER_WIDTH, _NL_PAPER_HEIGHT.
169 AC_DEFUN([PSPP_LC_PAPER],
170 [AC_CACHE_CHECK(for LC_PAPER, pspp_cv_lc_paper, [
175 #include <langinfo.h>
177 [(void) LC_PAPER; (void) _NL_PAPER_WIDTH; (void) _NL_PAPER_HEIGHT])],
178 [pspp_cv_lc_paper=yes])
180 if test "$pspp_cv_lc_paper" = yes; then
181 AC_DEFINE(HAVE_LC_PAPER, 1, [Define if you have LC_PAPER.])
186 # PSPP_LINK2_IFELSE(SOURCE1, SOURCE2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
187 # -------------------------------------------------------------
188 # Based on AC_LINK_IFELSE, but tries to link both SOURCE1 and SOURCE2
191 # Test that resulting file is executable; see the problem reported by mwoehlke
192 # in <http://lists.gnu.org/archive/html/bug-coreutils/2006-10/msg00048.html>.
193 # But skip the test when cross-compiling, to prevent problems like the one
194 # reported by Chris Johns in
195 # <http://lists.gnu.org/archive/html/autoconf/2007-03/msg00085.html>.
197 m4_define([PSPP_LINK2_IFELSE],
198 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
199 mv conftest.$ac_ext conftest1.$ac_ext
200 m4_ifvaln([$2], [AC_LANG_CONFTEST([$2])])dnl
201 mv conftest.$ac_ext conftest2.$ac_ext
202 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
203 pspp_link2='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest1.$ac_ext conftest2.$ac_ext $LIBS >&5'
204 AS_IF([_AC_DO_STDERR($pspp_link2) && {
205 test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
206 test ! -s conftest.err
207 } && test -s conftest$ac_exeext && {
208 test "$cross_compiling" = yes ||
209 AS_TEST_X([conftest$ac_exeext])
212 [echo "$as_me: failed source file 1 of 2 was:" >&5
213 sed 's/^/| /' conftest1.$ac_ext >&5
214 echo "$as_me: failed source file 2 of 2 was:" >&5
215 sed 's/^/| /' conftest2.$ac_ext >&5
217 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
218 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
219 dnl as it would interfere with the next link command.
220 rm -rf conftest.dSYM conftest1.dSYM conftest2.dSYM
221 rm -f core conftest.err conftest1.err conftest2.err
222 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest*_ipa8_conftest*.oo
223 rm -f conftest$ac_exeext
224 rm -f m4_ifval([$1], [conftest1.$ac_ext]) m4_ifval([$2], [conftest1.$ac_ext])[]dnl
225 ])# PSPP_LINK2_IFELSE
227 # GSL uses "extern inline" without determining whether the compiler uses
228 # GCC inline rules or C99 inline rules. If it uses the latter then GSL
229 # will be broken without passing -fgnu89-inline to GCC.
230 AC_DEFUN([PSPP_GSL_NEEDS_FGNU89_INLINE],
231 [# GSL only uses "inline" at all if HAVE_INLINE is defined as a macro.
232 # In turn, gnulib's gl_INLINE is one macro that does that. We need to
233 # make sure that it has run by the time we run this test, otherwise we'll
234 # get a false result.
235 AC_REQUIRE([gl_INLINE])
236 PSPP_CHECK_CC_OPTION(
238 [AC_CACHE_CHECK([whether GSL needs -fgnu89-inline to link],
239 pspp_cv_gsl_needs_fgnu89_inline, [
241 [AC_LANG_PROGRAM([#include <gsl/gsl_math.h>
242 ], [GSL_MAX_INT(1,2);])],
243 [AC_LANG_SOURCE([#include <gsl/gsl_math.h>
245 [pspp_cv_gsl_needs_fgnu89_inline=no],
246 [pspp_cv_gsl_needs_fgnu89_inline=yes])])
247 if test "$pspp_cv_gsl_needs_fgnu89_inline" = "yes"; then
248 CFLAGS="$CFLAGS -fgnu89-inline"
251 dnl acinclude.m4 ends here