|
| 1 | +import sh |
| 2 | +import glob |
| 3 | +from os.path import exists, join |
| 4 | +from pythonforandroid.toolchain import Recipe, shprint |
| 5 | +from pythonforandroid.util import current_directory |
| 6 | +from multiprocessing import cpu_count |
| 7 | + |
| 8 | + |
| 9 | +class ZlibRecipe(Recipe): |
| 10 | + version = '1.2.11' |
| 11 | + url = 'https://zlib.net/zlib-{version}.tar.gz' |
| 12 | + depends = [] |
| 13 | + patches = ['lib-version.patch'] |
| 14 | + |
| 15 | + @property |
| 16 | + def version_link(self): |
| 17 | + return self.version.replace('.', '') |
| 18 | + |
| 19 | + def should_build(self, arch): |
| 20 | + return not exists( |
| 21 | + join(self.ctx.get_libs_dir(arch.arch), |
| 22 | + 'libz{}.so'.format(self.version_link))) |
| 23 | + |
| 24 | + def build_arch(self, arch): |
| 25 | + super(ZlibRecipe, self).build_arch(arch) |
| 26 | + build_dir = self.get_build_dir(arch.arch) |
| 27 | + |
| 28 | + with current_directory(build_dir): |
| 29 | + env = self.get_recipe_env(arch) |
| 30 | + |
| 31 | + shprint(sh.cmake, |
| 32 | + '-DP4A_LINK_VERSION={}'.format(self.version.replace('.', '')), |
| 33 | + '-DANDROID_ABI={}'.format(arch.arch), |
| 34 | + '-DANDROID_NATIVE_API_LEVEL={}'.format(self.ctx.ndk_api), |
| 35 | + |
| 36 | + '-DCMAKE_TOOLCHAIN_FILE={}'.format( |
| 37 | + join(self.ctx.ndk_dir, 'build', 'cmake', |
| 38 | + 'android.toolchain.cmake')), |
| 39 | + _env=env) |
| 40 | + shprint(sh.make, '-j' + str(cpu_count()), _env=env) |
| 41 | + |
| 42 | + # copy shared libs to libs collection |
| 43 | + so_libs = glob.glob(join(build_dir, '*.so')) |
| 44 | + self.install_libs(arch, *so_libs) |
| 45 | + |
| 46 | + |
| 47 | +recipe = ZlibRecipe() |
0 commit comments