GSS_S_PROMPTING_NEEDED is a bit
[cyrus-sasl.git] / cmulocal / berkdb.m4
1 dnl $Id: berkdb.m4,v 1.20 2005/04/26 19:14:07 shadow Exp $
2
3 AC_DEFUN([CMU_DB_INC_WHERE1], [
4 saved_CPPFLAGS=$CPPFLAGS
5 CPPFLAGS="$saved_CPPFLAGS -I$1"
6 AC_TRY_COMPILE([#include <db.h>],
7 [DB *db;
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
13 ])
14
15 AC_DEFUN([CMU_DB_INC_WHERE], [
16    for i in $1; do
17       AC_MSG_CHECKING(for db headers in $i)
18       CMU_DB_INC_WHERE1($i)
19       CMU_TEST_INCPATH($i, db)
20       if test "$ac_cv_found_db_inc" = "yes"; then
21         ac_cv_db_where_inc=$i
22         AC_MSG_RESULT(found)
23         break
24       else
25         AC_MSG_RESULT(not found)
26       fi
27     done
28 ])
29
30 #
31 # Test for lib files
32 #
33
34 AC_DEFUN([CMU_DB3_LIB_WHERE1], [
35 AC_REQUIRE([CMU_AFS])
36 AC_REQUIRE([CMU_KRB4])
37 saved_LIBS=$LIBS
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)
43 LIBS=$saved_LIBS
44 ])
45 AC_DEFUN([CMU_DB4_LIB_WHERE1], [
46 AC_REQUIRE([CMU_AFS])
47 AC_REQUIRE([CMU_KRB4])
48 saved_LIBS=$LIBS
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)
54 LIBS=$saved_LIBS
55 ])
56
57 AC_DEFUN([CMU_DB_LIB_WHERE], [
58    for i in $1; do
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
64 else
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
68 fi
69       if test "$ac_cv_found_db_lib" = "yes" ; then
70         ac_cv_db_where_lib=$i
71         AC_MSG_RESULT(found)
72         break
73       else
74         AC_MSG_RESULT(not found)
75       fi
76     done
77 ])
78
79 AC_DEFUN([CMU_USE_DB], [
80 AC_REQUIRE([CMU_FIND_LIB_SUBDIR])
81 AC_ARG_WITH(db,
82         [  --with-db=PREFIX      Compile with db support],
83         [if test "X$with_db" = "X"; then
84                 with_db=yes
85         fi])
86 AC_ARG_WITH(db-lib,
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])
90         fi])
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])
95         fi])
96 AC_ARG_ENABLE(db4,
97         [  --enable-db4          use db 4.x libraries])
98         
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
103           fi
104         fi
105
106         if test "X$with_db_lib" != "X"; then
107           ac_cv_db_where_lib=$with_db_lib
108         fi
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)
111         fi
112
113         if test "X$with_db_include" != "X"; then
114           ac_cv_db_where_inc=$with_db_include
115         fi
116         if test "X$ac_cv_db_where_inc" = "X"; then
117           CMU_DB_INC_WHERE(/usr/athena/include /usr/local/include)
118         fi
119
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
122           ac_cv_found_db=no
123           AC_MSG_RESULT(no)
124         else
125           ac_cv_found_db=yes
126           AC_MSG_RESULT(yes)
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"
132           else
133              DB_LIB_FLAGS="-L${DB_LIB_DIR} -ldb-3"
134           fi
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
140                 RPATH=""
141           fi
142           case "${host}" in
143             *-*-linux*)
144               if test "X$RPATH" = "X"; then
145                 RPATH="-Wl,-rpath,${DB_LIB_DIR}"
146               else 
147                 RPATH="${RPATH}:${DB_LIB_DIR}"
148               fi
149               ;;
150             *-*-hpux*)
151               if test "X$RPATH" = "X"; then
152                 RPATH="-Wl,+b${DB_LIB_DIR}"
153               else 
154                 RPATH="${RPATH}:${DB_LIB_DIR}"
155               fi
156               ;;
157             *-*-irix*)
158               if test "X$RPATH" = "X"; then
159                 RPATH="-Wl,-rpath,${DB_LIB_DIR}"
160               else 
161                 RPATH="${RPATH}:${DB_LIB_DIR}"
162               fi
163               ;;
164             *-*-solaris2*)
165               if test "$ac_cv_prog_gcc" = yes; then
166                 if test "X$RPATH" = "X"; then
167                   RPATH="-Wl,-R${DB_LIB_DIR}"
168                 else 
169                   RPATH="${RPATH}:${DB_LIB_DIR}"
170                 fi
171               else
172                 RPATH="${RPATH} -R${DB_LIB_DIR}"
173               fi
174               ;;
175           esac
176           AC_SUBST(RPATH)
177         fi
178         ])
179
180
181
182 dnl ---- CUT HERE ---
183
184 dnl These are the Cyrus Berkeley DB macros.  In an ideal world these would be
185 dnl identical to the above.
186
187 dnl They are here so that they can be shared between Cyrus IMAPd
188 dnl and Cyrus SASL with relative ease.
189
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.
193
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
196 dnl handling.
197
198 dnl Call these with BERKELEY_DB_CHK.
199
200 dnl We will also set $dblib to "berkeley" if we are successful, "no" otherwise.
201
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],
205 [
206         BDB_SAVE_LDFLAGS=$LDFLAGS
207
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)
211         else
212             BDB_LIBADD=""
213         fi
214
215         saved_LIBS=$LIBS
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
217           do
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,
222             dblib="no")
223             if test "$dblib" = "berkeley"; then break; fi
224           done
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,
230             dblib="no")
231         fi
232         LIBS=$saved_LIBS
233
234         LDFLAGS=$BDB_SAVE_LDFLAGS
235 ])
236
237 AC_DEFUN([CYRUS_BERKELEY_DB_OPTS],
238 [
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 ])
247 ])
248
249 AC_DEFUN([CYRUS_BERKELEY_DB_CHK],
250 [
251         AC_REQUIRE([CYRUS_BERKELEY_DB_OPTS])
252
253         cmu_save_CPPFLAGS=$CPPFLAGS
254
255         if test -d $with_bdb_inc; then
256             CPPFLAGS="$CPPFLAGS -I$with_bdb_inc"
257             BDB_INCADD="-I$with_bdb_inc"
258         else
259             BDB_INCADD=""
260         fi
261
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()],
266                         dblib="no")
267
268         CPPFLAGS=$cmu_save_CPPFLAGS
269 ])