summaryrefslogtreecommitdiff
path: root/ports/cortex_a76/gnu/example_build/build_threadx.sh
blob: b3b2cd36175af58350274bfd9c8eb0eccd56d872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/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/<core>/gnu/example_build -> up two levels is <core> -> 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"