-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
157 lines (131 loc) · 6.45 KB
/
Copy pathMakefile
File metadata and controls
157 lines (131 loc) · 6.45 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
## Project directory (portable — never hardcode absolute paths)
PROJECT_DIR := $(CURDIR)
## ── Toolchain ──────────────────────────────────────────────────────────────
CARGO := cargo
QEMU_AARCH64 := qemu-system-aarch64
QEMU_X86 := qemu-system-x86_64
## ── AArch64 build output ──────────────────────────────────────────────────
KERNEL_AARCH64 := $(PROJECT_DIR)/target/aarch64-unknown-none/release/toubkal_os
QEMU_FLAGS_AARCH64 := \
-M virt \
-cpu cortex-a72 \
-m 2G \
-drive file=$(PROJECT_DIR)/drive_aarch64.img,format=raw,if=none,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-netdev user,id=n0 -device virtio-net-device,netdev=n0
## ── x86_64 build output ───────────────────────────────────────────────────
KERNEL_X86 := $(PROJECT_DIR)/target/x86_64-unknown-none/release/toubkal_os
QEMU_FLAGS_X86 := \
-M q35 \
-m 2G \
-drive file=$(PROJECT_DIR)/drive_x86_64.img,format=raw,if=virtio \
-netdev user,id=n0 \
-device virtio-net-pci,netdev=n0
## ── Default ───────────────────────────────────────────────────────────────
.DEFAULT_GOAL := help
.PHONY: help build build-aarch64 build-x86 \
run run-serial run-gui \
run-x86 run-aarch64 \
drive_aarch64.img drive_x86_64.img fmt check clean
help:
@echo ""
@echo " ToubkalOS — Build System"
@echo ""
@echo " Targets (AArch64 — default):"
@echo " make build Build the AArch64 kernel (release)"
@echo " make run Run AArch64 kernel in QEMU (serial mode)"
@echo " make run-gui Run AArch64 kernel in QEMU (GUI mode)"
@echo ""
@echo " Targets (x86_64):"
@echo " make build-x86 Build the x86_64 kernel"
@echo " make run-x86 Run x86_64 kernel in QEMU"
@echo ""
@echo " Utilities:"
@echo " make fmt Format source code (cargo fmt)"
@echo " make check Cargo check + clippy warnings"
@echo " make drive.img Create a blank 64 MB FAT32 disk image"
@echo " make clean Remove build artifacts and disk image"
@echo ""
## ── Build ─────────────────────────────────────────────────────────────────
build: build-aarch64
build-aarch64:
@echo "[build] Compiling ToubkalOS for AArch64..."
$(CARGO) build --release --target aarch64-unknown-none
build-x86:
@echo "[build] Compiling ToubkalOS for x86_64..."
$(CARGO) build --release --target x86_64-unknown-none
## ── Disk image ────────────────────────────────────────────────────────────
## Create only if the file does not already exist.
build-hd-aarch64:
@echo "[disk] Re-creating 512 MB drive_aarch64.img..."
@rm -f drive_aarch64.img
@dd if=/dev/zero of=drive_aarch64.img bs=1M count=512 2>/dev/null
@echo "[disk] Formatting as partitionless FAT32 (4KB clusters)..."
@if [ "$$(uname)" = "Darwin" ]; then \
DISK=$$(hdiutil attach -nomount drive_aarch64.img | head -n 1 | awk '{print $$1}'); \
newfs_msdos -F 32 -c 8 -v TOUBKAL $$DISK; \
hdiutil detach $$DISK; \
else \
mkfs.fat -I -F 32 -s 8 -n TOUBKAL drive_aarch64.img; \
fi
drive_aarch64.img:
@if [ ! -f $@ ]; then \
$(MAKE) build-hd-aarch64; \
fi
drive_x86_64.img:
@if [ ! -f $@ ]; then \
echo "[disk] Creating 64 MB $@..."; \
dd if=/dev/zero of=$@ bs=1M count=64 2>/dev/null; \
echo "[disk] Formatting as FAT32..."; \
if [ "$$(uname)" = "Darwin" ]; then \
DISK=$$(hdiutil attach -nomount $@ | head -n 1 | awk '{print $$1}'); \
newfs_msdos -F 32 -v TOUBKAL $$DISK; \
hdiutil detach $$DISK; \
elif command -v mkfs.fat >/dev/null 2>&1; then \
mkfs.fat -F 32 -n TOUBKAL $@; \
fi; \
fi
## ── Run (AArch64) ─────────────────────────────────────────────────────────
run-serial: build-aarch64 drive_aarch64.img
@echo "[run] Starting AArch64 in serial mode (Ctrl+A then X to quit)..."
-@killall qemu-system-aarch64 2>/dev/null || true
$(QEMU_AARCH64) $(QEMU_FLAGS_AARCH64) -kernel $(KERNEL_AARCH64) -nographic
run-gui: build-aarch64 drive_aarch64.img
@echo "[run] Starting AArch64 in GUI mode..."
-@killall qemu-system-aarch64 2>/dev/null || true
$(QEMU_AARCH64) $(QEMU_FLAGS_AARCH64) \
-kernel $(KERNEL_AARCH64) \
-device virtio-gpu-device \
-device virtio-keyboard-device \
-device virtio-tablet-device \
-display default \
-serial stdio
run: run-serial
run-aarch64: run-serial
## ── Run (x86_64) ──────────────────────────────────────────────────────────
run-x86: build-x86 drive_x86_64.img
@echo "[run] Starting x86_64 in serial mode (Ctrl+A then X to quit)..."
-@killall qemu-system-x86_64 2>/dev/null || true
$(QEMU_X86) $(QEMU_FLAGS_X86) \
-device loader,file=$(KERNEL_X86),cpu-num=0 \
-nographic
run-gui-x86: build-x86 drive_x86_64.img
@echo "[run] Starting x86_64 in GUI mode..."
-@killall qemu-system-x86_64 2>/dev/null || true
$(QEMU_X86) $(QEMU_FLAGS_X86) \
-device loader,file=$(KERNEL_X86),cpu-num=0 \
-device virtio-gpu-pci \
-device virtio-keyboard-pci \
-device virtio-tablet-pci \
-display default \
-serial stdio
## ── Developer utilities ───────────────────────────────────────────────────
fmt:
$(CARGO) fmt --all
check:
$(CARGO) check --target aarch64-unknown-none
$(CARGO) clippy --target aarch64-unknown-none -- -D warnings
## ── Clean ─────────────────────────────────────────────────────────────────
clean:
$(CARGO) clean
rm -f drive_aarch64.img drive_x86_64.img serial.log