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

Pil's recipe migrated to Pillow (Fixed Headers) #786

Closed
wants to merge 7 commits 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
111 changes: 77 additions & 34 deletions pythonforandroid/recipes/pil/__init__.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,84 @@
from os.path import join

from pythonforandroid.toolchain import shprint
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
from pythonforandroid.logger import info
from os.path import join, exists
import sh


class PILRecipe(CompiledComponentsPythonRecipe):
name = 'pil'
version = '1.1.7'
url = 'http://effbot.org/downloads/Imaging-{version}.tar.gz'
depends = ['python2', 'png', 'jpeg']
site_packages_name = 'PIL'

patches = ['disable-tk.patch',
'fix-directories.patch']

def get_recipe_env(self, arch=None):
env = super(PILRecipe, self).get_recipe_env(arch)

png = self.get_recipe('png', self.ctx)
png_lib_dir = png.get_lib_dir(arch)
png_jni_dir = png.get_jni_dir(arch)
jpeg = self.get_recipe('jpeg', self.ctx)
jpeg_lib_dir = jpeg.get_lib_dir(arch)
jpeg_jni_dir = jpeg.get_jni_dir(arch)
env['JPEG_ROOT'] = '{}|{}'.format(jpeg_lib_dir, jpeg_jni_dir)

cflags = ' -I{} -L{} -I{} -L{}'.format(png_jni_dir, png_lib_dir, jpeg_jni_dir, jpeg_lib_dir)
env['CFLAGS'] += cflags
env['CXXFLAGS'] += cflags
env['CC'] += cflags
env['CXX'] += cflags

ndk_dir = self.ctx.ndk_platform
ndk_lib_dir = join(ndk_dir, 'usr', 'lib')
ndk_include_dir = join(ndk_dir, 'usr', 'include')
env['ZLIB_ROOT'] = '{}|{}'.format(ndk_lib_dir, ndk_include_dir)

return env
name = 'pil'
version = '3.1.0'
url = 'https://pypi.python.org/packages/source/P/Pillow/Pillow-{version}.tar.gz'
depends = ['incremental', 'setuptools', ('python2', 'python3'), 'png', 'jpeg', 'freetype']
call_hostpython_via_targetpython = False
site_packages_name = 'PIL'
patches = ['disable-tk.patch',
'fix-directories.patch']

def get_recipe_env(self, arch=None):
# The python's headers/linking should be placed into recipe.py file...
# and should be removed at some point, details in:
# https://github.com/kivy/python-for-android/pull/793/files
env = super(PILRecipe, self).get_recipe_env(arch)
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
' -lpython2.7'

# Set linker to use the correct gcc
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'

# png flags
r = self.get_recipe('png', self.ctx)
png_lib_dir = r.get_lib_dir(arch)
png_inc_dir = join(r.get_build_dir(arch.arch), 'jni')
cflags = ' -I{} -L{}'.format(png_inc_dir, png_lib_dir)

# jpeg flags
r = self.get_recipe('jpeg', self.ctx)
jpeg_lib_dir = r.get_lib_dir(arch)
jpeg_jni_dir = r.get_jni_dir(arch)
cflags += ' -I{} -I{} -I{} -L{}'.format(
jpeg_jni_dir, join(jpeg_jni_dir, 'android'),
join(jpeg_jni_dir, 'simd'), jpeg_lib_dir)

# freetype flags
r = self.get_recipe('freetype', self.ctx)
env['FREETYPE_VERSION'] = r.version
free_lib_dir = join(r.get_build_dir(arch.arch), 'objs', '.libs')
free_inc_dir = join(r.get_build_dir(arch.arch), 'include')
cflags += ' -I{} -L{}'.format(free_inc_dir, free_lib_dir)
env['LDFLAGS'] += ' -L{} -lfreetype{}'.format(
free_lib_dir, '')
if 'harfbuzz' in self.ctx.recipe_build_order:
r = self.get_recipe('harfbuzz', self.ctx)
harf_lib_dir = join(r.get_build_dir(arch.arch), 'src', '.libs')
harf_inc_dir = r.get_build_dir(arch.arch)
cflags += ' -I{} -I{} -L{}'.format(
harf_inc_dir, join(harf_inc_dir, 'src'),
harf_lib_dir)
env['LDFLAGS'] += ' -L{} -lharfbuzz{}'.format(
harf_lib_dir, '')
# Patch freetype headers to be found by pil
freetype_link = join(free_inc_dir, 'freetype')
if not exists(freetype_link):
shprint(sh.ln, '-s', join(free_inc_dir), freetype_link)

env['JPEG_ROOT'] = '{}|{}'.format(jpeg_lib_dir, jpeg_jni_dir)
env['FREETYPE_ROOT'] = '{}|{}'.format(free_lib_dir, free_inc_dir)
info('JPEG_ROOT: {}'.format(env['JPEG_ROOT']))
info('FREETYPE_ROOT: {}'.format(env['FREETYPE_ROOT']))

env['CFLAGS'] += cflags
env['CXXFLAGS'] += cflags
env['CC'] += cflags
env['CXX'] += cflags

ndk_dir = self.ctx.ndk_platform
ndk_lib_dir = join(ndk_dir, 'usr', 'lib')
ndk_include_dir = join(ndk_dir, 'usr', 'include')
env['ZLIB_ROOT'] = '{}|{}'.format(ndk_lib_dir, ndk_include_dir)

return env

recipe = PILRecipe()
21 changes: 10 additions & 11 deletions pythonforandroid/recipes/pil/disable-tk.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
--- Imaging-1.1.7/setup.py.orig 2012-08-31 12:52:25.000000000 +0200
+++ Imaging-1.1.7/setup.py 2012-08-31 12:53:04.000000000 +0200
@@ -322,7 +322,7 @@
"_imagingcms", ["_imagingcms.c"], libraries=["lcms"] + extra
))

- if sys.platform == "darwin":
+ if False: #sys.platform == "darwin":
# locate Tcl/Tk frameworks
frameworks = []
framework_roots = [
--- pil/setup.py.orig 2016-04-11 01:08:18.290901000 +0200
+++ pil/setup.py 2016-04-11 01:11:36.427513351 +0200
@@ -581,7 +581,7 @@
"PIL._webp", ["_webp.c"], libraries=libs, define_macros=defs))

if feature.tcl and feature.tk:
- if sys.platform == "darwin":
+ if False: #sys.platform == "darwin":
# locate Tcl/Tk frameworks
frameworks = []
framework_roots = [
Loading