|
| 1 | +""" ifaddrs for Android |
| 2 | +""" |
| 3 | +from os.path import join, exists |
| 4 | +import sh |
| 5 | +from pythonforandroid.logger import info, shprint |
| 6 | + |
| 7 | +from pythonforandroid.toolchain import (CompiledComponentsPythonRecipe, |
| 8 | + current_directory) |
| 9 | + |
| 10 | +class IFAddrRecipe(CompiledComponentsPythonRecipe): |
| 11 | + version = 'master' |
| 12 | + url = 'git+https://github.com/morristech/android-ifaddrs.git' |
| 13 | + depends = [('hostpython2', 'hostpython3'), ('python2', 'python3crystax')] |
| 14 | + |
| 15 | + call_hostpython_via_targetpython = False |
| 16 | + site_packages_name = 'ifaddrs' |
| 17 | + generated_libraries = ['libifaddrs.so'] |
| 18 | + |
| 19 | + def should_build(self, arch): |
| 20 | + """It's faster to build than check""" |
| 21 | + return not (exists(join(self.ctx.libs_dir, arch.arch, 'libifaddrs.so')) |
| 22 | + and exists(join(self.ctx.get_python_install_dir(), 'lib' |
| 23 | + "libifaddrs.so")) |
| 24 | + ) |
| 25 | + |
| 26 | + def prebuild_arch(self, arch): |
| 27 | + """Make the build and target directories""" |
| 28 | + path = self.get_build_dir(arch.arch) |
| 29 | + if not exists(path): |
| 30 | + info("creating {}".format(path)) |
| 31 | + shprint(sh.mkdir, '-p', path) |
| 32 | + |
| 33 | + def build_arch(self, arch): |
| 34 | + """simple shared compile""" |
| 35 | + env = self.get_recipe_env(arch, with_flags_in_cc=False) |
| 36 | + for path in (self.get_build_dir(arch.arch), |
| 37 | + join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'), |
| 38 | + join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include'), |
| 39 | + ): |
| 40 | + if not exists(path): |
| 41 | + info("creating {}".format(path)) |
| 42 | + shprint(sh.mkdir, '-p', path) |
| 43 | + cli = env['CC'].split() |
| 44 | + cc = sh.Command(cli[0]) |
| 45 | + |
| 46 | + with current_directory(self.get_build_dir(arch.arch)): |
| 47 | + cflags = env['CFLAGS'].split() |
| 48 | + cflags.extend(['-I.', '-c', '-l.', 'ifaddrs.c', '-I.']) |
| 49 | + shprint(cc, *cflags, _env=env) |
| 50 | + |
| 51 | + cflags = env['CFLAGS'].split() |
| 52 | + cflags.extend(['-shared', '-I.', 'ifaddrs.o', '-o', 'libifaddrs.so']) |
| 53 | + cflags.extend(env['LDFLAGS'].split()) |
| 54 | + shprint(cc, *cflags, _env=env) |
| 55 | + |
| 56 | + shprint(sh.cp, 'libifaddrs.so', self.ctx.get_libs_dir(arch.arch)) |
| 57 | + shprint(sh.cp, "libifaddrs.so", join(self.ctx.get_python_install_dir(), 'lib')) |
| 58 | + # drop header in to the Python include directory |
| 59 | + shprint(sh.cp, "ifaddrs.h", join(self.ctx.get_python_install_dir(), |
| 60 | + 'include/python{}'.format( |
| 61 | + self.ctx.python_recipe.version[0:3] |
| 62 | + ) |
| 63 | + ) |
| 64 | + ) |
| 65 | + include_path = join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include') |
| 66 | + shprint(sh.cp, "ifaddrs.h", include_path) |
| 67 | + |
| 68 | +recipe = IFAddrRecipe() |
0 commit comments