From 8b6996cab8db7b7b6664e7de5d25f2e5314d7b78 Mon Sep 17 00:00:00 2001 From: Tom-on64 Date: Sun, 14 Apr 2024 18:48:15 +0200 Subject: [PATCH] Switched to using make instead of a build.sh script --- Makefile | 36 ++++++++++++++++++++++++++++++++++++ build.sh | 33 --------------------------------- 2 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 Makefile delete mode 100644 build.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cfe6f9b --- /dev/null +++ b/Makefile @@ -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 + diff --git a/build.sh b/build.sh deleted file mode 100644 index dee6c99..0000000 --- a/build.sh +++ /dev/null @@ -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 -