|
1 | 1 | from pythonforandroid.recipe import CompiledComponentsPythonRecipe |
2 | | -from pythonforandroid.toolchain import shprint |
3 | | -from os.path import join, dirname |
4 | | -import sh |
| 2 | +from os.path import join |
5 | 3 |
|
6 | 4 |
|
7 | 5 | class PillowRecipe(CompiledComponentsPythonRecipe): |
8 | 6 |
|
9 | 7 | version = '5.2.0' |
10 | 8 | url = 'https://github.com/python-pillow/Pillow/archive/{version}.tar.gz' |
11 | 9 | site_packages_name = 'Pillow' |
12 | | - depends = [ |
13 | | - 'png', |
14 | | - 'jpeg', |
15 | | - 'freetype', |
16 | | - 'setuptools' |
17 | | - ] |
18 | | - patches = [ |
19 | | - join('patches', 'fix-docstring.patch'), |
20 | | - join('patches', 'fix-setup.patch') |
21 | | - ] |
| 10 | + depends = ['png', 'jpeg', 'freetype', 'setuptools'] |
| 11 | + patches = [join('patches', 'fix-docstring.patch'), |
| 12 | + join('patches', 'fix-setup.patch')] |
22 | 13 |
|
23 | 14 | call_hostpython_via_targetpython = False |
24 | 15 |
|
25 | | - def get_recipe_env(self, arch=None): |
26 | | - env = super(PillowRecipe, self).get_recipe_env(arch) |
27 | | - py_ver = self.ctx.python_recipe.version[0:3] |
| 16 | + def get_recipe_env(self, arch=None, with_flags_in_cc=True): |
| 17 | + env = super(PillowRecipe, self).get_recipe_env(arch, with_flags_in_cc) |
28 | 18 |
|
29 | | - ndk_dir = self.ctx.ndk_platform |
30 | | - ndk_lib_dir = join(ndk_dir, 'usr', 'lib') |
31 | | - ndk_include_dir = ( |
32 | | - join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include') |
33 | | - if py_ver == '2.7' else join(ndk_dir, 'usr', 'include')) |
| 19 | + env['ANDROID_ROOT'] = join(self.ctx.ndk_platform, 'usr') |
| 20 | + ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib') |
| 21 | + ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include') |
34 | 22 |
|
35 | 23 | png = self.get_recipe('png', self.ctx) |
36 | 24 | png_lib_dir = png.get_lib_dir(arch) |
37 | 25 | png_jni_dir = png.get_jni_dir(arch) |
38 | 26 |
|
39 | 27 | jpeg = self.get_recipe('jpeg', self.ctx) |
40 | | - jpeg_lib_dir = jpeg.get_lib_dir(arch) |
41 | | - jpeg_jni_dir = jpeg.get_jni_dir(arch) |
| 28 | + jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch) |
42 | 29 |
|
43 | | - env['JPEG_ROOT'] = '{}|{}'.format(jpeg_lib_dir, jpeg_jni_dir) |
| 30 | + freetype = self.get_recipe('freetype', self.ctx) |
| 31 | + free_lib_dir = join(freetype.get_build_dir(arch.arch), 'objs', '.libs') |
| 32 | + free_inc_dir = join(freetype.get_build_dir(arch.arch), 'include') |
| 33 | + |
| 34 | + # harfbuzz is a direct dependency of freetype and we need the proper |
| 35 | + # flags to successfully build the Pillow recipe, so we add them here. |
| 36 | + harfbuzz = self.get_recipe('harfbuzz', self.ctx) |
| 37 | + harf_lib_dir = join(harfbuzz.get_build_dir(arch.arch), 'src', '.libs') |
| 38 | + harf_inc_dir = harfbuzz.get_build_dir(arch.arch) |
| 39 | + |
| 40 | + env['JPEG_ROOT'] = '{}|{}'.format(jpeg_lib_dir, jpeg_inc_dir) |
| 41 | + env['FREETYPE_ROOT'] = '{}|{}'.format(free_lib_dir, free_inc_dir) |
44 | 42 | env['ZLIB_ROOT'] = '{}|{}'.format(ndk_lib_dir, ndk_include_dir) |
45 | 43 |
|
46 | | - cflags = ' -nostdinc' |
47 | | - cflags += ' -I{} -L{}'.format(png_jni_dir, png_lib_dir) |
48 | | - cflags += ' -I{} -L{}'.format(jpeg_jni_dir, jpeg_lib_dir) |
49 | | - cflags += ' -I{} -L{}'.format(ndk_include_dir, ndk_lib_dir) |
50 | | - |
51 | | - gcc_lib = shprint( |
52 | | - sh.gcc, '-print-libgcc-file-name').stdout.decode('utf-8').split('\n')[0] |
53 | | - gcc_include = join(dirname(gcc_lib), 'include') |
54 | | - cflags += ' -I{}'.format(gcc_include) |
55 | | - |
56 | | - if self.ctx.ndk == 'crystax': |
57 | | - py_inc_dir = join( |
58 | | - self.ctx.ndk_dir, 'sources', 'python', py_ver, 'include', 'python') |
59 | | - py_lib_dir = join( |
60 | | - self.ctx.ndk_dir, 'sources', 'python', py_ver, 'libs', arch.arch) |
61 | | - cflags += ' -I{}'.format(py_inc_dir) |
62 | | - env['LDFLAGS'] += ' -L{} -lpython{}m'.format(py_lib_dir, py_ver) |
63 | | - |
64 | | - env['LDFLAGS'] += ' {} -L{}'.format(env['CFLAGS'], self.ctx.libs_dir) |
| 44 | + cflags = ' -I{}'.format(png_jni_dir) |
| 45 | + cflags += ' -I{} -I{}'.format(harf_inc_dir, join(harf_inc_dir, 'src')) |
| 46 | + cflags += ' -I{}'.format(free_inc_dir) |
| 47 | + cflags += ' -I{}'.format(jpeg_inc_dir) |
| 48 | + cflags += ' -I{}'.format(ndk_include_dir) |
| 49 | + |
| 50 | + env['LIBS'] = ' -lpng -lfreetype -lharfbuzz -ljpeg -lturbojpeg' |
| 51 | + |
| 52 | + env['LDFLAGS'] += ' -L{} -L{} -L{} -L{}'.format( |
| 53 | + png_lib_dir, harf_lib_dir, jpeg_lib_dir, ndk_lib_dir) |
65 | 54 | if cflags not in env['CFLAGS']: |
66 | 55 | env['CFLAGS'] += cflags |
67 | | - env['LDSHARED'] = '{} {}'.format( |
68 | | - env['CC'], |
69 | | - '-pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions') |
70 | 56 | return env |
71 | 57 |
|
72 | 58 |
|
|
0 commit comments