Index: configure.in
===================================================================
RCS file: /cvs/gnome/evolution-data-server/configure.in,v
retrieving revision 1.153
diff -u -r1.153 configure.in
--- configure.in	21 Jan 2006 10:04:36 -0000	1.153
+++ configure.in	30 Jan 2006 09:31:34 -0000
@@ -182,6 +182,38 @@
 				      [AC_MSG_ERROR([No regex library found])])])
 AC_SUBST(REGEX_LIBS)
 
+dnl **************************************************
+dnl * libdb checking
+dnl **************************************************
+
+AC_ARG_WITH(libdb, AC_HELP_STRING([--with-libdb],[Prefix where libdb is installed]), dynamic_libdb=yes, dynamic_libdb=no)
+if test "x${dynamic_libdb}" = "xyes"; then
+        DB_CFLAGS="-I$withval/include"
+        DB_LIBS="-L$withval/lib -ldb"
+
+        AC_MSG_CHECKING([Berkeley DB])
+        save_cflags=$CFLAGS; CFLAGS=$DB_CFLAGS
+        save_libs=$LIBS; LIBS="$DB_LIBS"
+        AC_LINK_IFELSE(
+                [AC_LANG_PROGRAM([[#include <db.h>]],
+                                 [db_create(NULL, NULL, 0)])],
+                AC_MSG_RESULT(yes),
+                AC_MSG_ERROR(cannot find libdb))
+        CFLAGS=$save_cflags
+        LIBS=$save_libs
+
+        msg_libdb="dynamically linked"
+else
+        DB_CFLAGS="-I\$(top_srcdir)/libdb/dist"
+        DB_LIBS="\$(top_builddir)/libdb/dist/libdb-4.1.la"
+        AC_MSG_NOTICE(Using local libdb)
+        msg_libdb="statically linked to local copy"
+fi
+AM_CONDITIONAL(WITH_LIBDB, test "x$dynamic_libdb" != "xno")
+AC_SUBST(DB_CFLAGS)
+AC_SUBST(DB_LIBS)
+
+
 dnl ******************************
 dnl iconv checking
 dnl ******************************
@@ -1270,8 +1302,9 @@
 export privincludedir
 export privdatadir
 AC_CONFIG_SUBDIRS(calendar/libical)
-AC_CONFIG_SUBDIRS(libdb/dist)
-
+if test $dynamic_libdb = no; then
+        AC_CONFIG_SUBDIRS(libdb/dist)
+fi
 AC_OUTPUT([
 Makefile
 evolution-data-server-zip
@@ -1373,6 +1406,7 @@
 	SSL support:      $msg_ssl
 	SMIME support:    $msg_smime
 	IPv6 support:     $msg_ipv6
+	Berkeley DB:      $msg_libdb
 	Exchange support: $msg_exchange
 	Dot Locking:	  $msg_dot
 	File Locking:	  $msg_file
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/evolution-data-server/Makefile.am,v
retrieving revision 1.20
diff -u -p -r1.20 Makefile.am
--- Makefile.am	2 Dec 2005 00:06:42 -0000	1.20
+++ Makefile.am	30 Jan 2006 09:06:06 -0000
@@ -1,7 +1,11 @@
 AUTOMAKE_OPTIONS = 1.6
 DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
 
-SUBDIRS = libdb win32 libedataserver servers camel addressbook calendar libedataserverui src docs art po
+if ! WITH_LIBDB
+LIBDB = libdb
+endif
+
+SUBDIRS = $(LIBDB) win32 libedataserver servers camel addressbook calendar libedataserverui src docs art po
 DIST_SUBDIRS= win32 libedataserver servers camel addressbook calendar libedataserverui src docs art po
 
 changelogs =			\
Index: addressbook/backends/file/Makefile.am
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/backends/file/Makefile.am,v
retrieving revision 1.9
diff -u -p -r1.9 Makefile.am
--- addressbook/backends/file/Makefile.am	22 Jun 2005 12:34:21 -0000	1.9
+++ addressbook/backends/file/Makefile.am	30 Jan 2006 09:06:52 -0000
@@ -4,7 +4,7 @@ INCLUDES =						\
 	-I$(top_builddir)				\
 	-I$(top_srcdir)/addressbook			\
 	-I$(top_builddir)/addressbook			\
-	-I$(top_srcdir)/libdb/dist			\
+	$(DB_CFLAGS)					\
         $(EVOLUTION_ADDRESSBOOK_CFLAGS)
 
 extension_LTLIBRARIES = libebookbackendfile.la
@@ -18,7 +18,7 @@ libebookbackendfile_la_LIBADD =						\
 	$(top_builddir)/addressbook/libebook/libebook-1.2.la		\
 	$(top_builddir)/addressbook/libedata-book/libedata-book-1.2.la	\
 	$(top_builddir)/libedataserver/libedataserver-1.2.la		\
-	$(top_builddir)/libdb/dist/libdb-4.1.la				\
+	$(DB_LIBS)				\
 	$(EVOLUTION_ADDRESSBOOK_LIBS)
 
 libebookbackendfile_la_LDFLAGS =	\
Index: libedataserver/Makefile.am
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserver/Makefile.am,v
retrieving revision 1.28
diff -u -p -r1.28 Makefile.am
--- libedataserver/Makefile.am	10 Jan 2006 07:59:04 -0000	1.28
+++ libedataserver/Makefile.am	30 Jan 2006 09:07:20 -0000
@@ -1,7 +1,7 @@
 INCLUDES =								\
 	-I$(top_srcdir)							\
 	-DG_LOG_DOMAIN=\"e-data-server\"				\
-	-I$(top_srcdir)/libdb/dist					\
+	$(DB_CFLAGS)							\
 	-DE_DATA_SERVER_PREFIX=\"$(prefix)\"				\
 	-DEVOLUTION_LOCALEDIR=\""$(localedir)"\"			\
 	-DE_DATA_SERVER_EXTENSIONDIR=\"$(extensiondir)\"		\
@@ -49,7 +49,7 @@ libedataserver_1_2_la_SOURCES =		\
 libedataserver_1_2_la_LIBADD = 				\
 	$(E_DATA_SERVER_LIBS)				\
 	$(ICONV_LIBS)					\
-	$(top_builddir)/libdb/dist/libdb-4.1.la		\
+	$(DB_LIBS)					\
 	$(SOCKET_LIBS)
 
 libedataserver_1_2_la_LDFLAGS = \
