Initial git import
[sxemacs] / m4 / sxe-option-groups.m4
1 dnl sxe-option-groups.m4 --- Option group miracle
2 dnl
3 dnl Copyright (C) 2005, 2006, 2007, 2008 Sebastian Freundt
4 dnl
5 dnl Author: Sebastian Freundt <hroptatyr@sxemacs.org>
6 dnl
7 dnl This file is part of SXEmacs.
8
9
10 AC_DEFUN([OG_ARG_POSSVAL], [dnl
11 [Possible arguments:]ifelse($2,,,[ for $2])[]dnl
12 ifelse(dnl
13 $1,[og_any], [dnl
14 [ anything]],
15 $1,[og_file], [dnl
16 [ ]any file names],
17 $1,,[dnl
18 [ ]either `yes' or `no'],[dnl
19 [ ]one of [`]patsubst([$1],[ ],['[,] `])[']])])
20
21 AC_DEFUN([OG_OPTION_GROUP], [dnl
22 AC_ARG_WITH(xyzoptiongroup,[
23 [$1]
24 patsubst([$1],[.],[=])])])
25
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
34   update your scripts.
35 - If you are absolutely sure that `$withval' _should_ work[,] try again!
36   .oO(and see me barf again, too)
37 ])
38
39 dnl borrowed from the openldap crew, slightly modified
40 dnl --------------------------------------------------------------------
41 dnl Restricted form of AC_ARG_WITH that limits user options
42 dnl
43 dnl $1 = option name
44 dnl $2 = help-string
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], [-], [_]))
53
54         sxe_with_options="$sxe_with_options $1"
55         og_[]og_group[]_opts="$5"
56
57         AC_ARG_WITH($1,[
58 [$2]ifelse($5,[og_any],,[
59 AS_HELP_STRING([], (OG_ARG_POSSVAL($5)))])[]ifelse($4,,,[
60 AS_HELP_STRING([], [@<:@Default: $4@:>@])])],[
61         ifelse($5,og_any,,[
62                 og_arg=invalid
63                 for og_val in ifelse($5,,[yes no],[$5]) ; do
64                         if test "$withval" = "$og_val" ; then
65                                 og_arg="$og_val"
66                         fi
67                 done
68                 if test "$og_arg" = "invalid" ; then
69                         AS_MESSAGE(Wait a moment ... Are you nuts?)
70                         if test "`echo $withval | grep ','`"; then
71                                 AC_MSG_ERROR([dnl
72 Bad multiple value `$withval' for --with-$1.
73 ifelse($2,[og_any],,[
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!)
76
77 AS_ESCAPE(OG_ERROR_ADDITIONAL_VERBOSITY($1), [`])])])
78
79                         elif test "$withval" = "foo"; then
80                                 AC_MSG_ERROR([dnl
81 --with-$1=foo?! In your dreams, man!
82                         ])
83                         else
84                                 AC_MSG_ERROR([dnl
85 Bad value `$withval' for --with-$1.
86 ifelse($5,[og_any],,[
87 AS_ESCAPE(OG_ARG_POSSVAL($5,[--with-$1]), [`])
88 (and nothing else, and especially not `$withval'!)
89
90 AS_ESCAPE(OG_ERROR_ADDITIONAL_VERBOSITY($1), [`])])])
91                         fi
92                 fi])
93         with_[]og_group[]="$withval"
94         $6
95 ],[dnl
96         with_[]og_group[]=ifelse($3,,"",$3,none,"",$3,auto,"",["$3"])
97         $7])dnl
98 dnl AC_MSG_RESULT([Option Group --with-$1 $og_with_$1])
99 # end --with-$1
100         popdef([og_group])
101 ])dnl
102
103 dnl helper funs for multi arg case
104 dnl ==============================
105 dnl $1 - possible option values
106 dnl $2 - option name
107 AC_DEFUN([OG_MULTIARG_POSSVAL], [dnl
108 [Possible arguments:]ifelse($2,,,[ for $2])[]dnl
109 ifelse(dnl
110 $1,[og_any], [dnl
111 [ anything]],
112 $1,[og_file], [dnl
113 [ ]any file names],
114 $1,,[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
119
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.])
127
128 dnl
129 dnl $1 = option name
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],[-],[_])])
134         new_default=
135         for og_val in $2 `echo "$withval" | sed -e 's/,/ /g'`; do
136                 og_arg=invalid
137                 case "$og_val" in
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 ;;
141                 esac
142                 ifelse($3,,,[
143                         case "$og_val" in
144                         translit([$3],[ ],[|]) )
145                                 og_arg=valid
146                                 eval with_[]og_group[]_${og_val}=yes;;
147                         [no]patsubst([$3],[ ],[|no]) )
148                                 og_arg=valid
149                                 eval `echo $og_val | sed -e 's/^no/with_[]og_group[]_/'`=no
150                         esac
151                 ])
152                 if test -n "$new_default"; then
153 dnl                     for og_item in "[$3]"; do
154 dnl                             with_[]og_group[]_$og_item="$new_default"
155 dnl                     done
156                         with_[]og_group[]_[]patsubst([$3],[ ],[=$new_default; with_[]og_group[]_])[]=$new_default
157                                 new_default=
158                                 og_arg=valid
159                         fi
160                 if test "$og_arg" = "invalid" ; then
161                         AS_MESSAGE(Wait a moment ... dnl
162 Find a coffee factory! Drink it! And now listen:)
163                         AC_MSG_ERROR(dnl
164 Bad value `$og_val' for --with-$1.
165
166 m4_text_wrap(OG_MULTIARG_POSSVAL($3, [--with-$1])
167 OG_MULTIARG_MORE_ON_POSSVALS)
168
169 OG_ERROR_ADDITIONAL_VERBOSITY($1)
170 )
171                 fi
172         done
173         popdef([og_group])
174 ])
175
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:])
181 $1
182         popdef([OG_MULTIARG_MUTEX])
183         popdef([OG_MULTIARG_ITEM])
184 ])dnl OG_MULTIARG_HELP_STRINGS
185
186 dnl multiple arg form of OG_ARG_WITH, that is it accepts any (comma separated)
187 dnl combination of args
188 dnl
189 dnl $1 = option name
190 dnl $2 = help-string
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)
196 dnl improved version
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"
200
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]))
207         $5
208         popdef([OG_MULTIARG_ITEM])
209         popdef([OG_MULTIARG_MUTEX])
210         pushdef([OG_MULTIARG_ITEM], $[1])
211         pushdef([OG_MULTIARG_MUTEX], [])
212         pushdef([og_items],
213                 patsubst(
214                         patsubst(
215                                 patsubst(
216                                         patsubst([$5], [[        ]+], []),
217                         [
218 ], [ ]), [^ +], []), [ +$], [])) dnl autoconf is soooo brilliant, is it not? :)
219         popdef([OG_MULTIARG_MUTEX])
220         popdef([OG_MULTIARG_ITEM])
221
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)], [^[  ]+], []), [[    ]+$], []), [^[  ]*
227 ], [])])
228
229         dnl I personally shoot everybody who fiddles with the whitespace here!!!!
230         AC_ARG_WITH($1, [
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@:>@])])],[
236
237         ## now process all supplied options (prepend the default opts)
238         OG_MULTIARG_PROCESS($1,og_DefVal,og_items)
239         $6
240 ],[
241         withval=
242         with_[]og_group[]="og_DefVal"
243         OG_MULTIARG_PROCESS($1,og_DefVal,og_items)
244         $7
245         # end --with-$1
246 ])
247
248         dnl AC_MSG_RESULT([Option Group --with-$1 $og_with_$1])
249         popdef([og_desc])
250         popdef([og_helps])
251         popdef([og_items])
252         popdef([og_DefVal])
253         popdef([og_group])
254 ])dnl
255
256 dnl Print a summary for OG_ARG_WITH options
257 dnl
258 dnl $1 = option name
259 dnl $2 = headline for option
260 dnl $3 = per-line indentation
261 AC_DEFUN([OG_ARG_SUMMARY], [# Option Group --with-$1 (arg)
262         result="uncertain"
263         pushdef([og_group], [translit([$1],[-],[_])])
264         pushdef([indent], [ifelse([$3],[],[],[$3])])
265
266         if test -z "$og_[]og_group[]_opts"; then
267                 if eval "test \"\$have_[]og_group\" = \"yes\" -a \
268                         \"\$with_[]og_group\" = \"yes\""; then
269                         result="yes"
270                 elif eval "test \"\$have_[]og_group\" = \"yes\" -a \
271                         \"\$with_[]og_group\" != \"yes\""; then
272                         result="yes+"
273                 elif eval "test \"\$have_[]og_group\" != \"yes\" -a \
274                         \"\$with_[]og_group\" = \"yes\""; then
275                         result="no*"
276                 else
277                         result="no"
278                 fi
279                 echo "indent[$2]: $result"
280         else
281                 echo "indent[$2]:"
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
285                                 :
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"
291                         else
292                                 echo "indent[  ]( ) $og_val"
293                         fi
294                 done
295         fi
296
297         popdef([indent])
298         popdef([og_group])
299 ])
300
301 dnl Print a summary for OG_MULTIARG_WITH options
302 dnl
303 dnl $1 = option name
304 dnl $2 = headline for option
305 AC_DEFUN([OG_MULTIARG_SUMMARY], [# Option Group --with-$1 (multiarg)
306         tmp_enabled=
307         tmp_enabled_verb=
308         tmp_disabled=
309         tmp_omitted=
310         tmp_omitted_verb=
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])])
315
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}\" \
319                            != \"yes\""; then
320                                 tmp_enabled="$tmp_enabled $og_val+"
321                         else
322                                 tmp_enabled="$tmp_enabled $og_val"
323                         fi
324
325                         if eval "test -n \
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}\""
335                                 tmp_mtx_grp=
336                                 tmp_mtx_grp_desc=
337
338                         else
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)\""
342                         fi
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")
348
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\\\"\""
352                         tmp_mtx_grp=
353                 elif eval "test \"\$with_[]og_group[]_${og_val}\" = \"yes\""; then
354                         tmp_disabled="$tmp_disabled $og_val*"
355                 else
356                         tmp_disabled="$tmp_disabled $og_val"
357                 fi
358         done
359
360         if test -z "$tmp_enabled"; then
361                 tmp_enabled="None."
362         fi
363         if test -z "$tmp_disabled"; then
364                 tmp_disabled="None."
365         fi
366         if test -z "$tmp_omitted"; then
367                 tmp_omitted="None."
368         fi
369
370         echo "indent[$2]:"
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"
376         fi
377         echo "indent  Disabled [$2]: $tmp_disabled"
378
379         popdef([indent])
380         popdef([og_mutices])
381         popdef([og_items])
382         popdef([og_group])
383 ])
384
385 AC_DEFUN([_OG_MULTIARG_ITEM], [dnl
386         # $1 option group name,
387         # $2 item 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]"
394         popdef([og_group])
395 ])
396
397 AC_DEFUN([_OG_MULTIARG_MUTEX], [dnl
398         # $1 option group name,
399         # $2 mutex 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]\""
409         done
410         popdef([og_group])
411 ])
412
413 AC_DEFUN([OG_CHECK_OPTION], [## arg #1 is with or enable, arg #2 the option
414         pushdef([og_group], [$1])
415         __foundp="nil"
416         for __opt in $sxe_[]og_group[]_options; do
417                 if test "[$2]" = "$__opt"; then
418                         __foundp="t"
419                         break
420                 fi
421         done
422         if test "$__foundp" != "nil"; then
423                 [$3]
424                 :
425         else
426                 [$4]
427                 :
428         fi
429         popdef([og_group])
430 ])
431
432
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]))
441
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:]
446         OG_INSTEAD[])
447         echo ""
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
451         echo ""
452
453         popdef([OG_OPT])
454         popdef([OG_INSTEAD])
455         popdef([OG_PENALTY_TIME])
456         popdef([OG_PENALTY_TIME_UNIT])
457 ])dnl OG_WARN_OBSOLETE_OPTION