2
0

curl-mbedtls.m4 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 mbedTLS
  26. dnl ----------------------------------------------------
  27. AC_DEFUN([CURL_WITH_MBEDTLS], [
  28. if test "x$OPT_MBEDTLS" != xno; then
  29. _cppflags=$CPPFLAGS
  30. _ldflags=$LDFLAGS
  31. _ldflagspc=$LDFLAGSPC
  32. ssl_msg=
  33. if test X"$OPT_MBEDTLS" != Xno; then
  34. if test "$OPT_MBEDTLS" = "yes"; then
  35. OPT_MBEDTLS=""
  36. fi
  37. if test -z "$OPT_MBEDTLS" ; then
  38. dnl check for lib first without setting any new path
  39. AC_CHECK_LIB(mbedtls, mbedtls_havege_init,
  40. dnl libmbedtls found, set the variable
  41. [
  42. AC_DEFINE(USE_MBEDTLS, 1, [if mbedTLS is enabled])
  43. AC_SUBST(USE_MBEDTLS, [1])
  44. MBEDTLS_ENABLED=1
  45. USE_MBEDTLS="yes"
  46. ssl_msg="mbedTLS"
  47. test mbedtls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
  48. ], [], -lmbedx509 -lmbedcrypto)
  49. fi
  50. addld=""
  51. addlib=""
  52. addcflags=""
  53. mbedtlslib=""
  54. if test "x$USE_MBEDTLS" != "xyes"; then
  55. dnl add the path and test again
  56. addld=-L$OPT_MBEDTLS/lib$libsuff
  57. addcflags=-I$OPT_MBEDTLS/include
  58. mbedtlslib=$OPT_MBEDTLS/lib$libsuff
  59. LDFLAGS="$LDFLAGS $addld"
  60. LDFLAGSPC="$LDFLAGSPC $addld"
  61. if test "$addcflags" != "-I/usr/include"; then
  62. CPPFLAGS="$CPPFLAGS $addcflags"
  63. fi
  64. AC_CHECK_LIB(mbedtls, mbedtls_ssl_init,
  65. [
  66. AC_DEFINE(USE_MBEDTLS, 1, [if mbedTLS is enabled])
  67. AC_SUBST(USE_MBEDTLS, [1])
  68. MBEDTLS_ENABLED=1
  69. USE_MBEDTLS="yes"
  70. ssl_msg="mbedTLS"
  71. test mbedtls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
  72. ],
  73. [
  74. CPPFLAGS=$_cppflags
  75. LDFLAGS=$_ldflags
  76. LDFLAGSPC=$_ldflagspc
  77. ], -lmbedx509 -lmbedcrypto)
  78. fi
  79. if test "x$USE_MBEDTLS" = "xyes"; then
  80. AC_MSG_NOTICE([detected mbedTLS])
  81. check_for_ca_bundle=1
  82. LIBS="-lmbedtls -lmbedx509 -lmbedcrypto $LIBS"
  83. if test -n "$mbedtlslib"; then
  84. dnl when shared libs were found in a path that the run-time
  85. dnl linker doesn't search through, we need to add it to
  86. dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
  87. dnl due to this
  88. if test "x$cross_compiling" != "xyes"; then
  89. CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$mbedtlslib"
  90. export CURL_LIBRARY_PATH
  91. AC_MSG_NOTICE([Added $mbedtlslib to CURL_LIBRARY_PATH])
  92. fi
  93. fi
  94. dnl FIXME: Enable when mbedTLS was detected via pkg-config
  95. if false; then
  96. LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE mbedtls"
  97. fi
  98. fi
  99. fi dnl mbedTLS not disabled
  100. test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
  101. fi
  102. ])