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