#!/bin/bash
|
|
# Git url
|
GITURL=https://gitlab.freedesktop.org/libevdev/libevdev.git
|
|
# branch
|
BRANCH=master
|
|
# 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
|
|
# check installed or not file
|
INST_FILE=$PREFIX_PATH/lib/libevdev.so
|
|
# 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 CROSS_FILE=cross.txt
|
}
|
|
function do_fetch()
|
{
|
if [ -e ${INST_FILE} ] ; then
|
pr_warn "$LIB_NAME compiled already, exit..."
|
exit;
|
fi
|
|
if [ -d $LIB_NAME ] ; 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 $PRJ_PATH
|
}
|
|
function do_build()
|
{
|
BUILD_DIR="build"
|
|
cd "$LIB_NAME" || exit 1
|
|
rm -rf "$BUILD_DIR" && mkdir -p $BUILD_DIR && cd $BUILD_DIR
|
|
cat > "$CROSS_FILE" <<EOF
|
|
[binaries]
|
c = '${CC}'
|
cpp = '${CXX}'
|
ar = '${AR}'
|
strip = '${STRIP}'
|
pkgconfig = 'pkg-config'
|
|
[host_machine]
|
system = 'linux'
|
cpu_family = 'arm'
|
cpu = 'armv7'
|
endian = 'little'
|
EOF
|
|
meson setup .. --cross-file "$CROSS_FILE" --prefix="$PREFIX_PATH" -Ddocumentation=disabled -Dtests=disabled
|
|
ninja -j$(nproc) && ninja install
|
|
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
|
|
do_fetch
|
|
do_export
|
|
do_build
|