forked from kivy/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
69 lines (52 loc) · 2.76 KB
/
__init__.py
File metadata and controls
69 lines (52 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from os.path import join
from pythonforandroid.recipe import PyProjectRecipe
class PillowRecipe(PyProjectRecipe):
"""
A recipe for Pillow (previously known as Pil).
This recipe allow us to build the Pillow recipe with support for different
types of images and fonts. But you should be aware, that in order to use
some of the features of Pillow, we must build some libraries. By default
we automatically trigger the build of below libraries::
- freetype: rendering fonts support.
- harfbuzz: a text shaping library.
- jpeg: reading and writing JPEG image files.
- png: support for PNG images.
But you also could enable the build of some extra image types by requesting
the build of some libraries via argument `requirements`::
- libwebp: library to encode and decode images in WebP format.
"""
version = '11.3.0'
url = 'https://github.com/python-pillow/Pillow/archive/{version}.tar.gz'
site_packages_name = 'PIL'
patches = ["setup.py.patch"]
depends = ['png', 'jpeg', 'freetype']
hostpython_prerequisites = ["setuptools>=77"]
opt_depends = ['libwebp']
def get_recipe_env(self, arch, **kwargs):
env = super().get_recipe_env(arch, **kwargs)
# Add math library linkage
env["LDFLAGS"] = env.get("LDFLAGS", "") + " -lm"
jpeg = self.get_recipe('jpeg', self.ctx)
jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch)
env["JPEG_ROOT"] = "{}:{}".format(jpeg_lib_dir, jpeg_inc_dir)
freetype = self.get_recipe('freetype', self.ctx)
free_lib_dir = join(freetype.get_build_dir(arch.arch), 'objs', '.libs')
free_inc_dir = join(freetype.get_build_dir(arch.arch), 'include')
env["FREETYPE_ROOT"] = "{}:{}".format(free_lib_dir, free_inc_dir)
# harfbuzz is a direct dependency of freetype and we need the proper
# flags to successfully build the Pillow recipe, so we add them here.
harfbuzz = self.get_recipe('harfbuzz', self.ctx)
harf_lib_dir = join(harfbuzz.get_build_dir(arch.arch), 'src', '.libs')
harf_inc_dir = harfbuzz.get_build_dir(arch.arch)
env["HARFBUZZ_ROOT"] = "{}:{}".format(harf_lib_dir, harf_inc_dir)
env["ZLIB_ROOT"] = f"{arch.ndk_lib_dir_versioned}:{self.ctx.ndk.sysroot_include_dir}"
# libwebp is an optional dependency, so we add the
# flags if we have it in our `ctx.recipe_build_order`
if 'libwebp' in self.ctx.recipe_build_order:
webp = self.get_recipe('libwebp', self.ctx)
webp_install = join(
webp.get_build_dir(arch.arch), 'installation'
)
env["WEBP_ROOT"] = f"{join(webp_install, 'lib')}:{join(webp_install, 'include')}"
return env
recipe = PillowRecipe()