要从 GitHub 签出最新版本的 Boost 库,请执行以下操作:
- 结帐 Boost 超级项目(最低要求):
git clone --single-branch --branch master --depth=1 https://github.com/boostorg/boost.git。
cd boost/
- 检查所有子模块(仅需要最低要求):
git submodule update --init --recursive --remote --no-fetch --depth=1。
如果出现如下错误:
Cloning into 'libs/predef'...
remote: Counting objects: 243, done.
remote: Compressing objects: 100% (163/163), done.
remote: Total 243 (delta 128), reused 126 (delta 70), pack-reused 0
Receiving objects: 100% (243/243), 142.82 KiB | 209.00 KiB/s, done.
Resolving deltas: 100% (128/128), done.
Checking connectivity... done.
fatal: Needed a single revision
Unable to find current origin/master revision in submodule path 'libs/predef'
然后使用脚本(reget.bash):
#! /usr/bin/env bash -vex
rm -rf $3/$1 .git/modules/$1
git clone --depth=1 --branch=$2 --single-branch --separate-git-dir .git/modules/$1 https://github.com/boostorg/$1 $3/$1
其中$1 是predef,$2 是master,$3 是libs,即运行bash reget.bash predef master libs。
不同的子模块可能会发生多次错误,只需使用上述脚本清理不可恢复的 git 错误并检查失败子模块的最新提交即可。然后重用git submodule update --init --recursive --remote --no-fetch --depth=1。
检查完所有子模块后,构建b2 可执行文件。对于 clang,它看起来像:
export CC=clang
export CFLAGS="-march=native -Ofast"
export CXX=clang++
export CXXFLAGS="-march=native -Ofast"
bash bootstrap.sh --with-toolset=clang
您已获得b2 可执行文件。用它来构建整个Boost:
sudo ./b2 -j`nproc` toolset=clang --build-dir=/tmp/build-boost --without-mpi install
附加:
如果您只想克隆 boost 本身的 HEAD 及其所有子模块的 HEADS,那么您可以使用以下 Lua 脚本(在https://github.com/boostorg/boost.git 仓库):
-- mkdir boost ; cd boost ; lua ../git-submodules-clone-HEAD.lua https://github.com/boostorg/boost.git .
local module_url = arg[1] or 'https://github.com/boostorg/boost.git'
local module = arg[2] or module_url:match('.+/([_%d%a]+)%.git')
local branch = arg[3] or 'master'
function execute(command)
print('# ' .. command)
return os.execute(command)
end
-- execute('rm -rf ' .. module)
if not execute('git clone --single-branch --branch master --depth=1 ' .. module_url .. ' ' .. module) then
io.stderr:write('can\'t clone repository from ' .. module_url .. ' to ' .. module .. '\n')
return 1
end
-- cd $module ; git submodule update --init --recursive --remote --no-fetch --depth=1
execute('mkdir -p ' .. module .. '/.git/modules')
assert(io.input(module .. '/.gitmodules'))
local lines = {}
for line in io.lines() do
table.insert(lines, line)
end
local submodule
local path
local submodule_url
for _, line in ipairs(lines) do
local submodule_ = line:match('^%[submodule %"([_%d%a]-)%"%]$')
if submodule_ then
submodule = submodule_
path = nil
submodule_url = nil
else
local path_ = line:match('^%s*path = (.+)$')
if path_ then
path = path_
else
submodule_url = line:match('^%s*url = (.+)$')
end
if submodule and path and submodule_url then
-- execute('rm -rf ' .. path)
local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
-- execute('rm -rf ' .. git_dir)
execute('mkdir -p $(dirname "' .. git_dir .. '")')
if not execute('git clone --depth=1 --single-branch --branch=' .. branch .. ' --separate-git-dir ' .. git_dir .. ' ' .. module_url .. '/' .. submodule_url .. ' ' .. module .. '/' .. path) then
io.stderr:write('can\'t clone submodule ' .. submodule)
return 1
end
path = nil
submodule_url = nil
end
end
end