|
1 |
| -from pythonforandroid.recipe import NDKRecipe |
2 |
| -from pythonforandroid.util import current_directory |
| 1 | +from pythonforandroid.recipe import Recipe |
3 | 2 | from pythonforandroid.logger import shprint
|
4 |
| - |
| 3 | +from pythonforandroid.util import current_directory |
| 4 | +from multiprocessing import cpu_count |
| 5 | +from os.path import join, exists |
5 | 6 | import sh
|
6 | 7 |
|
7 |
| -from os.path import join |
8 | 8 |
|
9 |
| - |
10 |
| -class PngRecipe(NDKRecipe): |
| 9 | +class PngRecipe(Recipe): |
11 | 10 | name = 'png'
|
12 |
| - # This version is the last `sha commit` published in the repo (it's more |
13 |
| - # than one year old...) and it's for libpng version `1.6.29`. We set a |
14 |
| - # commit for a version because the author of the github's repo never |
15 |
| - # released/tagged it, despite He performed the necessary changes in |
16 |
| - # master branch. |
17 |
| - version = 'b43b4c6' |
18 |
| - |
19 |
| - # TODO: Try to move the repo to mainline |
20 |
| - url = 'https://github.com/julienr/libpng-android/archive/{version}.zip' |
21 |
| - |
22 |
| - patches = ['build_shared_library.patch'] |
23 |
| - |
24 |
| - generated_libraries = ['libpng.so'] |
| 11 | + version = 'v1.6.37' |
| 12 | + url = 'https://github.com/glennrp/libpng/archive/{version}.zip' |
| 13 | + |
| 14 | + def should_build(self, arch): |
| 15 | + return not exists( |
| 16 | + join(self.get_build_dir(arch.arch), '.libs', 'libpng16.so') |
| 17 | + ) |
| 18 | + |
| 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 |
25 | 27 |
|
26 | 28 | def build_arch(self, arch):
|
27 | 29 | super(PngRecipe, self).build_arch(arch)
|
28 |
| - |
29 |
| - with current_directory(self.get_build_dir(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 | + ) |
30 | 38 | shprint(
|
31 |
| - sh.cp, |
32 |
| - join( |
33 |
| - self.get_build_dir(arch.arch), |
34 |
| - 'libs', |
35 |
| - arch.arch, |
36 |
| - 'libpng.so'), |
37 |
| - join(self.ctx.get_libs_dir(arch.arch), 'libpng16.so')) |
38 |
| - |
39 |
| - |
40 |
| - pass |
| 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')) |
| 50 | + |
41 | 51 |
|
42 | 52 | recipe = PngRecipe()
|
0 commit comments