Skip to content

Commit 845dc00

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 845dc00

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

mk/toolchain.mk

+14-18
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)