---
 * make openldap support optional and auto-detected

 configure.in |   65 +++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 43 insertions(+), 22 deletions(-)

Index: b/configure.in
===================================================================
--- a/configure.in
+++ b/configure.in
@@ -207,36 +207,57 @@ AC_CHECK_HEADERS(syslog.h sys/wait.h)
 
 AC_CHECK_FUNCS(getuid sigaction fsync fchmod fdwalk)
 
+dnl **************************************************
+dnl LDAP support.
+dnl **************************************************
+
+AC_ARG_WITH(openldap,
+  AS_HELP_STRING([--with-openldap],
+    [Enable LDAP backend @<:@default=auto@:>@]),
+  ,with_openldap=auto)
 
 LDAP_LIBS=
-AC_CHECK_HEADER(ldap.h, [
+
+if test "x$with_openldap" != "xno"; then
+  AC_CHECK_HEADER(ldap.h, [
     AC_CHECK_LIB(ldap, ldap_init, AC_CHECK_LIB(lber, ber_free, [LDAP_LIBS="-lldap -llber"]))
   ])
-AC_SUBST(LDAP_LIBS)
-AM_CONDITIONAL(LDAP_SUPPORT, test -n "$LDAP_LIBS")
 
-dnl **************************************************
-dnl LDAP support.
-dnl **************************************************
-if test "$os_win32" != yes; then
+  if test "x$os_win32" != "xyes"; then
+    SAVE_CFLAGS="$CFLAGS"
+    SAVE_LIBS="$LIBS"
+    LDAP_CFLAGS="-DLDAP_DEPRECATED"
+    CFLAGS="$CFLAGS $LDAP_CFLAGS"
+    LIBS="$LIBS $LDAP_LIBS"
+    AC_CHECK_FUNCS(ldap_ntlm_bind)
+    CFLAGS="$SAVE_CFLAGS"
+    LIBS="$SAVE_LIBS"
+
+  else # Win32
+    LDAP_CFLAGS="-DLDAP_DEPRECATED"
+    LDAP_LIBS="-lwldap32"
+    AC_SUBST(LDAP_CFLAGS)
+    AC_SUBST(LDAP_LIBS)
+    AC_DEFINE(HAVE_LDAP,1,[Define if you have LDAP support])
+    msg_ldap="yes"
+
+  fi # Win32
+
+  if test -z "$LDAP_LIBS"; then
+    if test "x$with_openldap" = "xyes"; then
+      AC_MSG_ERROR([*** LDAP support explicitely requested but not found ***])
+    else
+      AC_MSG_WARN([*** LDAP support not found ***])
+    fi
+  fi
 
-SAVE_CFLAGS="$CFLAGS"
-SAVE_LIBS="$LIBS"
-LDAP_CFLAGS="-DLDAP_DEPRECATED"
-CFLAGS="$CFLAGS $LDAP_CFLAGS"
-LIBS="$LIBS $LDAP_LIBS"
-AC_CHECK_FUNCS(ldap_ntlm_bind)
-CFLAGS="$SAVE_CFLAGS"
-LIBS="$SAVE_LIBS"
-
-else # Win32
-LDAP_CFLAGS="-DLDAP_DEPRECATED"
-LDAP_LIBS="-lwldap32"
+  have_ldap=yes
+else
+  have_ldap=no
+fi
 AC_SUBST(LDAP_CFLAGS)
 AC_SUBST(LDAP_LIBS)
-AC_DEFINE(HAVE_LDAP,1,[Define if you have LDAP support])
-msg_ldap="yes"
-fi # Win32
+AM_CONDITIONAL(LDAP_SUPPORT, [test -n "$LDAP_LIBS"])
 
 IT_PROG_INTLTOOL([0.35.0])
 
