summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-07-20 16:02:49 +0200
committerCarlos Maiolino <[email protected]>2025-07-20 16:02:49 +0200
commit05a32c2b36552deff0c74a2aab8de07811eb92b1 (patch)
tree2407b383d717cb9162ba9a4b38ee6f4f29e36f04 /Makefile
parentc6882778696fe40b799887d35ec3f4b48792abaf (diff)
Tidy up Makefile
Remove some duplicate code by creating a few variables Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile39
1 files changed, 24 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index eccede7..af36f24 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,17 @@
-FILLES = ./build/kernel.asm.o ./build/kernel.o
-INCLUDES= -I./src/include
-FLAGS= -g -ffreestanding -falign-jumps -falign-functions \
+BUILD_DIR = ./build
+
+BOOT_ASM =./src/boot/bootloader.asm
+
+KERNEL_ASM_OBJ = $(BUILD_DIR)/kernel.asm.o
+KERNEL_OBJ = $(BUILD_DIR)/kernel.o
+KOBJ_FILES = $(KERNEL_ASM_OBJ) $(KERNEL_OBJ)
+
+BOOT_TGT =./bin/boot.bin
+KERNEL_TGT = ./bin/kernel.bin
+BIN_TGT = $(BOOT_TGT) $(KERNEL_TGT)
+
+INCLUDES = -I./src/include
+FLAGS = -g -ffreestanding -falign-jumps -falign-functions \
-falign-labels -falign-loops -fstrength-reduce \
-fomit-frame-pointer -finline-functions \
-Wno-unused-function -fno-builtin -Werror \
@@ -8,26 +19,24 @@ FLAGS= -g -ffreestanding -falign-jumps -falign-functions \
-nostdlib -nostartfiles -nodefaultlibs -Wall -O0 -Iinc \
-BOOTLOADER=./src/boot/bootloader.asm
-TARGET=./bin/boot.bin
-all: ./bin/boot.bin ./bin/kernel.bin
+all: $(BIN_TGT)
rm -rf ./bin/os.bin
dd if=./bin/boot.bin >> ./bin/os.bin
dd if=./bin/kernel.bin >> ./bin/os.bin
dd if=/dev/zero bs=512 count=100 >> ./bin/os.bin
-./bin/kernel.bin: ./build/kernel.asm.o ./build/kernel.o
- i686-elf-ld -g -relocatable ./build/kernel.asm.o ./build/kernel.o -o ./build/cemOS.o
- i686-elf-gcc $(FLAGS) -T ./src/linker.ld -o ./bin/kernel.bin -ffreestanding -O0 -nostdlib ./build/cemOS.o
+./bin/kernel.bin: $(KOBJ_FILES)
+ i686-elf-ld -g -relocatable $(KOBJ_FILES) -o $(BUILD_DIR)/cemOS.o
+ i686-elf-gcc $(FLAGS) -T ./src/linker.ld -o ./bin/kernel.bin -ffreestanding -O0 -nostdlib $(BUILD_DIR)/cemOS.o
-./bin/boot.bin: ./src/boot/bootloader.asm
- nasm -f bin $(BOOTLOADER) -o $(TARGET)
+./bin/boot.bin: $(BOOT_ASM)
+ nasm -f bin $(BOOT_ASM) -o $(TARGET)
-./build/kernel.asm.o: ./src/kernel.asm
- nasm -f elf -g ./src/kernel.asm -o ./build/kernel.asm.o
+$(BUILD_DIR)/kernel.asm.o: ./src/kernel.asm
+ nasm -f elf -g ./src/kernel.asm -o $(BUILD_DIR)/kernel.asm.o
-./build/kernel.o: ./src/kernel.c
- i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./src/kernel.c -o ./build/kernel.o
+$(BUILD_DIR)/kernel.o: ./src/kernel.c
+ i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./src/kernel.c -o $(BUILD_DIR)/kernel.o
clean:
rm -f $(TARGET)