aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-12-23 15:58:39 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-12-23 16:01:57 +0300
commit84dfd52f13102cea21b2a932556fac49ed770cee (patch)
treed2b3b56e0d232178cbf5079c200d4c791e14d613
parent4dadf8ec97d74ab2034452833067ee5e7a6ee25f (diff)
downloadlibmicrohttpd-84dfd52f13102cea21b2a932556fac49ed770cee.tar.gz
libmicrohttpd-84dfd52f13102cea21b2a932556fac49ed770cee.zip
Added new M4 helper macro
-rw-r--r--m4/mhd_check_link_run.m467
1 files changed, 67 insertions, 0 deletions
diff --git a/m4/mhd_check_link_run.m4 b/m4/mhd_check_link_run.m4
new file mode 100644
index 00000000..731ab81e
--- /dev/null
+++ b/m4/mhd_check_link_run.m4
@@ -0,0 +1,67 @@
1# SYNOPSIS
2#
3# MHD_CHECK_LINK_RUN(MESSAGE, CACHE_ID, COMMAND_IF_CROSS_COMPILING, INPUT,
4# [ACTION_IF_SUCCEED], [ACTION_IF_FAILED])
5#
6# DESCRIPTION
7#
8# Improved version of AC_RUN_IFELSE macro.
9# Unlike AC_RUN_IFELSE, this macro tries to link the code if cross-compiling.
10# Action COMMAND_IF_CROSS_COMPILING is executed only if link is succeed,
11# otherwise CACHE_ID variable set to "no".
12# COMMAND_IF_CROSS_COMPILING action must set CACHE_ID variable to "yes", "no",
13# "assuming yes" or "assuming no".
14# ACTION_IF_SUCCEED is executed if result is "yes" or "assuming yes".
15# ACTION_IF_FAILED is execuded if result is "no" or "assuming no".
16#
17# Example usage:
18#
19# MHD_CHECK_LINK_RUN([for valid snprintf()], [mhd_cv_snprintf_valid],
20# AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
21# [if (4 != snprintf(NULL, 0, "test"))
22# return 2;])],
23# [mhd_cv_snprintf_valid='assuming no'])
24#
25#
26# LICENSE
27#
28# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
29#
30# Copying and distribution of this file, with or without modification, are
31# permitted in any medium without royalty provided the copyright notice
32# and this notice are preserved. This file is offered as-is, without any
33# warranty.
34
35#serial 1
36
37AC_DEFUN([MHD_CHECK_LINK_RUN],[dnl
38m4_ifblank([$1],[m4_fatal([$0: The first macro argument ("MESSAGE") must not be empty])])dnl
39m4_ifblank([$2],[m4_fatal([$0: The second macro argument ("CACHE_ID") must not be empty])])dnl
40m4_ifblank([$3],[m4_fatal([$0: The third macro argument ("COMMAND_IF_CROSS_COMPILING") ]dnl
41[must not be empty])])dnl
42m4_ifblank([$4],[m4_fatal([$0: The fourth macro argument ("INPUT") must not be empty])])dnl
43m4_bmatch(_mhd_norm_expd([$2]),[\s],dnl
44[m4_fatal([$0: The second macro argument ("CACHE_ID") must not contain whitespaces])])dnl
45m4_bmatch(_mhd_norm_expd([$3]),[\<]m4_re_escape(_mhd_norm_expd([$2]))[\>],[],dnl
46[m4_fatal([$0: The third macro argument ("COMMAND_IF_CROSS_COMPILING") must assign ]dnl
47[a value to the cache variable ']_mhd_norm_expd([$2])['])])dnl
48m4_pushdef([cacheVar],_mhd_norm_expd([$2]))dnl
49AC_CACHE_CHECK([$1],[$2],
50[
51AC_LANG_CONFTEST([$4])
52AS_VAR_IF([cross_compiling],["yes"],
53[AC_LINK_IFELSE([],[
54$3
55],[cacheVar='no'])dnl AC_LINK_IFELSE
56],dnl
57[AC_RUN_IFELSE([],[cacheVar='yes'],[cacheVar='no'],[[# Dummy placeholder]])
58])
59rm -f conftest.$ac_ext
60])
61m4_ifnblank([$5],[
62AS_IF([test "x$cacheVar" = "xyes" || test "x$cacheVar" = "xassuming yes"],[$5])dnl AS_IF
63])dnl m4_ifnblank
64m4_ifnblank([$6],[
65AS_IF([test "x$cacheVar" = "xno" || test "x$cacheVar" = "xassuming no"],[$6])dnl AS_IF
66])dnl m4_ifnblank
67])dnl AC_DEFUN