~iheino+ub/+junk/nut-upsconf-docfix

« back to all changes in this revision

Viewing changes to m4/nut_check_libopenssl.m4

  • Committer: Tuomas Heino
  • Author(s): Laurent Bigonville
  • Date: 2014-04-22 20:46:12 UTC
  • Revision ID: iheino+ub@cc.hut.fi-20140422204612-1x2gh3nkezfsdao4
Tags: upstream-2.7.2
ImportĀ upstreamĀ versionĀ 2.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl Check for OpenSSL (LIBOPENSSL) compiler flags. On success, set 
 
2
dnl nut_have_openssl="yes" and nut_ssl_lib="OpenSSL", and define WITH_SSL,
 
3
dnl WITH_OPENSSL, LIBSSL_CFLAGS and LIBSSL_LIBS. On failure, set
 
4
dnl nut_have_libssl="no".
 
5
dnl This macro can be run multiple times, but will do the checking only once. 
 
6
 
 
7
AC_DEFUN([NUT_CHECK_LIBOPENSSL], 
 
8
[
 
9
if test -z "${nut_have_libopenssl_seen}"; then
 
10
        nut_have_libopenssl_seen=yes
 
11
 
 
12
        dnl save CFLAGS and LIBS
 
13
        CFLAGS_ORIG="${CFLAGS}"
 
14
        LIBS_ORIG="${LIBS}"
 
15
 
 
16
        AC_MSG_CHECKING(for OpenSSL version via pkg-config)
 
17
        OPENSSL_VERSION="`pkg-config --silence-errors --modversion openssl 2>/dev/null`"
 
18
        if test "$?" = "0" -a -n "${OPENSSL_VERSION}"; then
 
19
                CFLAGS="`pkg-config --silence-errors --cflags openssl 2>/dev/null`"
 
20
                LIBS="`pkg-config --silence-errors --libs openssl 2>/dev/null`"
 
21
        else
 
22
                OPENSSL_VERSION="none"
 
23
                CFLAGS=""
 
24
                LIBS="-lssl -lcrypto"
 
25
        fi
 
26
        AC_MSG_RESULT(${OPENSSL_VERSION} found)
 
27
 
 
28
        dnl allow overriding OpenSSL settings if the user knows best
 
29
        AC_MSG_CHECKING(for OpenSSL cflags)
 
30
        AC_ARG_WITH(openssl-includes,
 
31
                AS_HELP_STRING([@<:@--with-openssl-includes=CFLAGS@:>@], [include flags for the OpenSSL library]),
 
32
        [
 
33
                case "${withval}" in
 
34
                yes|no)
 
35
                        AC_MSG_ERROR(invalid option --with(out)-openssl-includes - see docs/configure.txt)
 
36
                        ;;
 
37
                *)
 
38
                        CFLAGS="${withval}"
 
39
                        ;;
 
40
                esac
 
41
        ], [])
 
42
        AC_MSG_RESULT([${CFLAGS}])
 
43
 
 
44
        AC_MSG_CHECKING(for OpenSSL ldflags)
 
45
        AC_ARG_WITH(openssl-libs,
 
46
                AS_HELP_STRING([@<:@--with-openssl-libs=LIBS@:>@], [linker flags for the OpenSSL library]),
 
47
        [
 
48
                case "${withval}" in
 
49
                yes|no)
 
50
                        AC_MSG_ERROR(invalid option --with(out)-openssl-libs - see docs/configure.txt)
 
51
                        ;;
 
52
                *)
 
53
                        LIBS="${withval}"
 
54
                        ;;
 
55
                esac
 
56
        ], [])
 
57
        AC_MSG_RESULT([${LIBS}])
 
58
 
 
59
        dnl check if openssl is usable
 
60
        AC_CHECK_HEADERS(openssl/ssl.h, [nut_have_openssl=yes], [nut_have_openssl=no], [AC_INCLUDES_DEFAULT])
 
61
        AC_CHECK_FUNCS(SSL_library_init, [], [nut_have_openssl=no])
 
62
 
 
63
        if test "${nut_have_openssl}" = "yes"; then
 
64
                nut_with_ssl="yes"
 
65
                nut_ssl_lib="(OpenSSL)"
 
66
                AC_DEFINE(WITH_SSL, 1, [Define to enable SSL support])
 
67
                AC_DEFINE(WITH_OPENSSL, 1, [Define to enable SSL support using OpenSSL])
 
68
                LIBSSL_CFLAGS="${CFLAGS}"
 
69
                LIBSSL_LIBS="${LIBS}"
 
70
        fi
 
71
 
 
72
        dnl restore original CFLAGS and LIBS
 
73
        CFLAGS="${CFLAGS_ORIG}"
 
74
        LIBS="${LIBS_ORIG}"
 
75
fi
 
76
])