2
0

curl-rustls.m4 6.3 KB

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