aboutsummaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2024-04-21 19:01:23 +0200
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2024-04-24 17:40:52 +0200
commitc11ea1f96a257f15628caf0383edc7a9d291097b (patch)
tree134e06a4162a1e1eb21fc9bc4c04324236ef11a9 /m4
parentc1e4368fcaed8167a85458c72fe5dc19d894c800 (diff)
downloadlibmicrohttpd-c11ea1f96a257f15628caf0383edc7a9d291097b.tar.gz
libmicrohttpd-c11ea1f96a257f15628caf0383edc7a9d291097b.zip
mhd_check_func_run.m4: new autoconf macro
Diffstat (limited to 'm4')
-rw-r--r--m4/mhd_check_func_run.m4120
1 files changed, 120 insertions, 0 deletions
diff --git a/m4/mhd_check_func_run.m4 b/m4/mhd_check_func_run.m4
new file mode 100644
index 00000000..d935ee85
--- /dev/null
+++ b/m4/mhd_check_func_run.m4
@@ -0,0 +1,120 @@
1# SYNOPSIS
2#
3# MHD_CHECK_FUNC_RUN(FUNCTION_NAME,
4# [INCLUDES=AC_INCLUDES_DEFAULT], CHECK_CODE
5# COMMAND_IF_CROSS_COMPILING,
6# [ACTION_IF_AVAILABLE], [ACTION_IF_NOT_AVAILABLE],
7# [ADDITIONAL_LIBS])
8#
9# DESCRIPTION
10#
11# This macro checks for presence of specific function by including
12# specified headers, checking for declaration of the function and then
13# compiling and linking CHECK_CODE. If all previous steps succeed,
14# the binary is executed.
15# The CHECK_CODE is full body of the "main" function and must include
16# the final "return" keyword.
17# This checks the declaration, the presence in library and the functionality.
18# If function is available then macro HAVE_function_name (the name
19# of the function conveted to all uppercase characters) is defined
20# automatically.
21# By using definition from provided headers, this macro ensures that
22# correct calling convention is used for detection.
23# The compilation and linking is tried even if cross-compiling. If they
24# failed then the result is "no".
25# The COMMAND_IF_CROSS_COMPILING commands are executed if and only if
26# the compilation and linking succeed. These commands must set 'cacheVar'
27# variable to "yes", "no", "assuming yes" or "assuming no".
28# ACTION_IF_SUCCEED is executed if result is "yes" or "assuming yes".
29# ACTION_IF_FAILED is executed if result is "no" or "assuming no".
30#
31# Example usage:
32#
33# MHD_CHECK_FUNC_RUN([memmem],
34# [[#include <string.h>]],
35# [[const void *ptr = memmem("aa", 2, "a", 1);
36# if (((void*)0) == ptr) return 1;
37# return 0;]],
38# [cacheVar="assuming yes"],
39# [var_use_memmem='yes'], [var_use_memmem='no'])
40#
41# The cache variable used in check so if any test will not work
42# correctly on some platform, user may simply fix it by giving cache
43# variable in configure parameters, for example:
44#
45# ./configure mhd_cv_works_func_memmem=no
46#
47# This simplifies building from source on exotic platforms as patching
48# of configure.ac is not required to change the results of the tests.
49#
50# LICENSE
51#
52# Copyright (c) 2024 Karlson2k (Evgeny Grin) <k2k@narod.ru>
53#
54# Copying and distribution of this file, with or without modification, are
55# permitted in any medium without royalty provided the copyright notice
56# and this notice are preserved. This file is offered as-is, without any
57# warranty.
58
59#serial 1
60
61dnl $1: FUNCTION_NAME
62dnl $2: INCLUDES
63dnl $3: CHECK_CODE
64dnl $4: COMMAND_IF_CROSS_COMPILING
65dnl $5: ACTION_IF_AVAILABLE
66dnl $6: ACTION_IF_NOT_AVAILABLE
67dnl $7: ADDITIONAL_LIBS
68AC_DEFUN([MHD_CHECK_FUNC_RUN],[dnl
69AC_PREREQ([2.64])dnl for AS_VAR_SET_IF, m4_ifblank, m4_ifnblank, m4_default_nblank
70m4_newline([[# Expansion of $0 macro starts here]])
71AC_LANG_ASSERT([C])dnl
72m4_ifblank(m4_translit([$1],[()],[ ]), [m4_fatal([$0: First macro argument ("FUNCTION_NAME") must not be empty])])dnl
73m4_ifblank([$3], [m4_fatal([$0: Third macro argument ("CHECK_CODE") must not be empty])])dnl
74m4_bmatch(m4_normalize([$1]), [\s],dnl
75 [m4_fatal([$0: First macro argument ("FUNCTION_NAME") must not contain whitespaces])])dnl
76m4_if(m4_index([$3], m4_normalize(m4_translit([$1],[()],[ ]))), [-1], dnl
77 [m4_fatal([$0: "CHECK_CODE" macro parameter (third argument) does not contain ']m4_normalize([$1])[' token])])dnl
78m4_if(m4_index([$3],return), [-1], dnl
79 [m4_fatal([$0: "CHECK_CODE" macro parameter (third argument) does not contain 'return' token])])dnl
80m4_bmatch(_mhd_norm_expd([$4]),[\<]cacheVar[\>],[],dnl
81[m4_fatal([$0: The fourth macro argument ("COMMAND_IF_CROSS_COMPILING") must assign ]dnl
82[a value to the cache variable 'cacheVar'. The variable must be not overquoted.])])dnl
83AS_VAR_PUSHDEF([decl_cv_Var],[ac_cv_have_decl_]m4_bpatsubst(_mhd_norm_expd(m4_translit([$1],[()],[ ])),[[^a-zA-Z0-9]],[_]))dnl
84AS_VAR_PUSHDEF([cacheVar],[mhd_cv_works_func_]m4_bpatsubst(_mhd_norm_expd(m4_translit([$1],[()],[ ])),[[^a-zA-Z0-9]],[_]))dnl
85AS_VAR_SET_IF([cacheVar],[],[AC_CHECK_DECL(_mhd_norm_expd([$1]),[],[cacheVar="no"],[$2])])
86AC_CACHE_CHECK([whether '$1' available and works],[cacheVar],dnl
87[
88AC_LANG_CONFTEST([AC_LANG_SOURCE([
89m4_default_nblank([$2],[AC_INCLUDES_DEFAULT])
90
91[int main(void)
92{
93 ]$3[
94}
95]])])
96m4_ifnblank([$7],[dnl
97mhd_check_func_SAVE_LIBS="$LIBS"
98LIBS="_mhd_norm_expd([$7]) $LIBS"
99])dnl m4_ifnblank
100AS_VAR_IF([cross_compiling],["yes"],
101[AC_LINK_IFELSE([],[
102$4
103],[cacheVar='no'])dnl AC_LINK_IFELSE
104],dnl
105[AC_RUN_IFELSE([],[cacheVar='yes'],[cacheVar='no'],[[# Dummy placeholder]])
106])
107rm -f conftest.$ac_ext
108m4_ifnblank([$7],[dnl
109 LIBS="${mhd_check_func_SAVE_LIBS}"
110 AS_UNSET([mhd_check_func_SAVE_LIBS])
111])dnl m4_ifnblank
112])dnl AC_CACHE_CHECK
113m4_ifnblank([$5],[
114AS_IF([test "x$cacheVar" = "xyes" || test "x$cacheVar" = "xassuming yes"],[$5])dnl AS_IF
115])dnl m4_ifnblank
116m4_ifnblank([$6],[
117AS_IF([test "x$cacheVar" = "xno" || test "x$cacheVar" = "xassuming no"],[$6])dnl AS_IF
118])dnl m4_ifnblank
119m4_newline([[# Expansion of $0 macro ends here]])
120])dnl AC_DEFUN MHD_CHECK_FUNC_RUN