aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Jenkins <charlie@rivosinc.com>2025-04-30 16:38:31 -0700
committerAnup Patel <anup@brainfault.org>2025-06-14 10:11:11 +0530
commit27347f0902cdf69b20786726e3827df6df089b2a (patch)
treebdc36729c703440845ce0f911035158c480565bd
parent69a0f0245f39ea3af4685cab4cb2dda90acd17cd (diff)
downloadopensbi-27347f0902cdf69b20786726e3827df6df089b2a.zip
opensbi-27347f0902cdf69b20786726e3827df6df089b2a.tar.gz
opensbi-27347f0902cdf69b20786726e3827df6df089b2a.tar.bz2
Makefile: Make $(LLVM) more flexible
Introduce a way for developers to easily switch between LLVM versions with LLVM=/path/to/llvm/ and LLVM=-version. This is a useful addition to the existing LLVM=1 variable which will select the first clang and llvm binutils available on the path. Reviewed-by: Anup Patel <anup@brainfault.org> Tested-by: Anup Patel <anup@brainfault.org> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Link: https://lore.kernel.org/r/20250430-improve_llvm_building-v1-1-caae96cc6be6@rivosinc.com Signed-off-by: Anup Patel <anup@brainfault.org>
-rw-r--r--Makefile14
-rw-r--r--README.md12
2 files changed, 22 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 85748bc..adb4862 100644
--- a/Makefile
+++ b/Makefile
@@ -104,10 +104,16 @@ endif
# Setup compilation commands
ifneq ($(LLVM),)
-CC = clang
-AR = llvm-ar
-LD = ld.lld
-OBJCOPY = llvm-objcopy
+ifneq ($(filter %/,$(LLVM)),)
+LLVM_PREFIX := $(LLVM)
+else ifneq ($(filter -%,$(LLVM)),)
+LLVM_SUFFIX := $(LLVM)
+endif
+
+CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
+AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
+LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
+OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
else
ifdef CROSS_COMPILE
CC = $(CROSS_COMPILE)gcc
diff --git a/README.md b/README.md
index 2795cc1..fd40be0 100644
--- a/README.md
+++ b/README.md
@@ -252,6 +252,18 @@ option with:
make LLVM=1
```
+To build with a specific version of LLVM, a path to a directory containing the
+LLVM tools can be provided:
+```
+make LLVM=/path/to/llvm/
+```
+
+If you have versioned llvm tools you would like to use, such as `clang-17`, the LLVM variable can
+be set as:
+```
+make LLVM=-17
+```
+
When using Clang, *CROSS_COMPILE* often does not need to be defined unless
using GNU binutils with prefixed binary names. *PLATFORM_RISCV_XLEN* will be
used to infer a default triple to pass to Clang, so if *PLATFORM_RISCV_XLEN*