2010-09-21 04:08:53 +08:00
|
|
|
# config/general.m4
|
2000-09-22 04:17:43 +08:00
|
|
|
|
|
|
|
# This file defines new macros to process configure command line
|
|
|
|
# arguments, to replace the brain-dead AC_ARG_WITH and AC_ARG_ENABLE.
|
|
|
|
# The flaw in these is particularly that they only differentiate
|
|
|
|
# between "given" and "not given" and do not provide enough help to
|
|
|
|
# process arguments that only accept "yes/no", that require an
|
|
|
|
# argument (other than "yes/no"), etc.
|
|
|
|
#
|
|
|
|
# The point of this implementation is to reduce code size and
|
2020-07-24 16:34:16 +08:00
|
|
|
# redundancy in configure.ac and to improve robustness and consistency
|
2000-09-22 04:17:43 +08:00
|
|
|
# in the option evaluation code.
|
|
|
|
|
|
|
|
|
|
|
|
# Convert type and name to shell variable name (e.g., "enable_long_strings")
|
2002-03-30 01:32:55 +08:00
|
|
|
m4_define([pgac_arg_to_variable],
|
|
|
|
[$1[]_[]patsubst($2, -, _)])
|
2000-09-22 04:17:43 +08:00
|
|
|
|
|
|
|
|
2008-10-29 17:27:24 +08:00
|
|
|
# PGAC_ARG(TYPE, NAME, HELP-STRING-LHS-EXTRA, HELP-STRING-RHS,
|
2000-09-22 04:17:43 +08:00
|
|
|
# [ACTION-IF-YES], [ACTION-IF-NO], [ACTION-IF-ARG],
|
|
|
|
# [ACTION-IF-OMITTED])
|
2008-10-29 17:27:24 +08:00
|
|
|
# ------------------------------------------------------------
|
2000-09-22 04:17:43 +08:00
|
|
|
# This is the base layer. TYPE is either "with" or "enable", depending
|
2008-10-29 17:27:24 +08:00
|
|
|
# on what you like. NAME is the rest of the option name.
|
|
|
|
# HELP-STRING-LHS-EXTRA is a string to append to the option name on
|
|
|
|
# the left-hand side of the help output, e.g., an argument name. If
|
|
|
|
# set to "-", append nothing, but let the option appear in the
|
|
|
|
# negative form (disable/without). HELP-STRING-RHS is the option
|
|
|
|
# description, for the right-hand side of the help output.
|
|
|
|
# ACTION-IF-YES is executed if the option is given without an argument
|
|
|
|
# (or "yes", which is the same); similar for ACTION-IF-NO.
|
2000-09-22 04:17:43 +08:00
|
|
|
|
|
|
|
AC_DEFUN([PGAC_ARG],
|
2002-03-30 01:32:55 +08:00
|
|
|
[
|
|
|
|
m4_case([$1],
|
|
|
|
|
|
|
|
enable, [
|
2008-10-29 17:27:24 +08:00
|
|
|
AC_ARG_ENABLE([$2], [AS_HELP_STRING([--]m4_if($3, -, disable, enable)[-$2]m4_if($3, -, , $3), [$4])], [
|
2002-03-30 01:32:55 +08:00
|
|
|
case [$]enableval in
|
2000-09-22 04:17:43 +08:00
|
|
|
yes)
|
2008-10-29 17:27:24 +08:00
|
|
|
m4_default([$5], :)
|
2000-09-22 04:17:43 +08:00
|
|
|
;;
|
|
|
|
no)
|
2008-10-29 17:27:24 +08:00
|
|
|
m4_default([$6], :)
|
2000-09-22 04:17:43 +08:00
|
|
|
;;
|
2002-03-30 01:32:55 +08:00
|
|
|
*)
|
2008-10-29 17:27:24 +08:00
|
|
|
$7
|
2000-09-22 04:17:43 +08:00
|
|
|
;;
|
2002-03-30 01:32:55 +08:00
|
|
|
esac
|
|
|
|
],
|
2008-10-29 17:27:24 +08:00
|
|
|
[$8])[]dnl AC_ARG_ENABLE
|
2002-03-30 01:32:55 +08:00
|
|
|
],
|
|
|
|
|
|
|
|
with, [
|
2008-10-29 17:27:24 +08:00
|
|
|
AC_ARG_WITH([$2], [AS_HELP_STRING([--]m4_if($3, -, without, with)[-$2]m4_if($3, -, , $3), [$4])], [
|
2002-03-30 01:32:55 +08:00
|
|
|
case [$]withval in
|
|
|
|
yes)
|
2008-10-29 17:27:24 +08:00
|
|
|
m4_default([$5], :)
|
2002-03-30 01:32:55 +08:00
|
|
|
;;
|
|
|
|
no)
|
2008-10-29 17:27:24 +08:00
|
|
|
m4_default([$6], :)
|
2002-03-30 01:32:55 +08:00
|
|
|
;;
|
|
|
|
*)
|
2008-10-29 17:27:24 +08:00
|
|
|
$7
|
2002-03-30 01:32:55 +08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
],
|
2008-10-29 17:27:24 +08:00
|
|
|
[$8])[]dnl AC_ARG_WITH
|
2002-03-30 01:32:55 +08:00
|
|
|
],
|
|
|
|
|
|
|
|
[m4_fatal([first argument of $0 must be 'enable' or 'with', not '$1'])]
|
|
|
|
)
|
2000-09-22 04:17:43 +08:00
|
|
|
])# PGAC_ARG
|
|
|
|
|
|
|
|
|
2008-10-29 17:27:24 +08:00
|
|
|
# PGAC_ARG_BOOL(TYPE, NAME, DEFAULT, HELP-STRING-RHS,
|
2000-09-22 04:17:43 +08:00
|
|
|
# [ACTION-IF-YES], [ACTION-IF-NO])
|
2008-10-29 17:27:24 +08:00
|
|
|
# ---------------------------------------------------
|
2000-09-22 04:17:43 +08:00
|
|
|
# Accept a boolean option, that is, one that only takes yes or no.
|
|
|
|
# ("no" is equivalent to "disable" or "without"). DEFAULT is what
|
|
|
|
# should be done if the option is omitted; it should be "yes" or "no".
|
|
|
|
# (Consequently, one of ACTION-IF-YES and ACTION-IF-NO will always
|
|
|
|
# execute.)
|
|
|
|
|
|
|
|
AC_DEFUN([PGAC_ARG_BOOL],
|
2008-10-29 17:27:24 +08:00
|
|
|
[dnl The following hack is necessary because in a few instances this
|
|
|
|
dnl macro is called twice for the same option with different default
|
|
|
|
dnl values. But we only want it to appear once in the help. We achieve
|
|
|
|
dnl that by making the help string look the same, which is why we need to
|
|
|
|
dnl save the default that was passed in previously.
|
|
|
|
m4_define([_pgac_helpdefault], m4_ifdef([pgac_defined_$1_$2_bool], [m4_defn([pgac_defined_$1_$2_bool])], [$3]))dnl
|
2010-11-24 04:27:50 +08:00
|
|
|
PGAC_ARG([$1], [$2], [m4_if(_pgac_helpdefault, yes, -)], [$4], [$5], [$6],
|
2000-09-22 04:17:43 +08:00
|
|
|
[AC_MSG_ERROR([no argument expected for --$1-$2 option])],
|
2002-03-30 01:32:55 +08:00
|
|
|
[m4_case([$3],
|
|
|
|
yes, [pgac_arg_to_variable([$1], [$2])=yes
|
2000-09-22 04:17:43 +08:00
|
|
|
$5],
|
2002-03-30 01:32:55 +08:00
|
|
|
no, [pgac_arg_to_variable([$1], [$2])=no
|
2000-09-22 04:17:43 +08:00
|
|
|
$6],
|
2002-03-30 01:32:55 +08:00
|
|
|
[m4_fatal([third argument of $0 must be 'yes' or 'no', not '$3'])])])[]dnl
|
2008-10-29 17:27:24 +08:00
|
|
|
m4_define([pgac_defined_$1_$2_bool], [$3])dnl
|
2000-09-22 04:17:43 +08:00
|
|
|
])# PGAC_ARG_BOOL
|
|
|
|
|
|
|
|
|
2008-10-29 17:27:24 +08:00
|
|
|
# PGAC_ARG_REQ(TYPE, NAME, HELP-ARGNAME, HELP-STRING-RHS,
|
|
|
|
# [ACTION-IF-GIVEN], [ACTION-IF-NOT-GIVEN])
|
|
|
|
# -------------------------------------------------------
|
2000-09-22 04:17:43 +08:00
|
|
|
# This option will require an argument; "yes" or "no" will not be
|
2008-10-29 17:27:24 +08:00
|
|
|
# accepted. HELP-ARGNAME is a name for the argument for the help output.
|
2000-09-22 04:17:43 +08:00
|
|
|
|
|
|
|
AC_DEFUN([PGAC_ARG_REQ],
|
2008-10-29 17:27:24 +08:00
|
|
|
[PGAC_ARG([$1], [$2], [=$3], [$4],
|
2000-09-22 04:17:43 +08:00
|
|
|
[AC_MSG_ERROR([argument required for --$1-$2 option])],
|
|
|
|
[AC_MSG_ERROR([argument required for --$1-$2 option])],
|
2008-10-29 17:27:24 +08:00
|
|
|
[$5],
|
|
|
|
[$6])])# PGAC_ARG_REQ
|
2000-09-22 04:17:43 +08:00
|
|
|
|
|
|
|
|
2008-10-29 17:27:24 +08:00
|
|
|
# PGAC_ARG_OPTARG(TYPE, NAME, HELP-ARGNAME, HELP-STRING-RHS,
|
|
|
|
# [DEFAULT-ACTION], [ARG-ACTION],
|
2000-09-22 04:17:43 +08:00
|
|
|
# [ACTION-ENABLED], [ACTION-DISABLED])
|
2008-10-29 17:27:24 +08:00
|
|
|
# ----------------------------------------------------------
|
2000-09-22 04:17:43 +08:00
|
|
|
# This will create an option that behaves as follows: If omitted, or
|
|
|
|
# called with "no", then set the enable_variable to "no" and do
|
|
|
|
# nothing else. If called with "yes", then execute DEFAULT-ACTION. If
|
|
|
|
# called with argument, set enable_variable to "yes" and execute
|
|
|
|
# ARG-ACTION. Additionally, execute ACTION-ENABLED if we ended up with
|
|
|
|
# "yes" either way, else ACTION-DISABLED.
|
|
|
|
#
|
|
|
|
# The intent is to allow enabling a feature, and optionally pass an
|
|
|
|
# additional piece of information.
|
|
|
|
|
|
|
|
AC_DEFUN([PGAC_ARG_OPTARG],
|
2008-10-29 17:27:24 +08:00
|
|
|
[PGAC_ARG([$1], [$2], [@<:@=$3@:>@], [$4], [$5], [],
|
2000-09-22 04:17:43 +08:00
|
|
|
[pgac_arg_to_variable([$1], [$2])=yes
|
2008-10-29 17:27:24 +08:00
|
|
|
$6],
|
2000-09-22 04:17:43 +08:00
|
|
|
[pgac_arg_to_variable([$1], [$2])=no])
|
|
|
|
dnl Add this code only if there's a ACTION-ENABLED or ACTION-DISABLED.
|
2008-10-29 17:27:24 +08:00
|
|
|
m4_ifval([$7[]$8],
|
2000-09-22 04:17:43 +08:00
|
|
|
[
|
|
|
|
if test "[$]pgac_arg_to_variable([$1], [$2])" = yes; then
|
2008-10-29 17:27:24 +08:00
|
|
|
m4_default([$7], :)
|
|
|
|
m4_ifval([$8],
|
2000-09-22 04:17:43 +08:00
|
|
|
[else
|
2008-10-29 17:27:24 +08:00
|
|
|
$8
|
2000-09-22 04:17:43 +08:00
|
|
|
])[]dnl
|
|
|
|
fi
|
|
|
|
])[]dnl
|
|
|
|
])# PGAC_ARG_OPTARG
|