roken: rk_undumpdata free allocation on error
[heimdal.git] / cf / db.m4
blob49ffd81ef7698b6b3438d4c4396b6b277e957370
1 dnl $Id$
2 dnl
3 dnl tests for various db libraries
4 dnl
6 AC_DEFUN([rk_DB],[
7 AC_ARG_WITH(db-type-preference,
8                        AS_HELP_STRING([--with-db-type-preference],
9                                       [specify HDB backend DB type preference as whitespace-separated list]),
10                        [db_type_preference="$withval"],
11                        [db_type_preference="lmdb db3 db1 sqlite"])
12 AC_ARG_WITH(berkeley-db,
13                        AS_HELP_STRING([--with-berkeley-db],
14                                       [enable support for berkeley db @<:@default=check@:>@]),
15                        [],
16                        [with_berkeley_db=check])
18 dbheader=""
19 AC_ARG_WITH(berkeley-db-include,
20                        AS_HELP_STRING([--with-berkeley-db-include=dir],
21                                       [use berkeley-db headers in dir]),
22                        [dbheader=$withval],
23                        [with_berkeley_db_include=check])
25 AC_ARG_ENABLE(ndbm-db,
26                        AS_HELP_STRING([--disable-ndbm-db],
27                                       [if you don't want ndbm db]),[
30 AC_ARG_ENABLE(mdb-db,
31                        AS_HELP_STRING([--disable-mdb-db],
32                                       [if you don't want LMDB]),[
35 have_db1=no
36 have_db3=no
37 have_lmdb=no
38 db_type=unknown
40 AS_IF([test "x$with_berkeley_db" != xno],
41   [AS_IF([test "x$with_berkeley_db_include" != xcheck],
42     [AC_CHECK_HEADERS(["$dbheader/db.h"],
43                    [AC_SUBST([DBHEADER], [$dbheader])
44                     AC_DEFINE([HAVE_DBHEADER], [1],
45                                       [Define if you have user supplied header location])
46                    ],
47                    [if test "x$with_berkeley_db_include" != xcheck; then
48                      AC_MSG_FAILURE(
49                        [--with-berkeley-db-include was given but include test failed])
50                     fi
51                    ])],
52     [AC_CHECK_HEADERS([                                 \
53                    db6/db.h                             \
54                    db5/db.h                             \
55                    db4/db.h                             \
56                    db3/db.h                             \
57                    db.h                                 \
58     ])])
60 dnl db_create is used by db3 and db4 and db5
62   AC_FIND_FUNC_NO_LIBS(db_create, [$dbheader] db-5 db5 db4 db3 db, [
63   #include <stdio.h>
64   #ifdef HAVE_DBHEADER
65   #include <$dbheader/db.h>
66   #elif HAVE_DB6_DB_H
67   #include <db6/db.h>
68   #elif HAVE_DB5_DB_H
69   #include <db5/db.h>
70   #elif HAVE_DB4_DB_H
71   #include <db4/db.h>
72   #elif defined(HAVE_DB3_DB_H)
73   #include <db3/db.h>
74   #else
75   #include <db.h>
76   #endif
77   ],[NULL, NULL, 0])
79   if test "$ac_cv_func_db_create" = "yes"; then
80     have_db3=yes
81     if test "$ac_cv_funclib_db_create" != "yes"; then
82       DB3LIB="$ac_cv_funclib_db_create"
83     else
84       DB3LIB=""
85     fi
86     AC_DEFINE(HAVE_DB3, 1, [define if you have a berkeley db3/4/5 library])
87   fi
89 dnl dbopen is used by db1/db2
91   AC_FIND_FUNC_NO_LIBS(dbopen, db2 db, [
92   #include <stdio.h>
93   #if defined(HAVE_DB2_DB_H)
94   #include <db2/db.h>
95   #elif defined(HAVE_DB_H)
96   #include <db.h>
97   #else
98   #error no db.h
99   #endif
100   ],[NULL, 0, 0, 0, NULL])
102   if test "$ac_cv_func_dbopen" = "yes"; then
103     have_db1=yes
104     if test "$ac_cv_funclib_dbopen" != "yes"; then
105       DB1LIB="$ac_cv_funclib_dbopen"
106     else
107       DB1LIB=""
108     fi
109     AC_DEFINE(HAVE_DB1, 1, [define if you have a berkeley db1/2 library])
110   fi
112 dnl test for ndbm compatability
114   if test "$ac_cv_func_dbm_firstkey" != yes; then
115     AC_FIND_FUNC_NO_LIBS2(dbm_firstkey, $ac_cv_funclib_dbopen $ac_cv_funclib_db_create, [
116     #include <stdio.h>
117     #define DB_DBM_HSEARCH 1
118     #include <db.h>
119     DBM *dbm;
120     ],[NULL])
121   
122     if test "$ac_cv_func_dbm_firstkey" = "yes"; then
123       if test "$ac_cv_funclib_dbm_firstkey" != "yes"; then
124         NDBMLIB="$ac_cv_funclib_dbm_firstkey"
125       else
126         NDBMLIB=""
127       fi
128       AC_DEFINE(HAVE_DB_NDBM, 1, [define if you have ndbm compat in db])
129       AC_DEFINE(HAVE_NEW_DB, 1, [Define if NDBM really is DB (creates files *.db)])
130     else
131       $as_unset ac_cv_func_dbm_firstkey
132       $as_unset ac_cv_funclib_dbm_firstkey
133     fi
134   fi
136 ]) # fi berkeley db
139 AS_IF([test "x$enable_mdb_db" != xno],
140     [AC_CHECK_HEADER(lmdb.h, [
141                 AC_CHECK_LIB(lmdb, mdb_env_create, have_lmdb=yes; LMDBLIB="-llmdb"
142                 AC_DEFINE(HAVE_LMDB, 1, [define if you have the LMDB library]))])])
144 for db_type in unknown $db_type_preference; do
145     if eval test \"x\$have_${db_type}\" = xyes; then
146         break
147     fi
148     db_type=unknown
149 done
151 AS_IF([test "x$have_db3" = xyes -a "$db_type" = unknown], db_type=db3, db_type="$db_type")
152 AS_IF([test "x$have_db1" = xyes -a "$db_type" = unknown], db_type=db1, db_type="$db_type")
153 AS_IF([test "x$have_lmdb" = xyes -a "$db_type" = unknown], db_type=lmdb, db_type="$db_type")
155 if test "$enable_ndbm_db" != "no"; then
157   if test "$db_type" = "unknown" -o "$ac_cv_func_dbm_firstkey" = ""; then
159     AC_CHECK_HEADERS([                          \
160         dbm.h                                   \
161         ndbm.h                                  \
162     ])
163   
164     AC_FIND_FUNC_NO_LIBS(dbm_firstkey, ndbm, [
165     #include <stdio.h>
166     #if defined(HAVE_NDBM_H)
167     #include <ndbm.h>
168     #elif defined(HAVE_DBM_H)
169     #include <dbm.h>
170     #endif
171     DBM *dbm;
172     ],[NULL])
173   
174     if test "$ac_cv_func_dbm_firstkey" = "yes"; then
175       if test "$ac_cv_funclib_dbm_firstkey" != "yes"; then
176         NDBMLIB="$ac_cv_funclib_dbm_firstkey"
177       else
178         NDBMLIB=""
179       fi
180       AC_DEFINE(HAVE_NDBM, 1, [define if you have a ndbm library])dnl
181       have_ndbm=yes
182     else
183   
184       $as_unset ac_cv_func_dbm_firstkey
185       $as_unset ac_cv_funclib_dbm_firstkey
186   
187       AC_CHECK_HEADERS([                                \
188           gdbm/ndbm.h                           \
189       ])
190   
191       AC_FIND_FUNC_NO_LIBS(dbm_firstkey, gdbm, [
192       #include <stdio.h>
193       #include <gdbm/ndbm.h>
194       DBM *dbm;
195       ],[NULL])
196   
197       if test "$ac_cv_func_dbm_firstkey" = "yes"; then
198         if test "$ac_cv_funclib_dbm_firstkey" != "yes"; then
199         NDBMLIB="$ac_cv_funclib_dbm_firstkey"
200         else
201         NDBMLIB=""
202         fi
203         AC_DEFINE(HAVE_NDBM, 1, [define if you have a ndbm library])dnl
204         have_ndbm=yes
205         if test "$db_type" = "unknown"; then
206         db_type=ndbm
207         fi
208       fi
209     fi
210   fi #enable_ndbm_db
211 fi # unknown
213 if test "$have_ndbm" = "yes"; then
214   AC_MSG_CHECKING([if ndbm is implemented with db])
215   AC_RUN_IFELSE([AC_LANG_SOURCE([[
216 #include <unistd.h>
217 #include <fcntl.h>
218 #if defined(HAVE_GDBM_NDBM_H)
219 #include <gdbm/ndbm.h>
220 #elif defined(HAVE_NDBM_H)
221 #include <ndbm.h>
222 #elif defined(HAVE_DBM_H)
223 #include <dbm.h>
224 #endif
225 int main(int argc, char **argv)
227   DBM *d;
229   d = dbm_open("conftest", O_RDWR | O_CREAT, 0666);
230   if (d == NULL)
231     return 1;
232   dbm_close(d);
233   return 0;
234 }]])],[
235     if test -f conftest.db; then
236       AC_MSG_RESULT([yes])
237       AC_DEFINE(HAVE_NEW_DB, 1, [Define if NDBM really is DB (creates files *.db)])
238     else
239       AC_MSG_RESULT([no])
240     fi],[AC_MSG_RESULT([no])],[AC_MSG_RESULT([no-cross])])
243 AM_CONDITIONAL(HAVE_DB1, test "$have_db1" = yes)dnl
244 AM_CONDITIONAL(HAVE_DB3, test "$have_db3" = yes)dnl
245 AM_CONDITIONAL(HAVE_LMDB, test "$have_lmdb" = yes)dnl
246 AM_CONDITIONAL(HAVE_NDBM, test "$have_ndbm" = yes)dnl
247 AM_CONDITIONAL(HAVE_DBHEADER, test "$dbheader" != "")dnl
249 ## it's probably not correct to include LDFLAGS here, but we might
250 ## need it, for now just add any possible -L
251 z=""
252 for i in $LDFLAGS; do
253         case "$i" in
254         -L*) z="$z $i";;
255         esac
256 done
257 DB3LIB="$z $DB3LIB"
258 DB1LIB="$z $DB1LIB"
259 LMDBLIB="$z $LMDBLIB"
260 NDMBLIB="$z $NDBMLIB"
261 AC_SUBST(DB3LIB)dnl
262 AC_SUBST(DB1LIB)dnl
263 AC_SUBST(LMDBLIB)dnl
264 AC_SUBST(NDBMLIB)dnl
265 AC_SUBST(NDBMLIB)dnl
266 AC_SUBST(db_type)dnl
267 AC_SUBST(db_type_preference)dnl