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