• 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
23dnl ----------------------------------------------------
24dnl check for mbedTLS
25dnl ----------------------------------------------------
26AC_DEFUN([CURL_WITH_MBEDTLS], [
27
28if test "x$OPT_MBEDTLS" != xno; then
29  _cppflags=$CPPFLAGS
30  _ldflags=$LDFLAGS
31  ssl_msg=
32
33  if test X"$OPT_MBEDTLS" != Xno; then
34
35    if test "$OPT_MBEDTLS" = "yes"; then
36      OPT_MBEDTLS=""
37    fi
38
39    if test -z "$OPT_MBEDTLS" ; then
40      dnl check for lib first without setting any new path
41
42      AC_CHECK_LIB(mbedtls, mbedtls_havege_init,
43      dnl libmbedtls found, set the variable
44       [
45         AC_DEFINE(USE_MBEDTLS, 1, [if mbedTLS is enabled])
46         AC_SUBST(USE_MBEDTLS, [1])
47         MBEDTLS_ENABLED=1
48         USE_MBEDTLS="yes"
49         ssl_msg="mbedTLS"
50	 test mbedtls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
51        ], [], -lmbedx509 -lmbedcrypto)
52    fi
53
54    addld=""
55    addlib=""
56    addcflags=""
57    mbedtlslib=""
58
59    if test "x$USE_MBEDTLS" != "xyes"; then
60      dnl add the path and test again
61      addld=-L$OPT_MBEDTLS/lib$libsuff
62      addcflags=-I$OPT_MBEDTLS/include
63      mbedtlslib=$OPT_MBEDTLS/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(mbedtls, mbedtls_ssl_init,
71       [
72       AC_DEFINE(USE_MBEDTLS, 1, [if mbedTLS is enabled])
73       AC_SUBST(USE_MBEDTLS, [1])
74       MBEDTLS_ENABLED=1
75       USE_MBEDTLS="yes"
76       ssl_msg="mbedTLS"
77       test mbedtls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
78       ],
79       [
80         CPPFLAGS=$_cppflags
81         LDFLAGS=$_ldflags
82       ], -lmbedx509 -lmbedcrypto)
83    fi
84
85    if test "x$USE_MBEDTLS" = "xyes"; then
86      AC_MSG_NOTICE([detected mbedTLS])
87      check_for_ca_bundle=1
88
89      LIBS="-lmbedtls -lmbedx509 -lmbedcrypto $LIBS"
90
91      if test -n "$mbedtlslib"; 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:$mbedtlslib"
98          export CURL_LIBRARY_PATH
99          AC_MSG_NOTICE([Added $mbedtlslib to CURL_LIBRARY_PATH])
100        fi
101      fi
102    fi
103
104  fi dnl mbedTLS not disabled
105
106  test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
107fi
108
109])
110