LingYun Studio embeded system framwork software, such as thirdparty build shell and lingyun library
guowenxue
2024-08-21 655ce0907581ca2fdebdb87a154901c09763db56
update libgpiod build shell script
3 files modified
304 ■■■■ changed files
3rdparty/libgpiod/build.sh 209 ●●●● patch | view | raw | blame | history
hal/api/libgpiod/build.sh 88 ●●●● patch | view | raw | blame | history
hal/api/makefile 7 ●●●●● patch | view | raw | blame | history
3rdparty/libgpiod/build.sh
@@ -1,54 +1,128 @@
#!/bin/bash
#+--------------------------------------------------------------------------------------------
#|Description:  This shell script used download and compile libgpiod for ARM
#|     Author:  GuoWenxue <guowenxue@gmail.com>
#|  ChangeLog:
#|           1, Initialize 1.0.0 on 2011.04.12
#|
#|   Warnning: libgpiod configure depends on automake >= 1.14, use follow command to change it
#|             sudo update-alternatives --config automake
#+--------------------------------------------------------------------------------------------
# library name and version
# Official: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
LIB_NAME=libgpiod-2.0.1
PACK_SUFIX=tar.gz
PRJ_PATH=`pwd`
PREFIX_PATH=`pwd`/../install
# LingYun source code FTP server
LY_FTP=http://master.weike-iot.com:2211/src/
LYFTP_SRC=http://master.weike-iot.com:2211/src/
# library download URL address
LIB_URL=$LY_FTP
CROSSTOOL=/opt/gcc-aarch32-10.3-2021.07/bin/arm-none-linux-gnueabihf-
# Cross compiler for cross compile on Linux server
CROSS_COMPILE=arm-linux-gnueabihf-
function msg_banner()
{
    echo ""
    echo "+-----------------------------------------------------------------------"
    echo "|  $1 "
    echo "+-----------------------------------------------------------------------"
    echo ""
# 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 install path
PREFIX_PATH=$TOP_PATH/install
BIN_PATH=$PREFIX_PATH/bin
LIB_PATH=$PREFIX_PATH/lib
INC_PATH=$PREFIX_PATH/include
# check installed or not file
INST_FILE=$PREFIX_PATH/lib/libgpiod.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 check_result()
{
    if [ $? != 0 ] ; then
       echo ""
       echo "+-----------------------------------------------------------------------"
       echo "|  $1 "
       echo "+-----------------------------------------------------------------------"
       echo ""
       exit ;
        pr_error "$1"
        exit
    fi
}
function export_cross()
# decompress a packet to destination path
function do_unpack()
{
    tarball=$1
    dstpath=`pwd`
    if [[ $# == 2 ]] ; then
        dstpath=$2
    fi
    pr_info "decompress $tarball => $dstpath"
    mkdir -p $dstpath
    case $tarball in
        *.tar.gz)
            tar -xzf $tarball -C $dstpath
            ;;
        *.tar.bz2)
            tar -xjf $tarball -C $dstpath
            ;;
        *.tar.xz)
            tar -xJf $tarball -C $dstpath
            ;;
        *.tar.zst)
            tar -I zstd -xf $tarball -C $dstpath
            ;;
        *.tar)
            tar -xf $tarball -C $dstpath
            ;;
        *.zip)
            unzip -qo $tarball -d $dstpath
            ;;
        *)
            pr_error "decompress Unsupport packet: $tarball"
            return 1;
            ;;
    esac
}
function do_export()
{
    BUILD_ARCH=$(uname -m)
    if [[ $BUILD_ARCH =~ "arm" ]] ; then
        pr_warn "local($BUILD_ARCH) compile $LIB_NAME"
        return ;
    fi
    pr_warn "cross(${CROSS_COMPILE}) compile $LIB_NAME"
    # export cross toolchain
    export CC=${CROSSTOOL}gcc
    export AS=${CROSSTOOL}as
    export AR=${CROSSTOOL}ar
    export LD=${CROSSTOOL}ld
    export NM=${CROSSTOOL}nm
    export RANLIB=${CROSSTOOL}ranlib
    export OBJDUMP=${CROSSTOOL}objdump
    export STRIP=${CROSSTOOL}strip
    export CC=${CROSS_COMPILE}gcc
    export CXX=${CROSS_COMPILE}g++
    export AS=${CROSS_COMPILE}as
    export AR=${CROSS_COMPILE}ar
    export LD=${CROSS_COMPILE}ld
    export NM=${CROSS_COMPILE}nm
    export RANLIB=${CROSS_COMPILE}ranlib
    export OBJDUMP=${CROSS_COMPILE}objdump
    export STRIP=${CROSS_COMPILE}strip
    # export cross configure 
    export CONFIG_CROSS=" --build=i686-pc-linux --host=arm-linux "
@@ -58,40 +132,55 @@
    export CFLAGS=
}
function compile_libgpiod()
function do_fetch()
{
    SRC_NAME=libgpiod-2.0.1
    PACK_SUFIX=tar.gz
    IMG_NAME=libgpiod.so.2.1.1
    if [ -f ${PREFIX_PATH}/lib/${IMG_NAME} ] ; then
        msg_banner "$SRC_NAME already compile and installed"
        return 0;
    if [ -e ${INST_FILE} ] ; then
        pr_warn "$LIB_NAME compile and installed alredy"
        exit ;
    fi
    msg_banner "Start cross compile $SRC_NAME "
    if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then
        #wget https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/snapshot/${SRC_NAME}.${PACK_SUFIX}
        wget $LYFTP_SRC/$SRC_NAME.$PACK_SUFIX
        check_result "ERROR: download ${SRC_NAME} failure"
    if [ -d $LIB_NAME ] ; then
        pr_warn "$LIB_NAME fetch already"
        return ;
    fi
    tar -xzf ${SRC_NAME}.${PACK_SUFIX}
    cd ${SRC_NAME}
    if [ ! -f ${LIB_NAME}.${PACK_SUFIX} ] ; then
        wget ${LIB_URL}/${LIB_NAME}.${PACK_SUFIX}
        check_result "ERROR: download ${LIB_NAME} failure"
    fi
    do_unpack ${LIB_NAME}.${PACK_SUFIX}
}
function do_build()
{
    cd $LIB_NAME
    ./autogen.sh
    do_export
    echo "ac_cv_func_malloc_0_nonnull=yes" >arm-linux.cache 
    ./configure --prefix=${PREFIX_PATH} ${CONFIG_CROSS} --cache-file=arm-linux.cache --enable-tools
    check_result "ERROR: configure ${SRC_NAME} failure"
    ./configure --prefix=${PREFIX_PATH} ${CONFIG_CROSS} --enable-static \
        --cache-file=arm-linux.cache --enable-tools
    check_result "ERROR: configure ${LIB_NAME} failure"
    make  && make install
    check_result "ERROR: compile ${SRC_NAME} failure"
    cd -
    make -j ${JOBS} && make install
    check_result "ERROR: compile ${LIB_NAME} failure"
}
export_cross
function do_clean()
{
    rm -rf *${LIB_NAME}*
}
compile_libgpiod
if [[ $# == 1 && $1 == -c ]] ;then
    pr_warn "start clean ${LIB_NAME}"
    do_clean
    exit;
fi
do_fetch
do_build
hal/api/libgpiod/build.sh
@@ -2,20 +2,38 @@
# library name and version
# Official: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
LIB_NAME=libgpiod-2.0
LIB_NAME=libgpiod-2.0.1
PACK_SUFIX=tar.gz
# LingYun source code FTP server
LY_FTP=http://master.weike-iot.com:2211/src/
# library download URL address
LIB_URL=$LY_FTP
# Cross compiler for cross compile on Linux server
CROSS_COMPILE=arm-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 install path
PREFIX_PATH=$PRJ_PATH/install
PREFIX_PATH=$TOP_PATH/install
BIN_PATH=$PREFIX_PATH/bin
LIB_PATH=$PREFIX_PATH/lib
INC_PATH=$PREFIX_PATH/include
# check installed or not file
INST_FILE=$PREFIX_PATH/lib/libgpiod.so
# shell script will exit once get command error
set -e
#+-------------------------+
#| Shell script functions  |
@@ -36,13 +54,64 @@
function check_result()
{
    if [ $? != 0 ] ; then
        pr_error $1
        pr_error "$1"
        exit
    fi  
}
# decompress a packet to destination path
function do_unpack()
{
    tarball=$1
    dstpath=`pwd`
    if [[ $# == 2 ]] ; then
        dstpath=$2
    fi
    pr_info "decompress $tarball => $dstpath"
    mkdir -p $dstpath
    case $tarball in
        *.tar.gz)
            tar -xzf $tarball -C $dstpath
            ;;
        *.tar.bz2)
            tar -xjf $tarball -C $dstpath
            ;;
        *.tar.xz)
            tar -xJf $tarball -C $dstpath
            ;;
        *.tar.zst)
            tar -I zstd -xf $tarball -C $dstpath
            ;;
        *.tar)
            tar -xf $tarball -C $dstpath
            ;;
        *.zip)
            unzip -qo $tarball -d $dstpath
            ;;
        *)
            pr_error "decompress Unsupport packet: $tarball"
            return 1;
            ;;
    esac
}
function do_export()
{
    pr_warn "set cross(${CROSS_COMPILE})"
    BUILD_ARCH=$(uname -m)
    if [[ $BUILD_ARCH =~ "arm" ]] ; then
        pr_warn "local($BUILD_ARCH) compile $LIB_NAME"
        return ;
    fi
    pr_warn "cross(${CROSS_COMPILE}) compile $LIB_NAME"
    # export cross toolchain
    export CC=${CROSS_COMPILE}gcc
@@ -76,12 +145,11 @@
    fi
    if [ ! -f ${LIB_NAME}.${PACK_SUFIX} ] ; then
        wget https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/snapshot/${LIB_NAME}.${PACK_SUFIX}
        wget ${LIB_URL}/${LIB_NAME}.${PACK_SUFIX}
        check_result "ERROR: download ${LIB_NAME} failure"
    fi
    pr_warn "$LIB_NAME download already, decompress it now"
    tar -xzf ${LIB_NAME}.${PACK_SUFIX}
    do_unpack ${LIB_NAME}.${PACK_SUFIX}
}
function do_build()
@@ -103,12 +171,11 @@
function do_clean()
{
    rm -rf ${LIB_NAME}*
    rm -rf install
    rm -rf *${LIB_NAME}*
}
if [[ $# == 1 && $1 == -c ]] ;then
    pr_warn "start clean $LIB_NAME"
    pr_warn "start clean ${LIB_NAME}"
    do_clean
    exit;
fi
@@ -116,3 +183,4 @@
do_fetch
do_build
hal/api/makefile
@@ -27,9 +27,9 @@
BINARIES=$(SRCFILES:%.c=%)
# libgpiod compile install path
LIBGPIOD_PATH=libgpiod/install
CFLAGS+=-I ${LIBGPIOD_PATH}/include
LDFLAGS+=-L ${LIBGPIOD_PATH}/lib -lgpiod
LIBS_PATH=install
CFLAGS+=-I ${LIBS_PATH}/include
LDFLAGS+=-L ${LIBS_PATH}/lib -lgpiod
all: libs binaries install
@@ -50,5 +50,6 @@
distclean: clean
    @rm -f  tags cscope*
    @make clean -C libgpiod
    @rm -rf install
.PHONY: clean entry