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