configure: Improve check for PostgreSQL's libpq.
[pspp] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2
3 dnl Initialize.
4 AC_PREREQ(2.63)
5 AC_INIT([GNU PSPP], [0.7.4], [bug-gnu-pspp@gnu.org], [pspp])
6 AC_CONFIG_HEADERS([config.h])
7 AC_CONFIG_TESTDIR([tests])
8 AM_INIT_AUTOMAKE
9
10 dnl Checks for programs.
11 AC_GNU_SOURCE
12 AC_PROG_CC
13 gl_EARLY
14 AM_PROG_CC_C_O
15 AC_LIBTOOL_WIN32_DLL
16 AC_LIBTOOL_DLOPEN
17 AC_PROG_LIBTOOL
18 PKG_PROG_PKG_CONFIG
19 m4_pattern_forbid([PKG_CHECK_MODULES])
20 PSPP_CHECK_CLICKSEQUENCE
21
22 AC_ARG_ENABLE(
23   anachronistic-dependencies, 
24   [AS_HELP_STRING([--enable-anachronistic-dependencies], 
25                   [Attempt to allow building against older versions of dependent libraries])])
26
27 PSPP_ENABLE_OPTION(-Wdeclaration-after-statement)
28
29 AM_CONDITIONAL(cc_is_gcc, test x"$GCC" = x"yes" )
30
31 PSPP_CC_FOR_BUILD
32 PSPP_PERL
33
34 dnl Internationalization macros.
35 AC_PROVIDE([AM_PO_SUBDIRS])     # PSPP provides its own po/ support.
36 AM_GNU_GETTEXT([external], [need-ngettext])
37 AM_GNU_GETTEXT_VERSION([0.17])
38 if test -n "$LIBINTL"; then
39   AC_DEFINE([DEPENDS_ON_LIBINTL], [1], 
40     [Define to 1 if libintl is a separate library, not integrated into libc])
41 fi
42
43 dnl Checks for libraries.
44 AC_SYS_LARGEFILE
45 AC_SEARCH_LIBS([sin], [m])
46 AC_SEARCH_LIBS([dcgettext], [intl])
47 PSPP_LC_PAPER
48
49
50 AC_ARG_VAR([PSPP_LDFLAGS], [linker flags to be used for linking the pspp binary only])
51 AC_ARG_VAR([PSPPIRE_LDFLAGS], [linker flags to be used for linking the psppire binary only])
52
53 # Support for Cairo and Pango.
54 AC_ARG_WITH([cairo],
55   [AS_HELP_STRING(
56     [--without-cairo], 
57     [Don't build support for charts (using Cairo and Pango);
58      implies --without-gui])],
59   [], [with_cairo=yes])
60 AM_CONDITIONAL([HAVE_CAIRO], [test "$with_cairo" != no])
61 if test "$with_cairo" != no; then
62   PKG_CHECK_MODULES([CAIRO], [cairo >= 1.5 pango >= 1.20 pangocairo], 
63     [CPPFLAGS="$CPPFLAGS $CAIRO_CFLAGS"
64      AC_DEFINE([HAVE_CAIRO], 1, 
65        [Define to 1 if Cairo and Pango are available.])],
66     [PSPP_REQUIRED_PREREQ([cairo 1.5 or later and pango 1.20 or later (or use --without-cairo)])])
67   AC_PATH_PROG([XMLLINT], [xmllint], [echo], [$PATH])
68   AC_SUBST(XMLLINT)
69 fi
70
71 # Support for GUI.
72 AC_ARG_WITH([gui], 
73   [AS_HELP_STRING([--without-gui], 
74                   [Don't build the PSPPIRE GUI (using GTK+)])],
75   [], [with_gui=yes])
76 AM_CONDITIONAL([HAVE_GUI], 
77                [test "$with_cairo" != no && test "$with_gui" != "no"])
78 if test "$with_cairo" != no && test "$with_gui" != "no"; then
79   PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.12], [],
80     [PSPP_REQUIRED_PREREQ([gtk+ 2.0 version 2.12 or later (or use --without-gui)])])
81
82   AC_ARG_VAR([GLIB_GENMARSHAL])
83   AC_CHECK_PROGS([GLIB_GENMARSHAL], [glib-genmarshal])
84   if test "x$GLIB_GENMARSHAL" = x; then
85     PSPP_REQUIRED_PREREQ([glib-genmarshal (or use --without-gui)])
86   fi
87 fi
88
89 dnl Checks needed for psql reader
90
91 dnl The 8.x series postgres tarballs installs with a default prefix of
92 dnl /usr/local/pgsql whereas, OSes (such as debian)  install into /usr .
93
94 dnl If the libpq.so file is in a non standard path, (one which the linker
95 dnl doesn't search) then we must set the PG_LDFLAGS to -R/usr/wherever/
96 dnl However, if the system happens to have more than one version of other
97 dnl dependent libraries (eg. libgtk) in different standard paths. (eg:
98 dnl /usr and /usr/local) then the wrong one may get linked. 
99
100 dnl To overcome this, we first check for libpq in the standard places, and
101 dnl only set PG_LDFLAGS if it's not found.
102
103
104 AC_ARG_WITH(
105   libpq, 
106   [AS_HELP_STRING([--without-libpq], [don't compile in Postgres capability])])
107 AC_ARG_VAR([PG_CONFIG], 
108            [Full pathname of the pg_config program shipped with Postgresql])
109 AC_PATH_PROG([PG_CONFIG], [pg_config], [], 
110              [$PATH:/usr/local/pgsql/bin:/usr/pgsql/bin])
111
112 if test x"$with_libpq" != x"no" && test -n "$PG_CONFIG" ; then 
113   AC_SUBST(PG_CONFIG)
114   PG_CFLAGS=-I`$PG_CONFIG --includedir` 
115   AC_SUBST(PG_CFLAGS)
116
117   AC_CHECK_LIB([pq], [PQexec],
118      [:], 
119      [PG_LDFLAGS="-L`$PG_CONFIG --libdir` -R`$PG_CONFIG --libdir`"])
120   AC_SUBST(PG_LDFLAGS)
121
122   PG_LIBS=-lpq
123   AC_SUBST(PG_LIBS)
124
125   PKG_CHECK_EXISTS(libssl,
126         AC_DEFINE([USE_SSL],1,
127                    [Define to 1 if the openssl library is present.])
128            ,)
129
130   # Now verify that we can actually link against libpq.  If we are
131   # cross-compiling and picked up a host libpq, or if libpq is just
132   # badly installed, this will fail.
133   AC_CACHE_CHECK(
134     [whether -lpq links successfully],
135     [pspp_cv_have_libpq],
136     [save_CPPFLAGS=$CPPFLAGS
137      save_LIBS=$LIBS
138      save_LDFLAGS=$LDFLAGS
139      CPPFLAGS="$PG_CFLAGS $CPPFLAGS"
140      LIBS="$PG_LIBS $LIBS"
141      LDFLAGS="$PG_LDFLAGS $LDFLAGS"
142      AC_LINK_IFELSE(
143        [AC_LANG_PROGRAM(
144          [#include <libpq-fe.h>
145          ], [PQfinish (0);])],
146        [pspp_cv_have_libpq=yes],
147        [pspp_cv_have_libpq=no])
148      CPPFLAGS=$save_CPPFLAGS
149      LIBS=$save_LIBS
150      LDFLAGS=$save_LDFLAGS])
151
152   if test $pspp_cv_have_libpq = yes; then
153     AC_DEFINE([PSQL_SUPPORT], [1],
154       [Define to 1 if building in support for reading from postgres
155        databases.])
156   else
157     PG_CONFIG=
158     PG_CFLAGS=
159     PG_LDFLAGS=
160     PG_LIBS=
161   fi
162 else
163   pspp_cv_have_libpq=no
164 fi
165 AM_CONDITIONAL(PSQL_SUPPORT, test $pspp_cv_have_libpq = yes)
166
167 dnl Check for libxml2
168 PKG_CHECK_MODULES(
169   [LIBXML2], [libxml-2.0], 
170   [HAVE_LIBXML2=yes],
171   [HAVE_LIBXML2=no
172    PSPP_OPTIONAL_PREREQ([libxml2])])
173
174 dnl Check for zlib.
175 AC_SEARCH_LIBS(
176   [gzopen], [z],
177   [HAVE_ZLIB=yes],
178   [HAVE_ZLIB=no
179    PSPP_OPTIONAL_PREREQ([zlib])])
180 AC_CHECK_HEADERS(
181   [zlib.h], 
182   [],
183   [HAVE_ZLIB=no
184    PSPP_OPTIONAL_PREREQ([zlib])])
185
186 dnl Avoid interference between zlib's crc32() function and gnulib's
187 dnl crc32() function, which have different signatures.  PSPP calls
188 dnl only gnulib's crc32() directly, but it calls zlib's crc32()
189 dnl indirectly through other zlib calls.  If we don't rename gnulib's
190 dnl crc32(), then zlib will call gnulib's version instead of its own,
191 dnl causing failures.  (This can happen even if zlib isn't detected
192 dnl directly, because other libraries that PSPP uses, e.g. libpng,
193 dnl sometimes use zlib themselves.)
194 AC_DEFINE(
195   [crc32], [gl_crc32],
196   [Avoid making zlib call gnulib's crc32() instead of its own.])
197
198 dnl Gnumeric support requires libxml2 and zlib.
199 if test $HAVE_LIBXML2 = yes && test $HAVE_ZLIB = yes; then
200   GNM_SUPPORT=yes
201   AC_DEFINE(
202     [GNM_SUPPORT], [1],
203     [Define to 1 if building in support for reading Gnumeric files.])
204 else
205   GNM_SUPPORT=no
206 fi
207 AM_CONDITIONAL([GNM_SUPPORT], [test $GNM_SUPPORT = yes])
208
209 dnl ODT support requires libxml2.
210 if test $HAVE_LIBXML2 = yes; then
211   AC_DEFINE(
212     [ODT_SUPPORT], [1],
213     [Define to 1 if building in support for writing ODT files.])
214 fi
215 AM_CONDITIONAL([ODT_SUPPORT], [test $HAVE_LIBXML2 = yes])
216
217 AC_ARG_WITH(
218   gui_tools,
219   [AS_HELP_STRING([--with-gui-tools], [build the gui developer tools.  For DEVELOPERS only! There is no reason why users will need this flag.])])
220 if test x"$with_gui_tools" = x"yes" ; then 
221         PKG_CHECK_MODULES(GLADE_UI, gladeui-1.0)
222 fi
223 AM_CONDITIONAL(WITH_GUI_TOOLS, test x"$with_gui_tools" = x"yes")
224
225 if test x"$cross_compiling" != x"yes"; then
226    WITH_PERL_MODULE=yes
227 else
228    WITH_PERL_MODULE=no
229 fi      
230 AC_SUBST([WITH_PERL_MODULE])
231 AM_CONDITIONAL(WITH_PERL_MODULE, test $WITH_PERL_MODULE = yes)
232
233 AC_SEARCH_LIBS([cblas_dsdot], [gslcblas],,[PSPP_REQUIRED_PREREQ([libgslcblas])])
234 AC_SEARCH_LIBS([gsl_cdf_binomial_P], [gsl],,[PSPP_REQUIRED_PREREQ([libgsl (version 1.8 or later)])])
235 PSPP_GSL_NEEDS_FGNU89_INLINE
236
237 dnl Recent versions of GNU ncurses install the curses header files into
238 dnl /usr/include/ncurses, and provide a 'ncurses5-config' program which
239 dnl enables us to discover where they are. Earlier versions don't have
240 dnl this, so we can't rely on it.  So if ncurses5-config is present,
241 dnl we'll trust it to find the right information.  Otherwise, we'll
242 dnl try to discover it ourselves.
243 dnl To confound things further, Cygwin has decided to rename ncurses5-config
244 dnl to ncurses8-config !!!
245 AC_ARG_WITH(
246   libncurses, 
247   [AS_HELP_STRING([--without-libncurses], [don't compile in ncurses functions])])
248
249 if test x"$with_libncurses" != x"no" ; then
250   if test x"$cross_compiling" != x"yes" ; then
251           AC_CHECK_PROGS([NCURSES_CONFIG], [ncurses5-config ncurses8-config])
252   fi
253   if test x"$NCURSES_CONFIG" = x ; then
254           AC_SEARCH_LIBS([tgetent], [ncurses],
255               [curses_available=yes; AC_CHECK_HEADERS([term.h curses.h],,[curses_available=no])])
256   else
257           old_cflags=$CFLAGS
258           CFLAGS="$CFLAGS `$NCURSES_CONFIG --cflags`"
259           AC_CHECK_HEADERS([term.h curses.h],[curses_available=yes])
260           CFLAGS=$old_cflags
261           if test x"$curses_available" = x"yes" ; then
262            NCURSES_LIBS=`$NCURSES_CONFIG --libs`
263            NCURSES_CFLAGS=`$NCURSES_CONFIG --cflags`
264            AC_SUBST(NCURSES_CFLAGS)
265            AC_SUBST(NCURSES_LIBS)
266           fi
267   fi
268   if test x"$curses_available" = x"yes" ; then
269           AC_DEFINE([LIBNCURSES_USABLE], 1,
270               [Define to 1 if the libncurses is both present and usable.])
271   fi
272   AC_CHECK_HEADERS([termcap.h])
273 fi
274
275 PSPP_READLINE
276
277 dnl Checks for header files.
278 AC_CHECK_HEADERS([sys/wait.h fpu_control.h ieeefp.h fenv.h pwd.h])
279
280 # For gnulib.
281 gl_INIT
282
283 AC_C_INLINE
284
285 AC_CHECK_SIZEOF(double)
286
287 AC_C_BIGENDIAN
288
289 AC_CHECK_FUNCS([__setfpucw fork execl execlp isinf isnan finite getpid feholdexcept fpsetmask popen round])
290
291 AC_PROG_LN_S
292
293 AC_ARG_ENABLE(
294   debug, 
295   [AS_HELP_STRING([--enable-debug], 
296                   [Turn on diagnostic features in the program])])
297 if test x"$enable_debug" = x"yes"  ; then
298   AC_DEFINE(DEBUGGING, 1, [Define to 1 if debugging is enabled.])
299 fi
300
301 # iconv is required
302 if test "$am_cv_func_iconv" != "yes"; then
303    PSPP_REQUIRED_PREREQ([iconv (see http://www.gnu.org/software/libiconv/)])
304 fi
305
306 dnl Required by the gnulib 'relocatable-prog' module.
307 dnl See doc/relocatable-maint.texi in the gnulib tree for details.
308 RELOCATABLE_LIBRARY_PATH='$(libdir)'
309 RELOCATABLE_STRIP=:
310
311 PSPP_CHECK_PREREQS
312
313 AC_CONFIG_FILES(
314   [Makefile gl/Makefile po/Makefile tests/atlocal perl-module/lib/PSPP.pm])
315
316 AC_OUTPUT
317 echo "PSPP configured successfully."
318
319 dnl configure.ac ends here