Update PUI to use ffi-curl
[sxemacs] / m4 / sxe-dbms.m4
1 dnl sxe-dbms.m4 -- Database stuff
2
3
4 AC_DEFUN([_SXE_CHECK_POSTGRESQL], [dnl
5         ## (re)defines have_postgresql
6         ## defines HAVE_POSTGRESQL
7
8         ## compute pgsql specific compiler/linker flags
9         PGSQL_CPPFLAGS="-I$pgsql_incdir"
10         PGSQL_LDFLAGS="-L$pgsql_libdir ${pgsql_ldflags}"
11         ## do not add pgsql_libs here, as they concern the server only
12         PGSQL_LIBS="-lpq"
13
14         ## backup values for excursion
15         SXE_DUMP_LIBS
16         save_DB_LIBS="$DB_LIBS"
17         save_DB_LDFLAGS="$DB_LDFLAGS"
18         save_DB_CPPFLAGS="$DB_CPPFLAGS"
19
20         ## prepend temporarily
21         DB_CPPFLAGS="$PGSQL_CPPFLAGS $DB_CPPFLAGS"
22         DB_LDFLAGS="$PGSQL_LDFLAGS $DB_LDFLAGS"
23         DB_LIBS="$PGSQL_LIBS $DB_LIBS"
24
25         ## add DB_* to corresponding compiler vars temporarily
26         CPPFLAGS="$CPPFLAGS $DB_CPPFLAGS"
27         LDFLAGS="$LDFLAGS $DB_LDFLAGS $DB_LIBS"
28
29         ## check for necessary header
30         AC_CHECK_HEADERS([libpq-fe.h])
31
32         ## check for necessary functions
33         AC_CHECK_LIB([pq], [PQconnectdb])
34         AC_CHECK_LIB([pq], [PQconnectStart])
35         AC_CHECK_FUNC(PQserverVersion,
36                 [have_PQserverVersion=yes
37                  AC_DEFINE([HAVE_PQSERVERVERSION], [1],
38                          [Defined when PQserverVersion() is available])],
39                 [have_PQserverVersion=no])
40
41
42         if test "$ac_cv_header_libpq_fe_h" = "yes"; then
43                 libpq_fe_h_file="$pgsql_incdir/libpq-fe.h"
44                 AC_DEFINE_UNQUOTED([LIBPQ_FE_H_FILE], ["libpq-fe.h"],
45                         [name of the main libpq interface header file])
46         fi
47         if test "$ac_cv_lib_pq_PQconnectStart" = "yes"; then
48                 have_postgresqlv7="yes"
49                 AC_DEFINE([HAVE_POSTGRESQLV7], [1], [Description here!])
50         fi
51
52         ## final evaluation
53         if test "$ac_cv_header_libpq_fe_h" = "yes" -a \
54                 "$ac_cv_lib_pq_PQconnectdb" = "yes"; then
55                 have_postgresql="yes"
56                 AC_DEFINE([HAVE_POSTGRESQL], [1], [Description here!])
57                 ## keep the DB_* vars
58         else
59                 have_postgresql="no"
60                 ## restore all values of the DB_* vars
61                 DB_LIBS="$save_DB_LIBS"
62                 DB_LDFLAGS="$save_DB_LDFLAGS"
63                 DB_CPPFLAGS="$save_DB_CPPFLAGS"
64         fi
65         ## restore our global compiler state
66         SXE_RESTORE_LIBS
67
68 ])dnl _SXE_CHECK_POSTGRESQL
69
70 AC_DEFUN([SXE_CHECK_POSTGRESQL], [dnl
71         AC_MSG_CHECKING([for PostgreSQL])
72         AC_MSG_RESULT([])
73         AC_CHECK_PROG([have_pg_config], [pg_config], [yes], [no])
74
75         if test "$have_pg_config" = "yes"; then
76                 AC_PATH_PROG([PG_CONFIG], [pg_config], [:])
77                 pgsql_incdir=$(${PG_CONFIG} --includedir)
78                 pgsql_libdir=$(${PG_CONFIG} --libdir)
79                 pgsql_ldflags=$(${PG_CONFIG} --ldflags)
80
81                 if test -n "${PG_CONFIG}" -a -f "${PG_CONFIG}"; then
82                         pgsql_libs="$(${PG_CONFIG} --libs)"
83                 elif test -f "${pgsql_libdir}/libpq.so"; then
84                         pgsql_libs=$(${LDD} ${pgsql_libdir}/libpq.so | \
85                                 grep "=> /" | grep -v "=> /lib" | \
86                                 sed -e "s,.*/lib\(.*\)\.so.*,-l\1," | \
87                                 tr "\n" " ")
88                 else
89                         ## doesnt matter otherwise
90                         pgsql_libs=""
91                 fi
92                 if test "$have_openssl" = "no" -a -n "$(echo ${pgsql_libs} | grep ssl)"; then
93                         if test "$with_openssl" = "no"; then
94                                 AC_MSG_WARN([Your PostgreSQL seems to require OpenSSL.])
95                                 AC_MSG_WARN([Sadly OpenSSL is not available or is misconfigured,])
96                                 AC_MSG_WARN([and '--with-openssl=no' was passed. Disabling PostgreSQL])
97                                 have_postgresql="no"
98                         else
99                                 AC_MSG_WARN([Your PostgreSQL seems to require OpenSSL.])
100                                 AC_MSG_WARN([Sadly OpenSSL is not available or is misconfigured.])
101                                 AC_MSG_WARN([Performing the actual check anyway, cross your fingers!])
102                                 AC_MSG_WARN([If you still encounter problems disable using '--with-postgresql=no'.])
103                                 AC_MSG_WARN([NOTE: '--with-openssl=no' will also implictly disable PostgreSQL in this configuration.])
104                         fi
105                 fi
106         else
107                 AC_MSG_WARN([Unable to find pg_config, if you want PostgreSQL support])
108                 AC_MSG_WARN([in SXEmacs, check your PATH environment variable])
109                 AC_MSG_WARN([Performing the actual check anyway, cross your fingers!])
110         fi
111         if test "$have_postgresql" != "no"; then
112                 _SXE_CHECK_POSTGRESQL
113         fi
114         if test "$have_postgresql" = "yes"; then
115                 SXE_ADD_DB_OBJS([postgresql.o])
116                 AC_SUBST([DB_CPPFLAGS])
117                 AC_SUBST([DB_LDFLAGS])
118                 AC_SUBST([DB_LIBS])
119         else
120                 AC_MSG_WARN([Your PostgreSQL installation seems broken or is too old.])
121         fi
122 ])dnl SXE_CHECK_POSTGRESQL
123
124
125 AC_DEFUN([SXE_CHECK_LDAP], [dnl
126         AC_MSG_CHECKING([for LDAP])
127         AC_MSG_RESULT([])
128
129         ldap_libs=
130         AC_CHECK_HEADER(ldap.h, [], [have_ldap=no])
131         AC_CHECK_HEADER(lber.h, [], [have_ldap=no])
132         AC_CHECK_LIB(ldap, [ldap_search], [have_ldap=yes])
133         dnl Check for other libraries we need to link with to get the main routines.
134         if test "$have_ldap" != "yes"; then
135                 AC_CHECK_LIB(ldap, [ldap_open], [
136                         have_ldap=yes
137                         have_ldap_lber=yes], [], [-llber])
138         fi
139         if test "$habe_ldap" != "yes"; then
140                 AC_CHECK_LIB(ldap, [ldap_open], [
141                         have_ldap=yes
142                         have_ldap_lber=yes
143                         have_ldap_krb=yes], [], [-llber -lkrb])
144         fi
145         if test "$have_ldap" != "yes"; then
146                 AC_CHECK_LIB(ldap, [ldap_open], [
147                         have_ldap=yes
148                         have_ldap_lber=yes
149                         have_ldap_krb=yes
150                         have_ldap_des=yes], [], [-llber -lkrb -ldes])
151         fi
152         dnl Recently, we need -lber even though the main routines are elsewhere,
153         dnl because otherwise be get link errors w.r.t. ber_pvt_opt_on.  So just
154         dnl check for that (it's a variable not a fun but that doesn't seem to
155         dnl matter in these checks)  and stick in -lber if so.  Can't hurt (even to
156         dnl stick it in always shouldn't hurt, I don't think) ... #### Someone who
157         dnl #### understands LDAP needs to fix this properly.
158         if test "$have_ldap_lber" != "yes"; then
159                 AC_CHECK_LIB(lber, [ber_pvt_opt_on], [have_ldap_lber=yes])
160         fi
161 ])dnl SXE_CHECK_LDAP
162
163
164 AC_DEFUN([SXE_CHECK_NDBM], [dnl
165         SXE_CHECK_HEADERS([ndbm.h])
166         if test "$ac_cv_header_ndbm_h" = "yes"; then
167                 sxe_cv_feat_ndbm="yes"
168         else
169                 sxe_cv_feat_ndbm="no"
170         fi
171 ])dnl SXE_CHECK_NDBM
172
173 AC_DEFUN([SXE_CHECK_GDBM], [dnl
174         AC_REQUIRE([SXE_CHECK_NDBM])
175
176         if test "$sxe_cv_feat_ndbm" = "yes"; then
177                 AC_CHECK_LIB([gdbm], [dbm_open])
178                 AC_CHECK_LIB([gdbm_compat], [dbm_open], [:], [:], [-lgdbm])
179
180                 if test "$ac_cv_lib_gdbm_dbm_open" = "yes"; then
181                         sxe_cv_feat_gdbm="yes"
182                         libdbm="-lgdbm"
183                 elif test "$ac_cv_lib_gdbm_compat_dbm_open" = "yes"; then
184                         sxe_cv_feat_gdbm="yes"
185                         libdbm="-lgdbm_compat -lgdbm"
186                 else
187                         sxe_cv_feat_gdbm="no"
188                 fi
189         fi
190 ])dnl SXE_CHECK_GDBM
191
192 AC_DEFUN([SXE_CHECK_DBM], [dnl
193         AC_REQUIRE([SXE_CHECK_NDBM])
194
195         if test "$sxe_cv_feat_ndbm" = "yes"; then
196                 AC_CHECK_LIB([dbm], [dbm_open])
197
198                 if test "$ac_cv_lib_dbm_dbm_open" = "yes"; then
199                         sxe_cv_feat_dbm="yes"
200                         libdbm="-ldbm"
201                 else
202                         sxe_cv_feat_dbm="no"
203                 fi
204         fi
205 ])dnl SXE_CHECK_DBM
206
207 AC_DEFUN([SXE_CHECK_BERKDB], [dnl
208         SXE_MSG_CHECKING([for BerkeleyDB header file])
209
210         for header in "db/db.h" "db.h"; do
211                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
212 #include <stdlib.h>
213 #if !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1)
214 #ifdef HAVE_INTTYPES_H
215 #define __BIT_TYPES_DEFINED__
216 #include <inttypes.h>
217 typedef uint8_t  u_int8_t;
218 typedef uint16_t u_int16_t;
219 typedef uint32_t u_int32_t;
220 #ifdef WE_DONT_NEED_QUADS
221 typedef uint64_t u_int64_t;
222 #endif
223 #endif
224 #endif
225 #include <$header>
226                 ]])], [db_h_file="$header"; break])
227         done
228
229         if test -z "$db_h_file"; then
230                 SXE_MSG_RESULT([no])
231                 sxe_cv_feat_berkdb="no"
232         else
233                 SXE_MSG_RESULT([$db_h_file])
234                 sxe_cv_feat_berkdb="yes"
235         fi
236
237         SXE_MSG_CHECKING([for Berkeley DB version])
238         AC_EGREP_CPP([yes], [
239 #include <$db_h_file>
240 #if DB_VERSION_MAJOR > 1
241 yes
242 #endif
243                         ], [AC_EGREP_CPP([yes], [
244 #include <$db_h_file>
245 #if DB_VERSION_MAJOR > 2
246 yes
247 #endif
248                                 ], [AC_EGREP_CPP([yes], [
249 #include <$db_h_file>
250 #if DB_VERSION_MAJOR > 3
251 yes
252 #endif
253                                         ], [
254                                                 SXE_MSG_RESULT([4])
255                                                 dbfunc="db_create"
256                                                 dbver="4"], [
257                                         SXE_MSG_RESULT([3])
258                                         dbfunc="db_create"
259                                         dbver="3"])], [
260                                 SXE_MSG_RESULT([2])
261                                 dbfunc="db_open"
262                                 dbver="2"])], [
263                         SXE_MSG_RESULT([1])
264                         dbfunc="dbopen"
265                         dbver="1"])
266         AC_CHECK_FUNC([$dbfunc], [
267                 sxe_cv_feat_berkdb="yes"
268                 need_libdb="no"], [
269                         AC_CHECK_LIB([db], [$dbfunc], [
270                                 sxe_cv_feat_berkdb="yes"
271                                 need_libdb="yes"])])
272
273         dnl Berk db 4.1 decorates public functions with version information
274         if test "$sxe_cv_feat_berkdb" != "yes" -a "$dbver" = "4"; then
275                 rm -f $tempcname
276                 echo "#include <$db_h_file>" > $tempcname
277                 echo "configure___ dbfunc=db_create" >> $tempcname
278                 define(TAB, [   ])dnl
279                 eval $($CPP -Isrc $tempcname \
280                         | sed -n -e "s/[[ TAB]]*=[[ TAB\"]]*/='/" \
281                                 -e "s/[[ TAB\"]]*\$/'/" -e "s/^configure___//p")
282                 rm -f $tempcname
283                 AC_MSG_WARN([db_create is really $dbfunc])
284                 AC_CHECK_LIB([db], [$dbfunc], [
285                         sxe_cv_feat_berkdb="yes"
286                         need_libdb="yes"])
287         fi
288
289         if test "$sxe_cv_feat_berkdb" = "yes"; then
290                 if test -n "$db_h_file"; then
291                         AC_DEFINE_UNQUOTED([DB_H_FILE],
292                                 ["$db_h_file"], [Description here!])
293                 fi
294                 AC_DEFINE([HAVE_BERKELEY_DB], [1], [Description here!])
295                 if test "$need_libdb" = "yes"; then
296                         SXE_PREPEND([-ldb], [DB_LIBS])
297                 fi
298         else
299                 sxe_cv_feat_berkdb="no"
300         fi
301         if test "$sxe_cv_feat_berkdb" = "yes"; then
302                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
303 #include DB_H_FILE
304 main() {
305         int type = DB_UNKNOWN;
306         return 0;
307 }
308                 ]])], [have_db_unknown="yes"])
309                 if test "$have_db_unknown" = "yes"; then
310                         AC_DEFINE_UNQUOTED([HAVE_DB_UNKNOWN], [1],
311                                 [Berkley DB has DB_UNKNOWN type])
312                 fi
313         fi
314 ])dnl SXE_CHECK_BERKDB
315
316 AC_DEFUN([SXE_CHECK_NDBM_BERKDB_CONFLICT], [dnl
317         SXE_MSG_CHECKING([whether ndbm and berkdb can coexist])
318
319         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
320 #include DB_H_FILE
321 #include <ndbm.h>
322
323 int
324 main(void)
325 {
326         return 0;
327 }
328                 ]])],
329                 [sxe_cv_db_ndbm_berkdb_conflict="no"],
330                 [sxe_cv_db_ndbm_berkdb_conflict="yes"])
331
332         if test "$sxe_cv_db_ndbm_berkdb_conflict" = "no"; then
333                 SXE_MSG_RESULT([yes])
334         else
335                 SXE_MSG_RESULT([no])
336                 AC_MSG_WARN([disabling (g)dbm support again])
337         fi
338
339 ])dnl SXE_CHECK_NDBM_BERKDB_CONFLICT
340
341 dnl sxe-dbms.m4 ends here