|
1 |
| -from pythonforandroid.recipe import NDKRecipe |
| 1 | +from pythonforandroid.recipe import Recipe |
| 2 | +from pythonforandroid.logger import shprint |
| 3 | +from pythonforandroid.util import current_directory |
| 4 | +from multiprocessing import cpu_count |
| 5 | +from os.path import join, exists |
| 6 | +import sh |
2 | 7 |
|
3 | 8 |
|
4 |
| -class PngRecipe(NDKRecipe): |
| 9 | +class PngRecipe(Recipe): |
5 | 10 | name = 'png'
|
6 |
| - # This version is the last `sha commit` published in the repo (it's more |
7 |
| - # than one year old...) and it's for libpng version `1.6.29`. We set a |
8 |
| - # commit for a version because the author of the github's repo never |
9 |
| - # released/tagged it, despite He performed the necessary changes in |
10 |
| - # master branch. |
11 |
| - version = 'b43b4c6' |
| 11 | + version = 'v1.6.37' |
| 12 | + url = 'https://github.com/glennrp/libpng/archive/{version}.zip' |
12 | 13 |
|
13 |
| - # TODO: Try to move the repo to mainline |
14 |
| - url = 'https://github.com/julienr/libpng-android/archive/{version}.zip' |
| 14 | + def should_build(self, arch): |
| 15 | + return not exists( |
| 16 | + join(self.get_build_dir(arch.arch), '.libs', 'libpng16.so') |
| 17 | + ) |
15 | 18 |
|
16 |
| - generated_libraries = ['libpng.a'] |
| 19 | + def get_recipe_env(self, arch=None): |
| 20 | + env = super(PngRecipe, self).get_recipe_env(arch) |
| 21 | + ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib') |
| 22 | + ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include') |
| 23 | + env['CFLAGS'] += ' -I{}'.format(ndk_include_dir) |
| 24 | + env['LDFLAGS'] += ' -L{}'.format(ndk_lib_dir) |
| 25 | + env['LDFLAGS'] += ' --sysroot={}'.format(self.ctx.ndk_platform) |
| 26 | + return env |
| 27 | + |
| 28 | + def build_arch(self, arch): |
| 29 | + super(PngRecipe, self).build_arch(arch) |
| 30 | + build_dir = self.get_build_dir(arch.arch) |
| 31 | + with current_directory(build_dir): |
| 32 | + env = self.get_recipe_env(arch) |
| 33 | + build_arch = ( |
| 34 | + shprint(sh.gcc, '-dumpmachine') |
| 35 | + .stdout.decode('utf-8') |
| 36 | + .split('\n')[0] |
| 37 | + ) |
| 38 | + shprint( |
| 39 | + sh.Command('./configure'), |
| 40 | + '--build=' + build_arch, |
| 41 | + '--host=' + arch.command_prefix, |
| 42 | + '--target=' + arch.command_prefix, |
| 43 | + '--disable-static', |
| 44 | + '--enable-shared', |
| 45 | + '--prefix={}/install'.format(self.get_build_dir(arch.arch)), |
| 46 | + _env=env, |
| 47 | + ) |
| 48 | + shprint(sh.make, '-j', str(cpu_count()), _env=env) |
| 49 | + self.install_libs(arch, join(build_dir, '.libs', 'libpng16.so')) |
17 | 50 |
|
18 | 51 |
|
19 | 52 | recipe = PngRecipe()
|
0 commit comments