Move code from configure.ac to acinclude.m4 for readability.
[pspp-builds.git] / acinclude.m4
1 dnl Copyright (C) 2005, 2006 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 Check that a new enough version of Perl is available.
7 AC_DEFUN([PSPP_PERL],
8 [
9   AC_PATH_PROG([PERL], perl, no)
10   AC_SUBST([PERL])dnl
11   if test "$PERL" = no; then
12     AC_MSG_ERROR([perl is not found])
13   fi
14   $PERL -e 'require 5.005_03;' || {
15      AC_MSG_ERROR([Perl 5.005_03 or better is required])
16   }
17 ])
18
19 dnl Check that libplot is available.
20 AC_DEFUN([PSPP_LIBPLOT],
21 [
22   AC_ARG_WITH(libplot, [  --without-libplot         don't compile in support of charts (using libplot)])
23
24   if test x"$with_libplot" != x"no" ; then 
25           AC_CHECK_LIB(plot, pl_newpl_r,,
26             AC_MSG_ERROR([You must install libplot development libraries (or use --without-libplot)])
27           )
28   fi
29 ])
30
31 dnl Check that off_t is defined as an integer type.
32 dnl Solaris sometimes declares it as a struct, if it
33 dnl thinks that the compiler does not support `long long'.
34 AC_DEFUN([PSPP_OFF_T],
35 [
36   AC_COMPILE_IFELSE([#include <sys/types.h>
37   #include <unistd.h>
38   off_t x = 0;
39   int main (void) 
40   { 
41     lseek (0, 1, 2);
42     return 0;
43   }], [], [AC_MSG_ERROR(
44   [Your system's definition of off_t is broken.  You are probably
45   using Solaris.  You can probably fix the problem with
46   `--disable-largefile' or `CFLAGS=-ansi'.])])
47 ])
48
49 dnl Check whether a warning flag is accepted.
50 dnl If so, add it to CFLAGS.
51 dnl Example: PSPP_ENABLE_WARNING(-Wdeclaration-after-statement)
52 AC_DEFUN([PSPP_ENABLE_WARNING],
53 [
54   m4_define([pspp_cv_name], [pspp_cv_[]m4_translit([$1], [-], [_])])dnl
55   AC_CACHE_CHECK([whether $CC accepts $1], [pspp_cv_name], 
56     [pspp_save_CFLAGS="$CFLAGS"
57      CFLAGS="$CFLAGS $1"
58      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [pspp_cv_name[]=yes], [pspp_cv_name[]=no])
59      CFLAGS="$pspp_save_CFLAGS"])
60   if test $pspp_cv_name = yes; then
61     CFLAGS="$CFLAGS $1"
62   fi
63 ])
64
65 dnl Check for readline and history libraries.
66
67 dnl Modified for PSPP by Ben Pfaff, based on readline.m4 serial 3 from
68 dnl gnulib, which was written by Simon Josefsson, with help from Bruno
69 dnl Haible and Oskar Liljeblad.
70
71 AC_DEFUN([PSPP_READLINE],
72 [
73   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
74   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
75   AC_REQUIRE([AC_LIB_RPATH])
76
77   dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
78   dnl INCREADLINE accordingly.
79   AC_LIB_LINKFLAGS_BODY([readline])
80   AC_LIB_LINKFLAGS_BODY([history])
81
82   dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
83   dnl because if the user has installed libreadline and not disabled its use
84   dnl via --without-libreadline-prefix, he wants to use it. The AC_TRY_LINK
85   dnl will then succeed.
86   am_save_CPPFLAGS="$CPPFLAGS"
87   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE $INCHISTORY])
88
89   AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
90     gl_cv_lib_readline=no
91     am_save_LIBS="$LIBS"
92     dnl On some systems, -lreadline doesn't link without an additional
93     dnl -lncurses or -ltermcap.
94     dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
95     dnl by design and obsolete since 1994. Try -lcurses last, because
96     dnl libcurses is unusable on some old Unices.
97     for extra_lib in "" ncurses termcap curses; do
98       LIBS="$am_save_LIBS $LIBREADLINE $LIBHISTORY"
99       if test -n "$extra_lib"; then
100         LIBS="$LIBS -l$extra_lib"
101       fi
102       AC_TRY_LINK([#include <stdio.h>
103 #include <readline/readline.h>
104 #include <readline/history.h>],
105         [readline((char*)0); add_history((char*)0);],
106         gl_cv_lib_readline=yes)
107       if test "$gl_cv_lib_readline" = yes; then
108         if test -n "$extra_lib"; then
109           LIBREADLINE="$LIBREADLINE $LIBHISTORY -l$extra_lib"
110           LTLIBREADLINE="$LTLIBREADLINE $LTLIBHISTORY -l$extra_lib"
111         fi
112         break
113       fi
114     done
115     LIBS="$am_save_LIBS"
116   ])
117
118   if test "$gl_cv_lib_readline" = yes; then
119     AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
120   fi
121
122   if test "$gl_cv_lib_readline" = yes; then
123     AC_MSG_CHECKING([how to link with libreadline])
124     AC_MSG_RESULT([$LIBREADLINE])
125   else
126     dnl If $LIBREADLINE didn't lead to a usable library, we don't
127     dnl need $INCREADLINE either.
128     CPPFLAGS="$am_save_CPPFLAGS"
129     LIBREADLINE=
130     LTLIBREADLINE=
131     LIBHISTORY=
132     LTLIBHISTORY=
133   fi
134   AC_SUBST(LIBREADLINE)
135   AC_SUBST(LTLIBREADLINE)
136 ])
137
138 dnl aclocal.m4 ends here