Implement the REUSE specification for licensing and copyright
[librseq.git] / m4 / ae_config_feature.m4
1 # SPDX-License-Identifier: GPL-2.0-or-later WITH LicenseRef-Autoconf-exception-macro
2 #
3 # SYNOPSIS
4 #
5 # AE_FEATURE(FEATURE-NAME, FEATURE-DESCRIPTION,
6 # ACTION-IF-GIVEN?, ACTION-IF-NOT-GIVEN?,
7 # ACTION-IF-ENABLED?, ACTION-IF-NOT-ENABLED?)
8 #
9 # DESCRIPTION
10 #
11 # AE_FEATURE is a simple wrapper for AC_ARG_ENABLE.
12 #
13 # FEATURE-NAME should consist only of alphanumeric characters, dashes,
14 # plus signs, and dots.
15 #
16 # FEATURE-DESCRIPTION will be formatted with AS_HELP_STRING.
17 #
18 # If the user gave configure the option --enable-FEATURE or --disable-FEATURE,
19 # run shell commands ACTION-IF-GIVEN. If neither option was given, run shell
20 # commands ACTION-IF-NOT-GIVEN. The name feature indicates an optional
21 #
22 # If the feature is enabled, run shell commands ACTION-IF-ENABLED, if it is
23 # disabled, run shell commands ACTION-IF-NOT-ENABLED.
24 #
25 # A FEATURE has 3 different states, enabled, disabled and undefined. The first
26 # two are self explanatory, the third state means it's disabled by default
27 # and it was not explicitly enabled or disabled by the user or by the
28 # AE_FEATURE_ENABLE and AE_FEATURE_DISABLE macros.
29 #
30 # A feature is disabled by default, in order to change this behaviour use the
31 # AE_FEATURE_DEFAULT_ENABLE and AE_FEATURE_DEFAULT_DISABLE
32 # macros.
33 #
34 # A simple example:
35 #
36 # AE_FEATURE_DEFAULT_ENABLE
37 # AE_FEATURE(feature_xxxxx, [turns on/off XXXXX support])
38 #
39 # ...
40 #
41 # AE_FEATURE_DEFAULT_DISABLE
42 # AE_FEATURE(feature_yyyyy, [turns on/off YYYYY support])
43 # AM_CONDITIONAL(YYYYY, AE_IS_FEATURE_ENABLED([feature_yyyyy]))
44 #
45 # AE_FEATURE_DEFAULT_ENABLE
46 # AE_FEATURE(...)
47 #
48 # ...
49 #
50 # Use AE_FEATURE_ENABLE or AE_FEATURE_DISABLE in order to
51 # enable or disable a specific feature.
52 #
53 # Another simple example:
54 #
55 # AS_IF([some_test_here],[AE_FEATURE_ENABLE(feature_xxxxx)],[])
56 #
57 # AE_FEATURE(feature_xxxxx, [turns on/off XXXXX support],
58 # HAVE_XXXXX, [Define if you want XXXXX support])
59 # AE_FEATURE(feature_yyyyy, [turns on/off YYYYY support],
60 # HAVE_YYYYY, [Define if you want YYYYY support])
61 #
62 # ...
63 #
64 # NOTE: AE_FEATURE_ENABLE/DISABLE() must be placed first of the relative
65 # AE_FEATURE() macro if you want the the proper ACTION-IF-ENABLED and
66 # ACTION-IF-NOT-ENABLED to run.
67 #
68 # LICENSE
69 #
70 # Copyright (c) 2020 Michael Jeanson <mjeanson@efficios.com>
71 # Copyright (c) 2008 Francesco Salvestrini <salvestrini@users.sourceforge.net>
72 #
73 # This program is free software; you can redistribute it and/or modify it
74 # under the terms of the GNU General Public License as published by the
75 # Free Software Foundation; either version 2 of the License, or (at your
76 # option) any later version.
77 #
78 # This program is distributed in the hope that it will be useful, but
79 # WITHOUT ANY WARRANTY; without even the implied warranty of
80 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
81 # Public License for more details.
82 #
83 # You should have received a copy of the GNU General Public License along
84 # with this program. If not, see <https://www.gnu.org/licenses/>.
85 #
86 # As a special exception, the respective Autoconf Macro's copyright owner
87 # gives unlimited permission to copy, distribute and modify the configure
88 # scripts that are the output of Autoconf when processing the Macro. You
89 # need not follow the terms of the GNU General Public License when using
90 # or distributing such scripts, even though portions of the text of the
91 # Macro appear in them. The GNU General Public License (GPL) does govern
92 # all other use of the material that constitutes the Autoconf Macro.
93 #
94 # This special exception to the GPL applies to versions of the Autoconf
95 # Macro released by the Autoconf Archive. When you make and distribute a
96 # modified version of the Autoconf Macro, you may extend this special
97 # exception to the GPL to apply to your modified version as well.
98
99 #serial 2
100
101
102 # AE_FEATURE_DEFAULT_ENABLE: The next feature defined with AE_FEATURE will
103 # default to enable.
104 AC_DEFUN([AE_FEATURE_DEFAULT_ENABLE], [
105 m4_define([ae_feature_default_arg], [yes])
106 m4_define([ae_feature_default_switch], [disable])
107 ])
108
109
110 # AE_FEATURE_DEFAULT_DISABLE: The next feature defined with AE_FEATURE will
111 # default to disable.
112 #
113 AC_DEFUN([AE_FEATURE_DEFAULT_DISABLE], [
114 m4_define([ae_feature_default_arg], [no])
115 m4_define([ae_feature_default_switch], [enable])
116 ])
117
118
119 # AE_FEATURE_ENABLE(FEATURE-NAME): Enable the FEATURE, this will override the
120 # user's choice if it was made.
121 #
122 AC_DEFUN([AE_FEATURE_ENABLE],[ dnl
123 enable_[]patsubst([$1], -, _)[]=yes
124 ])
125
126
127 # AE_FEATURE_DISABLE(FEATURE-NAME): Disable the FEATURE, this will override the
128 # user's choice if it was made.
129 #
130 AC_DEFUN([AE_FEATURE_DISABLE],[ dnl
131 enable_[]patsubst([$1], -, _)[]=no
132 ])
133
134
135 # AE_IF_FEATURE_ENABLED(FEATURE-NAME, ACTION-IF-ENABLED, ACTION-IF-NOT-ENABLED?):
136 # Run shell code ACTION-IF-ENABLED if the FEATURE is enabled, otherwise run
137 # shell code ACTION-IF-NOT-ENABLED.
138 #
139 AC_DEFUN([AE_IF_FEATURE_ENABLED],[ dnl
140 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
141
142 AS_IF([test "$enable_[]FEATURE[]" = yes],[ dnl
143 $2
144 ],[: dnl
145 $3
146 ])
147 ])
148
149
150 # AE_IF_FEATURE_NOT_ENABLED(FEATURE-NAME, ACTION-IF-NOT-ENABLED,
151 # ACTION-IF-NOT-NOT-ENABLED?):
152 # Run shell code ACTION-IF-NOT-ENABLED if the FEATURE is not explicitly
153 # enabled, otherwise run shell code ACTION-IF-NOT-NOT-DISABLED.
154 #
155 # The distinction with AE_IF_FEATURE_DISABLED is that this will also
156 # match a feature that is undefined.
157 #
158 # A feature is undefined when it's disabled by default and was not explicitly
159 # enabled or disabled by the user or by AE_FEATURE_ENABLE/DISABLE.
160 #
161 AC_DEFUN([AE_IF_FEATURE_NOT_ENABLED],[ dnl
162 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
163
164 AS_IF([test "$enable_[]FEATURE[]" != yes],[ dnl
165 $2
166 ],[: dnl
167 $3
168 ])
169 ])
170
171
172 # AE_IF_FEATURE_DISABLED(FEATURE-NAME, ACTION-IF-DISABLED, ACTION-IF-NOT-DISABLED?):
173 # Run shell code ACTION-IF-DISABLED if the FEATURE is disabled, otherwise run
174 # shell code ACTION-IF-NOT-DISABLED.
175 #
176 AC_DEFUN([AE_IF_FEATURE_DISABLED],[ dnl
177 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
178
179 AS_IF([test "$enable_[]FEATURE[]" = no],[ dnl
180 $2
181 ],[: dnl
182 $3
183 ])
184 ])
185
186
187 # AE_IF_FEATURE_UNDEF(FEATURE-NAME, ACTION-IF-UNDEF, ACTION-IF-NOT-UNDEF?):
188 # Run shell code ACTION-IF-UNDEF if the FEATURE is undefined, otherwise run
189 # shell code ACTION-IF-NOT-UNDEF.
190 #
191 # A feature is undefined when it's disabled by default and was not explicitly
192 # enabled or disabled by the user or by AE_FEATURE_ENABLE/DISABLE.
193 #
194 AC_DEFUN([AE_IF_FEATURE_UNDEF],[ dnl
195 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
196
197 AS_IF([test "x$enable_[]FEATURE[]" = x],[ dnl
198 $2
199 ],[: dnl
200 $3
201 ])
202 ])
203
204
205 # AE_IS_FEATURE_ENABLED(FEATURE-NAME): outputs a shell condition (suitable
206 # for use in a shell if statement) that will return true if the FEATURE is
207 # enabled.
208 #
209 AC_DEFUN([AE_IS_FEATURE_ENABLED],[dnl
210 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
211 test "x$enable_[]FEATURE[]" = xyes dnl
212 ])
213
214
215 dnl Disabled by default, unless already overridden
216 m4_ifndef([ae_feature_default_arg],[AE_FEATURE_DEFAULT_DISABLE])
217
218
219 # AE_FEATURE(FEATURE-NAME, FEATURE-DESCRIPTION,
220 # ACTION-IF-GIVEN?, ACTION-IF-NOT-GIVEN?,
221 # ACTION-IF-ENABLED?, ACTION-IF-NOT-ENABLED?):
222 #
223 #
224 AC_DEFUN([AE_FEATURE],[ dnl
225 m4_pushdef([FEATURE], patsubst([$1], -, _))dnl
226
227 dnl If the option wasn't specified and the default is enabled, set enable_FEATURE to yes
228 AS_IF([test "x$enable_[]FEATURE[]" = x && test "ae_feature_default_arg" = yes],[ dnl
229 enable_[]FEATURE[]="ae_feature_default_arg"
230 ])
231
232 AC_ARG_ENABLE([$1],
233 AS_HELP_STRING([--ae_feature_default_switch-$1],dnl
234 [$2]),[
235 case "${enableval}" in
236 yes)
237 enable_[]FEATURE[]=yes
238 ;;
239 no)
240 enable_[]FEATURE[]=no
241 ;;
242 *)
243 AC_MSG_ERROR([bad value ${enableval} for feature --$1])
244 ;;
245 esac
246
247 $3
248 ],[: dnl
249 $4
250 ])
251
252 AS_IF([test "$enable_[]FEATURE[]" = yes],[: dnl
253 $5
254 ],[: dnl
255 $6
256 ])
257
258 m4_popdef([FEATURE])dnl
259 ])
This page took 0.034664 seconds and 4 git commands to generate.