#!/bin/bash # library name and version # Official: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git LIB_NAME=libgpiod-2.0 PACK_SUFIX=tar.gz # Cross compiler for cross compile on Linux server CROSS_COMPILE=arm-linux-gnueabihf- # this project absolute path PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) # binaries install path PREFIX_PATH=$PRJ_PATH/install # check installed or not file INST_FILE=$PREFIX_PATH/lib/libgpiod.so #+-------------------------+ #| 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 pr_error $1 fi } function do_export() { pr_warn "set cross(${CROSS_COMPILE})" # export cross toolchain 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 " # Clear LDFLAGS and CFLAGS export LDFLAGS= export CFLAGS= } function do_fetch() { if [ -e ${INST_FILE} ] ; then pr_warn "$LIB_NAME compile and installed alredy" exit ; fi if [ -d $LIB_NAME ] ; then pr_warn "$LIB_NAME fetch already" return ; fi if [ ! -f ${LIB_NAME}.${PACK_SUFIX} ] ; then wget https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/snapshot/${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} } 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} --enable-static \ --cache-file=arm-linux.cache --enable-tools check_result "ERROR: configure ${LIB_NAME} failure" make -j ${JOBS} && make install check_result "ERROR: compile ${LIB_NAME} failure" } function do_clean() { rm -rf ${LIB_NAME}* rm -rf install } if [[ $# == 1 && $1 == -c ]] ;then pr_warn "start clean $LIB_NAME" do_clean exit; fi do_fetch do_build