Also warn about missing prerequisites as we encounter them (bug #24445).
[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 Summarize all the missing prerequisites at the end of the run to
9 dnl increase user-friendliness.
10 AC_DEFUN([PSPP_REQUIRED_PREREQ], 
11   [AC_MSG_WARN([You must install $1 before building PSPP.])
12 pspp_required_prereqs="$pspp_required_prereqs
13         $1"])
14 AC_DEFUN([PSPP_OPTIONAL_PREREQ], [pspp_optional_prereqs="$pspp_optional_prereqs
15         $1"])
16 AC_DEFUN([PSPP_CHECK_PREREQS], 
17 [
18   if test "$pspp_optional_prereqs" != ""; then
19     AC_MSG_WARN([The following optional prerequisites are not installed.
20 You may wish to install them to obtain additional functionality:$pspp_optional_prereqs])
21 fi
22   if test "$pspp_required_prereqs" != ""; then
23     AC_MSG_ERROR([The following required prerequisites are not installed.
24 You must install them before PSPP can be built:$pspp_required_prereqs])
25 fi
26 ])
27     
28
29 dnl Check that a new enough version of Perl is available.
30 AC_DEFUN([PSPP_PERL],
31 [
32   AC_PATH_PROG([PERL], perl, no)
33   AC_SUBST([PERL])dnl
34   if test "$PERL" != no && $PERL -e 'require 5.005_03;'; then :; else
35     PSPP_REQUIRED_PREREQ([Perl 5.005_03 (or later)])
36   fi
37 ])
38
39 dnl Check that libplot is available.
40 AC_DEFUN([PSPP_LIBPLOT],
41 [
42   AC_ARG_WITH(
43     libplot, 
44     [AS_HELP_STRING([--without-libplot],
45                     [don't compile in support of charts (using libplot)])])
46
47   if test x"$with_libplot" != x"no" ; then 
48     # Check whether we can link against libplot without any extra libraries.
49     AC_CHECK_LIB(plot, pl_newpl_r, [LIBPLOT_LIBS="-lplot"])
50
51     # Check whether we can link against libplot if we also link X.
52     if test x"$LIBPLOT_LIBS" = x""; then
53       AC_PATH_XTRA
54       extra_libs="-lXaw -lXmu -lXt $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS -lm"
55       AC_CHECK_LIB(plot, pl_newpl_r,
56                    [LIBPLOT_LIBS="-lplot $extra_libs"
57                     LDFLAGS="$LDFLAGS $X_LIBS"],,
58                    [$extra_libs])
59     fi
60
61     # Still can't link?
62     if test x"$LIBPLOT_LIBS" = x""; then
63       PSPP_REQUIRED_PREREQ([libplot (or use --without-libplot)])
64     fi
65
66     # Set up to make everything work.
67     LIBS="$LIBPLOT_LIBS $LIBS"
68     AC_DEFINE(HAVE_LIBPLOT, 1,
69               [Define to 1 if you have the `libplot' library (-lplot).])
70   fi
71 ])
72
73 dnl Check whether a C compiler option is accepted.
74 dnl If so, add it to CFLAGS.
75 dnl Example: PSPP_ENABLE_OPTION(-Wdeclaration-after-statement)
76 AC_DEFUN([PSPP_ENABLE_OPTION],
77 [
78   m4_define([pspp_cv_name], [pspp_cv_[]m4_translit([$1], [-], [_])])dnl
79   AC_CACHE_CHECK([whether $CC accepts $1], [pspp_cv_name], 
80     [pspp_save_CFLAGS="$CFLAGS"
81      CFLAGS="$CFLAGS $1"
82      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [pspp_cv_name[]=yes], [pspp_cv_name[]=no])
83      CFLAGS="$pspp_save_CFLAGS"])
84   if test $pspp_cv_name = yes; then
85     CFLAGS="$CFLAGS $1"
86   fi
87 ])
88
89 dnl Check for readline and history libraries.
90
91 dnl Modified for PSPP, based on readline.m4 serial 3 from
92 dnl gnulib, which was written by Simon Josefsson, with help from Bruno
93 dnl Haible and Oskar Liljeblad.
94
95 AC_DEFUN([PSPP_READLINE],
96 [
97   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
98   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
99   AC_REQUIRE([AC_LIB_RPATH])
100
101   dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
102   dnl INCREADLINE accordingly.
103   AC_LIB_LINKFLAGS_BODY([readline])
104   AC_LIB_LINKFLAGS_BODY([history])
105
106   dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
107   dnl because if the user has installed libreadline and not disabled its use
108   dnl via --without-libreadline-prefix, he wants to use it. The AC_LINK_IFELSE
109   dnl will then succeed.
110   am_save_CPPFLAGS="$CPPFLAGS"
111   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE $INCHISTORY])
112
113   AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
114     gl_cv_lib_readline=no
115     am_save_LIBS="$LIBS"
116     dnl On some systems, -lreadline doesn't link without an additional
117     dnl -lncurses or -ltermcap.
118     dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
119     dnl by design and obsolete since 1994. Try -lcurses last, because
120     dnl libcurses is unusable on some old Unices.
121     for extra_lib in "" ncurses termcap curses; do
122       LIBS="$am_save_LIBS $LIBREADLINE $LIBHISTORY"
123       if test -n "$extra_lib"; then
124         LIBS="$LIBS -l$extra_lib"
125       fi
126       AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
127 #include <readline/readline.h>
128 #include <readline/history.h>]], [[readline((char*)0); add_history((char*)0);]])],[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
211 # PSPP_LINK2_IFELSE(SOURCE1, SOURCE2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
212 # -------------------------------------------------------------
213 # Based on AC_LINK_IFELSE, but tries to link both SOURCE1 and SOURCE2
214 # into a program.
215 #
216 # Test that resulting file is executable; see the problem reported by mwoehlke
217 # in <http://lists.gnu.org/archive/html/bug-coreutils/2006-10/msg00048.html>.
218 # But skip the test when cross-compiling, to prevent problems like the one
219 # reported by Chris Johns in
220 # <http://lists.gnu.org/archive/html/autoconf/2007-03/msg00085.html>.
221 #
222 m4_define([PSPP_LINK2_IFELSE],
223 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
224 mv conftest.$ac_ext conftest1.$ac_ext
225 m4_ifvaln([$2], [AC_LANG_CONFTEST([$2])])dnl
226 mv conftest.$ac_ext conftest2.$ac_ext
227 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
228 pspp_link2='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest1.$ac_ext conftest2.$ac_ext $LIBS >&5'
229 AS_IF([_AC_DO_STDERR($pspp_link2) && {
230          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
231          test ! -s conftest.err
232        } && test -s conftest$ac_exeext && {
233          test "$cross_compiling" = yes ||
234          AS_TEST_X([conftest$ac_exeext])
235        }],
236       [$3],
237       [echo "$as_me: failed source file 1 of 2 was:" >&5
238 sed 's/^/| /' conftest1.$ac_ext >&5
239 echo "$as_me: failed source file 2 of 2 was:" >&5
240 sed 's/^/| /' conftest2.$ac_ext >&5
241         $4])
242 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
243 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
244 dnl as it would interfere with the next link command.
245 rm -rf conftest.dSYM conftest1.dSYM conftest2.dSYM
246 rm -f core conftest.err conftest1.err conftest2.err
247 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest*_ipa8_conftest*.oo
248 rm -f conftest$ac_exeext
249 rm -f m4_ifval([$1], [conftest1.$ac_ext]) m4_ifval([$2], [conftest1.$ac_ext])[]dnl
250 ])# PSPP_LINK2_IFELSE
251
252 # GSL uses "extern inline" without determining whether the compiler uses
253 # GCC inline rules or C99 inline rules.  If it uses the latter then GSL
254 # will be broken without passing -fgnu89-inline to GCC.
255 AC_DEFUN([PSPP_GSL_NEEDS_FGNU89_INLINE],
256 [# GSL only uses "inline" at all if HAVE_INLINE is defined as a macro.
257  # In turn, gnulib's gl_INLINE is one macro that does that.  We need to
258  # make sure that it has run by the time we run this test, otherwise we'll
259  # get a false result.
260  AC_REQUIRE([gl_INLINE])
261  AC_CACHE_CHECK([whether GSL needs -fgnu89-inline to link],
262                 pspp_cv_gsl_needs_fgnu89_inline, [
263                 PSPP_LINK2_IFELSE(
264                   [AC_LANG_PROGRAM([#include <gsl/gsl_math.h>
265                                    ], [GSL_MAX_INT(1,2);])],
266                   [AC_LANG_SOURCE([#include <gsl/gsl_math.h>
267                                    void x (void) {}])],
268                   [pspp_cv_gsl_needs_fgnu89_inline=no],
269                   [pspp_cv_gsl_needs_fgnu89_inline=yes])])
270  if test "$pspp_cv_gsl_needs_fgnu89_inline" = "yes"; then
271      CFLAGS="$CFLAGS -fgnu89-inline"
272  fi
273 ])
274 dnl acinclude.m4 ends here