You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.6 KiB

#!/bin/bash
TOOLCHAIN_URL="https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu.tar.xz?revision=972019b5-912f-4ae6-864a-f61f570e2e7e&la=en&hash=B8618949E6095C87E4C9FFA1648CAA67D4997D88"
LIBREALSENSE_GIT="https://github.com/IntelRealSense/librealsense.git"
SYSROOT_TOOL_URL="https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py"
CURDIR=$(pwd)
PI_USER_HOST="naresh@192.168.0.110"
# Download the toolchain
mkdir -p ./tools
cd ./tools
if [ ! -f ./toolchain.tar.xz ]
then
wget -O toolchain.tar.xz $TOOLCHAIN_URL
tar xf ./toolchain.tar.xz
fi
TOOLCHAIN_DIR=$(find . -maxdepth 1 -type d -name "gcc*")
if [ $(echo $TOOLCHAIN_DIR | wc -l) != 1 ] && [ -d $TOOLCHAIN_DIR ]
then
echo "An error has occured."
exit
fi
TOOLCHAIN_DIR=$(readlink -f $TOOLCHAIN_DIR)
# Retrieve libraries from live PI
cd $CURDIR
rsync -avz --rsync-path="sudo rsync" $PI_USER_HOST:/lib sysroot/
rsync -avz --rsync-path="sudo rsync" $PI_USER_HOST:/usr/include sysroot/usr/
rsync -avz --rsync-path="sudo rsync" $PI_USER_HOST:/usr/lib sysroot/usr/
#rsync -avz --rsync-path="sudo rsync" $PI_USER_HOST:/opt/vc sysroot/opt/
SYSROOT=$(readlink -f ./sysroot)
if [ ! -f ./sysroot-relativelinks.py ]
then
wget $SYSROOT_TOOL_URL
chmod +x ./sysroot-relativelinks.py
fi
./sysroot-relativelinks.py ./sysroot
# Press toolchain template
sed "s/TEMPLATESYSROOT/$(echo $SYSROOT | sed 's_/_\\/_g')/" ./toolchain.cmake.template > ./toolchain.cmake
sed -i "s/TEMPLATETOOLCHAIN/$(echo $TOOLCHAIN_DIR | sed 's_/_\\/_g')/" ./toolchain.cmake
# Clone librealsense
cd $CURDIR
if [ ! -d ./librealsense ]
then
git clone $LIBREALSENSE_GIT ./librealsense
fi
cd ./librealsense
rm -rf ./build
mkdir -p ./build
cd ./build
cmake ../ -DBUILD_EXAMPLES=false \
-DBUILD_GRAPHICAL_EXAMPLES=false \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_PYTHON_BINDINGS:bool=true \
-DPython_INCLUDE_DIR="${SYSROOT}/usr/include/python3.8" \
-DPython_LIBRARY="${SYSROOT}/usr/lib/aarch64-linux-gnu/libpython3.8.so" \
-DLIBUSB_LIB="${SYSROOT}/usr/lib/aarch64-linux-gnu/libusb-1.0.so.0.2.0" \
-DCMAKE_TOOLCHAIN_FILE=${CURDIR}/toolchain.cmake
make -j14
# Collect built binaries and tar up
mkdir -p $CURDIR/output
make DESTDIR=$CURDIR/output install
cd $CURDIR/output
tar cvzf ./librealsense2_pyrealsense2_aarch64.tar.gz ./*
cd $CURDIR
read -p "Remove generated build files (incl. toolchain, librealsense source and Raspi libraries)? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm -rf ./sysroot ./tools ./librealsense ./output
fi