如何在 Autotools 中添加和实现配置标志?
我们研究小组的部分程序具有 ctemplate 库提供的辅助功能。 在我们过时的集群上,由于编译,我们无法构建软件,因此我想分离此功能并通过 configure
标志控制是否包含它,例如 --禁用-ctemplate
。
该软件用 C++ 编写,使用 Autotools 构建系统——我对这两个系统都没有太多经验。 我的理解是,要完成此任务,我需要执行以下操作:
通过在
configure.ac
中创建新的AC_ARG_ENABLE
条目,向配置脚本添加新标志>.在使用
ctemplate
库的代码以及调用的任何代码周围添加一些#ifdef
(或可能#ifndef
)语句该代码。
我认为第一步看起来像这样:
AC_ARG_ENABLE(ctemplate,
[ --disable-ctemplate Disable HTML output],
[case "${enableval}" in
yes) ctemplate=false ;;
no) ctemplate=true ;;
*) AC_MSG_ERROR(bad value ${enableval} for --disable-ctemplate) ;;
esac],[ctemplate=true])
AM_CONDITIONAL(NOCTEMPLATE, test x$ctemplate = xfalse)
虽然我不知道逻辑是否正确,因为我已经从使用 --enable-FLAG
而不是 的示例中改编了这个示例>--禁用-FLAG
。
对于第二步,我将把各个部分包装在预处理器标志中,例如
#ifndef NOCTEMPLATE
void Class::MethodUsingCtemplate(...)
{
...
}
#endif
如果我执行 configure --disable-ctemplate
,这会正确“连接”所有内容吗?
另外,这是否可以确保程序不会进入ctemplate库进行编译? 如果没有,那么这一切都是白费; 我必须能够阻止编译 ctemplate
库和依赖组件。
我要重申一下,我对 C++ 和 Autotools 都不熟悉; 我首先采取了一种非常幼稚的方法来解决这个问题。 如果您有这方面的经验,我非常感谢您的更正和您可以提供的任何解释。
A portion of our research group's program has auxiliary functionality provided by ctemplate library. On our dated cluster, we can not build the software due to compilation , so I would like to separate this functionality and control whether it is included or not via a configure
flag, such as --disable-ctemplate
.
The software, written in C++, uses the Autotools build system—neither of which I have much experience with. My understanding is that to accomplish this task, I need to do the following:
Add a new flag to the configure script by creating a new
AC_ARG_ENABLE
entry inconfigure.ac
.Add some
#ifdef
(or possibly#ifndef
) statements around the code that uses thectemplate
library, and around any code that calls that code.
I think the first step would look something like this:
AC_ARG_ENABLE(ctemplate,
[ --disable-ctemplate Disable HTML output],
[case "${enableval}" in
yes) ctemplate=false ;;
no) ctemplate=true ;;
*) AC_MSG_ERROR(bad value ${enableval} for --disable-ctemplate) ;;
esac],[ctemplate=true])
AM_CONDITIONAL(NOCTEMPLATE, test x$ctemplate = xfalse)
though I don't know if the logic is correct, since I've adapted this example from examples that used --enable-FLAG
instead of --disable-FLAG
.
For the second step, I'll wrap sections in preprocessor flags such as
#ifndef NOCTEMPLATE
void Class::MethodUsingCtemplate(...)
{
...
}
#endif
Would this correctly "wire up" everything if I did configure --disable-ctemplate
?
Also, will this ensure that the program does not go into the ctemplate
library for compilation? If not, then all of this is for nothing; it's imperative that I can prevent compilation of the ctemplate
library and dependent components.
I'll re-iterate that I'm unfamiliar with both C++ and Autotools; I have taken a very naive first approach at solving this problem. If you have experience in this area, I would really appreciate your corrections and any explanations you could offer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我在阅读文档、教程、帮助线程、邮件列表等后整理出来的解决方案,并且只是简单地尝试直到它们起作用,我可以解释它们为什么起作用。
在
configure.ac
中,我放置了以下代码行在下一步中,我将顶层的
Makefile.am
更改为以下内容:在较低级别
Makefile.am
s,我添加了最后,我必须确保关键的 C++ 头文件之一(包含在代码的其他部分中)具有以下内容:
config.h
包含使用 AC_DEFINE 创建的任何新定义,因此此文件必须包含在检查此路由创建的宏定义是否已定义(或未定义)的部分中。这花了我很多时间,也让我克服了挫败感。 我只能希望在这里记录这个解释可以让其他人免于同样的命运。
Here is the solution that I put together after reading through documentation, tutorials, help threads, mailing lists, etc., and just plain trying things until they worked I could explain why they worked.
In
configure.ac
, I placed the following lines of codeIn the next step, I changed the
Makefile.am
at the top level to the following:In lower level
Makefile.am
s, I addedFinally, I had to make sure that one of the key C++ header files (included by other parts of the code) had the following:
config.h
contains any new definitions one creates withAC_DEFINE
, so this file must be included in parts that check whether a macro definition created by this route is defined (or undefined).This took a lot of time and pushing through frustration on my part; I can only hope documenting this explanation here saves someone else from the same fate.
为了防止构建尝试在 ctemplate 子目录中进行编译,您需要执行以下操作:
在 Makefile.am 中
To prevent the build from attempting to compile in the ctemplate subdirectory, you'll want to do something like:
in Makefile.am