summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksa Vučković <aleksav013@gmail.com>2021-10-25 00:36:33 +0200
committerAleksa Vučković <aleksav013@gmail.com>2021-10-25 00:36:33 +0200
commit20dd72e40dc2728d3c5335d860e4b8ab8da14fcc (patch)
treedabdfdf736c45f9632fa1388d2144b1de7a438b0
parent0bca634f7e70b05239f46f3bd40bb37468d67957 (diff)
Changing build system to recursive make
-rw-r--r--Makefile70
-rw-r--r--src/as/Makefile5
-rw-r--r--src/as/boot.s (renamed from src/boot.s)0
-rw-r--r--src/as/crti.s (renamed from src/crti.s)0
-rw-r--r--src/as/crtn.s (renamed from src/crtn.s)0
-rw-r--r--src/c/Makefile5
-rw-r--r--src/c/gdt.c (renamed from src/gdt.c)2
-rw-r--r--src/c/heap.c (renamed from src/heap.c)2
-rw-r--r--src/c/idt.c (renamed from src/idt.c)2
-rw-r--r--src/c/kernel.c (renamed from src/kernel.c)5
-rw-r--r--src/c/keyboard.c (renamed from src/keyboard.c)6
-rw-r--r--src/c/keymap.c (renamed from src/keymap.c)0
-rw-r--r--src/c/stdio.c (renamed from src/stdio.c)4
-rw-r--r--src/c/string.c (renamed from src/string.c)2
-rw-r--r--src/c/tty.c (renamed from src/tty.c)8
-rw-r--r--src/c/vga.c (renamed from src/vga.c)6
-rw-r--r--src/include/asm.h (renamed from src/asm.h)0
-rw-r--r--src/include/heap.h (renamed from src/heap.h)0
-rw-r--r--src/include/stdio.h (renamed from src/stdio.h)0
-rw-r--r--src/include/string.h (renamed from src/string.h)0
-rw-r--r--src/include/types.h (renamed from src/types.h)0
21 files changed, 66 insertions, 51 deletions
diff --git a/Makefile b/Makefile
index dc2c620..7e99767 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
ARCH=i686-elf
-CC=$(ARCH)-gcc
-AS=$(ARCH)-as
-CFLAGS=-ffreestanding -O2 -Wall -Wextra
+export CC=$(ARCH)-gcc
+export AS=$(ARCH)-as
+export CFLAGS=-ffreestanding -O2 -Wall -Wextra
MKDIR=mkdir -p
RM=rm -rf
@@ -10,24 +10,49 @@ CP=cp
QEMU=qemu-system-x86_64
SOURCE_DIR=src
-BUILD_DIR=build
+AS_SOURCE_DIR=$(SOURCE_DIR)/as
+C_SOURCE_DIR=$(SOURCE_DIR)/c
+export BUILD_DIR=${CURDIR}/build
ISO_DIR=isodir
TARGET=myos
BINARY=$(BUILD_DIR)/$(TARGET).bin
ISO=$(TARGET).iso
-OBJ_FILES=boot.o kernel.o gdt.o idt.o keyboard.o keymap.o vga.o string.o tty.o stdio.o heap.o
+CRTI_SOURCE=crti.s
+CRTN_SOURCE=crtn.s
+AS_SOURCE=boot.s
+C_SOURCES=gdt.c heap.c idt.c kernel.c keyboard.c keymap.c stdio.c string.c tty.c vga.c
+
+C_SOURCE_FILES=$(patsubst %,$(C_SOURCE_DIR)/%,$(C_SOURCES))
+export C_OBJECTS=$(patsubst %,$(BUILD_DIR)/%,$(C_SOURCES:c=o))
+
+AS_OBJECT=$(patsubst %,$(BUILD_DIR)/%,$(AS_SOURCE:s=o))
+CRTI_OBJECT=$(patsubst %,$(BUILD_DIR)/%,$(CRTI_SOURCE:s=o))
+CRTN_OBJECT=$(patsubst %,$(BUILD_DIR)/%,$(CRTN_SOURCE:s=o))
+
+AS_SOURCES=$(AS_SOURCE) $(CRTI_SOURCE) $(CRTN_SOURCE)
+AS_SOURCE_FILES=$(patsubst %,$(AS_SOURCE_DIR)/%,$(AS_SOURCES))
+export AS_OBJECTS=$(patsubst %,$(BUILD_DIR)/%,$(AS_SOURCES:s=o))
+
CRTBEGIN_OBJ=$(shell $(CC) -print-file-name=crtbegin.o)
CRTEND_OBJ=$(shell $(CC) -print-file-name=crtend.o)
-OBJ=$(BUILD_DIR)/crti.o $(CRTBEGIN_OBJ) $(patsubst %,$(BUILD_DIR)/%,$(OBJ_FILES)) $(CRTEND_OBJ) $(BUILD_DIR)/crtn.o
+OBJ=$(CRTI_OBJECT) $(CRTBEGIN_OBJ) $(AS_OBJECT) $(C_OBJECTS) $(CRTEND_OBJ) $(CRTN_OBJECT)
-# Default action is set to making kernel binary
-.PHONY: all run run-iso clean
-all: $(BINARY)
-# Creating iso file
+.PHONY: all compile run run-iso clean
+all: compile
+
+$(BINARY): $(OBJ)
+ $(CC) -T $(SOURCE_DIR)/linker.ld -o $(BINARY) $(CFLAGS) -nostdlib -lgcc $(OBJ)
+
+compile: $(AS_SOURCE_FILES) $(C_SOURCE_FILES)
+ $(MKDIR) $(BUILD_DIR)
+ $(MAKE) --directory $(AS_SOURCE_DIR)
+ $(MAKE) --directory $(C_SOURCE_DIR)
+ $(MAKE) $(BINARY)
+
$(ISO): $(BINARY)
grub-file --is-x86-multiboot $(BINARY)
mkdir -p $(ISO_DIR)/boot/grub
@@ -35,28 +60,11 @@ $(ISO): $(BINARY)
$(CP) $(SOURCE_DIR)/grub.cfg $(ISO_DIR)/boot/grub/grub.cfg
grub-mkrescue -o $(ISO) $(ISO_DIR)
-# Linking object files into kernel binary
-$(BINARY): $(OBJ)
- $(CC) -T $(SOURCE_DIR)/linker.ld -o $@ $(CFLAGS) -nostdlib $^ -lgcc
-
-# Compiling as sources
-$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.s
- $(MKDIR) $(BUILD_DIR)
- $(AS) $< -o $@
-
-# Compiling C sources
-$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c
- $(MKDIR) $(BUILD_DIR)
- $(CC) -c $< -o $@ -std=gnu99 $(CFLAGS)
-
-# Boot kernel binary in qemu
-run: $(BINARY)
- $(QEMU) -kernel $<
+run: compile
+ $(QEMU) -kernel $(BINARY)
-# Boot iso in qemu
-run-iso: $(ISO)
- $(QEMU) -cdrom $<
+run-iso: compile $(ISO)
+ $(QEMU) -cdrom $(ISO)
-# Clean build files
clean:
$(RM) $(BUILD_DIR) $(ISO_DIR) $(ISO)
diff --git a/src/as/Makefile b/src/as/Makefile
new file mode 100644
index 0000000..e2c476d
--- /dev/null
+++ b/src/as/Makefile
@@ -0,0 +1,5 @@
+.PHONY: all
+all: $(AS_OBJECTS)
+
+$(BUILD_DIR)/%.o: %.s
+ $(AS) $< -o $@
diff --git a/src/boot.s b/src/as/boot.s
index 6fe5ab8..6fe5ab8 100644
--- a/src/boot.s
+++ b/src/as/boot.s
diff --git a/src/crti.s b/src/as/crti.s
index 30dd4ea..30dd4ea 100644
--- a/src/crti.s
+++ b/src/as/crti.s
diff --git a/src/crtn.s b/src/as/crtn.s
index 1da795d..1da795d 100644
--- a/src/crtn.s
+++ b/src/as/crtn.s
diff --git a/src/c/Makefile b/src/c/Makefile
new file mode 100644
index 0000000..7c5d1af
--- /dev/null
+++ b/src/c/Makefile
@@ -0,0 +1,5 @@
+.PHONY: all
+all: $(C_OBJECTS)
+
+$(BUILD_DIR)/%.o: %.c
+ $(CC) -c $< -o $@ -std=gnu99 $(CFLAGS)
diff --git a/src/gdt.c b/src/c/gdt.c
index 31eb560..8fcda3a 100644
--- a/src/gdt.c
+++ b/src/c/gdt.c
@@ -1,4 +1,4 @@
-#include"types.h"
+#include"../include/types.h"
struct gdt_entry
{
diff --git a/src/heap.c b/src/c/heap.c
index 9b86ad6..1bad05e 100644
--- a/src/heap.c
+++ b/src/c/heap.c
@@ -1,4 +1,4 @@
-#include"types.h"
+#include"../include/types.h"
/*
2014 Leonard Kevin McGuire Jr (www.kmcg3413.net) (kmcg3413@gmail.com)
diff --git a/src/idt.c b/src/c/idt.c
index 1d327ce..274db6d 100644
--- a/src/idt.c
+++ b/src/c/idt.c
@@ -1,4 +1,4 @@
-#include"types.h"
+#include"../include/types.h"
#define INTERRUPT_GATE_32 0x8e
diff --git a/src/kernel.c b/src/c/kernel.c
index b77bf2c..e18a7c0 100644
--- a/src/kernel.c
+++ b/src/c/kernel.c
@@ -1,13 +1,10 @@
-#include"heap.h"
-#include"stdio.h"
+#include"../include/heap.h"
void terminal_initialize(void);
void init_idt_table(void);
void init_keyboard(void);
void prompt(void);
-void *f();
-
void kernel_main(void)
{
terminal_initialize();
diff --git a/src/keyboard.c b/src/c/keyboard.c
index c945acd..548cdda 100644
--- a/src/keyboard.c
+++ b/src/c/keyboard.c
@@ -1,6 +1,6 @@
-#include"types.h"
-#include"asm.h"
-#include"stdio.h"
+#include"../include/types.h"
+#include"../include/asm.h"
+#include"../include/stdio.h"
#define BUFFER_SIZE 200
char buffer[BUFFER_SIZE];
diff --git a/src/keymap.c b/src/c/keymap.c
index 04c79b2..04c79b2 100644
--- a/src/keymap.c
+++ b/src/c/keymap.c
diff --git a/src/stdio.c b/src/c/stdio.c
index e93dea1..83d2b0a 100644
--- a/src/stdio.c
+++ b/src/c/stdio.c
@@ -1,5 +1,5 @@
-#include"types.h"
-#include"string.h"
+#include"../include/types.h"
+#include"../include/string.h"
#include<stdarg.h>
void terminal_putchar(char c);
diff --git a/src/string.c b/src/c/string.c
index b0c42f2..5667715 100644
--- a/src/string.c
+++ b/src/c/string.c
@@ -1,4 +1,4 @@
-#include"types.h"
+#include"../include/types.h"
size_t stringlen(char *str)
{
diff --git a/src/tty.c b/src/c/tty.c
index 9fc8a39..5728a47 100644
--- a/src/tty.c
+++ b/src/c/tty.c
@@ -1,6 +1,6 @@
-#include"types.h"
-#include"string.h"
-#include"stdio.h"
+#include"../include/types.h"
+#include"../include/string.h"
+#include"../include/stdio.h"
#define CMD_LENGTH 20
@@ -48,7 +48,7 @@ void merge(char parts[][CMD_LENGTH])
void ls(size_t numberof,char parts[][CMD_LENGTH])
{
- printf("filesystem not implemented yet\n");
+ printf("filesystem not implemented yet, %d,%s\n",numberof,parts[0]);
}
void number(size_t numberof,char parts[][CMD_LENGTH])
diff --git a/src/vga.c b/src/c/vga.c
index 5bd2caf..07dec60 100644
--- a/src/vga.c
+++ b/src/c/vga.c
@@ -1,6 +1,6 @@
-#include"types.h"
-#include"string.h"
-#include"asm.h"
+#include"../include/types.h"
+#include"../include/string.h"
+#include"../include/asm.h"
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
diff --git a/src/asm.h b/src/include/asm.h
index 1d61b88..1d61b88 100644
--- a/src/asm.h
+++ b/src/include/asm.h
diff --git a/src/heap.h b/src/include/heap.h
index 2f66501..2f66501 100644
--- a/src/heap.h
+++ b/src/include/heap.h
diff --git a/src/stdio.h b/src/include/stdio.h
index 2d0aa8a..2d0aa8a 100644
--- a/src/stdio.h
+++ b/src/include/stdio.h
diff --git a/src/string.h b/src/include/string.h
index 500f545..500f545 100644
--- a/src/string.h
+++ b/src/include/string.h
diff --git a/src/types.h b/src/include/types.h
index a6d6530..a6d6530 100644
--- a/src/types.h
+++ b/src/include/types.h