|
| 1 | +from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory |
| 2 | +from os.path import join, exists |
| 3 | +import sh |
| 4 | + |
| 5 | +# This recipe builds libtorrent with Python bindings |
| 6 | +# It depends on Boost.Build and the source of several Boost libraries present in BOOST_ROOT, |
| 7 | +# which is all provided by the boost recipe |
| 8 | +class LibtorrentRecipe(Recipe): |
| 9 | + version = '1.0.8' |
| 10 | + # Don't forget to change the URL when changing the version |
| 11 | + url = 'http://github.com/arvidn/libtorrent/archive/libtorrent-1_0_8.tar.gz' |
| 12 | + depends = ['boost', 'python2'] #'openssl' |
| 13 | + patches = ['disable-so-version.patch', 'use-soname-python.patch'] |
| 14 | + |
| 15 | + def should_build(self, arch): |
| 16 | + return not ( self.has_libs(arch, 'libboost_python.so', 'libboost_system.so', 'libtorrent.so') |
| 17 | + and self.ctx.has_package('libtorrent.so', arch.arch) ) |
| 18 | + |
| 19 | + def build_arch(self, arch): |
| 20 | + super(LibtorrentRecipe, self).build_arch(arch) |
| 21 | + env = self.get_recipe_env(arch) |
| 22 | + with current_directory(join(self.get_build_dir(arch.arch), 'bindings/python')): |
| 23 | + # Compile libtorrent with boost libraries and python bindings |
| 24 | + b2 = sh.Command(join(env['BOOST_ROOT'], 'b2')) |
| 25 | + shprint(b2, |
| 26 | + '-q', |
| 27 | + '-j5', |
| 28 | + 'toolset=gcc-' + env['ARCH'], |
| 29 | + 'target-os=android', |
| 30 | + 'threading=multi', |
| 31 | + 'link=shared', |
| 32 | + 'boost-link=shared', |
| 33 | + 'boost=source', |
| 34 | + # 'encryption=openssl', |
| 35 | + '--prefix=' + env['CROSSHOME'], |
| 36 | + 'release' |
| 37 | + , _env=env) |
| 38 | + # Copy the shared libraries into the libs folder |
| 39 | + build_subdirs = 'gcc-arm/release/boost-link-shared/boost-source/libtorrent-python-pic-on/target-os-android/threading-multi/visibility-hidden' #encryption-openssl |
| 40 | + shutil.copyfile(join(env['BOOST_BUILD_PATH'], 'bin.v2/libs/python/build', build_subdirs, 'libboost_python.so'), |
| 41 | + join(self.ctx.get_libs_dir(arch.arch), 'libboost_python.so')) |
| 42 | + shutil.copyfile(join(env['BOOST_BUILD_PATH'], 'bin.v2/libs/system/build', build_subdirs, 'libboost_system.so'), |
| 43 | + join(self.ctx.get_libs_dir(arch.arch), 'libboost_system.so')) |
| 44 | + shutil.copyfile(join(self.get_build_dir(arch.arch), 'bin', build_subdirs, 'libtorrent.so'), |
| 45 | + join(self.ctx.get_libs_dir(arch.arch), 'libtorrent.so')) |
| 46 | + shutil.copyfile(join(self.get_build_dir(arch.arch), 'bindings/python/bin', build_subdirs, 'libtorrent.so'), |
| 47 | + join(self.ctx.get_site_packages_dir(arch.arch), 'libtorrent.so')) |
| 48 | + |
| 49 | + def get_recipe_env(self, arch): |
| 50 | + env = super(LibtorrentRecipe, self).get_recipe_env(arch) |
| 51 | + # Copy environment from boost recipe |
| 52 | + env.update(self.get_recipe('boost', self.ctx).get_recipe_env(arch)) |
| 53 | + return env |
| 54 | + |
| 55 | +recipe = LibtorrentRecipe() |
0 commit comments