|
| 1 | +from pythonforandroid.util import current_directory # type: ignore |
| 2 | +from pythonforandroid.recipe import NDKRecipe # type: ignore |
| 3 | +from pythonforandroid.recipe import Recipe # type: ignore |
| 4 | +from pythonforandroid.logger import shprint # type: ignore |
| 5 | +import shutil |
| 6 | +import sh # type: ignore |
| 7 | +import os |
| 8 | + |
| 9 | + |
| 10 | +class LibhackrfRecipe(NDKRecipe): |
| 11 | + |
| 12 | + url = 'https://github.com/greatscottgadgets/hackrf/releases/download/v{version}/hackrf-{version}.tar.xz' |
| 13 | + patches = ['public_hackrf_open_setup.patch'] |
| 14 | + generated_libraries = ['libhackrf.so'] |
| 15 | + site_packages_name = 'libhackrf' |
| 16 | + version = '2024.02.1' |
| 17 | + depends = ['libusb'] |
| 18 | + name = 'libhackrf' |
| 19 | + |
| 20 | + def should_build(self, arch): |
| 21 | + return True |
| 22 | + |
| 23 | + def prebuild_arch(self, arch): |
| 24 | + super().prebuild_arch(arch) |
| 25 | + |
| 26 | + if not os.path.exists(os.path.join(self.get_build_dir(arch.arch), 'android')): |
| 27 | + |
| 28 | + os.mkdir(os.path.join(self.get_build_dir(arch.arch), 'android')) |
| 29 | + os.mkdir(os.path.join(self.get_build_dir(arch.arch), 'android', 'jni')) |
| 30 | + os.mkdir(os.path.join(self.get_build_dir(arch.arch), 'android', 'libusb')) |
| 31 | + |
| 32 | + shutil.copy(os.path.join(self.get_recipe_dir(), 'jni', 'Application.mk'), os.path.join(self.get_build_dir(arch.arch), 'android', 'jni')) |
| 33 | + shutil.copy(os.path.join(self.get_recipe_dir(), 'jni', 'libhackrf.mk'), os.path.join(self.get_build_dir(arch.arch), 'android', 'jni')) |
| 34 | + shutil.copy(os.path.join(self.get_recipe_dir(), 'jni', 'Android.mk'), os.path.join(self.get_build_dir(arch.arch), 'android', 'jni')) |
| 35 | + |
| 36 | + def get_lib_dir(self, arch): |
| 37 | + return os.path.join(self.get_build_dir(arch.arch), 'android', 'obj', 'local', arch.arch) |
| 38 | + |
| 39 | + def get_jni_dir(self, arch): |
| 40 | + return os.path.join(self.get_build_dir(arch.arch), 'android', 'jni') |
| 41 | + |
| 42 | + def build_arch(self, arch, *extra_args): |
| 43 | + if not os.path.exists(os.path.join(self.get_build_dir(arch.arch), 'android', 'libusb', 'libusb-1.0.so')): |
| 44 | + libusb_recipe = Recipe.get_recipe('libusb', arch) |
| 45 | + shutil.copy(os.path.join(libusb_recipe.get_lib_dir(arch), 'libusb1.0.so'), os.path.join(self.get_build_dir(arch.arch), 'android', 'libusb', 'libusb-1.0.so')) |
| 46 | + shutil.copy(os.path.join(libusb_recipe.get_build_dir(arch), 'libusb', 'libusb.h'), os.path.join(self.get_build_dir(arch.arch), 'android', 'libusb')) |
| 47 | + |
| 48 | + env = self.get_recipe_env(arch) |
| 49 | + with current_directory(self.get_build_dir(arch.arch)): |
| 50 | + shprint( |
| 51 | + sh.Command(os.path.join(self.ctx.ndk_dir, 'ndk-build')), |
| 52 | + 'NDK_PROJECT_PATH=' + self.get_build_dir(arch.arch) + '/android', |
| 53 | + 'APP_PLATFORM=android-' + str(self.ctx.ndk_api), |
| 54 | + 'NDK='+self.ctx.ndk_dir, |
| 55 | + 'APP_ABI=' + arch.arch, |
| 56 | + *extra_args, |
| 57 | + _env=env |
| 58 | + ) |
| 59 | + |
| 60 | + shutil.copyfile(os.path.join(self.get_build_dir(arch.arch), 'android', 'obj', 'local', arch.arch, 'libhackrf.so'), os.path.join(self.ctx.get_libs_dir(arch.arch), 'libhackrf.so')) |
| 61 | + |
| 62 | + |
| 63 | +recipe = LibhackrfRecipe() |
0 commit comments