3 # PDNS_CHECK_LIBCRYPTO([action-if-found[, action-if-not-found]])
7 # Look for OpenSSL's libcrypto in a number of default spots, or in a
8 # user-selected spot (via --with-libcrypto). Sets
10 # LIBCRYPTO_INCLUDES to the include directives required
11 # LIBCRYPTO_LIBS to the -l directives required
12 # LIBCRYPTO_LDFLAGS to the -L or -R flags required
14 # and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
16 # This macro sets LIBCRYPTO_INCLUDES such that source files should use the
17 # openssl/ directory in include directives:
19 # #include <openssl/hmac.h>
23 # Taken and modified from AX_CHECK_OPENSSL by:
24 # Copyright (c) 2009,2010 Zmanda Inc. <http://www.zmanda.com/>
25 # Copyright (c) 2009,2010 Dustin J. Mitchell <dustin@zmanda.com>
27 # Copying and distribution of this file, with or without modification, are
28 # permitted in any medium without royalty provided the copyright notice
29 # and this notice are preserved. This file is offered as-is, without any
34 AU_ALIAS([CHECK_LIBCRYPTO], [PDNS_CHECK_LIBCRYPTO])
35 AC_DEFUN([PDNS_CHECK_LIBCRYPTO], [
37 AC_ARG_WITH([libcrypto],
38 [AS_HELP_STRING([--with-libcrypto=DIR],
39 [root of the OpenSSL directory])],
42 "" | y | ye | yes | n | no)
43 AC_MSG_ERROR([Invalid --with-libcrypto value])
49 # if pkg-config is installed and openssl has installed a .pc file,
50 # then use that information and don't search ssldirs
51 AC_CHECK_TOOL([PKG_CONFIG], [pkg-config])
52 if test x"$PKG_CONFIG" != x""; then
53 LIBCRYPTO_LDFLAGS=`$PKG_CONFIG libcrypto --libs-only-L 2>/dev/null`
55 LIBCRYPTO_LIBS=`$PKG_CONFIG libcrypto --libs-only-l 2>/dev/null`
56 LIBCRYPTO_INCLUDES=`$PKG_CONFIG libcrypto --cflags-only-I 2>/dev/null`
57 ssldir=`$PKG_CONFIG libcrypto --variable=prefix 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/crypto.h in $ssldir])
77 if test -f "$ssldir/include/openssl/crypto.h"; then
78 LIBCRYPTO_INCLUDES="-I$ssldir/include"
79 LIBCRYPTO_LDFLAGS="-L$ssldir/lib"
80 LIBCRYPTO_LIBS="-lcrypto"
89 # if the file wasn't found, well, go ahead and try the link anyway -- maybe
94 AC_DEFINE([HAVE_LIBCRYPTO], [1], [Define to 1 if you have OpenSSL libcrypto])
97 # try the preprocessor and linker with our new flags,
98 # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
100 AC_MSG_CHECKING([whether compiling and linking against OpenSSL's libcrypto works])
101 echo "Trying link with LIBCRYPTO_LDFLAGS=$LIBCRYPTO_LDFLAGS;" \
102 "LIBCRYPTO_LIBS=$LIBCRYPTO_LIBS; LIBCRYPTO_INCLUDES=$LIBCRYPTO_INCLUDES" >&AS_MESSAGE_LOG_FD
105 save_LDFLAGS="$LDFLAGS"
106 save_CPPFLAGS="$CPPFLAGS"
107 LDFLAGS="$LDFLAGS $LIBCRYPTO_LDFLAGS"
108 LIBS="$LIBCRYPTO_LIBS $LIBS"
109 CPPFLAGS="$LIBCRYPTO_INCLUDES $CPPFLAGS"
111 [AC_LANG_PROGRAM([#include <openssl/crypto.h>], [ERR_load_CRYPTO_strings()])],
114 AC_CHECK_FUNCS([RAND_bytes RAND_pseudo_bytes])
120 CPPFLAGS="$save_CPPFLAGS"
121 LDFLAGS="$save_LDFLAGS"
124 AC_SUBST([LIBCRYPTO_INCLUDES])
125 AC_SUBST([LIBCRYPTO_LIBS])
126 AC_SUBST([LIBCRYPTO_LDFLAGS])
127 AM_CONDITIONAL([HAVE_LIBCRYPTO], [test "x$LIBCRYPTO_LIBS" != "x"])