From 631cbc07d0749318c072010a35ffd981347e59d9 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 26 Dec 2023 17:45:53 -0500 Subject: [PATCH] Simplify Scripts --- scripts/build.sh | 63 ++++++++++++++++-------------------- scripts/setup.sh | 84 ++++++++++++++++++++++-------------------------- 2 files changed, 67 insertions(+), 80 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index e166ddf9..2c713f11 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,42 +2,35 @@ set -e -# Build -build() { - # Use Build Dir - if [ ! -f "build/${MODE}-${ARCH}/arm/build.ninja" ] || [ ! -f "build/${MODE}-${ARCH}/native/build.ninja" ]; then - # Run CMake - ./scripts/setup.sh "${MODE}" "${ARCH}" - fi - cd "build/${MODE}-${ARCH}" - - # Create Prefix - if [ -z "${DESTDIR+x}" ]; then - export DESTDIR="$(cd ../../; pwd)/out/${MODE}-${ARCH}" - rm -rf "${DESTDIR}" - mkdir -p "${DESTDIR}" - fi - - # Build ARM Components - cd arm - cmake --build . - cmake --install . - cd ../ - - # Build Native Components - cd native - cmake --build . - cmake --install . - cd ../ - - # Exit - cd ../../ -} - # Variables MODE="$(echo "$1" | tr '[:upper:]' '[:lower:]')" ARCH="$(echo "$2" | tr '[:upper:]' '[:lower:]')" -shift 2 -# Build -build "${MODE}" "${ARCH}" +# Run CMake If Needed +if [ ! -f "build/${MODE}-${ARCH}/arm/build.ninja" ] || [ ! -f "build/${MODE}-${ARCH}/native/build.ninja" ]; then + ./scripts/setup.sh "${MODE}" "${ARCH}" +fi +# Use Build Dir +cd "build/${MODE}-${ARCH}" + +# Create Prefix +if [ -z "${DESTDIR+x}" ]; then + export DESTDIR="$(cd ../../; pwd)/out/${MODE}-${ARCH}" + rm -rf "${DESTDIR}" + mkdir -p "${DESTDIR}" +fi + +# Build ARM Components +cd arm +cmake --build . +cmake --install . +cd ../ + +# Build Native Components +cd native +cmake --build . +cmake --install . +cd ../ + +# Exit +cd ../../ diff --git a/scripts/setup.sh b/scripts/setup.sh index 4d8a0112..33f9f24a 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -5,49 +5,6 @@ set -e # ARM Toolchain File ARM_TOOLCHAIN_FILE="$(pwd)/cmake/toolchain/armhf-toolchain.cmake" -# Setup -setup() { - # Find Toolchain - toolchain_file="$(pwd)/cmake/toolchain/${ARCH}-toolchain.cmake" - if [ ! -f "${toolchain_file}" ]; then - echo "Invalid Architecture: ${ARCH}" > /dev/stderr - exit 1 - fi - - # Create Build Dir - rm -rf "build/${MODE}-${ARCH}" - mkdir -p "build/${MODE}-${ARCH}" - cd "build/${MODE}-${ARCH}" - - # Server Build - server_mode='OFF' - if [ "${MODE}" = "server" ]; then - server_mode='ON' - fi - # Mixed Build - mixed_build='ON' - if [ "${ARCH}" = "armhf" ]; then - mixed_build='OFF' - fi - # Extra Flags - extra_flags="-DMCPI_IS_MIXED_BUILD=${mixed_build} -DMCPI_SERVER_MODE=${server_mode}" - - # Build ARM Components - mkdir arm - cd arm - cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=arm ${extra_flags} "$@" ../../.. - cd ../ - - # Build Native Components - mkdir native - cd native - cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" -DMCPI_BUILD_MODE=native ${extra_flags} "$@" ../../.. - cd ../ - - # Exit - cd ../../ -} - # Variables MODE="$(echo "$1" | tr '[:upper:]' '[:lower:]')" ARCH="$(echo "$2" | tr '[:upper:]' '[:lower:]')" @@ -59,5 +16,42 @@ if [ "${MODE}" != "client" ] && [ "${MODE}" != "server" ]; then exit 1 fi -# Setup -setup "$@" +# Find Toolchain +toolchain_file="$(pwd)/cmake/toolchain/${ARCH}-toolchain.cmake" +if [ ! -f "${toolchain_file}" ]; then + echo "Invalid Architecture: ${ARCH}" > /dev/stderr + exit 1 +fi + +# Create Build Dir +rm -rf "build/${MODE}-${ARCH}" +mkdir -p "build/${MODE}-${ARCH}" +cd "build/${MODE}-${ARCH}" + +# Server Build +server_mode='OFF' +if [ "${MODE}" = "server" ]; then + server_mode='ON' +fi +# Mixed Build +mixed_build='ON' +if [ "${ARCH}" = "armhf" ]; then + mixed_build='OFF' +fi +# Extra Flags +extra_flags="-DMCPI_IS_MIXED_BUILD=${mixed_build} -DMCPI_SERVER_MODE=${server_mode}" + +# Build ARM Components +mkdir arm +cd arm +cmake -GNinja -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=arm ${extra_flags} "$@" ../../.. +cd ../ + +# Build Native Components +mkdir native +cd native +cmake -GNinja -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" -DMCPI_BUILD_MODE=native ${extra_flags} "$@" ../../.. +cd ../ + +# Exit +cd ../../