# Настройки
CC = gcc
AS = nasm
LD = ld

# Добавь эти флаги в CFLAGS:
CFLAGS = -m32 -ffreestanding -O2 -Wall -Wextra \
         -fno-stack-protector -fno-exceptions \
         -fno-pie -fno-stack-protector \
         -fno-asynchronous-unwind-tables \
         -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -mno-mmx \
         -I./src
ASFLAGS = -f elf32
LDFLAGS = -m elf_i386 -T linker.ld -nostdlib
BMP_FILES := $(wildcard assets/*.bmp)
BMP_OBJS  := $(patsubst assets/%.bmp, assets/%.o, $(BMP_FILES))
# Файлы
SOURCES = $(wildcard src/*.c)
ASM_SOURCES = $(wildcard src/*.asm)
OBJECTS = $(patsubst %.c,%.o,$(wildcard src/*.c)) $(patsubst %.asm,%.o,$(wildcard src/*.asm))
TARGET = kernel.bin

all: $(TARGET) iso

assets/%.o: assets/%.bmp
	@mkdir -p assets
	objcopy -I binary -O elf32-i386 -B i386 $< $@

# Сборка ядра
$(TARGET): $(OBJECTS) $(BMP_OBJS)
	$(LD) $(LDFLAGS) -o $@ $(OBJECTS) $(BMP_OBJS)

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

%.o: %.asm
	$(AS) $(ASFLAGS) $< -o $@

# Сборка ISO
iso: $(TARGET)
	mkdir -p iso/boot/
	cp $(TARGET) iso/boot/
	grub-mkrescue -o zalupa.iso iso/

run: iso
	qemu-system-i386 -vga std -cdrom zalupa.iso -serial stdio -monitor none #-d int,cpu_reset -no-reboot -no-shutdown

clean:
	rm -f src/*.o assets/*.o $(TARGET) zalupa.iso
	rm -rf iso/boot/$(TARGET)
