是否有办法将AS_HELP_STRING
(或其他宏)转换为多行nicely格式帮助?
我有一个--enable-option=
,它可以采用多个值val1,val2,...
,我希望configure --help
为每个值显示一个帮助行。
我为这种情况编写了自己的NA_HELP_STRINGS()
宏:
dnl NA_HELP_STRINGS(list1, help1[, list2, help2[, ... listN, helpN]])
dnl **************************************************************************
dnl
dnl Similar to `AS_HELP_STRING()`, but with support for multiple strings, each
dnl one associated with one or more options
dnl
dnl From: https://github.com/madmurphy/not-autotools
dnl
dnl **************************************************************************
m4_define([NA_HELP_STRINGS],
[m4_if(m4_count($1), [1],
[m4_if([$#], [0], [], [$#], [1],
[m4_text_wrap($1, [ ])],
[AS_HELP_STRING(m4_normalize($1), [$2])m4_if([$#], [2], [], [m4_newline()NA_HELP_STRINGS(m4_shift2($@))])])],
[m4_text_wrap(m4_argn(1, $1)[,], [ ])m4_newline()NA_HELP_STRINGS(m4_dquote(m4_shift($1))m4_if([$#], [1], [], [, m4_shift($@)]))])])
示例用法:
AC_ARG_ENABLE([foo],
[NA_HELP_STRINGS(
[--disable-foo],
[disable the `foo` feature; on some machines the package might not
work properly without the `foo` feature enabled],
[[--enable-foo], [--enable-foo=yes], [--enable-foo=enhanced]],
[install this package with the `foo` feature enabled; if `foo` is
enabled in `enhanced` mode Autoconf might get sentimental],
[[--enable-foo=auto], [--enable-foo=check], [@<:@omitted@:>@]],
[decide automatically whether it is opportune to enable the `foo`
feature on this machine or not]
)],
[:],
[AS_VAR_SET([enable_foo], ['check'])])
用户启动./configure --help
时的输出:
--disable-foo disable the `foo` feature; on some machines the
package might not work properly without the `foo`
feature enabled
--enable-foo,
--enable-foo=yes,
--enable-foo=enhanced install this package with the `foo` feature enabled;
if `foo` is enabled in `enhanced` mode Autoconf
might get sentimental
--enable-foo=auto,
--enable-foo=check,
[omitted] decide automatically whether it is opportune to
enable the `foo` feature on this machine or not
有关更多m4-ish示例,请查看Not Autotools项目。