forked from 4thel00z/pyhackrf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
66 lines (56 loc) · 2.43 KB
/
build.py
File metadata and controls
66 lines (56 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import shutil
import subprocess
import sys
import tempfile
import urllib.request
from typing import Union
def download(url: str) -> bytes:
response = urllib.request.urlopen(url)
return response.read() # a `bytes` object
def write(path: str, payload: Union[str, bytes], mode: str = "wb"):
with open(path, mode=mode) as f:
f.write(payload)
def install_cmake():
"""
wget https://cmake.org/files/v3.20/cmake-3.20.3.tar.gz
tar -xzvf cmake-3.20.3.tar.gz
cd cmake-3.20.3/
./bootstrap
make -j4
sudo make install
cmake --version
:return:
"""
cmake_src_url = "https://cmake.org/files/v3.20/cmake-3.20.3.tar.gz"
_, tar_name = cmake_src_url.rsplit("/", 1)
unpacked_name, _, _ = tar_name.rsplit(".", 2)
with tempfile.TemporaryDirectory(prefix="pyhackrf-cmake") as tmp_dir_name:
write(tar_name, download(cmake_src_url))
src_dir = f"{tmp_dir_name}/{unpacked_name}"
subprocess.run(["tar", "-vxzf", tar_name, "-C", tmp_dir_name], stderr=sys.stderr, stdout=sys.stdout)
subprocess.run(["./bootstrap"], stderr=sys.stderr, stdout=sys.stdout, cwd=src_dir)
subprocess.run(["make", "-j4"], stderr=sys.stderr, stdout=sys.stdout, cwd=src_dir)
subprocess.run(["sudo", "make", "install"], stderr=sys.stderr, stdout=sys.stdout, cwd=src_dir)
subprocess.run(["cmake", "--version"], stderr=sys.stderr, stdout=sys.stdout)
def build(kwargs):
if not shutil.which("cmake"):
install_cmake()
install_hackrf()
def install_hackrf():
with tempfile.TemporaryDirectory(prefix="pyhackrf") as tmp_dir_name:
subprocess.run(["git",
"clone",
"--recurse-submodules",
"https://github.com/mossmann/hackrf.git"],
stderr=sys.stderr,
stdout=sys.stdout,
cwd=tmp_dir_name)
src_dir = f"{tmp_dir_name}/hackrf"
host_dir = f"{src_dir}/host"
build_dir = f"{host_dir}/build"
os.makedirs(build_dir, exist_ok=True)
subprocess.run(["cmake", ".."], stderr=sys.stderr, stdout=sys.stdout, cwd=build_dir)
subprocess.run(["make"], stderr=sys.stderr, stdout=sys.stdout, cwd=build_dir)
subprocess.run(["sudo", "make", "install"], stderr=sys.stderr, stdout=sys.stdout, cwd=build_dir)
subprocess.run(["sudo", "ldconfig"], stderr=sys.stderr, stdout=sys.stdout, cwd=build_dir)