3 # This file defines new macros to process configure command line
4 # arguments, to replace the brain-dead AC_ARG_WITH and AC_ARG_ENABLE.
5 # The flaw in these is particularly that they only differentiate
6 # between "given" and "not given" and do not provide enough help to
7 # process arguments that only accept "yes/no", that require an
8 # argument (other than "yes/no"), etc.
10 # The point of this implementation is to reduce code size and
11 # redundancy in configure.ac and to improve robustness and consistency
12 # in the option evaluation code.
15 # Convert type and name to shell variable name (e.g., "enable_long_strings")
16 m4_define([pgac_arg_to_variable],
17 [$1[]_[]patsubst($2, -, _)])
20 # PGAC_ARG(TYPE, NAME, HELP-STRING-LHS-EXTRA, HELP-STRING-RHS,
21 # [ACTION-IF-YES], [ACTION-IF-NO], [ACTION-IF-ARG],
22 # [ACTION-IF-OMITTED])
23 # ------------------------------------------------------------
24 # This is the base layer. TYPE is either "with" or "enable", depending
25 # on what you like. NAME is the rest of the option name.
26 # HELP-STRING-LHS-EXTRA is a string to append to the option name on
27 # the left-hand side of the help output, e.g., an argument name. If
28 # set to "-", append nothing, but let the option appear in the
29 # negative form (disable/without). HELP-STRING-RHS is the option
30 # description, for the right-hand side of the help output.
31 # ACTION-IF-YES is executed if the option is given without an argument
32 # (or "yes", which is the same); similar for ACTION-IF-NO.
39 AC_ARG_ENABLE([$2], [AS_HELP_STRING([--]m4_if($3, -, disable, enable)[-$2]m4_if($3, -, , $3), [$4])], [
52 [$8])[]dnl AC_ARG_ENABLE
56 AC_ARG_WITH([$2], [AS_HELP_STRING([--]m4_if($3, -, without, with)[-$2]m4_if($3, -, , $3), [$4])], [
69 [$8])[]dnl AC_ARG_WITH
72 [m4_fatal([first argument of $0 must be 'enable' or 'with', not '$1'])]
77 # PGAC_ARG_BOOL(TYPE, NAME, DEFAULT, HELP-STRING-RHS,
78 # [ACTION-IF-YES], [ACTION-IF-NO])
79 # ---------------------------------------------------
80 # Accept a boolean option, that is, one that only takes yes or no.
81 # ("no" is equivalent to "disable" or "without"). DEFAULT is what
82 # should be done if the option is omitted; it should be "yes" or "no".
83 # (Consequently, one of ACTION-IF-YES and ACTION-IF-NO will always
86 AC_DEFUN([PGAC_ARG_BOOL],
87 [dnl The following hack is necessary because in a few instances this
88 dnl macro is called twice for the same option with different default
89 dnl values. But we only want it to appear once in the help. We achieve
90 dnl that by making the help string look the same, which is why we need to
91 dnl save the default that was passed in previously.
92 m4_define([_pgac_helpdefault], m4_ifdef([pgac_defined_$1_$2_bool], [m4_defn([pgac_defined_$1_$2_bool])], [$3]))dnl
93 PGAC_ARG([$1], [$2], [m4_if(_pgac_helpdefault, yes, -)], [$4], [$5], [$6],
94 [AC_MSG_ERROR([no argument expected for --$1-$2 option])],
96 yes, [pgac_arg_to_variable([$1], [$2])=yes
98 no, [pgac_arg_to_variable([$1], [$2])=no
100 [m4_fatal([third argument of $0 must be 'yes' or 'no', not '$3'])])])[]dnl
101 m4_define([pgac_defined_$1_$2_bool], [$3])dnl
105 # PGAC_ARG_REQ(TYPE, NAME, HELP-ARGNAME, HELP-STRING-RHS,
106 # [ACTION-IF-GIVEN], [ACTION-IF-NOT-GIVEN])
107 # -------------------------------------------------------
108 # This option will require an argument; "yes" or "no" will not be
109 # accepted. HELP-ARGNAME is a name for the argument for the help output.
111 AC_DEFUN([PGAC_ARG_REQ],
112 [PGAC_ARG([$1], [$2], [=$3], [$4],
113 [AC_MSG_ERROR([argument required for --$1-$2 option])],
114 [AC_MSG_ERROR([argument required for --$1-$2 option])],
116 [$6])])# PGAC_ARG_REQ
119 # PGAC_ARG_OPTARG(TYPE, NAME, HELP-ARGNAME, HELP-STRING-RHS,
120 # [DEFAULT-ACTION], [ARG-ACTION],
121 # [ACTION-ENABLED], [ACTION-DISABLED])
122 # ----------------------------------------------------------
123 # This will create an option that behaves as follows: If omitted, or
124 # called with "no", then set the enable_variable to "no" and do
125 # nothing else. If called with "yes", then execute DEFAULT-ACTION. If
126 # called with argument, set enable_variable to "yes" and execute
127 # ARG-ACTION. Additionally, execute ACTION-ENABLED if we ended up with
128 # "yes" either way, else ACTION-DISABLED.
130 # The intent is to allow enabling a feature, and optionally pass an
131 # additional piece of information.
133 AC_DEFUN([PGAC_ARG_OPTARG],
134 [PGAC_ARG([$1], [$2], [@<:@=$3@:>@], [$4], [$5], [],
135 [pgac_arg_to_variable([$1], [$2])=yes
137 [pgac_arg_to_variable([$1], [$2])=no])
138 dnl Add this code only if there's a ACTION-ENABLED or ACTION-DISABLED.
141 if test "[$]pgac_arg_to_variable([$1], [$2])" = yes; then