• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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        BEARSSL_ENABLED=1
50        USE_BEARSSL="yes"
51        ssl_msg="BearSSL"
52        test bearssl != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
53      ], [], -lbearssl)
54    fi
55
56    addld=""
57    addlib=""
58    addcflags=""
59    bearssllib=""
60
61    if test "x$USE_BEARSSL" != "xyes"; then
62      dnl add the path and test again
63      addld=-L$OPT_BEARSSL/lib$libsuff
64      addcflags=-I$OPT_BEARSSL/include
65      bearssllib=$OPT_BEARSSL/lib$libsuff
66
67      LDFLAGS="$LDFLAGS $addld"
68      LDFLAGSPC="$LDFLAGSPC $addld"
69      if test "$addcflags" != "-I/usr/include"; then
70        CPPFLAGS="$CPPFLAGS $addcflags"
71      fi
72
73      AC_CHECK_LIB(bearssl, br_ssl_client_init_full,
74        [
75        AC_DEFINE(USE_BEARSSL, 1, [if BearSSL is enabled])
76        BEARSSL_ENABLED=1
77        USE_BEARSSL="yes"
78        ssl_msg="BearSSL"
79        test bearssl != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
80        ],
81        [
82          CPPFLAGS=$_cppflags
83          LDFLAGS=$_ldflags
84          LDFLAGSPC=$_ldflagspc
85        ], -lbearssl)
86    fi
87
88    if test "x$USE_BEARSSL" = "xyes"; then
89      AC_MSG_NOTICE([detected BearSSL])
90      check_for_ca_bundle=1
91
92      LIBS="-lbearssl $LIBS"
93
94      if test -n "$bearssllib"; then
95        dnl when shared libs were found in a path that the run-time
96        dnl linker doesn't search through, we need to add it to
97        dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
98        dnl due to this
99        if test "x$cross_compiling" != "xyes"; then
100          CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$bearssllib"
101          export CURL_LIBRARY_PATH
102          AC_MSG_NOTICE([Added $bearssllib to CURL_LIBRARY_PATH])
103        fi
104      fi
105    fi
106
107  fi dnl BearSSL not disabled
108
109  test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
110fi
111])
112