improve arch-specific build scripts

This commit is contained in:
Quinten Kock 2020-12-04 02:20:46 +01:00
parent 2cc8a36c11
commit 8b4fde6686
7 changed files with 16 additions and 11 deletions

3
.gitignore vendored
View File

@ -1,7 +1,6 @@
kornos.img
kernel/kernel*
bin/
obj/
*.o
zig-cache/

View File

@ -8,7 +8,7 @@ KERNEL_HDD = kornos.img
.DEFAULT_GOAL = $(KERNEL_HDD)
$(COMPONENTS):
$(MAKE) -C $@ $@-$(ARCH)
$(MAKE) -C $@ bin/$@-$(ARCH)
disk: $(KERNEL_HDD)
run: $(KERNEL_HDD)
@ -28,7 +28,7 @@ $(KERNEL_HDD): ext/limine/limine-install $(COMPONENTS)
parted -s $(KERNEL_HDD) mklabel msdos
parted -s $(KERNEL_HDD) mkpart primary 1 100%
echfs-utils -m -p0 $(KERNEL_HDD) quick-format 32768 > /dev/null # silence UUID
@for f in $(COMPONENTS); do echo "Installing $$f ($$(du -h $$f/$$f | cut -f1))"; echfs-utils -m -p0 $@ import $$f/$$f-$(ARCH) $$f; done
@for f in $(COMPONENTS); do echo "Installing $$f ($$(du -h $$f/bin/$$f-$(ARCH) | cut -f1))"; echfs-utils -m -p0 $@ import $$f/bin/$$f-$(ARCH) $$f; done
echfs-utils -m -p0 $(KERNEL_HDD) import ext/limine.cfg limine.cfg
ext/limine/limine-install ext/limine/limine.bin $(KERNEL_HDD)

View File

@ -4,13 +4,14 @@ ARCH ?= x86_64
CC = zig cc -target $(ARCH)-freestanding
LD = ld -m elf_$(ARCH)
LDSCRIPT = make/$(ARCH)/linker.ld
-include make.$(ARCH).config
-include make/$(ARCH)/make.config
CFLAGS ?= -O2
CFLAGS := $(CFLAGS) $(ARCH_CFLAGS) \
-Wall -Wextra -pedantic -Wno-language-extension-token -std=gnu11 -I../ext/limine/stivale -fPIE
LDFLAGS := $(LDFLAGS) -T linker.ld.$(ARCH)
LDFLAGS := $(LDFLAGS) -T $(LDSCRIPT)
TARGET := kernel
@ -20,16 +21,21 @@ ARCHFILES := $(shell find src/arch/$(ARCH) -type f -name '*.c' -print)
HFILES := $(shell find src -type f -name '*.h')
OBJ := $(patsubst src/%.c,obj/$(ARCH)/%.o,$(CFILES) $(ARCHFILES))
.PHONY: all clean obj
.PHONY: all clean obj dirs
all: $(TARGET)
all: bin/$(TARGET)-$(ARCH)
$(TARGET)-$(ARCH): $(OBJ)
bin/$(TARGET)-$(ARCH): $(OBJ)
mkdir -p bin
$(LD) $(LDFLAGS) $(OBJ) -o $@
obj/$(ARCH)/%.o: src/%.c $(HFILES)
@mkdir -p obj/$(ARCH)/arch/$(ARCH)
$(CC) $(CFLAGS) -c $< -o $@
dirs:
mkdir -p bin obj
mkdir -p $(patsubst src/%,obj/%, $(shell find src -type d -print))
clean:
rm -rf $(TARGET)* obj zig-cache
rm -rf bin obj zig-cache

View File

@ -1 +0,0 @@
ARCH_CFLAGS = -mcmodel=kernel

View File

@ -0,0 +1 @@
ARCH_CFLAGS = -mcmodel=kernel