begin fixing build errors

This commit is contained in:
vmttmv
2025-10-26 03:03:20 +03:00
parent c22f6b6f14
commit 9216673b18
18 changed files with 111 additions and 78 deletions

View File

@@ -1,5 +1,6 @@
AS = nasm
CC = gcc
CFLAGS = -std=c11 -m32 -ffreestanding -c -fno-stack-protector -fno-pie
LD = ld
QEMU = qemu-system-i386
IMG_SIZE = 1440k
@@ -10,8 +11,15 @@ BOOT_SRC = bootloader/boot.asm
BOOT_OBJ = $(BUILD_DIR)/boot.o
BOOT_ELF = $(BUILD_DIR)/boot.elf
BOOT_IMG = $(BUILD_DIR)/boot.img
KERNEL_SRC = kernel/kmain.c
KERNEL_C_SRC = $(wildcard kernel/*.c)
KERNEL_ASM_SRC = $(wildcard kernel/*.asm)
KERNEL_OBJ = $(patsubst kernel/%.c, $(BUILD_DIR)/%.o, $(KERNEL_C_SRC))
KERNEL_OBJ += $(patsubst kernel/%.asm, $(BUILD_DIR)/asm_%.o, $(KERNEL_ASM_SRC))
KERNEL_OBJ += $(BUILD_DIR)/boot1.o
KERNEL_ELF = $(BUILD_DIR)/kernel.elf
KERNEL_BIN = $(BUILD_DIR)/kernel.bin
DISK_IMG = $(BUILD_DIR)/disk.img
all: $(BOOT_IMG) $(KERNEL_BIN) $(DISK_IMG)
@@ -29,9 +37,17 @@ $(BOOT_IMG): $(BOOT_ELF)
objcopy -O binary $< $@
truncate -s $(IMG_SIZE) $@
$(KERNEL_BIN): $(KERNEL_SRC) | $(BUILD_DIR)
$(CC) -ffreestanding -c $< -o $(BUILD_DIR)/kernel.o
$(LD) -T bootloader/linker.ld -o $@ $(BUILD_DIR)/kernel.o
$(BUILD_DIR)/boot1.o: bootloader/boot1.asm
$(AS) -f elf32 -o $@ $<
$(BUILD_DIR)/asm_%.o: kernel/%.asm
$(AS) -f elf32 -o $@ $<
$(BUILD_DIR)/%.o: kernel/%.c
$(CC) $(CFLAGS) $< -o $@
$(KERNEL_BIN): $(KERNEL_OBJ) | $(BUILD_DIR)
$(LD) -melf_i386 --oformat binary -T bootloader/linker.ld -o $@ $(KERNEL_OBJ)
$(DISK_IMG): $(BOOT_IMG) $(KERNEL_BIN)
dd if=$(BOOT_IMG) of=$@ bs=512 seek=4