Skip to content

Commit 6ec6f11

Browse files
committed
add levedb recipe;
1 parent 24831df commit 6ec6f11

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- leveldb/build_detect_platform 2014-09-16 23:19:52.000000000 +0200
2+
+++ leveldb-patch/build_detect_platform 2016-03-01 20:25:04.074484399 +0100
3+
@@ -124,6 +124,7 @@
4+
;;
5+
OS_ANDROID_CROSSCOMPILE)
6+
PLATFORM=OS_ANDROID
7+
+ PLATFORM_SHARED_VERSIONED=
8+
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX"
9+
PLATFORM_LDFLAGS="" # All pthread features are in the Android C library
10+
PORT_FILE=port/port_posix.cc
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- leveldb/build_detect_platform 2014-09-16 23:19:52.000000000 +0200
2+
+++ leveldb-patch/build_detect_platform 2016-03-01 21:56:04.926650079 +0100
3+
@@ -156,7 +157,7 @@
4+
# except for the test and benchmark files. By default, find will output a list
5+
# of all files matching either rule, so we need to append -print to make the
6+
# prune take effect.
7+
-DIRS="$PREFIX/db $PREFIX/util $PREFIX/table"
8+
+DIRS="$PREFIX/snappy $PREFIX/db $PREFIX/util $PREFIX/table"
9+
10+
set -f # temporarily disable globbing so that our patterns aren't expanded
11+
PRUNE_TEST="-name *test*.cc -prune"

0 commit comments

Comments
 (0)