aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNic Gaffney <gaffney_nic@protonmail.com>2024-02-22 22:59:47 -0600
committerNic Gaffney <gaffney_nic@protonmail.com>2024-02-22 22:59:47 -0600
commit8873d14c69ba8f22db794838845c01a044aabaa4 (patch)
treede63cae7030b1b5d3261137e205d4355da5c78a7
parent2ae431b4fb4460cc222f059a343dd8ecade8e1ea (diff)
downloadgftos-8873d14c69ba8f22db794838845c01a044aabaa4.tar.gz
Cleaned up makefile
-rw-r--r--.gitignore1
-rw-r--r--Makefile85
-rw-r--r--compile_flags.txt1
-rw-r--r--src/kernel/compile_flags.txt1
-rw-r--r--src/kernel/kernel.c1
-rw-r--r--src/kernel/keyboard/compile_flags.txt1
-rw-r--r--src/kernel/print.c1
-rw-r--r--src/kernel/tables/compile_flags.txt1
-rw-r--r--src/utils/compile_flags.txt1
9 files changed, 68 insertions, 25 deletions
diff --git a/.gitignore b/.gitignore
index a52f8ff..3fa9e7b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ build/
out/*.iso
out/isodir/boot/*.bin
bochs/*.txt
+.cache
diff --git a/Makefile b/Makefile
index c2d043c..a7285e3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+# Basic vars
OUT_DIR = out
SRC = src
BUILD = build
@@ -5,41 +6,50 @@ BOCHS = bochs
TESTS = tests
TEST = $(TESTS)/debug.rc
TARGET = i686-elf
-
ISO = gftos
+# Define source files
ASM := $(sort $(shell find $(SRC) -name '*.s'))
C := $(sort $(shell find $(SRC) -name '*.c'))
+# Includes
INCLUDE_DIR = $(SRC)/include
INCLUDES := -I$(INCLUDE_DIR)
+# Compiler / assembler
ASSEMBLER = nasm -felf32
CC = $(TARGET)-gcc
CFLAGS = $(INCLUDES) -std=gnu99 -ffreestanding -O2 -Wall -Wextra
TEST_FLAGS = -nographic
-
+# Linker info
LINK_FILE = linker.ld
LDFLAGS = -O2 -nostdlib -lgcc -ffreestanding
+# Objects
OBJS =
C_OBJS := $(C:$(SRC)/%.c=$(BUILD)/%.o)
ASM_OBJS := $(ASM:$(SRC)/%.s=$(BUILD)/%.o)
+# CRTI/CRTN objects
CRTBEGIN_OBJ := $(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o)
CRTEND_OBJ := $(shell $(CC) $(CFLAGS) -print-file-name=crtend.o)
CRTI_OBJ = $(BUILD)/boot/crti.o
CRTN_OBJ = $(BUILD)/boot/crtn.o
+# Add objects in order
OBJS += $(CRTI_OBJ) $(CRTBEGIN_OBJ)
OBJS += $(C_OBJS) $(ASM_OBJS)
OBJS += $(CRTEND_OBJ) $(CRTN_OBJ)
+# Objects we make & dependencies
INTERNAL_OBJS = $(CRTI_OBJ) $(ASM_OBJS) $(C_OBJS) $(CRTN_OBJ)
DEPS := $(OBJS:.o=.d)
+# Compile DB
+COMPDBS := $(C_OBJS:.o=.json)
+
.PHONY: all
# Build gftos
all: $(OUT_DIR)/$(ISO).iso
@@ -47,22 +57,34 @@ all: $(OUT_DIR)/$(ISO).iso
.PHONY: run
# Run gftos in qemu
run: all
- qemu-system-i386 -cdrom $(OUT_DIR)/$(ISO).iso
+ @qemu-system-i386 -cdrom $(OUT_DIR)/$(ISO).iso
+ @echo "QEMU \t$(OUT_DIR)/$(ISO).iso"
.PHONY: test
# Generate logfiles using bochs
test: all
- mkdir -p $(BOCHS)
- bochs -f .bochsrc -q -rc $(TEST)
+ @mkdir -p $(BOCHS)
+ @bochs -f .bochsrc -q -rc $(TEST) > /dev/null 2>&1
+ @echo "BOCHS \t$(TEST)"
.PHONY: clean
# Clean the build environment
clean:
- rm -rf $(BOCHS)
- rm -rf $(INTERNAL_OBJS)
- rm -rf $(OUT_DIR)/$(ISO).iso
- rm -rf $(OUT_DIR)/isodir/boot/$(ISO).bin
- rm -rf $(BUILD)
+ @rm -rf $(BOCHS)
+ @echo "RM \t$(BOCHS)"
+ @rm -rf $(INTERNAL_OBJS)
+ @for F in $(INTERNAL_OBJS); \
+ do echo "RM \t$$F"; done
+ @rm -rf $(OUT_DIR)/$(ISO).iso
+ @echo "RM \t$(OUT_DIR)/$(ISO).iso"
+ @rm -rf $(OUT_DIR)/isodir/boot/$(ISO).bin
+ @echo "RM \t$(OUT_DIR)/isodir/boot/$(ISO).bin"
+ @rm -rf $(BUILD)
+ @echo "RM \t$(BUILD)"
+
+.PHONY: compdb
+# Generate JSON compilation database
+compdb: $(BUILD)/compile_commands.json
# https://stackoverflow.com/a/35730928
.PHONY: help
@@ -70,18 +92,45 @@ clean:
help:
@awk '/^#/{c=substr($$0,3);next}c&&/^[[:alpha:]][[:alnum:]_-]+:/{print substr($$1,1,index($$1,":")),c}1{c=0}' $(MAKEFILE_LIST) | column -s: -t
+# ISO recipe (requires .bin)
$(OUT_DIR)/$(ISO).iso : $(OUT_DIR)/isodir/boot/$(ISO).bin
- grub-mkrescue -o $@ $(OUT_DIR)/isodir
+ @grub-mkrescue -o $@ $(OUT_DIR)/isodir 2>/dev/null
+ @echo "GRUB \t$<"
+# .bin Recipe (requires objects)
$(OUT_DIR)/isodir/boot/$(ISO).bin : $(OBJS)
- $(CC) -T $(SRC)/$(LINK_FILE) -o $@ $(LDFLAGS) $^
+ @$(CC) -T $(SRC)/$(LINK_FILE) -o $@ $(LDFLAGS) $^
+ @echo "LD \t$(SRC)/$(LINK_FILE)"
+# ASM object recipes
$(BUILD)/%.o: $(SRC)/%.s
- mkdir -p $(BUILD)
- mkdir -p $(@D)
- $(ASSEMBLER) $^ -o $@
+ @mkdir -p $(BUILD)
+ @mkdir -p $(@D)
+ @$(ASSEMBLER) $^ -o $@
+ @echo "AS \t$<"
+# C object recipes
$(BUILD)/%.o: $(SRC)/%.c
- mkdir -p $(BUILD)
- mkdir -p $(@D)
- $(CC) $(CFLAGS) -c $^ -o $@
+ @mkdir -p $(BUILD)
+ @mkdir -p $(@D)
+ @$(CC) $(CFLAGS) -c $^ -o $@
+ @echo "CC \t$<"
+
+# COMPDB recipe (looks at all compdbs)
+$(BUILD)/compile_commands.json: $(COMPDBS)
+ @mkdir -p $(@D)
+ @printf "[\n" > $@
+ @sed -e '$$s/$$/,/' -s $(COMPDBS) | sed -e '$$s/,$$//' -e 's/^/ /' >> $@
+ @printf "]\n" >> $@
+ @for F in $(COMPDBS); \
+ do echo "COMPDB \t$$F"; done;
+
+# JSON recipe (looks at C files)
+$(BUILD)/%.json: $(SRC)/%.c
+ @mkdir -p $(@D)
+ @printf "\
+ {\n\
+ \"directory\": \"$(CURDIR)\",\n\
+ \"command\": \"$(CC) $(CFLAGS) -c $< -o $(basename $@).o\",\n\
+ \"file\": \"$<\"\n\
+ }\n" > $@
diff --git a/compile_flags.txt b/compile_flags.txt
deleted file mode 100644
index cec6042..0000000
--- a/compile_flags.txt
+++ /dev/null
@@ -1 +0,0 @@
--I src/include/
diff --git a/src/kernel/compile_flags.txt b/src/kernel/compile_flags.txt
deleted file mode 100644
index 11ef7f9..0000000
--- a/src/kernel/compile_flags.txt
+++ /dev/null
@@ -1 +0,0 @@
--I../include/
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 7dd3deb..d960c20 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -1,4 +1,3 @@
-#include "asm.h"
#include "gdt.h"
#include "isr.h"
#include "print.h"
diff --git a/src/kernel/keyboard/compile_flags.txt b/src/kernel/keyboard/compile_flags.txt
deleted file mode 100644
index 2af49c7..0000000
--- a/src/kernel/keyboard/compile_flags.txt
+++ /dev/null
@@ -1 +0,0 @@
--I../../include/
diff --git a/src/kernel/print.c b/src/kernel/print.c
index 3ddb445..f635fe5 100644
--- a/src/kernel/print.c
+++ b/src/kernel/print.c
@@ -6,7 +6,6 @@
// Constants
static const size_t NUM_COLS = 80;
static const size_t NUM_ROWS = 25;
-static uint8_t cursor = 0;
// Char struct
struct Char {
diff --git a/src/kernel/tables/compile_flags.txt b/src/kernel/tables/compile_flags.txt
deleted file mode 100644
index 2af49c7..0000000
--- a/src/kernel/tables/compile_flags.txt
+++ /dev/null
@@ -1 +0,0 @@
--I../../include/
diff --git a/src/utils/compile_flags.txt b/src/utils/compile_flags.txt
deleted file mode 100644
index b02b210..0000000
--- a/src/utils/compile_flags.txt
+++ /dev/null
@@ -1 +0,0 @@
--I../include