Index: configure.in
===================================================================
--- configure.in	(revision 254)
+++ configure.in	(working copy)
@@ -178,6 +178,23 @@
 				      [AC_MSG_ERROR([No regex library found])])])
 AC_SUBST(REGEX_LIBS)
 
+dnl **************************************************
+dnl * libdb checking
+dnl **************************************************
+
+AC_ARG_WITH(libdb41, [  --with-libdb41         Prefix where libdb 4.1 is installed], dynamic_libdb=yes, dynamic_libdb=no)
+if test "x${dynamic_libdb}" = "xyes"; then
+        DB_CFLAGS="-I$withval/include/db4"
+        DB_LIBS="-L$withval/lib -ldb-4.1"
+else
+        DB_CFLAGS="-I\$(top_srcdir)/libdb/dist"
+        DB_LIBS="\$(top_builddir)/libdb/dist/libdb-4.1.la"
+fi
+AM_CONDITIONAL(WITH_LIBDB, test "x$dynamic_libdb" != "xno")
+AC_SUBST(DB_CFLAGS)
+AC_SUBST(DB_LIBS)
+# TODO: print status 
+
 dnl ******************************
 dnl iconv checking
 dnl ******************************
@@ -1316,7 +1333,9 @@
 export privincludedir
 export privdatadir
 AC_CONFIG_SUBDIRS(calendar/libical)
-AC_CONFIG_SUBDIRS(libdb/dist)
+if test "x${dynamic_libdb}" != "xyes"; then
+        AC_CONFIG_SUBDIRS(libdb/dist)
+fi
 
 AC_OUTPUT([
 Makefile
@@ -1439,3 +1458,4 @@
 patch in servers/exchange/docs/openldap-ntlm.diff
 ])
 fi
+# TODO:print libdb status
\ No newline at end of file
Index: Makefile.am
===================================================================
--- Makefile.am	(revision 253)
+++ Makefile.am	(working copy)
@@ -1,6 +1,11 @@
 AUTOMAKE_OPTIONS = 1.6
 DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
 
+if ! WITH_LIBDB
+LIBDB = libdb
+endif
+
+
 if ENABLE_CAMEL
 CAMEL_DIR = camel
 else
@@ -8,9 +13,9 @@
 endif
 
 if ENABLE_DBUS
-SUBDIRS = libdb libedataserver $(CAMEL_DIR) addressbook calendar libedataserverui docs art po
+SUBDIRS = $(LIBDB) libedataserver $(CAMEL_DIR) addressbook calendar libedataserverui docs art po
 else
-SUBDIRS = libdb libedataserver servers $(CAMEL_DIR) addressbook calendar libedataserverui src docs art po
+SUBDIRS = $(LIBDB) libedataserver servers $(CAMEL_DIR) addressbook calendar libedataserverui src docs art po
 endif
 
 DIST_SUBDIRS= libedataserver servers camel ucamel addressbook calendar libedataserverui src docs art po
Index: addressbook/backends/file/Makefile.am
===================================================================
--- addressbook/backends/file/Makefile.am	(revision 227)
+++ addressbook/backends/file/Makefile.am	(working copy)
@@ -4,7 +4,7 @@
 	-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 @@
 	$(top_builddir)/addressbook/libebook-dbus/libebook-$(API_VERSION).la		\
 	$(top_builddir)/addressbook/libedata-book-dbus/libedata-book-$(API_VERSION).la	\
 	$(top_builddir)/libedataserver/libedataserver-$(API_VERSION).la		\
-	$(top_builddir)/libdb/dist/libdb-4.1.la				\
+	$(DB_LIBS)				\
 	$(EVOLUTION_ADDRESSBOOK_LIBS)
 
 libebookbackendfile_la_LDFLAGS =	\
Index: libedataserver/Makefile.am
===================================================================
--- libedataserver/Makefile.am	(revision 227)
+++ libedataserver/Makefile.am	(working copy)
@@ -1,7 +1,7 @@
 INCLUDES =								\
 	-I$(top_srcdir)							\
 	-DG_LOG_DOMAIN=\"e-data-server\"				\
-	-I$(top_srcdir)/libdb/dist					\
+	$(DB_CFLAGS)							\
 	-DE_DATA_SERVER_EXTENSIONDIR=\"$(extensiondir)\"		\
 	-DE_DATA_SERVER_IMAGESDIR=\"$(imagesdir)\"			\
 	$(E_DATA_SERVER_CFLAGS)
@@ -48,7 +48,7 @@
 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 = \
