]> granicus.if.org Git - postgresql/blob - config/general.m4
Mention actual function names in documentation of how to pass binary
[postgresql] / config / general.m4
1 # $PostgreSQL: pgsql/config/general.m4,v 1.9 2006/11/30 22:21:23 tgl Exp $
2
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.
9 #
10 # The point of this implementation is to reduce code size and
11 # redundancy in configure.in and to improve robustness and consistency
12 # in the option evaluation code.
13
14
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, -, _)])
18
19
20 # PGAC_ARG(TYPE, NAME, HELP-STRING,
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, HELP-STRING
26 # as usual. ACTION-IF-YES is executed if the option is given without
27 # an argument (or "yes", which is the same); similar for ACTION-IF-NO.
28
29 AC_DEFUN([PGAC_ARG],
30 [
31 pgac_args="$pgac_args pgac_arg_to_variable([$1],[$2])"
32 m4_case([$1],
33
34 enable, [
35 AC_ARG_ENABLE([$2], [$3], [
36   case [$]enableval in
37     yes)
38       m4_default([$4], :)
39       ;;
40     no)
41       m4_default([$5], :)
42       ;;
43     *)
44       $6
45       ;;
46   esac
47 ],
48 [$7])[]dnl AC_ARG_ENABLE
49 ],
50
51 with, [
52 AC_ARG_WITH([$2], [$3], [
53   case [$]withval in
54     yes)
55       m4_default([$4], :)
56       ;;
57     no)
58       m4_default([$5], :)
59       ;;
60     *)
61       $6
62       ;;
63   esac
64 ],
65 [$7])[]dnl AC_ARG_WITH
66 ],
67
68 [m4_fatal([first argument of $0 must be 'enable' or 'with', not '$1'])]
69 )
70 ])# PGAC_ARG
71
72 # PGAC_ARG_CHECK()
73 # ----------------
74 # Checks if the user passed any --with/without/enable/disable
75 # arguments that were not defined. Just prints out a warning message,
76 # so this should be called near the end, so the user will see it.
77
78 AC_DEFUN([PGAC_ARG_CHECK],
79 [for pgac_var in `set | sed 's/=.*//' | $EGREP 'with_|enable_'`; do
80   for pgac_arg in $pgac_args with_gnu_ld; do
81     if test "$pgac_var" = "$pgac_arg"; then
82       continue 2
83     fi
84   done
85   pgac_txt=`echo $pgac_var | sed 's/_/-/g'`
86   AC_MSG_WARN([option ignored: --$pgac_txt])
87 done])# PGAC_ARG_CHECK
88
89 # PGAC_ARG_BOOL(TYPE, NAME, DEFAULT, HELP-STRING, 
90 #               [ACTION-IF-YES], [ACTION-IF-NO])
91 # -----------------------------------------------
92 # Accept a boolean option, that is, one that only takes yes or no.
93 # ("no" is equivalent to "disable" or "without"). DEFAULT is what
94 # should be done if the option is omitted; it should be "yes" or "no".
95 # (Consequently, one of ACTION-IF-YES and ACTION-IF-NO will always
96 # execute.)
97
98 AC_DEFUN([PGAC_ARG_BOOL],
99 [PGAC_ARG([$1], [$2], [$4], [$5], [$6], 
100           [AC_MSG_ERROR([no argument expected for --$1-$2 option])],
101           [m4_case([$3],
102                    yes, [pgac_arg_to_variable([$1], [$2])=yes
103 $5],
104                    no,  [pgac_arg_to_variable([$1], [$2])=no
105 $6],
106                    [m4_fatal([third argument of $0 must be 'yes' or 'no', not '$3'])])])[]dnl
107 ])# PGAC_ARG_BOOL
108
109
110 # PGAC_ARG_REQ(TYPE, NAME, HELP-STRING, [ACTION-IF-GIVEN], [ACTION-IF-NOT-GIVEN])
111 # -------------------------------------------------------------------------------
112 # This option will require an argument; "yes" or "no" will not be
113 # accepted.
114
115 AC_DEFUN([PGAC_ARG_REQ],
116 [PGAC_ARG([$1], [$2], [$3],
117           [AC_MSG_ERROR([argument required for --$1-$2 option])],
118           [AC_MSG_ERROR([argument required for --$1-$2 option])],
119           [$4],
120           [$5])])# PGAC_ARG_REQ
121
122
123 # PGAC_ARG_OPTARG(TYPE, NAME, HELP-STRING, [DEFAULT-ACTION], [ARG-ACTION]
124 #                 [ACTION-ENABLED], [ACTION-DISABLED])
125 # -----------------------------------------------------------------------
126 # This will create an option that behaves as follows: If omitted, or
127 # called with "no", then set the enable_variable to "no" and do
128 # nothing else. If called with "yes", then execute DEFAULT-ACTION. If
129 # called with argument, set enable_variable to "yes" and execute
130 # ARG-ACTION. Additionally, execute ACTION-ENABLED if we ended up with
131 # "yes" either way, else ACTION-DISABLED.
132 #
133 # The intent is to allow enabling a feature, and optionally pass an
134 # additional piece of information.
135
136 AC_DEFUN([PGAC_ARG_OPTARG],
137 [PGAC_ARG([$1], [$2], [$3], [$4], [],
138           [pgac_arg_to_variable([$1], [$2])=yes
139 $5],
140           [pgac_arg_to_variable([$1], [$2])=no])
141 dnl Add this code only if there's a ACTION-ENABLED or ACTION-DISABLED.
142 m4_ifval([$6[]$7],
143 [
144 if test "[$]pgac_arg_to_variable([$1], [$2])" = yes; then
145   m4_default([$6], :)
146 m4_ifval([$7],
147 [else
148   $7
149 ])[]dnl
150 fi
151 ])[]dnl
152 ])# PGAC_ARG_OPTARG