I'm having problems understanding how to specify and invoke targets with bjam. By this, I mean that I want to provide bjam with command-line targets to build (from a Makefile actually) that correspond to different aspects of the build process, rather than just running the whole thing.
For example, right now when I type 'bjam' it goes off and builds a python extension, runs a unit-test file, and also creates a separate 'main' executable. I have custom rules that do each step, and my Jamfile simply lists them in order:
project-name = example ;
sources =
$(project-name).cpp
$(project-name)_ext.cpp
;
build-ext $(project-name) : $(sources) ;
build-main $(project-name) ;
In my Jamroot (up one directory) I have these rules defined, here's the incomplete file:
# 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>. ;
}
However I've noticed that the following invocations of bjam don't do what I'd like them to do:
$ 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...
^^^ but the install rule wasn't run so the binary isn't copied to the Jamfile directory.
Oddly, there are some targets that do things, but not always what I expect:
$ 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...
That did create the binary, in the Jamfile directory.
Where did the main
target come from? I didn't define it...
Another odd one:
$ 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...
^^^ created example_ext.so, but didn't copy it to the Jamfile location.
$ 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...
^^^ created the .so file and copied it, but didn't invoke convenient-copy to bring in the libboost_python.so files.
I really don't understand what's going on here. The bjam documentation is really causing me serious problems. It describes targets in detail, but in the context of rules, not in the context of invoking bjam from the command line. I did come across some mention of pseudotargets and 'generate' but it seemed far too complicated for what I feel should be a simple use-case. There was also mention of a 'bind' mechanism but the documentation mentions =$(BINDRULE[1])=
which makes no sense to me.
I also came across aliases, NOTFILE
and explicit
but I wasn't sure if I was on the right track, and wasn't able to do anything conclusive.
Are there any good examples of how to create custom targets in bjam? Or am I simply trying to use bjam in ways that weren't intended?