curl-mbedtls.m4 3.4 KB

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