forked from adafruit/Raspberry-Pi-Installer-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libgpiod.py
executable file
·61 lines (48 loc) · 2.48 KB
/
libgpiod.py
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
# Instructions!
# cd ~
# sudo apt-get install python3-pip
# sudo pip3 install --upgrade adafruit-python3-shell click
# wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/libgpiod.py
# sudo python3 libgpiod.py
try:
import click
except ImportError:
raise RuntimeError("The library 'Click' was not found. To install, try typing: sudo pip3 install Click==7.0")
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
shell.group = 'LIBGPIOD'
@click.command()
@click.option('-l', '--legacy', is_flag=True, help="Install a legacy version of libgpiod for systems with older libraries")
def main(legacy):
print("""Installing build requirements - this may take a few minutes!
""")
# install generic linux packages required
shell.run_command("sudo apt-get update")
shell.run_command("sudo apt-get install -y autoconf autoconf-archive automake build-essential git libtool pkg-config python3-dev python3-setuptools swig3.0 wget")
# for raspberry pi we need...
shell.run_command("sudo apt-get install -y raspberrypi-kernel-headers")
build_dir = shell.run_command("mktemp -d /tmp/libgpiod.XXXX", return_output=True)
print("""Cloning libgpiod repository to {}
""".format(build_dir))
shell.chdir(build_dir)
shell.run_command("git clone git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git .")
if legacy:
shell.run_command("git checkout v1.4.2 -b v1.4.2")
print("""Building libgpiod
""")
include_path = shell.run_command("python3 -c \"from sysconfig import get_paths; print(get_paths()['include'])\"", return_output=True)
shell.run_command("export PYTHON_VERSION=3")
shell.run_command("./autogen.sh --enable-tools=yes --prefix=/usr/local/ --enable-bindings-python CFLAGS=\"-I/{}\" && make && sudo make install && sudo ldconfig".format(include_path))
if shell.exists("bindings/python/.libs"):
# This is not the right way to do this, but it works
shell.run_command("sudo cp bindings/python/.libs/gpiod.so /usr/local/lib/python3.?/dist-packages/")
shell.run_command("sudo cp bindings/python/.libs/gpiod.la /usr/local/lib/python3.?/dist-packages/")
shell.run_command("sudo cp bindings/python/.libs/gpiod.a /usr/local/lib/python3.?/dist-packages/")
shell.exit()
# Main function
if __name__ == "__main__":
shell.require_root()
main()