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