]> git.ipfire.org Git - thirdparty/pdns.git/blob - m4/pdns_check_libcrypto.m4
Add debug informations to the MPlexer unit tests, tracking a failure
[thirdparty/pdns.git] / m4 / pdns_check_libcrypto.m4
1 # SYNOPSIS
2 #
3 # PDNS_CHECK_LIBCRYPTO([action-if-found[, action-if-not-found]])
4 #
5 # DESCRIPTION
6 #
7 # Look for OpenSSL's libcrypto in a number of default spots, or in a
8 # user-selected spot (via --with-libcrypto). Sets
9 #
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
13 #
14 # and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
15 #
16 # This macro sets LIBCRYPTO_INCLUDES such that source files should use the
17 # openssl/ directory in include directives:
18 #
19 # #include <openssl/hmac.h>
20 #
21 # LICENSE
22 #
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>
26 #
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
30 # warranty.
31
32 #serial 1
33
34 AU_ALIAS([CHECK_LIBCRYPTO], [PDNS_CHECK_LIBCRYPTO])
35 AC_DEFUN([PDNS_CHECK_LIBCRYPTO], [
36 found=false
37 AC_ARG_WITH([libcrypto],
38 [AS_HELP_STRING([--with-libcrypto=DIR],
39 [root of the OpenSSL directory])],
40 [
41 case "$withval" in
42 "" | y | ye | yes | n | no)
43 AC_MSG_ERROR([Invalid --with-libcrypto value])
44 ;;
45 *) ssldirs="$withval"
46 ;;
47 esac
48 ], [
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`
54 if test $? = 0; then
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`
58 found=true
59 fi
60 fi
61
62 # no such luck; use some default ssldirs
63 if ! $found; then
64 ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
65 fi
66 ]
67 )
68
69
70 # note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
71 # an 'openssl' subdirectory
72
73 if ! $found; then
74 LIBCRYPTO_INCLUDES=
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"
81 found=true
82 AC_MSG_RESULT([yes])
83 break
84 else
85 AC_MSG_RESULT([no])
86 fi
87 done
88
89 # if the file wasn't found, well, go ahead and try the link anyway -- maybe
90 # it will just work!
91 fi
92
93 if $found; then
94 AC_DEFINE([HAVE_LIBCRYPTO], [1], [Define to 1 if you have OpenSSL libcrypto])
95 fi
96
97 # try the preprocessor and linker with our new flags,
98 # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
99
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
103
104 save_LIBS="$LIBS"
105 save_LDFLAGS="$LDFLAGS"
106 save_CPPFLAGS="$CPPFLAGS"
107 LDFLAGS="$LDFLAGS $LIBCRYPTO_LDFLAGS"
108 LIBS="$LIBCRYPTO_LIBS $LIBS"
109 CPPFLAGS="$LIBCRYPTO_INCLUDES $CPPFLAGS"
110 AC_LINK_IFELSE(
111 [AC_LANG_PROGRAM([#include <openssl/crypto.h>], [ERR_load_CRYPTO_strings()])],
112 [
113 AC_MSG_RESULT([yes])
114 AC_CHECK_FUNCS([RAND_bytes RAND_pseudo_bytes])
115 $1
116 ], [
117 AC_MSG_RESULT([no])
118 $2
119 ])
120 CPPFLAGS="$save_CPPFLAGS"
121 LDFLAGS="$save_LDFLAGS"
122 LIBS="$save_LIBS"
123
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"])
128 ])