最終更新日時:
が更新

履歴 編集

ビルドツール

インデックス

ビルドしたバイナリを実行する

bjamでバイナリをビルドした場合、toolsetやvariantによって最終生成物が非常に深い位置に生成される。

これを実行するのはインストールするまで困難であるが、notfileモジュールを使用することで実現できる。

import notfile ;

project /sample ;

exe executable : source.cpp ;

actions exec_executable
{
        $(2)
}

notfile exec : @exec_executable : /sample//executable ;
explicit exec ;

explicitルールを指定しないと意図しないタイミングで実行されてしまうので注意されたい。

$ cat source.cpp
#include <iostream>
int main()
{
    std::cout << __GNUC__ << "." << __GNUC_MINOR__ << std::endl;
}
$ bjam --toolset=gcc-4.5
...found 9 targets...
...updating 5 targets...
common.mkdir bin
common.mkdir bin/gcc-4.5
common.mkdir bin/gcc-4.5/debug
gcc.compile.c++ bin/gcc-4.5/debug/source.o
gcc.link bin/gcc-4.5/debug/executable
...updated 5 targets...
$ bjam --toolset=gcc-4.6
...found 9 targets...
...updating 4 targets...
common.mkdir bin/gcc-4.6
common.mkdir bin/gcc-4.6/debug
gcc.compile.c++ bin/gcc-4.6/debug/source.o
gcc.link bin/gcc-4.6/debug/executable
...updated 4 targets...
$ bjam --toolset=gcc-4.5 exec
...found 10 targets...
...updating 1 target...
Jamfile</home/boosters>.exec_executable <l./gcc-4.5/debug>exec
4.5
...updated 1 target...
$ bjam --toolset=gcc-4.6 exec
...found 10 targets...
...updating 1 target...
Jamfile</home/boosters>.exec_executable <l./gcc-4.6/debug>exec
4.6
...updated 1 target...

実行時はビルド時と同じtoolset,variantを指定する必要がある。ビルドされていない場合、ビルドを行ってから実行する。

ディレクトリ構造を保存した状態でインストールを行う

通常インストールターゲットを定義する際、packageモジュールのinstallルールを用いることが多い。しかし、これはヘッダファイルのディレクトリ構造をデフォルトで保存しない。ヘッダファイルを細かく分けることの多いC++などではこの動作は使いにくい。以下にデフォルトの動作を例示する。

# Jamroot.jam
import package ;
import path ;

path-constant project-root : [ path.make ./ ] ;
project /sample ;

explicit install ;
package.install install
  : # requirements
  : # binaries
  : # libraries
  : [ path.glob-tree $(project-root) : *.hpp ]
  ;

$ ls -R
.:
Jamroot.jam  sample/

./sample:
detail/  sample.hpp

./sample/detail:
sample1.hpp
$ bjam install --prefix=$HOME/local
...found 10 targets...
...updating 3 targets...
common.mkdir /home/boosters/local/include
common.copy /home/boosters/local/include/sample.hpp
common.copy /home/boosters/local/include/sample1.hpp
...updated 3 targets...
$ ls -R $HOME/local
/home/boosters/local:
include/

/home/boosters/local/include:
sample1.hpp  sample.hpp
$

これを回避するには<install-source-root>を使用すればよい。具体的には以下のようになる。

# Jamroot.jam
import package ;
import path ;

path-constant project-root : [ path.make ./ ] ;
project /sample ;

explicit install ;
package.install install
  : <install-source-root>$(project-root)
  : # binaries
  : # libraries
  : [ path.glob-tree $(project-root) : *.hpp ]
  ;

$ ls -R
.:
Jamroot.jam  sample/

./sample:
detail/  sample.hpp

./sample/detail:
sample1.hpp
$ bjam install --prefix=$HOME/local
...found 12 targets...
...updating 5 targets...
common.mkdir /home/boosters/local/include
common.mkdir /home/boosters/local/include/sample
common.copy /home/boosters/local/include/sample/sample.hpp
common.mkdir /home/boosters/local/include/sample/detail
common.copy /home/boosters/local/include/sample/detail/sample1.hpp
...updated 5 targets...
$ ls -R $HOME/local
/home/boosters/local:
include/

/home/boosters/local/include:
sample/

/home/boosters/local/include/sample:
detail/  sample.hpp

/home/boosters/local/include/sample/detail:
sample1.hpp
$