2
0

curl-gnutls.m4 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. LIBS="$addlib $LIBS"
  84. LDFLAGS="$LDFLAGS $addld"
  85. if test "$addcflags" != "-I/usr/include"; then
  86. CPPFLAGS="$CPPFLAGS $addcflags"
  87. fi
  88. dnl this function is selected since it was introduced in 3.1.10
  89. AC_CHECK_LIB(gnutls, gnutls_x509_crt_get_dn2,
  90. [
  91. AC_DEFINE(USE_GNUTLS, 1, [if GnuTLS is enabled])
  92. AC_SUBST(USE_GNUTLS, [1])
  93. GNUTLS_ENABLED=1
  94. USE_GNUTLS="yes"
  95. ssl_msg="GnuTLS"
  96. test gnutls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
  97. ],
  98. [
  99. LIBS="$CLEANLIBS"
  100. CPPFLAGS="$CLEANCPPFLAGS"
  101. ])
  102. if test "x$USE_GNUTLS" = "xyes"; then
  103. AC_MSG_NOTICE([detected GnuTLS version $version])
  104. check_for_ca_bundle=1
  105. if test -n "$gtlslib"; then
  106. dnl when shared libs were found in a path that the run-time
  107. dnl linker doesn't search through, we need to add it to
  108. dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
  109. dnl due to this
  110. if test "x$cross_compiling" != "xyes"; then
  111. CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$gtlslib"
  112. export CURL_LIBRARY_PATH
  113. AC_MSG_NOTICE([Added $gtlslib to CURL_LIBRARY_PATH])
  114. fi
  115. fi
  116. fi
  117. fi
  118. fi dnl GNUTLS not disabled
  119. test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
  120. fi
  121. dnl ---
  122. dnl Check which crypto backend GnuTLS uses
  123. dnl ---
  124. if test "$GNUTLS_ENABLED" = "1"; then
  125. USE_GNUTLS_NETTLE=
  126. # First check if we can detect either crypto library via transitive linking
  127. AC_CHECK_LIB(gnutls, nettle_MD5Init, [ USE_GNUTLS_NETTLE=1 ])
  128. # If not, try linking directly to both of them to see if they are available
  129. if test "$USE_GNUTLS_NETTLE" = ""; then
  130. AC_CHECK_LIB(nettle, nettle_MD5Init, [ USE_GNUTLS_NETTLE=1 ])
  131. fi
  132. if test "$USE_GNUTLS_NETTLE" = ""; then
  133. AC_MSG_ERROR([GnuTLS found, but nettle was not found])
  134. fi
  135. LIBS="-lnettle $LIBS"
  136. fi
  137. dnl ---
  138. dnl We require GnuTLS with SRP support.
  139. dnl ---
  140. if test "$GNUTLS_ENABLED" = "1"; then
  141. AC_CHECK_LIB(gnutls, gnutls_srp_verifier,
  142. [
  143. AC_DEFINE(HAVE_GNUTLS_SRP, 1, [if you have the function gnutls_srp_verifier])
  144. AC_SUBST(HAVE_GNUTLS_SRP, [1])
  145. ])
  146. fi
  147. ])