bd85534ed8a9b4520ff00e628419501628be0dea
[platform/upstream/evolution-data-server.git] / m4 / evo_sunldap_check.m4
1 dnl EVO_SUNLDAP_CHECK
2 dnl Add --with-sunldap and --with-static-sunldap options. --with-sunldap
3 dnl defaults to the given value if not specified. If LDAP support is
4 dnl configured, HAVE_LDAP will be defined and the automake conditional
5 dnl ENABLE_LDAP will be set. LDAP_CFLAGS and LDAP_LIBS will be set
6 dnl appropriately, and --with-sunldap and --with-openldap is mutually exclusive.
7 #serial 0.1
8 AC_DEFUN([EVO_SUNLDAP_CHECK], [
9         default="$1"
10
11         AC_ARG_WITH([sunldap],
12                 [AS_HELP_STRING([--with-sunldap],
13                 [Enable SunLDAP support in evolution])])
14         AC_ARG_WITH([static-sunldap],
15                 [AS_HELP_STRING([--with-static-sunldap],
16                 [Link SunLDAP support statically into evolution])])
17         AC_CACHE_CHECK([for SunLDAP],[ac_cv_with_sunldap],[ac_cv_with_sunldap="${with_sunldap:=$default}"])
18         case $ac_cv_with_sunldap in
19         no|"")
20                 with_sunldap=no
21                 ;;
22         yes)
23                 with_sunldap=/usr
24                 ;;
25         *)
26                 with_sunldap=$ac_cv_with_sunldap
27                 LDAP_CFLAGS="-I$ac_cv_with_sunldap/include"
28                 LDAP_LDFLAGS="-L$ac_cv_with_sunldap/lib"
29                 ;;
30         esac
31
32         if test "$with_sunldap" != no; then
33                 AC_DEFINE(HAVE_LDAP,1,[Define if you have LDAP support])
34                 AC_DEFINE(SUNLDAP, 1, [Define if you use SunLDAP])
35
36                 case $with_static_sunldap in
37                 no|"")
38                         with_static_sunldap=no
39                         ;;
40                 *)
41                         with_static_sunldap=yes
42                         ;;
43                 esac
44
45                 AC_CACHE_CHECK([if SunLDAP is version 2.x], [ac_cv_sunldap_version2], [
46                         CPPFLAGS_save="$CPPFLAGS"
47                         CPPFLAGS="$CPPFLAGS $LDAP_CFLAGS"
48                         AC_EGREP_CPP(yes, [
49                                 #include "ldap.h"
50                                 #if LDAP_VENDOR_VERSION >= 500
51                                 yes
52                                 #endif
53                         ],[ac_cv_sunldap_version2=yes],[ac_cv_sunldap_version2=no])
54                         CPPFLAGS="$CPPFLAGS_save"
55                 ])
56                 if test "$ac_cv_sunldap_version2" = no; then
57                        AC_MSG_ERROR([evolution requires SunLDAP version >= 2])
58                 fi
59
60                 AC_CHECK_LIB(resolv, res_query, [LDAP_LIBS="-lresolv"])
61                 AC_CHECK_LIB(socket, bind, [LDAP_LIBS="$LDAP_LIBS -lsocket"])
62                 AC_CHECK_LIB(nsl, gethostbyaddr, [LDAP_LIBS="$LDAP_LIBS -lnsl"])
63                 AC_CHECK_LIB(ldap, ldap_open, [
64                         if test $with_static_sunldap = "yes"; then
65                                 LDAP_LIBS="$with_sunldap/lib/libldap.a $LDAP_LIBS"
66                         else
67                                 LDAP_LIBS="-lldap $LDAP_LIBS"
68                         fi
69                         if test `uname -s` != "SunOS" ; then
70                                 AC_CHECK_LIB(lber, ber_get_tag, [
71                                         if test "$with_static_sunldap" = "yes"; then
72                                                 LDAP_LIBS="$with_sunldap/lib/liblber.a $LDAP_LIBS"
73                                                 # libldap might depend on OpenSSL... We need to pull
74                                                 # in the dependency libs explicitly here since we're
75                                                 # not using libtool for the configure test.
76                                                 if test -f $with_sunldap/lib/libldap.la; then
77                                                         LDAP_LIBS="`. $with_sunldap/lib/libldap.la; echo $dependency_libs` $LDAP_LIBS"
78                                                 fi
79                                         else
80                                                 LDAP_LIBS="-llber $LDAP_LIBS"
81                                         fi], [LDAP_LIBS=""], [$LDAP_LDFLAGS $LDAP_LIBS])
82                         fi
83                         LDAP_LIBS="$LDAP_LDFLAGS $LDAP_LIBS"
84                 ], [LDAP_LIBS=""], [$LDAP_LDFLAGS $LDAP_LIBS])
85
86                 if test -z "$LDAP_LIBS"; then
87                         AC_MSG_ERROR([could not find SunLDAP libraries])
88                 fi
89
90                 AC_SUBST(LDAP_CFLAGS)
91                 AC_SUBST(LDAP_LIBS)
92         fi
93         AM_CONDITIONAL(ENABLE_LDAP, test "$with_sunldap" != "no")
94 ])