]> arthur.barton.de Git - netatalk.git/blob - macros/db3-check.m4
We now require Berkeley DB >= 4.1. There have been several reports of strange, mostly...
[netatalk.git] / macros / db3-check.m4
1 dnl $Id: db3-check.m4,v 1.11.6.5 2004-03-30 04:18:21 bfernhomberg Exp $
2 dnl Autoconf macro to check for the Berkeley DB library
3
4 AC_DEFUN([AC_PATH_BDB], 
5 [
6         trybdbdir=""
7         dobdbsearch=yes
8         bdb_search_dirs="/usr/local/include/db4 /usr/local/include /usr/include/db4 /usr/include"
9
10
11         AC_ARG_WITH(bdb,
12                 [  --with-bdb=PATH         specify path to Berkeley DB installation[[auto]]],
13                 if test "x$withval" = "xno"; then
14                         dobdbsearch=no
15                 elif test "x$withval" = "xyes"; then
16                         dobdbsearch=yes
17                 else
18                         bdb_search_dirs="$withval/include/db4 $withval/include $withval"
19                 fi
20         )
21
22         bdbfound=no
23         if test "x$dobdbsearch" = "xyes"; then
24             for bdbdir in $bdb_search_dirs; do
25                 AC_MSG_CHECKING([for Berkeley DB headers in $bdbdir])
26                 if test -f "$bdbdir/db.h" ; then
27                         AC_MSG_RESULT([yes])
28                         bdblibdir="`echo $bdbdir | sed 's/include\/db4$/lib/'`"
29                         bdblibdir="`echo $bdblibdir | sed 's/include$/lib/'`"
30                         bdbbindir="`echo $bdbdir | sed 's/include\/db4$/bin/'`"
31                         bdbbindir="`echo $bdbbindir | sed 's/include$/bin/'`"
32
33                         savedcflags="$CFLAGS"
34                         savedldflags="$LDFLAGS"
35                         savedcppflags="$CPPFLAGS"
36                         savedlibs="$LIBS"
37                         CPPFLAGS="$CFLAGS -I$bdbdir"
38                         CFLAGS=""
39                         LDFLAGS="-L$bdblibdir $LDFLAGS"
40
41 dnl This check breaks if bdb was configured with --with-uniquename, removed for now
42 dnl                     dnl db_create is BDB >3 specific 
43 dnl                     AC_CHECK_LIB(db, db_create, [
44 dnl                             bdbfound=yes
45 dnl                             LIBS="$LIBS -ldb"
46 dnl                             BDB_LIBS="-ldb"], [
47 dnl                         AC_CHECK_LIB(db4, db_create, [
48 dnl                                     bdbfound=yes
49 dnl                                     LIBS="$LIBS -ldb4"
50 dnl                                     BDB_LIBS="-ldb4"])
51 dnl                        ])
52                         
53                         bdbfound=yes
54                         LIBS="$LIBS -ldb"
55                         BDB_LIBS="-ldb"
56
57                         dnl check for header ... should only fail if the header cannot be compiled
58                         dnl it does exist, otherwise we wouldn't be here
59
60                         if test "x$bdbfound" = "xyes"; then
61                             AC_CHECK_HEADERS(db.h, bdbfound=yes, bdbfound=no)
62                         fi
63
64                         if test "x$bdbfound" = "xno"; then
65                                 AC_MSG_WARN([Berkeley DB libraries found, but required header files cannot be used!!!])
66                         fi
67
68                         dnl check we have the correct bdb version
69                         AC_MSG_CHECKING([Berkeley DB version >= 4.1])
70                         AC_TRY_RUN([ 
71 #if STDC_HEADERS
72 #include <stdlib.h>
73 #endif
74 #include <stdio.h>
75 #include <db.h>
76
77 #define DB_MAJOR_REQ    4
78 #define DB_MINOR_REQ    1
79 #define DB_PATCH_REQ    0
80
81
82 int main(void) {
83         int major, minor, patch;
84         char *version_str;
85
86         version_str = db_version(&major, &minor, &patch);
87
88         /* check header version */
89         if (DB_VERSION_MAJOR < DB_MAJOR_REQ || DB_VERSION_MINOR < DB_MINOR_REQ ||
90             DB_VERSION_PATCH < DB_PATCH_REQ ) {
91                 printf("header file version too old (%d.%d.%d), ", DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH);
92                 exit (1);
93         }
94                 
95         /* check library version */
96         if (major < DB_MAJOR_REQ || minor < DB_MINOR_REQ || patch < DB_PATCH_REQ) {
97                 printf("library version too old (%d.%d.%d), ",major, minor, patch);
98                 exit (2);
99         }
100
101         /* check header and library match */
102         if ( major != DB_VERSION_MAJOR || minor != DB_VERSION_MINOR || patch != DB_VERSION_PATCH) {
103                 printf("header/library version mismatch (%d.%d.%d/%d.%d.%d), ",
104                          DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH, major, minor, patch);
105                 exit(3);
106         }
107
108         printf("%d.%d.%d, ",major, minor, patch); 
109         exit (0);
110 }
111 ], atalk_cv_bdbversion="yes", atalk_cv_bdbversion="no", atalk_cv_bdbversion="cross")
112
113
114                         if test ${atalk_cv_bdbversion} = "yes"; then
115                                 AC_MSG_RESULT(yes)
116                         else
117                                 AC_MSG_RESULT(no)
118                                 bdbfound=no
119                         fi
120
121                         if test "x$bdbfound" = "xyes"; then
122                                 if test "$bdbdir" != "/usr/include"; then
123                                     BDB_CFLAGS="-I$bdbdir"
124                                 fi
125                                 if test "$bdblibdir" != "/usr/lib"; then
126                                     BDB_LIBS="-L$bdblibdir $BDB_LIBS"
127                                 fi
128                                 BDB_BIN=$bdbbindir
129                                 BDB_PATH="`echo $bdbdir | sed 's,include\/db4$,,'`"
130                                 BDB_PATH="`echo $BDB_PATH | sed 's,include$,,'`"
131                         fi
132                         CFLAGS="$savedcflags"
133                         LDFLAGS="$savedldflags"
134                         CPPFLAGS="$savedcppflags"
135                         LIBS="$savedlibs"
136                         break;
137                 else
138                         AC_MSG_RESULT([no])
139                 fi
140             done
141         fi
142
143         if test "x$bdbfound" = "xyes"; then
144                 ifelse([$1], , :, [$1])
145         else
146                 ifelse([$2], , :, [$2])     
147         fi
148
149         AC_SUBST(BDB_CFLAGS)
150         AC_SUBST(BDB_LIBS)
151         AC_SUBST(BDB_BIN)
152         AC_SUBST(BDB_PATH)
153 ])
154
155