summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: b63fa277c7004a62cb42a59a3bd97515ca7a4cd8 (plain) (blame)
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
include config.mk

KERNEL_BIN := $(KERNELDIR)/jove.elf
INITRD_TAR := $(SYSROOTDIR)/boot/initrd.tar

TEST_HDD := $(PWD)/test.hdd
TEST_HDD_SIZEM = 64
TEST_HDD_DIR := $(PWD)/test_hdd

all: $(KERNEL_BIN)

.PHONY: clean
clean:
	$(MAKE) -C $(KERNELDIR) clean CONFIG=$(PWD)/config.mk 
	-rm $(STATICLIBS)
	-rm $(APPS)
	$(foreach dir, $(filter %/, $(wildcard $(APPSDIR)/*/)), $(MAKE) -C $(dir) clean CONFIG=$(PWD)/config.mk)
	$(foreach dir, $(filter %/, $(wildcard $(LIBDIR)/*/)), $(MAKE) -C $(dir) clean CONFIG=$(PWD)/config.mk)

.PHONY: $(KERNEL_BIN)
$(KERNEL_BIN):
	$(MAKE) -C $(KERNELDIR) CONFIG=$(PWD)/config.mk

.PHONY: $(INITRD_TAR)
$(INITRD_TAR): $(APPS)
	$(MAKE) -C $(INITRDDIR) CONFIG=$(PWD)/config.mk OUT=$(INITRD_TAR)

$(INITRDDIR)/files/bin/% : $(STATICLIBS) FORCE
	$(MAKE) -C $(APPSDIR)/$(subst $(INITRDDIR)/files/bin/,,$@) CONFIG=$(PWD)/config.mk OUT=$(INITRDDIR)/files/bin

$(SYSROOTDIR)/lib/%.a : $(SYSROOTDIR) FORCE
	$(MAKE) -C $(LIBDIR)/$(subst $(SYSROOTDIR)/lib/,,$(subst .a,,$@)) CONFIG=$(PWD)/config.mk OUT=$(SYSROOTDIR)/lib

.PHONY: $(SYSROOTDIR)/usr/include
$(SYSROOTDIR)/usr/include:
	rm -rf $(SYSROOTDIR)/usr/include
	cp -r $(LIBDIR)/libc-headless/include $(SYSROOTDIR)/usr/include
	cp -r $(KERNELDIR)/include/ $(SYSROOTDIR)/usr/include/kernel
	cp -r $(LIBDIR)/libjove/include $(SYSROOTDIR)/usr/include/jove

$(SYSROOTDIR): $(SYSROOTDIR)/usr/include

.PHONY: test
.ONESHELL:
test: $(TEST_HDD) $(KERNEL_BIN) $(INITRD_TAR) $(SYSROOTDIR)
	sudo rm -rf $(TEST_HDD_DIR)
	mkdir -p $(TEST_HDD_DIR)
	export LOOPBACK_DEV=$(shell sudo losetup -Pf --show $(TEST_HDD))
	sudo partprobe $$LOOPBACK_DEV
	sudo mkfs.fat -F 32 "$$LOOPBACK_DEV"p1
	sudo mount "$$LOOPBACK_DEV"p1 $(TEST_HDD_DIR)
	sudo cp -r $(SYSROOTDIR)/* $(TEST_HDD_DIR)
	sudo cp $(KERNEL_BIN) $(TEST_HDD_DIR)/boot
	sudo cp limine/limine.exe $(TEST_HDD_DIR)/boot
	sudo mkdir -p $(TEST_HDD_DIR)/EFI/BOOT
	sudo cp limine/BOOTX64.EFI $(TEST_HDD_DIR)/EFI/BOOT
	sync
	sudo umount $(TEST_HDD_DIR)
	sudo losetup -d $$LOOPBACK_DEV
	sudo rm -rf $(TEST_HDD_DIR)
	qemu-system-x86_64 -m 512M -M q35 -bios ovmf-x64/OVMF.fd -net none -smp 4 -hda test.hdd -serial stdio -no-shutdown -no-reboot -s -d int -d guest_errors

.PHONY: $(TEST_HDD)
$(TEST_HDD):
	rm -f $(TEST_HDD)
	dd if=/dev/zero bs=1M count=0 seek=$(TEST_HDD_SIZEM) of=$(TEST_HDD)
	parted -s $(TEST_HDD) mklabel gpt
	parted -s $(TEST_HDD) mkpart primary 2048s 100%

FORCE: ;