#!/bin/bash
|
|
# Git url
|
GITURL=https://github.com/lvgl/lv_port_linux.git
|
|
# branch
|
BRANCH=release/v9.5
|
|
# library name
|
LIB_NAME=$(basename "$GITURL" .git)
|
|
# Cross compiler for cross compile on Linux server
|
CROSS_COMPILE=/opt/gcc-aarch32-10.3-2021.07/bin/arm-none-linux-gnueabihf-
|
|
# compile jobs
|
JOBS=`cat /proc/cpuinfo |grep "processor"|wc -l`
|
|
# this project absolute path
|
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
|
|
# top project absolute path
|
TOP_PATH=$(realpath $PRJ_PATH/..)
|
|
# binaries build prefix install path
|
PREFIX_PATH=$TOP_PATH/install
|
|
# binaries finally install path if needed
|
#INST_PATH=/tftp
|
|
# download taballs path
|
TARBALL_PATH=$PRJ_PATH/tarballs
|
|
# shell script will exit once get command error
|
set -e
|
|
#+-------------------------+
|
#| Shell script functions |
|
#+-------------------------+
|
|
function pr_error() {
|
echo -e "\033[40;31m $1 \033[0m"
|
}
|
|
function pr_warn() {
|
echo -e "\033[40;33m $1 \033[0m"
|
}
|
|
function pr_info() {
|
echo -e "\033[40;32m $1 \033[0m"
|
}
|
|
function do_export()
|
{
|
pr_warn "cross(${CROSS_COMPILE}) compile $LIB_NAME"
|
|
export CC=${CROSS_COMPILE}gcc
|
export CXX=${CROSS_COMPILE}g++
|
export AR=${CROSS_COMPILE}ar
|
export LD=${CROSS_COMPILE}ld
|
export STRIP=${CROSS_COMPILE}strip
|
|
export PKG_CONFIG_PATH=$PREFIX_PATH/lib/pkgconfig:$PKG_CONFIG_PATH
|
export LIBRARY_PATH=$PREFIX_PATH/lib/:$LIBRARY_PATH
|
export LDFLAGS="-L$PREFIX_PATH/lib"
|
}
|
|
function do_fetch()
|
{
|
if [ -d $LIB_NAME/lvgl ] ; then
|
pr_warn "$LIB_NAME source code fetched already"
|
return 0;
|
fi
|
|
pr_info "start fetch $LIB_NAME source code"
|
if [ ! -d $LIB_NAME ] ; then
|
git clone -b $BRANCH $GITURL
|
fi
|
|
cd $LIB_NAME
|
git submodule update --init --recursive
|
|
cd $PRJ_PATH
|
}
|
|
function do_patch()
|
{
|
FILE=user_cross_compile_setup.cmake
|
TOOLCHAIN_ROOT=$(dirname $(dirname $CROSS_COMPILE))
|
TOOLCHAIN_PREFIX=$(basename $CROSS_COMPILE)
|
|
cd "$LIB_NAME" || exit 1
|
|
if grep -q "${TOOLCHAIN_PREFIX}" $FILE; then
|
pr_warn "toolchain already updated"
|
cd "$PRJ_PATH" || exit 1
|
return 0
|
fi
|
|
pr_info "modify toolchain config..."
|
|
sed -i \
|
-e "s#^set(tools .*#set(tools ${TOOLCHAIN_ROOT})#" \
|
-e "s#arm-openwrt-linux-gnueabi-gcc#${TOOLCHAIN_PREFIX}gcc#" \
|
-e "s#arm-openwrt-linux-gnueabi-g++#${TOOLCHAIN_PREFIX}g++#" \
|
$FILE
|
|
cd "$PRJ_PATH" || exit 1
|
}
|
|
function do_build()
|
{
|
BUILD_DIR="build"
|
|
cd "$LIB_NAME" || exit 1
|
|
if [ ! -f "$BUILD_DIR/CMakeCache.txt" ]; then
|
pr_info "configuring cmake..."
|
cmake -B "$BUILD_DIR" -S . -DCMAKE_TOOLCHAIN_FILE=./user_cross_compile_setup.cmake
|
else
|
pr_warn "cmake already configured"
|
fi
|
|
pr_info "building..."
|
cmake --build "$BUILD_DIR" -j$(nproc)
|
|
cd "$PRJ_PATH" || exit 1
|
}
|
|
function do_depends()
|
{
|
cd $TOP_PATH/libevdev || exit 1
|
|
pr_info "build depend libevdev..."
|
./build.sh
|
|
cd $PRJ_PATH || exit 1
|
}
|
|
function do_clean()
|
{
|
rm -rf *${LIB_NAME}*
|
}
|
|
if [[ $# == 1 && $1 == -c ]] ;then
|
pr_warn "start clean ${LIB_NAME}"
|
do_clean
|
exit;
|
fi
|
|
if [ -e $LIB_NAME/build/bin/lvglsim ] ; then
|
pr_warn "$LIB_NAME compiled already, exit..."
|
exit;
|
fi
|
|
do_depends
|
|
do_fetch
|
|
do_export
|
|
do_patch
|
|
do_build
|