|
| 1 | +from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory |
| 2 | +from pythonforandroid.util import ensure_dir |
| 3 | +from os.path import exists, join |
| 4 | +import sh |
| 5 | + |
| 6 | + |
| 7 | +class LibZMQRecipe(Recipe): |
| 8 | + version = '4.1.4' |
| 9 | + url = 'http://download.zeromq.org/zeromq-{version}.tar.gz' |
| 10 | + depends = ['python2'] |
| 11 | + |
| 12 | + def should_build(self, arch): |
| 13 | + super(LibZMQRecipe, self).should_build(arch) |
| 14 | + return True |
| 15 | + return not exists(join(self.ctx.get_libs_dir(arch.arch), 'libzmq.so')) |
| 16 | + |
| 17 | + def build_arch(self, arch): |
| 18 | + super(LibZMQRecipe, self).build_arch(arch) |
| 19 | + env = self.get_recipe_env(arch) |
| 20 | + # |
| 21 | + # libsodium_recipe = Recipe.get_recipe('libsodium', self.ctx) |
| 22 | + # libsodium_dir = libsodium_recipe.get_build_dir(arch.arch) |
| 23 | + # env['sodium_CFLAGS'] = '-I{}'.format(join( |
| 24 | + # libsodium_dir, 'src')) |
| 25 | + # env['sodium_LDLAGS'] = '-L{}'.format(join( |
| 26 | + # libsodium_dir, 'src', 'libsodium', '.libs')) |
| 27 | + |
| 28 | + curdir = self.get_build_dir(arch.arch) |
| 29 | + prefix = join(curdir, "install") |
| 30 | + with current_directory(curdir): |
| 31 | + bash = sh.Command('sh') |
| 32 | + shprint( |
| 33 | + bash, './configure', |
| 34 | + '--host=arm-linux-androideabi', |
| 35 | + '--without-documentation', |
| 36 | + '--prefix={}'.format(prefix), |
| 37 | + '--with-libsodium=no', |
| 38 | + _env=env) |
| 39 | + shprint(sh.make, _env=env) |
| 40 | + shprint(sh.make, 'install', _env=env) |
| 41 | + shutil.copyfile('.libs/libzmq.so', join( |
| 42 | + self.ctx.get_libs_dir(arch.arch), 'libzmq.so')) |
| 43 | + |
| 44 | + bootstrap_obj_dir = join(self.ctx.bootstrap.build_dir, 'obj', 'local', arch.arch) |
| 45 | + ensure_dir(bootstrap_obj_dir) |
| 46 | + shutil.copyfile( |
| 47 | + '{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}/libgnustl_shared.so'.format( |
| 48 | + self.ctx.ndk_dir, arch), |
| 49 | + join(bootstrap_obj_dir, 'libgnustl_shared.so')) |
| 50 | + |
| 51 | + def get_recipe_env(self, arch): |
| 52 | + # XXX should stl be configuration for the toolchain itself? |
| 53 | + env = super(LibZMQRecipe, self).get_recipe_env(arch) |
| 54 | + env['CFLAGS'] += ' -Os' |
| 55 | + env['CXXFLAGS'] += ' -Os -fPIC -fvisibility=default' |
| 56 | + env['CXXFLAGS'] += ' -I{}/sources/cxx-stl/gnu-libstdc++/4.8/include'.format(self.ctx.ndk_dir) |
| 57 | + env['CXXFLAGS'] += ' -I{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}/include'.format( |
| 58 | + self.ctx.ndk_dir, arch) |
| 59 | + env['CXXFLAGS'] += ' -L{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}'.format( |
| 60 | + self.ctx.ndk_dir, arch) |
| 61 | + env['CXXFLAGS'] += ' -lgnustl_shared' |
| 62 | + env['LDFLAGS'] += ' -L{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}'.format( |
| 63 | + self.ctx.ndk_dir, arch) |
| 64 | + return env |
| 65 | + |
| 66 | + |
| 67 | +recipe = LibZMQRecipe() |
0 commit comments