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