# Define the object files
OBJS = bin/boot.o bin/kernel.o bin/idt.o bin/isr.o bin/screen.o bin/utils.o bin/string.o bin/stdio.o bin/gdt.o bin/disk.o

# Define the compiler and assembler
CC = gcc -D__is_katauos
AS = nasm

# Define the compiler flags
CFLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra -m32
ASFLAGS = -f elf32

# Define the linker flags
LDFLAGS = -ffreestanding -O2 -nostdlib -m32
LDSCRIPT = link.ld

# Define the output file
OUTPUT = myos.bin

all: $(OUTPUT)

image:
	cp myos.bin grubshit/boot/
	grub-mkrescue -o boot.iso grubshit

test:
	qemu-system-i386 -drive file=boot.iso,media=disk,format=raw -m 512M

test-bochs:
	bochs -f bochsrc

$(OUTPUT): $(OBJS)
	$(CC) -T $(LDSCRIPT) -o $@ $(OBJS) $(LDFLAGS)

bin/boot.o: src/boot.asm
	$(AS) $(ASFLAGS) $< -o $@

bin/kernel.o: src/kernel.c
	$(CC) $(CFLAGS) -c $< -o $@

bin/screen.o: src/screen.c
	$(CC) $(CFLAGS) -c $< -o $@

bin/isr.o: src/isr.c
	$(CC) $(CFLAGS) -c $< -o $@

bin/idt.o: src/idt.c
	$(CC) $(CFLAGS) -c $< -o $@

bin/utils.o: src/utils.c
	$(CC) $(CFLAGS) -c $< -o $@

bin/string.o: src/string.c
	$(CC) $(CFLAGS) -c $< -o $@

bin/stdio.o: src/stdio.c
	$(CC) $(CFLAGS) -c $< -o $@

bin/gdt.o: src/gdt.c
	$(CC) $(CFLAGS) -c $< -o $@

bin/disk.o: src/disk.c
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -rf bin/
	rm -f $(OUTPUT)
	rm boot.iso

.PHONY: all clean
