我在理解如何使用 bjam 指定和调用目标时遇到问题。通过这个,我的意思是我想为 bjam 提供命令行目标来构建(实际上是从 Makefile 构建),这些目标对应于构建过程的不同方面,而不是仅仅运行整个事情。
例如,现在当我键入“bjam”时,它会关闭并构建一个 python 扩展,运行一个单元测试文件,并创建一个单独的“main”可执行文件。我有执行每个步骤的自定义规则,我的 Jamfile 只是按顺序列出它们:
project-name = example ;
sources =
$(project-name).cpp
$(project-name)_ext.cpp
;
build-ext $(project-name) : $(sources) ;
build-main $(project-name) ;
在我的 Jamroot(上一个目录)中,我定义了这些规则,这是不完整的文件:
# A rule to simplify declaration of extension tests:
rule run-test ( test-name : sources + )
{
import testing ;
testing.make-test run-pyd : $(sources) : : $(test-name) ;
}
# A rule to further simply declaration of extension tests:
rule run-ext-test ( project-name )
{
run-test $(project-name) : $(project-name)_ext test_$(project-name)_ext.py ;
}
# A rule to simplify copying of the extension and Boost.Python libraries to the current directory
rule convenient-copy ( project-name )
{
install convenient_copy
: $(project-name)_ext
: <install-dependencies>on <install-type>SHARED_LIB <install-type>PYTHON_EXTENSION
<location>.
;
}
rule build-ext ( project-name : sources + )
{
python-extension $(project-name)_ext : $(sources) : ;
# copy the extension and Boost.Python libraries to the current directory
convenient-copy $(project-name) ;
# run extension tests
run-ext-test $(project-name) ;
}
rule build-main ( project-name : other-sources * )
{
obj $(project-name).o : $(project-name).cpp ;
exe main_$(project-name) : main_$(project-name).cpp $(project-name).o $(other-sources) ;
install main : main_$(project-name) : <location>. ;
}
但是我注意到以下对 bjam 的调用并没有做我希望他们做的事情:
$ bjam build-main
notice: could not find main target build-main
notice: assuming it is a name of file to create.
don't know how to make <e>build-main
...found 1 target...
...can't find 1 target...
$ bjam main_example
...patience...
...patience...
...found 1597 targets...
...updating 3 targets...
gcc.compile.c++ bin/gcc-4.6/debug/main_example.o
gcc.compile.c++ bin/gcc-4.6/debug/example.o
gcc.link bin/gcc-4.6/debug/main_example
...updated 3 targets...
^^^ 但安装规则未运行,因此二进制文件未复制到 Jamfile 目录。
奇怪的是,有一些目标会做一些事情,但并不总是我所期望的:
$ bjam main
...patience...
...patience...
...found 1598 targets...
...updating 3 targets...
gcc.compile.c++ bin/gcc-4.6/debug/main_example.o
gcc.compile.c++ bin/gcc-4.6/debug/example.o
gcc.link main_example
...updated 3 targets...
这确实在 Jamfile 目录中创建了二进制文件。
目标从何main
而来?我没有定义它...
另一个奇怪的:
$ bjam example_ext
...patience...
...patience...
...found 2834 targets...
...updating 3 targets...
gcc.compile.c++ bin/gcc-4.6/debug/example.o
gcc.compile.c++ bin/gcc-4.6/debug/example_ext.o
gcc.link.dll bin/gcc-4.6/debug/example_ext.so
...updated 3 targets...
^^^ 创建了 example_ext.so,但没有将其复制到 Jamfile 位置。
$ bjam example_ext.so
notice: could not find main target example_ext.so
notice: assuming it is a name of file to create.
...patience...
...patience...
...found 2836 targets...
...updating 4 targets...
gcc.compile.c++ bin/gcc-4.6/debug/example.o
gcc.compile.c++ bin/gcc-4.6/debug/example_ext.o
gcc.link.dll bin/gcc-4.6/debug/example_ext.so
common.copy example_ext.so
...updated 4 targets...
^^^ 创建 .so 文件并复制它,但没有调用便捷复制来引入 libboost_python.so 文件。
我真的不明白这里发生了什么。bjam 文档确实给我带来了严重的问题。它详细描述了目标,但在规则的上下文中,而不是在从命令行调用 bjam 的上下文中。我确实提到过一些伪目标和“生成”,但对于我认为应该是一个简单的用例来说,这似乎太复杂了。还提到了“绑定”机制,但文档提到=$(BINDRULE[1])=
这对我来说毫无意义。
我也遇到了化名,NOTFILE
但explicit
我不确定我是否走在正确的轨道上,也无法做出任何决定性的事情。
有没有关于如何在 bjam 中创建自定义目标的好例子?还是我只是想以非预期的方式使用 bjam?