Update code to work with OpenSSL 1.1
[nsca-ng.git] / m4 / openssl.m4
bloba429a52d2defdde21b5365c15b123db2f232dd31
1 # Copyright (c) 2013 Holger Weiss <holger@weiss.in-berlin.de>
2 # All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
7 # 1. Redistributions of source code must retain the above copyright notice, this
8 #    list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright notice,
11 #    this list of conditions and the following disclaimer in the documentation
12 #    and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 # DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 # NSCA_LIB_OPENSSL
26 # ----------------
27 # Check the availability of OpenSSL 1.0.0 or newer.  As this is a required
28 # dependency, we bail out if the user specified "--without-openssl", if we fail
29 # to link against the library, or if the OpenSSL version we found is too old.
30 # On success, we set the output variables SSLCPPFLAGS, SSLLDFLAGS, and SSLLIBS
31 # to appropriate values.  (Why are there no underscores in these variable names?
32 # Because Automake treats names like "foo_CPPFLAGS" specially.)
33 AC_DEFUN([NSCA_LIB_OPENSSL],
35   nsca_save_CPPFLAGS=$CPPFLAGS
36   nsca_save_LDFLAGS=$LDFLAGS
37   AC_ARG_WITH([openssl],
38     [AS_HELP_STRING([--with-openssl=PATH],
39       [use the OpenSSL library in PATH])],
40     [nsca_ssl_dir=$with_openssl],
41     [nsca_ssl_dir=yes])
42   AC_MSG_CHECKING([whether OpenSSL is desired])
43   AS_CASE([$nsca_ssl_dir],
44     [no],
45       [AC_MSG_RESULT([no])
46        AC_MSG_ERROR([building without OpenSSL is not supported])],
47     [yes],
48       [AC_MSG_RESULT([yes])
49        AC_MSG_CHECKING([for the location of OpenSSL])
50        nsca_ssl_dir=unknown
51        for _nsca_ssl_dir in "$ac_pwd/lib/ssl" /usr /usr/local /usr/local/ssl \
52          /usr/pkg
53        do dnl Solaris 10 doesn't have "test -e".
54          AS_IF([test -r "$_nsca_ssl_dir/include/openssl/ssl.h"],
55            [nsca_ssl_dir=$_nsca_ssl_dir
56             break])
57        done
58       AS_IF([test "x$nsca_ssl_dir" != xunknown],
59         [AC_MSG_RESULT([$nsca_ssl_dir])],
60         [AC_MSG_RESULT([not found, continuing anyway])])],
61     [AC_MSG_RESULT([yes])])
62   AS_IF([test "x$nsca_ssl_dir" != xunknown && test "x$nsca_ssl_dir" != x/usr],
63     [SSLCPPFLAGS="-I$nsca_ssl_dir/include"
64      SSLLDFLAGS="-L$nsca_ssl_dir/lib"
65      CPPFLAGS="$SSLCPPFLAGS $CPPFLAGS"
66      LDFLAGS="$SSLLDFLAGS $LDFLAGS"])
67   AC_CHECK_HEADER([openssl/ssl.h], [],
68     [AC_MSG_ERROR([OpenSSL header files not found])])
69   AC_CHECK_LIB([crypto], [BIO_new],
70     [AC_CHECK_LIB([crypto], [DSO_load],
71       [SSLLIBS='-lcrypto'],
72       [AC_CHECK_LIB([dl], [DSO_load],
73         [SSLLIBS='-lcrypto -ldl'],
74         [AC_MSG_FAILURE([cannot link with OpenSSL])],
75         [-lcrypto -ldl])])],
76     [AC_MSG_FAILURE([cannot link with OpenSSL])])
77   AC_CHECK_LIB([ssl], [SSL_new],
78     [SSLLIBS="-lssl $SSLLIBS"],
79     [AC_MSG_FAILURE([cannot link with OpenSSL])],
80     [$SSLLIBS])
81   AC_CHECK_LIB([ssl], [SSL_get_psk_identity], [:],
82     [AC_MSG_ERROR([OpenSSL too old, version 1.0.0 or newer is required])],
83     [$SSLLIBS])
84   AC_SUBST([SSLCPPFLAGS])
85   AC_SUBST([SSLLDFLAGS])
86   AC_SUBST([SSLLIBS])
87   CPPFLAGS=$nsca_save_CPPFLAGS
88   LDFLAGS=$nsca_save_LDFLAGS
89 ])# NSCA_LIB_OPENSSL
91 dnl vim:set joinspaces textwidth=80: