89 lines
3.6 KiB
Bash
89 lines
3.6 KiB
Bash
#!/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 [ ${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 [${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 '/')"
|
|
|
|
if [[ $current_project_path =~ "$base_folder" ]] && [ ! -z $base_folder ]; then
|
|
echo ""
|
|
else
|
|
echo "base_folder = $base_folder"
|
|
echo "current_project_path = $current_project_path"
|
|
echo -e "\e[31m Error: 环境配置不匹配,在当前项目下请重新配置:\n\e[35m\t source build/envsetup.sh \e[0m"
|
|
exit -2
|
|
fi
|
|
|
|
build_path=$(echo "$current_project_path" | sed "s|${base_folder}|${base_folder}/out/build/${pd_complier_type}/|g")
|
|
echo "build_path = ${build_path}"
|
|
|
|
if [[ $1 == "clean" ]] || [[ $1 == "-c" ]] || [[ $1 == "all" ]];then
|
|
if [[ "$build_path" == *"/out/build/"* ]]; then
|
|
rm -rvf ${build_path}
|
|
else
|
|
if [ -d ${build_path} ];then
|
|
find "${build_path}" -name '*.o' -print0 | xargs -r0 rm -f
|
|
find ${build_path} -name 'cmake_install.cmake' -print0 | xargs -r0 rm -f
|
|
find ${build_path} -name 'CMakeCache.txt' -print0 | xargs -r0 rm -f
|
|
find ${build_path} -type d -name 'CMakeFiles' -print0 | xargs -r0 rm -rf
|
|
fi
|
|
fi
|
|
echo " clean done."
|
|
echo "====================================================build shell end [ ${current_project_name} ]===================================================="
|
|
if [[ $1 != "all" ]];then exit 0; fi
|
|
fi
|
|
|
|
|
|
# build path
|
|
mkdir -p ${build_path}
|
|
cmake -B ${build_path}
|
|
echo "----------------make start----------------"
|
|
cmake --build "${build_path}" -j4 || exit $?
|
|
|
|
echo "===============================build shell end [${current_project_name}] [${pd_complier_type}]===================================================="
|
|
|