2018-04-16 19:03:33 +02:00
|
|
|
# Target architecture for the build.
|
2020-09-07 22:21:42 +02:00
|
|
|
|
2020-11-06 09:54:45 +01:00
|
|
|
# The correct triple for 32 bit embedded RISC-V targets is "riscv32-none-elf".
|
|
|
|
# However, is unknown is used as sys (in place of none), it will also fall back
|
|
|
|
# to none. Finally, if the GCC RISC-V cross compiler is compiled with full
|
|
|
|
# multilib support, it can create both 32 bit and 64 bit binaries. Often this is
|
|
|
|
# indicated with "riscv" being used instead of "riscv32/riscv64", but e.g.
|
|
|
|
# Ubuntu uses "riscv64-unknown-elf" despite being able to produce both 32 and
|
|
|
|
# 64 bit binaries. We'll test all possible combinations from the most correct
|
|
|
|
# triple to the least correct triple all that might be able to produce our
|
|
|
|
# binaries. Finally, "riscv-none-embed" is also tested for compatibility with
|
|
|
|
# an previously popular legacy toolchain.
|
|
|
|
|
|
|
|
_TRIPLES_TO_TEST := \
|
|
|
|
riscv32-none-elf \
|
|
|
|
riscv-none-elf \
|
|
|
|
riscv32-unknown-elf \
|
|
|
|
riscv-unknown-elf \
|
|
|
|
riscv64-none-elf \
|
|
|
|
riscv64-unknown-elf \
|
|
|
|
riscv-none-embed
|
|
|
|
|
|
|
|
TARGET_ARCH_RISCV ?= \
|
|
|
|
$(strip \
|
|
|
|
$(subst -gcc,,\
|
|
|
|
$(notdir \
|
|
|
|
$(word 1,\
|
2021-09-03 11:27:03 +02:00
|
|
|
$(foreach triple,$(_TRIPLES_TO_TEST),$(shell which $(triple)-gcc 2> /dev/null))))))
|
2020-09-07 22:21:42 +02:00
|
|
|
|
2020-09-08 22:28:41 +02:00
|
|
|
TARGET_ARCH ?= $(TARGET_ARCH_RISCV)
|
2018-04-16 19:03:33 +02:00
|
|
|
|
|
|
|
# define build specific options
|
2020-10-07 09:37:52 +02:00
|
|
|
CFLAGS_CPU = -march=rv32imac -mabi=ilp32
|
|
|
|
ifeq ($(TOOLCHAIN),llvm)
|
|
|
|
# Always use riscv32-none-elf as target triple for clang, as some
|
|
|
|
# autodetected gcc target triples are incompatible with clang
|
|
|
|
TARGET_ARCH_LLVM := riscv32-none-elf
|
|
|
|
else
|
|
|
|
CFLAGS_CPU += -mcmodel=medlow -msmall-data-limit=8
|
2021-02-09 10:45:51 +01:00
|
|
|
ifneq (,$(shell $(TARGET_ARCH)-gcc --help=target | grep '\-malign-data='))
|
|
|
|
CFLAGS_CPU += -malign-data=natural
|
|
|
|
endif
|
2020-10-07 09:37:52 +02:00
|
|
|
endif
|
|
|
|
CFLAGS_LINK = -ffunction-sections -fdata-sections
|
2019-10-21 11:27:21 +02:00
|
|
|
CFLAGS_DBG ?= -g3
|
|
|
|
CFLAGS_OPT ?= -Os
|
2018-04-16 19:03:33 +02:00
|
|
|
|
2020-09-09 21:37:15 +02:00
|
|
|
LINKFLAGS += -L$(RIOTCPU)/$(CPU)/ldscripts -L$(RIOTCPU)/riscv_common/ldscripts
|
2020-01-02 09:51:20 +01:00
|
|
|
LINKER_SCRIPT ?= $(CPU_MODEL).ld
|
|
|
|
LINKFLAGS += -T$(LINKER_SCRIPT)
|
2018-04-16 19:03:33 +02:00
|
|
|
|
2019-08-27 16:06:41 +02:00
|
|
|
CFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) $(CFLAGS_LINK)
|
|
|
|
ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG)
|
2018-04-16 19:03:33 +02:00
|
|
|
# export linker flags
|
2020-10-07 09:37:52 +02:00
|
|
|
LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) -nostartfiles -Wl,--gc-sections -static -lgcc
|