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 automatically generated help string
177 AC_DEFUN([OG_MULTIARG_HELP_STRINGS], [dnl
178 pushdef([OG_MULTIARG_ITEM], AS_HELP_STRING([], - $[1] for $[3]))
179 pushdef([OG_MULTIARG_MUTEX], [])
180 AS_HELP_STRING([], [Explanation of the items:])
182 popdef([OG_MULTIARG_MUTEX])
183 popdef([OG_MULTIARG_ITEM])
184 ])dnl OG_MULTIARG_HELP_STRINGS
186 dnl multiple arg form of OG_ARG_WITH, that is it accepts any (comma separated)
187 dnl combination of args
191 dnl $3 = default value, can be auto or none
192 dnl $3 = default value documentation
193 dnl $5 = allowed values [yes no] if empty, can be [og_any]
194 dnl $6 = actions in case option was set (old AC_ARG_WITH arg #3)
195 dnl $7 = actions in case option was not set (old AC_ARG_WITH arg #4)
197 AC_DEFUN([OG_MULTIARG_WITH], [# Option Group --with-$1 (multiarg)
198 ## announce this option as valid option
199 sxe_with_options="$sxe_with_options $1"
201 pushdef([og_group], [translit([$1],[-],[_])])
202 pushdef([og_DefVal],ifelse($3,,auto,$3))
203 pushdef([OG_MULTIARG_ITEM], dnl
204 _OG_MULTIARG_ITEM($1, $[1], $[2], $[3]))
205 pushdef([OG_MULTIARG_MUTEX], dnl
206 _OG_MULTIARG_MUTEX($1, $[1], $[2], $[3], $[4]))
208 popdef([OG_MULTIARG_ITEM])
209 popdef([OG_MULTIARG_MUTEX])
210 pushdef([OG_MULTIARG_ITEM], $[1])
211 pushdef([OG_MULTIARG_MUTEX], [])
216 patsubst([$5], [[ ]+], []),
218 ], [ ]), [^ +], []), [ +$], [])) dnl autoconf is soooo brilliant, is it not? :)
219 popdef([OG_MULTIARG_MUTEX])
220 popdef([OG_MULTIARG_ITEM])
222 pushdef([OG_HELP_STRING], [AS_HELP_STRING($[1], $[2])])
223 pushdef([og_desc], [dnl
224 patsubst([$2], [^[ ]AS_HELP_STRING], [AS_HELP_STRING])])
225 pushdef([og_helps], [dnl
226 patsubst(patsubst(patsubst([OG_MULTIARG_HELP_STRINGS($5)], [^[ ]+], []), [[ ]+$], []), [^[ ]*
229 dnl I personally shoot everybody who fiddles with the whitespace here!!!!
231 og_desc[]ifelse($5,[og_any],,[
232 AS_HELP_STRING([], OG_MULTIARG_POSSVAL(og_items))
233 AS_HELP_STRING([], OG_MULTIARG_MORE_ON_POSSVALS)
234 og_helps])[]ifelse($4,,,[dnl
235 AS_HELP_STRING([], [@<:@Default: $4@:>@])])],[
237 ## now process all supplied options (prepend the default opts)
238 OG_MULTIARG_PROCESS($1,og_DefVal,og_items)
242 with_[]og_group[]="og_DefVal"
243 OG_MULTIARG_PROCESS($1,og_DefVal,og_items)
248 dnl AC_MSG_RESULT([Option Group --with-$1 $og_with_$1])
256 dnl Print a summary for OG_ARG_WITH options
259 dnl $2 = headline for option
260 dnl $3 = per-line indentation
261 AC_DEFUN([OG_ARG_SUMMARY], [# Option Group --with-$1 (arg)
263 pushdef([og_group], [translit([$1],[-],[_])])
264 pushdef([indent], [ifelse([$3],[],[],[$3])])
266 if test -z "$og_[]og_group[]_opts"; then
267 if eval "test \"\$have_[]og_group\" = \"yes\" -a \
268 \"\$with_[]og_group\" = \"yes\""; then
270 elif eval "test \"\$have_[]og_group\" = \"yes\" -a \
271 \"\$with_[]og_group\" != \"yes\""; then
273 elif eval "test \"\$have_[]og_group\" != \"yes\" -a \
274 \"\$with_[]og_group\" = \"yes\""; then
279 echo "indent[$2]: $result"
282 for og_val in `expr "$og_[]og_group[]_opts"`; do
283 if test "$og_val" = "auto"; then
284 ## do not list auto as option
286 elif test "$have_[]og_group" = "$og_val" -a \
287 "$with_[]og_group" = "auto"; then
288 echo "indent[ ](X) $og_val (auto)"
289 elif test "$have_[]og_group" = "$og_val"; then
290 echo "indent[ ](X) $og_val"
292 echo "indent[ ]( ) $og_val"
301 dnl Print a summary for OG_MULTIARG_WITH options
304 dnl $2 = headline for option
305 AC_DEFUN([OG_MULTIARG_SUMMARY], [# Option Group --with-$1 (multiarg)
311 pushdef([og_group], [translit([$1],[-],[_])])
312 pushdef([og_items], [ifelse([$4],[],[$sxe_og_[]og_group[]_items],[$4])])
313 pushdef([og_mutices], [$sxe_og_[]og_group[]_mutices])
314 pushdef([indent], [ifelse([$3],[],[],[$3])])
316 for og_val in og_items; do
317 if eval "test \"\$have_[]og_group[]_${og_val}\" = \"yes\""; then
318 if eval "test \"\$with_[]og_group[]_${og_val}\" \
320 tmp_enabled="$tmp_enabled $og_val+"
322 tmp_enabled="$tmp_enabled $og_val"
326 \"\$sxe_og_[]og_group[]_${og_val}_mutexgroup\""; then
327 tmp_mtx_grp=$(eval "echo \$sxe_og_[]og_group[]_${og_val}_mutexgroup")
328 tmp_mtx_grp_desc=$(eval "echo \$sxe_og_[]og_group[]_${tmp_mtx_grp}_mutexdesc")
329 tmp_enabled_verb="$tmp_enabled_verb
330 echo \"[]indent[ ] + ${tmp_mtx_grp} (${tmp_mtx_grp_desc})\"
331 echo \"[]indent[ ] (X) \$sxe_og_[]og_group[]_${og_val}_short \
332 (\$sxe_og_[]og_group[]_${og_val}_desc)\""
333 tmp_enabled_verb="$tmp_enabled_verb
334 eval \"\${sum_[]og_group[]_omitted_${tmp_mtx_grp}_verb}\""
339 tmp_enabled_verb="$tmp_enabled_verb
340 echo \"[]indent[ ] - \$sxe_og_[]og_group[]_${og_val}_short \
341 (\$sxe_og_[]og_group[]_${og_val}_desc)\""
343 elif eval "test \"\$with_[]og_group[]_${og_val}\" = \"yes\" \
344 -a -n \"\$omit_[]og_group[]_${og_val}_in_favour_of\" \
345 -a -n \"\$sxe_og_[]og_group[]_${og_val}_mutexgroup\""; then
346 tmp_omitted="$tmp_omitted $og_val"
347 tmp_mtx_grp=$(eval "echo \$sxe_og_[]og_group[]_${og_val}_mutexgroup")
349 eval sum_[]og_group[]_omitted_${tmp_mtx_grp}_verb="\"\$sum_[]og_group[]_omitted_${tmp_mtx_grp}_verb
350 echo \\\"[]indent[ ] ( ) \$sxe_og_[]og_group[]_${og_val}_short \
351 (\$sxe_og_[]og_group[]_${og_val}_desc) available but omitted\\\"\""
353 elif eval "test \"\$with_[]og_group[]_${og_val}\" = \"yes\""; then
354 tmp_disabled="$tmp_disabled $og_val*"
356 tmp_disabled="$tmp_disabled $og_val"
360 if test -z "$tmp_enabled"; then
363 if test -z "$tmp_disabled"; then
366 if test -z "$tmp_omitted"; then
371 echo "indent Enabled [$2]: $tmp_enabled"
372 eval "$tmp_enabled_verb"
373 if test -n "$sxe_og_[]og_group[]_mutices"; then
374 echo "indent Omitted [$2]: $tmp_omitted"
375 dnl eval "$tmp_omitted_verb"
377 echo "indent Disabled [$2]: $tmp_disabled"
385 AC_DEFUN([_OG_MULTIARG_ITEM], [dnl
386 # $1 option group name,
388 # $3 short description
389 # $4 long description
390 pushdef([og_group], [translit([$1],[-],[_])])
391 sxe_og_[]og_group[]_items="$sxe_og_[]og_group[]_items $2"
392 sxe_og_[]og_group[]_[]$2[]_short="[$3]"
393 sxe_og_[]og_group[]_[]$2[]_desc="[$4]"
397 AC_DEFUN([_OG_MULTIARG_MUTEX], [dnl
398 # $1 option group name,
400 # $3 mutex description
401 # $4 item names in descending order of favouriteness
402 pushdef([og_group], [translit([$1],[-],[_])])
403 sxe_og_[]og_group[]_mutices="$sxe_og_[]og_group[]_mutices $2"
404 sxe_og_[]og_group[]_[]$2[]_mutexdesc="[$3]"
405 sxe_og_[]og_group[]_[]$2[]_mutexitems="[$4]"
406 for og_item in [$4]; do
407 ## bind each mutex item to name the mutex group it belongs to
408 eval "sxe_og_[]og_group[]_${og_item}_mutexgroup=\"[$2]\""
413 AC_DEFUN([OG_CHECK_OPTION], [## arg #1 is with or enable, arg #2 the option
414 pushdef([og_group], [$1])
416 for __opt in $sxe_[]og_group[]_options; do
417 if test "[$2]" = "$__opt"; then
422 if test "$__foundp" != "nil"; then
433 AC_DEFUN([OG_WARN_OBSOLETE_OPTION], [dnl
434 ## arg1 is the --with option
435 ## arg2 is the instead string
436 ## arg3 is the penalty time, 10 seconds by default
437 pushdef([OG_OPT], [$1])
438 pushdef([OG_INSTEAD], [$2])
439 pushdef([OG_PENALTY_TIME], ifelse($3,,10,$3))
440 pushdef([OG_PENALTY_TIME_UNIT], ifelse(OG_PENALTY_TIME,1,[second],[seconds]))
442 AC_MSG_WARN([You've just been caught using an obsolete option.])
443 AC_MSG_WARN([Listen, mate, thou shalt not use ]OG_OPT[,])
444 AC_MSG_WARN([as it will disappear soon and thence cause more trouble.])
445 AC_MSG_WARN([To migrate cleanly you should use instead:]
448 AC_MSG_WARN([To substantiate my seriousness I will go on strike for ]
449 OG_PENALTY_TIME[ ]OG_PENALTY_TIME_UNIT[ now!])
450 sleep OG_PENALTY_TIME
455 popdef([OG_PENALTY_TIME])
456 popdef([OG_PENALTY_TIME_UNIT])
457 ])dnl OG_WARN_OBSOLETE_OPTION