-#if test "$PTHREADLIB" != "-lpthread"; then
-# AC_MSG_ERROR(failed: I need posix threads, pthread)
-#fi
-
-dnl Converts the ARCH to be the same as dpkg
+dnl if test "$PTHREADLIB" != "-lpthread"; then
+dnl AC_MSG_ERROR(failed: I need posix threads, pthread)
+dnl fi
+
+dnl Check for BDB
+saveLIBS="$LIBS"
+LIBS="$LIBS -ldb"
+
+AC_CHECK_HEADER(db.h,
+ [AC_MSG_CHECKING(if we can link against BerkeleyDB)
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [#include <db.h>],
+ [int r, s, t; db_version(&r, &s, &t);]
+ )],
+ [AC_DEFINE(HAVE_BDB)
+ BDBLIB="-ldb"
+ AC_MSG_RESULT(yes)],
+ [BDBLIB=""
+ AC_MSG_RESULT(no)]
+ )]
+)
+
+LIBS="$saveLIBS"
+
+AC_SUBST(BDBLIB)
+
+dnl Converts the ARCH to be something singular for this general CPU family
+dnl This is often the dpkg architecture string.
+dnl First check against the full canonical canoncial-system-type in $target
+dnl and if that fails, just look for the cpu