Improve portability to NetBSD and Alpha.
[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 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(libplot, [  --without-libplot         don't compile in support of charts (using libplot)])
41
42   if test x"$with_libplot" != x"no" ; then 
43     AC_CHECK_LIB(plot, pl_newpl_r,,
44                  [PSPP_REQUIRED_PREREQ([libplot (or use --without-libplot)])])
45   fi
46 ])
47
48 dnl Check that off_t is defined as an integer type.
49 dnl Solaris sometimes declares it as a struct, if it
50 dnl thinks that the compiler does not support `long long'.
51 AC_DEFUN([PSPP_OFF_T],
52 [
53   AC_COMPILE_IFELSE([#include <sys/types.h>
54   #include <unistd.h>
55   off_t x = 0;
56   int main (void) 
57   { 
58     lseek (0, 1, 2);
59     return 0;
60   }], [], [AC_MSG_ERROR(
61   [Your system's definition of off_t is broken.  You are probably
62   using Solaris.  You can probably fix the problem with
63   `--disable-largefile' or `CFLAGS=-ansi'.])])
64 ])
65
66 dnl Check whether a C compiler option is accepted.
67 dnl If so, add it to CFLAGS.
68 dnl Example: PSPP_ENABLE_OPTION(-Wdeclaration-after-statement)
69 AC_DEFUN([PSPP_ENABLE_OPTION],
70 [
71   m4_define([pspp_cv_name], [pspp_cv_[]m4_translit([$1], [-], [_])])dnl
72   AC_CACHE_CHECK([whether $CC accepts $1], [pspp_cv_name], 
73     [pspp_save_CFLAGS="$CFLAGS"
74      CFLAGS="$CFLAGS $1"
75      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [pspp_cv_name[]=yes], [pspp_cv_name[]=no])
76      CFLAGS="$pspp_save_CFLAGS"])
77   if test $pspp_cv_name = yes; then
78     CFLAGS="$CFLAGS $1"
79   fi
80 ])
81
82 dnl Check for readline and history libraries.
83
84 dnl Modified for PSPP, based on readline.m4 serial 3 from
85 dnl gnulib, which was written by Simon Josefsson, with help from Bruno
86 dnl Haible and Oskar Liljeblad.
87
88 AC_DEFUN([PSPP_READLINE],
89 [
90   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
91   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
92   AC_REQUIRE([AC_LIB_RPATH])
93
94   dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
95   dnl INCREADLINE accordingly.
96   AC_LIB_LINKFLAGS_BODY([readline])
97   AC_LIB_LINKFLAGS_BODY([history])
98
99   dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
100   dnl because if the user has installed libreadline and not disabled its use
101   dnl via --without-libreadline-prefix, he wants to use it. The AC_TRY_LINK
102   dnl will then succeed.
103   am_save_CPPFLAGS="$CPPFLAGS"
104   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE $INCHISTORY])
105
106   AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
107     gl_cv_lib_readline=no
108     am_save_LIBS="$LIBS"
109     dnl On some systems, -lreadline doesn't link without an additional
110     dnl -lncurses or -ltermcap.
111     dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
112     dnl by design and obsolete since 1994. Try -lcurses last, because
113     dnl libcurses is unusable on some old Unices.
114     for extra_lib in "" ncurses termcap curses; do
115       LIBS="$am_save_LIBS $LIBREADLINE $LIBHISTORY"
116       if test -n "$extra_lib"; then
117         LIBS="$LIBS -l$extra_lib"
118       fi
119       AC_TRY_LINK([#include <stdio.h>
120 #include <readline/readline.h>
121 #include <readline/history.h>],
122         [readline((char*)0); add_history((char*)0);],
123         gl_cv_lib_readline=yes)
124       if test "$gl_cv_lib_readline" = yes; then
125         if test -n "$extra_lib"; then
126           LIBREADLINE="$LIBREADLINE $LIBHISTORY -l$extra_lib"
127           LTLIBREADLINE="$LTLIBREADLINE $LTLIBHISTORY -l$extra_lib"
128         fi
129         break
130       fi
131     done
132     LIBS="$am_save_LIBS"
133   ])
134
135   if test "$gl_cv_lib_readline" = yes; then
136     AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
137     AC_MSG_CHECKING([how to link with libreadline])
138     AC_MSG_RESULT([$LIBREADLINE])
139   else
140     dnl If $LIBREADLINE didn't lead to a usable library, we don't
141     dnl need $INCREADLINE either.
142     CPPFLAGS="$am_save_CPPFLAGS"
143     LIBREADLINE=
144     LTLIBREADLINE=
145     LIBHISTORY=
146     LTLIBHISTORY=
147     PSPP_OPTIONAL_PREREQ([libreadline (which may itself require libncurses or libtermcap)])
148   fi
149   AC_SUBST(LIBREADLINE)
150   AC_SUBST(LTLIBREADLINE)
151 ])
152
153 dnl Check for build tools.  Adapted from bfd library.
154
155 AC_DEFUN([PSPP_CC_FOR_BUILD],
156 [# Put a plausible default for CC_FOR_BUILD in Makefile.
157 if test -z "$CC_FOR_BUILD"; then
158   if test "x$cross_compiling" = "xno"; then
159     CC_FOR_BUILD='$(CC)'
160   else
161     CC_FOR_BUILD=cc
162   fi
163 fi
164 AC_SUBST(CC_FOR_BUILD)
165 # Also set EXEEXT_FOR_BUILD.
166 if test "x$cross_compiling" = "xno"; then
167   EXEEXT_FOR_BUILD='$(EXEEXT)'
168 else
169   AC_CACHE_CHECK([for build system executable suffix], pspp_cv_build_exeext,
170     [rm -f conftest*
171      echo 'int main () { return 0; }' > conftest.c
172      pspp_cv_build_exeext=
173      ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
174      for file in conftest.*; do
175        case $file in # (
176        *.c | *.o | *.obj | *.ilk | *.pdb) ;; # (
177        *) pspp_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
178        esac
179      done
180      rm -f conftest*
181      test x"${pspp_cv_build_exeext}" = x && pspp_cv_build_exeext=no])
182   EXEEXT_FOR_BUILD=""
183   test x"${pspp_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${pspp_cv_build_exeex
184 t}
185 fi
186 AC_SUBST(EXEEXT_FOR_BUILD)])
187
188 dnl aclocal.m4 ends here