mirror of
https://git.stationery.faith/corn/corn.git
synced 2024-11-21 23:52:20 +00:00
64 lines
1.7 KiB
Makefile
64 lines
1.7 KiB
Makefile
SRC_DIR=src
|
|
INCLUDE_DIR=include
|
|
BUILD_DIR=build
|
|
|
|
K_BIN_NAME=kernel.bin
|
|
ISO_NAME=os_image.iso
|
|
|
|
CC=cc
|
|
LD=ld
|
|
AS=nasm
|
|
|
|
CFLAGS+=-std=c2x -ffreestanding -fno-stack-protector -g -Wall -Wextra -pedantic -lgcc -isystem $(INCLUDE_DIR)
|
|
CFLAGS+=-DPAGE_SIZE=4096
|
|
|
|
LDFLAGS+=-nmagic
|
|
|
|
C_SRC=$(shell find $(SRC_DIR) -type f -name "*.c")
|
|
C_OBJ=$(patsubst %.c,$(BUILD_DIR)/%.o,$(C_SRC))
|
|
|
|
H_SRC=$(shell find $(SRC_DIR) -type f -name "*.h")
|
|
H_INCLUDE=$(shell find $(INCLUDE_DIR) -type f -name "*.h")
|
|
|
|
A_SRC=$(shell find $(SRC_DIR) -type f -name "*.S")
|
|
A_OBJ=$(patsubst %.S,$(BUILD_DIR)/%.S.o,$(A_SRC))
|
|
|
|
.PHONY: all clean
|
|
|
|
all: $(BUILD_DIR)/$(ISO_NAME)
|
|
|
|
clean:
|
|
@printf "\033[31m RM \033[0m%s\n" $(BUILD_DIR)
|
|
@rm -rf $(BUILD_DIR)/*
|
|
|
|
$(A_OBJ): $(BUILD_DIR)/%.S.o : %.S
|
|
@mkdir -p $(@D)
|
|
@printf "\033[33m AS \033[0m%s\n" $<
|
|
@nasm $< -f elf64 -o $@
|
|
|
|
$(C_OBJ): $(BUILD_DIR)/%.o : %.c
|
|
@mkdir -p $(@D)
|
|
@printf "\033[34m CC \033[0m%s\n" $<
|
|
@$(CC) -c $(CFLAGS) -o $@ $<
|
|
|
|
$(BUILD_DIR)/$(K_BIN_NAME): arch/amd64/linker.ld $(A_OBJ) $(C_OBJ) $(H_SRC) $(H_INCLUDE)
|
|
@mkdir -p $(@D)
|
|
@printf "\033[32m LD \033[0m%s\n" $@
|
|
@$(LD) $(LDFLAGS) --no-warn-rwx-segments -T arch/amd64/linker.ld -o $(BUILD_DIR)/$(K_BIN_NAME) $(A_OBJ) $(C_OBJ)
|
|
|
|
$(BUILD_DIR)/$(ISO_NAME): $(BUILD_DIR)/$(K_BIN_NAME) grub.cfg
|
|
@mkdir -p $(@D)
|
|
@mkdir -p $(BUILD_DIR)/iso/boot/grub
|
|
@cp grub.cfg $(BUILD_DIR)/iso/boot/grub
|
|
@cp $(BUILD_DIR)/$(K_BIN_NAME) $(BUILD_DIR)/iso/boot
|
|
@printf "\033[35m ISO \033[0m%s\n" $(BUILD_DIR)/$(ISO_NAME)
|
|
@grub-mkrescue -o $(BUILD_DIR)/$(ISO_NAME) $(BUILD_DIR)/iso 2> /dev/null
|
|
|
|
run: all
|
|
@qemu-system-x86_64 \
|
|
-cdrom $(BUILD_DIR)/$(ISO_NAME) \
|
|
-serial stdio \
|
|
-display gtk,show-menubar=off,zoom-to-fit=on \
|
|
-m 4G \
|
|
-enable-kvm \
|
|
-name corn
|