Skip to content

Commit 27347f0

Browse files
charlie-rivosavpatel
authored andcommitted
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 <[email protected]> Tested-by: Anup Patel <[email protected]> Signed-off-by: Charlie Jenkins <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
1 parent 69a0f02 commit 27347f0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,16 @@ endif
104104

105105
# Setup compilation commands
106106
ifneq ($(LLVM),)
107-
CC = clang
108-
AR = llvm-ar
109-
LD = ld.lld
110-
OBJCOPY = llvm-objcopy
107+
ifneq ($(filter %/,$(LLVM)),)
108+
LLVM_PREFIX := $(LLVM)
109+
else ifneq ($(filter -%,$(LLVM)),)
110+
LLVM_SUFFIX := $(LLVM)
111+
endif
112+
113+
CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
114+
AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
115+
LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
116+
OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
111117
else
112118
ifdef CROSS_COMPILE
113119
CC = $(CROSS_COMPILE)gcc

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ option with:
252252
make LLVM=1
253253
```
254254

255+
To build with a specific version of LLVM, a path to a directory containing the
256+
LLVM tools can be provided:
257+
```
258+
make LLVM=/path/to/llvm/
259+
```
260+
261+
If you have versioned llvm tools you would like to use, such as `clang-17`, the LLVM variable can
262+
be set as:
263+
```
264+
make LLVM=-17
265+
```
266+
255267
When using Clang, *CROSS_COMPILE* often does not need to be defined unless
256268
using GNU binutils with prefixed binary names. *PLATFORM_RISCV_XLEN* will be
257269
used to infer a default triple to pass to Clang, so if *PLATFORM_RISCV_XLEN*

0 commit comments

Comments
 (0)