1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_check_openssl.html
3 # ===========================================================================
7 # AX_CHECK_OPENSSL([action-if-found[, action-if-not-found]])
11 # Look for OpenSSL in a number of default spots, or in a user-selected
12 # spot (via --with-openssl). Sets
14 # SSL_INCLUDES to the include directives required
15 # SSL_LIBS to the -l directives required
16 # SSL_LDFLAGS to the -L or -R flags required
18 # and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
20 # This macro sets SSL_INCLUDES such that source files should use the
21 # openssl/ directory in include directives:
23 # #include <openssl/hmac.h>
27 # Copyright (c) 2009,2010 Zmanda Inc. <http://www.zmanda.com/>
28 # Copyright (c) 2009,2010 Dustin J. Mitchell <dustin@zmanda.com>
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
37 AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL])
38 AC_DEFUN([AX_CHECK_OPENSSL], [
40 AC_ARG_WITH([openssl],
41 [AS_HELP_STRING([--with-openssl=DIR],
42 [root of the OpenSSL directory])],
45 "" | y | ye | yes | n | no)
46 AC_MSG_ERROR([Invalid --with-openssl value])
52 # if pkg-config is installed and openssl has installed a .pc file,
53 # then use that information and don't search ssldirs
54 AC_PATH_PROG([PKG_CONFIG], [pkg-config])
55 if test x"$PKG_CONFIG" != x""; then
56 SSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
58 SSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
59 SSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
64 # no such luck; use some default ssldirs
66 ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
72 # note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
73 # an 'openssl' subdirectory
77 for ssldir in $ssldirs; do
78 AC_MSG_CHECKING([for openssl/ssl.h in $ssldir])
79 if test -f "$ssldir/include/openssl/ssl.h"; then
80 SSL_INCLUDES="-I$ssldir/include"
81 SSL_LDFLAGS="-L$ssldir/lib"
82 if test "$WIN32" = "yes"; then
83 SSL_LIBS="-lssleay32 -llibeay32"
85 SSL_LIBS="-lssl -lcrypto"
95 # if the file wasn't found, well, go ahead and try the link anyway -- maybe
99 # try the preprocessor and linker with our new flags,
100 # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
102 AC_MSG_CHECKING([whether compiling and linking against OpenSSL works])
103 echo "Trying link with SSL_LDFLAGS=$SSL_LDFLAGS;" \
104 "SSL_LIBS=$SSL_LIBS; SSL_INCLUDES=$SSL_INCLUDES" >&AS_MESSAGE_LOG_FD
107 save_LDFLAGS="$LDFLAGS"
108 save_CPPFLAGS="$CPPFLAGS"
109 LDFLAGS="$LDFLAGS $SSL_LDFLAGS"
110 LIBS="$SSL_LIBS $LIBS"
111 CPPFLAGS="$SSL_INCLUDES $CPPFLAGS"
113 [AC_LANG_PROGRAM([#include <openssl/ssl.h>],
114 [SSL_CTX *ctx=NULL;SSL_new(ctx)])],
122 CPPFLAGS="$save_CPPFLAGS"
123 LDFLAGS="$save_LDFLAGS"
126 AC_SUBST([SSL_INCLUDES])
128 AC_SUBST([SSL_LDFLAGS])