From 962bfb6ce228092ec44791b1421aa4525fd46469 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 2 Jun 2025 08:42:18 +1200 Subject: [PATCH] 'Generic Commit' --- src/dropshell-build | 56 +++++++++++++++++++++++++++++++-------------- test.sh | 2 +- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/dropshell-build b/src/dropshell-build index f86f9a4..33b6500 100755 --- a/src/dropshell-build +++ b/src/dropshell-build @@ -4,17 +4,13 @@ set -euo pipefail # SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -ARCHS=( - "x86_64" - "aarch64" -) - HOSTARCH=$(uname -m) # set flags from command line RELEASE=0 MULTIBUILD=0 +MUSL_ROOT_PATH="${HOME}/.musl-cross" function help() { echo "Usage: $0 [options]" @@ -57,15 +53,22 @@ function centerlittletitle() { function set_current_arch() { local FULLARCH="$1" # e.g. aarch64-linux-musl-cross - # split on - + # ARCH=aarch64 + # ARCH_OS=linux-musl-cross + # ARCH_FULL_PREFIX=aarch64-linux-musl-cross + # ARCH_SHORT_PREFIX=aarch64-linux-musl + # MUSL_PATH=/home/jde/.musl-cross/aarch64-linux-musl-cross + # arch should just be x86_64 or aarch64 + export ARCH="${FULLARCH%%-*}" export ARCH_OS="${FULLARCH#*-}" - export ARCH_PREFIX="${ARCH}-${OS}" - export ARCH="${FULLARCH%-*}" - export MUSL_PATH="${HOME}/.musl-cross/${FULLARCH}" + export ARCH_FULL_PREFIX="${FULLARCH}" + export ARCH_SHORT_PREFIX="${FULLARCH%-*}" + export MUSL_PATH="${MUSL_ROOT_PATH}/${FULLARCH}" echo "ARCH: ${ARCH}" echo "ARCH_OS: ${ARCH_OS}" - echo "ARCH_PREFIX: ${ARCH_PREFIX}" + echo "ARCH_FULL_PREFIX: ${ARCH_FULL_PREFIX}" + echo "ARCH_SHORT_PREFIX: ${ARCH_SHORT_PREFIX}" echo "MUSL_PATH: ${MUSL_PATH}" } @@ -90,8 +93,9 @@ function build_arch() { echo "Building for ${ARCH} in ${ARCH_BUILD_DIR}" - if [ ! -f "${HOME}/.musl-cross/${ARCH}-linux-musl-cross/bin/${ARCH}-linux-musl-g++" ]; then - echo "Musl cross toolchain not found for ${ARCH}." + if [ ! -f "${MUSL_PATH}/bin/${ARCH_SHORT_PREFIX}-g++" ]; then + echo "Musl cross toolchain not found for ${ARCH}" + echo "Missing file: ${MUSL_PATH}/bin/${ARCH_SHORT_PREFIX}-g++" exit 1 fi @@ -100,8 +104,8 @@ function build_arch() { CMAKE_BUILD_TYPE="Debug" fi - export CC="${MUSL_PATH}/bin/${ARCH_PREFIX}-gcc" - export CXX="${MUSL_PATH}/bin/${ARCH_PREFIX}-g++" + export CC="${MUSL_PATH}/bin/${ARCH_SHORT_PREFIX}-gcc" + export CXX="${MUSL_PATH}/bin/${ARCH_SHORT_PREFIX}-g++" export SYSROOT="${MUSL_PATH}/${ARCH_OS}/sysroot" export OPENSSL_ROOT_DIR="${SYSROOT}/usr" @@ -157,9 +161,27 @@ function build() { # if have the -m option, then build for multiple architectures if [ $MULTIBUILD -eq 1 ]; then - for arch in "${ARCHS[@]}"; do - set_current_arch "$arch" - build_arch "$CMAKE_DIR" + # get all the architectures from the musl-cross-make directory + local musl_toolchains + mapfile -t musl_toolchains < <(ls -d "${MUSL_ROOT_PATH}/"*) + + for tchain in "${musl_toolchains[@]}"; do + local arch="${tchain##*/}" + local buildthis="false" + if [[ "$arch" = "$HOSTARCH"* && "$arch" == *-native ]]; then + # Native toolchain for host arch + buildthis="true" + elif [[ "$arch" != "$HOSTARCH"* && "$arch" != *-native ]]; then + # Cross toolchain for non-host arch + buildthis="true" + fi + if [ "$buildthis" = "true" ]; then + echo "Building for $arch with $tchain" + set_current_arch "$arch" + build_arch "$CMAKE_DIR" + else + echo "Skipping $tchain" + fi done else set_current_arch "$HOSTARCH-linux-musl-native" diff --git a/test.sh b/test.sh index d61e357..e71fec0 100755 --- a/test.sh +++ b/test.sh @@ -6,7 +6,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" echo "Testing dropshell-build" -DROPSHELL_BUILD_TAG="test" "${SCRIPT_DIR}/src/dropshell-build" "${SCRIPT_DIR}/ipdemo" +DROPSHELL_BUILD_TAG="test" "${SCRIPT_DIR}/src/dropshell-build" -r -m "${SCRIPT_DIR}/ipdemo" "${SCRIPT_DIR}/ipdemo/output/ipdemo.x86_64"