Add TOOLCHAIN{,_PREFIX} make options

This commit is contained in:
Mintsuki 2025-07-08 15:11:00 +02:00
parent 0ea88ff820
commit f377341e3f
No known key found for this signature in database
GPG key ID: 1F3C021BECA23821
2 changed files with 34 additions and 2 deletions

View file

@ -12,6 +12,19 @@ It is recommended to build this project using a standard UNIX-like system, using
Additionally, building an ISO with `make all` requires `xorriso`, and building a HDD/USB image with `make all-hdd` requires `sgdisk` (usually from `gdisk` or `gptfdisk` packages) and `mtools`.
### Toolchain selection
The `TOOLCHAIN` and `TOOLCHAIN_PREFIX` `make` variables can be used to set the toolchain. `TOOLCHAIN` can be set to `llvm` to use Clang/LLVM.
For example:
```
make TOOLCHAIN=llvm
```
or:
```
make TOOLCHAIN_PREFIX=x86_64-elf-
```
### Architectural targets
The `ARCH` make variable determines the target architecture to build the kernel and image for.

View file

@ -17,11 +17,30 @@ ifeq ($(filter $(ARCH),aarch64 loongarch64 riscv64 x86_64),)
$(error Architecture $(ARCH) not supported)
endif
# User controllable toolchain and toolchain prefix.
TOOLCHAIN :=
TOOLCHAIN_PREFIX :=
ifneq ($(TOOLCHAIN),)
ifeq ($(TOOLCHAIN_PREFIX),)
TOOLCHAIN_PREFIX := $(TOOLCHAIN)-
endif
endif
# User controllable C compiler command.
CC := cc
ifneq ($(TOOLCHAIN_PREFIX),)
CC := $(TOOLCHAIN_PREFIX)gcc
else
CC := cc
endif
# User controllable linker command.
LD := ld
LD := $(TOOLCHAIN_PREFIX)ld
# Defaults overrides for variables if using "llvm" as toolchain.
ifeq ($(TOOLCHAIN),llvm)
CC := clang
LD := ld.lld
endif
# User controllable C flags.
CFLAGS := -g -O2 -pipe