|
1 |
| -from pythonforandroid.recipe import TargetPythonRecipe |
| 1 | +from pythonforandroid.recipe import TargetPythonRecipe, Recipe |
2 | 2 | from pythonforandroid.toolchain import shprint, current_directory
|
3 | 3 | from pythonforandroid.logger import logger, info
|
4 | 4 | from pythonforandroid.util import ensure_dir, walk_valid_filens
|
|
33 | 33 |
|
34 | 34 |
|
35 | 35 | class Python3Recipe(TargetPythonRecipe):
|
| 36 | + ''' |
| 37 | + .. note:: |
| 38 | + In order to build certain python modules, we need to add some extra |
| 39 | + recipes to our build requirements: |
| 40 | +
|
| 41 | + - ctypes: you must add the recipe for ``libffi``. |
| 42 | + ''' |
36 | 43 | version = '3.7.1'
|
37 | 44 | url = 'https://www.python.org/ftp/python/{version}/Python-{version}.tgz'
|
38 | 45 | name = 'python3'
|
39 | 46 |
|
40 | 47 | depends = ['hostpython3']
|
41 | 48 | conflicts = ['python3crystax', 'python2']
|
42 |
| - # opt_depends = ['openssl', 'sqlite3'] |
| 49 | + opt_depends = ['libffi'] # 'openssl', 'sqlite3' |
| 50 | + |
| 51 | + configure_args = ( |
| 52 | + '--host={android_host}', |
| 53 | + '--build={android_build}', |
| 54 | + '--enable-shared', |
| 55 | + '--disable-ipv6', |
| 56 | + 'ac_cv_file__dev_ptmx=yes', |
| 57 | + 'ac_cv_file__dev_ptc=no', |
| 58 | + '--without-ensurepip', |
| 59 | + 'ac_cv_little_endian_double=yes', |
| 60 | + '--prefix={prefix}', |
| 61 | + '--exec-prefix={exec_prefix}') |
| 62 | + |
| 63 | + def set_libs_flags(self, env, arch): |
| 64 | + '''Takes care to properly link libraries with python depending on our |
| 65 | + requirements and the attribute :attr:`opt_depends`. |
| 66 | + ''' |
| 67 | + def add_flags(include_flags, link_flags): |
| 68 | + env['CPPFLAGS'] = env.get('CPPFLAGS', '') + include_flags |
| 69 | + env['LDFLAGS'] = env.get('LDFLAGS', '') + link_flags |
| 70 | + |
| 71 | + if 'libffi' in self.ctx.recipe_build_order: |
| 72 | + info('Activating flags for libffi') |
| 73 | + recipe = Recipe.get_recipe('libffi', self.ctx) |
| 74 | + include = ' -I' + ' -I'.join(recipe.get_include_dirs(arch)) |
| 75 | + ldflag = ' -L' + join(recipe.get_build_dir(arch.arch), |
| 76 | + recipe.get_host(arch), '.libs') + ' -lffi' |
| 77 | + add_flags(include, ldflag) |
| 78 | + # libffi needs some extra configurations |
| 79 | + env['LIBFFI_CFLAGS'] = env.get('CFLAGS', '') + include |
| 80 | + env['LIBFFI_LIBS'] = ldflag |
| 81 | + self.configure_args += ('--with-system-ffi',) |
| 82 | + return env |
43 | 83 |
|
44 | 84 | def build_arch(self, arch):
|
45 | 85 | recipe_build_dir = self.get_build_dir(arch.arch)
|
@@ -112,22 +152,15 @@ def build_arch(self, arch):
|
112 | 152 |
|
113 | 153 | env['SYSROOT'] = sysroot
|
114 | 154 |
|
| 155 | + env = self.set_libs_flags(env, arch) |
| 156 | + |
115 | 157 | if not exists('config.status'):
|
116 | 158 | shprint(sh.Command(join(recipe_build_dir, 'configure')),
|
117 |
| - *(' '.join(('--host={android_host}', |
118 |
| - '--build={android_build}', |
119 |
| - '--enable-shared', |
120 |
| - '--disable-ipv6', |
121 |
| - 'ac_cv_file__dev_ptmx=yes', |
122 |
| - 'ac_cv_file__dev_ptc=no', |
123 |
| - '--without-ensurepip', |
124 |
| - 'ac_cv_little_endian_double=yes', |
125 |
| - '--prefix={prefix}', |
126 |
| - '--exec-prefix={exec_prefix}')).format( |
127 |
| - android_host=android_host, |
128 |
| - android_build=android_build, |
129 |
| - prefix=sys_prefix, |
130 |
| - exec_prefix=sys_exec_prefix)).split(' '), _env=env) |
| 159 | + *(' '.join(self.configure_args).format( |
| 160 | + android_host=android_host, |
| 161 | + android_build=android_build, |
| 162 | + prefix=sys_prefix, |
| 163 | + exec_prefix=sys_exec_prefix)).split(' '), _env=env) |
131 | 164 |
|
132 | 165 | if not exists('python'):
|
133 | 166 | shprint(sh.make, 'all', _env=env)
|
|
0 commit comments