/
erhoof
/
telegraf
Обзор
Документация
Войти
/
erhoof
/
telegraf
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
scripts/build_tdlib.bash
265 строк
6 KB
Alexey Nosov
18-tf Добавлена поддержка всех стандартных режимов сборки cmake
08 ноя 2024, 04:59
08 ноя 2024, 04:59
79d04a8
Код
Авторство
О чём код?
#!/bin/bash set -o nounset set -o errexit version="1.1.0" self="$0" current_dir="$(pwd)" help() { echo "Usage: $self [...<option>]" echo "Mandatory arguments to long options are mandatory for short options too." echo " -p, --path=<path> tdlib sources path, default: current dir" echo " -s, --sdk-base=<sdk> stk base name, default: \"AuroraOS-5.1.1.60\"" echo " -f, --flush flush build and target dirs" echo " -b, --build-dir=<dir> build dir path, default: \"<path>/build/<arch>\"" echo " -i, --install-dir=<div> install dir path, default: \"<path>/install/<arch>\"" echo " -a, --architechtures=<arch_1>,<arch_2>,..." echo " build specified architectures only," echo " default: x86_64,aarch64,armv7hl" echo " -c, --compress compress to a tar archive with xz" echo " -D, --debug build for debugging" echo " -R, --release-with-info build a release with debug info" echo " -M, --min-size-release build a minimum size release" echo " -j, --just-compress just create an archive" echo " -A, --archive=<filename> archive filename default: \"tdlib-<git-commit>.tar.xz\"" echo " -d, --dry-run only print commands" echo " -r, --run start building" echo " -v, --version print the script version" echo " -h, --help show this text" } base= apsdk_base="sfdk engine exec sb2 -t" sdk_base="AuroraOS-5.1.1.60" flush=0 build_dir= install_dir= archs_list="x86_64 aarch64 armv7hl" build_type=Release compress=0 just_compress=0 archive_file= dry_run=0 if [[ $# -eq 0 ]]; then help exit 0 fi short_arguments="fpsbiadrcjAhvDRM" while [ $# -ne 0 ]; do key="$1" case "$key" in -f | --flush) flush=1 shift ;; -p | --path) shift base="$1" shift ;; --path=*) base="$(echo "$key" | sed -e 's/^--path=//')" shift ;; -s | --sdk-base) shift sdk_base="$1" shift ;; --sdk-base=*) sdk_base="$(echo "$key" | sed -e 's/^--sdk-base=//')" shift ;; -b | --build-dir) shift build_dir="$1" shift ;; --build-dir=*) build_dir="$(echo "$key" | sed -e 's/^--build-dir=//')" shift ;; -i | --install-dir) shift install_dir="$1" shift ;; --install-dir=*) install_dir="$(echo "$key" | sed -e 's/^--install-dir=//')" shift ;; -a | --architectures) shift archs_list=$(echo "$1" | sed -e 's/,/ /g') shift ;; --architectures=*) archs_list="$(echo "$key" | sed -e 's/^--architectures=//' -e 's/,/ /g')" shift ;; -D | --debug) build_type=Debug shift ;; -R | --release-with-info) build_type=RelWithDebInfo shift ;; -M | --min-size-release) build_type=MinSizeRel shift ;; -d | --dry-run) dry_run=1 shift ;; -r | --run) shift ;; -c | --compress) compress=1 shift ;; -j | --just-compress) just_compress=1 shift ;; -A | --archive) shift archive_file="$1" shift ;; --archive=*) archive_file="$(echo "$key" | sed -e 's/^--archive=//')" shift ;; -h | --help) help exit ;; -v | --version) echo "version: $version" exit ;; -*) shift extracted_short_arguments= extracted_short_parameter= for ((i = 1; i < ${#key}; i++)); do if [[ "$short_arguments" == *"${key:$i:1}"* ]]; then extracted_short_arguments="$extracted_short_arguments -${key:$i:1}" else extracted_short_parameter="${key:$i}" break fi done if [[ "$extracted_short_parameter" == "" ]]; then set -- $extracted_short_arguments "$@" else set -- $extracted_short_arguments "${key:$i}" "$@" fi ;; *) break ;; esac done archs=($archs_list) apsdk_base="$apsdk_base $sdk_base" if [[ "$base" = "" ]]; then base="$(pwd)" fi if [[ "$build_dir" = "" ]]; then build_dir="$base/build" fi if [[ "$install_dir" = "" ]]; then install_dir="$base/install" fi echo "source path: $base" echo "sdk: $sdk_base" echo "target architectures: $archs_list" echo "build type: $build_type" if [[ "$flush" -eq 1 ]]; then echo "flush: true" else echo "flush: false" fi echo "build directory: $build_dir" echo "install directory: $install_dir" echo "" build_for() { local arch=$1 local apsdk="$apsdk_base-$arch" echo "building for $arch" if [[ "$dry_run" -eq "1" ]]; then if [[ $flush -eq 1 ]]; then echo "rm --force --recursive \"$build_dir/$arch\" && rm --force --recursive \"$install_dir/$arch\"" fi echo "mkdir --parents \"$build_dir/$arch\"" echo "cd \"$build_dir/$arch\"" echo "$apsdk cmake -DCMAKE_BUILD_TYPE=$build_type \"$base\"" echo "$apsdk cmake --build . -- -j$(nproc)" echo "mkdir --parents \"$install_dir/$arch\"" echo "$apsdk cmake --install . --prefix \"$install_dir/$arch\"" else if [[ $flush -eq 1 ]]; then rm --force --recursive "$build_dir/$arch" && rm --force --recursive "$install_dir/$arch" fi mkdir --parents "$build_dir/$arch" cd "$build_dir/$arch" $apsdk cmake -DCMAKE_BUILD_TYPE=$build_type "$base" $apsdk cmake --build . -- -j$(nproc) mkdir --parents "$install_dir/$arch" $apsdk cmake --install . --prefix "$install_dir/$arch" fi echo "done: $arch" echo "" } if [[ "$just_compress" -ne "1" ]]; then for arch in ${archs[*]}; do build_for "$arch" done fi if [[ "$compress" -eq "1" ]] || [[ "$just_compress" -eq "1" ]]; then if [[ "$archive_file" = "" ]]; then cd "$base" archive_file="tdlib-$(git describe --tags --long --always --dirty).tar.xz" fi cd "$current_dir" echo "archive file: $archive_file" if [[ "$dry_run" -eq "1" ]]; then echo "tar --directory=\"$install_dir\" --create --xz --file=\"$archive_file\" $(echo ${archs[*]// /|})" else tar --directory="$install_dir" --create --xz --file="$archive_file" $(echo ${archs[*]// /|}) fi echo "archive \"$archive_file\" has been successfully created" fi cd "$current_dir"