summaryrefslogtreecommitdiff
path: root/ports/arm9/gnu/example_build/build_threadx_sample.sh
blob: d9339bc071c1ce041e4263e0c68b4d19bcacf7d3 (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
#!/bin/bash
##############################################################################
# Copyright (c) 2024 Microsoft Corporation
# 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.
#
# SPDX-License-Identifier: MIT
#
# AI Disclosure: This file was largely AI-generated by Copilot (Claude Sonnet 4.6).
# Portions of this file were generated with AI assistance.
# 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
##############################################################################

set -e
cd "$(dirname "$0")"

# Toolchain selection. The default is the GNU toolchain, so an existing
# invocation of this script behaves exactly as before. Set TOOLCHAIN=atfe to
# build with Arm Toolchain for Embedded, which is LLVM based and is the
# successor to Arm Compiler 6:
#
#     TOOLCHAIN=atfe ATFE_CLANG=/path/to/clang ./build_threadx_sample.sh
#
: "${TOOLCHAIN:=gnu}"
case "${TOOLCHAIN}" in
    gnu)
        CC="arm-none-eabi-gcc"
        AR="arm-none-eabi-ar"
        TARGET_FLAGS=""
        ENTRY_FLAG="-ereset_handler"
        SYSCALL_LIB="--specs=nosys.specs"
        ;;
    atfe)
        CC="${ATFE_CLANG:-clang}"
        # llvm-ar ships beside clang in the toolchain.
        case "${CC}" in
            */*) AR="$(dirname "${CC}")/llvm-ar" ;;
            *)   AR="llvm-ar" ;;
        esac
        TARGET_FLAGS="--target=arm-none-eabi"
        ENTRY_FLAG="-Wl,--entry=reset_handler"
        # picolibc leaves _exit to the application; the toolchain's own
        # semihosting library supplies it, which suits an example that runs on
        # a model.
        SYSCALL_LIB="-lsemihost"
        ;;
    *)
        echo "Unknown TOOLCHAIN '${TOOLCHAIN}'; expected gnu or atfe" >&2
        exit 1
        ;;
esac

"${CC}" ${TARGET_FLAGS} -c -g -mcpu=arm9 reset.S
"${CC}" ${TARGET_FLAGS} -c -g -mcpu=arm9 crt0.S
"${CC}" ${TARGET_FLAGS} -c -g -mcpu=arm9 tx_initialize_low_level.S
"${CC}" ${TARGET_FLAGS} -c -g -mcpu=arm9 -I../../../../common/inc -I../inc sample_threadx.c
"${CC}" ${TARGET_FLAGS} -g -nostartfiles -mcpu=arm9 -T sample_threadx.ld ${SYSCALL_LIB} -o sample_threadx.out -Wl,-Map=sample_threadx.map reset.o crt0.o tx_initialize_low_level.o sample_threadx.o tx.a