Skip to content

Commit

Permalink
Makefile: fix linking on macOS with Homebrew
Browse files Browse the repository at this point in the history
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

Signed-off-by: Alexis Deruelle <alexis.deruelle@gmail.com>
  • Loading branch information
alxdrl committed Feb 1, 2025
1 parent a300ecc commit ca77118
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ?=
Expand Down

0 comments on commit ca77118

Please # to comment.