您是否可以覆盖作为运行autoconf的一部分生成的默认配置帮助消息?

时间:2015-04-28 20:01:28

标签: configure autoconf

我想修改一个configure.ac脚本,这样当我通过autoconf生成配置脚本时,它会有一个自定义帮助消息。

E.g:

$autoconf
$./configure --help

产量

"Hello World"

而不是关于微调安装目录和修改构建标志的默认值。

这可能吗?

2 个答案:

答案 0 :(得分:1)

在autoconf general.m4脚本中查看_AC_INIT_HELP宏。它负责打印帮助信息。

此脚本会将文字插入general.m4中列出的不同diversions

dnl The order of the diversions here is
dnl - HELP_BEGIN
dnl   which may be extended by extra generic options such as with X or
dnl   AC_ARG_PROGRAM.  Displayed only in long --help.
dnl
dnl - HELP_CANON
dnl   Support for cross compilation (--build, --host and --target).
dnl   Display only in long --help.
dnl
dnl - HELP_ENABLE
dnl   which starts with the trailer of the HELP_BEGIN, HELP_CANON section,
dnl   then implements the header of the non generic options.
dnl
dnl - HELP_WITH
dnl
dnl - HELP_VAR
dnl
dnl - HELP_VAR_END
dnl
dnl - HELP_END
dnl   initialized below, in which we dump the trailer (handling of the
dnl   recursion for instance).

显示Hello World帮助消息的最简单方法是在configure.ac文件的末尾插入以下代码:

m4_cleardivert([HELP_BEGIN])dnl
m4_cleardivert([HELP_CANON])dnl
m4_cleardivert([HELP_ENABLE])dnl
m4_cleardivert([HELP_WITH])dnl
m4_cleardivert([HELP_VAR])dnl
m4_cleardivert([HELP_VAR_END])dnl
m4_cleardivert([HELP_END])dnl
m4_divert_push([HELP_BEGIN])dnl
  cat <<_ACEOF
Hello World
_ACEOF
m4_divert_pop([HELP_BEGIN])dnl
m4_divert_push([HELP_END])dnl
exit 0
m4_divert_pop([HELP_END])dnl

它将清除所有转移并插入您的自定义文本,而无需包含任何自定义m4脚本。在显示帮助时,需要exit来停止处理configure脚本。

如果您想对帮助文本引入更多更改,可以在configure.ac文件的开头包含您自己的m4脚本:

m4_include([custom_help.m4])

_AC_INIT_HELP宏复制到您的custom_help.m4脚本,并根据您的需要进行修改。

答案 1 :(得分:0)

我尝试了 answer by baf,但发现它会导致无条件打印“Hello world”,而不管 --help!这可能是由于 autoconf 中的版本差异;我使用的是 2.69 版。

我发现作为检查 $ac_init_help 并且仅在打印消息后立即退出的变体起作用。这出现在 configure.acconfigure.in 的末尾:

dnl# Clear the default help message.
m4_cleardivert([HELP_BEGIN])dnl
m4_cleardivert([HELP_CANON])dnl
m4_cleardivert([HELP_ENABLE])dnl
m4_cleardivert([HELP_WITH])dnl
m4_cleardivert([HELP_VAR])dnl
m4_cleardivert([HELP_VAR_END])dnl
m4_cleardivert([HELP_END])dnl

dnl# Specify custom help.
m4_divert_push([HELP_BEGIN])dnl
if test "$ac_init_help" = "long"; then
  cat <<_ACEOF
Hello world.  Remember this is processed by M4, so you will need
to quote any string that contains square brackets, for example:

Usage: my-program [[options]] [[file [file..]]]

_ACEOF

  # Stop after printing the help.
  exit 0
fi
m4_divert_pop([HELP_BEGIN])dnl

然后它在有和没有 --help 的情况下都可以工作:

$ ./configure --help
Hello world.  Remember this is processed by M4, so you will need
to quote any string that contains square brackets, for example:

Usage: my-program [options] [file [file..]]

$ ./configure
checking for gcc... gcc
[...]