|
| 1 | +from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory |
| 2 | +from os.path import join, exists |
| 3 | +import sh |
| 4 | + |
| 5 | +class LevelDBRecipe(Recipe): |
| 6 | + version = '1.18' |
| 7 | + url = 'https://github.com/google/leveldb/archive/v{version}.tar.gz' |
| 8 | + opt_depends = ['snappy'] |
| 9 | + patches = ['disable-so-version.patch', 'find-snappy.patch'] |
| 10 | + |
| 11 | + def should_build(self, arch): |
| 12 | + return not self.has_libs(arch, 'libleveldb.so', 'libgnustl_shared.so') |
| 13 | + |
| 14 | + def build_arch(self, arch): |
| 15 | + super(LevelDBRecipe, self).build_arch(arch) |
| 16 | + env = self.get_recipe_env(arch) |
| 17 | + with current_directory(self.get_build_dir(arch.arch)): |
| 18 | + if 'snappy' in recipe.ctx.recipe_build_order: |
| 19 | + # Copy source from snappy recipe |
| 20 | + sh.cp('-rf', self.get_recipe('snappy', self.ctx).get_build_dir(arch.arch), 'snappy') |
| 21 | + # Build |
| 22 | + shprint(sh.make, _env=env) |
| 23 | + # Copy the shared library |
| 24 | + shutil.copyfile('libleveldb.so', join(self.ctx.get_libs_dir(arch.arch), 'libleveldb.so')) |
| 25 | + # Copy stl |
| 26 | + shutil.copyfile(self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/libgnustl_shared.so', |
| 27 | + join(self.ctx.get_libs_dir(arch.arch), 'libgnustl_shared.so')) |
| 28 | + |
| 29 | + def get_recipe_env(self, arch): |
| 30 | + env = super(LevelDBRecipe, self).get_recipe_env(arch) |
| 31 | + env['TARGET_OS'] = 'OS_ANDROID_CROSSCOMPILE' |
| 32 | + if 'snappy' in recipe.ctx.recipe_build_order: |
| 33 | + env['CFLAGS'] += ' -DSNAPPY' + \ |
| 34 | + ' -I./snappy' |
| 35 | + env['CFLAGS'] += ' -I' + self.ctx.ndk_dir + '/platforms/android-' + str(self.ctx.android_api) + '/arch-' + arch.arch.replace('eabi', '') + '/usr/include' + \ |
| 36 | + ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/include' + \ |
| 37 | + ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/include' |
| 38 | + env['CXXFLAGS'] = env['CFLAGS'] |
| 39 | + env['CXXFLAGS'] += ' -frtti' |
| 40 | + env['CXXFLAGS'] += ' -fexceptions' |
| 41 | + env['LDFLAGS'] += ' -L' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + \ |
| 42 | + ' -lgnustl_shared' |
| 43 | + return env |
| 44 | + |
| 45 | +recipe = LevelDBRecipe() |
0 commit comments