-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
113 lines (93 loc) · 3.29 KB
/
Makefile
File metadata and controls
113 lines (93 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# BonfireOS - Minimal x86_64 OS Build System
# Uses cross-compiler: x86_64-elf-gcc, x86_64-elf-ld, nasm
# Run: make, make run (QEMU), make iso (bootable image)
ARCH := x86_64
CC := x86_64-elf-gcc
LD := x86_64-elf-ld
AS := nasm
OBJCOPY := x86_64-elf-objcopy
GRUB_MKRESCUE := grub-mkrescue
# Optional GUI (1980s-style). Set ENABLE_GUI=0 to build without GUI.
ENABLE_GUI ?= 1
# Optional TCP/IP stack + Lynx-style host. Set ENABLE_NET=0 to omit.
ENABLE_NET ?= 1
# Flags
CFLAGS := -ffreestanding -fno-pie -fno-stack-protector -fno-builtin \
-m64 -march=x86-64 -mno-red-zone -mno-mmx -mno-sse -mno-sse2 \
-Wall -Wextra -O2 -g -I include -DENABLE_GUI=$(ENABLE_GUI) -DENABLE_NET=$(ENABLE_NET)
ASFLAGS := -f elf64
LDFLAGS := -nostdlib -static -z max-page-size=0x1000 -T linker.ld
# Directories
BUILD := build
OBJ := $(BUILD)/obj
BOOT := $(BUILD)/boot
ISO := $(BUILD)/iso
ISO_BOOT := $(ISO)/boot
GRUB_CFG := scripts/grub.cfg
# Kernel objects (C and ASM) — mirror src/ under build/obj/
# When ENABLE_GUI=0, exclude GUI sources so the kernel builds without GUI.
# When ENABLE_NET=0, exclude net/ and lynx_host/.
C_SRCS_ALL := $(shell find src -name '*.c')
GUI_SRCS := $(wildcard src/kernel/gui/*.c)
NET_SRCS := $(wildcard src/kernel/net/*.c)
LYNX_SRCS := $(wildcard src/kernel/lynx_host/*.c)
ifeq ($(ENABLE_GUI),0)
C_SRCS := $(filter-out $(GUI_SRCS),$(C_SRCS_ALL))
else
C_SRCS := $(C_SRCS_ALL)
endif
ifeq ($(ENABLE_NET),0)
C_SRCS := $(filter-out $(NET_SRCS),$(C_SRCS))
C_SRCS := $(filter-out $(LYNX_SRCS),$(C_SRCS))
endif
ASM_SRCS := $(shell find src -name '*.asm' -o -name '*.s')
C_OBJS := $(patsubst src/%.c,$(OBJ)/%.o,$(C_SRCS))
ASM_OBJS := $(patsubst src/%.asm,$(OBJ)/%.o,$(filter %.asm,$(ASM_SRCS)))
ASM_OBJS += $(patsubst src/%.s,$(OBJ)/%.o,$(filter %.s,$(ASM_SRCS)))
OBJS := $(C_OBJS) $(ASM_OBJS)
# Targets
KERNEL_BIN := $(BUILD)/kernel.bin
ISO_IMG := $(BUILD)/bonfireos.iso
.PHONY: all clean run iso dirs no-gui no-net
all: dirs $(KERNEL_BIN)
# Build without the optional GUI (CLI-only kernel).
no-gui:
$(MAKE) all ENABLE_GUI=0
# Build without TCP/IP and Lynx host.
no-net:
$(MAKE) all ENABLE_NET=0
dirs:
@mkdir -p $(BOOT) $(OBJ) $(shell dirname $(C_OBJS)) $(shell dirname $(ASM_OBJS))
# Compile C sources
$(OBJ)/%.o: src/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
# Assemble ASM sources
$(OBJ)/%.o: src/%.asm
@mkdir -p $(dir $@)
$(AS) $(ASFLAGS) $< -o $@
$(OBJ)/%.o: src/%.s
@mkdir -p $(dir $@)
$(AS) $(ASFLAGS) $< -o $@
# Link kernel
$(KERNEL_BIN): $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -o $@
# Build bootable ISO (for QEMU and VirtualBox)
iso: all
@mkdir -p $(ISO_BOOT)/grub
cp $(KERNEL_BIN) $(ISO_BOOT)/
cp $(GRUB_CFG) $(ISO_BOOT)/grub/
$(GRUB_MKRESCUE) -o $(ISO_IMG) $(ISO)
@echo "ISO image: $(ISO_IMG)"
# Run in QEMU (kernel only, no ISO - faster for dev)
run: all
qemu-system-x86_64 -kernel $(KERNEL_BIN) -serial stdio -no-reboot -no-shutdown
# Run from ISO (closer to real hardware / VirtualBox)
run-iso: iso
qemu-system-x86_64 -cdrom $(ISO_IMG) -serial stdio -no-reboot -no-shutdown
clean:
rm -rf $(BUILD)
# Check for cross-compiler
check-toolchain:
@which $(CC) >/dev/null 2>&1 || (echo "Install x86_64-elf cross compiler. See docs/BUILD.md"; exit 1)
@which $(AS) >/dev/null 2>&1 || (echo "Install nasm"; exit 1)