Luna/kernel/Makefile

71 lines
2.5 KiB
Makefile
Raw Normal View History

2022-09-05 14:13:51 +00:00
MOON_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
MOON_SRC := $(MOON_DIR)/src
MOON_OBJ := $(MOON_DIR)/lib
MOON_BIN := $(MOON_DIR)/bin
CFLAGS ?= -Os
2022-10-30 17:20:16 +00:00
CFLAGS := ${CFLAGS} -pedantic -Wall -Wextra -Werror -Wvla -Wfloat-equal -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion -ffreestanding -fstack-protector-strong -fno-omit-frame-pointer -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fshort-wchar -mcmodel=kernel -I$(MOON_DIR)/include -isystem $(MOON_DIR)/include/std
2022-10-07 16:19:06 +00:00
CXXFLAGS := -fno-rtti -fno-exceptions -Wsign-promo -Wstrict-null-sentinel -Wctor-dtor-privacy
2022-10-02 15:01:30 +00:00
ASMFLAGS := -felf64
LDFLAGS := -T$(MOON_DIR)/moon.ld -nostdlib -lgcc -Wl,--build-id=none -z max-page-size=0x1000 -mno-red-zone -mcmodel=kernel
2022-09-05 14:13:51 +00:00
2022-09-07 13:02:54 +00:00
ifneq ($(MOON_BUILD_STABLE), 1)
CFLAGS := ${CFLAGS} -D_MOON_SUFFIX=-$(shell git rev-parse --short HEAD)
2022-09-07 13:02:54 +00:00
endif
ifeq ($(MOON_BUILD_DEBUG), 1)
CFLAGS := -ggdb ${CFLAGS}
endif
2022-09-05 14:13:51 +00:00
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
CXX_SRC = $(call rwildcard,$(MOON_SRC),*.cpp)
C_SRC = $(call rwildcard,$(MOON_SRC),*.c)
NASM_SRC = $(call rwildcard,$(MOON_SRC),*.asm)
OBJS = $(patsubst $(MOON_SRC)/%.cpp, $(MOON_OBJ)/%.cpp.o, $(CXX_SRC))
OBJS += $(patsubst $(MOON_SRC)/%.c, $(MOON_OBJ)/%.c.o, $(C_SRC))
OBJS += $(patsubst $(MOON_SRC)/%.asm, $(MOON_OBJ)/%.asm.o, $(NASM_SRC))
default: $(MOON_BIN)/moon.elf
2022-09-14 16:54:40 +00:00
$(MOON_OBJ)/main.cpp.o: $(MOON_SRC)/main.cpp
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -fno-stack-protector $(CXXFLAGS) -o $@ -c $^
$(MOON_OBJ)/misc/config.cpp.o: $(MOON_SRC)/misc/config.cpp FORCE
@mkdir -p $(@D)
$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $(MOON_SRC)/misc/config.cpp
2022-09-14 16:54:40 +00:00
$(MOON_OBJ)/init/Init.cpp.o: $(MOON_SRC)/init/Init.cpp
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -fno-stack-protector $(CXXFLAGS) -o $@ -c $^
2022-09-05 14:13:51 +00:00
$(MOON_OBJ)/%.cpp.o: $(MOON_SRC)/%.cpp
@mkdir -p $(@D)
$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $^
$(MOON_OBJ)/%.c.o: $(MOON_SRC)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -o $@ -c $^
$(MOON_OBJ)/%.asm.o: $(MOON_SRC)/%.asm
@mkdir -p $(@D)
2022-10-02 15:01:30 +00:00
$(ASM) $(ASMFLAGS) -o $@ $^
2022-09-05 14:13:51 +00:00
build: $(OBJS)
2022-10-24 18:52:11 +00:00
@mkdir -p $(MOON_BIN)
$(CC) $(OBJS) $(LDFLAGS) -o $(MOON_BIN)/moon.elf
2022-09-05 14:13:51 +00:00
clean:
2022-09-05 14:13:51 +00:00
rm -rf $(MOON_OBJ)/*
rm -rf $(MOON_BIN)/*
2022-09-05 14:13:51 +00:00
install: $(MOON_BIN)/moon.elf
2022-10-24 18:52:11 +00:00
@mkdir -p $(LUNA_ROOT)/initrd/boot
cp $^ $(LUNA_ROOT)/initrd/boot/moon.elf
$(LUNA_ROOT)/tools/generate-symbols.sh
$(STRIP) $(LUNA_ROOT)/initrd/boot/moon.elf
.PHONY: build clean install FORCE
FORCE: