Skip to content

Commit 16d9b79

Browse files
committed
Detect toolchain automatically
Detect toolchain automatically by creating toolchain list, and check the items in list is installed or not. If there are multiple toolchain installed, get the first item in valid toolchain list.
1 parent 40d91b0 commit 16d9b79

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

mk/riscv-arch-test.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,5 @@ $(ARCH_TEST_BUILD):
1111
git submodule update --init $(dir $@)
1212

1313
arch-test: $(BIN) $(ARCH_TEST_BUILD)
14-
ifndef CROSS_COMPILE
15-
$(error GNU Toolchain for RISC-V is required. Please check package installation)
16-
endif
1714
$(Q)$(MAKE) --quiet -C $(ARCH_TEST_DIR) clean
1815
$(Q)$(MAKE) --quiet -C $(ARCH_TEST_DIR)

mk/toolchain.mk

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,20 @@ else
99
endif
1010

1111
# Validate GNU Toolchain for RISC-V
12-
CROSS_COMPILE ?= riscv32-unknown-elf-
13-
RV32_CC = $(CROSS_COMPILE)gcc
14-
RV32_CC := $(shell which $(RV32_CC))
15-
ifndef RV32_CC
16-
# xPack GNU RISC-V Embedded GCC
17-
CROSS_COMPILE = riscv-none-elf-
18-
RV32_CC = $(CROSS_COMPILE)gcc
19-
RV32_CC := $(shell which $(RV32_CC))
20-
ifndef RV32_CC
21-
# DEPRECATED: Replaced by xpack-dev-tools/riscv-none-elf-gcc-xpack
22-
CROSS_COMPILE = riscv-none-embed-
23-
RV32_CC = $(CROSS_COMPILE)gcc
24-
RV32_CC := $(shell which $(RV32_CC))
25-
ifndef RV32_CC
26-
$(warning No GNU Toolchain for RISC-V found.)
27-
CROSS_COMPILE :=
28-
endif
29-
endif
12+
TOOLCHAIN_LIST := riscv-none-elf- \
13+
riscv32-unknown-elf- \
14+
riscv64-unknown-elf- \
15+
riscv-none-embed-
16+
17+
# TODO: add support to clang/llvm based cross compilers
18+
VALID_TOOLCHAIN := $(foreach toolchain,$(TOOLCHAIN_LIST), \
19+
$(shell which $(toolchain)gcc > /dev/null) \
20+
$(if $(filter 0,$(.SHELLSTATUS)),$(toolchain)))
21+
22+
# Get the first element in valid toolchain list
23+
CROSS_COMPILE = $(word 1,$(VALID_TOOLCHAIN))
24+
ifeq ($(CROSS_COMPILE),)
25+
$(error GNU Toolchain for RISC-V is required. Please check package installation)
3026
endif
3127

3228
export CROSS_COMPILE

0 commit comments

Comments
 (0)