mhd_check_func.m4 4.0 KB

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