curl-gnutls.m4 5.2 KB

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