1# LIBLDAP_CHECK_CONFIG ([DEFAULT-ACTION]) 2# ---------------------------------------------------------- 3# Eugene Grigorjev <eugene@zabbix.com> Feb-02-2007 4# 5# Checks for ldap. DEFAULT-ACTION is the string yes or no to 6# specify whether to default to --with-ldap or --without-ldap. 7# If not supplied, DEFAULT-ACTION is no. 8# 9# This macro #defines HAVE_LDAP if a required header files is 10# found, and sets @LDAP_CPPFLAGS@, @LDAP_LDFLAGS@ and @LDAP_LIBS@ 11# to the necessary values. 12# 13# Users may override the detected values by doing something like: 14# LDAP_LIBS="-lldap" LDAP_CPPFLAGS="-I/usr/myinclude" ./configure 15# 16# This macro is distributed in the hope that it will be useful, 17# but WITHOUT ANY WARRANTY; without even the implied warranty of 18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 20AC_DEFUN([LIBLDAP_TRY_LINK], 21[ 22_save_ldap_cppflags="$CPPFLAGS" 23_save_ldap_cflags="$CFLAGS" 24_save_ldap_ldflags="$LDFLAGS" 25_save_ldap_libs="$LIBS" 26 27LIBS="$LIBS $1" 28LDFLAGS="$LDFLAGS $2" 29CPPFLAGS="$CPPFLAGS $3" 30CFLAGS="$CFLAGS $4" 31ldap_link="no" 32 33AC_TRY_LINK([ 34#include <stdio.h> 35#include <ldap.h> 36#include <lber.h> 37#include <ldap_schema.h> 38],[ 39printf("%p,%p", ldap_initialize, ldap_str2attributetype); 40printf("%p", ber_free); 41return 0; 42],[ 43ldap_link="yes" 44]) 45 46CPPFLAGS="$_save_ldap_cppflags" 47CFLAGS="$_save_ldap_cflags" 48LDFLAGS="$_save_ldap_ldflags" 49LIBS="$_save_ldap_libs" 50unset _save_ldap_cppflags 51unset _save_ldap_cflags 52unset _save_ldap_ldflags 53unset _save_ldap_libs 54]dnl 55[AS_IF([test "x$ldap_link" = "xyes"], [$5], [$6])]dnl 56)dnl 57 58 59AC_DEFUN([LIBLDAP_CHECK_CONFIG], 60[ 61 AC_ARG_WITH(ldap,[ 62If you want to check LDAP servers: 63AC_HELP_STRING([--with-ldap@<:@=DIR@:>@],[Include LDAP support @<:@default=no@:>@. DIR is the LDAP base install directory, default is to search through a number of common places for the LDAP files.])], 64 [ if test "$withval" = "no"; then 65 want_ldap="no" 66 _libldap_with="no" 67 elif test "$withval" = "yes"; then 68 want_ldap="yes" 69 _libldap_with="yes" 70 else 71 want_ldap="yes" 72 _libldap_with=$withval 73 fi 74 ],[_libldap_with=ifelse([$1],,[no],[$1])]) 75 76 if test "x$_libldap_with" != x"no"; then 77 AC_MSG_CHECKING([for LDAP support of ldap.h]) 78 79 if test "$_libldap_with" = "yes"; then 80 if test -f /usr/local/openldap/include/ldap.h; then 81 LDAP_INCDIR=/usr/local/openldap/include/ 82 LDAP_LIBDIR=/usr/local/openldap/lib/ 83 found_ldap="yes" 84 elif test -f /usr/include/ldap.h; then 85 LDAP_INCDIR=/usr/include 86 LDAP_LIBDIR=/usr/lib 87 found_ldap="yes" 88 elif test -f /usr/local/include/ldap.h; then 89 LDAP_INCDIR=/usr/local/include 90 LDAP_LIBDIR=/usr/local/lib 91 found_ldap="yes" 92 else 93 found_ldap="no" 94 AC_MSG_RESULT(no) 95 fi 96 else 97 if test -f $_libldap_with/include/ldap.h; then 98 LDAP_INCDIR=$_libldap_with/include 99 LDAP_LIBDIR=$_libldap_with/lib 100 _ldap_dir_lib="$LDAP_LIBDIR" 101 102 found_ldap="yes" 103 else 104 found_ldap="no" 105 AC_MSG_RESULT(no) 106 fi 107 fi 108 109 if test "x$found_ldap" != "xno"; then 110 111 AC_MSG_RESULT(yes) 112 LDAP_CPPFLAGS="-I$LDAP_INCDIR" 113 LDAP_LDFLAGS="-L$LDAP_LIBDIR" 114 LDAP_LIBS="-lldap -llber $LDAP_LIBS" 115 116 if test "x$enable_static" = "xyes"; then 117 LDAP_LIBS="$LDAP_LIBS -lgnutls -lpthread -lsasl2" 118 elif test "x$enable_static_libs" = "xyes"; then 119 AC_MSG_CHECKING([compatibility of static LDAP libs]) 120 test "x$static_linking_support" = "xno" -a -z "$_ldap_dir_lib" && AC_MSG_ERROR(["Compiler not support statically linked libs from default folders"]) 121 122 if test "x$static_linking_support" = "xno"; then 123 LDAP_LIBS=`echo "$LDAP_LIBS"|sed "s|-lldap|$_ldap_dir_lib/libldap.a|g"|sed "s|-llber|$_ldap_dir_lib/liblber.a|g"` 124 fi 125 126 # without SSL and SASL 127 if test "x$static_linking_support" = "xno"; then 128 TRY_LDAP_LIBS="$LDAP_LIBS -lpthread" 129 else 130 TRY_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS ${static_linking_support}dynamic -lpthread" 131 fi 132 LIBLDAP_TRY_LINK([$TRY_LDAP_LIBS], [$LDAP_LDFLAGS], [$LDAP_CPPFLAGS], ,[ 133 LDAP_LIBS=$TRY_LDAP_LIBS 134 AC_MSG_RESULT([without SSL]) 135 ]) 136 137 # without SSL 138 if test "x$ldap_link" = "xno"; then 139 if test "x$static_linking_support" = "xno"; then 140 TRY_LDAP_LIBS="$LDAP_LIBS -lpthread -lsasl2" 141 else 142 TRY_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS ${static_linking_support}dynamic -lpthread -lsasl2" 143 fi 144 LIBLDAP_TRY_LINK([$TRY_LDAP_LIBS], [$LDAP_LDFLAGS], [$LDAP_CPPFLAGS], ,[ 145 LDAP_LIBS=$TRY_LDAP_LIBS 146 AC_MSG_RESULT([without SSL]) 147 ]) 148 fi 149 150 # without SSL for Solaris 151 if test "x$ldap_link" = "xno"; then 152 if test "x$static_linking_support" = "xno"; then 153 TRY_LDAP_LIBS="$LDAP_LIBS -lpthread -lsasl" 154 else 155 TRY_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS ${static_linking_support}dynamic -lpthread -lsasl" 156 fi 157 LIBLDAP_TRY_LINK([$TRY_LDAP_LIBS], [$LDAP_LDFLAGS], [$LDAP_CPPFLAGS], ,[ 158 LDAP_LIBS=$TRY_LDAP_LIBS 159 AC_MSG_RESULT([without SSL and with sasl]) 160 ]) 161 fi 162 163 # with system GnuTLS 164 if test "x$ldap_link" = "xno"; then 165 if test "x$static_linking_support" = "xno"; then 166 TRY_LDAP_LIBS="$LDAP_LIBS -lgnutls -lsasl2 -lgssapi_krb5 -lpthread" 167 else 168 TRY_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS ${static_linking_support}dynamic -lgnutls -lsasl2 -lgssapi_krb5 -lpthread" 169 fi 170 LIBLDAP_TRY_LINK([$TRY_LDAP_LIBS], [$LDAP_LDFLAGS], [$LDAP_CPPFLAGS], ,[ 171 LDAP_LIBS=$TRY_LDAP_LIBS 172 AC_MSG_RESULT([with system GnuTLS linking]) 173 ]) 174 fi 175 176 # with static OpenSSL and SASL2 177 if test "x$ldap_link" = "xno" -a "x$want_openssl" = "xyes"; then 178 if test "x$static_linking_support" = "xno"; then 179 OSSL_LDAP_LIBS="$LDAP_LIBS $OPENSSL_LIBS -lsasl2" 180 else 181 OSSL_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS -lsasl2 ${static_linking_support}dynamic $OPENSSL_LIBS" 182 fi 183 OSSL_LDAP_CPPFLAGS="$LDAP_CPPFLAGS $OPENSSL_CPPFLAGS" 184 OSSL_LDAP_CFLAGS="$LDAP_CPPFLAGS $OPENSSL_CFLAGS" 185 OSSL_LDAP_LDFLAGS="$LDAP_LDFLAGS $OPENSSL_LDFLAGS" 186 LIBLDAP_TRY_LINK([$OSSL_LDAP_LIBS], [$OSSL_LDAP_LDFLAGS], [$OSSL_LDAP_CPPFLAGS], [$OSSL_LDAP_CFLAGS],[ 187 LDAP_LIBS="$OSSL_LDAP_LIBS" 188 AC_MSG_RESULT([with static OpenSSL and static sasl2]) 189 ]) 190 fi 191 192 # with static OpenSSL 193 if test "x$ldap_link" = "xno" -a "x$want_openssl" = "xyes"; then 194 if test "x$static_linking_support" = "xno"; then 195 OSSL_LDAP_LIBS="$LDAP_LIBS $OPENSSL_LIBS -lsasl2" 196 else 197 OSSL_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS ${static_linking_support}dynamic $OPENSSL_LIBS -lsasl2" 198 fi 199 OSSL_LDAP_CPPFLAGS="$LDAP_CPPFLAGS $OPENSSL_CPPFLAGS" 200 OSSL_LDAP_CFLAGS="$LDAP_CPPFLAGS $OPENSSL_CFLAGS" 201 OSSL_LDAP_LDFLAGS="$LDAP_LDFLAGS $OPENSSL_LDFLAGS" 202 LIBLDAP_TRY_LINK([$OSSL_LDAP_LIBS], [$OSSL_LDAP_LDFLAGS], [$OSSL_LDAP_CPPFLAGS], [$OSSL_LDAP_CFLAGS],[ 203 LDAP_LIBS="$OSSL_LDAP_LIBS" 204 AC_MSG_RESULT([with static OpenSSL]) 205 ]) 206 fi 207 208 # with static OpenSSL for Solaris 209 if test "x$ldap_link" = "xno" -a "x$want_openssl" = "xyes"; then 210 if test "x$static_linking_support" = "xno"; then 211 OSSL_LDAP_LIBS="$LDAP_LIBS $OPENSSL_LIBS -lsasl" 212 else 213 OSSL_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS ${static_linking_support}dynamic $OPENSSL_LIBS -lsasl" 214 fi 215 OSSL_LDAP_CPPFLAGS="$LDAP_CPPFLAGS $OPENSSL_CPPFLAGS" 216 OSSL_LDAP_CFLAGS="$LDAP_CPPFLAGS $OPENSSL_CFLAGS" 217 OSSL_LDAP_LDFLAGS="$LDAP_LDFLAGS $OPENSSL_LDFLAGS" 218 LIBLDAP_TRY_LINK([$OSSL_LDAP_LIBS], [$OSSL_LDAP_LDFLAGS], [$OSSL_LDAP_CPPFLAGS], [$OSSL_LDAP_CFLAGS],[ 219 LDAP_LIBS="$OSSL_LDAP_LIBS" 220 AC_MSG_RESULT([with static OpenSSL and sasl]) 221 ],[ 222 AC_MSG_ERROR([Not compatible with static OpenLDAP libs version of static OpenSSL: "$OPENSSL_LDFLAGS"]) 223 ]) 224 fi 225 226 # with system OpenSSL and SASL2 227 if test "x$ldap_link" = "xno"; then 228 if test "x$static_linking_support" = "xno"; then 229 TRY_LDAP_LIBS="$LDAP_LIBS -lssl -lsasl2 -lcrypto" 230 else 231 TRY_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS -lsasl2 ${static_linking_support}dynamic -lssl -lcrypto" 232 fi 233 LIBLDAP_TRY_LINK([$TRY_LDAP_LIBS], [$LDAP_LDFLAGS], [$LDAP_CPPFLAGS], ,[ 234 LDAP_LIBS=$TRY_LDAP_LIBS 235 AC_MSG_RESULT([with system OpenSSL and static sasl2 linking]) 236 ]) 237 fi 238 239 # with system OpenSSL 240 if test "x$ldap_link" = "xno"; then 241 if test "x$static_linking_support" = "xno"; then 242 TRY_LDAP_LIBS="$LDAP_LIBS -lssl -lsasl2 -lcrypto" 243 else 244 TRY_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS ${static_linking_support}dynamic -lssl -lsasl2 -lcrypto" 245 fi 246 LIBLDAP_TRY_LINK([$TRY_LDAP_LIBS], [$LDAP_LDFLAGS], [$LDAP_CPPFLAGS], ,[ 247 LDAP_LIBS=$TRY_LDAP_LIBS 248 AC_MSG_RESULT([with system OpenSSL linking]) 249 ]) 250 fi 251 252 # with system OpenSSL for Solaris 253 if test "x$ldap_link" = "xno"; then 254 if test "x$static_linking_support" = "xno"; then 255 TRY_LDAP_LIBS="$LDAP_LIBS -lssl -lsasl -lcrypto" 256 else 257 TRY_LDAP_LIBS="${static_linking_support}static $LDAP_LIBS ${static_linking_support}dynamic -lssl -lsasl -lcrypto" 258 fi 259 LIBLDAP_TRY_LINK([$TRY_LDAP_LIBS], [$LDAP_LDFLAGS], [$LDAP_CPPFLAGS], ,[ 260 LDAP_LIBS=$TRY_LDAP_LIBS 261 AC_MSG_RESULT([with system OpenSSL and sasl linking]) 262 ]) 263 fi 264 265 if test "x$ldap_link" = "xno"; then 266 AC_MSG_ERROR([Not found compatible version of OpenLDAP static libs]) 267 fi 268 fi 269 270 found_ldap="yes" 271 AC_DEFINE(HAVE_LDAP,1,[Define to 1 if LDAP should be enabled.]) 272 AC_DEFINE(LDAP_DEPRECATED, 1, [Define to 1 if LDAP deprecated functions is used.]) 273 274 if test "x$enable_static" = "xyes"; then 275 AC_CHECK_LIB(gnutls, main, , AC_MSG_ERROR([Not found GnuTLS library])) 276 AC_CHECK_LIB(pthread, main, , AC_MSG_ERROR([Not found Pthread library])) 277 AC_CHECK_LIB(sasl2, main, , AC_MSG_ERROR([Not found SASL2 library])) 278 fi 279 fi 280 fi 281 282 AC_SUBST(LDAP_CPPFLAGS) 283 AC_SUBST(LDAP_LDFLAGS) 284 AC_SUBST(LDAP_LIBS) 285 286 unset _libldap_with 287])dnl 288