mhd_check_func.m4 3.3 KB

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