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