From 08e372eaf280cb3c60988a17704157ec5c387aea Mon Sep 17 00:00:00 2001 From: Egor Tsyganchuk Date: Tue, 31 Mar 2026 13:54:49 +0300 Subject: [PATCH] Refactor build-libraries.sh and env.sh for improved environment setup - Updated build-libraries.sh to use --global and --path options for environment registration, enhancing clarity and consistency. - Modified env.sh to support custom paths and improved error handling for the --path argument, streamlining toolchain path resolution. - Removed redundant SYSROOT_DIR assignments to simplify the script logic. --- build-libraries.sh | 15 +++++++-------- env.sh | 28 ++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/build-libraries.sh b/build-libraries.sh index 5153f3a..9b29b80 100755 --- a/build-libraries.sh +++ b/build-libraries.sh @@ -8,9 +8,10 @@ source "$(dirname "$0")/versions.sh" TOP="$(pwd)" INSTALL_DIR="${TOP}/build/install" INSTALL_BIN_DIR="${INSTALL_DIR}/bin" +SYSROOT_DIR="${INSTALL_DIR}/sysroot" # Запускаем предварительно для того чтобы подтянуть переменные -. ./env.sh --toolchain --register "${INSTALL_DIR}" +. ./env.sh --global --path "${INSTALL_DIR}" # Сбрасываем CFLAGS/CXXFLAGS — все флаги уже встроены в CC/CXX export CFLAGS="" @@ -19,7 +20,6 @@ export CXXFLAGS="" # Подготавливаем пути к разделам LIB_DIR="${TOP}/src/libs" -SYSROOT_DIR="${SYSROOT}" SYSROOT_ETC_DIR="${SYSROOT_DIR}/etc" SYSROOT_USR_DIR="${SYSROOT_DIR}/usr" BUILD_SRC_DIR="${TOP}/build" @@ -77,8 +77,8 @@ echo "== Распаковка завершена ==" # Установка окружения # ================================================================== -cd ${TOP} -. ./env.sh --toolchain --register "${INSTALL_DIR}" "rc" +cd "${TOP}" +. ./env.sh --global --path "${INSTALL_DIR}" export CFLAGS="" export CXXFLAGS="" @@ -89,8 +89,8 @@ make install # ================================================================== -cd ${TOP} -. ./env.sh --toolchain --register "${INSTALL_DIR}" +cd "${TOP}" +. ./env.sh --global --path "${INSTALL_DIR}" export CFLAGS="" export CXXFLAGS="" @@ -173,5 +173,4 @@ make install # ================================================================== -cd ${TOP} -. ./env.sh --toolchain --unregister \ No newline at end of file +cd "${TOP}" \ No newline at end of file diff --git a/env.sh b/env.sh index f573d2d..e48e85d 100755 --- a/env.sh +++ b/env.sh @@ -1,15 +1,31 @@ TOP="$(pwd)" TOOLCHAIN_PATH="" GLOBAL_MODE=0 +CUSTOM_PATH="" -for arg in "$@"; do - if [ "$arg" = "--global" ]; then - GLOBAL_MODE=1 - break - fi +while [ $# -gt 0 ]; do + case "$1" in + --global) + GLOBAL_MODE=1 + shift + ;; + --path) + if [ -z "$2" ]; then + echo "Ошибка: для --path нужно указать путь" + return 1 2>/dev/null || exit 1 + fi + CUSTOM_PATH="$2" + shift 2 + ;; + *) + shift + ;; + esac done -if [ -d "${TOP}/arm-uclinuxfdpiceabi" ]; then +if [ -n "${CUSTOM_PATH}" ]; then + TOOLCHAIN_PATH="${CUSTOM_PATH}" +elif [ -d "${TOP}/arm-uclinuxfdpiceabi" ]; then TOOLCHAIN_PATH="${TOP}/arm-uclinuxfdpiceabi" elif [ -d "${TOP}/build/install" ]; then TOOLCHAIN_PATH="${TOP}/build/install"