From 25f0a1fff7fd7e416850466be9187f4ee835e3fd Mon Sep 17 00:00:00 2001 From: Alexis Deruelle Date: Sat, 1 Feb 2025 17:07:14 +0100 Subject: [PATCH] Makefile: fix linking on macOS with Homebrew On macOS with current version of Homebrew clang and ld.lld comes from separate packages, the assumptions for the linker path does not hold anymore and the linking fails. Fix by using distinct variables in Makefile for clang and ld.lld: - TOOLCHAIN: remove the check for `uname -p` and use `brew --prefix` output instead of hardcoded path - add a LLDDIR variable to allow for specific ld.ldd location - LLDDIR: use TOOLCHAIN value if ld.lld is found there, use the output of `brew --prefix lld` otherwise - LD: use LLDIR instead of TOOLCHAIN Fixes: #431 # Veuillez saisir le message de validation pour vos --- Makefile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b10362ab1..a34d72fdb 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,12 @@ RUSTARCH ?= aarch64-unknown-none-softfloat ifeq ($(shell uname),Darwin) USE_CLANG ?= 1 $(info INFO: Building on Darwin) -ifeq ($(shell uname -p),arm) -TOOLCHAIN ?= /opt/homebrew/opt/llvm/bin/ +BREW ?= $(shell command -v brew) +TOOLCHAIN ?= $(shell $(BREW) --prefix llvm)/bin/ +ifeq ($(shell ls $(TOOLCHAIN)/ld.lld 2>/dev/null),) +LLDDIR ?= $(shell $(BREW) --prefix lld)/bin/ else -TOOLCHAIN ?= /usr/local/opt/llvm/bin/ +LLDDIR ?= $(TOOLCHAIN) endif $(info INFO: Toolchain path: $(TOOLCHAIN)) endif @@ -17,10 +19,14 @@ else ARCH ?= aarch64-linux-gnu- endif +ifneq ($(TOOLCHAIN),$(LLDDIR)) +$(info INFO: LLD path: $(LLDDIR)) +endif + ifeq ($(USE_CLANG),1) CC := $(TOOLCHAIN)clang --target=$(ARCH) AS := $(TOOLCHAIN)clang --target=$(ARCH) -LD := $(TOOLCHAIN)ld.lld +LD := $(LLDDIR)ld.lld OBJCOPY := $(TOOLCHAIN)llvm-objcopy CLANG_FORMAT ?= $(TOOLCHAIN)clang-format EXTRA_CFLAGS ?=