Skip to content

Commit 8c96f95

Browse files
authored
Reorganise file structure of repo (#8)
* Move all kernel files to kernel/ * Move GNUmakefule to kernel * Add orchestrator makefile * Update build.sh * Fix format
1 parent d9a3ac9 commit 8c96f95

38 files changed

Lines changed: 31 additions & 13 deletions

.github/workflows/format-check.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ jobs:
1616
run: sudo apt-get install -y clang-format
1717

1818
- name: Run clang-format in dry-run mode
19-
run: |
20-
find src/ include/ -type f \( -name '*.c' -o -name '*.h' \) ! -name 'limine.h' -exec clang-format --Werror --dry-run {} +
19+
run: make format

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.PHONY: all kernel clean format
2+
3+
all: kernel
4+
5+
kernel:
6+
@echo "Building Kernel..."
7+
$(MAKE) -C kernel
8+
9+
format:
10+
@echo "Formatting Kernel..."
11+
$(MAKE) -C kernel format
12+
13+
clean:
14+
@echo "Cleaning Kernel..."
15+
$(MAKE) -C kernel clean

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ echo -e "\e[1;33m\n$(heading "Building OS binaries")\n\e[0m"
113113

114114
make -j$(nproc)
115115

116-
echo -e "\nentry.elf generated with size $(wc -c <"build/entry.elf") bytes"
116+
echo -e "\nentry.elf generated with size $(wc -c <"build/kernel/entry.elf") bytes"
117117

118118
echo -e "\e[1;33m\n$(heading "Building Limine-deploy")\n\e[0m"
119119

@@ -130,7 +130,7 @@ mkdir -p iso_root/boot/limine
130130

131131
# Copy the relevant files over.
132132
cp -v limine.conf limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/boot/limine/
133-
cp -v build/entry.elf iso_root/boot/
133+
cp -v build/kernel/entry.elf iso_root/boot/
134134

135135
# Create the EFI boot tree and copy Limine's EFI executables over.
136136
mkdir -p iso_root/EFI/BOOT

GNUmakefile renamed to kernel/GNUmakefile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,40 @@ endif
8181

8282
# Use "find" to glob all *.c, *.s, and *.asm files in the tree and obtain the
8383
# object and header dependency file names.
84-
override CFILES := $(shell find -L . -type f -name '*.c' | grep -v 'limine/')
85-
override ASFILES := $(shell find -L . -type f -name '*.s' | grep -v 'limine/')
86-
override OBJ := $(patsubst %.c,build/%.c.o,$(CFILES)) $(patsubst %.s,build/%.s.o,$(ASFILES))
87-
override HEADER_DEPS := $(patsubst %.c,build/%.c.d,$(CFILES)) $(patsubst %.s,build/%.s.d,$(ASFILES))
84+
override CFILES := $(shell find -L . -type f -name '*.c')
85+
override ASFILES := $(shell find -L . -type f -name '*.s')
86+
87+
# Output directory for the build. Can be overridden.
88+
override BUILD_DIR := ../build/kernel
89+
90+
override OBJ := $(patsubst %.c,$(BUILD_DIR)/%.c.o,$(CFILES)) $(patsubst %.s,$(BUILD_DIR)/%.s.o,$(ASFILES))
91+
override HEADER_DEPS := $(patsubst %.c,$(BUILD_DIR)/%.c.d,$(CFILES)) $(patsubst %.s,$(BUILD_DIR)/%.s.d,$(ASFILES))
8892

8993
# Default target.
9094
.PHONY: all
91-
all: build/$(KERNEL)
95+
all: $(BUILD_DIR)/$(KERNEL)
9296

9397
# Link rules for the final kernel executable.
94-
build/$(KERNEL): $(OBJ)
98+
$(BUILD_DIR)/$(KERNEL): $(OBJ)
9599
$(LD) $(OBJ) $(LDFLAGS) -o $@
96100

97101
# Include header dependencies.
98102
-include $(HEADER_DEPS)
99103

100104
# Compilation rules for *.c files.
101-
build/%.c.o: %.c | $(BUILD_DIR)
105+
$(BUILD_DIR)/%.c.o: %.c
102106
@mkdir -p $(@D)
103107
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
104108

105109
# Compilation rules for *.S files.
106-
build/%.s.o: %.s
110+
$(BUILD_DIR)/%.s.o: %.s
107111
@mkdir -p $(@D)
108112
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
109113

110114
# Remove object files and the final executable.
111115
.PHONY: clean
112116
clean:
113-
rm -rf $(KERNEL) $(OBJ) $(HEADER_DEPS)
117+
rm -rf $(BUILD_DIR)
114118

115119
# Format C source and header files (only touches src/ and main/)
116120
.PHONY: format

0 commit comments

Comments
 (0)