From 14c45586ac7c9e01cb4745185e698e593773bf08 Mon Sep 17 00:00:00 2001 From: guowenxue <guowenxue@gmail.com> Date: Wed, 28 Aug 2024 17:52:01 +0800 Subject: [PATCH] update openlibs top build.sh --- openlibs/busybox/build.sh | 195 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 152 insertions(+), 43 deletions(-) diff --git a/openlibs/busybox/build.sh b/openlibs/busybox/build.sh index 615c9dd..be2b3a7 100755 --- a/openlibs/busybox/build.sh +++ b/openlibs/busybox/build.sh @@ -1,75 +1,184 @@ #!/bin/bash -set -e +# library name and version +# Official: https://busybox.net/downloads/ +LIB_NAME=busybox-1.36.0 +PACK_SUFIX=tar.bz2 -ROOTFS_PATH=`pwd`/../../linux-bsp/rootfs/ - +# LingYun source code FTP server LYFTP_SRC=http://master.weike-iot.com:2211/src/ +# library download URL address +LIB_URL=$LYFTP_SRC + +# 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) -JOBS=`cat /proc/cpuinfo | grep processor | wc -l` +# top project absolute path +TOP_PATH=$(realpath $PRJ_PATH/..) -function msg_banner() -{ - echo "" - echo "+-----------------------------------------------------------------------" - echo "| $1 " - echo "+-----------------------------------------------------------------------" - echo "" +# 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/bin/busybox + +# 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" fi } - - -function compile_busybox() +# decompress a packet to destination path +function do_unpack() { - SRC_NAME=busybox-1.31.0 - PACK_SUFIX=tar.bz2 + tarball=$1 + dstpath=`pwd` - if [ -f $SRC_NAME/busybox ] ; then - msg_banner "$SRC_NAME already compile and installed" - return 0; - fi - - msg_banner "start download and compile $SRC_NAME " - - if [ ! -d $SRC_NAME ] ; then - if [ ! -f $SRC_NAME.${PACK_SUFIX} ] ; then - wget ${LYFTP_SRC}/${SRC_NAME}.${PACK_SUFIX} - check_result "ERROR: download ${SRC_NAME} failure" - fi - - tar -xjf $SRC_NAME.${PACK_SUFIX} + if [[ $# == 2 ]] ; then + dstpath=$2 fi - cp config/${SRC_NAME}.config $SRC_NAME/.config + pr_info "decompress $tarball => $dstpath" - cd $SRC_NAME + mkdir -p $dstpath + case $tarball in + *.tar.gz) + tar -xzf $tarball -C $dstpath + ;; - sed -i "s|^CONFIG_CROSS_COMPILER_PREFIX.*|CONFIG_CROSS_COMPILER_PREFIX=\"${CROSS_COMPILE}\"|g" .config - sed -i "s|^CONFIG_PREFIX.*|CONFIG_PREFIX=\"$ROOTFS_PATH\"|g" .config + *.tar.bz2) + tar -xjf $tarball -C $dstpath + ;; - make - #make uninstall && sudo make install + *.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 -compile_busybox + pr_warn "cross(${CROSS_COMPILE}) compile $LIB_NAME" + # 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 ${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 + + cp $PRJ_PATH/config/${LIB_NAME}.config .config + + do_export + + make -j ${JOBS} CROSS_COMPILE=$CROSS_COMPILE + check_result "ERROR: compile ${LIB_NAME} failure" + + pr_info "${LIB_NAME} installed to '${BIN_PATH}'" + mkdir -p ${BIN_PATH} + install -m 755 busybox ${BIN_PATH}/ +} + +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_build -- Gitblit v1.9.1