|
| 1 | +import os |
1 | 2 | from pythonforandroid.recipe import CompiledComponentsPythonRecipe |
2 | 3 |
|
3 | 4 |
|
4 | 5 | class CffiRecipe(CompiledComponentsPythonRecipe): |
5 | | - name = 'cffi' |
6 | | - version = '1.4.2' |
7 | | - url = 'https://pypi.python.org/packages/source/c/cffi/cffi-{version}.tar.gz' |
8 | | - |
9 | | - depends = [('python2', 'python3crystax'), 'setuptools', 'pycparser', 'libffi'] |
10 | | - |
11 | | - patches = ['disable-pkg-config.patch'] |
12 | | - |
13 | | - # call_hostpython_via_targetpython = False |
14 | | - install_in_hostpython = True |
15 | | - |
16 | | - def get_recipe_env(self, arch=None): |
17 | | - env = super(CffiRecipe, self).get_recipe_env(arch) |
18 | | - libffi = self.get_recipe('libffi', self.ctx) |
19 | | - includes = libffi.get_include_dirs(arch) |
20 | | - env['CFLAGS'] = ' -I'.join([env.get('CFLAGS', '')] + includes) |
21 | | - env['LDFLAGS'] = (env.get('CFLAGS', '') + ' -L' + |
22 | | - self.ctx.get_libs_dir(arch.arch)) |
23 | | - env['PYTHONPATH'] = ':'.join([ |
24 | | - self.ctx.get_site_packages_dir(), |
25 | | - env['BUILDLIB_PATH'], |
26 | | - ]) |
27 | | - return env |
| 6 | + name = 'cffi' |
| 7 | + version = '1.4.2' |
| 8 | + url = 'https://pypi.python.org/packages/source/c/cffi/cffi-{version}.tar.gz' |
| 9 | + |
| 10 | + depends = [('python2', 'python3crystax'), 'setuptools', 'pycparser', 'libffi'] |
| 11 | + |
| 12 | + patches = ['disable-pkg-config.patch'] |
| 13 | + |
| 14 | + # call_hostpython_via_targetpython = False |
| 15 | + install_in_hostpython = True |
| 16 | + |
| 17 | + def get_recipe_env(self, arch=None): |
| 18 | + env = super(CffiRecipe, self).get_recipe_env(arch) |
| 19 | + # sets linker to use the correct gcc (cross compiler) |
| 20 | + env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' |
| 21 | + libffi = self.get_recipe('libffi', self.ctx) |
| 22 | + includes = libffi.get_include_dirs(arch) |
| 23 | + env['CFLAGS'] = ' -I'.join([env.get('CFLAGS', '')] + includes) |
| 24 | + env['LDFLAGS'] = (env.get('CFLAGS', '') + ' -L' + |
| 25 | + self.ctx.get_libs_dir(arch.arch)) |
| 26 | + env['LDFLAGS'] += ' -L{}'.format(os.path.join(self.ctx.bootstrap.build_dir, 'libs', arch.arch)) |
| 27 | + # required for libc and libdl |
| 28 | + ndk_dir = self.ctx.ndk_platform |
| 29 | + ndk_lib_dir = os.path.join(ndk_dir, 'usr', 'lib') |
| 30 | + env['LDFLAGS'] += ' -L{}'.format(ndk_lib_dir) |
| 31 | + env['LDFLAGS'] += " --sysroot={}".format(self.ctx.ndk_platform) |
| 32 | + env['PYTHONPATH'] = ':'.join([ |
| 33 | + self.ctx.get_site_packages_dir(), |
| 34 | + env['BUILDLIB_PATH'], |
| 35 | + ]) |
| 36 | + if self.ctx.ndk == 'crystax': |
| 37 | + # only keeps major.minor (discards patch) |
| 38 | + python_version = self.ctx.python_recipe.version[0:3] |
| 39 | + ndk_dir_python = os.path.join(self.ctx.ndk_dir, 'sources/python/', python_version) |
| 40 | + env['LDFLAGS'] += ' -L{}'.format(os.path.join(ndk_dir_python, 'libs', arch.arch)) |
| 41 | + env['LDFLAGS'] += ' -lpython{}m'.format(python_version) |
| 42 | + # until `pythonforandroid/archs.py` gets merged upstream: |
| 43 | + # https://github.com/kivy/python-for-android/pull/1250/files#diff-569e13021e33ced8b54385f55b49cbe6 |
| 44 | + env['CFLAGS'] += ' -I{}/include/python/'.format(ndk_dir_python) |
| 45 | + return env |
28 | 46 |
|
29 | 47 |
|
30 | 48 | recipe = CffiRecipe() |
0 commit comments