got*_*nes 5 configuration build-process autotools
我们研究小组的一部分程序具有ctemplate库提供的辅助功能.在我们过时的集群中,我们无法通过编译来构建软件,因此我想将此功能分开并通过configure标志来控制它是否包含在内,例如--disable-ctemplate.
这个用C++编写的软件使用的是Autotools构建系统 - 我都没有这方面的经验.我的理解是,要完成这项任务,我需要做以下事情:
通过在中创建新AC_ARG_ENABLE条目,在configure脚本中添加新标志configure.ac.
在使用该库的代码周围添加一些#ifdef(或可能#ifndef)语句ctemplate,并围绕调用该代码的任何代码.
我认为第一步看起来像这样:
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)
Run Code Online (Sandbox Code Playgroud)
虽然我不知道逻辑是否正确,因为我已经从使用的示例改编了这个例子--enable-FLAG而不是--disable-FLAG.
对于第二步,我将在预处理器标志中包含部分,例如
#ifndef NOCTEMPLATE
void Class::MethodUsingCtemplate(...)
{
...
}
#endif
Run Code Online (Sandbox Code Playgroud)
如果我这样做,这会正确"连接"所有内容configure --disable-ctemplate吗?
另外,这是否会确保程序不会进入ctemplate库进行编译?如果没有,那么所有这一切都是徒劳的; 我必须阻止编译ctemplate库和依赖组件.
我会重复一遍,我不熟悉C++和Autotools; 我已经采取了一种非常天真的第一种方法来解决这个问题.如果您有这方面的经验,我将非常感谢您的更正和您可以提供的任何解释.
这是我在阅读完文档,教程,帮助主题,邮件列表等之后放在一起的解决方案,只是在他们工作之前简单地尝试我可以解释他们工作的原因.
在configure.ac,我放置了以下代码行
# This adds the option of compiling without using the ctemplate library,
# which has proved troublesome for compilation on some platforms
AC_ARG_ENABLE(ctemplate,
[ --disable-ctemplate Disable compilation with ctemplate and HTML output],
[case "${enableval}" in
yes | no ) WITH_CTEMPLATE="${enableval}" ;;
*) AC_MSG_ERROR(bad value ${enableval} for --disable-ctemplate) ;;
esac],
[WITH_CTEMPLATE="yes"]
)
dnl Make sure we register this option with Automake, so we know whether to
dnl descend into ctemplate for more configuration or not
AM_CONDITIONAL([WITH_CTEMPLATE], [test "x$WITH_CTEMPLATE" = "xyes"])
# Define CTEMPLATE in config.h if we're going to compile against it
if test "x$WITH_CTEMPLATE" = "xyes"; then
AC_DEFINE([CTEMPLATE], [], ["build using ctemplate library"])
AC_MSG_NOTICE([ctemplate will be used, HTML output enabled])
else
AC_MSG_NOTICE([ctemplate will not be used, HTML output disabled])
fi
Run Code Online (Sandbox Code Playgroud)
在下一步中,我Makefile.am将顶层更改为以下内容:
if WITH_CTEMPLATE
MAYBE_CTEMPLATE = ctemplate
endif
SUBDIRS = boost libgsl $(MAYBE_CTEMPLATE) libutil ...
Run Code Online (Sandbox Code Playgroud)
在较低级别的Makefile.ams中,我补充道
if WITH_CTEMPLATE
# some change to the configuration
else
# some other change to the configuration
endif
Run Code Online (Sandbox Code Playgroud)
最后,我必须确保其中一个关键的C++头文件(包含在代码的其他部分中)具有以下内容:
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
Run Code Online (Sandbox Code Playgroud)
config.h包含任何创建的新定义AC_DEFINE,因此该文件必须包含在检查此路由创建的宏定义是否已定义(或未定义)的部分中.
这耗费了大量时间,让我感到沮丧; 我只能希望在这里记录这个解释可以让其他人免于同样的命运.
| 归档时间: |
|
| 查看次数: |
4810 次 |
| 最近记录: |