xref: /curl/m4/curl-wolfssl.m4 (revision e244d500)
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23#***************************************************************************
24
25AC_DEFUN([CURL_WITH_WOLFSSL], [
26dnl ----------------------------------------------------
27dnl check for wolfSSL
28dnl ----------------------------------------------------
29
30case "$OPT_WOLFSSL" in
31  yes|no)
32    wolfpkg=""
33    ;;
34  *)
35    wolfpkg="$withval/lib/pkgconfig"
36    ;;
37esac
38
39if test "x$OPT_WOLFSSL" != xno; then
40  _cppflags=$CPPFLAGS
41  _ldflags=$LDFLAGS
42  _ldflagspc=$LDFLAGSPC
43
44  ssl_msg=
45
46  if test X"$OPT_WOLFSSL" != Xno; then
47
48    if test "$OPT_WOLFSSL" = "yes"; then
49      OPT_WOLFSSL=""
50    fi
51
52    dnl try pkg-config magic
53    CURL_CHECK_PKGCONFIG(wolfssl, [$wolfpkg])
54    AC_MSG_NOTICE([Check dir $wolfpkg])
55
56    addld=""
57    addlib=""
58    addcflags=""
59    if test "$PKGCONFIG" != "no" ; then
60      addlib=`CURL_EXPORT_PCDIR([$wolfpkg])
61        $PKGCONFIG --libs-only-l wolfssl`
62      addld=`CURL_EXPORT_PCDIR([$wolfpkg])
63        $PKGCONFIG --libs-only-L wolfssl`
64      addcflags=`CURL_EXPORT_PCDIR([$wolfpkg])
65        $PKGCONFIG --cflags-only-I wolfssl`
66      version=`CURL_EXPORT_PCDIR([$wolfpkg])
67        $PKGCONFIG --modversion wolfssl`
68      wolfssllibpath=`echo $addld | $SED -e 's/^-L//'`
69    else
70      addlib=-lwolfssl
71      dnl use system defaults if user does not supply a path
72      if test -n "$OPT_WOLFSSL"; then
73        addld=-L$OPT_WOLFSSL/lib$libsuff
74        addcflags=-I$OPT_WOLFSSL/include
75        wolfssllibpath=$OPT_WOLFSSL/lib$libsuff
76      fi
77    fi
78
79    if test "x$USE_WOLFSSL" != "xyes"; then
80
81      LDFLAGS="$LDFLAGS $addld"
82      LDFLAGSPC="$LDFLAGSPC $addld"
83      AC_MSG_NOTICE([Add $addld to LDFLAGS])
84      if test "$addcflags" != "-I/usr/include"; then
85        CPPFLAGS="$CPPFLAGS $addcflags"
86        AC_MSG_NOTICE([Add $addcflags to CPPFLAGS])
87      fi
88
89      my_ac_save_LIBS="$LIBS"
90      LIBS="$addlib $LIBS"
91      AC_MSG_NOTICE([Add $addlib to LIBS])
92
93      AC_MSG_CHECKING([for wolfSSL_Init in -lwolfssl])
94      AC_LINK_IFELSE([
95        AC_LANG_PROGRAM([[
96          /* These are not needed for detection and confuse wolfSSL.
97             They are set up properly later if it is detected.  */
98          #undef SIZEOF_LONG
99          #undef SIZEOF_LONG_LONG
100          #include <wolfssl/options.h>
101          #include <wolfssl/ssl.h>
102        ]],[[
103          return wolfSSL_Init();
104        ]])
105      ],[
106        AC_MSG_RESULT(yes)
107        AC_DEFINE(USE_WOLFSSL, 1, [if wolfSSL is enabled])
108        AC_SUBST(USE_WOLFSSL, [1])
109        WOLFSSL_ENABLED=1
110        USE_WOLFSSL="yes"
111        ssl_msg="wolfSSL"
112        QUIC_ENABLED=yes
113        test wolfssl != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
114      ],
115      [
116        AC_MSG_RESULT(no)
117        CPPFLAGS=$_cppflags
118        LDFLAGS=$_ldflags
119        LDFLAGSPC=$_ldflagspc
120        wolfssllibpath=""
121      ])
122      LIBS="$my_ac_save_LIBS"
123    fi
124
125    if test "x$USE_WOLFSSL" = "xyes"; then
126      AC_MSG_NOTICE([detected wolfSSL])
127      check_for_ca_bundle=1
128
129      dnl wolfssl/ctaocrypt/types.h needs SIZEOF_LONG_LONG defined!
130      CURL_SIZEOF(long long)
131
132      LIBS="$addlib -lm $LIBS"
133
134      dnl wolfSSL needs configure --enable-opensslextra to have *get_peer*
135      dnl DES* is needed for NTLM support and lives in the OpenSSL compatibility
136      dnl layer
137      AC_CHECK_FUNCS(wolfSSL_get_peer_certificate \
138                     wolfSSL_UseALPN )
139
140      dnl if this symbol is present, we want the include path to include the
141      dnl OpenSSL API root as well
142      AC_CHECK_FUNC(wolfSSL_DES_ecb_encrypt,
143        [
144          AC_DEFINE(HAVE_WOLFSSL_DES_ECB_ENCRYPT, 1,
145                    [if you have wolfSSL_DES_ecb_encrypt])
146          WOLFSSL_NTLM=1
147        ]
148        )
149
150      dnl if this symbol is present, we can make use of BIO filter chains
151      AC_CHECK_FUNC(wolfSSL_BIO_new,
152        [
153          AC_DEFINE(HAVE_WOLFSSL_BIO, 1,
154                    [if you have wolfSSL_BIO_new])
155          WOLFSSL_BIO=1
156        ]
157        )
158      dnl if this symbol is present, we have the full BIO feature set
159      AC_CHECK_FUNC(wolfSSL_BIO_set_shutdown,
160        [
161          AC_DEFINE(HAVE_WOLFSSL_FULL_BIO, 1,
162                    [if you have wolfSSL_BIO_set_shutdown])
163          WOLFSSL_FULL_BIO=1
164        ]
165        )
166
167      if test -n "$wolfssllibpath"; then
168        dnl when shared libs were found in a path that the run-time
169        dnl linker doesn't search through, we need to add it to
170        dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
171        dnl due to this
172        if test "x$cross_compiling" != "xyes"; then
173          CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$wolfssllibpath"
174          export CURL_LIBRARY_PATH
175          AC_MSG_NOTICE([Added $wolfssllibpath to CURL_LIBRARY_PATH])
176        fi
177      fi
178      LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE wolfssl"
179    else
180      AC_MSG_ERROR([--with-wolfssl but wolfSSL was not found or doesn't work])
181    fi
182
183  fi dnl wolfSSL not disabled
184
185  test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
186fi
187
188])
189