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