|
1 |
| -from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory |
2 |
| -from os.path import exists, join |
3 |
| -import sh |
| 1 | +from pythonforandroid.util import current_directory, ensure_dir |
| 2 | +from pythonforandroid.toolchain import shprint |
| 3 | +from pythonforandroid.recipe import Recipe |
4 | 4 | from multiprocessing import cpu_count
|
| 5 | +from os.path import join |
| 6 | +import sh |
5 | 7 |
|
6 | 8 |
|
7 | 9 | class LibgeosRecipe(Recipe):
|
8 |
| - version = '3.5' |
9 |
| - # url = 'http://download.osgeo.org/geos/geos-{version}.tar.bz2' |
10 |
| - url = 'https://github.com/libgeos/libgeos/archive/svn-{version}.zip' |
| 10 | + version = '3.7.1' |
| 11 | + url = 'https://github.com/libgeos/libgeos/archive/{version}.zip' |
11 | 12 | depends = []
|
12 |
| - |
13 |
| - def should_build(self, arch): |
14 |
| - super(LibgeosRecipe, self).should_build(arch) |
15 |
| - return not exists(join(self.ctx.get_libs_dir(arch.arch), 'libgeos_c.so')) |
| 13 | + built_libraries = { |
| 14 | + 'libgeos.so': 'install_target/lib', |
| 15 | + 'libgeos_c.so': 'install_target/lib' |
| 16 | + } |
| 17 | + need_stl_shared = True |
16 | 18 |
|
17 | 19 | def build_arch(self, arch):
|
18 |
| - super(LibgeosRecipe, self).build_arch(arch) |
19 |
| - env = self.get_recipe_env(arch) |
20 |
| - |
21 |
| - with current_directory(self.get_build_dir(arch.arch)): |
22 |
| - dst_dir = join(self.get_build_dir(arch.arch), 'dist') |
23 |
| - bash = sh.Command('bash') |
24 |
| - print("If this fails make sure you have autoconf and libtool installed") |
25 |
| - shprint(bash, 'autogen.sh') # Requires autoconf and libtool |
26 |
| - shprint(bash, 'configure', '--host=arm-linux-androideabi', '--enable-shared', '--prefix={}'.format(dst_dir), _env=env) |
27 |
| - shprint(sh.make, '-j', str(cpu_count()), _env=env) |
| 20 | + source_dir = self.get_build_dir(arch.arch) |
| 21 | + build_target = join(source_dir, 'build_target') |
| 22 | + install_target = join(source_dir, 'install_target') |
| 23 | + |
| 24 | + ensure_dir(build_target) |
| 25 | + with current_directory(build_target): |
| 26 | + env = self.get_recipe_env(arch) |
| 27 | + shprint(sh.cmake, source_dir, |
| 28 | + '-DANDROID_ABI={}'.format(arch.arch), |
| 29 | + '-DANDROID_NATIVE_API_LEVEL={}'.format(self.ctx.ndk_api), |
| 30 | + '-DANDROID_STL=' + self.stl_lib_name, |
| 31 | + |
| 32 | + '-DCMAKE_TOOLCHAIN_FILE={}'.format( |
| 33 | + join(self.ctx.ndk_dir, 'build', 'cmake', |
| 34 | + 'android.toolchain.cmake')), |
| 35 | + '-DCMAKE_INSTALL_PREFIX={}'.format(install_target), |
| 36 | + '-DCMAKE_BUILD_TYPE=Release', |
| 37 | + |
| 38 | + '-DGEOS_ENABLE_TESTS=OFF', |
| 39 | + |
| 40 | + '-DBUILD_SHARED_LIBS=1', |
| 41 | + |
| 42 | + _env=env) |
| 43 | + shprint(sh.make, '-j' + str(cpu_count()), _env=env) |
| 44 | + |
| 45 | + # We make the install because this way we will have all the |
| 46 | + # includes in one place (mostly we are interested in `geos_c.h`, |
| 47 | + # which is not in the include folder, so this way we make easier to |
| 48 | + # link with this library...case of shapely's recipe) |
28 | 49 | shprint(sh.make, 'install', _env=env)
|
29 |
| - shutil.copyfile('{}/lib/libgeos_c.so'.format(dst_dir), join(self.ctx.get_libs_dir(arch.arch), 'libgeos_c.so')) |
30 |
| - |
31 |
| - def get_recipe_env(self, arch): |
32 |
| - env = super(LibgeosRecipe, self).get_recipe_env(arch) |
33 |
| - env['CXXFLAGS'] += ' -I{}/sources/cxx-stl/gnu-libstdc++/4.8/include'.format(self.ctx.ndk_dir) |
34 |
| - env['CXXFLAGS'] += ' -I{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}/include'.format( |
35 |
| - self.ctx.ndk_dir, arch) |
36 |
| - env['CXXFLAGS'] += ' -L{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}'.format( |
37 |
| - self.ctx.ndk_dir, arch) |
38 |
| - env['CXXFLAGS'] += ' -lgnustl_shared' |
39 |
| - env['LDFLAGS'] += ' -L{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}'.format( |
40 |
| - self.ctx.ndk_dir, arch) |
41 |
| - return env |
42 | 50 |
|
43 | 51 |
|
44 | 52 | recipe = LibgeosRecipe()
|
0 commit comments