2 dnl Copyright (C) 2005 Free Software Foundation, Inc.
4 dnl This file is free software, distributed under the terms of the GNU
5 dnl General Public License. As a special exception to the GNU General
6 dnl Public License, this file may be distributed as part of a program
7 dnl that contains a configuration script generated by Autoconf, under
8 dnl the same distribution terms as the rest of that program.
10 dnl Defines @GPGKEYS_LDAP@ to a executable name if a working ldap
11 dnl setup is found, and sets @LDAPLIBS@ to the necessary libraries.
13 AC_DEFUN([GNUPG_CHECK_LDAP],
15 # Try and link a LDAP test program to weed out unusable LDAP
16 # libraries. -lldap [-llber [-lresolv]] is for older OpenLDAPs.
17 # OpenLDAP, circa 1999, was terrible with creating weird dependencies.
18 # If all else fails, the user can play guess-the-dependency by using
19 # something like ./configure LDAPLIBS="-Lfoo -lbar"
22 AC_HELP_STRING([--with-ldap=DIR],[look for the LDAP library in DIR]),
23 [_ldap_with=$withval])
25 if test x$_ldap_with != xno ; then
27 if test -d "$withval" ; then
28 LDAP_CPPFLAGS="-I$withval/include"
29 LDAP_LDFLAGS="-L$withval/lib"
32 _ldap_save_cppflags=$CPPFLAGS
33 CPPFLAGS="${LDAP_CPPFLAGS} ${CPPFLAGS}"
34 _ldap_save_ldflags=$LDFLAGS
35 LDFLAGS="${LDAP_LDFLAGS} ${LDFLAGS}"
37 for MY_LDAPLIBS in ${LDAPLIBS+"$LDAPLIBS"} "-lldap" "-lldap -llber" "-lldap -llber -lresolv" "-lwldap32"; do
39 LIBS="$MY_LDAPLIBS $1 $LIBS"
41 AC_MSG_CHECKING([whether LDAP via \"$MY_LDAPLIBS\" is present and sane])
49 ],[ldap_open("foobar",1234);],
50 [gnupg_cv_func_ldap_init=yes],[gnupg_cv_func_ldap_init=no])
51 AC_MSG_RESULT([$gnupg_cv_func_ldap_init])
53 if test $gnupg_cv_func_ldap_init = no; then
54 AC_MSG_CHECKING([whether I can make LDAP be sane with lber.h])
55 AC_TRY_LINK([#include <lber.h>
56 #include <ldap.h>],[ldap_open("foobar",1234);],
57 [gnupg_cv_func_ldaplber_init=yes],[gnupg_cv_func_ldaplber_init=no])
58 AC_MSG_RESULT([$gnupg_cv_func_ldaplber_init])
61 if test "$gnupg_cv_func_ldaplber_init" = yes ; then
62 AC_DEFINE(NEED_LBER_H,1,[Define if the LDAP library requires including lber.h before ldap.h])
65 if test "$gnupg_cv_func_ldap_init" = yes || \
66 test "$gnupg_cv_func_ldaplber_init" = yes ; then
67 LDAPLIBS="$LDAP_LDFLAGS $MY_LDAPLIBS"
68 GPGKEYS_LDAP="gpg2keys_ldap$EXEEXT"
70 AC_CHECK_FUNCS(ldap_get_option ldap_set_option)
71 # The extra test for ldap_start_tls_sA is for W32 because
72 # that is the actual function in the library.
73 AC_CHECK_FUNCS(ldap_start_tls_s ldap_start_tls_sA)
75 if test "$ac_cv_func_ldap_get_option" != yes ; then
76 AC_MSG_CHECKING([whether LDAP supports ld_errno])
77 AC_TRY_LINK([#include <ldap.h>],[LDAP *ldap; ldap->ld_errno;],
78 [gnupg_cv_func_ldap_ld_errno=yes],
79 [gnupg_cv_func_ldap_ld_errno=no])
80 AC_MSG_RESULT([$gnupg_cv_func_ldap_ld_errno])
82 if test "$gnupg_cv_func_ldap_ld_errno" = yes ; then
83 AC_DEFINE(HAVE_LDAP_LD_ERRNO,1,[Define if the LDAP library supports ld_errno])
90 if test "$GPGKEYS_LDAP" != "" ; then break; fi
93 AC_SUBST(GPGKEYS_LDAP)
95 AC_SUBST(LDAP_CPPFLAGS)
97 CPPFLAGS=$_ldap_save_cppflags
98 LDFLAGS=$_ldap_save_ldflags