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_RUSTLS], [ 26dnl ---------------------------------------------------- 27dnl check for Rustls 28dnl ---------------------------------------------------- 29 30if test "x$OPT_RUSTLS" != xno; then 31 ssl_msg= 32 33 dnl backup the pre-ssl variables 34 CLEANLDFLAGS="$LDFLAGS" 35 CLEANCPPFLAGS="$CPPFLAGS" 36 37 ## NEW CODE 38 39 dnl use pkg-config unless we have been given a path 40 dnl even then, try pkg-config first 41 42 case "$OPT_RUSTLS" in 43 yes) 44 dnl --with-rustls (without path) used 45 PKGTEST="yes" 46 PREFIX_RUSTLS= 47 ;; 48 *) 49 dnl check the provided --with-rustls path 50 PKGTEST="no" 51 PREFIX_RUSTLS=$OPT_RUSTLS 52 53 dnl Try pkg-config even when cross-compiling. Since we 54 dnl specify PKG_CONFIG_LIBDIR we are only looking where 55 dnl the user told us to look 56 57 RUSTLS_PCDIR="$PREFIX_RUSTLS/lib/pkgconfig" 58 if test -f "$RUSTLS_PCDIR/rustls.pc"; then 59 AC_MSG_NOTICE([PKG_CONFIG_LIBDIR will be set to "$RUSTLS_PCDIR"]) 60 PKGTEST="yes" 61 fi 62 63 if test "$PKGTEST" != "yes"; then 64 # try lib64 instead 65 RUSTLS_PCDIR="$PREFIX_RUSTLS/lib64/pkgconfig" 66 if test -f "$RUSTLS_PCDIR/rustls.pc"; then 67 AC_MSG_NOTICE([PKG_CONFIG_LIBDIR will be set to "$RUSTLS_PCDIR"]) 68 PKGTEST="yes" 69 fi 70 fi 71 72 if test "$PKGTEST" != "yes"; then 73 dnl pkg-config came up empty, use what we got 74 dnl via --with-rustls 75 76 addld=-L$PREFIX_RUSTLS/lib$libsuff 77 addcflags=-I$PREFIX_RUSTLS/include 78 79 LDFLAGS="$LDFLAGS $addld" 80 if test "$addcflags" != "-I/usr/include"; then 81 CPPFLAGS="$CPPFLAGS $addcflags" 82 fi 83 84 case $host in 85 *-apple-*) 86 RUSTLS_LDFLAGS="-framework Security -framework Foundation" 87 ;; 88 *) 89 RUSTLS_LDFLAGS="-lpthread -ldl -lm" 90 ;; 91 esac 92 AC_CHECK_LIB(rustls, rustls_connection_read, 93 [ 94 AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled]) 95 AC_SUBST(USE_RUSTLS, [1]) 96 RUSTLS_ENABLED=1 97 USE_RUSTLS="yes" 98 ssl_msg="rustls" 99 test rustls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes 100 ], 101 AC_MSG_ERROR([--with-rustls was specified but could not find Rustls.]), 102 $RUSTLS_LDFLAGS) 103 104 LIB_RUSTLS="$PREFIX_RUSTLS/lib$libsuff" 105 if test "$PREFIX_RUSTLS" != "/usr" ; then 106 SSL_LDFLAGS="-L$LIB_RUSTLS $RUSTLS_LDFLAGS" 107 SSL_CPPFLAGS="-I$PREFIX_RUSTLS/include" 108 fi 109 fi 110 ;; 111 esac 112 113 if test "$PKGTEST" = "yes"; then 114 115 CURL_CHECK_PKGCONFIG(rustls, [$RUSTLS_PCDIR]) 116 117 if test "$PKGCONFIG" != "no" ; then 118 SSL_LIBS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl 119 $PKGCONFIG --libs-only-l --libs-only-other rustls 2>/dev/null` 120 121 SSL_LDFLAGS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl 122 $PKGCONFIG --libs-only-L rustls 2>/dev/null` 123 124 SSL_CPPFLAGS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl 125 $PKGCONFIG --cflags-only-I rustls 2>/dev/null` 126 127 AC_SUBST(SSL_LIBS) 128 AC_MSG_NOTICE([pkg-config: SSL_LIBS: "$SSL_LIBS"]) 129 AC_MSG_NOTICE([pkg-config: SSL_LDFLAGS: "$SSL_LDFLAGS"]) 130 AC_MSG_NOTICE([pkg-config: SSL_CPPFLAGS: "$SSL_CPPFLAGS"]) 131 132 LIB_RUSTLS=`echo $SSL_LDFLAGS | sed -e 's/^-L//'` 133 134 dnl use the values pkg-config reported. This is here 135 dnl instead of below with CPPFLAGS and LDFLAGS because we only 136 dnl learn about this via pkg-config. If we only have 137 dnl the argument to --with-rustls we don't know what 138 dnl additional libs may be necessary. Hope that we 139 dnl don't need any. 140 LIBS="$SSL_LIBS $LIBS" 141 ssl_msg="rustls" 142 AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled]) 143 AC_SUBST(USE_RUSTLS, [1]) 144 USE_RUSTLS="yes" 145 RUSTLS_ENABLED=1 146 test rustls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes 147 else 148 AC_MSG_ERROR([pkg-config: Could not find Rustls]) 149 fi 150 151 else 152 dnl we did not use pkg-config, so we need to add the 153 dnl Rustls lib to LIBS 154 LIBS="-lrustls -lpthread -ldl -lm $LIBS" 155 fi 156 157 dnl finally, set flags to use this TLS backend 158 CPPFLAGS="$CLEAN_CPPFLAGS $SSL_CPPFLAGS" 159 LDFLAGS="$CLAN_LDFLAGS $SSL_LDFLAGS" 160 161 if test "x$USE_RUSTLS" = "xyes"; then 162 AC_MSG_NOTICE([detected Rustls]) 163 check_for_ca_bundle=1 164 165 if test -n "$LIB_RUSTLS"; then 166 dnl when shared libs were found in a path that the run-time 167 dnl linker does not search through, we need to add it to 168 dnl CURL_LIBRARY_PATH so that further configure tests do not 169 dnl fail due to this 170 if test "x$cross_compiling" != "xyes"; then 171 CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$LIB_RUSTLS" 172 export CURL_LIBRARY_PATH 173 AC_MSG_NOTICE([Added $LIB_RUSTLS to CURL_LIBRARY_PATH]) 174 fi 175 fi 176 LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE rustls" 177 fi 178 179 test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg" 180 181 if test X"$OPT_RUSTLS" != Xno && 182 test "$RUSTLS_ENABLED" != "1"; then 183 AC_MSG_NOTICE([OPT_RUSTLS: $OPT_RUSTLS]) 184 AC_MSG_NOTICE([RUSTLS_ENABLED: $RUSTLS_ENABLED]) 185 AC_MSG_ERROR([--with-rustls was given but Rustls could not be detected]) 186 fi 187fi 188]) 189 190RUSTLS_ENABLED 191