diff options
author | Freya Murphy <freya@freyacat.org> | 2024-02-04 14:19:54 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-02-04 14:19:54 -0500 |
commit | 1b09896afcf562d199d4df8d671601bba2b1f081 (patch) | |
tree | b4ee4ae8e6e1ff5c5b27fe97509752b17fae330b /Makefile | |
parent | fix acpi on uefi, kprint fixes (diff) | |
download | corn-main.tar.gz corn-main.tar.bz2 corn-main.zip |
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 46 |
1 files changed, 34 insertions, 12 deletions
@@ -1,10 +1,14 @@ -KERNEL=kernel.bin -ISO=os_image.iso +# +# Makefile Configuration +# -ARCH=amd64 CC=cc LD=ld AS=nasm +ARCH=amd64 +ARCH_COMMON=x86_common + +BUILD=build CFLAGS += -std=c2x -ffreestanding -lgcc -isystem include -pipe CFLAGS += -Wall -Wextra -pedantic @@ -13,24 +17,37 @@ CFLAGS += -DPAGE_SIZE=4096 LDFLAGS += -nmagic --no-warn-rwx-segments -nostdlib -H_SRC = $(shell find src include -type f -name "*.h") +# +# Makefile +# + +ARCH_COMMON += $(ARCH) -C_SRC = $(shell find src -type f -name "*.c") +KERNEL=kernel.bin +ISO=os_image.iso + +ARCH_DIRS = $(patsubst %,src/arch/%,$(ARCH_COMMON)) +ARCH_INCLUDES = $(shell find $(ARCH_DIRS) -type d -name "include") +CFLAGS_ARCH = $(patsubst %, -isystem %,$(ARCH_INCLUDES)) + +H_SRC = $(shell find src include -type f -name "*.h" -not -path "src/arch/*") +HA_SRC = $(shell find $(ARCH_DIRS) -type f -name "*.h") + +C_SRC = $(shell find src -type f -name "*.c" -not -path "src/arch/*") C_OBJ = $(patsubst %.c,build/%.o,$(C_SRC)) +CA_SRC = $(shell find $(ARCH_DIRS) -type f -name "*.c") +CA_OBJ = $(patsubst %.c,build/%.o,$(CA_SRC)) -A_SRC = $(shell find src -type f -name "*.S" -not -path "src/arch/*") -A_SRC += $(shell find src/arch/$(ARCH) -type f -name "*.S") +A_SRC = $(shell find $(ARCH_DIRS) -type f -name "*.S") A_OBJ = $(patsubst %.S,build/%.S.o,$(A_SRC)) .PHONY: all clean all: build/$(ISO) -build: build/$(ISO) - clean: @printf "\033[31m RM \033[0m%s\n" build - @rm -rf build/* + @rm -fr ./build $(A_OBJ): build/%.S.o : %.S @mkdir -p $(@D) @@ -42,10 +59,15 @@ $(C_OBJ): build/%.o : %.c @printf "\033[34m CC \033[0m%s\n" $< @$(CC) -c $(CFLAGS) -o $@ $< -build/$(KERNEL): arch/$(ARCH)/linker.ld $(A_OBJ) $(C_OBJ) $(H_SRC) +$(CA_OBJ): build/%.o : %.c + @mkdir -p $(@D) + @printf "\033[34m CC \033[0m%s\n" $< + @$(CC) -c $(CFLAGS) $(CFLAGS_ARCH) -o $@ $< + +build/$(KERNEL): arch/$(ARCH)/linker.ld $(A_OBJ) $(C_OBJ) $(CA_OBJ) $(H_SRC) $(HA_SRC) @mkdir -p $(@D) @printf "\033[32m LD \033[0m%s\n" $@ - @$(LD) $(LDFLAGS) -T arch/$(ARCH)/linker.ld -o build/$(KERNEL) $(A_OBJ) $(C_OBJ) + @$(LD) $(LDFLAGS) -T arch/$(ARCH)/linker.ld -o build/$(KERNEL) $(A_OBJ) $(C_OBJ) $(CA_OBJ) build/$(ISO): build/$(KERNEL) grub.cfg @mkdir -p $(@D) |