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
|
|
|
|
|
2022-10-12 12:31:41 +00:00
|
|
|
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
|
2022-10-08 13:57:07 +00:00
|
|
|
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)
|
2022-09-07 17:41:08 +00:00
|
|
|
CFLAGS := ${CFLAGS} -D_MOON_SUFFIX=-$(shell git rev-parse --short HEAD)
|
2022-09-07 13:02:54 +00:00
|
|
|
endif
|
|
|
|
|
2022-09-07 13:05:57 +00:00
|
|
|
ifeq ($(MOON_BUILD_DEBUG), 1)
|
2022-11-05 09:47:18 +00:00
|
|
|
CFLAGS := -ggdb -fsanitize=undefined ${CFLAGS}
|
2022-09-07 13:05:57 +00:00
|
|
|
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))
|
|
|
|
|
2022-11-03 19:44:37 +00:00
|
|
|
default: $(MOON_BIN)/moon
|
2022-09-05 14:13:51 +00:00
|
|
|
|
2022-09-14 16:54:40 +00:00
|
|
|
$(MOON_OBJ)/main.cpp.o: $(MOON_SRC)/main.cpp
|
|
|
|
@mkdir -p $(@D)
|
2022-11-08 17:03:43 +00:00
|
|
|
@$(CXX) $(CFLAGS) -fno-stack-protector $(CXXFLAGS) -o $@ -c $^
|
|
|
|
@echo " CXX $^"
|
2022-09-14 16:54:40 +00:00
|
|
|
|
2022-10-04 16:46:10 +00:00
|
|
|
$(MOON_OBJ)/misc/config.cpp.o: $(MOON_SRC)/misc/config.cpp FORCE
|
|
|
|
@mkdir -p $(@D)
|
2022-11-08 17:03:43 +00:00
|
|
|
@$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $(MOON_SRC)/misc/config.cpp
|
|
|
|
@echo " CXX $^"
|
2022-10-04 16:46:10 +00:00
|
|
|
|
2022-09-14 16:54:40 +00:00
|
|
|
$(MOON_OBJ)/init/Init.cpp.o: $(MOON_SRC)/init/Init.cpp
|
|
|
|
@mkdir -p $(@D)
|
2022-11-08 17:03:43 +00:00
|
|
|
@$(CXX) $(CFLAGS) -fno-stack-protector $(CXXFLAGS) -o $@ -c $^
|
|
|
|
@echo " CXX $^"
|
2022-09-14 16:54:40 +00:00
|
|
|
|
2022-09-05 14:13:51 +00:00
|
|
|
$(MOON_OBJ)/%.cpp.o: $(MOON_SRC)/%.cpp
|
|
|
|
@mkdir -p $(@D)
|
2022-11-08 17:03:43 +00:00
|
|
|
@$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $^
|
|
|
|
@echo " CXX $^"
|
2022-09-05 14:13:51 +00:00
|
|
|
|
2022-11-05 09:47:18 +00:00
|
|
|
$(MOON_OBJ)/memory/liballoc/liballoc.c.o: $(MOON_SRC)/memory/liballoc/liballoc.c
|
|
|
|
@mkdir -p $(@D)
|
2022-11-08 17:03:43 +00:00
|
|
|
@$(CC) $(CFLAGS) -fno-sanitize=undefined -o $@ -c $^
|
|
|
|
@echo " CC $^"
|
2022-11-05 09:47:18 +00:00
|
|
|
|
2022-09-05 14:13:51 +00:00
|
|
|
$(MOON_OBJ)/%.c.o: $(MOON_SRC)/%.c
|
|
|
|
@mkdir -p $(@D)
|
2022-11-08 17:03:43 +00:00
|
|
|
@$(CC) $(CFLAGS) -o $@ -c $^
|
|
|
|
@echo " CC $^"
|
2022-09-05 14:13:51 +00:00
|
|
|
|
|
|
|
$(MOON_OBJ)/%.asm.o: $(MOON_SRC)/%.asm
|
|
|
|
@mkdir -p $(@D)
|
2022-11-08 17:03:43 +00:00
|
|
|
@$(ASM) $(ASMFLAGS) -o $@ $^
|
|
|
|
@echo " ASM $^"
|
2022-09-05 14:13:51 +00:00
|
|
|
|
2022-10-02 10:44:32 +00:00
|
|
|
build: $(OBJS)
|
2022-10-24 18:52:11 +00:00
|
|
|
@mkdir -p $(MOON_BIN)
|
2022-11-08 17:03:43 +00:00
|
|
|
@$(CC) $(OBJS) $(LDFLAGS) -o $(MOON_BIN)/moon
|
|
|
|
@echo " CCLD $(MOON_BIN)/moon"
|
2022-09-05 14:13:51 +00:00
|
|
|
|
2022-10-02 10:44:32 +00:00
|
|
|
clean:
|
2022-09-05 14:13:51 +00:00
|
|
|
rm -rf $(MOON_OBJ)/*
|
2022-09-18 18:20:51 +00:00
|
|
|
rm -rf $(MOON_BIN)/*
|
2022-09-05 14:13:51 +00:00
|
|
|
|
2022-11-03 19:44:37 +00:00
|
|
|
install: $(MOON_BIN)/moon
|
2022-10-24 18:52:11 +00:00
|
|
|
@mkdir -p $(LUNA_ROOT)/initrd/boot
|
2022-11-08 17:03:43 +00:00
|
|
|
@cp $^ $(LUNA_ROOT)/initrd/boot/moon
|
|
|
|
@echo " INSTALL $^"
|
|
|
|
@$(LUNA_ROOT)/tools/generate-symbols.sh
|
|
|
|
@$(STRIP) $(LUNA_ROOT)/initrd/boot/moon
|
|
|
|
@echo " STRIP $(LUNA_ROOT)/initrd/boot/moon"
|
2022-10-04 16:46:10 +00:00
|
|
|
|
|
|
|
.PHONY: build clean install FORCE
|
|
|
|
FORCE:
|