PsppireDictView: Change "dictionary" property to "model".
[pspp-builds.git] / acinclude.m4
1 dnl Copyright (C) 2005, 2006, 2007, 2009 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   # The PSPP autobuilder appends a build number to the PSPP version number,
39   # e.g. "0.7.2-build40".  But Perl won't parse version numbers that contain
40   # anything other than digits and periods, so "-build" causes an error.  So we
41   # define $(VERSION_FOR_PERL) that drops everything from the hyphen onward.
42   VERSION_FOR_PERL=`echo "$VERSION" | sed 's/-.*//'`
43   AC_SUBST([VERSION_FOR_PERL])
44 ])
45
46 dnl Check that libplot is available.
47 AC_DEFUN([PSPP_LIBPLOT],
48 [
49   AC_ARG_WITH(
50     libplot, 
51     [AS_HELP_STRING([--without-libplot],
52                     [don't compile in support of charts (using libplot)])])
53
54   if test x"$with_libplot" != x"no" ; then 
55     # Check whether we can link against libplot without any extra libraries.
56     AC_CHECK_LIB(plot, pl_newpl_r, [LIBPLOT_LIBS="-lplot"])
57
58     # Check whether we can link against libplot if we also link X.
59     if test x"$LIBPLOT_LIBS" = x""; then
60       AC_PATH_XTRA
61       extra_libs="-lXaw -lXmu -lXt $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS -lm"
62       AC_CHECK_LIB(plot, pl_newpl_r,
63                    [LIBPLOT_LIBS="-lplot $extra_libs"
64                     LDFLAGS="$LDFLAGS $X_LIBS"],,
65                    [$extra_libs])
66     fi
67
68     # Still can't link?
69     if test x"$LIBPLOT_LIBS" = x""; then
70       PSPP_REQUIRED_PREREQ([libplot (or use --without-libplot)])
71     fi
72
73     # Set up to make everything work.
74     LIBS="$LIBPLOT_LIBS $LIBS"
75     AC_DEFINE(HAVE_LIBPLOT, 1,
76               [Define to 1 if you have the `libplot' library (-lplot).])
77   fi
78 ])
79
80 dnl PSPP_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
81 dnl Check whether the given C compiler OPTION is accepted.
82 dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
83 AC_DEFUN([PSPP_CHECK_CC_OPTION],
84 [
85   m4_define([pspp_cv_name], [pspp_cv_[]m4_translit([$1], [-], [_])])dnl
86   AC_CACHE_CHECK([whether $CC accepts $1], [pspp_cv_name], 
87     [pspp_save_CFLAGS="$CFLAGS"
88      CFLAGS="$CFLAGS $1"
89      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [pspp_cv_name[]=yes], [pspp_cv_name[]=no])
90      CFLAGS="$pspp_save_CFLAGS"])
91   if test $pspp_cv_name = yes; then
92     m4_if([$2], [], [;], [$2])
93   else
94     m4_if([$3], [], [:], [$3])
95   fi
96 ])
97
98 dnl PSPP_ENABLE_OPTION([OPTION])
99 dnl Check whether the given C compiler OPTION is accepted.
100 dnl If so, add it to CFLAGS.
101 dnl Example: PSPP_ENABLE_OPTION([-Wdeclaration-after-statement])
102 AC_DEFUN([PSPP_ENABLE_OPTION], 
103   [PSPP_CHECK_CC_OPTION([$1], [CFLAGS="$CFLAGS $1"])])
104
105 dnl Check for readline and history libraries.
106
107 dnl Modified for PSPP, based on readline.m4 serial 3 from
108 dnl gnulib, which was written by Simon Josefsson, with help from Bruno
109 dnl Haible and Oskar Liljeblad.
110
111 AC_DEFUN([PSPP_READLINE],
112 [
113   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
114   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
115   AC_REQUIRE([AC_LIB_RPATH])
116
117   dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
118   dnl INCREADLINE accordingly.
119   AC_LIB_LINKFLAGS_BODY([readline])
120   AC_LIB_LINKFLAGS_BODY([history])
121
122   dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
123   dnl because if the user has installed libreadline and not disabled its use
124   dnl via --without-libreadline-prefix, he wants to use it. The AC_LINK_IFELSE
125   dnl will then succeed.
126   am_save_CPPFLAGS="$CPPFLAGS"
127   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE $INCHISTORY])
128
129   AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
130     gl_cv_lib_readline=no
131     am_save_LIBS="$LIBS"
132     dnl On some systems, -lreadline doesn't link without an additional
133     dnl -lncurses or -ltermcap.
134     dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
135     dnl by design and obsolete since 1994. Try -lcurses last, because
136     dnl libcurses is unusable on some old Unices.
137     for extra_lib in "" ncurses termcap curses; do
138       LIBS="$am_save_LIBS $LIBREADLINE $LIBHISTORY"
139       if test -n "$extra_lib"; then
140         LIBS="$LIBS -l$extra_lib"
141       fi
142       AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
143 #include <readline/readline.h>
144 #include <readline/history.h>]], [[readline((char*)0); add_history((char*)0);]])],[gl_cv_lib_readline=yes],[])
145       if test "$gl_cv_lib_readline" = yes; then
146         if test -n "$extra_lib"; then
147           LIBREADLINE="$LIBREADLINE $LIBHISTORY -l$extra_lib"
148           LTLIBREADLINE="$LTLIBREADLINE $LTLIBHISTORY -l$extra_lib"
149         fi
150         break
151       fi
152     done
153     LIBS="$am_save_LIBS"
154   ])
155
156   if test "$gl_cv_lib_readline" = yes; then
157     AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
158     AC_MSG_CHECKING([how to link with libreadline])
159     AC_MSG_RESULT([$LIBREADLINE])
160   else
161     dnl If $LIBREADLINE didn't lead to a usable library, we don't
162     dnl need $INCREADLINE either.
163     CPPFLAGS="$am_save_CPPFLAGS"
164     LIBREADLINE=
165     LTLIBREADLINE=
166     LIBHISTORY=
167     LTLIBHISTORY=
168     PSPP_OPTIONAL_PREREQ([libreadline (which may itself require libncurses or libtermcap)])
169   fi
170   AC_SUBST(LIBREADLINE)
171   AC_SUBST(LTLIBREADLINE)
172 ])
173
174 dnl Check for build tools.  Adapted from bfd library.
175
176 AC_DEFUN([PSPP_CC_FOR_BUILD],
177 [# Put a plausible default for CC_FOR_BUILD in Makefile.
178 if test -z "$CC_FOR_BUILD"; then
179   if test "x$cross_compiling" = "xno"; then
180     CC_FOR_BUILD='$(CC)'
181   else
182     CC_FOR_BUILD=cc
183   fi
184 fi
185 AC_SUBST(CC_FOR_BUILD)
186 # Also set EXEEXT_FOR_BUILD.
187 if test "x$cross_compiling" = "xno"; then
188   EXEEXT_FOR_BUILD='$(EXEEXT)'
189 else
190   AC_CACHE_CHECK([for build system executable suffix], pspp_cv_build_exeext,
191     [rm -f conftest*
192      echo 'int main () { return 0; }' > conftest.c
193      pspp_cv_build_exeext=
194      ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
195      for file in conftest.*; do
196        case $file in # (
197        *.c | *.o | *.obj | *.ilk | *.pdb) ;; # (
198        *) pspp_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
199        esac
200      done
201      rm -f conftest*
202      test x"${pspp_cv_build_exeext}" = x && pspp_cv_build_exeext=no])
203   EXEEXT_FOR_BUILD=""
204   test x"${pspp_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${pspp_cv_build_exeex
205 t}
206 fi
207 AC_SUBST(EXEEXT_FOR_BUILD)])
208
209 dnl Check for LC_PAPER, _NL_PAPER_WIDTH, _NL_PAPER_HEIGHT.
210 AC_DEFUN([PSPP_LC_PAPER],
211 [AC_CACHE_CHECK(for LC_PAPER, pspp_cv_lc_paper, [
212     pspp_cv_lc_paper=no
213     AC_COMPILE_IFELSE(
214       [AC_LANG_PROGRAM(
215         [#include <locale.h>
216 #include <langinfo.h>
217 ],
218         [(void) LC_PAPER; (void) _NL_PAPER_WIDTH; (void) _NL_PAPER_HEIGHT])],
219       [pspp_cv_lc_paper=yes])
220   ])
221   if test "$pspp_cv_lc_paper" = yes; then
222     AC_DEFINE(HAVE_LC_PAPER, 1, [Define if you have LC_PAPER.])
223   fi
224 ])
225
226
227 # PSPP_LINK2_IFELSE(SOURCE1, SOURCE2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
228 # -------------------------------------------------------------
229 # Based on AC_LINK_IFELSE, but tries to link both SOURCE1 and SOURCE2
230 # into a program.
231 #
232 # Test that resulting file is executable; see the problem reported by mwoehlke
233 # in <http://lists.gnu.org/archive/html/bug-coreutils/2006-10/msg00048.html>.
234 # But skip the test when cross-compiling, to prevent problems like the one
235 # reported by Chris Johns in
236 # <http://lists.gnu.org/archive/html/autoconf/2007-03/msg00085.html>.
237 #
238 m4_define([PSPP_LINK2_IFELSE],
239 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
240 mv conftest.$ac_ext conftest1.$ac_ext
241 m4_ifvaln([$2], [AC_LANG_CONFTEST([$2])])dnl
242 mv conftest.$ac_ext conftest2.$ac_ext
243 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
244 pspp_link2='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest1.$ac_ext conftest2.$ac_ext $LIBS >&5'
245 AS_IF([_AC_DO_STDERR($pspp_link2) && {
246          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
247          test ! -s conftest.err
248        } && test -s conftest$ac_exeext && {
249          test "$cross_compiling" = yes ||
250          AS_TEST_X([conftest$ac_exeext])
251        }],
252       [$3],
253       [echo "$as_me: failed source file 1 of 2 was:" >&5
254 sed 's/^/| /' conftest1.$ac_ext >&5
255 echo "$as_me: failed source file 2 of 2 was:" >&5
256 sed 's/^/| /' conftest2.$ac_ext >&5
257         $4])
258 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
259 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
260 dnl as it would interfere with the next link command.
261 rm -rf conftest.dSYM conftest1.dSYM conftest2.dSYM
262 rm -f core conftest.err conftest1.err conftest2.err
263 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest*_ipa8_conftest*.oo
264 rm -f conftest$ac_exeext
265 rm -f m4_ifval([$1], [conftest1.$ac_ext]) m4_ifval([$2], [conftest1.$ac_ext])[]dnl
266 ])# PSPP_LINK2_IFELSE
267
268 # GSL uses "extern inline" without determining whether the compiler uses
269 # GCC inline rules or C99 inline rules.  If it uses the latter then GSL
270 # will be broken without passing -fgnu89-inline to GCC.
271 AC_DEFUN([PSPP_GSL_NEEDS_FGNU89_INLINE],
272 [# GSL only uses "inline" at all if HAVE_INLINE is defined as a macro.
273  # In turn, gnulib's gl_INLINE is one macro that does that.  We need to
274  # make sure that it has run by the time we run this test, otherwise we'll
275  # get a false result.
276  AC_REQUIRE([gl_INLINE])
277  PSPP_CHECK_CC_OPTION(
278    [-fgnu89-inline],
279    [AC_CACHE_CHECK([whether GSL needs -fgnu89-inline to link],
280                     pspp_cv_gsl_needs_fgnu89_inline, [
281                     PSPP_LINK2_IFELSE(
282                       [AC_LANG_PROGRAM([#include <gsl/gsl_math.h>
283                                        ], [GSL_MAX_INT(1,2);])],
284                       [AC_LANG_SOURCE([#include <gsl/gsl_math.h>
285                                        void x (void) {}])],
286                       [pspp_cv_gsl_needs_fgnu89_inline=no],
287                       [pspp_cv_gsl_needs_fgnu89_inline=yes])])
288      if test "$pspp_cv_gsl_needs_fgnu89_inline" = "yes"; then
289          CFLAGS="$CFLAGS -fgnu89-inline"
290      fi])
291 ])
292
293 AC_DEFUN([PSPP_CHECK_CLICKSEQUENCE],
294   [AC_REQUIRE([AM_INIT_AUTOMAKE])  # Defines MAKEINFO
295    AC_CACHE_CHECK([whether makeinfo supports @clicksequence],
296      [pspp_cv_have_clicksequence],
297      [cat > conftest.texi  <<EOF
298 @setfilename conftest.info
299 @clicksequence{File @click{} Open}
300 EOF
301       echo "configure:__oline__: running $MAKEINFO conftest.texi >&AS_MESSAGE_LOG_FD" >&AS_MESSAGE_LOG_FD
302       eval "$MAKEINFO conftest.texi >&AS_MESSAGE_LOG_FD 2>&1"
303       retval=$?
304       echo "configure:__oline__: \$? = $retval" >&AS_MESSAGE_LOG_FD
305       if test $retval = 0; then
306         pspp_cv_have_clicksequence=yes
307       else
308         pspp_cv_have_clicksequence=no
309       fi
310       rm -f conftest.texi conftest.info])
311    if test $pspp_cv_have_clicksequence = no; then
312        AM_MAKEINFOFLAGS="$AM_MAKEINFOFLAGS -DMISSING_CLICKSEQUENCE"
313        AC_SUBST([AM_MAKEINFOFLAGS])
314    fi])