openldap.m4 5.7 KB

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