diff options
| -rw-r--r-- | .github/FUNDING.yml | 1 | ||||
| -rw-r--r-- | Kconfig | 96 | ||||
| -rw-r--r-- | bin/Kbuild | 24 | ||||
| -rw-r--r-- | bin/Kconfig | 21 | ||||
| -rw-r--r-- | bin/clear/Kbuild | 1 | ||||
| -rw-r--r-- | bin/echo/Kbuild | 1 | ||||
| -rw-r--r-- | bin/false/Kbuild | 2 | ||||
| -rw-r--r-- | boot/Kbuild | 2 | ||||
| -rw-r--r-- | boot/Kconfig | 8 | ||||
| -rw-r--r-- | lib/Kbuild | 4 | ||||
| -rw-r--r-- | lib/Kconfig | 24 | ||||
| -rw-r--r-- | lib/libc/Kbuild | 3 | ||||
| -rw-r--r-- | lib/libm/Kbuild | 3 | ||||
| -rw-r--r-- | makefile | 79 | ||||
| -rw-r--r-- | scripts/makefile.build | 63 |
15 files changed, 242 insertions, 90 deletions
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..ce0ab007 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +buy_me_a_coffee: fiedorowico @@ -1,15 +1,111 @@ mainmenu "Openlinux Configuration" +config MODULES + bool + modules + default y + menu "General Setup" + choice + prompt "Select target architecture" + default ARCH_X86_64 + + config ARCH_X86_64 + bool "x86_64" + help + Target the x86_64 architecture. + + # config ARCH_AARCH64 + # bool "aarch64" + # help + # Target the ARM 64-bit architecture. + + endchoice + + config LLVM + bool "Use LLVM/Clang toolchain" + default y + help + Select this option to use the LLVM/Clang toolchain + for building the system instead of GCC. + config WERROR + default n bool "Compile the system with -Werror" help If you select this option, all compiler warnings will be treated as errors. config DEBUG bool "Enable Debugging Features" + default y help Enable this option to include debugging symbols and additional debug information in the build. + + choice + prompt "Compiler optimization level" + default OPTIMIZATION_LEVEL_G + + + config OPTIMIZATION_LEVEL_O0 + bool "No optimization (-O0)" + help + Compile the system without any optimization. + This is useful for debugging but results in + slower binaries. + + config OPTIMIZATION_LEVEL_G + bool "Optimize for debugging (-Og)" + help + Compile the system with optimizations that + are compatible with debugging, providing a + balance between performance and debuggability. + + config OPTIMIZATION_LEVEL_O1 + bool "Optimize for size and speed (-O1)" + help + Compile the system with basic optimizations + that improve performance without significantly + increasing compile time. + + config OPTIMIZATION_LEVEL_O2 + bool "Optimize for speed (-O2)" + help + Compile the system with optimizations that + improve execution speed. This is a good + balance between performance and compile time. + + config OPTIMIZATION_LEVEL_O3 + bool "Optimize for maximum speed (-O3)" + help + Compile the system with aggressive optimizations + that maximize execution speed, potentially at + the cost of longer compile times and larger binaries. + + config OPTIMIZATION_LEVEL_S + bool "Optimize for size (-Os)" + help + Compile the system with optimizations that + reduce binary size, which is useful for + resource-constrained environments. + + config OPTIMIZATION_LEVEL_Z + bool "Optimize for minimum size (-Oz)" + help + Compile the system with optimizations that + focus on minimizing binary size as much as + possible, often at the expense of performance. + + config OPTIMIZATION_LEVEL_FAST + bool "Optimize for maximum speed (Ofast)" + depends on LLVM + help + Compile the system with aggressive optimizations + that may violate strict standards compliance + to achieve the highest possible performance. + endchoice + endmenu +source "boot/Kconfig" +source "lib/Kconfig" source "bin/Kconfig" @@ -1,13 +1,11 @@ -obj-y += playground/ - -obj-y += basename/ -obj-y += clear/ -obj-y += echo/ -obj-y += false/ -obj-y += free/ -obj-y += gzip/ -obj-y += pwd/ -obj-y += sleep/ -obj-y += sync/ -obj-y += true/ -obj-y += yes/ +obj-$(CONFIG_BIN_BASENAME) += basename/ +obj-$(CONFIG_BIN_CLEAR) += clear/ +obj-$(CONFIG_BIN_ECHO) += echo/ +obj-$(CONFIG_BIN_FALSE) += false/ +obj-$(CONFIG_BIN_FREE) += free/ +obj-$(CONFIG_BIN_GZIP) += gzip/ +obj-$(CONFIG_BIN_PWD) += pwd/ +obj-$(CONFIG_BIN_SLEEP) += sleep/ +obj-$(CONFIG_BIN_SYNC) += sync/ +obj-$(CONFIG_BIN_TRUE) += true/ +obj-$(CONFIG_BIN_YES) += yes/ diff --git a/bin/Kconfig b/bin/Kconfig index 0dcab22e..67e4e63d 100644 --- a/bin/Kconfig +++ b/bin/Kconfig @@ -1,46 +1,51 @@ # bin/Kconfig -menu "Binary Utilities Configuration" +menu "Command-line tools" + config BIN_CLEAR bool "clear" default y + depends on LIB_LIBC help - Enable the 'clear' command to clear the terminal screen. + Build/Add the 'clear' command to clear the terminal screen. config BIN_ECHO bool "echo" default y + depends on LIB_LIBC help - Enable the 'echo' command to display a line of text. + Build/Add the 'echo' command to display a line of text. config BIN_FALSE bool "false" default y help - Enable the 'false' command which returns a non-zero exit status. + Build/Add the 'false' command which returns a non-zero exit status. config BIN_FREE bool "free" default y + depends on LIB_LIBC help - Enable the 'free' command to display memory usage. + Build/Add the 'free' command to display memory usage. config BIN_GZIP bool "gzip" default n + depends on LIB_LIBC && LIB_LIBM help - Enable the 'gzip' command to compress files using the gzip algorithm. + Build/Add the 'gzip' command to compress files using the gzip algorithm. config BIN_SYNC bool "sync" default y help - Enable the 'sync' command to flush filesystem buffers. + Build/Add the 'sync' command to flush filesystem buffers. config BIN_TRUE bool "true" default y help - Enable the 'true' command which returns a zero exit status. + Build/Add the 'true' command which returns a zero exit status. endmenu diff --git a/bin/clear/Kbuild b/bin/clear/Kbuild index 3e56e161..845df317 100644 --- a/bin/clear/Kbuild +++ b/bin/clear/Kbuild @@ -1,4 +1,3 @@ bin-y := clear obj-y += clear.o libs-y += $(srctree)/lib/libc/libc.a -install-y := bin/clear diff --git a/bin/echo/Kbuild b/bin/echo/Kbuild index 0f816ddf..00d6ecdd 100644 --- a/bin/echo/Kbuild +++ b/bin/echo/Kbuild @@ -1,4 +1,3 @@ bin-y := echo obj-y += echo.o libs-y += $(srctree)/lib/libc/libc.a -install-y := bin/echo diff --git a/bin/false/Kbuild b/bin/false/Kbuild index 2f8e102d..122d0838 100644 --- a/bin/false/Kbuild +++ b/bin/false/Kbuild @@ -1,4 +1,2 @@ bin-y := false obj-y += arch/ - -install-y := bin/false diff --git a/boot/Kbuild b/boot/Kbuild index 01daa04b..cb673478 100644 --- a/boot/Kbuild +++ b/boot/Kbuild @@ -1 +1 @@ -obj-y += init/ +obj-$(CONFIG_BOOT_INIT) += init/ diff --git a/boot/Kconfig b/boot/Kconfig new file mode 100644 index 00000000..ae77f1cb --- /dev/null +++ b/boot/Kconfig @@ -0,0 +1,8 @@ +menu "Boot" + +config BOOT_INIT + bool "init" + default n + depends on LIB_LIBC + +endmenu @@ -1,2 +1,2 @@ -obj-y += libc/ -obj-y += libm/ +obj-$(CONFIG_LIB_LIBC) += libc/ +obj-$(CONFIG_LIB_LIBM) += libm/ diff --git a/lib/Kconfig b/lib/Kconfig new file mode 100644 index 00000000..d5854b78 --- /dev/null +++ b/lib/Kconfig @@ -0,0 +1,24 @@ +# lib/Kconfig + +menu "Libraries" + +config LIB_LIBC + tristate "libc" + default m + help + Build/Add the 'libc' library. + +config LIB_LIBC_HEADERS + bool "libc headers" + default n + help + Add the 'libc' library headers. + + +config LIB_LIBM + tristate "libm" + default n + help + Build/Add the 'libm' library. + +endmenu diff --git a/lib/libc/Kbuild b/lib/libc/Kbuild index 60ab4f8e..762c95aa 100644 --- a/lib/libc/Kbuild +++ b/lib/libc/Kbuild @@ -1,5 +1,4 @@ -lib-y := libc.a -install-y := lib/libc.a +lib-$(CONFIG_LIB_LIBC) := libc.a cflags-y += -I $(src)/internal/include diff --git a/lib/libm/Kbuild b/lib/libm/Kbuild index 7dc47f30..b857231d 100644 --- a/lib/libm/Kbuild +++ b/lib/libm/Kbuild @@ -1,5 +1,4 @@ -lib-y := libm.a -install-y := lib/libm.a +lib-$(CONFIG_LIB_LIBM) := libm.a obj-y += __cos.o obj-y += __cosdf.o @@ -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 diff --git a/scripts/makefile.build b/scripts/makefile.build index 6467d2ad..e4926b3e 100644 --- a/scripts/makefile.build +++ b/scripts/makefile.build @@ -11,6 +11,8 @@ src := $(patsubst %/,%,$(obj)) ifdef lib-y export cflags-y +else ifdef lib-m + export cflags-y endif ifdef bin-y @@ -18,8 +20,16 @@ ifdef bin-y export ldflags-y endif +ifneq ($(strip $(lib-y) $(lib-m) $(lib-n)),) +lib = $(lib-y)$(lib-m)$(lib-n) +endif +ifneq ($(strip $(bin-y) $(bin-n)),) +bin = $(bin-y)$(bin-n) +endif + + objects := $(filter %.o,$(obj-y)) -subdirs := $(filter %/,$(obj-y)) +subdirs := $(filter %/,$(obj-y)) $(filter %/,$(obj-m)) cflags := $(cflags-y) $(KBUILD_CFLAGS) -MMD -MP asflags := $(asflags-y) $(KBUILD_ASFLAGS) @@ -29,7 +39,8 @@ collect-obj-y = $(foreach e,$(shell echo 'all:; @echo $$(obj-y)' | \ $(MAKE) -f $(obj)$(1)Kbuild -f - --no-print-directory 2>/dev/null),\ $(if $(filter %/,$(e)),$(addprefix $(e),$(call collect-obj-y,$(1)$(e))),$(e))) -ifdef lib-y + +ifneq ($(strip $(lib-y) $(lib-m)),) subdir-objects := $(foreach d,$(subdirs),$(addprefix $(d),$(call collect-obj-y,$(d)))) all-objects := $(objects) $(subdir-objects) else ifdef bin-y @@ -47,23 +58,26 @@ s-sources := $(wildcard $(addprefix $(obj),$(objects:.o=.s))) subdir-c-sources := $(wildcard $(addprefix $(obj),$(subdir-objects:.o=.c))) subdir-s-sources := $(wildcard $(addprefix $(obj),$(subdir-objects:.o=.s))) -PHONY := all +PHONY := all install ifdef lib-y all: $(obj)$(lib-y) $(addprefix $(obj),$(always)) -$(obj)$(lib-y): $(addprefix $(obj),$(all-objects)) +$(obj)$(lib): $(addprefix $(obj),$(all-objects)) $(MSG) AR "$@" $(Q)$(AR) rcs $@ $^ -$(O)/$(install-y): $(obj)$(lib-y) - mkdir -p $(O)/$(dir $(install-y)) - install -m 0644 $< $(O)/$(install-y) +$(O)/$(parent)/$(lib-y): $(obj)$(lib-y) + $(Q)mkdir -p $(O)/$(dir $@) + $(Q)install -m 0644 $< $@ -ifdef install-y -install: $(O)/$(install-y) -else -install: -endif +install: $(O)/$(parent)/$(lib-y) + +else ifdef lib-m +all: $(obj)$(lib-m) $(addprefix $(obj),$(always)) + +$(obj)$(lib): $(addprefix $(obj),$(all-objects)) + $(MSG) AR "$@" + $(Q)$(AR) rcs $@ $^ else ifdef bin-y all: $(obj)$(bin-y) $(addprefix $(obj),$(always)) @@ -72,16 +86,11 @@ $(obj)$(bin-y): $(addprefix $(obj),$(all-objects)) $(libs-y) ${prereq} $(MSG) LD "$@" $(Q)$(LD) $(ldflags) -o $@ $^ -ifdef install-y -$(O)/$(install-y): $(obj)$(bin-y) - mkdir -p $(O)/$(dir $(install-y)) - install -m 0755 $< $(O)/$(install-y) - -install: $(O)/$(install-y) -else -install: -endif +$(O)/$(parent)/$(bin-y): $(obj)$(bin-y) + $(Q)mkdir -p $(O)/$(parent) + $(Q)install -m 0755 $< $@ +install: $(O)/$(parent)/$(bin-y) else all: $(addprefix $(obj),$(all-objects)) $(subdirs) $(addprefix $(obj),$(always)) @@ -99,29 +108,27 @@ endif ifdef all-objects $(Q)rm -f $(addprefix $(obj),$(all-objects)) endif -ifdef lib-y - $(Q)rm -f $(obj)$(lib-y) +ifdef lib + $(Q)rm -f "$(obj)$(lib)" endif -ifdef bin-y - $(Q)rm -f $(obj)$(bin-y) +ifdef bin + $(Q)rm -f $(obj)$(bin) endif ifdef always $(Q)rm -f $(addprefix $(obj),$(always)) endif -# Build C sources to objects $(filter $(addprefix $(obj),$(all-objects)),$(c-sources:.c=.o) $(subdir-c-sources:.c=.o)): $(obj)%.o: $(obj)%.c $(MSG) CC "$@" $(Q)$(CC) $(cflags) -c $< -o $@ -# Build assembly sources to objects $(filter $(addprefix $(obj),$(all-objects)),$(s-sources:.s=.o) $(subdir-s-sources:.s=.o)): $(obj)%.o: $(obj)%.s $(MSG) AS "$@" $(Q)$(CC) $(asflags) -c $< -o $@ .PHONY: $(subdirs) $(subdirs): - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.build obj="$(obj)$@" ${MAKECMDGOALS} + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.build obj="$(obj)$@" parent="$(obj)" ${MAKECMDGOALS} clean-%: $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.build obj="$(obj)$*" clean |
