Move kadmin and ktutil to /usr/bin.
[heimdal.git] / cf / db.m4
blobb2749d33e5158fe74019cda2bda42e8b033b66ac
1 dnl $Id$
2 dnl
3 dnl tests for various db libraries
4 dnl
6 AC_DEFUN([rk_DB],[
7 AC_ARG_WITH(berkeley-db,
8                        AS_HELP_STRING([--with-berkeley-db],
9                                       [enable support for berkeley db @<:@default=check@:>@]),
10                        [],
11                        [with_berkeley_db=check])
13 dbheader=""
14 AC_ARG_WITH(berkeley-db-include,
15                        AS_HELP_STRING([--with-berkeley-db-include=dir],
16                                       [use berkeley-db headers in dir]),
17                        [dbheader=$withval],
18                        [with_berkeley_db_include=check])
20 AC_ARG_ENABLE(ndbm-db,
21                        AS_HELP_STRING([--disable-ndbm-db],
22                                       [if you don't want ndbm db]),[
25 AC_ARG_ENABLE(mdb-db,
26                        AS_HELP_STRING([--disable-mdb-db],
27                                       [if you don't want OpenLDAP libmdb db]),[
30 have_ndbm=no
31 db_type=unknown
33 AS_IF([test "x$with_berkeley_db" != xno],
34   [AS_IF([test "x$with_berkeley_db_include" != xcheck],
35     [AC_CHECK_HEADERS(["$dbheader/db.h"],
36                    [AC_SUBST([DBHEADER], [$dbheader])
37                     AC_DEFINE([HAVE_DBHEADER], [1],
38                                       [Define if you have user supplied header location])
39                    ],
40                    [if test "x$with_berkeley_db_include" != xcheck; then
41                      AC_MSG_FAILURE(
42                        [--with-berkeley-db-include was given but include test failed])
43                     fi
44                    ])],
45     [AC_CHECK_HEADERS([                                 \
46                    db6/db.h                             \
47                    db5/db.h                             \
48                    db4/db.h                             \
49                    db3/db.h                             \
50                    db.h                                 \
51     ])])
53 dnl db_create is used by db3 and db4 and db5
55   AC_FIND_FUNC_NO_LIBS(db_create, [$dbheader] db5 db4 db3 db, [
56   #include <stdio.h>
57   #ifdef HAVE_DBHEADER
58   #include <$dbheader/db.h>
59   #elif HAVE_DB6_DB_H
60   #include <db6/db.h>
61   #elif HAVE_DB5_DB_H
62   #include <db5/db.h>
63   #elif HAVE_DB4_DB_H
64   #include <db4/db.h>
65   #elif defined(HAVE_DB3_DB_H)
66   #include <db3/db.h>
67   #else
68   #include <db.h>
69   #endif
70   ],[NULL, NULL, 0])
72   if test "$ac_cv_func_db_create" = "yes"; then
73     db_type=db3
74     if test "$ac_cv_funclib_db_create" != "yes"; then
75       DBLIB="$ac_cv_funclib_db_create"
76     else
77       DBLIB=""
78     fi
79     AC_DEFINE(HAVE_DB3, 1, [define if you have a berkeley db3/4/5 library])
80   fi
82 dnl dbopen is used by db1/db2
84   AC_FIND_FUNC_NO_LIBS(dbopen, db2 db, [
85   #include <stdio.h>
86   #if defined(HAVE_DB2_DB_H)
87   #include <db2/db.h>
88   #elif defined(HAVE_DB_H)
89   #include <db.h>
90   #else
91   #error no db.h
92   #endif
93   ],[NULL, 0, 0, 0, NULL])
95   if test "$ac_cv_func_dbopen" = "yes"; then
96     db_type=db1
97     if test "$ac_cv_funclib_dbopen" != "yes"; then
98       DBLIB="$ac_cv_funclib_dbopen"
99     else
100       DBLIB=""
101     fi
102     AC_DEFINE(HAVE_DB1, 1, [define if you have a berkeley db1/2 library])
103   fi
105 dnl test for ndbm compatability
107   if test "$ac_cv_func_dbm_firstkey" != yes; then
108     AC_FIND_FUNC_NO_LIBS2(dbm_firstkey, $ac_cv_funclib_dbopen $ac_cv_funclib_db_create, [
109     #include <stdio.h>
110     #define DB_DBM_HSEARCH 1
111     #include <db.h>
112     DBM *dbm;
113     ],[NULL])
114   
115     if test "$ac_cv_func_dbm_firstkey" = "yes"; then
116       if test "$ac_cv_funclib_dbm_firstkey" != "yes"; then
117         LIB_NDBM="$ac_cv_funclib_dbm_firstkey"
118       else
119         LIB_NDBM=""
120       fi
121       AC_DEFINE(HAVE_DB_NDBM, 1, [define if you have ndbm compat in db])
122       AC_DEFINE(HAVE_NEW_DB, 1, [Define if NDBM really is DB (creates files *.db)])
123     else
124       $as_unset ac_cv_func_dbm_firstkey
125       $as_unset ac_cv_funclib_dbm_firstkey
126     fi
127   fi
129 ]) # fi berkeley db
131 if test "$enable_mdb_db" != "no"; then
132   if test "$db_type" = "unknown"; then
133     AC_CHECK_HEADER(mdb.h, [
134                 AC_CHECK_LIB(mdb, mdb_env_create, db_type=mdb; DBLIB="-lmdb"
135                 AC_DEFINE(HAVE_MDB, 1, [define if you have the OpenLDAP mdb library]))])
136   fi
139 if test "$enable_ndbm_db" != "no"; then
141   if test "$db_type" = "unknown" -o "$ac_cv_func_dbm_firstkey" = ""; then
143     AC_CHECK_HEADERS([                          \
144         dbm.h                                   \
145         ndbm.h                                  \
146     ])
147   
148     AC_FIND_FUNC_NO_LIBS(dbm_firstkey, ndbm, [
149     #include <stdio.h>
150     #if defined(HAVE_NDBM_H)
151     #include <ndbm.h>
152     #elif defined(HAVE_DBM_H)
153     #include <dbm.h>
154     #endif
155     DBM *dbm;
156     ],[NULL])
157   
158     if test "$ac_cv_func_dbm_firstkey" = "yes"; then
159       if test "$ac_cv_funclib_dbm_firstkey" != "yes"; then
160         LIB_NDBM="$ac_cv_funclib_dbm_firstkey"
161       else
162         LIB_NDBM=""
163       fi
164       AC_DEFINE(HAVE_NDBM, 1, [define if you have a ndbm library])dnl
165       have_ndbm=yes
166       if test "$db_type" = "unknown"; then
167         db_type=ndbm
168         DBLIB="$LIB_NDBM"
169       fi
170     else
171   
172       $as_unset ac_cv_func_dbm_firstkey
173       $as_unset ac_cv_funclib_dbm_firstkey
174   
175       AC_CHECK_HEADERS([                                \
176           gdbm/ndbm.h                           \
177       ])
178   
179       AC_FIND_FUNC_NO_LIBS(dbm_firstkey, gdbm, [
180       #include <stdio.h>
181       #include <gdbm/ndbm.h>
182       DBM *dbm;
183       ],[NULL])
184   
185       if test "$ac_cv_func_dbm_firstkey" = "yes"; then
186         if test "$ac_cv_funclib_dbm_firstkey" != "yes"; then
187         LIB_NDBM="$ac_cv_funclib_dbm_firstkey"
188         else
189         LIB_NDBM=""
190         fi
191         AC_DEFINE(HAVE_NDBM, 1, [define if you have a ndbm library])dnl
192         have_ndbm=yes
193         if test "$db_type" = "unknown"; then
194         db_type=ndbm
195         DBLIB="$LIB_NDBM"
196         fi
197       fi
198     fi
199   fi #enable_ndbm_db
200 fi # unknown
202 if test "$have_ndbm" = "yes"; then
203   AC_MSG_CHECKING([if ndbm is implemented with db])
204   AC_RUN_IFELSE([AC_LANG_SOURCE([[
205 #include <unistd.h>
206 #include <fcntl.h>
207 #if defined(HAVE_GDBM_NDBM_H)
208 #include <gdbm/ndbm.h>
209 #elif defined(HAVE_NDBM_H)
210 #include <ndbm.h>
211 #elif defined(HAVE_DBM_H)
212 #include <dbm.h>
213 #endif
214 int main(int argc, char **argv)
216   DBM *d;
218   d = dbm_open("conftest", O_RDWR | O_CREAT, 0666);
219   if (d == NULL)
220     return 1;
221   dbm_close(d);
222   return 0;
223 }]])],[
224     if test -f conftest.db; then
225       AC_MSG_RESULT([yes])
226       AC_DEFINE(HAVE_NEW_DB, 1, [Define if NDBM really is DB (creates files *.db)])
227     else
228       AC_MSG_RESULT([no])
229     fi],[AC_MSG_RESULT([no])],[AC_MSG_RESULT([no-cross])])
232 AM_CONDITIONAL(HAVE_DB1, test "$db_type" = db1)dnl
233 AM_CONDITIONAL(HAVE_DB3, test "$db_type" = db3)dnl
234 AM_CONDITIONAL(HAVE_MDB, test "$db_type" = mdb)dnl
235 AM_CONDITIONAL(HAVE_NDBM, test "$db_type" = ndbm)dnl
236 AM_CONDITIONAL(HAVE_DBHEADER, test "$dbheader" != "")dnl
238 ## it's probably not correct to include LDFLAGS here, but we might
239 ## need it, for now just add any possible -L
240 z=""
241 for i in $LDFLAGS; do
242         case "$i" in
243         -L*) z="$z $i";;
244         esac
245 done
246 DBLIB="$z $DBLIB"
247 AC_SUBST(DBLIB)dnl
248 AC_SUBST(LIB_NDBM)dnl