|
| 1 | +""" |
| 2 | + android libglob |
| 3 | + available via '-lglob' LDFLAG |
| 4 | +""" |
| 5 | +from os.path import exists, join, dirname |
| 6 | +from pythonforandroid.toolchain import (CompiledComponentsPythonRecipe, |
| 7 | + current_directory) |
| 8 | +from pythonforandroid.logger import shprint, info, warning, info_main |
| 9 | +import sh |
| 10 | + |
| 11 | +class LibGlobRecipe(CompiledComponentsPythonRecipe): |
| 12 | + """Make a glob.h and glob.so for the python_install_dir()""" |
| 13 | + version = '0.0.1' |
| 14 | + url = None |
| 15 | + # |
| 16 | + # glob.h and glob.c extracted from |
| 17 | + # https://github.com/white-gecko/TokyoCabinet, e.g.: |
| 18 | + # https://raw.githubusercontent.com/white-gecko/TokyoCabinet/master/glob.h |
| 19 | + # https://raw.githubusercontent.com/white-gecko/TokyoCabinet/master/glob.c |
| 20 | + # and pushed in via patch |
| 21 | + name = 'libglob' |
| 22 | + |
| 23 | + depends = [('hostpython2', 'hostpython3'), ('python2', 'python3crystax')] |
| 24 | + patches = ['glob.patch'] |
| 25 | + |
| 26 | + def should_build(self, arch): |
| 27 | + """It's faster to build than check""" |
| 28 | + return True |
| 29 | + |
| 30 | + def prebuild_arch(self, arch): |
| 31 | + """Make the build and target directories""" |
| 32 | + path = self.get_build_dir(arch.arch) |
| 33 | + if not exists(path): |
| 34 | + info("creating {}".format(path)) |
| 35 | + shprint(sh.mkdir, '-p', path) |
| 36 | + |
| 37 | + def build_arch(self, arch): |
| 38 | + """simple shared compile""" |
| 39 | + env = self.get_recipe_env(arch, with_flags_in_cc=False) |
| 40 | + for path in (self.get_build_dir(arch.arch), |
| 41 | + join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'), |
| 42 | + join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include'), |
| 43 | + ): |
| 44 | + if not exists(path): |
| 45 | + info("creating {}".format(path)) |
| 46 | + shprint(sh.mkdir, '-p', path) |
| 47 | + cli = env['CC'].split() |
| 48 | + cc = sh.Command(cli[0]) |
| 49 | + |
| 50 | + with current_directory(self.get_build_dir(arch.arch)): |
| 51 | + cflags = env['CFLAGS'].split() |
| 52 | + cflags.extend(['-I.', '-c', '-l.', 'glob.c', '-I.']) # , '-o', 'glob.o']) |
| 53 | + shprint(cc, *cflags, _env=env) |
| 54 | + |
| 55 | + cflags = env['CFLAGS'].split() |
| 56 | + srindex = cflags.index('--sysroot') |
| 57 | + if srindex: |
| 58 | + cflags[srindex+1] = self.ctx.ndk_platform |
| 59 | + cflags.extend(['-shared', '-I.', 'glob.o', '-o', 'libglob.so']) |
| 60 | + shprint(cc, *cflags, _env=env) |
| 61 | + |
| 62 | + shprint(sh.cp, 'libglob.so', join(self.ctx.libs_dir, arch.arch)) |
| 63 | + shprint(sh.cp, "libglob.so", join(self.ctx.get_python_install_dir(), 'lib')) |
| 64 | + # drop header in to the Python include directory |
| 65 | + shprint(sh.cp, "glob.h", join(self.ctx.get_python_install_dir(), |
| 66 | + 'include/python{}'.format( |
| 67 | + self.ctx.python_recipe.version[0:3] |
| 68 | + ) |
| 69 | + ) |
| 70 | + ) |
| 71 | + include_path = join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include') |
| 72 | + shprint(sh.cp, "glob.h", include_path) |
| 73 | + |
| 74 | +recipe = LibGlobRecipe() |
0 commit comments