curl-rustls.m4 6.3 KB

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