Skip to content

Commit 5c1a157

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 5c1a157

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

mk/toolchain.mk

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,14 @@ 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
30-
endif
12+
TOOLCHAIN_LIST := riscv-none-elf- \
13+
riscv32-unknown-elf- \
14+
riscv64-unknown-elf-
15+
16+
VALID_TOOLCHAIN := $(foreach toolchain,$(TOOLCHAIN_LIST), \
17+
$(shell which $(toolchain)gcc > /dev/null) \
18+
$(if $(filter 0,$(.SHELLSTATUS)),$(toolchain)))
3119

20+
# Get the first element in valid toolchain list
21+
CROSS_COMPILE := $(word 1,$(VALID_TOOLCHAIN))
3222
export CROSS_COMPILE

0 commit comments

Comments
 (0)