]> git.ipfire.org Git - thirdparty/pdns.git/blob - m4/pdns_check_libcrypto.m4
Merge pull request #4198 from stutiredboy/master
[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 found=true
58 fi
59 fi
60
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
68
69 # note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
70 # an 'openssl' subdirectory
71
72 if ! $found; then
73 LIBCRYPTO_INCLUDES=
74 for ssldir in $ssldirs; do
75 AC_MSG_CHECKING([for openssl/crypto.h in $ssldir])
76 if test -f "$ssldir/include/openssl/crypto.h"; then
77 LIBCRYPTO_INCLUDES="-I$ssldir/include"
78 LIBCRYPTO_LDFLAGS="-L$ssldir/lib"
79 LIBCRYPTO_LIBS="-lcrypto"
80 found=true
81 AC_MSG_RESULT([yes])
82 break
83 else
84 AC_MSG_RESULT([no])
85 fi
86 done
87
88 # if the file wasn't found, well, go ahead and try the link anyway -- maybe
89 # it will just work!
90 fi
91
92 # try the preprocessor and linker with our new flags,
93 # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
94
95 AC_MSG_CHECKING([whether compiling and linking against OpenSSL's libcrypto works])
96 echo "Trying link with LIBCRYPTO_LDFLAGS=$LIBCRYPTO_LDFLAGS;" \
97 "LIBCRYPTO_LIBS=$LIBCRYPTO_LIBS; LIBCRYPTO_INCLUDES=$LIBCRYPTO_INCLUDES" >&AS_MESSAGE_LOG_FD
98
99 save_LIBS="$LIBS"
100 save_LDFLAGS="$LDFLAGS"
101 save_CPPFLAGS="$CPPFLAGS"
102 LDFLAGS="$LDFLAGS $LIBCRYPTO_LDFLAGS"
103 LIBS="$LIBCRYPTO_LIBS $LIBS"
104 CPPFLAGS="$LIBCRYPTO_INCLUDES $CPPFLAGS"
105 AC_LINK_IFELSE(
106 [AC_LANG_PROGRAM([#include <openssl/crypto.h>], [ERR_load_CRYPTO_strings()])],
107 [
108 AC_MSG_RESULT([yes])
109 $1
110 ], [
111 AC_MSG_RESULT([no])
112 $2
113 ])
114 CPPFLAGS="$save_CPPFLAGS"
115 LDFLAGS="$save_LDFLAGS"
116 LIBS="$save_LIBS"
117
118 AC_SUBST([LIBCRYPTO_INCLUDES])
119 AC_SUBST([LIBCRYPTO_LIBS])
120 AC_SUBST([LIBCRYPTO_LDFLAGS])
121 ])