Introduce common generic header file
[librseq.git] / m4 / ae_config_feature.m4
1 # SPDX-License-Identifier: GPL-2.0-or-later WITH LicenseRef-Autoconf-exception-macro
2 # SPDX-FileCopyrightText: 2020 Michael Jeanson <mjeanson@efficios.com>
3 # SPDX-FileCopyrightText: 2008 Francesco Salvestrini <salvestrini@users.sourceforge.net>
4 #
5 # SYNOPSIS
6 #
7 # AE_FEATURE(FEATURE-NAME, FEATURE-DESCRIPTION,
8 # ACTION-IF-GIVEN?, ACTION-IF-NOT-GIVEN?,
9 # ACTION-IF-ENABLED?, ACTION-IF-NOT-ENABLED?)
10 #
11 # DESCRIPTION
12 #
13 # AE_FEATURE is a simple wrapper for AC_ARG_ENABLE.
14 #
15 # FEATURE-NAME should consist only of alphanumeric characters, dashes,
16 # plus signs, and dots.
17 #
18 # FEATURE-DESCRIPTION will be formatted with AS_HELP_STRING.
19 #
20 # If the user gave configure the option --enable-FEATURE or --disable-FEATURE,
21 # run shell commands ACTION-IF-GIVEN. If neither option was given, run shell
22 # commands ACTION-IF-NOT-GIVEN. The name feature indicates an optional
23 #
24 # If the feature is enabled, run shell commands ACTION-IF-ENABLED, if it is
25 # disabled, run shell commands ACTION-IF-NOT-ENABLED.
26 #
27 # A FEATURE has 3 different states, enabled, disabled and undefined. The first
28 # two are self explanatory, the third state means it's disabled by default
29 # and it was not explicitly enabled or disabled by the user or by the
30 # AE_FEATURE_ENABLE and AE_FEATURE_DISABLE macros.
31 #
32 # A feature is disabled by default, in order to change this behaviour use the
33 # AE_FEATURE_DEFAULT_ENABLE and AE_FEATURE_DEFAULT_DISABLE
34 # macros.
35 #
36 # A simple example:
37 #
38 # AE_FEATURE_DEFAULT_ENABLE
39 # AE_FEATURE(feature_xxxxx, [turns on/off XXXXX support])
40 #
41 # ...
42 #
43 # AE_FEATURE_DEFAULT_DISABLE
44 # AE_FEATURE(feature_yyyyy, [turns on/off YYYYY support])
45 # AM_CONDITIONAL(YYYYY, AE_IS_FEATURE_ENABLED([feature_yyyyy]))
46 #
47 # AE_FEATURE_DEFAULT_ENABLE
48 # AE_FEATURE(...)
49 #
50 # ...
51 #
52 # Use AE_FEATURE_ENABLE or AE_FEATURE_DISABLE in order to
53 # enable or disable a specific feature.
54 #
55 # Another simple example:
56 #
57 # AS_IF([some_test_here],[AE_FEATURE_ENABLE(feature_xxxxx)],[])
58 #
59 # AE_FEATURE(feature_xxxxx, [turns on/off XXXXX support],
60 # HAVE_XXXXX, [Define if you want XXXXX support])
61 # AE_FEATURE(feature_yyyyy, [turns on/off YYYYY support],
62 # HAVE_YYYYY, [Define if you want YYYYY support])
63 #
64 # ...
65 #
66 # NOTE: AE_FEATURE_ENABLE/DISABLE() must be placed first of the relative
67 # AE_FEATURE() macro if you want the the proper ACTION-IF-ENABLED and
68 # ACTION-IF-NOT-ENABLED to run.
69
70 #serial 3
71
72
73 # AE_FEATURE_DEFAULT_ENABLE: The next feature defined with AE_FEATURE will
74 # default to enable.
75 AC_DEFUN([AE_FEATURE_DEFAULT_ENABLE], [
76 m4_define([ae_feature_default_arg], [yes])
77 m4_define([ae_feature_default_switch], [disable])
78 ])
79
80
81 # AE_FEATURE_DEFAULT_DISABLE: The next feature defined with AE_FEATURE will
82 # default to disable.
83 #
84 AC_DEFUN([AE_FEATURE_DEFAULT_DISABLE], [
85 m4_define([ae_feature_default_arg], [no])
86 m4_define([ae_feature_default_switch], [enable])
87 ])
88
89
90 # AE_FEATURE_ENABLE(FEATURE-NAME): Enable the FEATURE, this will override the
91 # user's choice if it was made.
92 #
93 AC_DEFUN([AE_FEATURE_ENABLE],[ dnl
94 enable_[]patsubst([$1], -, _)[]=yes
95 ])
96
97
98 # AE_FEATURE_DISABLE(FEATURE-NAME): Disable the FEATURE, this will override the
99 # user's choice if it was made.
100 #
101 AC_DEFUN([AE_FEATURE_DISABLE],[ dnl
102 enable_[]patsubst([$1], -, _)[]=no
103 ])
104
105
106 # AE_IF_FEATURE_ENABLED(FEATURE-NAME, ACTION-IF-ENABLED, ACTION-IF-NOT-ENABLED?):
107 # Run shell code ACTION-IF-ENABLED if the FEATURE is enabled, otherwise run
108 # shell code ACTION-IF-NOT-ENABLED.
109 #
110 AC_DEFUN([AE_IF_FEATURE_ENABLED],[ dnl
111 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
112
113 AS_IF([test "$enable_[]FEATURE[]" = yes],[ dnl
114 $2
115 ],[: dnl
116 $3
117 ])
118 ])
119
120
121 # AE_IF_FEATURE_NOT_ENABLED(FEATURE-NAME, ACTION-IF-NOT-ENABLED,
122 # ACTION-IF-NOT-NOT-ENABLED?):
123 # Run shell code ACTION-IF-NOT-ENABLED if the FEATURE is not explicitly
124 # enabled, otherwise run shell code ACTION-IF-NOT-NOT-DISABLED.
125 #
126 # The distinction with AE_IF_FEATURE_DISABLED is that this will also
127 # match a feature that is undefined.
128 #
129 # A feature is undefined when it's disabled by default and was not explicitly
130 # enabled or disabled by the user or by AE_FEATURE_ENABLE/DISABLE.
131 #
132 AC_DEFUN([AE_IF_FEATURE_NOT_ENABLED],[ dnl
133 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
134
135 AS_IF([test "$enable_[]FEATURE[]" != yes],[ dnl
136 $2
137 ],[: dnl
138 $3
139 ])
140 ])
141
142
143 # AE_IF_FEATURE_DISABLED(FEATURE-NAME, ACTION-IF-DISABLED, ACTION-IF-NOT-DISABLED?):
144 # Run shell code ACTION-IF-DISABLED if the FEATURE is disabled, otherwise run
145 # shell code ACTION-IF-NOT-DISABLED.
146 #
147 AC_DEFUN([AE_IF_FEATURE_DISABLED],[ dnl
148 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
149
150 AS_IF([test "$enable_[]FEATURE[]" = no],[ dnl
151 $2
152 ],[: dnl
153 $3
154 ])
155 ])
156
157
158 # AE_IF_FEATURE_UNDEF(FEATURE-NAME, ACTION-IF-UNDEF, ACTION-IF-NOT-UNDEF?):
159 # Run shell code ACTION-IF-UNDEF if the FEATURE is undefined, otherwise run
160 # shell code ACTION-IF-NOT-UNDEF.
161 #
162 # A feature is undefined when it's disabled by default and was not explicitly
163 # enabled or disabled by the user or by AE_FEATURE_ENABLE/DISABLE.
164 #
165 AC_DEFUN([AE_IF_FEATURE_UNDEF],[ dnl
166 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
167
168 AS_IF([test "x$enable_[]FEATURE[]" = x],[ dnl
169 $2
170 ],[: dnl
171 $3
172 ])
173 ])
174
175
176 # AE_IS_FEATURE_ENABLED(FEATURE-NAME): outputs a shell condition (suitable
177 # for use in a shell if statement) that will return true if the FEATURE is
178 # enabled.
179 #
180 AC_DEFUN([AE_IS_FEATURE_ENABLED],[dnl
181 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
182 test "x$enable_[]FEATURE[]" = xyes dnl
183 ])
184
185
186 dnl Disabled by default, unless already overridden
187 m4_ifndef([ae_feature_default_arg],[AE_FEATURE_DEFAULT_DISABLE])
188
189
190 # AE_FEATURE(FEATURE-NAME, FEATURE-DESCRIPTION,
191 # ACTION-IF-GIVEN?, ACTION-IF-NOT-GIVEN?,
192 # ACTION-IF-ENABLED?, ACTION-IF-NOT-ENABLED?):
193 #
194 #
195 AC_DEFUN([AE_FEATURE],[ dnl
196 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
197
198 dnl If the option wasn't specified and the default is enabled, set enable_FEATURE to yes
199 AS_IF([test "x$enable_[]FEATURE[]" = x && test "ae_feature_default_arg" = yes],[ dnl
200 enable_[]FEATURE[]="ae_feature_default_arg"
201 ])
202
203 AC_ARG_ENABLE([$1],
204 AS_HELP_STRING([--ae_feature_default_switch-$1],dnl
205 [$2]),[
206 case "${enableval}" in
207 yes)
208 enable_[]FEATURE[]=yes
209 ;;
210 no)
211 enable_[]FEATURE[]=no
212 ;;
213 *)
214 AC_MSG_ERROR([bad value ${enableval} for feature --$1])
215 ;;
216 esac
217
218 $3
219 ],[: dnl
220 $4
221 ])
222
223 AS_IF([test "$enable_[]FEATURE[]" = yes],[: dnl
224 $5
225 ],[: dnl
226 $6
227 ])
228
229 m4_popdef([FEATURE])dnl
230 ])
This page took 0.038905 seconds and 4 git commands to generate.