Skip to content

Instantly share code, notes, and snippets.

@yeyeto2788
Created November 10, 2020 13:56
Show Gist options
  • Save yeyeto2788/dd3e5c42c61558da49d8e0c8b6c6fe14 to your computer and use it in GitHub Desktop.
Save yeyeto2788/dd3e5c42c61558da49d8e0c8b6c6fe14 to your computer and use it in GitHub Desktop.
Install gpiod python3 binding for Sunxi hardware devices.
#!/bin/sh
# Instructions!
# cd ~
# Copy content of file on a batch script (install_libgpiod.sh)
# chmod +x install_libgpiod.sh
# ./install_libgpiod.sh
# Credits: Adafruit's initial work https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/libgpiod.sh
is_legacy=0
# Loop through arguments and process them
for arg in "$@"
do
case $arg in
-l|--legacy)
is_legacy=1
shift
;;
*)
shift
;;
esac
done
echo "Installing build requirements - this may take a few minutes!"
echo
# install generic linux packages required
sudo apt-get update && sudo apt-get install -y \
autoconf \
autoconf-archive \
automake \
build-essential \
git \
libtool \
pkg-config \
python3 \
python3-dev \
python3-setuptools \
swig3.0 \
wget
# For sunxi hardware we need
sudo apt-get install -y linux-headers-current-sunxi
build_dir=`mktemp -d /tmp/libgpiod.XXXX`
echo "Cloning libgpiod repository to $build_dir"
echo
cd "$build_dir"
git clone git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git .
if test $is_legacy = 1; then
git checkout v1.4.1 -b v1.4.1
fi
echo "Building libgpiod"
echo
include_path=`python3 -c "from sysconfig import get_paths; print(get_paths()['include'])"`
export PYTHON_VERSION=3
./autogen.sh --enable-tools=yes --prefix=/usr/local/ --enable-bindings-python CFLAGS="-I/$include_path" \
&& make \
&& sudo make install \
&& sudo ldconfig
# This is not the right way to do this:
sudo cp bindings/python/.libs/gpiod.so /usr/local/lib/python3.?/dist-packages/
sudo cp bindings/python/.libs/gpiod.la /usr/local/lib/python3.?/dist-packages/
sudo cp bindings/python/.libs/gpiod.a /usr/local/lib/python3.?/dist-packages/
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment