fix: select medany toolchain and available GDB

This commit is contained in:
2026-07-29 00:16:57 +03:00
parent 9b0828dbaa
commit a6bb080270
4 changed files with 44 additions and 11 deletions
+15 -4
View File
@@ -21,23 +21,32 @@ VIVADO ?= $(lastword $(sort $(wildcard /tools/Xilinx/*/Vivado/bin/vivado) $(shel
# TOOLCHAIN keeps compatibility with the existing software Makefiles.
RISCV_TOOLCHAIN ?=
_RISCV_SEARCH_DIRS := \
$(if $(strip $(RISCV_TOOLCHAIN)),$(RISCV_TOOLCHAIN) $(RISCV_TOOLCHAIN)/bin) \
$(TOOLCHAIN) \
$(RISCV_TOOLCHAIN) \
$(RISCV_TOOLCHAIN)/bin \
$(PROJECT_TOOLS_DIR)/riscv/bin \
/tools/toolchains-medany/bin \
/tools/toolchains/rvtc-medany/bin \
/tools/toolchain/bin \
/tools/toolchains/bin \
/tools/toolchains/rvtc-medany/bin
/tools/toolchains/bin
_RISCV_GCC := $(firstword \
$(foreach d,$(_RISCV_SEARCH_DIRS),$(wildcard $(d)/riscv64-unknown-elf-gcc)) \
$(foreach d,$(_RISCV_SEARCH_DIRS),$(wildcard $(d)/riscv64-none-elf-gcc)) \
$(shell command -v riscv64-unknown-elf-gcc 2>/dev/null) \
$(shell command -v riscv64-none-elf-gcc 2>/dev/null))
# An explicit RISCV_TOOLCHAIN is authoritative, including over an old
# TOOLCHAIN/RISCV_PREFIX inherited from the shell. Without override, Make's
# environment-variable semantics leave CROSS pointing at the stale toolchain
# even though _RISCV_GCC was found in RISCV_TOOLCHAIN.
ifneq ($(strip $(RISCV_TOOLCHAIN)),)
override TOOLCHAIN := $(patsubst %/,%,$(dir $(_RISCV_GCC)))
override RISCV_PREFIX := $(if $(_RISCV_GCC),$(patsubst %-gcc,%-,$(notdir $(_RISCV_GCC))),riscv64-unknown-elf-)
override CROSS := $(if $(strip $(TOOLCHAIN)),$(TOOLCHAIN)/)$(RISCV_PREFIX)
else
TOOLCHAIN ?= $(patsubst %/,%,$(dir $(_RISCV_GCC)))
RISCV_PREFIX ?= $(if $(_RISCV_GCC),$(patsubst %-gcc,%-,$(notdir $(_RISCV_GCC))),riscv64-unknown-elf-)
CROSS ?= $(if $(strip $(TOOLCHAIN)),$(TOOLCHAIN)/)$(RISCV_PREFIX)
endif
# Some compiler-only toolchains (notably rvtc-medany) do not ship GDB. Keep
# using the selected compiler toolchain, but fall back to the full local
@@ -45,6 +54,8 @@ CROSS ?= $(if $(strip $(TOOLCHAIN)),$(TOOLCHAIN)/)$(RISCV_PREFIX)
_RISCV_GDB := $(firstword \
$(wildcard $(TOOLCHAIN)/$(RISCV_PREFIX)gdb) \
$(wildcard /tools/toolchains/tc/toolchain/bin/$(RISCV_PREFIX)gdb) \
$(wildcard /tools/toolchain/bin/$(RISCV_PREFIX)gdb) \
$(lastword $(sort $(wildcard /tools/Xilinx/*/gnu/riscv/lin/bin/$(RISCV_PREFIX)gdb))) \
$(shell command -v $(RISCV_PREFIX)gdb 2>/dev/null))
GDB ?= $(if $(_RISCV_GDB),$(_RISCV_GDB),$(CROSS)gdb)