summaryrefslogtreecommitdiff
path: root/Makefile
blob: 947a4dcdefe11bfa3faa5985f1eab1130c1d983f (plain)
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
### Copyright (c) 2025 Freya Murphy <freya@freyacat.org>

.PHONY: build clean fmt qemu qemu-kvm qemu-gdb gdb
.SILENT:

BIN=bin
ISO=os.iso

QEMU ?= qemu-system-x86_64
GRUB ?= grub-mkrescue

QEMUOPTS += -cdrom $(BIN)/$(ISO) \
		    -no-reboot \
		    -drive format=raw,file=user/bin/initrd.tar \
		    -audiodev pa,id=speaker -machine pcspk-audiodev=speaker \
		    -serial mon:stdio \
		    -m 4G \
		    -name kern

ifdef UEFI
QEMU = qemu-system-x86_64-uefi
GRUB = grub-mkrescue-uefi
endif

ifndef DISPLAY
QEMUOPTS += -nographic
endif

qemu: $(BIN)/$(ISO)
	$(QEMU) $(QEMUOPTS)

qemu-kvm: $(BIN)/$(ISO)
	$(QEMU) $(QEMUOPTS) -cpu host --enable-kvm

qemu-gdb: $(BIN)/$(ISO)
	$(QEMU) $(QEMUOPTS) -S -gdb tcp::1337

gdb:
	gdb -q -n -x config/gdbinit

build:
	make -s -C kernel build
	make -s -C user build

clean:
	rm -fr $(BIN)
	make -s -C kernel clean
	make -s -C user clean

fmt:
	clang-format -i $(shell find -type f -name "*.[ch]" -and -not -path "./kernel/old/*")
	sed -i 's/[ \t]*$$//' $(shell find -type f -name "*.[chS]" -and -not -path "./kernel/old/*")

$(BIN)/$(ISO): build config/grub.cfg
	printf "\033[35m  ISO \033[0m%s\n" $@
	mkdir -p $(BIN)/iso/boot/grub
	cp config/grub.cfg $(BIN)/iso/boot/grub
	cp kernel/bin/kernel $(BIN)/iso/boot
	cp user/bin/initrd.tar $(BIN)/iso/boot
	$(GRUB) -o $(BIN)/$(ISO) bin/iso 2>/dev/null