2023-04-19 03:44:10 +00:00
|
|
|
CC=i386-elf-gcc
|
|
|
|
LD=i386-elf-ld
|
2023-04-21 13:39:35 +00:00
|
|
|
CFLAGS=-ffreestanding -ggdb -m32 -std=gnu17 -O3 -Wall -Wextra -pedantic -lgcc -isystem ./libk/include
|
2023-04-19 03:44:10 +00:00
|
|
|
|
|
|
|
C_SOURCE=$(shell find kernel -type f -name "*.c")
|
|
|
|
C_OBJ=$(patsubst %.c,bin/%.o,$(C_SOURCE))
|
|
|
|
|
|
|
|
A_SOURCE=$(shell find kernel -type f -name "*.asm")
|
|
|
|
A_OBJ=$(patsubst %.asm,bin/%_asm.o,$(A_SOURCE))
|
|
|
|
|
|
|
|
LIBK_SOURCE=$(shell find libk -type f -name "*.c")
|
|
|
|
LIBK_OBJ=$(patsubst %.c,bin/%.o,$(LIBK_SOURCE))
|
|
|
|
|
|
|
|
.PHONY: test all run clean
|
|
|
|
|
|
|
|
all: bin/os.iso
|
|
|
|
|
|
|
|
$(A_OBJ): bin/%_asm.o : %.asm
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
nasm $< -f elf -o $@
|
|
|
|
|
|
|
|
$(C_OBJ): bin/%.o : %.c
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(CC) -c $(CFLAGS) -o $@ $<
|
|
|
|
|
|
|
|
$(LIBK_OBJ): bin/%.o : %.c
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(CC) -c $(CFLAGS) -o $@ $<
|
|
|
|
|
|
|
|
bin/libk.a: $(LIBK_OBJ)
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(AR) rcs bin/libk.a $(LIBK_OBJ)
|
|
|
|
|
2023-04-21 13:39:35 +00:00
|
|
|
bin/kernel.bin: bin/libk.a linker.ld $(A_OBJ) $(C_OBJ)
|
2023-04-19 03:44:10 +00:00
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(LD) -nmagic -o bin/kernel.bin -T linker.ld $(A_OBJ) $(C_OBJ) bin/libk.a
|
|
|
|
|
2023-04-21 13:39:35 +00:00
|
|
|
bin/os.iso: bin/kernel.bin grub.cfg
|
2023-04-19 03:44:10 +00:00
|
|
|
@mkdir -p $(@D)
|
|
|
|
@mkdir -p bin/iso/boot/grub
|
|
|
|
cp grub.cfg bin/iso/boot/grub
|
|
|
|
cp bin/kernel.bin bin/iso/boot
|
|
|
|
grub-mkrescue -o bin/os.iso bin/iso
|
|
|
|
|
|
|
|
run: all
|
|
|
|
qemu-system-i386 -cdrom bin/os.iso
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf bin
|