#!/bin/bash cd "$(dirname "$(readlink -f "$0")")" script_name=$(basename "$0") #if [ "$0" = "$script_name" ]; then echo "脚本被自身调用,请检查无效路径"; exit 1 ;fi # 显示脚本执行时间 start_time=$(date +%s); trap 'echo "$(print_execution_time $?)"' EXIT # 计算并打印脚本执行时间函数 function print_execution_time { end_time=$(date +%s); execution_time=$((end_time - start_time)); execution_time_formatted=$(date -u -d @$execution_time +"%T") if [ $1 -eq 0 ];then SET_COLOR="\e[32m "; else SET_COLOR="\e[31m error at $(pwd) \n\e[1m"; fi mydir_name="$(d=$(pwd); echo ${d##*/})" echo -e "${SET_COLOR} [$1] 执行时间:$execution_time_formatted ( $mydir_name )\e[0m " } current_project_path=$(pwd) export current_project_name=`echo ${current_project_path##*/}` echo "current_project_path = ${current_project_path}" echo "=========================build shell start [lib${current_project_name}]=============================" pd_complier_type=${TARGET_PRODUCT} if [ -z ${TARGET_PRODUCT} ];then PROJECT_ROOT=$(while [ ! -f "build/envsetup.sh" ]; do [ "$(pwd)" = "/" ] && exit 1; cd ..; done; pwd) if [ ! -z ${PROJECT_ROOT} ];then source ${PROJECT_ROOT}/build/envsetup.sh && lunch LAST if [ $? -eq 255 ];then exit 0; fi pd_complier_type=${TARGET_PRODUCT} fi fi echo -e " ready to build\e[34;1m ${pd_complier_type} \e[0m target [\e[34;1m ${current_project_name}\e[0m ] ......" unset LD_LIBRARY_PATH export pd_complier_name="$(if [[ "${TARGET_PRODUCT}" =~ "imx"* ]]; then echo "complier_arm"; else echo "complier_x86"; fi)" export arm_sysroot_path=${SYSROOT} export arm_compile_flags=${CFLAGS} echo "============================build shell start [lib${current_project_name}]====================================================" # set obj at: platform/out/build/xxxx/build check_dirs() { # check dir: process/ script/ local dir="$1"; if [[ -d "$dir/process" && -d "$dir/script" ]]; then echo "$dir"; exit 0;fi local parent="${dir%/*}"; if [[ "$parent" != "$dir" ]]; then check_dirs "$parent"; else echo "$(pwd)"; fi } base_folder="$(echo ${PROJECT_ROOT}|tr -s '/')" build_path=$(echo "$current_project_path" | sed "s|${base_folder}|${base_folder}/out/build/${pd_complier_type}/|g") echo "build_path = ${build_path}" pr_lib_dir="$(echo ${current_project_path::-4}|sed "s|/lib_src/|/lib/${pd_complier_type}/lib_|")" pr_lib_type="$(base_name=$(basename "$pr_lib_dir");echo ${base_name#*_})" #echo "pr_lib_dir = ${pr_lib_dir}" #echo "pr_lib_type = ${pr_lib_type}" if [[ $1 == "all" ]];then rm -rvf ${build_path} ./openssl-OpenSSL_1_1_1g/build.sh $@ || exit $? # 优先编译共享内存 ./paho.mqtt.c-1.3.13/build.sh $@ || exit $? # 优先编译共享内存 ./paho.mqtt.cpp-1.3.2/build.sh $@ || exit $? # 优先编译共享内存 fi echo "===============build shell end [ lib${current_project_name} ] [${pd_complier_type}]====================================================" #执行lib_general 编译 ./prpublicmemory/build.sh $@ || exit $? # 优先编译共享内存 ./prxml/build.sh $@ || exit $? # 后优先编译prxml # auto find build lib_src_dir_list=$(find */ -name build.sh -exec dirname {} \;) statistical_lists="" ignore_lists="" for dir in ${lib_src_dir_list[@]}; do # 已优先编译,遍历时跳过 if [[ "$dir" == "prxml" ]]; then continue fi # 仅在All时优先编译,其他情况不需要在遍历时编译 if [[ "$dir" == "openssl-OpenSSL_1_1_1g" \ || "$dir" == "paho.mqtt.c-1.3.13" \ || "$dir" == "paho.mqtt.cpp-1.3.2" ]]; then echo "ignore directory $dir" ignore_lists+=("\n\t\t\t\t${dir}") continue fi if [[ "$dir" == "libssh-0.9.8" ]] && [[ $pd_complier_name == "complier_x86" ]]; then echo "pd_complier_name = $pd_complier_name" echo "ignore directory $dir"; continue; ignore_lists+=("\n\t\t\t\t${dir}") fi if [[ "$dir" != "prlog" && "$dir" != "prsqlite" && "$dir" != "prxml" ]]; then echo -e "\e[32m enter dir: \e[34m$dir\e[0m" cd "$dir" || { echo "Failed to change to directory $dir"; continue; } && \ sh build.sh $@ || exit $? || { echo "Failed to execute build.sh in directory $dir"; cd - > /dev/null; continue; } && \ cd - statistical_lists+=("\n\t\t\t\t$dir") else echo -e "\e[35m enter dir: \e[34m$dir\e[0m" lib_path="${pr_lib_dir}/lib${dir}.${pr_lib_type}" if [ "$1" == "all" ] || [ "$1" == "clean" ] || [ "$1" == "-c" ] || [ ! -f "${lib_path}" ]; then cd "$dir" || { echo "Failed to change to directory $dir"; continue; } && \ sh build.sh $@ || exit $? || { echo "Failed to execute build.sh in directory $dir"; cd - > /dev/null; continue; } && \ cd - statistical_lists+=("\n\t\t\t\t$dir") else echo "jump $dir" ignore_lists+=("\n\t\t\t\t${dir}") fi fi done echo -e "\e[34m build Statistical Lists [$((${#statistical_lists[@]}-1))]: ${statistical_lists[@]} \e[0m" echo -e "\e[37m Ignore Lists[$((${#ignore_lists[@]}-1))]: ${ignore_lists[@]} \e[0m" echo "===============================build shell end [lib${current_project_name}] [${pd_complier_type}]===================================================="