#!/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 " } #先编译静态库 cd ./a_src && \ if [ -f build.sh ];then \ echo -e "\e[33;42;1mcd `pwd`/ \e[0m" && \ sh build.sh $@|| exit $?; \ fi && \ cd .. #再编译动态库 cd ./so_src && \ if [ -f build.sh ];then \ echo -e "\e[33;42;1mcd `pwd`/ \e[0m" && \ sh build.sh $@|| exit $? ; \ fi && \ cd ..