Switched to using make instead of a build.sh script

This commit is contained in:
2024-04-14 18:48:15 +02:00
parent b449663016
commit 8b6996cab8
2 changed files with 36 additions and 33 deletions
+36
View File
@@ -0,0 +1,36 @@
# Variables
CC = i386-elf-gcc
LD = i386-elf-ld
AS = nasm
CFLAGS = -ffreestanding -m32 -Iinclude -Wall -Wextra
SRC = ./src
BUILD = ./build
# C_FILES = $(shell find $(SRC) -name "*.c" -exec basename -s ".c" {} \;)
# Main compilation target
os: bootloader kernel
@cat $(BUILD)/boot.bin $(BUILD)/kernel.bin > $(BUILD)/os.bin
@dd if=/dev/zero of=kern.iso bs=512 count=2880
@dd if=$(BUILD)/os.bin of=kern.iso conv=notrunc
# Bootloader: This target is responsible for creating boot.bin
bootloader:
@$(AS) -fbin -o $(BUILD)/boot.bin $(SRC)/boot.asm
# Kernel: This target is responsible for creating kernel.bin
kernel: $(C_FILES) $(SRC)/entry.asm
@$(AS) -felf32 -o $(BUILD)/entry.o $(SRC)/entry.asm
@$(CC) $(CFLAGS) -o $(BUILD)/kernel.o -c $(SRC)/kernel.c
@$(LD) -Tkernel.ld --oformat binary -o $(BUILD)/kernel.bin $(BUILD)/*.o
# Run QEMU
run:
qemu-system-x86_64 -drive format=raw,file="./kern.iso",index=0,media=disk -m 256M -accel tcg
# Clean all build files
clean:
@rm -rf $(BUILD)/*
@rm -f kern.iso
-33
View File
@@ -1,33 +0,0 @@
#!/bin/bash
[[ -d ./build ]] || mkdir build
rm -rf ./build/**
# Bootloader
echo "Assembling ./src/boot.asm..."
nasm -fbin ./src/boot.asm -o ./build/boot.bin
# Kernel
echo "Assembling ./src/entry.asm..."
nasm -felf32 ./src/entry.asm -o ./build/entry.o
for file in ./src/*.c; do
filename=$(basename "$file" .c)
echo "Compiling $file..."
i386-elf-gcc -ffreestanding -Wall -Wextra -m32 -Iinclude -c "$file" -o "./build/$filename.o"
done
i386-elf-ld -o ./build/kernel.bin -Tkernel.ld --oformat binary ./build/*.o
# OS Image
echo "Creating kern.iso disk image..."
cat build/boot.bin build/kernel.bin > build/os.bin
dd if=/dev/zero of=./kern.iso bs=512 count=2880
dd if=./build/os.bin of=./kern.iso conv=notrunc
echo -e "\nDone!\n"
# Run QEMU
qemu-system-x86_64 -drive format=raw,file="./kern.iso",index=0,media=disk -m 256M -accel tcg