aboutsummaryrefslogtreecommitdiff
path: root/m4/mhd_find_add_cc_cflag.m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4/mhd_find_add_cc_cflag.m4')
-rw-r--r--m4/mhd_find_add_cc_cflag.m470
1 files changed, 70 insertions, 0 deletions
diff --git a/m4/mhd_find_add_cc_cflag.m4 b/m4/mhd_find_add_cc_cflag.m4
new file mode 100644
index 00000000..7afc0f39
--- /dev/null
+++ b/m4/mhd_find_add_cc_cflag.m4
@@ -0,0 +1,70 @@
1# SYNOPSIS
2#
3# MHD_FIND_ADD_CC_CFLAG([VARIABLE-TO-EXTEND],
4# [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
5#
6# DESCRIPTION
7#
8# This macro checks whether the specific compiler flags are supported.
9# The flags are checked one-by-one. The checking is stopped when the first
10# supported flag found.
11# The checks are performing by appending FLAGx-TO-TEST to the value of
12# VARIABLE-TO-EXTEND (CFLAGS if not specified), then prepending result to
13# CFLAGS (unless VARIABLE-TO-EXTEND is CFLAGS), and then performing compile
14# and link test. If test succeed without warnings, then the flag is added to
15# VARIABLE-TO-EXTEND and next flags are not checked. If compile-link cycle
16# cannot be performed without warning with all tested flags, no flag is
17# added to the VARIABLE-TO-EXTEND.
18#
19# Example usage:
20#
21# MHD_CHECK_CC_CFLAG([additional_CFLAGS],
22# [-ggdb3], [-g3], [-ggdb], [-g])
23#
24# Note: Unlike others MHD_CHECK_*CC_CFLAG* macro, this macro uses another
25# order of parameters.
26#
27# LICENSE
28#
29# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
30#
31# Copying and distribution of this file, with or without modification, are
32# permitted in any medium without royalty provided the copyright notice
33# and this notice are preserved. This file is offered as-is, without any
34# warranty.
35
36#serial 1
37
38AC_DEFUN([MHD_FIND_ADD_CC_CFLAG],[dnl
39_MHD_FIND_ADD_CC_XFLAG([[CFLAGS]],$@)])
40
41
42# SYNOPSIS
43#
44# _MHD_FIND_ADD_CC_XFLAG([CFLAGS|LDFLAGS],
45# [VARIABLE-TO-EXTEND],
46# [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
47#
48AC_DEFUN([_MHD_FIND_ADD_CC_XFLAG],[dnl
49 AC_PREREQ([2.64])dnl for m4_ifnblank
50 AC_LANG_ASSERT([C])dnl
51 m4_if(m4_eval([$# >= 3]), [0], [m4_fatal([$0: Macro must have at least three parameters])])dnl
52 m4_ifblank([$3],[m4_fatal([$0: Third macro argument must not be empty])])dnl
53 m4_bmatch(_mhd_norm_expd([$1]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
54 [m4_fatal([$0: First macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
55 m4_ifnblank([$2],[_MHD_FIND_ADD_CC_XFLAG_BODY($@)],dnl
56 [_MHD_FIND_ADD_CC_XFLAG_BODY([$1],[$1],m4_shift2($@))])dnl
57])
58
59
60m4_define([_MHD_FIND_ADD_CC_XFLAG_BODY],[dnl
61m4_version_prereq([2.64])dnl for m4_ifnblank
62m4_if([$#],[0],[m4_fatal([$0: no parameters])])dnl
63m4_bmatch(_mhd_norm_expd([$1]),[^\(CFLAGS\|LDFLAGS\)$],[],dnl
64[m4_fatal([$0: First macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
65m4_if([$#],[1],[m4_fatal([$0: not enough parameters])])dnl
66m4_if([$#],[2],[m4_fatal([$0: not enough parameters])])dnl
67m4_if([$#],[3],[m4_ifnblank([$3],[_MHD_CHECK_ADD_CC_XFLAG([$3],[$2],[],[],[$1])])],
68[m4_ifnblank([$3],[_MHD_CHECK_ADD_CC_XFLAG([$3],[$2],[],[$0([$1],[$2],m4_shift3($@))],[$1])],
69[$0([$1],[$2],m4_shift3($@))])])dnl
70])