--- config_office/configure.in.orig	2006-05-19 13:37:06.000000000 +0200
+++ config_office/configure.in	2006-05-19 15:22:04.000000000 +0200
@@ -2728,14 +2728,12 @@
 	test "$with_system_db" != "no"; then
     SYSTEM_DB=YES
     AC_MSG_RESULT([external])
-    AC_CHECK_HEADER(db.h, [ DB_INCLUDES=/usr/include ],
-        [
-             CFLAGS=-I/usr/include/db4
-             AC_CHECK_HEADER(db4/db.h,
-             [ DB_INCLUDES=/usr/include/db4 ],
-             [ AC_MSG_ERROR(no. install the db4 libraries) ], []+             )
-        ], []
-    )
+    for dbver in -4.4 4.4 -4.3 4.3 -4.2 4.2 -4.1 4.1 -4 4 ''; do
+       AC_CHECK_HEADER(db$dbver/db.h, [ DB_INCLUDES="/usr/include/db$dbver"; break ])
+    done
+    if test "$DB_INCLUDES" = ""; then
+       AC_MSG_ERROR(no. install the db4-dev package)
+    fi
     AC_MSG_CHECKING([whether db is at least 4.1])
     # FIXME: Will db 4.3 work? Can't test it since the 4.3 java bindings are not packaged :/
     for v in 1 2; do
@@ -2754,11 +2752,12 @@
     else
        AC_MSG_RESULT([no. you need at least db 4.1])
     fi
-    # does not work :/
-    #AC_CHECK_LIB(db, db_create, [],
-    #  [AC_MSG_ERROR([db library not installed or functional])], [])
-    AC_HAVE_LIBRARY(db, [],
-      [AC_MSG_ERROR([db not installed or functional])], [])
+    save_LIBS="$LIBS"
+    for dbver in -4.4 4.4 -4.3 4.3 -4.2 4.2 -4.1 4.1 -4 4 ''; do
+       AC_CHECK_LIB(db$dbver, db_create, [ DB_LIB="db$dbver"; DB_CPPLIB="db_cxx$dbver"; LIBS="-ldb$dbver $LIBS"; break ])
+    done
+    AC_CHECK_FUNC(db_create, [], [ AC_MSG_ERROR([db not installed or functional]) ])
+    LIBS="$save_LIBS"
      if test "$SOLAR_JAVA" = "TRUE"; then
        if test -z "$DB_JAR"; then
          # three different naming methods *grumble* Are there even more?
@@ -2967,6 +2966,8 @@
 fi
 AC_SUBST(SYSTEM_DB)
 AC_SUBST(DB_VERSION)
+AC_SUBST(DB_LIB)
+AC_SUBST(DB_CPPLIB)
 AC_SUBST(DB_INCLUDES)
 AC_SUBST(DB_JAR)
 
--- config_office/set_soenv.in.orig	2006-05-19 12:01:50.000000000 +0200
+++ config_office/set_soenv.in	2006-05-19 14:55:45.000000000 +0200
@@ -1767,6 +1767,8 @@
 ToFile( "SYSTEM_EXPAT",      "@SYSTEM_EXPAT@",     "e" );
 ToFile( "SYSTEM_DB",         "@SYSTEM_DB@",        "e" );
 ToFile( "DB_VERSION",        "@DB_VERSION@",       "e" );
+ToFile( "DB_LIB",            "@DB_LIB@",           "e" );
+ToFile( "DB_CPPLIB",         "@DB_CPPLIB@",        "e" );
 ToFile( "DB_INCLUDES",       "@DB_INCLUDES@",      "e" );
 ToFile( "DB_JAR",            "@DB_JAR@",           "e" );
 ToFile( "SYSTEM_HSQLDB",     "@SYSTEM_HSQLDB@",    "e" );
--- solenv/inc/libs.mk.orig	2006-05-19 14:54:48.000000000 +0200
+++ solenv/inc/libs.mk	2006-05-19 14:55:33.000000000 +0200
@@ -201,8 +201,8 @@
 .ENDIF
 NEON3RDLIB=-lneon
 .IF "$(SYSTEM_DB)" == "YES"
-BERKELEYLIB=-ldb
-BERKELEYCPPLIB=-ldb_cxx
+BERKELEYLIB=-l$(DB_LIB)
+BERKELEYCPPLIB=-l$(DB_CPPLIB)
 .ELSE
 BERKELEYLIB=-ldb-4.2
 BERKELEYCPPLIB=-ldb_cxx-4.2
