quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

curl-rustls.m4 (6492B)


      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 
     25 AC_DEFUN([CURL_WITH_RUSTLS], [
     26 dnl ----------------------------------------------------
     27 dnl check for Rustls
     28 dnl ----------------------------------------------------
     29 
     30 if 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         if test "$curl_cv_apple" = 'yes'; then
     87           RUSTLS_LDFLAGS="-framework Security -framework Foundation"
     88         else
     89           RUSTLS_LDFLAGS="-lpthread -ldl -lm"
     90         fi
     91 
     92         LIB_RUSTLS="$PREFIX_RUSTLS/lib$libsuff"
     93         if test "$PREFIX_RUSTLS" != "/usr" ; then
     94           SSL_LDFLAGS="-L$LIB_RUSTLS $RUSTLS_LDFLAGS"
     95           SSL_CPPFLAGS="-I$PREFIX_RUSTLS/include"
     96         fi
     97 
     98         dnl we will verify AC_CHECK_LIB later on
     99         AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled])
    100         USE_RUSTLS="yes"
    101       fi
    102       ;;
    103   esac
    104 
    105   link_pkgconfig=''
    106 
    107   if test "$PKGTEST" = "yes"; then
    108 
    109     CURL_CHECK_PKGCONFIG(rustls, [$RUSTLS_PCDIR])
    110 
    111     if test "$PKGCONFIG" != "no" ; then
    112       SSL_LIBS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl
    113         $PKGCONFIG --libs-only-l --libs-only-other rustls 2>/dev/null`
    114 
    115       SSL_LDFLAGS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl
    116         $PKGCONFIG --libs-only-L rustls 2>/dev/null`
    117 
    118       SSL_CPPFLAGS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl
    119         $PKGCONFIG --cflags-only-I rustls 2>/dev/null`
    120 
    121       AC_MSG_NOTICE([pkg-config: SSL_LIBS: "$SSL_LIBS"])
    122       AC_MSG_NOTICE([pkg-config: SSL_LDFLAGS: "$SSL_LDFLAGS"])
    123       AC_MSG_NOTICE([pkg-config: SSL_CPPFLAGS: "$SSL_CPPFLAGS"])
    124 
    125       LIB_RUSTLS=`echo $SSL_LDFLAGS | sed -e 's/^-L//'`
    126 
    127       dnl use the values pkg-config reported.  This is here
    128       dnl instead of below with CPPFLAGS and LDFLAGS because we only
    129       dnl learn about this via pkg-config.  If we only have
    130       dnl the argument to --with-rustls we don't know what
    131       dnl additional libs may be necessary.  Hope that we
    132       dnl don't need any.
    133       LIBS="$SSL_LIBS $LIBS"
    134       link_pkgconfig=1
    135       ssl_msg="rustls"
    136       AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled])
    137       USE_RUSTLS="yes"
    138       RUSTLS_ENABLED=1
    139       test rustls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
    140     else
    141       AC_MSG_ERROR([pkg-config: Could not find Rustls])
    142     fi
    143 
    144   else
    145     dnl we did not use pkg-config, so we need to add the
    146     dnl Rustls lib to LIBS
    147     LIBS="-lrustls -lpthread -ldl -lm $LIBS"
    148   fi
    149 
    150   dnl finally, set flags to use this TLS backend
    151   CPPFLAGS="$CLEANCPPFLAGS $SSL_CPPFLAGS"
    152   LDFLAGS="$CLEANLDFLAGS $SSL_LDFLAGS"
    153   LDFLAGSPC="$CLEANLDFLAGSPC $SSL_LDFLAGS"
    154 
    155   if test "x$USE_RUSTLS" = "xyes"; then
    156     AC_MSG_NOTICE([detected Rustls])
    157     check_for_ca_bundle=1
    158 
    159     if test -n "$LIB_RUSTLS"; then
    160       dnl when shared libs were found in a path that the run-time
    161       dnl linker does not search through, we need to add it to
    162       dnl CURL_LIBRARY_PATH so that further configure tests do not
    163       dnl fail due to this
    164       if test "x$cross_compiling" != "xyes"; then
    165         CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$LIB_RUSTLS"
    166         export CURL_LIBRARY_PATH
    167         AC_MSG_NOTICE([Added $LIB_RUSTLS to CURL_LIBRARY_PATH])
    168       fi
    169     fi
    170     if test -n "$link_pkgconfig"; then
    171       LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE rustls"
    172     fi
    173 
    174     AC_CHECK_LIB(rustls, rustls_supported_hpke,
    175         [
    176         AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled])
    177         RUSTLS_ENABLED=1
    178         USE_RUSTLS="yes"
    179         ssl_msg="rustls"
    180         test rustls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
    181         ],
    182         AC_MSG_ERROR([--with-rustls was specified but could not find compatible Rustls.]),
    183         $RUSTLS_LDFLAGS)
    184   fi
    185 
    186   test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
    187 
    188   if test X"$OPT_RUSTLS" != Xno &&
    189     test "$RUSTLS_ENABLED" != "1"; then
    190     AC_MSG_NOTICE([OPT_RUSTLS: $OPT_RUSTLS])
    191     AC_MSG_NOTICE([RUSTLS_ENABLED: $RUSTLS_ENABLED])
    192     AC_MSG_ERROR([--with-rustls was given but Rustls could not be detected])
    193   fi
    194 fi
    195 ])
    196 
    197 RUSTLS_ENABLED