|
| 1 | +from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory |
| 2 | +from pythonforandroid.util import ensure_dir |
| 3 | +from os.path import exists, join, abspath |
| 4 | +import sh |
| 5 | +from multiprocessing import cpu_count |
| 6 | + |
| 7 | +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' |
| 11 | + depends = ['python2'] |
| 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')) |
| 16 | + |
| 17 | + 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) |
| 28 | + 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 | + |
| 43 | +recipe = LibgeosRecipe() |
| 44 | + |
0 commit comments