commit 078fa5465d1105c466453a36a005e70d322c14dc Author: Nareshkumar Rao Date: Thu May 13 16:56:27 2021 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf533a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +sysroot/ +tools/ +librealsense/ +sysroot-relativelinks.py +toolchain.cmake \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..24307f8 --- /dev/null +++ b/build.sh @@ -0,0 +1,64 @@ +#!/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 +tar cvzf $CURDIR/librealsensecompiled.tar.gz $(find . -name "*.so*") diff --git a/toolchain.cmake.template b/toolchain.cmake.template new file mode 100644 index 0000000..c64ca47 --- /dev/null +++ b/toolchain.cmake.template @@ -0,0 +1,18 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) + +set(CMAKE_SYSROOT TEMPLATESYSROOT) + +set(tools TEMPLATETOOLCHAIN) +set(CMAKE_C_COMPILER ${tools}/bin/aarch64-none-linux-gnu-gcc) +set(CMAKE_CXX_COMPILER ${tools}/bin/aarch64-none-linux-gnu-g++) + +include_directories(SYSTEM TEMPLATESYSROOT/usr/include/aarch64-linux-gnu) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +set(CMAKE_THREAD_LIBS_INIT "-lpthread") +