]> git.ipfire.org Git - thirdparty/pdns.git/blame - m4/pdns_check_libcrypto.m4
Merge pull request #7871 from omoerbeek/calidns-openbsd
[thirdparty/pdns.git] / m4 / pdns_check_libcrypto.m4
CommitLineData
7581a35b
KM
1# SYNOPSIS
2#
74d83458 3# PDNS_CHECK_LIBCRYPTO([action-if-found[, action-if-not-found]])
7581a35b
KM
4#
5# DESCRIPTION
6#
74d83458
PL
7# Look for OpenSSL's libcrypto in a number of default spots, or in a
8# user-selected spot (via --with-libcrypto). Sets
7581a35b 9#
74d83458
PL
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
7581a35b
KM
13#
14# and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
15#
74d83458 16# This macro sets LIBCRYPTO_INCLUDES such that source files should use the
7581a35b
KM
17# openssl/ directory in include directives:
18#
19# #include <openssl/hmac.h>
20#
21# LICENSE
22#
74d83458 23# Taken and modified from AX_CHECK_OPENSSL by:
7581a35b
KM
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
74d83458 32#serial 1
7581a35b 33
74d83458
PL
34AU_ALIAS([CHECK_LIBCRYPTO], [PDNS_CHECK_LIBCRYPTO])
35AC_DEFUN([PDNS_CHECK_LIBCRYPTO], [
7581a35b 36 found=false
74d83458
PL
37 AC_ARG_WITH([libcrypto],
38 [AS_HELP_STRING([--with-libcrypto=DIR],
7581a35b
KM
39 [root of the OpenSSL directory])],
40 [
41 case "$withval" in
42 "" | y | ye | yes | n | no)
74d83458 43 AC_MSG_ERROR([Invalid --with-libcrypto value])
7581a35b
KM
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
74d83458 51 AC_CHECK_TOOL([PKG_CONFIG], [pkg-config])
7581a35b 52 if test x"$PKG_CONFIG" != x""; then
74d83458 53 LIBCRYPTO_LDFLAGS=`$PKG_CONFIG libcrypto --libs-only-L 2>/dev/null`
7581a35b 54 if test $? = 0; then
74d83458
PL
55 LIBCRYPTO_LIBS=`$PKG_CONFIG libcrypto --libs-only-l 2>/dev/null`
56 LIBCRYPTO_INCLUDES=`$PKG_CONFIG libcrypto --cflags-only-I 2>/dev/null`
2a4c3744 57 ssldir=`$PKG_CONFIG libcrypto --variable=prefix 2>/dev/null`
7581a35b
KM
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
74d83458 74 LIBCRYPTO_INCLUDES=
7581a35b 75 for ssldir in $ssldirs; do
793f83f4
KM
76 AC_MSG_CHECKING([for openssl/crypto.h in $ssldir])
77 if test -f "$ssldir/include/openssl/crypto.h"; then
74d83458
PL
78 LIBCRYPTO_INCLUDES="-I$ssldir/include"
79 LIBCRYPTO_LDFLAGS="-L$ssldir/lib"
80 LIBCRYPTO_LIBS="-lcrypto"
7581a35b
KM
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
f4b1f1fd
RG
93 if $found; then
94 AC_DEFINE([HAVE_LIBCRYPTO], [1], [Define to 1 if you have OpenSSL libcrypto])
95 fi
96
7581a35b
KM
97 # try the preprocessor and linker with our new flags,
98 # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
99
74d83458
PL
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
7581a35b
KM
103
104 save_LIBS="$LIBS"
105 save_LDFLAGS="$LDFLAGS"
106 save_CPPFLAGS="$CPPFLAGS"
74d83458
PL
107 LDFLAGS="$LDFLAGS $LIBCRYPTO_LDFLAGS"
108 LIBS="$LIBCRYPTO_LIBS $LIBS"
109 CPPFLAGS="$LIBCRYPTO_INCLUDES $CPPFLAGS"
7581a35b 110 AC_LINK_IFELSE(
74d83458 111 [AC_LANG_PROGRAM([#include <openssl/crypto.h>], [ERR_load_CRYPTO_strings()])],
7581a35b
KM
112 [
113 AC_MSG_RESULT([yes])
5d6a8b62 114 AC_CHECK_FUNCS([RAND_bytes RAND_pseudo_bytes])
7581a35b
KM
115 $1
116 ], [
117 AC_MSG_RESULT([no])
118 $2
119 ])
120 CPPFLAGS="$save_CPPFLAGS"
121 LDFLAGS="$save_LDFLAGS"
122 LIBS="$save_LIBS"
123
74d83458
PL
124 AC_SUBST([LIBCRYPTO_INCLUDES])
125 AC_SUBST([LIBCRYPTO_LIBS])
126 AC_SUBST([LIBCRYPTO_LDFLAGS])
f4b1f1fd 127 AM_CONDITIONAL([HAVE_LIBCRYPTO], [test "x$LIBCRYPTO_LIBS" != "x"])
7581a35b 128])