|
1
|
# =========================================================================== |
|
2
|
# http://www.gnu.org/software/autoconf-archive/ax_check_openssl.html |
|
3
|
# =========================================================================== |
|
4
|
# |
|
5
|
# SYNOPSIS |
|
6
|
# |
|
7
|
# AX_CHECK_OPENSSL([action-if-found[, action-if-not-found]]) |
|
8
|
# |
|
9
|
# DESCRIPTION |
|
10
|
# |
|
11
|
# Look for OpenSSL in a number of default spots, or in a user-selected |
|
12
|
# spot (via --with-openssl). Sets |
|
13
|
# |
|
14
|
# OPENSSL_INCLUDES to the include directives required |
|
15
|
# OPENSSL_LIBS to the -l directives required |
|
16
|
# OPENSSL_LDFLAGS to the -L or -R flags required |
|
17
|
# |
|
18
|
# and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately |
|
19
|
# |
|
20
|
# This macro sets OPENSSL_INCLUDES such that source files should use the |
|
21
|
# openssl/ directory in include directives: |
|
22
|
# |
|
23
|
# #include <openssl/hmac.h> |
|
24
|
# |
|
25
|
# LICENSE |
|
26
|
# |
|
27
|
# Copyright (c) 2009,2010 Zmanda Inc. <http://www.zmanda.com/> |
|
28
|
# Copyright (c) 2009,2010 Dustin J. Mitchell <[email protected]> |
|
29
|
# |
|
30
|
# Copying and distribution of this file, with or without modification, are |
|
31
|
# permitted in any medium without royalty provided the copyright notice |
|
32
|
# and this notice are preserved. This file is offered as-is, without any |
|
33
|
# warranty. |
|
34
|
|
|
35
|
#serial 7 |
|
36
|
|
|
37
|
AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL]) |
|
38
|
AC_DEFUN([AX_CHECK_OPENSSL], [ |
|
39
|
found=false |
|
40
|
AC_ARG_WITH(openssl, |
|
41
|
AS_HELP_STRING([--with-openssl=DIR], |
|
42
|
[root of the OpenSSL directory]), |
|
43
|
[ |
|
44
|
case "$withval" in |
|
45
|
"" | y | ye | yes | n | no) |
|
46
|
AC_MSG_ERROR([Invalid --with-openssl value]) |
|
47
|
;; |
|
48
|
*) ssldirs="$withval" |
|
49
|
;; |
|
50
|
esac |
|
51
|
], [ |
|
52
|
# if pkg-config is installed and openssl has installed a .pc file, |
|
53
|
# then use that information and don't search ssldirs |
|
54
|
AC_PATH_PROG(PKG_CONFIG, pkg-config) |
|
55
|
if test x"$PKG_CONFIG" != x""; then |
|
56
|
OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null` |
|
57
|
if test $? = 0; then |
|
58
|
OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null` |
|
59
|
OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null` |
|
60
|
found=true |
|
61
|
fi |
|
62
|
fi |
|
63
|
|
|
64
|
# no such luck; use some default ssldirs |
|
65
|
# -- check /usr/sfw first to get the right OpenSSL on Solaris 10 |
|
66
|
if ! $found; then |
|
67
|
ssldirs="/usr/sfw /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr" |
|
68
|
fi |
|
69
|
] |
|
70
|
) |
|
71
|
|
|
72
|
|
|
73
|
# note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in |
|
74
|
# an 'openssl' subdirectory |
|
75
|
|
|
76
|
if ! $found; then |
|
77
|
OPENSSL_INCLUDES= |
|
78
|
for ssldir in $ssldirs; do |
|
79
|
AC_MSG_CHECKING([for openssl/ssl.h in $ssldir]) |
|
80
|
if test -f "$ssldir/include/openssl/ssl.h"; then |
|
81
|
OPENSSL_INCLUDES="-I$ssldir/include" |
|
82
|
OPENSSL_LDFLAGS="-L$ssldir/lib" |
|
83
|
OPENSSL_LIBS="-lssl -lcrypto" |
|
84
|
found=true |
|
85
|
AC_MSG_RESULT([yes]) |
|
86
|
break |
|
87
|
else |
|
88
|
AC_MSG_RESULT([no]) |
|
89
|
fi |
|
90
|
done |
|
91
|
|
|
92
|
# if the file wasn't found, well, go ahead and try the link anyway -- maybe |
|
93
|
# it will just work! |
|
94
|
fi |
|
95
|
|
|
96
|
# try the preprocessor and linker with our new flags, |
|
97
|
# being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS |
|
98
|
|
|
99
|
AC_MSG_CHECKING([whether compiling and linking against OpenSSL works]) |
|
100
|
echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \ |
|
101
|
"OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&AS_MESSAGE_LOG_FD |
|
102
|
|
|
103
|
save_LIBS="$LIBS" |
|
104
|
save_LDFLAGS="$LDFLAGS" |
|
105
|
save_CPPFLAGS="$CPPFLAGS" |
|
106
|
LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS" |
|
107
|
LIBS="$OPENSSL_LIBS $LIBS" |
|
108
|
CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS" |
|
109
|
AC_LINK_IFELSE( |
|
110
|
AC_LANG_PROGRAM([#include <openssl/ssl.h>], [SSL_new(NULL)]), |
|
111
|
[ |
|
112
|
AC_MSG_RESULT([yes]) |
|
113
|
$1 |
|
114
|
], [ |
|
115
|
AC_MSG_RESULT([no]) |
|
116
|
$2 |
|
117
|
]) |
|
118
|
CPPFLAGS="$save_CPPFLAGS" |
|
119
|
LDFLAGS="$save_LDFLAGS" |
|
120
|
LIBS="$save_LIBS" |
|
121
|
|
|
122
|
AC_SUBST([OPENSSL_INCLUDES]) |
|
123
|
AC_SUBST([OPENSSL_LIBS]) |
|
124
|
AC_SUBST([OPENSSL_LDFLAGS]) |
|
125
|
]) |
|
126
|
|