1
1
from pythonforandroid .toolchain import Recipe , shprint , shutil , current_directory
2
2
from os .path import join , exists
3
+ from os import environ
3
4
import sh
4
5
5
6
"""
9
10
10
11
11
12
class BoostRecipe (Recipe ):
12
- version = '1.60.0'
13
- # Don't forget to change the URL when changing the version
14
- url = 'http://downloads.sourceforge.net/project/boost/boost/{version}/boost_1_60_0.tar.bz2'
15
- depends = ['python2' ]
16
- patches = ['disable-so-version.patch' , 'use-android-libs.patch' ]
13
+ # Todo: make recipe compatible with all p4a architectures
14
+ '''
15
+ .. note:: This recipe can be built only against API 21+ and arch armeabi-v7a
16
+
17
+ .. versionchanged:: 0.6.0
18
+ Rewrote recipe to support clang's build. The following changes has
19
+ been made:
20
+
21
+ - Bumped version number to 1.68.0
22
+ - Better version handling for url
23
+ - Added python 3 compatibility
24
+ - Default compiler for ndk's toolchain set to clang
25
+ - Python version will be detected via user-config.jam
26
+ - Changed stl's lib from ``gnustl_shared`` to ``c++_shared``
27
+ '''
28
+ version = '1.68.0'
29
+ url = 'http://downloads.sourceforge.net/project/boost/' \
30
+ 'boost/{version}/boost_{version_underscore}.tar.bz2'
31
+ depends = [('python2' , 'python3' )]
32
+ patches = ['disable-so-version.patch' ,
33
+ 'use-android-libs.patch' ,
34
+ 'fix-android-issues.patch' ]
35
+
36
+ @property
37
+ def versioned_url (self ):
38
+ if self .url is None :
39
+ return None
40
+ return self .url .format (
41
+ version = self .version ,
42
+ version_underscore = self .version .replace ('.' , '_' ))
17
43
18
44
def should_build (self , arch ):
19
45
return not exists (join (self .get_build_dir (arch .arch ), 'b2' ))
@@ -28,41 +54,50 @@ def prebuild_arch(self, arch):
28
54
shprint (bash , join (self .ctx .ndk_dir , 'build/tools/make-standalone-toolchain.sh' ),
29
55
'--arch=' + env ['ARCH' ],
30
56
'--platform=android-' + str (self .ctx .android_api ),
31
- '--toolchain=' + env ['CROSSHOST' ] + '-' + env ['TOOLCHAIN_VERSION' ],
57
+ '--toolchain=' + env ['CROSSHOST' ] + '-' + self .ctx .toolchain_version + ':-llvm' ,
58
+ '--use-llvm' ,
59
+ '--stl=libc++' ,
32
60
'--install-dir=' + env ['CROSSHOME' ]
33
- )
61
+ )
34
62
# Set custom configuration
35
63
shutil .copyfile (join (self .get_recipe_dir (), 'user-config.jam' ),
36
64
join (env ['BOOST_BUILD_PATH' ], 'user-config.jam' ))
37
65
38
66
def build_arch (self , arch ):
39
67
super (BoostRecipe , self ).build_arch (arch )
40
68
env = self .get_recipe_env (arch )
69
+ env ['PYTHON_HOST' ] = self .ctx .hostpython
41
70
with current_directory (self .get_build_dir (arch .arch )):
42
71
# Compile Boost.Build engine with this custom toolchain
43
72
bash = sh .Command ('bash' )
44
- shprint (bash , 'bootstrap.sh' ,
45
- '--with-python=' + join (env ['PYTHON_ROOT' ], 'bin/python.host' ),
46
- '--with-python-version=2.7' ,
47
- '--with-python-root=' + env ['PYTHON_ROOT' ]
48
- ) # Do not pass env
73
+ shprint (bash , 'bootstrap.sh' ) # Do not pass env
49
74
# Install app stl
50
- shutil .copyfile (join (env ['CROSSHOME' ], env ['CROSSHOST' ], 'lib/libgnustl_shared.so' ),
51
- join (self .ctx .get_libs_dir (arch .arch ), 'libgnustl_shared.so' ))
75
+ shutil .copyfile (
76
+ join (self .ctx .ndk_dir , 'sources/cxx-stl/llvm-libc++/libs/'
77
+ 'armeabi-v7a/libc++_shared.so' ),
78
+ join (self .ctx .get_libs_dir (arch .arch ), 'libc++_shared.so' ))
52
79
53
80
def select_build_arch (self , arch ):
54
81
return arch .arch .replace ('eabi-v7a' , '' ).replace ('eabi' , '' )
55
82
56
83
def get_recipe_env (self , arch ):
57
- env = super (BoostRecipe , self ).get_recipe_env (arch )
84
+ # We don't use the normal env because we
85
+ # are building with a standalone toolchain
86
+ env = environ .copy ()
87
+
58
88
env ['BOOST_BUILD_PATH' ] = self .get_build_dir (arch .arch ) # find user-config.jam
59
89
env ['BOOST_ROOT' ] = env ['BOOST_BUILD_PATH' ] # find boost source
60
- env ['PYTHON_ROOT' ] = self .ctx .get_python_install_dir ()
90
+
91
+ env ['PYTHON_ROOT' ] = self .ctx .python_recipe .link_root (arch .arch )
92
+ env ['PYTHON_INCLUDE' ] = self .ctx .python_recipe .include_root (arch .arch )
93
+ env ['PYTHON_MAJOR_MINOR' ] = self .ctx .python_recipe .version [:3 ]
94
+ env ['PYTHON_LINK_VERSION' ] = self .ctx .python_recipe .major_minor_version_string
95
+ if 'python3' in self .ctx .python_recipe .name :
96
+ env ['PYTHON_LINK_VERSION' ] += 'm'
97
+
61
98
env ['ARCH' ] = self .select_build_arch (arch )
62
- env ['ANDROIDAPI' ] = str (self .ctx .android_api )
63
99
env ['CROSSHOST' ] = env ['ARCH' ] + '-linux-androideabi'
64
100
env ['CROSSHOME' ] = join (env ['BOOST_ROOT' ], 'standalone-' + env ['ARCH' ] + '-toolchain' )
65
- env ['TOOLCHAIN_PREFIX' ] = join (env ['CROSSHOME' ], 'bin' , env ['CROSSHOST' ])
66
101
return env
67
102
68
103
0 commit comments