Fix building documentation when using OpenBSD's make.
[oweals/tinc.git] / m4 / openssl.m4
1 dnl Check to find the LibreSSL/OpenSSL headers/libraries
2
3 AC_DEFUN([tinc_OPENSSL],
4 [
5   case $host_os in
6     *mingw*)
7     ;;
8     *)
9       AC_CHECK_FUNC(dlopen,
10         [],
11         [AC_CHECK_LIB(dl, dlopen,
12           [LIBS="$LIBS -ldl"],
13           [AC_MSG_ERROR([LibreSSL/OpenSSL depends on libdl.]); break]
14         )]
15       )
16     ;;
17   esac
18
19   AC_ARG_WITH(openssl,
20     AS_HELP_STRING([--with-openssl=DIR], [LibreSSL/OpenSSL base directory, or:]),
21     [openssl="$withval"
22      CPPFLAGS="$CPPFLAGS -I$withval/include"
23      LDFLAGS="$LDFLAGS -L$withval/lib"]
24   )
25
26   AC_ARG_WITH(openssl-include,
27     AS_HELP_STRING([--with-openssl-include=DIR], [LibreSSL/OpenSSL headers directory (without trailing /openssl)]),
28     [openssl_include="$withval"
29      CPPFLAGS="$CPPFLAGS -I$withval"]
30   )
31
32   AC_ARG_WITH(openssl-lib,
33     AS_HELP_STRING([--with-openssl-lib=DIR], [LibreSSL/OpenSSL library directory]),
34     [openssl_lib="$withval"
35      LDFLAGS="$LDFLAGS -L$withval"]
36   )
37
38   AC_CHECK_HEADERS(openssl/evp.h openssl/rsa.h openssl/rand.h openssl/err.h openssl/sha.h openssl/pem.h openssl/engine.h,
39     [],
40     [AC_MSG_ERROR([LibreSSL/OpenSSL header files not found.]); break]
41   )
42
43   AC_CHECK_LIB(crypto, EVP_EncryptInit_ex,
44     [LIBS="-lcrypto $LIBS"],
45     [AC_MSG_ERROR([LibreSSL/OpenSSL libraries not found.])]
46   )
47
48   AC_CHECK_FUNCS([RAND_bytes EVP_EncryptInit_ex EVP_CIPHER_CTX_new], ,
49     [AC_MSG_ERROR([Missing LibreSSL/OpenSSL functionality, make sure you have installed the latest version.]); break],
50   )
51
52   AC_CHECK_DECLS([OpenSSL_add_all_algorithms, EVP_aes_256_cfb], ,
53     [AC_MSG_ERROR([Missing LibreSSL/OpenSSL functionality, make sure you have installed the latest version.]); break],
54     [#include <openssl/evp.h>]
55   )
56
57   AC_CHECK_FUNCS([BN_GENCB_new RSA_set0_key], , , [#include <openssl/rsa.h>])
58 ])