2
0

curl-gnutls.m4 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. dnl ----------------------------------------------------
  25. dnl check for GnuTLS
  26. dnl ----------------------------------------------------
  27. AC_DEFUN([CURL_WITH_GNUTLS], [
  28. if test "x$OPT_GNUTLS" != xno; then
  29. ssl_msg=
  30. if test X"$OPT_GNUTLS" != Xno; then
  31. addld=""
  32. addlib=""
  33. gtlslib=""
  34. version=""
  35. addcflags=""
  36. if test "x$OPT_GNUTLS" = "xyes"; then
  37. dnl this is with no particular path given
  38. CURL_CHECK_PKGCONFIG(gnutls)
  39. if test "$PKGCONFIG" != "no" ; then
  40. addlib=`$PKGCONFIG --libs-only-l gnutls`
  41. addld=`$PKGCONFIG --libs-only-L gnutls`
  42. addcflags=`$PKGCONFIG --cflags-only-I gnutls`
  43. version=`$PKGCONFIG --modversion gnutls`
  44. gtlslib=`echo $addld | $SED -e 's/^-L//'`
  45. else
  46. dnl without pkg-config, we try libgnutls-config as that was how it
  47. dnl used to be done
  48. check=`libgnutls-config --version 2>/dev/null`
  49. if test -n "$check"; then
  50. addlib=`libgnutls-config --libs`
  51. addcflags=`libgnutls-config --cflags`
  52. version=`libgnutls-config --version`
  53. gtlslib=`libgnutls-config --prefix`/lib$libsuff
  54. fi
  55. fi
  56. else
  57. dnl this is with a given path, first check if there's a libgnutls-config
  58. dnl there and if not, make an educated guess
  59. cfg=$OPT_GNUTLS/bin/libgnutls-config
  60. check=`$cfg --version 2>/dev/null`
  61. if test -n "$check"; then
  62. addlib=`$cfg --libs`
  63. addcflags=`$cfg --cflags`
  64. version=`$cfg --version`
  65. gtlslib=`$cfg --prefix`/lib$libsuff
  66. else
  67. dnl without pkg-config and libgnutls-config, we guess a lot!
  68. addlib=-lgnutls
  69. addld=-L$OPT_GNUTLS/lib$libsuff
  70. addcflags=-I$OPT_GNUTLS/include
  71. version="" # we just don't know
  72. gtlslib=$OPT_GNUTLS/lib$libsuff
  73. fi
  74. fi
  75. if test -z "$version"; then
  76. dnl lots of efforts, still no go
  77. version="unknown"
  78. fi
  79. if test -n "$addlib"; then
  80. CLEANLIBS="$LIBS"
  81. CLEANCPPFLAGS="$CPPFLAGS"
  82. CLEANLDFLAGS="$LDFLAGS"
  83. CLEANLDFLAGSPC="$LDFLAGSPC"
  84. LIBS="$addlib $LIBS"
  85. LDFLAGS="$LDFLAGS $addld"
  86. LDFLAGSPC="$LDFLAGSPC $addld"
  87. if test "$addcflags" != "-I/usr/include"; then
  88. CPPFLAGS="$CPPFLAGS $addcflags"
  89. fi
  90. dnl this function is selected since it was introduced in 3.1.10
  91. AC_CHECK_LIB(gnutls, gnutls_x509_crt_get_dn2,
  92. [
  93. AC_DEFINE(USE_GNUTLS, 1, [if GnuTLS is enabled])
  94. AC_SUBST(USE_GNUTLS, [1])
  95. GNUTLS_ENABLED=1
  96. USE_GNUTLS="yes"
  97. ssl_msg="GnuTLS"
  98. QUIC_ENABLED=yes
  99. test gnutls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
  100. ],
  101. [
  102. LIBS="$CLEANLIBS"
  103. CPPFLAGS="$CLEANCPPFLAGS"
  104. ])
  105. if test "x$USE_GNUTLS" = "xyes"; then
  106. AC_MSG_NOTICE([detected GnuTLS version $version])
  107. check_for_ca_bundle=1
  108. if test -n "$gtlslib"; then
  109. dnl when shared libs were found in a path that the run-time
  110. dnl linker doesn't search through, we need to add it to
  111. dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
  112. dnl due to this
  113. if test "x$cross_compiling" != "xyes"; then
  114. CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$gtlslib"
  115. export CURL_LIBRARY_PATH
  116. AC_MSG_NOTICE([Added $gtlslib to CURL_LIBRARY_PATH])
  117. fi
  118. fi
  119. LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE gnutls nettle"
  120. fi
  121. fi
  122. fi dnl GNUTLS not disabled
  123. test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
  124. fi
  125. dnl ---
  126. dnl Check which crypto backend GnuTLS uses
  127. dnl ---
  128. if test "$GNUTLS_ENABLED" = "1"; then
  129. USE_GNUTLS_NETTLE=
  130. # First check if we can detect either crypto library via transitive linking
  131. AC_CHECK_LIB(gnutls, nettle_MD5Init, [ USE_GNUTLS_NETTLE=1 ])
  132. # If not, try linking directly to both of them to see if they are available
  133. if test "$USE_GNUTLS_NETTLE" = ""; then
  134. AC_CHECK_LIB(nettle, nettle_MD5Init, [ USE_GNUTLS_NETTLE=1 ])
  135. fi
  136. if test "$USE_GNUTLS_NETTLE" = ""; then
  137. AC_MSG_ERROR([GnuTLS found, but nettle was not found])
  138. fi
  139. LIBS="-lnettle $LIBS"
  140. fi
  141. dnl ---
  142. dnl We require GnuTLS with SRP support.
  143. dnl ---
  144. if test "$GNUTLS_ENABLED" = "1"; then
  145. AC_CHECK_LIB(gnutls, gnutls_srp_verifier,
  146. [
  147. AC_DEFINE(HAVE_GNUTLS_SRP, 1, [if you have the function gnutls_srp_verifier])
  148. AC_SUBST(HAVE_GNUTLS_SRP, [1])
  149. ])
  150. fi
  151. ])