#!/bin/bash ############################################################################## # Copyright (c) 2026 Eclipse ThreadX contributors # # This program and the accompanying materials are made available under the # terms of the MIT License which is available at # https://opensource.org/licenses/MIT. # # AI Disclosure: This file was largely AI-generated by Claude Code (Opus 5). # The AI-generated portions may be considered public domain (CC0-1.0) # and not subject to the project's licence. The human contributor has # reviewed and verified that the code is correct. # # SPDX-License-Identifier: MIT and CC0-1.0 ############################################################################## # Builds the ThreadX library, tx.a, for the AArch64 port this script sits in. # The AArch64 examples previously had no build driver at all and could only be # built through Arm Development Studio project files. # # ./build_threadx.sh # TOOLCHAIN=atfe ATFE_CLANG=/path/to/clang ./build_threadx.sh # # The CPU is derived from the directory this script lives in, so one script # serves every AArch64 port rather than needing one copy per core. set -eu cd "$(dirname "$(realpath "$0")")" # ports//gnu/example_build -> up two levels is -> the -mcpu name. # The same example tree is copied into the SMP ports, where the core directory # carries an _smp suffix and the kernel sources live in common_smp. core="$(basename "$(cd ../.. && pwd)")" case "${core}" in *_smp) cpu="${core%_smp}"; common="common_smp" ;; *) cpu="${core}"; common="common" ;; esac cpu="${cpu//_/-}" : "${TOOLCHAIN:=gnu}" case "${TOOLCHAIN}" in gnu) CC="aarch64-none-elf-gcc" AR="aarch64-none-elf-ar" TARGET_FLAGS="" ;; atfe) CC="${ATFE_CLANG:-clang}" case "${CC}" in */*) AR="$(dirname "${CC}")/llvm-ar" ;; *) AR="llvm-ar" ;; esac TARGET_FLAGS="--target=aarch64-none-elf" ;; *) echo "Unknown TOOLCHAIN '${TOOLCHAIN}'; expected gnu or atfe" >&2 exit 1 ;; esac CFLAGS="-g -mcpu=${cpu} -I../../../../${common}/inc -I../inc" echo "Building tx.a for ${cpu} with ${TOOLCHAIN}" rm -f tx.a ./*.o # Port sources. The SMP ports carry C sources here as well as assembly. for src in ../src/*.S ../src/*.c; do [ -f "${src}" ] || continue obj="$(basename "${src}")" "${CC}" ${TARGET_FLAGS} -c ${CFLAGS} "${src}" -o "${obj%.*}.o" done # Common ThreadX sources. tx_misra.c is deliberately excluded: it is only for # MISRA builds and has an assembly counterpart in the port. for src in ../../../../${common}/src/*.c; do case "$(basename "${src}")" in tx_misra.c) continue ;; esac "${CC}" ${TARGET_FLAGS} -c ${CFLAGS} "${src}" -o "$(basename "${src%.c}").o" done "${AR}" -rcs tx.a ./*.o rm -f ./*.o echo "Done: $(basename "$(pwd)")/tx.a"