Skip to content

Commit 8b0b7b1

Browse files
committed
add boost recipe;
1 parent 77346c5 commit 8b0b7b1

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory
2+
from os.path import join, exists
3+
import sh
4+
5+
# This recipe creates a custom toolchain and bootstraps Boost from source to build Boost.Build
6+
# including python bindings
7+
class BoostRecipe(Recipe):
8+
version = '1.60.0'
9+
# Don't forget to change the URL when changing the version
10+
url = 'http://downloads.sourceforge.net/project/boost/boost/{version}/boost_1_60_0.tar.bz2'
11+
depends = ['python2']
12+
patches = ['disable-so-version.patch', 'use-android-libs.patch']
13+
14+
def should_build(self, arch):
15+
return not exists(join(self.get_build_dir(arch.arch), 'b2'))
16+
17+
def prebuild_arch(self, arch):
18+
super(BoostRecipe, self).prebuild_arch(arch)
19+
env = self.get_recipe_env(arch)
20+
with current_directory(self.get_build_dir(arch.arch)):
21+
# Make custom toolchain
22+
bash = sh.Command('bash')
23+
shprint(bash, join(self.ctx.ndk_dir, 'build/tools/make-standalone-toolchain.sh'),
24+
'--ndk-dir=' + self.ctx.ndk_dir,
25+
'--arch=' + env['ARCH'],
26+
'--platform=android-' + str(self.ctx.android_api),
27+
'--toolchain=' + env['CROSSHOST'] + '-' + env['TOOLCHAIN_VERSION'],
28+
'--install-dir=' + env['CROSSHOME'],
29+
'--system=' + 'linux-x86_64'
30+
)
31+
# Install app stl
32+
shutil.copyfile(join(env['CROSSHOME'], env['CROSSHOST'], 'lib/libgnustl_shared.so'),
33+
join(self.ctx.get_libs_dir(arch.arch), 'libgnustl_shared.so'))
34+
35+
def build_arch(self, arch):
36+
super(BoostRecipe, self).build_arch(arch)
37+
env = self.get_recipe_env(arch)
38+
with current_directory(self.get_build_dir(arch.arch)):
39+
# Compile Boost.Build engine with this custom toolchain
40+
bash = sh.Command('bash')
41+
shprint(bash, 'bootstrap.sh',
42+
'--with-python=' + join(env['PYTHON_ROOT'], 'bin/python.host'),
43+
'--with-python-version=2.7',
44+
'--with-python-root=' + env['PYTHON_ROOT']
45+
) # Do not pass env
46+
shutil.copyfile(join(self.get_recipe_dir(), 'user-config.jam'),
47+
join(env['BOOST_BUILD_PATH'], 'user-config.jam'))
48+
49+
def select_build_arch(self, arch):
50+
return arch.arch.replace('eabi', '')
51+
52+
def get_recipe_env(self, arch):
53+
env = super(BoostRecipe, self).get_recipe_env(arch)
54+
#env['OPENSSL_BUILD_PATH'] = self.get_recipe('openssl', self.ctx).get_build_dir(arch.arch)
55+
env['BOOST_BUILD_PATH'] = self.get_build_dir(arch.arch) # find user-config.jam
56+
env['BOOST_ROOT'] = env['BOOST_BUILD_PATH'] # find boost source
57+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
58+
env['ARCH'] = self.select_build_arch(arch)
59+
env['ANDROIDAPI'] = str(self.ctx.android_api)
60+
env['CROSSHOST'] = env['ARCH'] + '-linux-androideabi'
61+
env['CROSSHOME'] = join(env['BOOST_ROOT'], 'standalone-' + env['ARCH'] + '-toolchain')
62+
env['TOOLCHAIN_PREFIX'] = join(env['CROSSHOME'], 'bin', env['CROSSHOST'])
63+
return env
64+
65+
recipe = BoostRecipe()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- boost/boostcpp.jam 2015-12-14 03:30:09.000000000 +0100
2+
+++ boost-patch/boostcpp.jam 2016-02-08 16:38:40.510859612 +0100
3+
@@ -155,8 +155,9 @@
4+
if $(type) = SHARED_LIB &&
5+
! [ $(property-set).get <target-os> ] in windows cygwin darwin aix &&
6+
! [ $(property-set).get <toolset> ] in pgi
7+
{
8+
+ return $(result) ; # disable version suffix for android
9+
result = $(result).$(BOOST_VERSION) ;
10+
}
11+
12+
return $(result) ;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- boost/tools/build/src/tools/python.jam 2015-10-16 20:55:36.000000000 +0200
2+
+++ boost-patch/tools/build/src/tools/python.jam 2016-02-09 13:16:09.519261546 +0100
3+
@@ -646,6 +646,7 @@
4+
5+
case aix : return <library>pthread <library>dl ;
6+
7+
+ case * : return ; # use Android builtin libs
8+
case * : return <library>pthread <library>dl
9+
<toolset>gcc:<library>util <toolset-intel:platform>linux:<library>util ;
10+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os ;
2+
3+
local ANDROIDNDK = [ os.environ ANDROIDNDK ] ;
4+
local ANDROIDAPI = [ os.environ ANDROIDAPI ] ;
5+
local TOOLCHAIN_VERSION = [ os.environ TOOLCHAIN_VERSION ] ;
6+
local TOOLCHAIN_PREFIX = [ os.environ TOOLCHAIN_PREFIX ] ;
7+
local ARCH = [ os.environ ARCH ] ;
8+
local PYTHON_ROOT = [ os.environ PYTHON_ROOT ] ;
9+
#local OPENSSL_BUILD_PATH = [ os.environ OPENSSL_BUILD_PATH ] ;
10+
11+
using gcc : $(ARCH) : $(TOOLCHAIN_PREFIX)-g++ :
12+
<architecture>$(ARCH)
13+
<archiver>$(TOOLCHAIN_PREFIX)-ar
14+
<compileflags>-DBOOST_SP_USE_PTHREADS
15+
<compileflags>-DBOOST_AC_USE_PTHREADS
16+
<cxxflags>-DBOOST_SP_USE_PTHREADS
17+
<cxxflags>-DBOOST_AC_USE_PTHREADS
18+
<cxxflags>-frtti
19+
<cxxflags>-fexceptions
20+
<compileflags>-I$(ANDROIDNDK)/platforms/android-$(ANDROIDAPI)/arch-$(ARCH)/usr/include
21+
<compileflags>-I$(ANDROIDNDK)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/include
22+
<compileflags>-I$(ANDROIDNDK)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/$(ARCH)/include
23+
<compileflags>-I$(PYTHON_ROOT)/include/python2.7
24+
#<compileflags>-I$(OPENSSL_BUILD_PATH)/include
25+
#<compileflags>-I$(OPENSSL_BUILD_PATH)/include/openssl
26+
<linkflags>--sysroot=$(ANDROIDNDK)/platforms/android-$(ANDROIDAPI)/arch-$(ARCH)
27+
<linkflags>-L$(ANDROIDNDK)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/$(ARCH)
28+
<linkflags>-L$(PYTHON_ROOT)/lib
29+
#<linkflags>-L$(OPENSSL_BUILD_PATH)
30+
<linkflags>-lgnustl_shared
31+
<linkflags>-lpython2.7
32+
#<linkflags>-lcrypto
33+
#<linkflags>-lssl
34+
;

0 commit comments

Comments
 (0)