1 dnl sxe-option-groups.m4 --- Option group miracle
3 dnl Copyright (C) 2005, 2006, 2007, 2008 Sebastian Freundt
5 dnl Author: Sebastian Freundt <hroptatyr@sxemacs.org>
7 dnl This file is part of SXEmacs.
10 AC_DEFUN([OG_ARG_POSSVAL], [dnl
11 [Possible arguments:]ifelse($2,,,[ for $2])[]dnl
18 [ ]either `yes' or `no'],[dnl
19 [ ]one of [`]patsubst([$1],[ ],['[,] `])[']])])
21 AC_DEFUN([OG_OPTION_GROUP], [dnl
22 AC_ARG_WITH(xyzoptiongroup,[
24 patsubst([$1],[.],[=])])])
26 pushdef([OG_ERROR_ADDITIONAL_VERBOSITY], [dnl
27 - If you do not see or know what the option --with-$1 is all about
28 consider to consult $sxe_srcdir/configure --help.
29 - Also SXEmacs comes with a sophisticated set of default values which
30 run out of the box on most machines so retry your configure line
31 WITHOUT this option at all.
32 - If you used to pass the option `--with-$1=$withval' and it formerly
33 has been accepted please consult $sxe_srcdir/configure --help and perhaps
35 - If you are absolutely sure that `$withval' _should_ work[,] try again!
36 .oO(and see me barf again, too)
39 dnl borrowed from the openldap crew, slightly modified
40 dnl --------------------------------------------------------------------
41 dnl Restricted form of AC_ARG_WITH that limits user options
45 dnl $3 = default value, can be auto or none
46 dnl $4 = default value documentation
47 dnl $5 = allowed values [yes no] if empty, can be [og_any]
48 dnl $6 = actions in case option was set (old AC_ARG_WITH arg #3)
49 dnl $7 = actions in case option was not set (old AC_ARG_WITH arg #4)
50 AC_DEFUN([OG_ARG_WITH], [# Option Group --with-$1
51 ## announce this option as valid option
52 pushdef([og_group], translit([$1], [-], [_]))
54 sxe_with_options="$sxe_with_options $1"
55 og_[]og_group[]_opts="$5"
58 [$2]ifelse($5,[og_any],,[
59 AS_HELP_STRING([], (OG_ARG_POSSVAL($5)))])[]ifelse($4,,,[
60 AS_HELP_STRING([], [@<:@Default: $4@:>@])])],[
63 for og_val in ifelse($5,,[yes no],[$5]) ; do
64 if test "$withval" = "$og_val" ; then
68 if test "$og_arg" = "invalid" ; then
69 AS_MESSAGE(Wait a moment ... Are you nuts?)
70 if test "`echo $withval | grep ','`"; then
72 Bad multiple value `$withval' for --with-$1.
74 AS_ESCAPE(OG_ARG_POSSVAL($5,[--with-$1]), [`])
75 (and remember do NOT specify 2 or 3 or 4 or more values, ONE is enough! Believe me!)
77 AS_ESCAPE(OG_ERROR_ADDITIONAL_VERBOSITY($1), [`])])])
79 elif test "$withval" = "foo"; then
81 --with-$1=foo?! In your dreams, man!
85 Bad value `$withval' for --with-$1.
87 AS_ESCAPE(OG_ARG_POSSVAL($5,[--with-$1]), [`])
88 (and nothing else, and especially not `$withval'!)
90 AS_ESCAPE(OG_ERROR_ADDITIONAL_VERBOSITY($1), [`])])])
93 with_[]og_group[]="$withval"
96 with_[]og_group[]=ifelse($3,,"",$3,none,"",$3,auto,"",["$3"])
98 dnl AC_MSG_RESULT([Option Group --with-$1 $og_with_$1])
103 dnl helper funs for multi arg case
104 dnl ==============================
105 dnl $1 - possible option values
107 AC_DEFUN([OG_MULTIARG_POSSVAL], [dnl
108 [Possible arguments:]ifelse($2,,,[ for $2])[]dnl
115 [ ]either `all' or `none'],[dnl
116 [ ]`all' or `none' as the first argument[,] followed by dnl
117 any (comma-separated) combination out of [`(no)]patsubst([$1],[ ],['[,] `(no)])['].])
118 ])dnl OG_MULTIARG_POSSVAL
120 AC_DEFUN([OG_MULTIARG_MORE_ON_POSSVALS], [dnl
121 The `no' prefix hereby means not to include the item in question. dnl
122 E.g. combinations like `all[,]nofoo[,]nobar' are allowed to select dnl
123 everything but foo and bar. dnl
124 Later options in the chain override earlier ones. dnl
125 If `all' or `none' (as first argument) in the chain are omitted dnl
126 all items are supposed to be specified relative to the default value.])
130 dnl $2 = default value, can be auto, all, none, or any combination of $3
131 dnl $3 = allowed values, can be [og_any]
132 AC_DEFUN([OG_MULTIARG_PROCESS], [dnl
133 pushdef([og_group], [translit([$1],[-],[_])])
135 for og_val in $2 `echo "$withval" | sed -e 's/,/ /g'`; do
138 dnl all and none are only permitted as the first in the list.
139 no | none ) new_default=no ;;
140 yes | all | auto ) new_default=yes ;;
144 translit([$3],[ ],[|]) )
146 eval with_[]og_group[]_${og_val}=yes;;
147 [no]patsubst([$3],[ ],[|no]) )
149 eval `echo $og_val | sed -e 's/^no/with_[]og_group[]_/'`=no
152 if test -n "$new_default"; then
153 dnl for og_item in "[$3]"; do
154 dnl with_[]og_group[]_$og_item="$new_default"
156 with_[]og_group[]_[]patsubst([$3],[ ],[=$new_default; with_[]og_group[]_])[]=$new_default
160 if test "$og_arg" = "invalid" ; then
161 AS_MESSAGE(Wait a moment ... dnl
162 Find a coffee factory! Drink it! And now listen:)
164 Bad value `$og_val' for --with-$1.
166 m4_text_wrap(OG_MULTIARG_POSSVAL($3, [--with-$1])
167 OG_MULTIARG_MORE_ON_POSSVALS)
169 OG_ERROR_ADDITIONAL_VERBOSITY($1)
176 dnl helper for OG_MULTIARG_HELP_STINGS
177 dnl mimicking AS_HELP_STRING here
178 dnl we can't use AS_HELP_STRING (or m4_text_wrap) directly because
179 dnl we need $1 and $2 expanded and indirected, a bit like a lisp `
180 AC_DEFUN([_OG_MULTIARG_ITEM_EXPL], [dnl
182 ])dnl _OG_MULTIARG_ITEM_EXPL
184 dnl automatically generated help string
185 AC_DEFUN([OG_MULTIARG_HELP_STRINGS], [dnl
186 pushdef([OG_MULTIARG_ITEM],
187 _OG_MULTIARG_ITEM_EXPL($[1], $[3]))
188 pushdef([OG_MULTIARG_MUTEX], [])
189 AS_HELP_STRING([], [Explanation of the items:])
191 popdef([OG_MULTIARG_MUTEX])
192 popdef([OG_MULTIARG_ITEM])
193 ])dnl OG_MULTIARG_HELP_STRINGS
195 dnl multiple arg form of OG_ARG_WITH, that is it accepts any (comma separated)
196 dnl combination of args
200 dnl $3 = default value, can be auto or none
201 dnl $3 = default value documentation
202 dnl $5 = allowed values [yes no] if empty, can be [og_any]
203 dnl $6 = actions in case option was set (old AC_ARG_WITH arg #3)
204 dnl $7 = actions in case option was not set (old AC_ARG_WITH arg #4)
206 AC_DEFUN([OG_MULTIARG_WITH], [# Option Group --with-$1 (multiarg)
207 ## announce this option as valid option
208 sxe_with_options="$sxe_with_options $1"
210 pushdef([og_group], [translit([$1],[-],[_])])
211 pushdef([og_DefVal],ifelse($3,,auto,$3))
212 pushdef([OG_MULTIARG_ITEM], dnl
213 _OG_MULTIARG_ITEM($1, $[1], $[2], $[3]))
214 pushdef([OG_MULTIARG_MUTEX], dnl
215 _OG_MULTIARG_MUTEX($1, $[1], $[2], $[3], $[4]))
217 popdef([OG_MULTIARG_ITEM])
218 popdef([OG_MULTIARG_MUTEX])
219 pushdef([OG_MULTIARG_ITEM], $[1])
220 pushdef([OG_MULTIARG_MUTEX], [])
225 patsubst([$5], [[ ]+], []),
227 ], [ ]), [^ +], []), [ +$], [])) dnl autoconf is soooo brilliant, is it not? :)
228 popdef([OG_MULTIARG_MUTEX])
229 popdef([OG_MULTIARG_ITEM])
231 pushdef([OG_HELP_STRING], [AS_HELP_STRING($[1], $[2])])
232 pushdef([og_desc], [dnl
233 patsubst([$2], [^[ ]AS_HELP_STRING], [AS_HELP_STRING])])
234 pushdef([og_helps], [dnl
235 patsubst(patsubst(patsubst([OG_MULTIARG_HELP_STRINGS($5)], [^[ ]+], []), [[ ]+$], []), [^[ ]*
238 dnl I personally shoot everybody who fiddles with the whitespace here!!!!
240 og_desc[]ifelse($5,[og_any],,[
241 AS_HELP_STRING([], OG_MULTIARG_POSSVAL(og_items))
242 AS_HELP_STRING([], OG_MULTIARG_MORE_ON_POSSVALS)
243 og_helps])[]ifelse($4,,,[dnl
244 AS_HELP_STRING([], [@<:@Default: $4@:>@])])],[
246 ## now process all supplied options (prepend the default opts)
247 OG_MULTIARG_PROCESS($1,og_DefVal,og_items)
251 with_[]og_group[]="og_DefVal"
252 OG_MULTIARG_PROCESS($1,og_DefVal,og_items)
257 dnl AC_MSG_RESULT([Option Group --with-$1 $og_with_$1])
265 dnl Print a summary for OG_ARG_WITH options
268 dnl $2 = headline for option
269 dnl $3 = per-line indentation
270 AC_DEFUN([OG_ARG_SUMMARY], [# Option Group --with-$1 (arg)
272 pushdef([og_group], [translit([$1],[-],[_])])
273 pushdef([indent], [ifelse([$3],[],[],[$3])])
275 if test -z "$og_[]og_group[]_opts"; then
276 if eval "test \"\$have_[]og_group\" = \"yes\" -a \
277 \"\$with_[]og_group\" = \"yes\""; then
279 elif eval "test \"\$have_[]og_group\" = \"yes\" -a \
280 \"\$with_[]og_group\" != \"yes\""; then
282 elif eval "test \"\$have_[]og_group\" != \"yes\" -a \
283 \"\$with_[]og_group\" = \"yes\""; then
288 echo "indent[$2]: $result"
291 for og_val in `expr "$og_[]og_group[]_opts"`; do
292 if test "$og_val" = "auto"; then
293 ## do not list auto as option
295 elif test "$have_[]og_group" = "$og_val" -a \
296 "$with_[]og_group" = "auto"; then
297 echo "indent[ ](X) $og_val (auto)"
298 elif test "$have_[]og_group" = "$og_val"; then
299 echo "indent[ ](X) $og_val"
301 echo "indent[ ]( ) $og_val"
310 dnl Print a summary for OG_MULTIARG_WITH options
313 dnl $2 = headline for option
314 AC_DEFUN([OG_MULTIARG_SUMMARY], [# Option Group --with-$1 (multiarg)
320 pushdef([og_group], [translit([$1],[-],[_])])
321 pushdef([og_items], [ifelse([$4],[],[$sxe_og_[]og_group[]_items],[$4])])
322 pushdef([og_mutices], [$sxe_og_[]og_group[]_mutices])
323 pushdef([indent], [ifelse([$3],[],[],[$3])])
325 for og_val in og_items; do
326 if eval "test \"\$have_[]og_group[]_${og_val}\" = \"yes\""; then
327 if eval "test \"\$with_[]og_group[]_${og_val}\" \
329 tmp_enabled="$tmp_enabled $og_val+"
331 tmp_enabled="$tmp_enabled $og_val"
335 \"\$sxe_og_[]og_group[]_${og_val}_mutexgroup\""; then
336 tmp_mtx_grp=$(eval "echo \$sxe_og_[]og_group[]_${og_val}_mutexgroup")
337 tmp_mtx_grp_desc=$(eval "echo \$sxe_og_[]og_group[]_${tmp_mtx_grp}_mutexdesc")
338 tmp_enabled_verb="$tmp_enabled_verb
339 echo \"[]indent[ ] + ${tmp_mtx_grp} (${tmp_mtx_grp_desc})\"
340 echo \"[]indent[ ] (X) \$sxe_og_[]og_group[]_${og_val}_short \
341 (\$sxe_og_[]og_group[]_${og_val}_desc)\""
342 tmp_enabled_verb="$tmp_enabled_verb
343 eval \"\${sum_[]og_group[]_omitted_${tmp_mtx_grp}_verb}\""
348 tmp_enabled_verb="$tmp_enabled_verb
349 echo \"[]indent[ ] - \$sxe_og_[]og_group[]_${og_val}_short \
350 (\$sxe_og_[]og_group[]_${og_val}_desc)\""
352 elif eval "test \"\$with_[]og_group[]_${og_val}\" = \"yes\" \
353 -a -n \"\$omit_[]og_group[]_${og_val}_in_favour_of\" \
354 -a -n \"\$sxe_og_[]og_group[]_${og_val}_mutexgroup\""; then
355 tmp_omitted="$tmp_omitted $og_val"
356 tmp_mtx_grp=$(eval "echo \$sxe_og_[]og_group[]_${og_val}_mutexgroup")
358 eval sum_[]og_group[]_omitted_${tmp_mtx_grp}_verb="\"\$sum_[]og_group[]_omitted_${tmp_mtx_grp}_verb
359 echo \\\"[]indent[ ] ( ) \$sxe_og_[]og_group[]_${og_val}_short \
360 (\$sxe_og_[]og_group[]_${og_val}_desc) available but omitted\\\"\""
362 elif eval "test \"\$with_[]og_group[]_${og_val}\" = \"yes\""; then
363 tmp_disabled="$tmp_disabled $og_val*"
365 tmp_disabled="$tmp_disabled $og_val"
369 if test -z "$tmp_enabled"; then
372 if test -z "$tmp_disabled"; then
375 if test -z "$tmp_omitted"; then
380 echo "indent Enabled [$2]: $tmp_enabled"
381 eval "$tmp_enabled_verb"
382 if test -n "$sxe_og_[]og_group[]_mutices"; then
383 echo "indent Omitted [$2]: $tmp_omitted"
384 dnl eval "$tmp_omitted_verb"
386 echo "indent Disabled [$2]: $tmp_disabled"
394 AC_DEFUN([_OG_MULTIARG_ITEM], [dnl
395 # $1 option group name,
397 # $3 short description
398 # $4 long description
399 pushdef([og_group], [translit([$1],[-],[_])])
400 sxe_og_[]og_group[]_items="$sxe_og_[]og_group[]_items $2"
401 sxe_og_[]og_group[]_[]$2[]_short="[$3]"
402 sxe_og_[]og_group[]_[]$2[]_desc="[$4]"
406 AC_DEFUN([_OG_MULTIARG_MUTEX], [dnl
407 # $1 option group name,
409 # $3 mutex description
410 # $4 item names in descending order of favouriteness
411 pushdef([og_group], [translit([$1],[-],[_])])
412 sxe_og_[]og_group[]_mutices="$sxe_og_[]og_group[]_mutices $2"
413 sxe_og_[]og_group[]_[]$2[]_mutexdesc="[$3]"
414 sxe_og_[]og_group[]_[]$2[]_mutexitems="[$4]"
415 for og_item in [$4]; do
416 ## bind each mutex item to name the mutex group it belongs to
417 eval "sxe_og_[]og_group[]_${og_item}_mutexgroup=\"[$2]\""
422 AC_DEFUN([OG_CHECK_OPTION], [## arg #1 is with or enable, arg #2 the option
423 pushdef([og_group], [$1])
425 for __opt in $sxe_[]og_group[]_options; do
426 if test "[$2]" = "$__opt"; then
431 if test "$__foundp" != "nil"; then
442 AC_DEFUN([OG_WARN_OBSOLETE_OPTION], [dnl
443 ## arg1 is the --with option
444 ## arg2 is the instead string
445 ## arg3 is the penalty time, 10 seconds by default
446 pushdef([OG_OPT], [$1])
447 pushdef([OG_INSTEAD], [$2])
448 pushdef([OG_PENALTY_TIME], ifelse($3,,10,$3))
449 pushdef([OG_PENALTY_TIME_UNIT], ifelse(OG_PENALTY_TIME,1,[second],[seconds]))
451 AC_MSG_WARN([You've just been caught using an obsolete option.])
452 AC_MSG_WARN([Listen, mate, thou shalt not use ]OG_OPT[,])
453 AC_MSG_WARN([as it will disappear soon and thence cause more trouble.])
454 AC_MSG_WARN([To migrate cleanly you should use instead:]
457 AC_MSG_WARN([To substantiate my seriousness I will go on strike for ]
458 OG_PENALTY_TIME[ ]OG_PENALTY_TIME_UNIT[ now!])
459 sleep OG_PENALTY_TIME
464 popdef([OG_PENALTY_TIME])
465 popdef([OG_PENALTY_TIME_UNIT])
466 ])dnl OG_WARN_OBSOLETE_OPTION