curl-rustls.m4 6.0 KB

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