Debian Codegraph @

m4/mhd_check_func.m4

raw
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) <[email protected]>
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
50 #serial 6
51
52 AC_DEFUN([MHD_CHECK_FUNC],[dnl
53 AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifblank, m4_ifnblank
54 m4_newline([[# Expansion of $0 macro starts here]])
55 AC_LANG_ASSERT([C])dnl
56 m4_ifblank(m4_translit([$1],[()],[ ]), [m4_fatal([First macro argument must not be empty])])dnl
57 m4_ifblank([$3], [m4_fatal([Third macro argument must not be empty])])dnl
58 m4_bmatch(m4_normalize([$1]), [\s],dnl
59 [m4_fatal([First macro argument must not contain whitespaces])])dnl
60 m4_if(m4_index([$3], m4_normalize(m4_translit([$1],[()],[ ]))), [-1], dnl
61 [m4_fatal([CHECK_CODE parameter (third macro argument) does not contain ']m4_normalize([$1])[' token])])dnl
62 AS_VAR_PUSHDEF([decl_cv_Var],[ac_cv_have_decl_]m4_bpatsubst(_mhd_norm_expd(m4_translit([$1],[()],[ ])),[[^a-zA-Z0-9]],[_]))dnl
63 AS_VAR_PUSHDEF([cv_Var],[mhd_cv_have_func_]m4_bpatsubst(_mhd_norm_expd(m4_translit([$1],[()],[ ])),[[^a-zA-Z0-9]],[_]))dnl
64 AS_VAR_SET_IF([cv_Var],[],[AC_CHECK_DECL(_mhd_norm_expd([$1]),[],[cv_Var="no"],[$2])])
65 AC_CACHE_CHECK([f][or function $1], [cv_Var],dnl
66 [dnl
67 m4_ifnblank([$6],[dnl
68 mhd_check_func_SAVE_LIBS="$LIBS"
69 LIBS="_mhd_norm_expd([$6]) $LIBS"
70 ])dnl
71 AC_LINK_IFELSE(
72 [AC_LANG_SOURCE([
73 m4_default_nblank([$2],[AC_INCLUDES_DEFAULT])
74
75 [int main(void)
76 {
77
78 ]$3[
79
80 return 0;
81 }
82 ]])
83 ],
84 [AS_VAR_SET([cv_Var],["yes"])],
85 [AS_VAR_SET([cv_Var],["no"])]dnl
86 )
87 m4_ifnblank([$6],[dnl
88 LIBS="${mhd_check_func_SAVE_LIBS}"
89 AS_UNSET([mhd_check_func_SAVE_LIBS])
90 ])dnl
91 ],[AS_VAR_SET([cv_Var],["no"])]dnl
92 )
93 AS_VAR_IF([cv_Var], ["yes"],
94 [AC_DEFINE([[HAVE_]]m4_bpatsubst(m4_toupper(_mhd_norm_expd(m4_translit([$1],[()],[ ]))),[[^A-Z0-9]],[_]),
95 [1], [Define to 1 if you have the ']_mhd_norm_expd(m4_translit([$1],[()],[ ]))[' function.])
96 m4_n([$4])dnl
97 ],[$5])
98 AS_VAR_POPDEF([cv_Var])dnl
99 AS_VAR_POPDEF([decl_cv_Var])dnl
100 m4_newline([[# Expansion of $0 macro ends here]])
101 ])dnl AC_DEFUN MHD_CHECK_FUNC