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