1 dnl $Id: berkdb.m4,v 1.20 2005/04/26 19:14:07 shadow Exp $
3 AC_DEFUN([CMU_DB_INC_WHERE1], [
4 saved_CPPFLAGS=$CPPFLAGS
5 CPPFLAGS="$saved_CPPFLAGS -I$1"
6 AC_TRY_COMPILE([#include <db.h>],
8 db_create(&db, NULL, 0);
9 db->open(db, "foo.db", NULL, DB_UNKNOWN, DB_RDONLY, 0644);],
10 ac_cv_found_db_inc=yes,
11 ac_cv_found_db_inc=no)
12 CPPFLAGS=$saved_CPPFLAGS
15 AC_DEFUN([CMU_DB_INC_WHERE], [
17 AC_MSG_CHECKING(for db headers in $i)
19 CMU_TEST_INCPATH($i, db)
20 if test "$ac_cv_found_db_inc" = "yes"; then
25 AC_MSG_RESULT(not found)
34 AC_DEFUN([CMU_DB3_LIB_WHERE1], [
36 AC_REQUIRE([CMU_KRB4])
38 LIBS="$saved_LIBS -L$1 -ldb-3"
39 AC_TRY_LINK([#include <db.h>],
40 [db_env_create(NULL, 0);],
41 [ac_cv_found_db_3_lib=yes],
42 ac_cv_found_db_3_lib=no)
45 AC_DEFUN([CMU_DB4_LIB_WHERE1], [
47 AC_REQUIRE([CMU_KRB4])
49 LIBS="$saved_LIBS -L$1 -ldb-4"
50 AC_TRY_LINK([#include <db.h>],
51 [db_env_create(NULL, 0);],
52 [ac_cv_found_db_4_lib=yes],
53 ac_cv_found_db_4_lib=no)
57 AC_DEFUN([CMU_DB_LIB_WHERE], [
59 AC_MSG_CHECKING(for db libraries in $i)
60 if test "$enable_db4" = "yes"; then
61 CMU_DB4_LIB_WHERE1($i)
62 CMU_TEST_LIBPATH($i, [db-4])
63 ac_cv_found_db_lib=$ac_cv_found_db_4_lib
65 CMU_DB3_LIB_WHERE1($i)
66 CMU_TEST_LIBPATH($i, [db-3])
67 ac_cv_found_db_lib=$ac_cv_found_db_3_lib
69 if test "$ac_cv_found_db_lib" = "yes" ; then
74 AC_MSG_RESULT(not found)
79 AC_DEFUN([CMU_USE_DB], [
80 AC_REQUIRE([CMU_FIND_LIB_SUBDIR])
82 [ --with-db=PREFIX Compile with db support],
83 [if test "X$with_db" = "X"; then
87 [ --with-db-lib=dir use db libraries in dir],
88 [if test "$withval" = "yes" -o "$withval" = "no"; then
89 AC_MSG_ERROR([No argument for --with-db-lib])
91 AC_ARG_WITH(db-include,
92 [ --with-db-include=dir use db headers in dir],
93 [if test "$withval" = "yes" -o "$withval" = "no"; then
94 AC_MSG_ERROR([No argument for --with-db-include])
97 [ --enable-db4 use db 4.x libraries])
99 if test "X$with_db" != "X"; then
100 if test "$with_db" != "yes"; then
101 ac_cv_db_where_lib=$with_db/$CMU_LIB_SUBDIR
102 ac_cv_db_where_inc=$with_db/include
106 if test "X$with_db_lib" != "X"; then
107 ac_cv_db_where_lib=$with_db_lib
109 if test "X$ac_cv_db_where_lib" = "X"; then
110 CMU_DB_LIB_WHERE(/usr/athena/$CMU_LIB_SUBDIR /usr/$CMU_LIB_SUBDIR /usr/local/$CMU_LIB_SUBDIR)
113 if test "X$with_db_include" != "X"; then
114 ac_cv_db_where_inc=$with_db_include
116 if test "X$ac_cv_db_where_inc" = "X"; then
117 CMU_DB_INC_WHERE(/usr/athena/include /usr/local/include)
120 AC_MSG_CHECKING(whether to include db)
121 if test "X$ac_cv_db_where_lib" = "X" -o "X$ac_cv_db_where_inc" = "X"; then
127 DB_INC_DIR=$ac_cv_db_where_inc
128 DB_LIB_DIR=$ac_cv_db_where_lib
129 DB_INC_FLAGS="-I${DB_INC_DIR}"
130 if test "$enable_db4" = "yes"; then
131 DB_LIB_FLAGS="-L${DB_LIB_DIR} -ldb-4"
133 DB_LIB_FLAGS="-L${DB_LIB_DIR} -ldb-3"
135 dnl Do not force configure.in to put these in CFLAGS and LIBS unconditionally
136 dnl Allow makefile substitutions....
137 AC_SUBST(DB_INC_FLAGS)
138 AC_SUBST(DB_LIB_FLAGS)
139 if test "X$RPATH" = "X"; then
144 if test "X$RPATH" = "X"; then
145 RPATH="-Wl,-rpath,${DB_LIB_DIR}"
147 RPATH="${RPATH}:${DB_LIB_DIR}"
151 if test "X$RPATH" = "X"; then
152 RPATH="-Wl,+b${DB_LIB_DIR}"
154 RPATH="${RPATH}:${DB_LIB_DIR}"
158 if test "X$RPATH" = "X"; then
159 RPATH="-Wl,-rpath,${DB_LIB_DIR}"
161 RPATH="${RPATH}:${DB_LIB_DIR}"
165 if test "$ac_cv_prog_gcc" = yes; then
166 if test "X$RPATH" = "X"; then
167 RPATH="-Wl,-R${DB_LIB_DIR}"
169 RPATH="${RPATH}:${DB_LIB_DIR}"
172 RPATH="${RPATH} -R${DB_LIB_DIR}"
182 dnl ---- CUT HERE ---
184 dnl These are the Cyrus Berkeley DB macros. In an ideal world these would be
185 dnl identical to the above.
187 dnl They are here so that they can be shared between Cyrus IMAPd
188 dnl and Cyrus SASL with relative ease.
190 dnl The big difference between this and the ones above is that we don't assume
191 dnl that we know the name of the library, and we try a lot of permutations
192 dnl instead. We also assume that DB4 is acceptable.
194 dnl When we're done, there will be a BDB_LIBADD and a BDB_INCADD which should
195 dnl be used when necessary. We should probably be smarter about our RPATH
198 dnl Call these with BERKELEY_DB_CHK.
200 dnl We will also set $dblib to "berkeley" if we are successful, "no" otherwise.
202 dnl this is unbelievably painful due to confusion over what db-3 should be
203 dnl named and where the db-3 header file is located. arg.
204 AC_DEFUN([CYRUS_BERKELEY_DB_CHK_LIB],
206 BDB_SAVE_LDFLAGS=$LDFLAGS
208 if test -d $with_bdb_lib; then
209 CMU_ADD_LIBPATH_TO($with_bdb_lib, LDFLAGS)
210 CMU_ADD_LIBPATH_TO($with_bdb_lib, BDB_LIBADD)
216 for dbname in db-4.4 db4.4 db44 db-4.3 db4.3 db43 db-4.2 db4.2 db42 db-4.1 db4.1 db41 db-4.0 db4.0 db-4 db40 db4 db-3.3 db3.3 db33 db-3.2 db3.2 db32 db-3.1 db3.1 db31 db-3 db30 db3 db
218 LIBS="$saved_LIBS -l$dbname"
219 AC_TRY_LINK([#include <db.h>],
220 [db_create(NULL, NULL, 0);],
221 BDB_LIBADD="$BDB_LIBADD -l$dbname"; dblib="berkeley"; dbname=db,
223 if test "$dblib" = "berkeley"; then break; fi
225 if test "$dblib" = "no"; then
226 LIBS="$saved_LIBS -ldb"
227 AC_TRY_LINK([#include <db.h>],
228 [db_open(NULL, 0, 0, 0, NULL, NULL, NULL);],
229 BDB_LIBADD="$BDB_LIBADD -ldb"; dblib="berkeley"; dbname=db,
234 LDFLAGS=$BDB_SAVE_LDFLAGS
237 AC_DEFUN([CYRUS_BERKELEY_DB_OPTS],
239 AC_ARG_WITH(bdb-libdir,
240 [ --with-bdb-libdir=DIR Berkeley DB lib files are in DIR],
241 with_bdb_lib=$withval,
242 [ test "${with_bdb_lib+set}" = set || with_bdb_lib=none])
243 AC_ARG_WITH(bdb-incdir,
244 [ --with-bdb-incdir=DIR Berkeley DB include files are in DIR],
245 with_bdb_inc=$withval,
246 [ test "${with_bdb_inc+set}" = set || with_bdb_inc=none ])
249 AC_DEFUN([CYRUS_BERKELEY_DB_CHK],
251 AC_REQUIRE([CYRUS_BERKELEY_DB_OPTS])
253 cmu_save_CPPFLAGS=$CPPFLAGS
255 if test -d $with_bdb_inc; then
256 CPPFLAGS="$CPPFLAGS -I$with_bdb_inc"
257 BDB_INCADD="-I$with_bdb_inc"
262 dnl Note that FreeBSD puts it in a wierd place
263 dnl (but they should use with-bdb-incdir)
264 AC_CHECK_HEADER(db.h,
265 [CYRUS_BERKELEY_DB_CHK_LIB()],
268 CPPFLAGS=$cmu_save_CPPFLAGS