|
| 1 | +from pythonforandroid.recipe import Recipe |
| 2 | +from pythonforandroid.logger import shprint |
| 3 | +from pythonforandroid.util import current_directory |
| 4 | +from os.path import exists, join |
| 5 | +import sh |
| 6 | +import glob |
| 7 | + |
| 8 | + |
| 9 | +class LibffiRecipe(Recipe): |
| 10 | + name = 'libffi' |
| 11 | + version = 'v3.2.1' |
| 12 | + url = 'https://github.com/atgreen/libffi/archive/{version}.zip' |
| 13 | + |
| 14 | + patches = ['remove-version-info.patch'] |
| 15 | + |
| 16 | + host = 'arm-unknown-linux-androideabi' |
| 17 | + |
| 18 | + def should_build(self, arch): |
| 19 | + # return not bool(glob.glob(join(self.ctx.get_libs_dir(arch.arch), |
| 20 | + # 'libffi.so*'))) |
| 21 | + return not exists(join(self.ctx.get_libs_dir(arch.arch), 'libffi.so')) |
| 22 | + # return not exists(join(self.ctx.get_python_install_dir(), 'lib', |
| 23 | + # 'libffi.so')) |
| 24 | + |
| 25 | + def build_arch(self, arch): |
| 26 | + env = self.get_recipe_env(arch) |
| 27 | + with current_directory(self.get_build_dir(arch.arch)): |
| 28 | + if not exists('configure'): |
| 29 | + shprint(sh.Command('./autogen.sh'), _env=env) |
| 30 | + shprint(sh.Command('./configure'), '--host=arm-linux-androideabi', |
| 31 | + '--prefix=' + self.ctx.get_python_install_dir(), |
| 32 | + '--enable-shared', _env=env) |
| 33 | + shprint(sh.make, '-j5', 'libffi.la', _env=env) |
| 34 | + |
| 35 | + host = None |
| 36 | + with open('Makefile') as f: |
| 37 | + for line in f: |
| 38 | + if line.startswith('host = '): |
| 39 | + host = line.strip()[7:] |
| 40 | + break |
| 41 | + |
| 42 | + if not host or not exists(host): |
| 43 | + raise RuntimeError('failed to find build output! ({})' |
| 44 | + .format(host)) |
| 45 | + |
| 46 | + self.host = host |
| 47 | + |
| 48 | + # dlname = None |
| 49 | + # with open(join(host, 'libffi.la')) as f: |
| 50 | + # for line in f: |
| 51 | + # if line.startswith('dlname='): |
| 52 | + # dlname = line.strip()[8:-1] |
| 53 | + # break |
| 54 | + # |
| 55 | + # if not dlname or not exists(join(host, '.libs', dlname)): |
| 56 | + # raise RuntimeError('failed to locate shared object! ({})' |
| 57 | + # .format(dlname)) |
| 58 | + |
| 59 | + # shprint(sh.sed, '-i', 's/^dlname=.*$/dlname=\'libffi.so\'/', join(host, 'libffi.la')) |
| 60 | + |
| 61 | + shprint(sh.cp, '-t', self.ctx.get_libs_dir(arch.arch), |
| 62 | + join(host, '.libs', 'libffi.so')) #, |
| 63 | + # join(host, 'libffi.la')) |
| 64 | + |
| 65 | + def get_include_dirs(self, arch): |
| 66 | + return [join(self.get_build_dir(arch.arch), self.host, 'include')] |
| 67 | + |
| 68 | + |
| 69 | +recipe = LibffiRecipe() |
0 commit comments