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

127 lines
4.8 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 [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}
make distclean >/dev/null 2>&1 || true
rm -f Makefile configdata.pm configdata.pm.old
rm -rvf $(pwd)/ssl_result
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
# 3) 清理旧配置和环境污染
unset CROSS_COMPILE
unset PERL5LIB PERL_LOCAL_LIB_ROOT PERL_MB_OPT PERL_MM_OPT
# 4) 把环境里的 CC 拆成“编译器本体 + 参数”
RAW_CC="$CC"
REAL_CC="$(printf '%s\n' "$RAW_CC" | awk '{print $1}')"
EXTRA_CC_FLAGS="$(printf '%s\n' "$RAW_CC" | cut -d' ' -f2-)"
export CC="$REAL_CC"
export CFLAGS="${EXTRA_CC_FLAGS} ${CFLAGS}"
echo "RAW_CC=$RAW_CC"
echo "CC=$CC"
echo "CFLAGS=$CFLAGS"
# 只有第一次或 all 模式时,才重新 Configure
if [[ ! -f Makefile || "$1" == "all" ]]; then
/usr/bin/perl ./Configure linux-aarch64 \
no-asm shared no-async \
--prefix="$(pwd)/ssl_result" || exit $?
sed -i 's/-m64//g' Makefile
fi
# # 5) 重新配置
# perl ./Configure linux-aarch64 \
# no-asm shared no-async \
# --prefix="$(pwd)/ssl_result"
# 7. 强制用系统 Perl 编译和安装
make PERL=/usr/bin/perl -j4
make PERL=/usr/bin/perl install_sw
# # 7) 编译安装
# make -j4
# make install_sw
cp -ravf ssl_result/lib/libssl.so* ${PROJECT_ROOT}/out/${TARGET_PRODUCT}/lib/lib_so/
cp -ravf ssl_result/lib/libcrypto.so* ${PROJECT_ROOT}/out/${TARGET_PRODUCT}/lib/lib_so/
cp -ravf ssl_result/lib/libssl.so* ${PROJECT_ROOT}/board_dir/lib/
cp -ravf ssl_result/lib/libcrypto.so* ${PROJECT_ROOT}/board_dir/lib/
echo "===============================build shell end [lib${current_project_name}] [${pd_complier_type}]===================================================="