Skip to content

Commit 78232f3

Browse files
committed
updated recipies for p4a
1 parent 62766ba commit 78232f3

7 files changed

Lines changed: 220 additions & 27 deletions

File tree

android/libhackrf/__init__.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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()

android/libhackrf/jni/Android.mk

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# MIT License
2+
3+
# Copyright (c) 2023 GvozdevLeonid
4+
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
24+
LOCAL_PATH := $(call my-dir)
25+
26+
include $(LOCAL_PATH)/libhackrf.mk
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# MIT License
2+
3+
# Copyright (c) 2023 GvozdevLeonid
4+
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
APP_ABI := all
24+
25+
APP_CFLAGS := \
26+
-Werror=implicit-function-declaration \
27+
-Werror=missing-prototypes \
28+
-Werror=strict-prototypes \
29+
-Werror=format-security \
30+
-Werror=uninitialized \
31+
-Werror=implicit-int \
32+
-Werror=init-self \
33+
-Wwrite-strings \
34+
-Werror=undef \
35+
-std=gnu11 \
36+
-Wshadow \
37+
-Wunused \
38+
-Wextra \
39+
-Wall \
40+
41+
APP_LDFLAGS := -llog

android/libhackrf/jni/libhackrf.mk

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# MIT License
2+
3+
# Copyright (c) 2023 GvozdevLeonid
4+
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
LOCAL_PATH := $(call my-dir)
24+
LIBHACKRF_ROOT_REL := ../..
25+
LIBHACKRF_ROOT_ABS := $(LOCAL_PATH)/../..
26+
27+
# LIBHACKRF
28+
29+
include $(CLEAR_VARS)
30+
31+
LOCAL_SRC_FILES := $(LIBHACKRF_ROOT_REL)/host/libhackrf/src/hackrf.c
32+
33+
LOCAL_C_INCLUDES += $(LIBHACKRF_ROOT_ABS)/android/libusb
34+
35+
LOCAL_CFLAGS := \
36+
-I$(LIBHACKRF_ROOT_ABS)/android/libusb \
37+
-fvisibility=hidden \
38+
-pthread \
39+
-w
40+
41+
LOCAL_LDFLAGS := -L$(LIBHACKRF_ROOT_ABS)/android/libusb
42+
43+
LOCAL_LDLIBS := -llog
44+
45+
LOCAL_MODULE := libhackrf
46+
47+
include $(BUILD_SHARED_LIBRARY)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff -ruN hackrf/host/libhackrf/src/hackrf.c patched/host/libhackrf/src/hackrf.c
2+
--- hackrf/host/libhackrf/src/hackrf.c 2024-02-23 01:20:25
3+
+++ patched/host/libhackrf/src/hackrf.c 2024-08-10 22:22:58
4+
@@ -699,7 +699,7 @@
5+
return usb_device;
6+
}
7+
8+
-static int hackrf_open_setup(libusb_device_handle* usb_device, hackrf_device** device)
9+
+int hackrf_open_setup(libusb_device_handle* usb_device, hackrf_device** device)
10+
{
11+
int result;
12+
hackrf_device* lib_device;

android/libusb/__init__.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,42 @@
1-
from pythonforandroid.util import current_directory
2-
from pythonforandroid.recipe import NDKRecipe
3-
from pythonforandroid.logger import shprint
4-
from os.path import join
1+
from pythonforandroid.util import current_directory # type: ignore
2+
from pythonforandroid.recipe import NDKRecipe # type: ignore
3+
from pythonforandroid.logger import shprint # type: ignore
54
import shutil
6-
import sh
5+
import sh # type: ignore
6+
import os
77

88

99
class LibusbRecipe(NDKRecipe):
10-
version = '1.0.26'
10+
1111
url = 'https://github.com/libusb/libusb/archive/refs/tags/v{version}.tar.gz'
12+
generated_libraries = ['libusb-1.0.so']
1213
site_packages_name = 'libusb'
14+
version = '1.0.26'
1315
name = 'libusb'
14-
generated_libraries = ['libusb1.0.so']
1516

1617
def should_build(self, arch):
1718
return True
1819

19-
def get_recipe_env(self, arch):
20-
env = super().get_recipe_env(arch)
21-
22-
env['LOCAL_C_INCLUDES'] = ' $(LIBUSB_ROOT_ABS)'
23-
env['LOCAL_SHARED_LIBRARIES'] = ' libusb1.0'
24-
return env
25-
2620
def get_lib_dir(self, arch):
27-
return join(self.get_build_dir(arch.arch), 'android', 'obj', 'local', arch.arch)
21+
return os.path.join(self.get_build_dir(arch.arch), 'android', 'obj', 'local', arch.arch)
2822

2923
def get_jni_dir(self, arch):
30-
return join(self.get_build_dir(arch.arch), 'android', 'jni')
24+
return os.path.join(self.get_build_dir(arch.arch), 'android', 'jni')
3125

3226
def build_arch(self, arch, *extra_args):
3327
env = self.get_recipe_env(arch)
3428
with current_directory(self.get_build_dir(arch.arch)):
3529
shprint(
36-
sh.Command(join(self.ctx.ndk_dir, "ndk-build")),
30+
sh.Command(os.path.join(self.ctx.ndk_dir, 'ndk-build')),
3731
'NDK_PROJECT_PATH=' + self.get_build_dir(arch.arch) + '/android',
38-
'NDK='+self.ctx.ndk_dir,
3932
'APP_PLATFORM=android-' + str(self.ctx.ndk_api),
33+
'NDK='+self.ctx.ndk_dir,
4034
'APP_ABI=' + arch.arch,
41-
*extra_args, _env=env
35+
*extra_args,
36+
_env=env
4237
)
4338

44-
shutil.copyfile(join(self.get_build_dir(arch.arch), 'android', 'libs', arch.arch, 'libusb1.0.so'), join(self.ctx.get_libs_dir(arch.arch), 'libusb1.0.so'))
39+
shutil.copyfile(os.path.join(self.get_build_dir(arch.arch), 'android', 'obj', 'local', arch.arch, 'libusb1.0.so'), os.path.join(self.ctx.get_libs_dir(arch.arch), 'libusb-1.0.so'))
4540

4641

4742
recipe = LibusbRecipe()

android/python_hackrf/__init__.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,43 @@
55

66

77
class PythonHackrfRecipe(CythonRecipe):
8-
version = '1.1.1'
98
url = 'https://github.com/GvozdevLeonid/python_hackrf/releases/download/v.{version}/python_hackrf-{version}.tar.gz'
10-
depends = ['python3', 'setuptools', 'libusb', 'numpy']
9+
depends = ['python3', 'setuptools', 'libusb', 'libhackrf', 'numpy']
1110
site_packages_name = 'python_hackrf'
1211
name = 'python_hackrf'
12+
version = '1.1.1'
1313

1414
def get_recipe_env(self, arch):
1515
env = super().get_recipe_env(arch)
1616

17+
libhackrf_recipe = Recipe.get_recipe('libhackrf', arch)
1718
libusb_recipe = Recipe.get_recipe('libusb', arch)
18-
h_dir = os.path.join(libusb_recipe.get_build_dir(arch), 'libusb')
19-
so_dir = libusb_recipe.get_lib_dir(arch)
2019

21-
env['CFLAGS'] += ' -I' + h_dir
22-
env['LDFLAGS'] += ' -L' + so_dir
20+
libusb_h_dir = os.path.join(libusb_recipe.get_build_dir(arch), 'libusb')
21+
libusb_so_dir = libusb_recipe.get_lib_dir(arch)
22+
23+
libhackrf_h_dir = os.path.join(libhackrf_recipe.get_build_dir(arch), 'libhackrf')
24+
libhackrf_so_dir = libhackrf_recipe.get_lib_dir(arch)
25+
26+
env['LDFLAGS'] += f' -L{libusb_so_dir} -L{libhackrf_so_dir}'
27+
env['CFLAGS'] += f' -I{libusb_h_dir} -I{libhackrf_h_dir}'
28+
2329
return env
2430

2531
def postbuild_arch(self, arch):
2632
super().postbuild_arch(arch)
2733

2834
python_hackrf_dir = os.path.join(self.ctx.get_python_install_dir(arch.arch), 'python_hackrf')
2935
os.makedirs(python_hackrf_dir, exist_ok=True)
36+
3037
try:
31-
shutil.move(os.path.join(self.ctx.get_python_install_dir(arch.arch), 'pylibhackrf'), os.path.join(python_hackrf_dir, 'pylibhackrf'))
38+
3239
shutil.move(os.path.join(self.ctx.get_python_install_dir(arch.arch), 'pyhackrf_tools'), os.path.join(python_hackrf_dir, 'pyhackrf_tools'))
40+
shutil.move(os.path.join(self.ctx.get_python_install_dir(arch.arch), 'pylibhackrf'), os.path.join(python_hackrf_dir, 'pylibhackrf'))
3341

3442
shutil.copy(os.path.join(self.get_build_dir(arch.arch), '__init__.py'), python_hackrf_dir)
3543
shutil.copy(os.path.join(self.get_build_dir(arch.arch), '__main__.py'), python_hackrf_dir)
44+
3645
except FileNotFoundError:
3746
pass
3847

0 commit comments

Comments
 (0)