Skip to content

Commit 164c227

Browse files
committed
[libraries] Move png to mainline
Also modify Pillow recipe because depends on png
1 parent 1223337 commit 164c227

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

pythonforandroid/recipes/Pillow/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
2121
ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include')
2222

2323
png = self.get_recipe('png', self.ctx)
24-
png_lib_dir = png.get_lib_dir(arch)
25-
png_jni_dir = png.get_jni_dir(arch)
24+
png_lib_dir = join(png.get_build_dir(arch.arch), '.libs')
25+
png_inc_dir = png.get_build_dir(arch)
2626

2727
jpeg = self.get_recipe('jpeg', self.ctx)
2828
jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch)
@@ -41,7 +41,7 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
4141
env['FREETYPE_ROOT'] = '{}|{}'.format(free_lib_dir, free_inc_dir)
4242
env['ZLIB_ROOT'] = '{}|{}'.format(ndk_lib_dir, ndk_include_dir)
4343

44-
cflags = ' -I{}'.format(png_jni_dir)
44+
cflags = ' -I{}'.format(png_inc_dir)
4545
cflags += ' -I{} -I{}'.format(harf_inc_dir, join(harf_inc_dir, 'src'))
4646
cflags += ' -I{}'.format(free_inc_dir)
4747
cflags += ' -I{}'.format(jpeg_inc_dir)
Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
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
27

38

4-
class PngRecipe(NDKRecipe):
9+
class PngRecipe(Recipe):
510
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'
1213

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+
)
1518

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'))
1750

1851

1952
recipe = PngRecipe()

0 commit comments

Comments
 (0)