mirror of
https://git.stationery.faith/corn/corn.git
synced 2024-11-10 03:22:08 +00:00
65 lines
1.5 KiB
Makefile
65 lines
1.5 KiB
Makefile
KERNEL=kernel.bin
|
|
ISO=os_image.iso
|
|
|
|
ARCH=amd64
|
|
CC=cc
|
|
LD=ld
|
|
AS=nasm
|
|
|
|
CFLAGS += -std=c2x -ffreestanding -lgcc -isystem include -pipe
|
|
CFLAGS += -Wall -Wextra -pedantic
|
|
CFLAGS += -O2 -g -fno-stack-protector -fno-omit-frame-pointer
|
|
CFLAGS += -DPAGE_SIZE=4096
|
|
|
|
LDFLAGS += -nmagic --no-warn-rwx-segments -nostdlib
|
|
|
|
H_SRC = $(shell find src include -type f -name "*.h")
|
|
|
|
C_SRC = $(shell find src -type f -name "*.c")
|
|
C_OBJ = $(patsubst %.c,build/%.o,$(C_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_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/*
|
|
|
|
$(A_OBJ): build/%.S.o : %.S
|
|
@mkdir -p $(@D)
|
|
@printf "\033[33m AS \033[0m%s\n" $<
|
|
@nasm $< -f elf64 -o $@
|
|
|
|
$(C_OBJ): build/%.o : %.c
|
|
@mkdir -p $(@D)
|
|
@printf "\033[34m CC \033[0m%s\n" $<
|
|
@$(CC) -c $(CFLAGS) -o $@ $<
|
|
|
|
build/$(KERNEL): arch/$(ARCH)/linker.ld $(A_OBJ) $(C_OBJ) $(H_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)
|
|
|
|
build/$(ISO): build/$(KERNEL) grub.cfg
|
|
@mkdir -p $(@D)
|
|
@mkdir -p build/iso/boot/grub
|
|
@cp grub.cfg build/iso/boot/grub
|
|
@cp build/$(KERNEL) build/iso/boot
|
|
@printf "\033[35m ISO \033[0m%s\n" build/$(ISO)
|
|
@grub-mkrescue -o build/$(ISO) build/iso 2> /dev/null
|
|
|
|
run: all
|
|
@qemu-system-x86_64 \
|
|
-cdrom build/$(ISO) \
|
|
-serial stdio \
|
|
-display sdl \
|
|
-m 1G \
|
|
-enable-kvm \
|
|
-name corn
|