ax_check_openssl.m4 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_check_openssl.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CHECK_OPENSSL([action-if-found[, action-if-not-found]])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Look for OpenSSL in a number of default spots, or in a user-selected
  12. # spot (via --with-openssl). Sets
  13. #
  14. # OPENSSL_INCLUDES to the include directives required
  15. # OPENSSL_LIBS to the -l directives required
  16. # OPENSSL_LDFLAGS to the -L or -R flags required
  17. #
  18. # and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
  19. #
  20. # This macro sets OPENSSL_INCLUDES such that source files should use the
  21. # openssl/ directory in include directives:
  22. #
  23. # #include <openssl/hmac.h>
  24. #
  25. # LICENSE
  26. #
  27. # Copyright (c) 2009,2010 Zmanda Inc. <http://www.zmanda.com/>
  28. # Copyright (c) 2009,2010 Dustin J. Mitchell <dustin@zmanda.com>
  29. #
  30. # Copying and distribution of this file, with or without modification, are
  31. # permitted in any medium without royalty provided the copyright notice
  32. # and this notice are preserved. This file is offered as-is, without any
  33. # warranty.
  34. #serial 8
  35. AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL])
  36. AC_DEFUN([AX_CHECK_OPENSSL], [
  37. found=false
  38. AC_ARG_WITH([openssl],
  39. [AS_HELP_STRING([--with-openssl=DIR],
  40. [root of the OpenSSL directory])],
  41. [
  42. case "$withval" in
  43. "" | y | ye | yes | n | no)
  44. AC_MSG_ERROR([Invalid --with-openssl value])
  45. ;;
  46. *) ssldirs="$withval"
  47. ;;
  48. esac
  49. ], [
  50. # if pkg-config is installed and openssl has installed a .pc file,
  51. # then use that information and don't search ssldirs
  52. AC_PATH_PROG([PKG_CONFIG], [pkg-config])
  53. if test x"$PKG_CONFIG" != x""; then
  54. OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
  55. if test $? = 0; then
  56. OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
  57. OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
  58. found=true
  59. fi
  60. fi
  61. # no such luck; use some default ssldirs
  62. if ! $found; then
  63. ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
  64. fi
  65. ]
  66. )
  67. # note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
  68. # an 'openssl' subdirectory
  69. if ! $found; then
  70. OPENSSL_INCLUDES=
  71. for ssldir in $ssldirs; do
  72. AC_MSG_CHECKING([for openssl/ssl.h in $ssldir])
  73. if test -f "$ssldir/include/openssl/ssl.h"; then
  74. OPENSSL_INCLUDES="-I$ssldir/include"
  75. OPENSSL_LDFLAGS="-L$ssldir/lib"
  76. OPENSSL_LIBS="-lssl -lcrypto"
  77. found=true
  78. AC_MSG_RESULT([yes])
  79. break
  80. else
  81. AC_MSG_RESULT([no])
  82. fi
  83. done
  84. # if the file wasn't found, well, go ahead and try the link anyway -- maybe
  85. # it will just work!
  86. fi
  87. # try the preprocessor and linker with our new flags,
  88. # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
  89. AC_MSG_CHECKING([whether compiling and linking against OpenSSL works])
  90. echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \
  91. "OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&AS_MESSAGE_LOG_FD
  92. save_LIBS="$LIBS"
  93. save_LDFLAGS="$LDFLAGS"
  94. save_CPPFLAGS="$CPPFLAGS"
  95. LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
  96. LIBS="$OPENSSL_LIBS $LIBS"
  97. CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
  98. AC_LINK_IFELSE(
  99. [AC_LANG_PROGRAM([#include <openssl/ssl.h>], [SSL_new(NULL)])],
  100. [
  101. AC_MSG_RESULT([yes])
  102. $1
  103. ], [
  104. AC_MSG_RESULT([no])
  105. $2
  106. ])
  107. CPPFLAGS="$save_CPPFLAGS"
  108. LDFLAGS="$save_LDFLAGS"
  109. LIBS="$save_LIBS"
  110. AC_SUBST([OPENSSL_INCLUDES])
  111. AC_SUBST([OPENSSL_LIBS])
  112. AC_SUBST([OPENSSL_LDFLAGS])
  113. ])