openldap.m4 5.0 KB

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