xref: /curl/m4/curl-bearssl.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_BEARSSL], [
26dnl ----------------------------------------------------
27dnl check for BearSSL
28dnl ----------------------------------------------------
29
30if test "x$OPT_BEARSSL" != xno; then
31  _cppflags=$CPPFLAGS
32  _ldflags=$LDFLAGS
33  _ldflagspc=$LDFLAGSPC
34  ssl_msg=
35
36  if test X"$OPT_BEARSSL" != Xno; then
37
38    if test "$OPT_BEARSSL" = "yes"; then
39      OPT_BEARSSL=""
40    fi
41
42    if test -z "$OPT_BEARSSL" ; then
43      dnl check for lib first without setting any new path
44
45      AC_CHECK_LIB(bearssl, br_ssl_client_init_full,
46      dnl libbearssl found, set the variable
47      [
48        AC_DEFINE(USE_BEARSSL, 1, [if BearSSL is enabled])
49        AC_SUBST(USE_BEARSSL, [1])
50        BEARSSL_ENABLED=1
51        USE_BEARSSL="yes"
52        ssl_msg="BearSSL"
53        test bearssl != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
54      ], [], -lbearssl)
55    fi
56
57    addld=""
58    addlib=""
59    addcflags=""
60    bearssllib=""
61
62    if test "x$USE_BEARSSL" != "xyes"; then
63      dnl add the path and test again
64      addld=-L$OPT_BEARSSL/lib$libsuff
65      addcflags=-I$OPT_BEARSSL/include
66      bearssllib=$OPT_BEARSSL/lib$libsuff
67
68      LDFLAGS="$LDFLAGS $addld"
69      LDFLAGSPC="$LDFLAGSPC $addld"
70      if test "$addcflags" != "-I/usr/include"; then
71        CPPFLAGS="$CPPFLAGS $addcflags"
72      fi
73
74      AC_CHECK_LIB(bearssl, br_ssl_client_init_full,
75        [
76        AC_DEFINE(USE_BEARSSL, 1, [if BearSSL is enabled])
77        AC_SUBST(USE_BEARSSL, [1])
78        BEARSSL_ENABLED=1
79        USE_BEARSSL="yes"
80        ssl_msg="BearSSL"
81        test bearssl != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
82        ],
83        [
84          CPPFLAGS=$_cppflags
85          LDFLAGS=$_ldflags
86          LDFLAGSPC=$_ldflagspc
87        ], -lbearssl)
88    fi
89
90    if test "x$USE_BEARSSL" = "xyes"; then
91      AC_MSG_NOTICE([detected BearSSL])
92      check_for_ca_bundle=1
93
94      LIBS="-lbearssl $LIBS"
95
96      if test -n "$bearssllib"; then
97        dnl when shared libs were found in a path that the run-time
98        dnl linker doesn't search through, we need to add it to
99        dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
100        dnl due to this
101        if test "x$cross_compiling" != "xyes"; then
102          CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$bearssllib"
103          export CURL_LIBRARY_PATH
104          AC_MSG_NOTICE([Added $bearssllib to CURL_LIBRARY_PATH])
105        fi
106      fi
107    fi
108
109  fi dnl BearSSL not disabled
110
111  test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
112fi
113])
114