Use JMK build system
diff --git a/src/kernel/Makefile b/src/kernel/Makefile
index 9029f26..ebac3b5 100644
--- a/src/kernel/Makefile
+++ b/src/kernel/Makefile
@@ -1,4 +1,42 @@
-SOURCES = boot.o \
+jmk_project := kernel
+jmk_target = kernel.elf
+ROOT := /home/ch/dev/bluejay
+ASM ?= nasm
+CC ?= gcc
+LD ?= ld
+CFLAGS += -I$(ROOT)/include
+
+all: $(jmk_target)
+
+CFLAGS += -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding
+CFLAGS += -O2
+CFLAGS += -g
+CFLAGS += -m32
+CFLAGS += -Wall -Wno-unused-function -Wno-unused-variable
+ASM = nasm
+
+
+.c.o:
+ $(CC) -c $< -o $@ $(CFLAGS)
+
+.s.o:
+ $(ASM) $(ASMFLAGS) $< -o $@
+
+
+
+
+jmk_lib_path_initrd = $(ROOT)/boot/initrd
+jmk_lib_target_initrd = initrd.img
+jmk_libs_phony += $(jmk_lib_path_initrd)/$(jmk_lib_target_initrd)
+
+$(jmk_lib_path_initrd)/$(jmk_lib_target_initrd):
+ $(MAKE) -C $(jmk_lib_path_initrd) $(jmk_lib_target_initrd)
+
+LDFLAGS = -Tlink.ld -melf_i386
+ASMFLAGS = -felf
+QEMUFLAGS = -d cpu_reset
+
+OBJECTS = boot.o \
main.o \
descriptor_tables.o \
io.o \
@@ -18,19 +56,9 @@
multiboot.o \
vfs_initrd.o
-JAYROOT = ../../
-CFLAGS = -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding \
- -m32 -O2 -g -Wall -Wno-unused-function -Wno-unused-variable \
- -I$(JAYROOT)/include
-LDFLAGS = -Tlink.ld -melf_i386
-ASMFLAGS = -felf
-QEMUFLAGS = -d cpu_reset
-
-kernel.elf: $(SOURCES)
- ld $(LDFLAGS) -o $@ $^
-
-clean:
- rm -f *.o *.bin *.elf $(JAYROOT)/bin/*.iso
+$(jmk_target): $(OBJECTS)
+ $(LD) $(LDFLAGS) -o $@ $^
+
debug: kernel.elf
qemu-system-i386 -s -S -kernel kernel.elf &
@@ -42,21 +70,20 @@
qemu-system-i386 $(QEMUFLAGS) -monitor stdio -kernel kernel.elf -no-reboot
qemu-iso: install
- qemu-system-i386 $(QEMUFLAGS) -monitor stdio $(JAYROOT)/bin/bluejay.iso
+ qemu-system-i386 $(QEMUFLAGS) -monitor stdio $(ROOT)/bin/bluejay.iso
scan_codes.c: gen_scan_codes.py scan_codes.tsv
python3 $< > $@
-.s.o:
- nasm $(ASMFLAGS) $<
+install: kernel.elf $(jmk_lib_path_initrd)/$(jmk_lib_target_initrd)
+ cp kernel.elf $(ROOT)/boot/
+ rm -f $(ROOT)/bin/bluejay.iso
+ grub-mkrescue -o $(ROOT)/bin/bluejay.iso $(ROOT)
-$(JAYROOT)/boot/initrd.img:
- $(MAKE) -C $(JAYROOT)/boot/initrd initrd.img
- cp $(JAYROOT)/boot/initrd/initrd.img $(JAYROOT)/boot/
+clean:
+ rm -f *.o *.a *.so $(jmk_target)
-install: kernel.elf $(JAYROOT)/boot/initrd.img
- cp kernel.elf $(JAYROOT)/boot/
- rm -f $(JAYROOT)/bin/bluejay.iso
- grub-mkrescue -o $(JAYROOT)/bin/bluejay.iso $(JAYROOT)
+Makefile: Jmk
+ cd "/home/ch/dev/bluejay" && ./bin/jmk
-.PHONY: install qemu clean qemu-iso debug $(JAYROOT)/boot/initrd.img
+.PHONY: $(jmk_libs_phony) $(jmk_custom_phony) clean all