|
| 1 | +from pythonforandroid.recipe import Recipe |
| 2 | +from pythonforandroid.toolchain import current_directory, shprint |
| 3 | +from os.path import join, realpath |
| 4 | +from multiprocessing import cpu_count |
| 5 | +import sh |
| 6 | + |
| 7 | + |
| 8 | +TARGETS = { |
| 9 | + 'armeabi-v7a': 'armv7-android-gcc', |
| 10 | + 'arm64-v8a': 'arm64-android-gcc', |
| 11 | +} |
| 12 | + |
| 13 | + |
| 14 | +class VPXRecipe(Recipe): |
| 15 | + version = '1.9.0' |
| 16 | + url = 'https://github.com/webmproject/libvpx/archive/v{version}.tar.gz' |
| 17 | + |
| 18 | + patches = [ |
| 19 | + # See https://git.io/Jq50q |
| 20 | + join('patches', '0001-android-force-neon-runtime.patch'), |
| 21 | + ] |
| 22 | + |
| 23 | + def get_recipe_env(self, arch=None): |
| 24 | + env = super().get_recipe_env(arch) |
| 25 | + cxx_include_dir = join( |
| 26 | + self.ctx.ndk_dir, |
| 27 | + 'toolchains', |
| 28 | + 'llvm', |
| 29 | + 'prebuilt', |
| 30 | + 'linux-x86_64', |
| 31 | + 'sysroot', |
| 32 | + 'usr', |
| 33 | + 'include', |
| 34 | + 'c++', |
| 35 | + 'v1', |
| 36 | + ) |
| 37 | + env['CXXFLAGS'] += f' -I{cxx_include_dir}' |
| 38 | + if 'arm64' not in arch.arch: |
| 39 | + env['AS'] = arch.command_prefix + '-as' |
| 40 | + return env |
| 41 | + |
| 42 | + def build_arch(self, arch): |
| 43 | + with current_directory(self.get_build_dir(arch.arch)): |
| 44 | + env = self.get_recipe_env(arch) |
| 45 | + flags = [ |
| 46 | + '--target=' + TARGETS[arch.arch], |
| 47 | + '--enable-pic', |
| 48 | + '--enable-vp8', |
| 49 | + '--enable-vp9', |
| 50 | + '--enable-static', |
| 51 | + '--enable-small', |
| 52 | + '--disable-shared', |
| 53 | + '--disable-examples', |
| 54 | + '--disable-unit-tests', |
| 55 | + '--disable-tools', |
| 56 | + '--disable-docs', |
| 57 | + '--disable-install-docs', |
| 58 | + '--disable-realtime-only', |
| 59 | + f'--prefix={realpath(".")}', |
| 60 | + ] |
| 61 | + configure = sh.Command('./configure') |
| 62 | + shprint(configure, *flags, _env=env) |
| 63 | + shprint(sh.make, '-j', str(cpu_count()), _env=env) |
| 64 | + shprint(sh.make, 'install', _env=env) |
| 65 | + |
| 66 | + |
| 67 | +recipe = VPXRecipe() |
0 commit comments