Merge from vendor branch FILE:
[dragonfly.git] / crypto / heimdal-0.6.3 / cf / db.m4
1 dnl $Id: db.m4,v 1.9 2002/09/10 14:29:47 joda Exp $
2 dnl
3 dnl tests for various db libraries
4 dnl
5 AC_DEFUN([rk_DB],[
6 AC_ARG_ENABLE(berkeley-db,
7                        AC_HELP_STRING([--disable-berkeley-db],
8                                       [if you don't want berkeley db]),[
9 ])
10
11 have_ndbm=no
12 db_type=unknown
13
14 if test "$enable_berkeley_db" != no; then
15
16   AC_CHECK_HEADERS([                            \
17         db4/db.h                                \
18         db3/db.h                                \
19         db.h                                    \
20         db_185.h                                \
21   ])
22
23 dnl db_create is used by db3 and db4
24
25   AC_FIND_FUNC_NO_LIBS(db_create, db4 db3 db, [
26   #include <stdio.h>
27   #ifdef HAVE_DB4_DB_H
28   #include <db4/db.h>
29   #elif defined(HAVE_DB3_DB_H)
30   #include <db3/db.h>
31   #else
32   #include <db.h>
33   #endif
34   ],[NULL, NULL, 0])
35
36   if test "$ac_cv_func_db_create" = "yes"; then
37     db_type=db3
38     if test "$ac_cv_funclib_db_create" != "yes"; then
39       DBLIB="$ac_cv_funclib_db_create"
40     else
41       DBLIB=""
42     fi
43     AC_DEFINE(HAVE_DB3, 1, [define if you have a berkeley db3/4 library])
44   else
45
46 dnl dbopen is used by db1/db2
47
48     AC_FIND_FUNC_NO_LIBS(dbopen, db2 db, [
49     #include <stdio.h>
50     #if defined(HAVE_DB2_DB_H)
51     #include <db2/db.h>
52     #elif defined(HAVE_DB_185_H)
53     #include <db_185.h>
54     #elif defined(HAVE_DB_H)
55     #include <db.h>
56     #else
57     #error no db.h
58     #endif
59     ],[NULL, 0, 0, 0, NULL])
60
61     if test "$ac_cv_func_dbopen" = "yes"; then
62       db_type=db1
63       if test "$ac_cv_funclib_dbopen" != "yes"; then
64         DBLIB="$ac_cv_funclib_dbopen"
65       else
66         DBLIB=""
67       fi
68       AC_DEFINE(HAVE_DB1, 1, [define if you have a berkeley db1/2 library])
69     fi
70   fi
71
72 dnl test for ndbm compatability
73
74   if test "$ac_cv_func_dbm_firstkey" != yes; then
75     AC_FIND_FUNC_NO_LIBS2(dbm_firstkey, $ac_cv_funclib_dbopen $ac_cv_funclib_db_create, [
76     #include <stdio.h>
77     #define DB_DBM_HSEARCH 1
78     #include <db.h>
79     DBM *dbm;
80     ],[NULL])
81   
82     if test "$ac_cv_func_dbm_firstkey" = "yes"; then
83       if test "$ac_cv_funclib_dbm_firstkey" != "yes"; then
84         LIB_NDBM="$ac_cv_funclib_dbm_firstkey"
85       else
86         LIB_NDBM=""
87       fi
88       AC_DEFINE(HAVE_DB_NDBM, 1, [define if you have ndbm compat in db])
89       AC_DEFINE(HAVE_NEW_DB, 1, [Define if NDBM really is DB (creates files *.db)])
90     else
91       $as_unset ac_cv_func_dbm_firstkey
92       $as_unset ac_cv_funclib_dbm_firstkey
93     fi
94   fi
95
96 fi # berkeley db
97
98 if test "$db_type" = "unknown" -o "$ac_cv_func_dbm_firstkey" = ""; then
99
100   AC_CHECK_HEADERS([                            \
101         dbm.h                                   \
102         ndbm.h                                  \
103   ])
104
105   AC_FIND_FUNC_NO_LIBS(dbm_firstkey, ndbm, [
106   #include <stdio.h>
107   #if defined(HAVE_NDBM_H)
108   #include <ndbm.h>
109   #elif defined(HAVE_DBM_H)
110   #include <dbm.h>
111   #endif
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_NDBM, 1, [define if you have a ndbm library])dnl
122     have_ndbm=yes
123     if test "$db_type" = "unknown"; then
124       db_type=ndbm
125       DBLIB="$LIB_NDBM"
126     fi
127   else
128
129     $as_unset ac_cv_func_dbm_firstkey
130     $as_unset ac_cv_funclib_dbm_firstkey
131
132     AC_CHECK_HEADERS([                          \
133           gdbm/ndbm.h                           \
134     ])
135
136     AC_FIND_FUNC_NO_LIBS(dbm_firstkey, gdbm, [
137     #include <stdio.h>
138     #include <gdbm/ndbm.h>
139     DBM *dbm;
140     ],[NULL])
141
142     if test "$ac_cv_func_dbm_firstkey" = "yes"; then
143       if test "$ac_cv_funclib_dbm_firstkey" != "yes"; then
144         LIB_NDBM="$ac_cv_funclib_dbm_firstkey"
145       else
146         LIB_NDBM=""
147       fi
148       AC_DEFINE(HAVE_NDBM, 1, [define if you have a ndbm library])dnl
149       have_ndbm=yes
150       if test "$db_type" = "unknown"; then
151         db_type=ndbm
152         DBLIB="$LIB_NDBM"
153       fi
154     fi
155   fi
156
157 fi # unknown
158
159 if test "$have_ndbm" = "yes"; then
160   AC_MSG_CHECKING([if ndbm is implemented with db])
161   AC_TRY_RUN([
162 #include <unistd.h>
163 #include <fcntl.h>
164 #if defined(HAVE_GDBM_NDBM_H)
165 #include <gdbm/ndbm.h>
166 #elif defined(HAVE_NDBM_H)
167 #include <ndbm.h>
168 #elif defined(HAVE_DBM_H)
169 #include <dbm.h>
170 #endif
171 int main()
172 {
173   DBM *d;
174
175   d = dbm_open("conftest", O_RDWR | O_CREAT, 0666);
176   if (d == NULL)
177     return 1;
178   dbm_close(d);
179   return 0;
180 }],[
181     if test -f conftest.db; then
182       AC_MSG_RESULT([yes])
183       AC_DEFINE(HAVE_NEW_DB, 1, [Define if NDBM really is DB (creates files *.db)])
184     else
185       AC_MSG_RESULT([no])
186     fi],[AC_MSG_RESULT([no])])
187 fi
188
189 AM_CONDITIONAL(HAVE_DB1, test "$db_type" = db1)dnl
190 AM_CONDITIONAL(HAVE_DB3, test "$db_type" = db3)dnl
191 AM_CONDITIONAL(HAVE_NDBM, test "$db_type" = ndbm)dnl
192
193 ## it's probably not correct to include LDFLAGS here, but we might
194 ## need it, for now just add any possible -L
195 z=""
196 for i in $LDFLAGS; do
197         case "$i" in
198         -L*) z="$z $i";;
199         esac
200 done
201 DBLIB="$z $DBLIB"
202 AC_SUBST(DBLIB)dnl
203 AC_SUBST(LIB_NDBM)dnl
204 ])