aboutsummaryrefslogtreecommitdiffstats
path: root/SoftHSMv2/m4/acx_openssl.m4
blob: e90c78f8a24620fb4e9fe88bb19ff82113f9aa1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
AC_DEFUN([ACX_OPENSSL],[
	AC_ARG_WITH(openssl,
        	AC_HELP_STRING([--with-openssl=PATH],[Specify prefix of path of OpenSSL]),
		[
			OPENSSL_PATH="$withval"
		],
		[
			OPENSSL_PATH="/usr/local"
		])

	AC_MSG_CHECKING(what are the OpenSSL includes)
	OPENSSL_INCLUDES="-I$OPENSSL_PATH/include"
	AC_MSG_RESULT($OPENSSL_INCLUDES)

	AC_MSG_CHECKING(what are the OpenSSL libs)
	OPENSSL_LIBS="-L$OPENSSL_PATH/lib -lcrypto"
	AC_MSG_RESULT($OPENSSL_LIBS)

	tmp_CPPFLAGS=$CPPFLAGS
	tmp_LIBS=$LIBS

	CPPFLAGS="$CPPFLAGS $OPENSSL_INCLUDES"
	LIBS="$OPENSSL_LIBS $LIBS"

	AC_CHECK_HEADERS([openssl/ssl.h],,[AC_MSG_ERROR([Can't find OpenSSL headers])])
	AC_CHECK_LIB(crypto, BN_new,,[AC_MSG_ERROR([Can't find OpenSSL library])])

	AC_MSG_CHECKING([for OpenSSL version])
	CHECK_OPENSSL_VERSION=m4_format(0x%02x%02x%02x000L, $1, $2, $3)
	AC_LANG_PUSH([C])
	AC_RUN_IFELSE([
		AC_LANG_SOURCE([[
			#include <openssl/ssl.h>
			#include <openssl/opensslv.h>
			int main()
			{
			#ifndef OPENSSL_VERSION_NUMBER
				return -1;
			#endif
			#if OPENSSL_VERSION_NUMBER >= $CHECK_OPENSSL_VERSION
				return 0;
			#else
				return 1;
			#endif
			}
		]])
	],[
		AC_MSG_RESULT([>= $1.$2.$3])
	],[
		AC_MSG_RESULT([< $1.$2.$3])
		AC_MSG_ERROR([OpenSSL library too old ($1.$2.$3 or later required)])
	],[])
	AC_LANG_POP([C])

	CPPFLAGS=$tmp_CPPFLAGS
	LIBS=$tmp_LIBS

	AC_SUBST(OPENSSL_INCLUDES)
	AC_SUBST(OPENSSL_LIBS)
])