chiark / gitweb /
doc: Document summary values of TOFU_STATS
[gnupg2.git] / m4 / ldap.m4
1 dnl Check for LDAP
2 dnl Copyright (C) 2005 Free Software Foundation, Inc.
3 dnl
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.
9 dnl
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.
12
13 AC_DEFUN([GNUPG_CHECK_LDAP],
14 [
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"
20 gnupg_have_ldap=no
21 AC_ARG_WITH(ldap,
22   AC_HELP_STRING([--with-ldap=DIR],[look for the LDAP library in DIR]),
23   [_ldap_with=$withval])
24
25 if test x$_ldap_with != xno ; then
26
27   if test -d "$withval" ; then
28      LDAP_CPPFLAGS="-I$withval/include"
29      LDAP_LDFLAGS="-L$withval/lib"
30   fi
31
32   _ldap_save_cppflags=$CPPFLAGS
33   CPPFLAGS="${LDAP_CPPFLAGS} ${CPPFLAGS}"
34   _ldap_save_ldflags=$LDFLAGS
35   LDFLAGS="${LDAP_LDFLAGS} ${LDFLAGS}"
36
37   for MY_LDAPLIBS in ${LDAPLIBS+"$LDAPLIBS"} "-lldap" "-lldap -llber" "-lldap -llber -lresolv" "-lwldap32"; do
38     _ldap_save_libs=$LIBS
39     LIBS="$MY_LDAPLIBS $1 $LIBS"
40
41     AC_MSG_CHECKING([whether LDAP via \"$MY_LDAPLIBS\" is present and sane])
42     AC_TRY_LINK([
43 #ifdef _WIN32
44 #include <winsock2.h>
45 #include <winldap.h>
46 #else
47 #include <ldap.h>
48 #endif
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])
52
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])
59     fi
60
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])
63     fi
64
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"
69        gnupg_have_ldap=yes
70
71        AC_CHECK_FUNCS(ldap_get_option ldap_set_option)
72        # The extra test for ldap_start_tls_sA is for W32 because 
73        # that is the actual function in the library.
74        AC_CHECK_FUNCS(ldap_start_tls_s ldap_start_tls_sA)
75
76        if test "$ac_cv_func_ldap_get_option" != yes ; then
77           AC_MSG_CHECKING([whether LDAP supports ld_errno])
78           AC_TRY_LINK([#include <ldap.h>],[LDAP *ldap; ldap->ld_errno;],
79              [gnupg_cv_func_ldap_ld_errno=yes],
80              [gnupg_cv_func_ldap_ld_errno=no])
81           AC_MSG_RESULT([$gnupg_cv_func_ldap_ld_errno])
82
83           if test "$gnupg_cv_func_ldap_ld_errno" = yes ; then
84              AC_DEFINE(HAVE_LDAP_LD_ERRNO,1,[Define if the LDAP library supports ld_errno])
85           fi
86        fi
87     fi
88
89     LIBS=$_ldap_save_libs
90
91     if test "$GPGKEYS_LDAP" != "" ; then break; fi
92   done
93
94   AC_SUBST(GPGKEYS_LDAP)
95   AC_SUBST(LDAPLIBS)
96   AC_SUBST(LDAP_CPPFLAGS)
97
98   CPPFLAGS=$_ldap_save_cppflags
99   LDFLAGS=$_ldap_save_ldflags
100 fi
101 ])dnl