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