Initial setup
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
SRC_DIR := src
|
||||
BIN_DIR := bin
|
||||
OBJ_DIR := build
|
||||
INCLUDE_DIR := include
|
||||
|
||||
CXX ?= g++
|
||||
CC ?= gcc
|
||||
|
||||
TARGET_DEBUG := $(BIN_DIR)/blade-dbg
|
||||
TARGET_RELEASE := $(BIN_DIR)/blade
|
||||
|
||||
PCH_DIR_DEBUG := $(OBJ_DIR)/debug/pch
|
||||
PCH_DIR_RELEASE := $(OBJ_DIR)/release/pch
|
||||
|
||||
PCH_DEBUG := $(PCH_DIR_DEBUG)/pch.h.gch
|
||||
PCH_RELEASE := $(PCH_DIR_RELEASE)/pch.h.gch
|
||||
|
||||
MRUBY_CFLAGS ?= -I./libs/mruby/build/host/include
|
||||
MRUBY_LIBS ?= -L./libs/mruby/build/host/lib -lmruby
|
||||
|
||||
CFLAGS_DEBUG :=\
|
||||
-std=c++23 -Wall -Wextra -fno-rtti \
|
||||
-Og -fno-inline -gsplit-dwarf -DDEBUG \
|
||||
-g -fno-omit-frame-pointer -ffast-math \
|
||||
-I./include
|
||||
|
||||
CFLAGS_RELEASE :=\
|
||||
-std=c++23 -O3 -mtune=generic -fno-rtti \
|
||||
-fvisibility=hidden -static -ffast-math \
|
||||
-fomit-frame-pointer -DNDEBUG -s \
|
||||
-I./include
|
||||
|
||||
CFLAGS_DEBUG += $(MRUBY_CFLAGS)
|
||||
CFLAGS_RELEASE += $(MRUBY_CFLAGS)
|
||||
|
||||
LIBS := $(MRUBY_LIBS)
|
||||
|
||||
SRC := $(shell find $(SRC_DIR) -type f -name '*.cc')
|
||||
OBJ_DEBUG := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/debug/%.o,$(SRC))
|
||||
OBJ_RELEASE := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/release/%.o,$(SRC))
|
||||
|
||||
DEP_DEBUG := $(OBJ_DEBUG:.o=.d)
|
||||
DEP_RELEASE := $(OBJ_RELEASE:.o=.d)
|
||||
|
||||
.PHONY: all debug release clean
|
||||
|
||||
all: release
|
||||
|
||||
debug: $(TARGET_DEBUG)
|
||||
|
||||
release: $(TARGET_RELEASE)
|
||||
|
||||
$(PCH_DEBUG): $(INCLUDE_DIR)/pch.h
|
||||
@mkdir -p $(PCH_DIR_DEBUG)
|
||||
@$(CXX) $(CFLAGS_DEBUG) -x c++-header -o $@ $(INCLUDE_DIR)/pch.h
|
||||
@echo "Debug Precompiled header generated at $@"
|
||||
|
||||
$(PCH_RELEASE): $(INCLUDE_DIR)/pch.h
|
||||
@mkdir -p $(PCH_DIR_RELEASE)
|
||||
@$(CXX) $(CFLAGS_RELEASE) -x c++-header -o $@ $(INCLUDE_DIR)/pch.h
|
||||
@echo "Release Precompiled header generated at $@"
|
||||
|
||||
$(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG)
|
||||
@mkdir -p $(BIN_DIR)
|
||||
@$(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(LIBS)
|
||||
@echo "Debug build complete: $@"
|
||||
|
||||
$(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE)
|
||||
@mkdir -p $(BIN_DIR)
|
||||
@$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE)$(LIBS)
|
||||
@strip $@
|
||||
@echo "Release build complete: $@"
|
||||
|
||||
$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.cc $(PCH_DEBUG) $(GENERATED_HEADER)
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CXX) $(CFLAGS_DEBUG) -I$(PCH_DIR_DEBUG) -include pch.h -MMD -MP -c $< -o $@
|
||||
@echo "[CXX] Debug object file generated: $@ from $<"
|
||||
|
||||
$(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc $(PCH_RELEASE) $(GENERATED_HEADER)
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CXX) $(CFLAGS_RELEASE) -I$(PCH_DIR_RELEASE) -include pch.h -MMD -MP -c $< -o $@
|
||||
@echo "[CXX] release object file generated: $@ from $<"
|
||||
|
||||
-include $(DEP_DEBUG)
|
||||
-include $(DEP_RELEASE)
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJ_DIR) $(BIN_DIR)
|
||||
@echo "Cleaned build artifacts."
|
||||
Reference in New Issue
Block a user