1*6236dae4SAndroid Build Coastguard Worker#*************************************************************************** 2*6236dae4SAndroid Build Coastguard Worker# _ _ ____ _ 3*6236dae4SAndroid Build Coastguard Worker# Project ___| | | | _ \| | 4*6236dae4SAndroid Build Coastguard Worker# / __| | | | |_) | | 5*6236dae4SAndroid Build Coastguard Worker# | (__| |_| | _ <| |___ 6*6236dae4SAndroid Build Coastguard Worker# \___|\___/|_| \_\_____| 7*6236dae4SAndroid Build Coastguard Worker# 8*6236dae4SAndroid Build Coastguard Worker# Copyright (C) Daniel Stenberg, <[email protected]>, et al. 9*6236dae4SAndroid Build Coastguard Worker# 10*6236dae4SAndroid Build Coastguard Worker# This software is licensed as described in the file COPYING, which 11*6236dae4SAndroid Build Coastguard Worker# you should have received as part of this distribution. The terms 12*6236dae4SAndroid Build Coastguard Worker# are also available at https://curl.se/docs/copyright.html. 13*6236dae4SAndroid Build Coastguard Worker# 14*6236dae4SAndroid Build Coastguard Worker# You may opt to use, copy, modify, merge, publish, distribute and/or sell 15*6236dae4SAndroid Build Coastguard Worker# copies of the Software, and permit persons to whom the Software is 16*6236dae4SAndroid Build Coastguard Worker# furnished to do so, under the terms of the COPYING file. 17*6236dae4SAndroid Build Coastguard Worker# 18*6236dae4SAndroid Build Coastguard Worker# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19*6236dae4SAndroid Build Coastguard Worker# KIND, either express or implied. 20*6236dae4SAndroid Build Coastguard Worker# 21*6236dae4SAndroid Build Coastguard Worker# SPDX-License-Identifier: curl 22*6236dae4SAndroid Build Coastguard Worker# 23*6236dae4SAndroid Build Coastguard Worker#*************************************************************************** 24*6236dae4SAndroid Build Coastguard Worker 25*6236dae4SAndroid Build Coastguard WorkerAC_DEFUN([CURL_WITH_RUSTLS], [ 26*6236dae4SAndroid Build Coastguard Workerdnl ---------------------------------------------------- 27*6236dae4SAndroid Build Coastguard Workerdnl check for Rustls 28*6236dae4SAndroid Build Coastguard Workerdnl ---------------------------------------------------- 29*6236dae4SAndroid Build Coastguard Worker 30*6236dae4SAndroid Build Coastguard Workerif test "x$OPT_RUSTLS" != xno; then 31*6236dae4SAndroid Build Coastguard Worker ssl_msg= 32*6236dae4SAndroid Build Coastguard Worker 33*6236dae4SAndroid Build Coastguard Worker dnl backup the pre-ssl variables 34*6236dae4SAndroid Build Coastguard Worker CLEANLDFLAGS="$LDFLAGS" 35*6236dae4SAndroid Build Coastguard Worker CLEANCPPFLAGS="$CPPFLAGS" 36*6236dae4SAndroid Build Coastguard Worker 37*6236dae4SAndroid Build Coastguard Worker ## NEW CODE 38*6236dae4SAndroid Build Coastguard Worker 39*6236dae4SAndroid Build Coastguard Worker dnl use pkg-config unless we have been given a path 40*6236dae4SAndroid Build Coastguard Worker dnl even then, try pkg-config first 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard Worker case "$OPT_RUSTLS" in 43*6236dae4SAndroid Build Coastguard Worker yes) 44*6236dae4SAndroid Build Coastguard Worker dnl --with-rustls (without path) used 45*6236dae4SAndroid Build Coastguard Worker PKGTEST="yes" 46*6236dae4SAndroid Build Coastguard Worker PREFIX_RUSTLS= 47*6236dae4SAndroid Build Coastguard Worker ;; 48*6236dae4SAndroid Build Coastguard Worker *) 49*6236dae4SAndroid Build Coastguard Worker dnl check the provided --with-rustls path 50*6236dae4SAndroid Build Coastguard Worker PKGTEST="no" 51*6236dae4SAndroid Build Coastguard Worker PREFIX_RUSTLS=$OPT_RUSTLS 52*6236dae4SAndroid Build Coastguard Worker 53*6236dae4SAndroid Build Coastguard Worker dnl Try pkg-config even when cross-compiling. Since we 54*6236dae4SAndroid Build Coastguard Worker dnl specify PKG_CONFIG_LIBDIR we are only looking where 55*6236dae4SAndroid Build Coastguard Worker dnl the user told us to look 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard Worker RUSTLS_PCDIR="$PREFIX_RUSTLS/lib/pkgconfig" 58*6236dae4SAndroid Build Coastguard Worker if test -f "$RUSTLS_PCDIR/rustls.pc"; then 59*6236dae4SAndroid Build Coastguard Worker AC_MSG_NOTICE([PKG_CONFIG_LIBDIR will be set to "$RUSTLS_PCDIR"]) 60*6236dae4SAndroid Build Coastguard Worker PKGTEST="yes" 61*6236dae4SAndroid Build Coastguard Worker fi 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker if test "$PKGTEST" != "yes"; then 64*6236dae4SAndroid Build Coastguard Worker # try lib64 instead 65*6236dae4SAndroid Build Coastguard Worker RUSTLS_PCDIR="$PREFIX_RUSTLS/lib64/pkgconfig" 66*6236dae4SAndroid Build Coastguard Worker if test -f "$RUSTLS_PCDIR/rustls.pc"; then 67*6236dae4SAndroid Build Coastguard Worker AC_MSG_NOTICE([PKG_CONFIG_LIBDIR will be set to "$RUSTLS_PCDIR"]) 68*6236dae4SAndroid Build Coastguard Worker PKGTEST="yes" 69*6236dae4SAndroid Build Coastguard Worker fi 70*6236dae4SAndroid Build Coastguard Worker fi 71*6236dae4SAndroid Build Coastguard Worker 72*6236dae4SAndroid Build Coastguard Worker if test "$PKGTEST" != "yes"; then 73*6236dae4SAndroid Build Coastguard Worker dnl pkg-config came up empty, use what we got 74*6236dae4SAndroid Build Coastguard Worker dnl via --with-rustls 75*6236dae4SAndroid Build Coastguard Worker 76*6236dae4SAndroid Build Coastguard Worker addld=-L$PREFIX_RUSTLS/lib$libsuff 77*6236dae4SAndroid Build Coastguard Worker addcflags=-I$PREFIX_RUSTLS/include 78*6236dae4SAndroid Build Coastguard Worker 79*6236dae4SAndroid Build Coastguard Worker LDFLAGS="$LDFLAGS $addld" 80*6236dae4SAndroid Build Coastguard Worker if test "$addcflags" != "-I/usr/include"; then 81*6236dae4SAndroid Build Coastguard Worker CPPFLAGS="$CPPFLAGS $addcflags" 82*6236dae4SAndroid Build Coastguard Worker fi 83*6236dae4SAndroid Build Coastguard Worker 84*6236dae4SAndroid Build Coastguard Worker case $host in 85*6236dae4SAndroid Build Coastguard Worker *-apple-*) 86*6236dae4SAndroid Build Coastguard Worker RUSTLS_LDFLAGS="-framework Security -framework Foundation" 87*6236dae4SAndroid Build Coastguard Worker ;; 88*6236dae4SAndroid Build Coastguard Worker *) 89*6236dae4SAndroid Build Coastguard Worker RUSTLS_LDFLAGS="-lpthread -ldl -lm" 90*6236dae4SAndroid Build Coastguard Worker ;; 91*6236dae4SAndroid Build Coastguard Worker esac 92*6236dae4SAndroid Build Coastguard Worker AC_CHECK_LIB(rustls, rustls_connection_read, 93*6236dae4SAndroid Build Coastguard Worker [ 94*6236dae4SAndroid Build Coastguard Worker AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled]) 95*6236dae4SAndroid Build Coastguard Worker AC_SUBST(USE_RUSTLS, [1]) 96*6236dae4SAndroid Build Coastguard Worker RUSTLS_ENABLED=1 97*6236dae4SAndroid Build Coastguard Worker USE_RUSTLS="yes" 98*6236dae4SAndroid Build Coastguard Worker ssl_msg="rustls" 99*6236dae4SAndroid Build Coastguard Worker test rustls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes 100*6236dae4SAndroid Build Coastguard Worker ], 101*6236dae4SAndroid Build Coastguard Worker AC_MSG_ERROR([--with-rustls was specified but could not find Rustls.]), 102*6236dae4SAndroid Build Coastguard Worker $RUSTLS_LDFLAGS) 103*6236dae4SAndroid Build Coastguard Worker 104*6236dae4SAndroid Build Coastguard Worker LIB_RUSTLS="$PREFIX_RUSTLS/lib$libsuff" 105*6236dae4SAndroid Build Coastguard Worker if test "$PREFIX_RUSTLS" != "/usr" ; then 106*6236dae4SAndroid Build Coastguard Worker SSL_LDFLAGS="-L$LIB_RUSTLS $RUSTLS_LDFLAGS" 107*6236dae4SAndroid Build Coastguard Worker SSL_CPPFLAGS="-I$PREFIX_RUSTLS/include" 108*6236dae4SAndroid Build Coastguard Worker fi 109*6236dae4SAndroid Build Coastguard Worker fi 110*6236dae4SAndroid Build Coastguard Worker ;; 111*6236dae4SAndroid Build Coastguard Worker esac 112*6236dae4SAndroid Build Coastguard Worker 113*6236dae4SAndroid Build Coastguard Worker if test "$PKGTEST" = "yes"; then 114*6236dae4SAndroid Build Coastguard Worker 115*6236dae4SAndroid Build Coastguard Worker CURL_CHECK_PKGCONFIG(rustls, [$RUSTLS_PCDIR]) 116*6236dae4SAndroid Build Coastguard Worker 117*6236dae4SAndroid Build Coastguard Worker if test "$PKGCONFIG" != "no" ; then 118*6236dae4SAndroid Build Coastguard Worker SSL_LIBS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl 119*6236dae4SAndroid Build Coastguard Worker $PKGCONFIG --libs-only-l --libs-only-other rustls 2>/dev/null` 120*6236dae4SAndroid Build Coastguard Worker 121*6236dae4SAndroid Build Coastguard Worker SSL_LDFLAGS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl 122*6236dae4SAndroid Build Coastguard Worker $PKGCONFIG --libs-only-L rustls 2>/dev/null` 123*6236dae4SAndroid Build Coastguard Worker 124*6236dae4SAndroid Build Coastguard Worker SSL_CPPFLAGS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl 125*6236dae4SAndroid Build Coastguard Worker $PKGCONFIG --cflags-only-I rustls 2>/dev/null` 126*6236dae4SAndroid Build Coastguard Worker 127*6236dae4SAndroid Build Coastguard Worker AC_SUBST(SSL_LIBS) 128*6236dae4SAndroid Build Coastguard Worker AC_MSG_NOTICE([pkg-config: SSL_LIBS: "$SSL_LIBS"]) 129*6236dae4SAndroid Build Coastguard Worker AC_MSG_NOTICE([pkg-config: SSL_LDFLAGS: "$SSL_LDFLAGS"]) 130*6236dae4SAndroid Build Coastguard Worker AC_MSG_NOTICE([pkg-config: SSL_CPPFLAGS: "$SSL_CPPFLAGS"]) 131*6236dae4SAndroid Build Coastguard Worker 132*6236dae4SAndroid Build Coastguard Worker LIB_RUSTLS=`echo $SSL_LDFLAGS | sed -e 's/^-L//'` 133*6236dae4SAndroid Build Coastguard Worker 134*6236dae4SAndroid Build Coastguard Worker dnl use the values pkg-config reported. This is here 135*6236dae4SAndroid Build Coastguard Worker dnl instead of below with CPPFLAGS and LDFLAGS because we only 136*6236dae4SAndroid Build Coastguard Worker dnl learn about this via pkg-config. If we only have 137*6236dae4SAndroid Build Coastguard Worker dnl the argument to --with-rustls we don't know what 138*6236dae4SAndroid Build Coastguard Worker dnl additional libs may be necessary. Hope that we 139*6236dae4SAndroid Build Coastguard Worker dnl don't need any. 140*6236dae4SAndroid Build Coastguard Worker LIBS="$SSL_LIBS $LIBS" 141*6236dae4SAndroid Build Coastguard Worker ssl_msg="rustls" 142*6236dae4SAndroid Build Coastguard Worker AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled]) 143*6236dae4SAndroid Build Coastguard Worker AC_SUBST(USE_RUSTLS, [1]) 144*6236dae4SAndroid Build Coastguard Worker USE_RUSTLS="yes" 145*6236dae4SAndroid Build Coastguard Worker RUSTLS_ENABLED=1 146*6236dae4SAndroid Build Coastguard Worker test rustls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes 147*6236dae4SAndroid Build Coastguard Worker else 148*6236dae4SAndroid Build Coastguard Worker AC_MSG_ERROR([pkg-config: Could not find Rustls]) 149*6236dae4SAndroid Build Coastguard Worker fi 150*6236dae4SAndroid Build Coastguard Worker 151*6236dae4SAndroid Build Coastguard Worker else 152*6236dae4SAndroid Build Coastguard Worker dnl we did not use pkg-config, so we need to add the 153*6236dae4SAndroid Build Coastguard Worker dnl Rustls lib to LIBS 154*6236dae4SAndroid Build Coastguard Worker LIBS="-lrustls -lpthread -ldl -lm $LIBS" 155*6236dae4SAndroid Build Coastguard Worker fi 156*6236dae4SAndroid Build Coastguard Worker 157*6236dae4SAndroid Build Coastguard Worker dnl finally, set flags to use this TLS backend 158*6236dae4SAndroid Build Coastguard Worker CPPFLAGS="$CLEAN_CPPFLAGS $SSL_CPPFLAGS" 159*6236dae4SAndroid Build Coastguard Worker LDFLAGS="$CLAN_LDFLAGS $SSL_LDFLAGS" 160*6236dae4SAndroid Build Coastguard Worker 161*6236dae4SAndroid Build Coastguard Worker if test "x$USE_RUSTLS" = "xyes"; then 162*6236dae4SAndroid Build Coastguard Worker AC_MSG_NOTICE([detected Rustls]) 163*6236dae4SAndroid Build Coastguard Worker check_for_ca_bundle=1 164*6236dae4SAndroid Build Coastguard Worker 165*6236dae4SAndroid Build Coastguard Worker if test -n "$LIB_RUSTLS"; then 166*6236dae4SAndroid Build Coastguard Worker dnl when shared libs were found in a path that the run-time 167*6236dae4SAndroid Build Coastguard Worker dnl linker does not search through, we need to add it to 168*6236dae4SAndroid Build Coastguard Worker dnl CURL_LIBRARY_PATH so that further configure tests do not 169*6236dae4SAndroid Build Coastguard Worker dnl fail due to this 170*6236dae4SAndroid Build Coastguard Worker if test "x$cross_compiling" != "xyes"; then 171*6236dae4SAndroid Build Coastguard Worker CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$LIB_RUSTLS" 172*6236dae4SAndroid Build Coastguard Worker export CURL_LIBRARY_PATH 173*6236dae4SAndroid Build Coastguard Worker AC_MSG_NOTICE([Added $LIB_RUSTLS to CURL_LIBRARY_PATH]) 174*6236dae4SAndroid Build Coastguard Worker fi 175*6236dae4SAndroid Build Coastguard Worker fi 176*6236dae4SAndroid Build Coastguard Worker LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE rustls" 177*6236dae4SAndroid Build Coastguard Worker fi 178*6236dae4SAndroid Build Coastguard Worker 179*6236dae4SAndroid Build Coastguard Worker test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg" 180*6236dae4SAndroid Build Coastguard Worker 181*6236dae4SAndroid Build Coastguard Worker if test X"$OPT_RUSTLS" != Xno && 182*6236dae4SAndroid Build Coastguard Worker test "$RUSTLS_ENABLED" != "1"; then 183*6236dae4SAndroid Build Coastguard Worker AC_MSG_NOTICE([OPT_RUSTLS: $OPT_RUSTLS]) 184*6236dae4SAndroid Build Coastguard Worker AC_MSG_NOTICE([RUSTLS_ENABLED: $RUSTLS_ENABLED]) 185*6236dae4SAndroid Build Coastguard Worker AC_MSG_ERROR([--with-rustls was given but Rustls could not be detected]) 186*6236dae4SAndroid Build Coastguard Worker fi 187*6236dae4SAndroid Build Coastguard Workerfi 188*6236dae4SAndroid Build Coastguard Worker]) 189*6236dae4SAndroid Build Coastguard Worker 190*6236dae4SAndroid Build Coastguard WorkerRUSTLS_ENABLED 191