corn/Makefile

61 lines
1.5 KiB
Makefile

KERNEL=kernel.bin
ISO=os_image.iso
ARCH=amd64
CC=cc
LD=ld
AS=nasm
CFLAGS += -std=c2x -ffreestanding -fno-stack-protector -g -Wall -Wextra -pedantic -lgcc -isystem include
CFLAGS += -DPAGE_SIZE=4096
LDFLAGS += -nmagic -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)
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) --no-warn-rwx-segments -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 gtk,show-menubar=off,zoom-to-fit=on \
-m 1G \
-enable-kvm \
-name corn