diff --git a/cmulocal/berkdb.m4 b/cmulocal/berkdb.m4
index dbcdbc8..99a39ee 100644
--- a/cmulocal/berkdb.m4
+++ b/cmulocal/berkdb.m4
@@ -213,7 +213,7 @@ AC_DEFUN([CYRUS_BERKELEY_DB_CHK_LIB],
 	fi
 
 	saved_LIBS=$LIBS
-        for dbname in ${with_bdb} db-4.6 db4.6 db46 db-4.5 db4.5 db45 db-4.4 db4.4 db44 db-4.3 db4.3 db43 db-4.2 db4.2 db42 db-4.1 db4.1 db41 db-4.0 db4.0 db-4 db40 db4 db-3.3 db3.3 db33 db-3.2 db3.2 db32 db-3.1 db3.1 db31 db-3 db30 db3 db
+        for dbname in ${with_bdb} db-4.8 db4.8 db48 db-4.7 db4.7 db47 db-4.6 db4.6 db46 db-4.5 db4.5 db45 db-4.4 db4.4 db44 db-4.3 db4.3 db43 db-4.2 db4.2 db42 db-4.1 db4.1 db41 db-4.0 db4.0 db-4 db40 db4 db-3.3 db3.3 db33 db-3.2 db3.2 db32 db-3.1 db3.1 db31 db-3 db30 db3 db
           do
 	    LIBS="$saved_LIBS -l$dbname"
 	    AC_TRY_LINK([#include <stdio.h>
diff --git a/config/plain.m4 b/config/plain.m4
index ee9e0c4..3fb5ebb 100644
--- a/config/plain.m4
+++ b/config/plain.m4
@@ -21,7 +21,7 @@ dnl PLAIN
  if test "$plain" != no; then
   AC_MSG_RESULT(enabled)
   SASL_MECHS="$SASL_MECHS libplain.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS plain.o"
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/plain.c"
     AC_DEFINE(STATIC_PLAIN,[],[Link PLAIN Staticly])
diff --git a/config/sasldb.m4 b/config/sasldb.m4
index b28b087..13cca34 100644
--- a/config/sasldb.m4
+++ b/config/sasldb.m4
@@ -127,7 +127,7 @@ case "$dblib" in
     ;;
 esac
 
-if test "$enable_static" = yes; then
+if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     if test "$dblib" != "none"; then
       SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/sasldb.c $SASL_DB_BACKEND_STATIC_SRCS"
       SASL_STATIC_OBJS="$SASL_STATIC_OBJS sasldb.o $SASL_DB_BACKEND_STATIC"
diff --git a/configure.in b/configure.in
index 47138d9..f7f1a23 100644
--- a/configure.in
+++ b/configure.in
@@ -113,12 +113,19 @@ else
 	SASL_STATIC_LIBS=
 fi
 
+AC_ARG_ENABLE(staticplugin, [  --enable-staticplugin   link plugins statically [[no]] ],
+                enable_staticplugin=$enableval,
+                enable_staticplugin=no)
+if test "$enable_staticplugin" = yes; then
+  AC_DEFINE(STATIC_PLUGIN,[],[link plugins statically])
+fi
+
 AC_ARG_ENABLE(staticdlopen, [  --enable-staticdlopen   try dynamic plugins when we are a static libsasl [[no]] ],
                 enable_staticdlopen=$enableval,
                 enable_staticdlopen=no)
 
 if test "$enable_staticdlopen" = yes; then
-  AC_DEFINE(TRY_DLOPEN_WHEN_STATIC,[],[Should we try to dlopen() plugins while staticly compiled?])
+  AC_DEFINE(TRY_DLOPEN_WHEN_STATIC,[],[Should we try to dlopen() plugins while statically compiled?])
 fi
 
 if test "$ac_cv_prog_gcc" = yes; then
@@ -382,10 +389,10 @@ AC_MSG_CHECKING(CRAM-MD5)
 if test "$cram" != no; then
   AC_MSG_RESULT(enabled)
   SASL_MECHS="$SASL_MECHS libcrammd5.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS cram.o"
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/cram.c"
-    AC_DEFINE(STATIC_CRAMMD5, [], [Link CRAM-MD5 Staticly])
+    AC_DEFINE(STATIC_CRAMMD5, [], [Link CRAM-MD5 Statically])
   fi
 else
   AC_MSG_RESULT(disabled)
@@ -417,10 +424,10 @@ AC_MSG_CHECKING(DIGEST-MD5)
 if test "$digest" != no; then
   AC_MSG_RESULT(enabled)
   SASL_MECHS="$SASL_MECHS libdigestmd5.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/digestmd5.c"
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS digestmd5.o"
-    AC_DEFINE(STATIC_DIGESTMD5, [], [Link DIGEST-MD5 Staticly])
+    AC_DEFINE(STATIC_DIGESTMD5, [], [Link DIGEST-MD5 Statically])
   fi
 else
   AC_MSG_RESULT(disabled)
@@ -442,10 +449,10 @@ if test "$otp" != no; then
   OTP_LIBS="-lcrypto $LIB_RSAREF"
 
   SASL_MECHS="$SASL_MECHS libotp.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/otp.c"
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS otp.o"
-    AC_DEFINE(STATIC_OTP, [], [Link OTP Staticly])
+    AC_DEFINE(STATIC_OTP, [], [Link OTP Statically])
   fi
 
   dnl Test for OPIE
@@ -499,10 +506,10 @@ if test "$srp" != no; then
   SRP_LIBS="-lcrypto $LIB_RSAREF"
 
   SASL_MECHS="$SASL_MECHS libsrp.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/srp.c"
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS srp.o"
-    AC_DEFINE(STATIC_SRP, [], [Link SRP Staticly])
+    AC_DEFINE(STATIC_SRP, [], [Link SRP Statically])
   fi
 
 dnl srp_setpass support
@@ -528,7 +535,7 @@ SASL_KERBEROS_V4_CHK
 SASL_GSSAPI_CHK
 
 if test "$gssapi" != "no"; then
-  AC_DEFINE(STATIC_GSSAPIV2,[],[Link GSSAPI Staticly])
+  AC_DEFINE(STATIC_GSSAPIV2,[],[Link GSSAPI Statically])
   mutex_default="no"
   if test "$gss_impl" = "mit"; then
      mutex_default="yes"
@@ -555,10 +562,10 @@ AC_MSG_CHECKING(ANONYMOUS)
 if test "$anon" != no; then
   AC_MSG_RESULT(enabled)
   SASL_MECHS="$SASL_MECHS libanonymous.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS anonymous.o"
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/anonymous.c"
-    AC_DEFINE(STATIC_ANONYMOUS, [], [Link ANONYMOUS Staticly])
+    AC_DEFINE(STATIC_ANONYMOUS, [], [Link ANONYMOUS Statically])
   fi
 else
   AC_MSG_RESULT(disabled)
@@ -573,10 +580,10 @@ AC_MSG_CHECKING(LOGIN)
 if test "$login" != no; then
   AC_MSG_RESULT(enabled)
   SASL_MECHS="$SASL_MECHS liblogin.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/login.c"
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS login.o"
-    AC_DEFINE(STATIC_LOGIN,[],[Link LOGIN Staticly])
+    AC_DEFINE(STATIC_LOGIN,[],[Link LOGIN Statically])
   fi
 else
   AC_MSG_RESULT(disabled)
@@ -599,10 +606,10 @@ if test "$ntlm" != no; then
   AC_SUBST(NTLM_LIBS)
 
   SASL_MECHS="$SASL_MECHS libntlm.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/ntlm.c"
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS ntlm.o"
-    AC_DEFINE(STATIC_NTLM,[],[Link NTLM Staticly])
+    AC_DEFINE(STATIC_NTLM,[],[Link NTLM Statically])
   fi
 else
   AC_MSG_RESULT(disabled)
@@ -625,10 +632,10 @@ if test "$passdss" != no; then
   AC_SUBST(PASSDSS_LIBS)
 
   SASL_MECHS="$SASL_MECHS libpassdss.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS passdss.o"
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/passdss.c"
-    AC_DEFINE(STATIC_PASSDSS,[],[Link PASSDSS Staticly])
+    AC_DEFINE(STATIC_PASSDSS,[],[Link PASSDSS Statically])
   fi
 else
   AC_MSG_RESULT(disabled)
@@ -656,10 +663,10 @@ AC_MSG_CHECKING(SQL)
 if test "$sql" != no; then
   AC_MSG_RESULT(enabled)
   SASL_MECHS="$SASL_MECHS libsql.la"
-  if test "$enable_static" = yes; then
+  if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
     SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/sql.c"
     SASL_STATIC_OBJS="$SASL_STATIC_OBJS sql.o"
-    AC_DEFINE(STATIC_SQL,[],[Link SQL plugin staticly])
+    AC_DEFINE(STATIC_SQL,[],[Link SQL plugin statically])
   fi
 else
   AC_MSG_RESULT(disabled)
@@ -902,7 +909,7 @@ if test "$sql" = yes -a "$with_pgsql" = no -a "$with_mysql" = no -a "$with_sqlit
     AC_ERROR([--enable-sql chosen but neither Postgres nor MySQL nor SQLite nor SQLite3 found])
 fi
 
-if test "$enable_shared" = yes; then
+if test "$enable_shared" = yes -a "$enable_staticplugin" != yes; then
 	AC_DEFINE(DO_DLOPEN,[],[Should we build a shared plugin (via dlopen) library?])
 fi
 
@@ -948,10 +955,10 @@ if test "$ldapdb" != no; then
             AC_SUBST(LIB_LDAP)
 
             SASL_MECHS="$SASL_MECHS libldapdb.la"
-            if test "$enable_static" = yes; then
+            if test "$enable_static" = yes -o "$enable_staticplugin" = yes; then
                 SASL_STATIC_SRCS="$SASL_STATIC_SRCS \$(top_srcdir)/plugins/ldapdb.c"
                 SASL_STATIC_OBJS="$SASL_STATIC_OBJS ldapdb.o"
-                AC_DEFINE(STATIC_LDAPDB,[],[Link ldapdb plugin Staticly])
+                AC_DEFINE(STATIC_LDAPDB,[],[Link ldapdb plugin Statically])
             fi
         fi
     fi
@@ -969,6 +976,13 @@ AC_SUBST(SASL_STATIC_SRCS)
 AC_SUBST(SASL_STATIC_OBJS)
 AC_SUBST(SASL_STATIC_LIBS)
 
+SASL_STATIC_PLUGIN_SRCS="$SASL_STATIC_SRCS"
+SASL_STATIC_PLUGIN_OBJS="$SASL_STATIC_OBJS"
+SASL_STATIC_PLUGIN_LTOBJS=`echo "$SASL_STATIC_PLUGIN_@&t@OBJS" | sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
+AC_SUBST(SASL_STATIC_PLUGIN_SRCS)
+AC_SUBST(SASL_STATIC_PLUGIN_OBJS)
+AC_SUBST(SASL_STATIC_PLUGIN_LTOBJS)
+
 AC_ARG_WITH(plugindir, [  --with-plugindir=DIR    set the directory where plugins will
                           be found [[/usr/lib/sasl2]] ],
   plugindir=$withval,
diff --git a/lib/Makefile.am b/lib/Makefile.am
index b73e45c..d6eebcd 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -55,8 +55,8 @@ BUILT_SOURCES = $(SASL_STATIC_SRCS)
 common_headers = saslint.h
 common_sources = auxprop.c canonusr.c checkpw.c client.c common.c config.c external.c md5.c saslutil.c server.c seterror.c dlopen.c ../plugins/plugin_common.c
 
-LTLIBOBJS = @LTLIBOBJS@
-LIBOBJS = @LIBOBJS@
+LTLIBOBJS = @LTLIBOBJS@ @SASL_STATIC_PLUGIN_LTOBJS@
+LIBOBJS = @LIBOBJS@ @SASL_STATIC_PLUGIN_OBJS@
 LIB_DOOR= @LIB_DOOR@
 
 lib_LTLIBRARIES = libsasl2.la
diff --git a/lib/dlopen.c b/lib/dlopen.c
index b9c1c80..75b5923 100644
--- a/lib/dlopen.c
+++ b/lib/dlopen.c
@@ -56,7 +56,7 @@
 #include <sasl.h>
 #include "saslint.h"
 
-#ifndef PIC
+#if !defined(PIC) || defined(STATIC_PLUGIN)
 #include <saslplug.h>
 #include "staticopen.h"
 #endif
@@ -407,7 +407,7 @@ int _sasl_load_plugins(const add_plugin_list_t *entrypoints,
     DIR *dp;
     struct dirent *dir;
 #endif
-#ifndef PIC
+#if !defined(PIC) || defined(STATIC_PLUGIN)
     add_plugin_t *add_plugin;
     _sasl_plug_type type;
     _sasl_plug_rec *p;
@@ -422,7 +422,7 @@ int _sasl_load_plugins(const add_plugin_list_t *entrypoints,
 	|| ! verifyfile_cb->proc)
 	return SASL_BADPARAM;
 
-#ifndef PIC
+#if !defined(PIC) || defined(STATIC_PLUGIN)
     /* do all the static plugins first */
 
     for(cur_ep = entrypoints; cur_ep->entryname; cur_ep++) {
@@ -449,7 +449,7 @@ int _sasl_load_plugins(const add_plugin_list_t *entrypoints,
 	    	result = add_plugin(p->name, p->plug);
 	}
     }
-#endif /* !PIC */
+#endif /* !PIC || STATIC_PLUGIN */
 
 /* only do the following if:
  * 
diff --git a/sample/Makefile.am b/sample/Makefile.am
index 0e18483..d39e764 100644
--- a/sample/Makefile.am
+++ b/sample/Makefile.am
@@ -44,8 +44,8 @@
 
 INCLUDES=-I$(top_srcdir)/include
 
-noinst_PROGRAMS = client server
-EXTRA_PROGRAMS = sample-client sample-server
+noinst_PROGRAMS = client server sample-client sample-server
+EXTRA_PROGRAMS =
 CLEANFILES=sample-client sample-server ./.libs/*sample-client ./.libs/*sample-server
 
 sample_client_SOURCES = sample-client.c
@@ -54,10 +54,10 @@ sample_server_SOURCES = sample-server.c
 server_SOURCES = server.c common.c common.h
 client_SOURCES = client.c common.c common.h
 
-server_LDADD = ../lib/libsasl2.la $(LIB_SOCKET)
-client_LDADD = ../lib/libsasl2.la $(LIB_SOCKET)
+server_LDADD = ../lib/libsasl2.la $(LIB_SOCKET) $(LIB_DES) $(SASL_DB_LIB)
+client_LDADD = ../lib/libsasl2.la $(LIB_SOCKET) $(LIB_DES) $(SASL_DB_LIB)
 
-sample_client_LDADD = ../lib/libsasl2.la $(LIB_SOCKET)
-sample_server_LDADD = ../lib/libsasl2.la $(LIB_SOCKET)
+sample_client_LDADD = ../lib/libsasl2.la $(LIB_SOCKET) $(LIB_DES) $(SASL_DB_LIB)
+sample_server_LDADD = ../lib/libsasl2.la $(LIB_SOCKET) $(LIB_DES) $(SASL_DB_LIB)
 
 EXTRA_DIST = NTMakefile
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 7e2f983..f15d0a9 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -42,7 +42,7 @@
 #
 ################################################################
 
-all_sasl_libs = ../lib/libsasl2.la $(SASL_DB_LIB) $(LIB_SOCKET)
+all_sasl_libs = ../lib/libsasl2.la $(SASL_DB_LIB) $(LIB_SOCKET) $(LIB_DES)
 all_sasl_static_libs = ../lib/.libs/libsasl2.a $(SASL_DB_LIB) $(LIB_SOCKET) $(GSSAPIBASE_LIBS) $(GSSAPI_LIBS) $(SASL_KRB_LIB) $(LIB_DES) $(PLAIN_LIBS) $(SRP_LIBS) $(LIB_MYSQL) $(LIB_PGSQL) $(LIB_SQLITE)
 
 sbin_PROGRAMS = @SASL_DB_UTILS@ @SMTPTEST_PROGRAM@ pluginviewer