2 dnl These are the facilities for enable/disabling various features,
3 dnl and for collecting CFLAGS/LIBS and generating per feature .pc
4 dnl files, assembling list of source files to compile, creating
5 dnl cairo-features.h and other generated files, etc...
8 dnl ===========================================================================
11 dnl Define a macro to enable features
12 dnl - Macro: _CAIRO_ENABLE (ID, NAME, WHAT, DEFAULT, COMMANDS)
16 dnl ID is the sub-namespace in function names, eg. "ft" for cairo_ft_...
17 dnl NAME is the human-readable name of the feature, eg. "FreeType font"
18 dnl WHAT is the type of feature:
19 dnl "surface" for surface backends
20 dnl "font" for font backends
21 dnl "functions" for set of functions
22 dnl "" for private configurations
23 dnl DEFAULT is the default state of the feature:
24 dnl "no" for experimental features, eg. your favorite new backend
25 dnl "yes" for recommended features, eg. png functions
26 dnl "auto" for other supported features, eg. xlib surface backend
27 dnl "always" for mandatory features (can't be disabled), eg. image surface backend
28 dnl COMMANDS are run to check whether the feature can be enabled.
29 dnl They should set use_$(ID) to something other than yes if the
30 dnl feature cannot be built, eg. "no (requires SomeThing)". It then
31 dnl should also set $(ID)_REQUIRES/CFLAGS/LIBS/...
32 dnl appropriately. Look at the macro definition for more details,
33 dnl or ask if in doubt.
35 AC_DEFUN([_CAIRO_ENABLE],
40 m4_tolower(AS_TR_SH([$1])),
42 [m4_fatal([invalid feature name `$1'])]
44 m4_pushdef([cr_feature], [$1])dnl
45 m4_pushdef([cr_feature_name], m4_normalize([$2]))dnl
46 m4_pushdef([cr_feature_what], m4_normalize([$3]))dnl
47 m4_pushdef([cr_feature_default], m4_normalize([$4]))dnl
48 m4_pushdef([cr_feature_commands], [$5])dnl
50 m4_pushdef([cr_feature_arg], m4_translit([$1],_,-))dnl
52 dnl Sanity check default
59 [m4_fatal([Invalid default value `]cr_feature_default[' for feature `]cr_feature['])]
62 m4_if(cr_feature_default, [always],
66 AC_ARG_ENABLE(cr_feature_arg,
67 AS_HELP_STRING([--enable-]cr_feature_arg[=@<:@no/auto/yes@:>@],
68 [Enable cairo's ]cr_feature_name[ feature @<:@default=]cr_feature_default[@:>@]),
69 enable_$1=$enableval, enable_$1=cr_feature_default)
74 use_$1="no (disabled, use --enable-cr_feature_arg to enable)"
77 AC_MSG_CHECKING([for cairo's ]cr_feature_name[ feature])
81 CAIRO_FEATURE_VARS_FOREACH(cr_var, [cr_feature[_]cr_var[=]_CAIRO_SH_ESCAPE_UNQUOTED(m4_do([cr_var_default_]cr_var[_value]))]m4_newline)
85 AC_MSG_CHECKING([whether cairo's ]cr_feature_name[ feature could be enabled])
86 AC_MSG_RESULT([$use_$1])
88 AS_IF([test "x$enable_$1" = "xyes" -a "x$use_$1" != xyes],
91 m4_case(cr_feature_default,
92 [always], [mandatory],
95 ) cr_feature_name[ feature could not be enabled])
99 AC_MSG_ERROR([invalid argument passed to --enable-]cr_feature_arg[: `$use_$1', should be one of @<:@no/auto/yes@:>@])
102 AS_IF([test "x$use_$1" = "xyes"],
104 CAIRO_ACCUMULATED_FEATURE_VARS_FOREACH([cr_var],
106 CAIRO_ACCUMULATE_UNQUOTED_BEFORE(cr_var, [$]cr_feature[_]cr_var)
109 dnl If not enabled, empty the vars so no one accidentally uses them.
110 CAIRO_FEATURE_VARS_FOREACH([cr_var], [unset cr_feature[_]cr_var]m4_newline)
113 _CAIRO_FEATURE_HOOKS(cr_feature, cr_feature_name, cr_feature_default, cr_feature_what)dnl
115 m4_popdef([cr_feature])dnl
116 m4_popdef([cr_feature_name])dnl
117 m4_popdef([cr_feature_what])dnl
118 m4_popdef([cr_feature_default])dnl
119 m4_popdef([cr_feature_commands])dnl
120 m4_popdef([cr_feature_arg])dnl
124 dnl ===========================================================================
126 m4_define([_CAIRO_FEATURE_VARS])
129 dnl CAIRO_FEATURE_VARS_REGISTER(VARS, DEFAULT-VALUE=[])
131 dnl Registers variables to be collected from feature-enabling code segments.
132 dnl VARS should be a whitespace-separate list of variable names.
134 dnl DEFAULT-VALUE is m4 macros to set default value of VARS
136 AC_DEFUN([CAIRO_FEATURE_VARS_REGISTER],
138 m4_foreach_w([cr_var], [$1],
139 [m4_append_uniq([_CAIRO_FEATURE_VARS], cr_var, [ ],,
140 [m4_fatal([Feature variable `]cr_var[' already registered])])])dnl
141 m4_foreach_w([cr_var], [$1],
143 m4_define([cr_var_default_]cr_var[_value], m4_default([$2],[[$ac_env_[]]cr_feature[[]_]]cr_var[[_value]]))dnl
148 dnl CAIRO_FEATURE_VARS_FOREACH(VAR, COMMANDS)
150 dnl Run COMMANDS for each registered feature variable.
151 dnl Defines VAR to the variable being processed.
153 AC_DEFUN([CAIRO_FEATURE_VARS_FOREACH],
155 m4_foreach_w([$1], _CAIRO_FEATURE_VARS, [$2])dnl
159 dnl ===========================================================================
161 m4_define([_CAIRO_ACCUMULATORS])dnl
163 m4_define([_CAIRO_ACCUMULATORS_REGISTER],
165 m4_foreach_w([cr_var], [$1],
166 [m4_append_uniq([_CAIRO_ACCUMULATORS], cr_var, [ ],,
167 [m4_fatal([Accumulator `]cr_var[' already registered])])])dnl
168 m4_foreach_w([cr_var], [$1], [m4_define([cr_acc_]cr_var[_sep], [$2])])dnl
169 m4_foreach_w([cr_var], [$1], [[CAIRO_]cr_var[=$3]]m4_newline)dnl
170 m4_foreach_w([cr_var], [$1], [m4_pattern_allow([CAIRO_]cr_var)])dnl
173 m4_define([_CAIRO_SH_ESCAPE],['m4_bpatsubst([$1],['],[\\'])'])dnl
174 m4_define([_CAIRO_SH_ESCAPE_UNQUOTED],["m4_bpatsubst([$1],["],[\\"])"])dnl
177 dnl CAIRO_ACCUMULATORS_REGISTER(VARS, SEPARATOR=[], INITIAL-VALUE=[])
179 dnl Registers accumulators. An accumulator is a shell variable that can
180 dnl be accumulated to. The macros take care of adding a SEPARATOR between
181 dnl accumulated values.
183 dnl VARS should be a whitespace-separate list of variable names. The actual
184 dnl shell variable resulting for each variable is prefixed with CAIRO_.
186 AC_DEFUN([CAIRO_ACCUMULATORS_REGISTER],
188 _CAIRO_ACCUMULATORS_REGISTER([$1],[$2],_CAIRO_SH_ESCAPE([$3]))dnl
192 dnl Like CAIRO_ACCUMULATORS_REGISTER but INITIAL-VALUE is left unquoted,
193 dnl so it can reference other shell variables for example.
195 AC_DEFUN([CAIRO_ACCUMULATORS_REGISTER_UNQUOTED],
197 _CAIRO_ACCUMULATORS_REGISTER([$1],[$2],_CAIRO_SH_ESCAPE_UNQUOTED([$3]))dnl
200 m4_define([_CAIRO_ACCUMULATOR_CHECK],
202 m4_ifdef([cr_acc_$1_sep],,[m4_fatal([Accumulator `]$1[' not defined.])])dnl
205 m4_define([_CAIRO_ACCUMULATE],
207 _CAIRO_ACCUMULATOR_CHECK([$1])dnl
208 m4_ifval([$2], [$3]m4_newline)dnl
212 dnl CAIRO_ACCUMULATE(VAR, VALUE)
214 dnl Appends VALUE to accumulator VAR
216 AC_DEFUN([CAIRO_ACCUMULATE],
218 _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1="${CAIRO_$1}]m4_do([cr_acc_$1_sep])["_CAIRO_SH_ESCAPE([$2])])dnl
222 dnl CAIRO_ACCUMULATE_BEFORE(VAR, VALUE)
224 dnl Prepends VALUE to accumulator VAR
226 AC_DEFUN([CAIRO_ACCUMULATE_BEFORE],
228 _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1=_CAIRO_SH_ESCAPE([$2])"]m4_do([cr_acc_$1_sep])[${CAIRO_$1}"])dnl
231 m4_define([_CAIRO_ACCUMULATE_UNQUOTED],
233 _CAIRO_ACCUMULATOR_CHECK([$1])dnl
234 m4_ifval([$2], [m4_bmatch([$2],[[$]],[test -n "$2" &&]) $3]m4_newline)dnl
238 dnl CAIRO_ACCUMULATE_UNQUOTED(VAR, VALUE)
240 dnl Like CAIRO_ACCUMULATE but VALUE is left unquoted,
241 dnl so it can reference other shell variables for example.
243 AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED],
245 _CAIRO_ACCUMULATE_UNQUOTED([$1], [$2], [CAIRO_$1="${CAIRO_$1}]m4_do([cr_acc_$1_sep])["]_CAIRO_SH_ESCAPE_UNQUOTED([$2]))dnl
249 dnl CAIRO_ACCUMULATE_UNQUOTED_BEFORE(VAR, VALUE)
251 dnl Like CAIRO_ACCUMULATE_BEFORE but VALUE is left unquoted,
252 dnl so it can reference other shell variables for example.
254 AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED_BEFORE],
256 _CAIRO_ACCUMULATE_UNQUOTED([$1], [$2], [CAIRO_$1=]_CAIRO_SH_ESCAPE_UNQUOTED([$2])["]m4_do([cr_acc_$1_sep])[${CAIRO_$1}"])dnl
260 dnl CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED(VAR, VALUE)
262 dnl Like CAIRO_ACCUMULATE_UNQUOTED but VALUE is not tested for emptiness.
264 AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED],
266 _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1="${CAIRO_$1}]m4_do([cr_acc_$1_sep])["]_CAIRO_SH_ESCAPE_UNQUOTED([$2]))dnl
270 dnl CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED_BEFORE(VAR, VALUE)
272 dnl Like CAIRO_ACCUMULATE_UNQUOTED_BEFORE but VALUE is not tested for emptiness.
274 AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED_BEFORE],
276 _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1=]_CAIRO_SH_ESCAPE_UNQUOTED([$2])["]m4_do([cr_acc_$1_sep])[${CAIRO_$1}"])dnl
280 dnl CAIRO_ACCUMULATORS_FOREACH(VAR, COMMANDS)
282 dnl Run COMMANDS for each registered accumulator.
283 dnl Defines VAR to the accumulator being processed.
285 AC_DEFUN([CAIRO_ACCUMULATORS_FOREACH],
287 m4_foreach_w([$1], _CAIRO_ACCUMULATORS, [$2])dnl
291 dnl ===========================================================================
293 m4_define([_CAIRO_ACCUMULATED_FEATURE_VARS])dnl
296 dnl CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER(VARS, DEFAULT-VALUE=[], SEPARATOR=[], INITIAL-VALUE=[])
298 dnl Defines VARS as feature variables and accumulators. Also accumulates
299 dnl (prepending, not appending) feature values for VARS.
301 AC_DEFUN([CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER],
303 m4_foreach_w([cr_var], [$1],
304 [m4_append_uniq([_CAIRO_ACCUMULATED_FEATURE_VARS], cr_var, [ ],,
305 [m4_fatal([Accumulated feature variable `]cr_var[' already registered])])])dnl
306 CAIRO_FEATURE_VARS_REGISTER([$1],[$2])dnl
307 CAIRO_ACCUMULATORS_REGISTER_UNQUOTED([$1],[$3],[$4])dnl
311 dnl CAIRO_ACCUMULATED_FEATURE_VARS_FOREACH(VAR, COMMANDS)
313 dnl Run COMMANDS for each registered accumulated feature variable.
314 dnl Defines VAR to the variable being processed.
316 AC_DEFUN([CAIRO_ACCUMULATED_FEATURE_VARS_FOREACH],
318 m4_foreach_w([$1], _CAIRO_ACCUMULATED_FEATURE_VARS, [$2])dnl
321 dnl ===========================================================================
324 dnl CAIRO_FEATURE_IF_ENABLED(FEATURE=cr_feature, COMMANDS)
326 dnl Run COMMANDS if FEATURE is enabled.
328 AC_DEFUN([CAIRO_FEATURE_IF_ENABLED],
330 AS_IF([test "x$use_]m4_default([$1], cr_feature)[" = xyes], [$2], [$3])dnl
333 m4_define([_CAIRO_FEATURE_HOOK_MATCH_SH_BOOL],
337 [no], [AS_IF([test "x$2" != xyes], [:m4_newline()$3])],
338 [yes], [AS_IF([test "x$2" = xyes], [:m4_newline()$3])],
339 [m4_fatal([Invalid ENABLED value `]$1['])])dnl
342 m4_define([_CAIRO_FEATURE_HOOK_MATCH_M4],
348 [m4_bmatch([$1], [^!], [$3])])dnl
351 m4_define([_CAIRO_FEATURE_HOOKS])dnl
354 dnl CAIRO_FEATURE_HOOK_REGISTER(ENABLED, DEFAULT, WHAT, COMMANDS)
356 dnl ENABLED is the feature enabledness to match
357 dnl DEFAULT is the default value of features to match
358 dnl WHAT is the type of features to match
359 dnl COMMANDS is commands to run for matched features.
361 dnl Runs COMMANDS for features matching ENABLED, DEFAULT, and WHAT.
362 dnl Hooks are run for each feature in the order they are added.
364 dnl DEFAULT and WHAT are matched like this:
365 dnl [*] matches all values
366 dnl [val] matches [val]
367 dnl [!val] matches anything other than [val]
369 dnl ENABLED is matched like this:
370 dnl [yes] matches enabled features
371 dnl [no] matches disabled features
372 dnl [*] matches all features
374 dnl The following macros can be used in COMMANDS:
376 dnl cr_feature expands to the feature id, eg "ft"
377 dnl cr_feature_name expands to the human-readable name of the feature, eg. "FreeType font"
378 dnl cr_feature_default expands to the default state of the feature:
379 dnl "no" for experimental features, eg. your favorite new backend
380 dnl "yes" for recommended features, eg. png functions
381 dnl "auto" for other supported features, eg. xlib surface backend
382 dnl "always" for mandatory features (can't be disabled), eg. image surface backend
383 dnl cr_what expands to the type of feature:
384 dnl "surface" for surface backends
385 dnl "font" for font backends
386 dnl "functions" for set of functions
387 dnl "" for private configurations
389 dnl These four values are also set as $1 to $4. To know if feature was
390 dnl enabled from within COMMANDS, use CAIRO_FEATURE_IF_ENABLED:
392 dnl CAIRO_FEATURE_IF_ENABLED($1, [IF-ENABLED], [IF-DISABLED])
394 dnl or compare $use_$1 to string "yes". As in:
396 dnl AS_IF([test "x$use_$1" = "xyes"], [IF-ENABLED], [IF-DISABLED])
398 AC_DEFUN([CAIRO_FEATURE_HOOK_REGISTER],
400 m4_append([_CAIRO_FEATURE_HOOKS],
402 _CAIRO_FEATURE_HOOK_MATCH_M4([$2], cr_feature_default,
403 [_CAIRO_FEATURE_HOOK_MATCH_M4([$3], cr_feature_what,
404 [_CAIRO_FEATURE_HOOK_MATCH_SH_BOOL([$1], [$use_]cr_feature,