1 # ===========================================================================
2 # http://www.nongnu.org/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 # 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
18 # and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
20 # This macro sets OPENSSL_INCLUDES such that source files should use the
21 # openssl/ directory in include directives:
23 # #include <openssl/hmac.h>
27 # Copyright (c) 2009 Zmanda Inc. <http://www.zmanda.com/>
28 # Copyright (c) 2009 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
35 AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL])
36 AC_DEFUN([AX_CHECK_OPENSSL], [
39 AS_HELP_STRING([--with-openssl=DIR],
40 [root of the OpenSSL directory]),
43 "" | y | ye | yes | n | no)
44 AC_MSG_ERROR([Invalid --with-openssl value])
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`
56 OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
57 OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
62 # no such luck; use some default ssldirs
64 ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
70 # note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
71 # an 'openssl' subdirectory
75 for ssldir in $ssldirs; do
76 AC_MSG_CHECKING([for openssl/ssl.h in $ssldir])
77 if test -f "$ssldir/include/openssl/ssl.h"; then
78 OPENSSL_INCLUDES="-I$ssldir/include"
79 OPENSSL_LDFLAGS="-L $ssldir/lib"
80 OPENSSL_LIBS="-lssl -lcrypto"
89 # if the file wasn't found, well, go ahead and try the link anyway -- maybe
93 # try the preprocessor and linker with our new flags,
94 # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
96 AC_MSG_CHECKING([whether compiling and linking against OpenSSL works])
97 echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \
98 "OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&AS_MESSAGE_LOG_FD
101 save_LDFLAGS="$LDFLAGS"
102 save_CPPFLAGS="$CPPFLAGS"
103 LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
104 LIBS="$OPENSSL_LIBS $LIBS"
105 CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
107 AC_LANG_PROGRAM([#include <openssl/ssl.h>], [SSL_new(NULL)]),
115 CPPFLAGS="$save_CPPFLAGS"
116 LDFLAGS="$save_LDFLAGS"
119 AC_SUBST([OPENSSL_INCLUDES])
120 AC_SUBST([OPENSSL_LIBS])
121 AC_SUBST([OPENSSL_LDFLAGS])