From 5a70848b46dd0adaca0d77a989621d0e0b0a6928 Mon Sep 17 00:00:00 2001 From: Risheng1128 Date: Sat, 22 Oct 2022 23:05:26 +0800 Subject: [PATCH] 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. --- mk/toolchain.mk | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/mk/toolchain.mk b/mk/toolchain.mk index 61812c63..de42453b 100644 --- a/mk/toolchain.mk +++ b/mk/toolchain.mk @@ -9,24 +9,20 @@ else endif # Validate GNU Toolchain for RISC-V -CROSS_COMPILE ?= riscv32-unknown-elf- -RV32_CC = $(CROSS_COMPILE)gcc -RV32_CC := $(shell which $(RV32_CC)) -ifndef RV32_CC - # xPack GNU RISC-V Embedded GCC - CROSS_COMPILE = riscv-none-elf- - RV32_CC = $(CROSS_COMPILE)gcc - RV32_CC := $(shell which $(RV32_CC)) - ifndef RV32_CC - # DEPRECATED: Replaced by xpack-dev-tools/riscv-none-elf-gcc-xpack - CROSS_COMPILE = riscv-none-embed- - RV32_CC = $(CROSS_COMPILE)gcc - RV32_CC := $(shell which $(RV32_CC)) - ifndef RV32_CC - $(warning No GNU Toolchain for RISC-V found.) - CROSS_COMPILE := - endif - endif +TOOLCHAIN_LIST := riscv-none-elf- \ + riscv32-unknown-elf- \ + riscv64-unknown-elf- \ + riscv-none-embed- + +# TODO: add support to clang/llvm based cross compilers +VALID_TOOLCHAIN := $(foreach toolchain,$(TOOLCHAIN_LIST), \ + $(shell which $(toolchain)gcc > /dev/null) \ + $(if $(filter 0,$(.SHELLSTATUS)),$(toolchain))) + +# Get the first element in valid toolchain list +CROSS_COMPILE ?= $(word 1,$(VALID_TOOLCHAIN)) +ifeq ($(CROSS_COMPILE),) +$(warning GNU Toolchain for RISC-V is required. Please check package installation) endif export CROSS_COMPILE