summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authordzwdz2021-07-10 16:37:45 +0200
committerdzwdz2021-07-10 16:37:45 +0200
commitd093a8eea6bfb0ff7e621e9ba3307dae698322aa (patch)
tree08a5272e2813cf8db8feda4ff91d919cb9ad7330 /Makefile
parent1faac72e2514c335e2d5721dce8c9fd1da722062 (diff)
separate the source code from object files; more modular Makefile
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile42
1 files changed, 22 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index da06cb5..35bb882 100644
--- a/Makefile
+++ b/Makefile
@@ -2,41 +2,43 @@ AS = i686-elf-as
CC = i686-elf-gcc
CFLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra
CFLAGS += -mgeneral-regs-only
-CFLAGS += -I.
+CFLAGS += -Isrc/
LFLAGS = -ffreestanding -O2 -nostdlib -lgcc
QFLAGS = -no-reboot -d guest_errors,int,pcall,cpu_reset
-OBJ = $(patsubst %.s,%.o,$(wildcard platform/*.s))
-OBJ += $(patsubst %.c,%.o,$(wildcard kernel/*.c))
+OBJ = $(patsubst src/%.s,out/obj/%.s.o,$(shell find src/ -type f -name '*.s'))
+OBJ += $(patsubst src/%.c,out/obj/%.c.o,$(shell find src/ -type f -name '*.c'))
.PHONY: boot debug clean
-boot: kernel.bin
- qemu-system-i386 -kernel kernel.bin $(QFLAGS) -no-shutdown
+boot: out/fs/boot/kernel.bin
+ qemu-system-i386 -kernel $< $(QFLAGS) -no-shutdown
debug: kernel.bin
- qemu-system-i386 -kernel kernel.bin $(QFLAGS) -s -S &
+ qemu-system-i386 -kernel $< $(QFLAGS) -s -S &
sleep 1
gdb
clean:
- rm -vf kernel.bin
- rm -vf **/*.o
-
-boot.iso: kernel.bin grub.cfg
- mkdir iso_tmp
- mkdir -p iso_tmp/boot/grub
- cp kernel.bin iso_tmp/boot
- cp grub.cfg iso_tmp/boot/grub
- grub-mkrescue -o $@ iso_tmp
- rm -rv iso_tmp
-
-kernel.bin: $(OBJ)
+ rm -rv out/
+
+
+out/boot.iso: out/fs/boot/kernel.bin out/fs/boot/grub/grub.cfg
+ grub-mkrescue -o $@ out/fs/
+
+out/fs/boot/grub/grub.cfg: grub.cfg
+ @mkdir -p $(@D)
+ cp $< $@
+
+out/fs/boot/kernel.bin: $(OBJ)
+ @mkdir -p $(@D)
$(CC) $(LFLAGS) -T linker.ld $^ -o $@
grub-file --is-x86-multiboot $@
-platform/%.o: platform/%.s
+out/obj/%.s.o: src/%.s
+ @mkdir -p $(@D)
$(AS) $^ -o $@
-%.o: %.c
+out/obj/%.c.o: src/%.c
+ @mkdir -p $(@D)
$(CC) $(CFLAGS) -c $^ -o $@