Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Move png to mainline #1829

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pythonforandroid/recipes/Pillow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include')

png = self.get_recipe('png', self.ctx)
png_lib_dir = png.get_lib_dir(arch)
png_jni_dir = png.get_jni_dir(arch)
png_lib_dir = join(png.get_build_dir(arch.arch), '.libs')
png_inc_dir = png.get_build_dir(arch)

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

cflags = ' -I{}'.format(png_jni_dir)
cflags = ' -I{}'.format(png_inc_dir)
cflags += ' -I{} -I{}'.format(harf_inc_dir, join(harf_inc_dir, 'src'))
cflags += ' -I{}'.format(free_inc_dir)
cflags += ' -I{}'.format(jpeg_inc_dir)
Expand Down
55 changes: 44 additions & 11 deletions pythonforandroid/recipes/png/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
from pythonforandroid.recipe import NDKRecipe
from pythonforandroid.recipe import Recipe
from pythonforandroid.logger import shprint
from pythonforandroid.util import current_directory
from multiprocessing import cpu_count
from os.path import join, exists
import sh


class PngRecipe(NDKRecipe):
class PngRecipe(Recipe):
name = 'png'
# This version is the last `sha commit` published in the repo (it's more
# than one year old...) and it's for libpng version `1.6.29`. We set a
# commit for a version because the author of the github's repo never
# released/tagged it, despite He performed the necessary changes in
# master branch.
version = 'b43b4c6'
version = 'v1.6.37'
url = 'https://github.com/glennrp/libpng/archive/{version}.zip'

# TODO: Try to move the repo to mainline
url = 'https://github.com/julienr/libpng-android/archive/{version}.zip'
def should_build(self, arch):
return not exists(
join(self.get_build_dir(arch.arch), '.libs', 'libpng16.so')
)

generated_libraries = ['libpng.a']
def get_recipe_env(self, arch=None):
env = super(PngRecipe, self).get_recipe_env(arch)
ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib')
ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include')
env['CFLAGS'] += ' -I{}'.format(ndk_include_dir)
env['LDFLAGS'] += ' -L{}'.format(ndk_lib_dir)
env['LDFLAGS'] += ' --sysroot={}'.format(self.ctx.ndk_platform)
return env

def build_arch(self, arch):
super(PngRecipe, self).build_arch(arch)
build_dir = self.get_build_dir(arch.arch)
with current_directory(build_dir):
env = self.get_recipe_env(arch)
build_arch = (
shprint(sh.gcc, '-dumpmachine')
.stdout.decode('utf-8')
.split('\n')[0]
)
shprint(
sh.Command('./configure'),
'--build=' + build_arch,
'--host=' + arch.command_prefix,
'--target=' + arch.command_prefix,
'--disable-static',
'--enable-shared',
'--prefix={}/install'.format(self.get_build_dir(arch.arch)),
_env=env,
)
shprint(sh.make, '-j', str(cpu_count()), _env=env)
self.install_libs(arch, join(build_dir, '.libs', 'libpng16.so'))


recipe = PngRecipe()