mhd_check_func.m4 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # SYNOPSIS
  2. #
  3. # MHD_CHECK_FUNC([FUNCTION_NAME],
  4. # [INCLUDES=AC_INCLUDES_DEFAULT], [CHECK_CODE],
  5. # [ACTION-IF-AVAILABLE], [ACTION-IF-NOT-AVAILABLE],
  6. # [ADDITIONAL_LIBS])
  7. #
  8. # DESCRIPTION
  9. #
  10. # This macro checks for presence of specific function by including
  11. # specified headers, checking for declaration of the function and then
  12. # compiling and linking CHECK_CODE.
  13. # This checks both declaration and presence in library.
  14. # If function is available then macro HAVE_function_name (the name
  15. # of the function conveted to all uppercase characters) is defined
  16. # automatically.
  17. # Unlike AC_CHECK_FUNCS macro, this macro do not produce false
  18. # negative result if function is declared with specific calling
  19. # conventions like __stdcall' or attribute like
  20. # __attribute__((__dllimport__)) and linker failing to build test
  21. # program due to the different calling conventions.
  22. # By using definition from provided headers, this macro ensures that
  23. # correct calling convention is used for detection.
  24. #
  25. # Example usage:
  26. #
  27. # MHD_CHECK_FUNC([memmem],
  28. # [[#include <string.h>]],
  29. # [const void *ptr = memmem("aa", 2, "a", 1); (void)ptr;],
  30. # [var_use_memmem='yes'], [var_use_memmem='no'])
  31. #
  32. # The cache variable used in check so if any test will not work
  33. # correctly on some platform, user may simply fix it by giving cache
  34. # variable in configure parameters, for example:
  35. #
  36. # ./configure mhd_cv_have_func_memmem=no
  37. #
  38. # This simplifies building from source on exotic platforms as patching
  39. # of configure.ac is not required to change the results of the tests.
  40. #
  41. # LICENSE
  42. #
  43. # Copyright (c) 2019-2023 Karlson2k (Evgeny Grin) <k2k@narod.ru>
  44. #
  45. # Copying and distribution of this file, with or without modification, are
  46. # permitted in any medium without royalty provided the copyright notice
  47. # and this notice are preserved. This file is offered as-is, without any
  48. # warranty.
  49. #serial 6
  50. AC_DEFUN([MHD_CHECK_FUNC],[dnl
  51. AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifblank, m4_ifnblank
  52. m4_newline([[# Expansion of $0 macro starts here]])
  53. AC_LANG_ASSERT([C])dnl
  54. m4_ifblank(m4_translit([$1],[()],[ ]), [m4_fatal([First macro argument must not be empty])])dnl
  55. m4_ifblank([$3], [m4_fatal([Third macro argument must not be empty])])dnl
  56. m4_bmatch(m4_normalize([$1]), [\s],dnl
  57. [m4_fatal([First macro argument must not contain whitespaces])])dnl
  58. m4_if(m4_index([$3], m4_normalize(m4_translit([$1],[()],[ ]))), [-1], dnl
  59. [m4_fatal([CHECK_CODE parameter (third macro argument) does not contain ']m4_normalize([$1])[' token])])dnl
  60. AS_VAR_PUSHDEF([decl_cv_Var],[ac_cv_have_decl_]m4_bpatsubst(_mhd_norm_expd(m4_translit([$1],[()],[ ])),[[^a-zA-Z0-9]],[_]))dnl
  61. AS_VAR_PUSHDEF([cv_Var],[mhd_cv_have_func_]m4_bpatsubst(_mhd_norm_expd(m4_translit([$1],[()],[ ])),[[^a-zA-Z0-9]],[_]))dnl
  62. AS_VAR_SET_IF([cv_Var],[],[AC_CHECK_DECL(_mhd_norm_expd([$1]),[],[cv_Var="no"],[$2])])
  63. AC_CACHE_CHECK([f][or function $1], [cv_Var],dnl
  64. [dnl
  65. m4_ifnblank([$6],[dnl
  66. mhd_check_func_SAVE_LIBS="$LIBS"
  67. LIBS="_mhd_norm_expd([$6]) $LIBS"
  68. ])dnl
  69. AC_LINK_IFELSE(
  70. [AC_LANG_SOURCE([
  71. m4_default_nblank([$2],[AC_INCLUDES_DEFAULT])
  72. [int main(void)
  73. {
  74. ]$3[
  75. return 0;
  76. }
  77. ]])
  78. ],
  79. [AS_VAR_SET([cv_Var],["yes"])],
  80. [AS_VAR_SET([cv_Var],["no"])]dnl
  81. )
  82. m4_ifnblank([$6],[dnl
  83. LIBS="${mhd_check_func_SAVE_LIBS}"
  84. AS_UNSET([mhd_check_func_SAVE_LIBS])
  85. ])dnl
  86. ],[AS_VAR_SET([cv_Var],["no"])]dnl
  87. )
  88. AS_VAR_IF([cv_Var], ["yes"],
  89. [AC_DEFINE([[HAVE_]]m4_bpatsubst(m4_toupper(_mhd_norm_expd(m4_translit([$1],[()],[ ]))),[[^A-Z0-9]],[_]),
  90. [1], [Define to 1 if you have the ']_mhd_norm_expd(m4_translit([$1],[()],[ ]))[' function.])
  91. m4_n([$4])dnl
  92. ],[$5])
  93. AS_VAR_POPDEF([cv_Var])dnl
  94. AS_VAR_POPDEF([decl_cv_Var])dnl
  95. m4_newline([[# Expansion of $0 macro ends here]])
  96. ])dnl AC_DEFUN MHD_CHECK_FUNC