Merge branch 'master' of ssh://jstover@git.sv.gnu.org/srv/git/pspp
[pspp-builds.git] / acinclude.m4
1 dnl Copyright (C) 2005, 2006, 2007 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 Instead of giving an error about each prerequisite as we encounter it, 
9 dnl group them all together at the end of the run, to be user-friendly.
10 AC_DEFUN([PSPP_REQUIRED_PREREQ], [pspp_required_prereqs="$pspp_required_prereqs
11         $1"])
12 AC_DEFUN([PSPP_OPTIONAL_PREREQ], [pspp_optional_prereqs="$pspp_optional_prereqs
13         $1"])
14 AC_DEFUN([PSPP_CHECK_PREREQS], 
15 [
16   if test "$pspp_optional_prereqs" != ""; then
17     AC_MSG_WARN([The following optional prerequisites are not installed.
18 You may wish to install them to obtain additional functionality:$pspp_optional_prereqs])
19 fi
20   if test "$pspp_required_prereqs" != ""; then
21     AC_MSG_ERROR([The following required prerequisites are not installed.
22 You must install them before PSPP can be built:$pspp_required_prereqs])
23 fi
24 ])
25     
26
27 dnl Check that a new enough version of Perl is available.
28 AC_DEFUN([PSPP_PERL],
29 [
30   AC_PATH_PROG([PERL], perl, no)
31   AC_SUBST([PERL])dnl
32   if test "$PERL" != no && $PERL -e 'require 5.005_03;'; then :; else
33     PSPP_REQUIRED_PREREQ([Perl 5.005_03 (or later)])
34   fi
35 ])
36
37 dnl Check that libplot is available.
38 AC_DEFUN([PSPP_LIBPLOT],
39 [
40   AC_ARG_WITH(
41     libplot, 
42     [AS_HELP_STRING([--without-libplot],
43                     [don't compile in support of charts (using libplot)])])
44
45   if test x"$with_libplot" != x"no" ; then 
46     # Check whether we can link against libplot without any extra libraries.
47     AC_CHECK_LIB(plot, pl_newpl_r, [LIBPLOT_LIBS="-lplot"])
48
49     # Check whether we can link against libplot if we also link X.
50     if test x"$LIBPLOT_LIBS" = x""; then
51       AC_PATH_XTRA
52       extra_libs="-lXaw -lXmu -lXt $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS -lm"
53       AC_CHECK_LIB(plot, pl_newpl_r,
54                    [LIBPLOT_LIBS="-lplot $extra_libs"
55                     LDFLAGS="$LDFLAGS $X_LIBS"],,
56                    [$extra_libs])
57     fi
58
59     # Still can't link?
60     if test x"$LIBPLOT_LIBS" = x""; then
61       PSPP_REQUIRED_PREREQ([libplot (or use --without-libplot)])
62     fi
63
64     # Set up to make everything work.
65     LIBS="$LIBPLOT_LIBS $LIBS"
66     AC_DEFINE(HAVE_LIBPLOT, 1,
67               [Define to 1 if you have the `libplot' library (-lplot).])
68   fi
69 ])
70
71 dnl Check whether a C compiler option is accepted.
72 dnl If so, add it to CFLAGS.
73 dnl Example: PSPP_ENABLE_OPTION(-Wdeclaration-after-statement)
74 AC_DEFUN([PSPP_ENABLE_OPTION],
75 [
76   m4_define([pspp_cv_name], [pspp_cv_[]m4_translit([$1], [-], [_])])dnl
77   AC_CACHE_CHECK([whether $CC accepts $1], [pspp_cv_name], 
78     [pspp_save_CFLAGS="$CFLAGS"
79      CFLAGS="$CFLAGS $1"
80      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [pspp_cv_name[]=yes], [pspp_cv_name[]=no])
81      CFLAGS="$pspp_save_CFLAGS"])
82   if test $pspp_cv_name = yes; then
83     CFLAGS="$CFLAGS $1"
84   fi
85 ])
86
87 dnl Check for readline and history libraries.
88
89 dnl Modified for PSPP, based on readline.m4 serial 3 from
90 dnl gnulib, which was written by Simon Josefsson, with help from Bruno
91 dnl Haible and Oskar Liljeblad.
92
93 AC_DEFUN([PSPP_READLINE],
94 [
95   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
96   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
97   AC_REQUIRE([AC_LIB_RPATH])
98
99   dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
100   dnl INCREADLINE accordingly.
101   AC_LIB_LINKFLAGS_BODY([readline])
102   AC_LIB_LINKFLAGS_BODY([history])
103
104   dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
105   dnl because if the user has installed libreadline and not disabled its use
106   dnl via --without-libreadline-prefix, he wants to use it. The AC_LINK_IFELSE
107   dnl will then succeed.
108   am_save_CPPFLAGS="$CPPFLAGS"
109   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE $INCHISTORY])
110
111   AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
112     gl_cv_lib_readline=no
113     am_save_LIBS="$LIBS"
114     dnl On some systems, -lreadline doesn't link without an additional
115     dnl -lncurses or -ltermcap.
116     dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
117     dnl by design and obsolete since 1994. Try -lcurses last, because
118     dnl libcurses is unusable on some old Unices.
119     for extra_lib in "" ncurses termcap curses; do
120       LIBS="$am_save_LIBS $LIBREADLINE $LIBHISTORY"
121       if test -n "$extra_lib"; then
122         LIBS="$LIBS -l$extra_lib"
123       fi
124       AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
125 #include <readline/readline.h>
126 #include <readline/history.h>]], [[readline((char*)0); add_history((char*)0);]])],[gl_cv_lib_readline=yes],[])
127       if test "$gl_cv_lib_readline" = yes; then
128         if test -n "$extra_lib"; then
129           LIBREADLINE="$LIBREADLINE $LIBHISTORY -l$extra_lib"
130           LTLIBREADLINE="$LTLIBREADLINE $LTLIBHISTORY -l$extra_lib"
131         fi
132         break
133       fi
134     done
135     LIBS="$am_save_LIBS"
136   ])
137
138   if test "$gl_cv_lib_readline" = yes; then
139     AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
140     AC_MSG_CHECKING([how to link with libreadline])
141     AC_MSG_RESULT([$LIBREADLINE])
142   else
143     dnl If $LIBREADLINE didn't lead to a usable library, we don't
144     dnl need $INCREADLINE either.
145     CPPFLAGS="$am_save_CPPFLAGS"
146     LIBREADLINE=
147     LTLIBREADLINE=
148     LIBHISTORY=
149     LTLIBHISTORY=
150     PSPP_OPTIONAL_PREREQ([libreadline (which may itself require libncurses or libtermcap)])
151   fi
152   AC_SUBST(LIBREADLINE)
153   AC_SUBST(LTLIBREADLINE)
154 ])
155
156 dnl Check for build tools.  Adapted from bfd library.
157
158 AC_DEFUN([PSPP_CC_FOR_BUILD],
159 [# Put a plausible default for CC_FOR_BUILD in Makefile.
160 if test -z "$CC_FOR_BUILD"; then
161   if test "x$cross_compiling" = "xno"; then
162     CC_FOR_BUILD='$(CC)'
163   else
164     CC_FOR_BUILD=cc
165   fi
166 fi
167 AC_SUBST(CC_FOR_BUILD)
168 # Also set EXEEXT_FOR_BUILD.
169 if test "x$cross_compiling" = "xno"; then
170   EXEEXT_FOR_BUILD='$(EXEEXT)'
171 else
172   AC_CACHE_CHECK([for build system executable suffix], pspp_cv_build_exeext,
173     [rm -f conftest*
174      echo 'int main () { return 0; }' > conftest.c
175      pspp_cv_build_exeext=
176      ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
177      for file in conftest.*; do
178        case $file in # (
179        *.c | *.o | *.obj | *.ilk | *.pdb) ;; # (
180        *) pspp_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
181        esac
182      done
183      rm -f conftest*
184      test x"${pspp_cv_build_exeext}" = x && pspp_cv_build_exeext=no])
185   EXEEXT_FOR_BUILD=""
186   test x"${pspp_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${pspp_cv_build_exeex
187 t}
188 fi
189 AC_SUBST(EXEEXT_FOR_BUILD)])
190
191 dnl Check for LC_PAPER, _NL_PAPER_WIDTH, _NL_PAPER_HEIGHT.
192 AC_DEFUN([PSPP_LC_PAPER],
193 [AC_CACHE_CHECK(for LC_PAPER, pspp_cv_lc_paper, [
194     pspp_cv_lc_paper=no
195     AC_COMPILE_IFELSE(
196       [AC_LANG_PROGRAM(
197         [#include <locale.h>
198 #include <langinfo.h>
199 ],
200         [(void) LC_PAPER; (void) _NL_PAPER_WIDTH; (void) _NL_PAPER_HEIGHT])],
201       [pspp_cv_lc_paper=yes])
202   ])
203   if test "$pspp_cv_lc_paper" = yes; then
204     AC_DEFINE(HAVE_LC_PAPER, 1, [Define if you have LC_PAPER.])
205   fi
206 ])
207
208
209 # PSPP_LINK2_IFELSE(SOURCE1, SOURCE2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
210 # -------------------------------------------------------------
211 # Based on AC_LINK_IFELSE, but tries to link both SOURCE1 and SOURCE2
212 # into a program.
213 #
214 # Test that resulting file is executable; see the problem reported by mwoehlke
215 # in <http://lists.gnu.org/archive/html/bug-coreutils/2006-10/msg00048.html>.
216 # But skip the test when cross-compiling, to prevent problems like the one
217 # reported by Chris Johns in
218 # <http://lists.gnu.org/archive/html/autoconf/2007-03/msg00085.html>.
219 #
220 m4_define([PSPP_LINK2_IFELSE],
221 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
222 mv conftest.$ac_ext conftest1.$ac_ext
223 m4_ifvaln([$2], [AC_LANG_CONFTEST([$2])])dnl
224 mv conftest.$ac_ext conftest2.$ac_ext
225 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
226 pspp_link2='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest1.$ac_ext conftest2.$ac_ext $LIBS >&5'
227 AS_IF([_AC_DO_STDERR($pspp_link2) && {
228          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
229          test ! -s conftest.err
230        } && test -s conftest$ac_exeext && {
231          test "$cross_compiling" = yes ||
232          AS_TEST_X([conftest$ac_exeext])
233        }],
234       [$3],
235       [echo "$as_me: failed source file 1 of 2 was:" >&5
236 sed 's/^/| /' conftest1.$ac_ext >&5
237 echo "$as_me: failed source file 2 of 2 was:" >&5
238 sed 's/^/| /' conftest2.$ac_ext >&5
239         $4])
240 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
241 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
242 dnl as it would interfere with the next link command.
243 rm -rf conftest.dSYM conftest1.dSYM conftest2.dSYM
244 rm -f core conftest.err conftest1.err conftest2.err
245 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest*_ipa8_conftest*.oo
246 rm -f conftest$ac_exeext
247 rm -f m4_ifval([$1], [conftest1.$ac_ext]) m4_ifval([$2], [conftest1.$ac_ext])[]dnl
248 ])# PSPP_LINK2_IFELSE
249
250 # GSL uses "extern inline" without determining whether the compiler uses
251 # GCC inline rules or C99 inline rules.  If it uses the latter then GSL
252 # will be broken without passing -fgnu89-inline to GCC.
253 AC_DEFUN([PSPP_GSL_NEEDS_FGNU89_INLINE],
254 [# GSL only uses "inline" at all if HAVE_INLINE is defined as a macro.
255  # In turn, gnulib's gl_INLINE is one macro that does that.  We need to
256  # make sure that it has run by the time we run this test, otherwise we'll
257  # get a false result.
258  AC_REQUIRE([gl_INLINE])
259  AC_CACHE_CHECK([whether GSL needs -fgnu89-inline to link],
260                 pspp_cv_gsl_needs_fgnu89_inline, [
261                 PSPP_LINK2_IFELSE(
262                   [AC_LANG_PROGRAM([#include <gsl/gsl_math.h>
263                                    ], [GSL_MAX_INT(1,2);])],
264                   [AC_LANG_SOURCE([#include <gsl/gsl_math.h>
265                                    void x (void) {}])],
266                   [pspp_cv_gsl_needs_fgnu89_inline=no],
267                   [pspp_cv_gsl_needs_fgnu89_inline=yes])])
268  if test "$pspp_cv_gsl_needs_fgnu89_inline" = "yes"; then
269      CFLAGS="$CFLAGS -fgnu89-inline"
270  fi
271 ])
272 dnl acinclude.m4 ends here