Use fseeko module from gnulib instead of our home-grown solution.
[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_TRY_LINK
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_TRY_LINK([#include <stdio.h>
125 #include <readline/readline.h>
126 #include <readline/history.h>],
127         [readline((char*)0); add_history((char*)0);],
128         gl_cv_lib_readline=yes)
129       if test "$gl_cv_lib_readline" = yes; then
130         if test -n "$extra_lib"; then
131           LIBREADLINE="$LIBREADLINE $LIBHISTORY -l$extra_lib"
132           LTLIBREADLINE="$LTLIBREADLINE $LTLIBHISTORY -l$extra_lib"
133         fi
134         break
135       fi
136     done
137     LIBS="$am_save_LIBS"
138   ])
139
140   if test "$gl_cv_lib_readline" = yes; then
141     AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
142     AC_MSG_CHECKING([how to link with libreadline])
143     AC_MSG_RESULT([$LIBREADLINE])
144   else
145     dnl If $LIBREADLINE didn't lead to a usable library, we don't
146     dnl need $INCREADLINE either.
147     CPPFLAGS="$am_save_CPPFLAGS"
148     LIBREADLINE=
149     LTLIBREADLINE=
150     LIBHISTORY=
151     LTLIBHISTORY=
152     PSPP_OPTIONAL_PREREQ([libreadline (which may itself require libncurses or libtermcap)])
153   fi
154   AC_SUBST(LIBREADLINE)
155   AC_SUBST(LTLIBREADLINE)
156 ])
157
158 dnl Check for build tools.  Adapted from bfd library.
159
160 AC_DEFUN([PSPP_CC_FOR_BUILD],
161 [# Put a plausible default for CC_FOR_BUILD in Makefile.
162 if test -z "$CC_FOR_BUILD"; then
163   if test "x$cross_compiling" = "xno"; then
164     CC_FOR_BUILD='$(CC)'
165   else
166     CC_FOR_BUILD=cc
167   fi
168 fi
169 AC_SUBST(CC_FOR_BUILD)
170 # Also set EXEEXT_FOR_BUILD.
171 if test "x$cross_compiling" = "xno"; then
172   EXEEXT_FOR_BUILD='$(EXEEXT)'
173 else
174   AC_CACHE_CHECK([for build system executable suffix], pspp_cv_build_exeext,
175     [rm -f conftest*
176      echo 'int main () { return 0; }' > conftest.c
177      pspp_cv_build_exeext=
178      ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
179      for file in conftest.*; do
180        case $file in # (
181        *.c | *.o | *.obj | *.ilk | *.pdb) ;; # (
182        *) pspp_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
183        esac
184      done
185      rm -f conftest*
186      test x"${pspp_cv_build_exeext}" = x && pspp_cv_build_exeext=no])
187   EXEEXT_FOR_BUILD=""
188   test x"${pspp_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${pspp_cv_build_exeex
189 t}
190 fi
191 AC_SUBST(EXEEXT_FOR_BUILD)])
192
193 dnl Check for LC_PAPER, _NL_PAPER_WIDTH, _NL_PAPER_HEIGHT.
194 AC_DEFUN([PSPP_LC_PAPER],
195 [AC_CACHE_CHECK(for LC_PAPER, pspp_cv_lc_paper, [
196     pspp_cv_lc_paper=no
197     AC_COMPILE_IFELSE(
198       [AC_LANG_PROGRAM(
199         [#include <locale.h>
200 #include <langinfo.h>
201 ],
202         [(void) LC_PAPER; (void) _NL_PAPER_WIDTH; (void) _NL_PAPER_HEIGHT])],
203       [pspp_cv_lc_paper=yes])
204   ])
205   if test "$pspp_cv_lc_paper" = yes; then
206     AC_DEFINE(HAVE_LC_PAPER, 1, [Define if you have LC_PAPER.])
207   fi
208 ])
209
210 dnl acinclude.m4 ends here