|
1 | 1 | from pythonforandroid.toolchain import Recipe
|
| 2 | +from pythonforandroid.logger import shprint, info |
2 | 3 | from pythonforandroid.util import current_directory
|
3 |
| -from pythonforandroid.logger import shprint |
4 |
| -from os.path import exists, join, realpath |
| 4 | +from os.path import exists, join |
| 5 | +from multiprocessing import cpu_count |
5 | 6 | import sh
|
6 | 7 |
|
7 | 8 |
|
8 | 9 | class FreetypeRecipe(Recipe):
|
| 10 | + """The freetype library it's special, because has cyclic dependencies with |
| 11 | + harfbuzz library, so freetype can be build with harfbuzz support, and |
| 12 | + harfbuzz can be build with freetype support. This complicates the build of |
| 13 | + both recipes because in order to get the full set we need to compile those |
| 14 | + recipes several times: |
| 15 | + - build freetype without harfbuzz |
| 16 | + - build harfbuzz with freetype |
| 17 | + - build freetype with harfbuzz support |
| 18 | +
|
| 19 | + .. note:: |
| 20 | + To build freetype with harfbuzz support you must add `harfbuzz` to your |
| 21 | + requirements, otherwise freetype will be build without harfbuzz |
| 22 | +
|
| 23 | + .. seealso:: |
| 24 | + https://sourceforge.net/projects/freetype/files/freetype2/2.5.3/ |
| 25 | + """ |
9 | 26 |
|
10 | 27 | version = '2.5.5'
|
11 | 28 | url = 'http://download.savannah.gnu.org/releases/freetype/freetype-{version}.tar.gz' # noqa
|
12 | 29 |
|
13 |
| - depends = ['harfbuzz'] |
14 |
| - |
15 | 30 | def should_build(self, arch):
|
16 |
| - if exists(join(self.get_build_dir(arch.arch), |
17 |
| - 'objs', '.libs', 'libfreetype.a')): |
| 31 | + if exists( |
| 32 | + join( |
| 33 | + self.get_build_dir(arch.arch), |
| 34 | + 'objs', |
| 35 | + '.libs', |
| 36 | + 'libfreetype.so', |
| 37 | + ) |
| 38 | + ): |
18 | 39 | return False
|
19 | 40 | return True
|
20 | 41 |
|
21 |
| - def build_arch(self, arch): |
| 42 | + def build_arch(self, arch, with_harfbuzz=False): |
22 | 43 | env = self.get_recipe_env(arch)
|
| 44 | + harfbuzz_in_recipes = 'harfbuzz' in self.ctx.recipe_build_order |
| 45 | + prefix_path = self.get_build_dir(arch.arch) |
| 46 | + if not harfbuzz_in_recipes: |
| 47 | + info('Building freetype (harfbuzz support disabled)') |
| 48 | + elif harfbuzz_in_recipes and not with_harfbuzz: |
| 49 | + info('First Build of freetype (without harfbuzz, for now...)') |
| 50 | + prefix_path = join(prefix_path, 'install') |
| 51 | + elif harfbuzz_in_recipes and with_harfbuzz: |
| 52 | + # Is the second build, now we link with harfbuzz |
| 53 | + info('Second Build of freetype: enabling harfbuzz support ...') |
| 54 | + harfbuzz_build = self.get_recipe( |
| 55 | + 'harfbuzz', self.ctx |
| 56 | + ).get_build_dir(arch.arch) |
| 57 | + freetype_install = join(self.get_build_dir(arch.arch), 'install') |
| 58 | + env['CFLAGS'] = ' '.join( |
| 59 | + [ |
| 60 | + env['CFLAGS'], |
| 61 | + '-DFT_CONFIG_OPTION_USE_HARFBUZZ', |
| 62 | + '-I{harfbuzz}'.format(harfbuzz=harfbuzz_build), |
| 63 | + '-I{harfbuzz}/src'.format(harfbuzz=harfbuzz_build), |
| 64 | + '-I{freetype}/include/freetype2'.format( |
| 65 | + freetype=freetype_install |
| 66 | + ), |
| 67 | + ] |
| 68 | + ) |
23 | 69 |
|
24 |
| - harfbuzz_recipe = Recipe.get_recipe('harfbuzz', self.ctx) |
25 |
| - env['LDFLAGS'] = ' '.join( |
26 |
| - [env['LDFLAGS'], |
27 |
| - '-L{}'.format(join(harfbuzz_recipe.get_build_dir(arch.arch), |
28 |
| - 'src', '.libs'))]) |
| 70 | + env['HARFBUZZ_CFLAGS'] = '-I{harfbuzz} -I{harfbuzz}/src'.format( |
| 71 | + harfbuzz=harfbuzz_build |
| 72 | + ) |
| 73 | + env['HARFBUZZ_LIBS'] = ( |
| 74 | + '-L{freetype}/lib -lfreetype ' |
| 75 | + '-L{harfbuzz}/src/.libs -lharfbuzz'.format( |
| 76 | + freetype=freetype_install, harfbuzz=harfbuzz_build |
| 77 | + ) |
| 78 | + ) |
29 | 79 |
|
| 80 | + # Build freetype library |
| 81 | + config_args = { |
| 82 | + '--host={}'.format(arch.command_prefix), |
| 83 | + '--prefix={}'.format(prefix_path), |
| 84 | + '--without-zlib', |
| 85 | + '--with-png=no', |
| 86 | + } |
| 87 | + if not with_harfbuzz and harfbuzz_in_recipes: |
| 88 | + info('Build freetype for First time (without harfbuzz)') |
| 89 | + config_args = config_args.union({'--disable-shared'}) |
| 90 | + elif with_harfbuzz or not harfbuzz_in_recipes: |
| 91 | + info( |
| 92 | + 'Build freetype {}'.format( |
| 93 | + 'for Second time (with harfbuzz)' |
| 94 | + if harfbuzz_in_recipes |
| 95 | + else '(without harfbuzz)' |
| 96 | + ) |
| 97 | + ) |
| 98 | + config_args = config_args.union( |
| 99 | + {'--disable-static', '--enable-shared'} |
| 100 | + ) |
| 101 | + info('Configure args are: {}'.format('\n\t-'.join(config_args))) |
30 | 102 | with current_directory(self.get_build_dir(arch.arch)):
|
31 | 103 | configure = sh.Command('./configure')
|
32 |
| - shprint(configure, |
33 |
| - '--host=arm-linux-androideabi', |
34 |
| - '--prefix={}'.format(realpath('.')), |
35 |
| - '--without-zlib', |
36 |
| - '--with-png=no', |
37 |
| - '--disable-shared', |
38 |
| - _env=env) |
39 |
| - shprint(sh.make, '-j5', _env=env) |
40 |
| - |
41 |
| - shprint(sh.cp, 'objs/.libs/libfreetype.a', self.ctx.libs_dir) |
| 104 | + shprint(configure, *config_args, _env=env) |
| 105 | + shprint(sh.make, '-j', str(cpu_count()), _env=env) |
| 106 | + |
| 107 | + if not with_harfbuzz and harfbuzz_in_recipes: |
| 108 | + # First build, install the compiled lib, and clean build env |
| 109 | + shprint(sh.make, 'install', _env=env) |
| 110 | + shprint(sh.make, 'distclean', _env=env) |
| 111 | + else: |
| 112 | + # Second build (or the first if harfbuzz not enabled), now we |
| 113 | + # copy definitive libs to libs collection. Be sure to link your |
| 114 | + # recipes to the definitive library, located at: objs/.libs |
| 115 | + self.install_libs(arch, 'objs/.libs/libfreetype.so') |
42 | 116 |
|
43 | 117 |
|
44 | 118 | recipe = FreetypeRecipe()
|
0 commit comments