Files
he/lib_src/so_src/libssh-0.9.8/build.sh
T
2026-06-22 15:35:18 +08:00

111 lines
4.4 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] Compilation Time: $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} ]===================================================="
echo -e "\e[32m TOOLCHAIN=${TOOLCHAIN} \e[0m"
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)"
if [[ ! -z ${TOOLCHAIN} ]] && [[ -f ${TOOLCHAIN} ]] ;then
echo -e "\e[32m TOOLCHAIN=${TOOLCHAIN} \e[0m"
source ${TOOLCHAIN}
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 '/')"
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 [lib${current_project_name}]===================================================="
if [[ $1 != "all" ]];then exit 0; fi
fi
# build path
mkdir -p ${build_path}
cd ${build_path}
#pwd
echo "----------------make start----------------"
if [[ "$pd_complier_type" =~ imx* ]]; then
echo "$pd_complier_type"
cmake -B $(pwd) -S ${current_project_path} \
-DCMAKE_C_COMPILER=aarch64-poky-linux-gcc \
-DCMAKE_BUILD_TYPE=Release \
-DWITH_EXAMPLES=OFF \
-DCMAKE_C_FLAGS="-O2 -std=c99 -Wno-deprecated-declarations"
else
echo "$pd_complier_type"
cmake -B $(pwd) -S ${current_project_path} -DCMAKE_C_COMPILER=x86_64-linux-gnu-gcc -DCMAKE_BUILD_TYPE=Release -DWITH_EXAMPLES=OFF -DCMAKE_C_FLAGS="-O2 -std=c99 -Wno-deprecated-declarations"
fi
make -j4 || exit $?
cp -ravf ${build_path}/lib/* ${PROJECT_ROOT}/out/${TARGET_PRODUCT}/lib/lib_so/
cp -ravf ${build_path}/lib/* ${PROJECT_ROOT}/board_dir/lib/
cd -
echo "===============================build shell end [lib${current_project_name}] [${pd_complier_type}]===================================================="