openldap.m4 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # BEGIN COPYRIGHT BLOCK
  2. # Copyright (C) 2009 Red Hat, Inc.
  3. # All rights reserved.
  4. #
  5. # License: GPL (version 3 or any later version).
  6. # See LICENSE for details.
  7. # END COPYRIGHT BLOCK
  8. AC_CHECKING(for OpenLDAP)
  9. if test -z "$with_openldap"; then
  10. with_openldap=yes # Set default to yes
  11. fi
  12. # check for --with-openldap
  13. AC_MSG_CHECKING(for --with-openldap)
  14. AC_ARG_WITH(openldap, AS_HELP_STRING([--with-openldap@<:@=PATH@:>@],[Use OpenLDAP - optional PATH is path to OpenLDAP SDK]),
  15. [
  16. if test "$withval" = yes
  17. then
  18. AC_MSG_RESULT([using system OpenLDAP])
  19. ldaplib="openldap"
  20. ldaplib_defs="-DUSE_OPENLDAP"
  21. elif test "$withval" = no
  22. then
  23. AC_MSG_RESULT(no)
  24. elif test -e "$withval"/include/ldap.h -a -d "$withval"/lib
  25. then
  26. AC_MSG_RESULT([using $withval])
  27. OPENLDAPDIR=$withval
  28. ldaplib="openldap"
  29. ldaplib_defs="-DUSE_OPENLDAP"
  30. openldap_incdir="$OPENLDAPDIR/include"
  31. openldap_inc="-I$openldap_incdir"
  32. openldap_lib="-L$OPENLDAPDIR/lib"
  33. openldap_libdir="$OPENLDAPDIR/lib"
  34. openldap_bindir="$OPENLDAPDIR/bin"
  35. with_openldap=yes
  36. else
  37. echo
  38. AC_MSG_ERROR([$withval not found])
  39. fi
  40. ],
  41. AC_MSG_RESULT(no))
  42. # check for --with-openldap-inc
  43. AC_MSG_CHECKING(for --with-openldap-inc)
  44. AC_ARG_WITH(openldap-inc, AS_HELP_STRING([--with-openldap-inc=PATH],[OpenLDAP SDK include directory]),
  45. [
  46. if test -e "$withval"/ldap.h
  47. then
  48. AC_MSG_RESULT([using $withval])
  49. openldap_incdir="$withval"
  50. openldap_inc="-I$withval"
  51. with_openldap=yes
  52. else
  53. echo
  54. AC_MSG_ERROR([$withval not found])
  55. fi
  56. ],
  57. AC_MSG_RESULT(no))
  58. # check for --with-openldap-lib
  59. AC_MSG_CHECKING(for --with-openldap-lib)
  60. AC_ARG_WITH(openldap-lib, AS_HELP_STRING([--with-openldap-lib=PATH],[OpenLDAP SDK library directory]),
  61. [
  62. if test -d "$withval"
  63. then
  64. AC_MSG_RESULT([using $withval])
  65. openldap_lib="-L$withval"
  66. openldap_libdir="$withval"
  67. with_openldap=yes
  68. else
  69. echo
  70. AC_MSG_ERROR([$withval not found])
  71. fi
  72. ],
  73. AC_MSG_RESULT(no))
  74. # check for --with-openldap-bin
  75. AC_MSG_CHECKING(for --with-openldap-bin)
  76. AC_ARG_WITH(openldap-bin, AS_HELP_STRING([--with-openldap-bin=PATH],[OpenLDAP SDK binary directory]),
  77. [
  78. if test -d "$withval"
  79. then
  80. AC_MSG_RESULT([using $withval])
  81. openldap_bindir="$withval"
  82. with_openldap=yes
  83. else
  84. echo
  85. AC_MSG_ERROR([$withval not found])
  86. fi
  87. ],
  88. AC_MSG_RESULT(no))
  89. # if OPENLDAP is not found yet, try pkg-config
  90. if test "$with_openldap" = yes ; then # user wants to use openldap, but didn't specify paths
  91. if test -z "$openldap_inc" -o -z "$openldap_lib" -o -z "$openldap_libdir" -o -z "$openldap_bindir"; then
  92. AC_MSG_CHECKING(for OpenLDAP with pkg-config)
  93. if test -n "$PKG_CONFIG" && $PKG_CONFIG --exists openldap; then
  94. openldap_inc=`$PKG_CONFIG --cflags-only-I openldap`
  95. openldap_lib=`$PKG_CONFIG --libs-only-L openldap`
  96. openldap_libdir=`$PKG_CONFIG --libs-only-L openldap | sed -e s/-L// | sed -e s/\ .*$//`
  97. openldap_bindir=`$PKG_CONFIG --variable=bindir openldap`
  98. openldap_incdir=`$PKG_CONFIG --variable=includedir openldap`
  99. AC_MSG_RESULT([using system OpenLDAP from pkg-config])
  100. else
  101. openldap_incdir="/usr/include"
  102. openldap_inc="-I$openldap_incdir"
  103. AC_MSG_RESULT([no OpenLDAP pkg-config files])
  104. fi
  105. fi
  106. fi
  107. dnl lets see if we can find the headers and libs
  108. if test "$with_openldap" = yes ; then
  109. save_cppflags="$CPPFLAGS"
  110. CPPFLAGS="$openldap_inc $NSS_CFLAGS $NSPR_CFLAGS"
  111. AC_CHECK_HEADER([ldap_features.h], [],
  112. [AC_MSG_ERROR([specified with-openldap but ldap_features.h not found])])
  113. dnl figure out which version we're using from the header file
  114. ol_ver_maj=`grep LDAP_VENDOR_VERSION_MAJOR $openldap_incdir/ldap_features.h | awk '{print $3}'`
  115. ol_ver_min=`grep LDAP_VENDOR_VERSION_MINOR $openldap_incdir/ldap_features.h | awk '{print $3}'`
  116. ol_ver_pat=`grep LDAP_VENDOR_VERSION_PATCH $openldap_incdir/ldap_features.h | awk '{print $3}'`
  117. dnl full libname is libname-$maj.$min
  118. ol_libver="-${ol_ver_maj}.${ol_ver_min}"
  119. dnl look for ldap lib
  120. save_ldflags="$LDFLAGS"
  121. LDFLAGS="$openldap_lib $LDFLAGS"
  122. AC_CHECK_LIB([ldap$ol_libver], [ldap_initialize], [have_ldap_lib=1])
  123. if test -z "$have_ldap_lib" ; then
  124. AC_CHECK_LIB([ldap], [ldap_initialize], [unset ol_libver],
  125. [AC_MSG_ERROR([specified with-openldap but libldap not found])])
  126. fi
  127. dnl look for ldap_url_parse_ext
  128. AC_CHECK_LIB([ldap$ol_libver], [ldap_url_parse_ext],
  129. [AC_DEFINE([HAVE_LDAP_URL_PARSE_EXT], [1], [have the function ldap_url_parse_ext])])
  130. dnl look for separate libldif - newer versions of openldap have moved the
  131. dnl ldif functionality into libldap
  132. ldap_lib_ldif=""
  133. LDFLAGS="$LDFLAGS -lldap$ol_libver"
  134. AC_CHECK_LIB([ldif$ol_libver], [_init], [ldap_lib_ldif=-lldif$ol_libver],
  135. [ldap_lib_ldif=])
  136. AC_SUBST([ldap_lib_ldif])
  137. LDFLAGS="$save_ldflags"
  138. CPPFLAGS="$save_cppflags"
  139. AC_DEFINE([USE_OPENLDAP], [1], [If defined, using OpenLDAP for LDAP SDK])
  140. # where to find ldapsearch, et. al.
  141. ldaptool_bindir=$openldap_bindir
  142. # default options to pass to the tools
  143. # use -x because all of our scripts use simple bind
  144. ldaptool_opts=-x
  145. # get plain output from ldapsearch - no version, no comments
  146. plainldif_opts=-LLL
  147. fi
  148. AC_SUBST(openldap_inc)
  149. AC_SUBST(openldap_lib)
  150. AC_SUBST(openldap_libdir)
  151. AC_SUBST(openldap_bindir)
  152. AC_SUBST(ol_libver)