11# Proka Kernel - Root Makefile
22# Copyright (C) RainSTR Studio 2025-2026, All Rights Reserved.
33
4- .DEFAULT_GOAL := all
4+ .DEFAULT_GOAL := help
5+
6+ # OS detection
7+ UNAME_S := $(shell uname -s)
58
69# Verbosity control
710ifeq ($(V ) ,1)
1013 Q := @
1114endif
1215
16+ # Logging macro
17+ define log_info
18+ @echo "[INFO] $(1 ) "
19+ endef
20+ define log_success
21+ @echo "[OK] $(1 ) "
22+ endef
23+ define log_warn
24+ @echo "[WARN] $(1 ) "
25+ endef
26+ define log_error
27+ @echo "[ERR] $(1 ) "
28+ endef
29+
1330# Core variables
1431BUILD_DIRS ?= kernel
1532TARGET_DIR ?= $(CURDIR ) /target
@@ -22,32 +39,76 @@ INITRD ?= assets/initrd.cpio
2239XORRISO ?= xorriso
2340XORRISOFLAGS ?= -as mkisofs --efi-boot limine/limine-uefi-cd.bin -quiet
2441QEMU ?= qemu-system-x86_64
25- QEMU_FLAGS ?= -bios ./assets/OVMF.fd -cdrom $(ISO_IMAGE ) --machine q35 -m 1G
42+
43+ # Accelerator selection
44+ ifeq ($(UNAME_S ) ,Linux)
45+ QEMU_ACCEL ?= -enable-kvm
46+ else ifeq ($(UNAME_S),Darwin)
47+ QEMU_ACCEL ?= -accel hvf
48+ endif
49+
50+ QEMU_FLAGS ?= -bios ./assets/OVMF.fd -cdrom $(ISO_IMAGE ) --machine q35 -m 1G $(QEMU_ACCEL )
2651QEMU_OUT ?= -serial stdio
2752QEMU_EXTRA ?=
2853
2954# Profile handling (default to release)
3055PROFILE ?= dev
3156export PROFILE
3257
33- .PHONY : all debug clean distclean run rundebug menuconfig iso $(BUILD_DIRS ) docs-build docs-serve docs-clean
58+ .PHONY : all help debug clean distclean run rundebug menuconfig iso $(BUILD_DIRS ) \
59+ docs-build docs-serve docs-clean test clippy fmt check-tools
60+
61+ help :
62+ @echo " $( COLOR_INFO) Proka Kernel Build System$( COLOR_RESET) "
63+ @echo " "
64+ @echo " Usage: make [target] [VARIABLES]"
65+ @echo " "
66+ @echo " Targets:"
67+ @echo " all Build the kernel"
68+ @echo " iso Create a bootable ISO image"
69+ @echo " run Run the kernel in QEMU (with $( QEMU_ACCEL) )"
70+ @echo " rundebug Run the kernel in QEMU with GDB stub (-s -S)"
71+ @echo " test Run kernel tests"
72+ @echo " clippy Run clippy lints"
73+ @echo " fmt Format kernel source code"
74+ @echo " menuconfig Open kernel configuration menu"
75+ @echo " clean Remove build artifacts"
76+ @echo " distclean Full cleanup including target directory"
77+ @echo " doc Build documentation"
78+ @echo " check-tools Verify required build tools are installed"
79+ @echo " "
80+ @echo " Variables:"
81+ @echo " V=1 Enable verbose output"
82+ @echo " PROFILE=dev Set build profile (dev/release, default: dev)"
83+ @echo " QEMU_ACCEL= Override QEMU accelerator flags"
84+ @echo " "
85+ @echo " Detected OS: $( UNAME_S) "
86+
87+ # Tool check
88+ check-tools :
89+ $(call log_info,Checking build tools...)
90+ @command -v $(XORRISO ) > /dev/null 2>&1 || ( $( call log_error,$( XORRISO) not found) ; exit 1 )
91+ @command -v $(QEMU ) > /dev/null 2>&1 || ( $( call log_error,$( QEMU) not found) ; exit 1 )
92+ @command -v cargo > /dev/null 2>&1 || ( $( call log_error,cargo not found) ; exit 1 )
93+ @command -v cpio > /dev/null 2>&1 || ( $( call log_error,cpio not found) ; exit 1 )
94+ $(call log_success,All tools found.)
3495
3596# Documentation targets
3697doc :
37- @echo " Building guide (mdBook)..."
98+ $( call log_info, Building guide (mdBook) ...)
3899 $(Q ) mdbook build
39- @echo " Building API documentation (rustdoc)..."
100+ $( call log_info, Building API documentation (rustdoc) ...)
40101 $(Q ) cd kernel && cargo doc --no-deps
41102 $(Q ) rm -rf book/api
42103 $(Q ) cp -r kernel/target/x86_64-unknown-none/doc book/api
43- @echo " Documentation built in book/"
104+ $( call log_success, Documentation built in book/)
44105
45106docs-serve :
46- @echo " Serving documentation..."
107+ $( call log_info, Serving documentation...)
47108 $(Q ) mdbook serve --hostname 0.0.0.0
48109
49110docs-clean :
50- @echo " Cleaning documentation..."
111+ $( call log_info, Cleaning documentation...)
51112 $(Q ) mdbook clean
52113 $(Q ) rm -rf book
53114 $(Q ) cd kernel && cargo clean --doc
@@ -59,25 +120,26 @@ debug:
59120 $(Q )$(MAKE ) PROFILE=dev all
60121
61122$(BUILD_DIRS ) :
62- @echo " Entering directory: $@ "
123+ $( call log_info, Entering directory: $@ )
63124 $(Q ) mkdir -p $(OBJ_DIR )
64125 $(Q )$(MAKE ) -C $@ OBJ_DIR=$(OBJ_DIR ) V=$(V )
65126
66127# ISO image creation
67- iso : all $(INITRD )
68- @echo " Creating ISO image: $( ISO_IMAGE) "
128+ ROOTFS_SRC := $(shell find assets/rootfs -type f 2>/dev/null)
129+ iso : all $(INITRD ) $(ROOTFS_SRC )
130+ $(call log_info,Creating ISO image: $(ISO_IMAGE ) )
69131 $(Q ) mkdir -p $(ISO_DIR )
70132 $(Q ) cp -r ./assets/rootfs/* $(ISO_DIR ) /
71133 $(Q ) cp $(INITRD ) $(ISO_DIR ) /initrd.cpio
72134 $(Q ) cp ./kernel/kernel $(ISO_DIR ) /kernel
73135 $(Q )$(XORRISO ) $(XORRISOFLAGS ) $(ISO_DIR ) -o $(ISO_IMAGE )
74136 $(Q ) rm -rf $(ISO_DIR )
75- @echo " ISO build complete."
137+ $( call log_success, ISO build complete.)
76138
77139# Initrd creation
78140INITRD_SRC := $(shell find assets/initrd -type f 2>/dev/null)
79141$(INITRD ) : $(INITRD_SRC )
80- @echo " Creating initrd: $@ "
142+ $( call log_info, Creating initrd: $@ )
81143 $(Q ) mkdir -p assets
82144 $(Q ) cd assets/initrd && find . -print | cpio -H newc -o > ../initrd.cpio 2> /dev/null
83145
@@ -88,6 +150,14 @@ run: iso
88150rundebug :
89151 $(Q )$(MAKE ) QEMU_EXTRA=" -s -S" run
90152
153+ test :
154+ $(call log_info,Running kernel tests...)
155+ $(Q )$(MAKE ) -C kernel test
156+
157+ clippy :
158+ $(call log_info,Running clippy...)
159+ $(Q )$(MAKE ) -C kernel clippy
160+
91161menuconfig :
92162 $(Q )$(MAKE ) -C kernel menuconfig
93163
@@ -101,8 +171,9 @@ clean: docs-clean
101171 done
102172 $(Q ) rm -f $(ISO_IMAGE ) $(INITRD )
103173 $(Q ) rm -rf $(OBJ_DIR )
104- @echo " Cleaned."
174+ $( call log_success, Cleaned.)
105175
106176distclean : clean
107177 $(Q ) rm -rf $(TARGET_DIR )
108- @echo " Full cleanup complete."
178+ $(call log_success,Full cleanup complete.)
179+
0 commit comments