summaryrefslogtreecommitdiff
path: root/makefile
diff options
context:
space:
mode:
Diffstat (limited to 'makefile')
-rw-r--r--makefile79
1 files changed, 49 insertions, 30 deletions
diff --git a/makefile b/makefile
index a99129e9..b3aed7d6 100644
--- a/makefile
+++ b/makefile
@@ -12,28 +12,6 @@ this-makefile = $(lastword $(MAKEFILE_LIST))
srctree = $(realpath $(dir $(this-makefile)))
.DEFAULT_GOAL := all
-LLVM ?= 1
-ifneq ($(LLVM),1)
- ifneq ($(filter %/,$(LLVM)),)
- LLVM_PREFIX = $(LLVM)
- else ifneq ($(filter -%,$(LLVM)),)
- LLVM_SUFFIX = $(LLVM)
- endif
-endif
-
-# Variables
-ifeq ($(LLVM),1)
- CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
- LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
- AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
- STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
-else
- CC = $(CROSS_COMPILE)gcc
- LD = $(CROSS_COMPILE)ld
- AR = $(CROSS_COMPILE)ar
- STRIP = $(CROSS_COMPILE)strip
-endif
-
ifndef ARCH
ARCH := x86_64
endif
@@ -65,7 +43,25 @@ KCONFIG_CONFIG ?= .config
-include ${KCONFIG_CONFIG}
-# CFLAGS
+ifneq ($(CONFIG_LLVM),1)
+ ifneq ($(filter %/,$(LLVM)),)
+ LLVM_PREFIX = $(LLVM)
+ else ifneq ($(filter -%,$(LLVM)),)
+ LLVM_SUFFIX = $(LLVM)
+ endif
+endif
+
+ifeq ($(CONFIG_LLVM),1)
+ CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
+ LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
+ AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
+ STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
+else
+ CC = $(CROSS_COMPILE)gcc
+ LD = $(CROSS_COMPILE)ld
+ AR = $(CROSS_COMPILE)ar
+ STRIP = $(CROSS_COMPILE)strip
+endif
KBUILD_CFLAGS := -x c
@@ -99,9 +95,9 @@ endif
KBUILD_LDFLAGS :=
KBUILD_ASFLAGS :=
ifeq ($(CONFIG_DEBUG),y)
-KBUILD_CFLAGS += -g -O0 -fno-omit-frame-pointer -fno-stack-protector
+KBUILD_CFLAGS += -g
else
-KBUILD_CFLAGS += -O2 -fdata-sections -ffunction-sections
+KBUILD_CFLAGS += -fdata-sections -ffunction-sections
KBUILD_CFLAGS += -fno-unwind-tables -fomit-frame-pointer
KBUILD_CFLAGS += -flto
@@ -121,21 +117,41 @@ KBUILD_ASFLAGS += -target $(ARCH)-linux-eabi
KBUILD_ASFLAGS += -I$(srctree)/include
KUILD_ASFLAGS += -I$(srctree)/include/arch/$(ARCH)
+ifdef CONFIG_OPTIMIZATION_LEVEL_O0
+KBUILD_CFLAGS += -O0
+else ifdef CONFIG_OPTIMIZATION_LEVEL_G
+KBUILD_CFLAGS += -Og
+else ifdef CONFIG_OPTIMIZATION_LEVEL_O1
+KBUILD_CFLAGS += -O1
+else ifdef CONFIG_OPTIMIZATION_LEVEL_O2
+KBUILD_CFLAGS += -O2
+else ifdef CONFIG_OPTIMIZATION_LEVEL_O3
+KBUILD_CFLAGS += -O3
+else ifdef CONFIG_OPTIMIZATION_LEVEL_Os
+KBUILD_CFLAGS += -Os
+else ifdef CONFIG_OPTIMIZATION_LEVEL_Oz
+KBUILD_CFLAGS += -Oz
+else ifdef CONFIG_OPTIMIZATION_LEVEL_FAST
+KBUILD_CFLAGS += -Ofast
+endif
+
PHONY :=
export Q srctree MAKEFLAGS KCONFIG_CONFIG \
KBUILD_CFLAGS KBUILD_ASFLAGS KBUILD_LDFLAGS
PHONY += install
-all: compile_commands.json
+all:
$(Q)$(MAKE) -f scripts/makefile.build obj=$(obj)
PHONY += install
install: all
$(Q)$(MAKE) -f scripts/makefile.build obj=$(obj) install
+ifdef CONFIG_LIB_LIBC_HEADERS
mkdir -p $(O)/usr
cp -r $(srctree)/include $(O)/usr/
rm -rf $(O)/usr/include/arch $(O)/usr/include/generated ${O}/usr/include/config
+endif
PHONY += clean
clean:
@@ -162,13 +178,16 @@ PHONY += help
help:
@echo "Available make targets:"
@echo " all - Build the project (default)"
- @echo " install - Install the built files"
+ @echo " clang-format - Format source files using clang-format"
+ @echo " clang-tidy - Run clang-tidy on the source files"
@echo " clean - Clean build files"
@echo " distclean - Clean all generated files"
- @echo " menuconfig - Launch the menu-based configuration tool"
@echo " include-what-you-use - Run include-what-you-use on the source files"
- @echo " clang-tidy - Run clang-tidy on the source files"
- @echo " clang-format - Format source files using clang-format"
+ @echo " install - Install the built files"
+ @echo " menuconfig - Launch the menu-based configuration tool"
+ @echo "Flags:"
+ @echo " o=<dir>/ - Destination directory"
+ @echo " obj=<dir>/ - Build single target"
compile_commands.json:
$(Q)bear -- $(MAKE) -f scripts/makefile.build obj=$(obj) all