|
| 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() |
0 commit comments