aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile167
1 files changed, 95 insertions, 72 deletions
diff --git a/Makefile b/Makefile
index 6c9dccb..b932fe9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,32 +1,8 @@
-# ═══════════════════════════════════════════════════════════════════════════
-# Akiba OS - Build System
-# ═══════════════════════════════════════════════════════════════════════════
-#
-# Build system for Akiba OS featuring:
-# - Docker-based cross-compilation for portability
-# - Native builds on Arch Linux
-# - Automatic platform detection (macOS/Linux)
-# - AFS disk image creation with GPT partition table
-# - GRUB UEFI bootloader installation
-#
-# Usage:
-# make - Build bootable disk image
-# make run - Build and run in QEMU
-# make clean - Clean all build artifacts
-#
-# Requirements (Docker mode):
-# - Docker
-#
-# Requirements (Native mode, Arch Linux only):
-# - zig, grub, mtools, dosfstools, gdisk
-#
-# ═══════════════════════════════════════════════════════════════════════════
+.PHONY: all clean run docker-build docker-run native-build build-grub
-.PHONY: all clean run docker-build docker-run native-build native-clean
-
-# ───────────────────────────────────────────────────────────────────────────
+# ═══════════════════════════════════════════════════════════════════════════
# Platform Detection
-# ───────────────────────────────────────────────────────────────────────────
+# ═══════════════════════════════════════════════════════════════════════════
ifdef DOCKER_BUILD
BUILD_MODE = native
@@ -44,26 +20,28 @@ else
endif
endif
-# ───────────────────────────────────────────────────────────────────────────
-# Build Configuration
-# ───────────────────────────────────────────────────────────────────────────
+# ═══════════════════════════════════════════════════════════════════════════
+# Configuration
+# ═══════════════════════════════════════════════════════════════════════════
+
+GRUB_VERSION = 2.12
+GRUB_URL = https://ftp.gnu.org/gnu/grub/grub-$(GRUB_VERSION).tar.xz
+GRUB_SRC = toolchain/grub-afs/grub-$(GRUB_VERSION)
+GRUB_BUILD = toolchain/grub-afs/build
GRUB_CONFIG = boot/grub/grub.cfg
GRUB_THEME_DIR = boot/grub/themes
DISK_IMAGE = iso/akiba.img
FS_ROOT = iso/akiba
BUILD_DIR = iso/build
-
-# Directories to copy to /system/ on the disk
SYSTEM_DIRS = resources/fonts
-# Calculate disk size based on content
CONTENT_SIZE_KB := $(shell du -sk $(FS_ROOT) 2>/dev/null | awk '{sum += $$1} END {print sum + 10000}')
DISK_SIZE_MB := $(shell echo "$$(($(CONTENT_SIZE_KB) / 1024 + 50))")
-# ───────────────────────────────────────────────────────────────────────────
+# ═══════════════════════════════════════════════════════════════════════════
# Docker Build Mode
-# ───────────────────────────────────────────────────────────────────────────
+# ═══════════════════════════════════════════════════════════════════════════
ifeq ($(BUILD_MODE),docker)
@@ -71,48 +49,95 @@ all: docker-build
docker-build:
@echo "═══════════════════════════════════════════════════════════"
- @echo " Building Akiba OS (Docker mode - $(UNAME_S) detected)"
+ @echo " Building Akiba OS (Docker mode)"
@echo "═══════════════════════════════════════════════════════════"
@docker build -t akiba-builder ./toolchain
@docker run --rm -v $(PWD):/akiba -e DOCKER_BUILD=1 akiba-builder make all
docker-run:
- @echo "Running Akiba OS..."
@./scripts/run.sh
clean:
@docker run --rm -v $(PWD):/akiba -e DOCKER_BUILD=1 akiba-builder make clean 2>/dev/null || rm -rf iso/ zig-out/ zig-cache/ .zig-cache/
+clean-grub:
+ @docker run --rm -v $(PWD):/akiba -e DOCKER_BUILD=1 akiba-builder make clean-grub 2>/dev/null || rm -rf toolchain/grub-afs/grub-* toolchain/grub-afs/build
+
+clean-all: clean clean-grub
+
run: all docker-run
-# ───────────────────────────────────────────────────────────────────────────
-# Native Build Mode (Arch Linux or inside Docker)
-# ───────────────────────────────────────────────────────────────────────────
+# ═══════════════════════════════════════════════════════════════════════════
+# Native Build Mode
+# ═══════════════════════════════════════════════════════════════════════════
else
all: native-build
-native-build: $(DISK_IMAGE)
+native-build: build-grub $(DISK_IMAGE)
-native-clean:
+clean:
@rm -rf iso/ zig-out/ zig-cache/ .zig-cache/
-clean: native-clean
+clean-grub:
+ @rm -rf toolchain/grub-afs/grub-* toolchain/grub-afs/build
+
+clean-all: clean clean-grub
run: all
@./scripts/run.sh
endif
-# ───────────────────────────────────────────────────────────────────────────
-# Common Build Targets
-# ───────────────────────────────────────────────────────────────────────────
+# ═══════════════════════════════════════════════════════════════════════════
+# GRUB with AFS Built-in
+# ═══════════════════════════════════════════════════════════════════════════
+
+build-grub: $(GRUB_BUILD)/bin/grub-mkstandalone
+
+$(GRUB_SRC)/grub-core/fs/afs.c: toolchain/grub-afs/afs.c
+ @echo "→ Downloading GRUB source..."
+ @mkdir -p toolchain/grub-afs
+ @cd toolchain/grub-afs && curl -L $(GRUB_URL) -o grub.tar.xz
+ @cd toolchain/grub-afs && tar -xf grub.tar.xz
+ @rm -f toolchain/grub-afs/grub.tar.xz
+ @echo "→ Integrating AFS into GRUB source..."
+ @cp toolchain/grub-afs/afs.c $(GRUB_SRC)/grub-core/fs/
+ @echo "" >> $(GRUB_SRC)/grub-core/Makefile.core.def
+ @echo "module = {" >> $(GRUB_SRC)/grub-core/Makefile.core.def
+ @echo " name = afs;" >> $(GRUB_SRC)/grub-core/Makefile.core.def
+ @echo " common = fs/afs.c;" >> $(GRUB_SRC)/grub-core/Makefile.core.def
+ @echo "};" >> $(GRUB_SRC)/grub-core/Makefile.core.def
+ @echo "→ Creating missing build files..."
+ @touch $(GRUB_SRC)/grub-core/extra_deps.lst
+ @sleep 2
+ @touch $(GRUB_SRC)/grub-core/Makefile.core.am
+ @touch $(GRUB_SRC)/grub-core/Makefile.in
+ @touch $(GRUB_SRC)/configure
+ @touch $(GRUB_SRC)/grub-core/fs/afs.c
+
+$(GRUB_BUILD)/bin/grub-mkstandalone: $(GRUB_SRC)/grub-core/fs/afs.c
+ @echo "→ Building GRUB with AFS support (this takes a few minutes)..."
+ @mkdir -p $(GRUB_BUILD)
+ cd $(GRUB_BUILD) && ../grub-$(GRUB_VERSION)/configure \
+ --prefix=$$(pwd) \
+ --target=x86_64 \
+ --with-platform=efi \
+ --disable-werror
+ cd $(GRUB_BUILD) && $(MAKE) -j$$(nproc)
+ cd $(GRUB_BUILD) && $(MAKE) install
+ @echo " ✓ GRUB with AFS built successfully"
-prepare-filesystem:
+# ═══════════════════════════════════════════════════════════════════════════
+# Filesystem Preparation
+# ═══════════════════════════════════════════════════════════════════════════
+
+prepare-filesystem: build-grub
@echo "→ Preparing filesystem structure..."
@mkdir -p $(FS_ROOT)/boot/grub
@mkdir -p $(FS_ROOT)/system/akiba
+ @mkdir -p $(FS_ROOT)/EFI/BOOT
@mkdir -p $(BUILD_DIR)
@echo "→ Building Mirai kernel..."
@@ -131,34 +156,32 @@ prepare-filesystem:
@cp $(GRUB_CONFIG) $(FS_ROOT)/boot/grub/
@cp -R $(GRUB_THEME_DIR) $(FS_ROOT)/boot/grub/
-
-$(DISK_IMAGE): prepare-filesystem
- @echo "→ Creating AFS bootable disk ($(DISK_SIZE_MB)MB)..."
-
- @dd if=/dev/zero of=$(DISK_IMAGE) bs=1M count=$(DISK_SIZE_MB) 2>/dev/null
-
- @echo "→ Creating GPT partition table..."
- @sgdisk -n 1:2048:0 -t 1:EF00 -c 1:"EFI System" $(DISK_IMAGE) >/dev/null 2>&1
-
- @echo "→ Formatting as Akiba File System..."
- @mkfs.fat -F 32 -n AKIBA --offset 2048 $(DISK_IMAGE) >/dev/null 2>&1
- @echo "→ Copying files to disk..."
- @export MTOOLS_SKIP_CHECK=1; \
- mcopy -s -i $(DISK_IMAGE)@@1M $(FS_ROOT)/* ::
-
- @echo "→ Installing GRUB bootloader..."
- @mkdir -p $(FS_ROOT)/EFI/BOOT
- @grub-mkstandalone \
+ @echo "→ Creating GRUB bootloader with AFS support..."
+ @$(GRUB_BUILD)/bin/grub-mkstandalone \
--format=x86_64-efi \
--output=$(FS_ROOT)/EFI/BOOT/BOOTX64.EFI \
+ --directory=$(GRUB_BUILD)/lib/grub/x86_64-efi \
--locales="" \
- --fonts="" \
- --modules="part_gpt part_msdos fat iso9660 multiboot2 normal search search_label" \
- "boot/grub/grub.cfg=$(GRUB_CONFIG)" 2>/dev/null
- @export MTOOLS_SKIP_CHECK=1; \
- mmd -i $(DISK_IMAGE)@@1M ::EFI 2>/dev/null || true; \
- mmd -i $(DISK_IMAGE)@@1M ::EFI/BOOT 2>/dev/null || true; \
- mcopy -i $(DISK_IMAGE)@@1M $(FS_ROOT)/EFI/BOOT/BOOTX64.EFI ::EFI/BOOT/
+ --fonts="unicode" \
+ --modules="part_gpt part_msdos fat afs iso9660 multiboot2 normal all_video gfxterm png gfxmenu" \
+ "boot/grub/grub.cfg=$(GRUB_CONFIG)"
+
+ @echo "→ Copying AFS module to ESP structure..."
+ @mkdir -p $(FS_ROOT)/boot/grub/modules
+ @cp $(GRUB_BUILD)/lib/grub/x86_64-efi/afs.mod $(FS_ROOT)/boot/grub/modules/
+
+ @echo "✓ Build completed successfully"
+
+# ═══════════════════════════════════════════════════════════════════════════
+# Disk Image Creation
+# ═══════════════════════════════════════════════════════════════════════════
+
+$(DISK_IMAGE): prepare-filesystem
+ @echo "→ Building mkafsdisk tool..."
+ @cd toolchain/mkafsdisk && zig build --prefix ../../iso/build
+
+ @echo "→ Creating bootable disk image..."
+ @iso/build/bin/mkafsdisk $(FS_ROOT) $(DISK_IMAGE) $(DISK_SIZE_MB)
@echo "✓ Akiba OS disk image ready: $(DISK_IMAGE)" \ No newline at end of file