diff --git a/.gitignore b/.gitignore index 7e92dfc..0b2eec3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o bochslog.txt +build/ diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf index 3b8ed7b..faa52ed 100755 Binary files a/iso/boot/kernel.elf and b/iso/boot/kernel.elf differ diff --git a/kernel.elf b/kernel.elf index 3b8ed7b..faa52ed 100755 Binary files a/kernel.elf and b/kernel.elf differ diff --git a/makefile b/makefile index fff7463..f85980f 100644 --- a/makefile +++ b/makefile @@ -1,15 +1,30 @@ -OBJECTS = loader.o kmain.o stdio.o io.o string.o serial.o gdt.o idt.o system.o isr.o irq.o timer.o kb.o CC = gcc -CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c +CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c -I src/ LDFLAGS = -T link.ld -melf_i386 AS = nasm ASFLAGS = -f elf +SRC_DIR = src +OBJ_DIR = build -all: kernel.elf +C_SOURCES = $(wildcard $(SRC_DIR)/*.c) +ASM_SOURCES = $(wildcard $(SRC_DIR)/*.s) +OBJECTS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(C_SOURCES)) \ + $(patsubst $(SRC_DIR)/%.s, $(OBJ_DIR)/%.o, $(ASM_SOURCES)) + +all: $(OBJ_DIR) kernel.elf + +$(OBJ_DIR): + mkdir -p $(OBJ_DIR) kernel.elf: $(OBJECTS) ld $(LDFLAGS) $(OBJECTS) -o kernel.elf +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c + $(CC) $(CFLAGS) $< -o $@ + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.s + $(AS) $(ASFLAGS) $< -o $@ + os.iso: kernel.elf cp kernel.elf iso/boot/kernel.elf genisoimage -R \ @@ -26,10 +41,5 @@ os.iso: kernel.elf run: os.iso bochs -f bochsrc.txt -q -%.o: %.c - $(CC) $(CFLAGS) $< -o $@ -%.o: %.s - $(AS) $(ASFLAGS) $< -o $@ - clean: - rm -rf *.o kernel.elf os.iso + rm -rf $(OBJ_DIR) *.o kernel.elf os.iso diff --git a/gdt.c b/src/gdt.c similarity index 100% rename from gdt.c rename to src/gdt.c diff --git a/gdt.h b/src/gdt.h similarity index 100% rename from gdt.h rename to src/gdt.h diff --git a/idt.c b/src/idt.c similarity index 100% rename from idt.c rename to src/idt.c diff --git a/idt.h b/src/idt.h similarity index 100% rename from idt.h rename to src/idt.h diff --git a/io.h b/src/io.h similarity index 100% rename from io.h rename to src/io.h diff --git a/io.s b/src/io.s similarity index 100% rename from io.s rename to src/io.s diff --git a/irq.c b/src/irq.c similarity index 100% rename from irq.c rename to src/irq.c diff --git a/isr.c b/src/isr.c similarity index 100% rename from isr.c rename to src/isr.c diff --git a/kb.c b/src/kb.c similarity index 100% rename from kb.c rename to src/kb.c diff --git a/kmain.c b/src/kmain.c similarity index 100% rename from kmain.c rename to src/kmain.c diff --git a/loader.s b/src/loader.s similarity index 100% rename from loader.s rename to src/loader.s diff --git a/serial.c b/src/serial.c similarity index 100% rename from serial.c rename to src/serial.c diff --git a/serial.h b/src/serial.h similarity index 100% rename from serial.h rename to src/serial.h diff --git a/stdint.h b/src/stdint.h similarity index 100% rename from stdint.h rename to src/stdint.h diff --git a/stdio.c b/src/stdio.c similarity index 100% rename from stdio.c rename to src/stdio.c diff --git a/stdio.h b/src/stdio.h similarity index 100% rename from stdio.h rename to src/stdio.h diff --git a/string.c b/src/string.c similarity index 100% rename from string.c rename to src/string.c diff --git a/string.h b/src/string.h similarity index 100% rename from string.h rename to src/string.h diff --git a/system.c b/src/system.c similarity index 100% rename from system.c rename to src/system.c diff --git a/system.h b/src/system.h similarity index 100% rename from system.h rename to src/system.h diff --git a/timer.c b/src/timer.c similarity index 100% rename from timer.c rename to src/timer.c