# --------------------------------------------------------------------------- # Compiler and Base Flags # --------------------------------------------------------------------------- CXX := g++ # Common flags (for both Debug and Release) CXXFLAGS_BASE := -Wall -Wextra -std=c++17 # Debug flags (includes TIMERS and DEBUG, plus -g) CXXFLAGS_DEBUG := $(CXXFLAGS_BASE) -g -DDEBUG -DTIMERS # Release flags (optimized, no debug macros, no timers) CXXFLAGS_RELEASE := $(CXXFLAGS_BASE) -O2 -DNDEBUG # By default, we build in Debug mode: BUILD_TYPE ?= debug # We’ll dynamically set BUILD_DIR and CXXFLAGS based on BUILD_TYPE ifeq ($(BUILD_TYPE),debug) BUILD_DIR := build CXXFLAGS := $(CXXFLAGS_DEBUG) else ifeq ($(BUILD_TYPE),release) BUILD_DIR := release CXXFLAGS := $(CXXFLAGS_RELEASE) else $(error Unknown BUILD_TYPE '$(BUILD_TYPE)'. Valid options: debug or release) endif # --------------------------------------------------------------------------- # Detect Platform # --------------------------------------------------------------------------- ifeq ($(OS),Windows_NT) # -------------------- Windows -------------------- EXE_EXT := .exe # Example paths (adjust if you have your libs somewhere else): GLFW_INCLUDE := C:/libs/glfw/include GLEW_INCLUDE := C:/libs/glew/include LIB_PATHS := -LC:/libs/glfw/lib \ -LC:/libs/glew/lib \ -Llib LIBS := -lglfw3 -lopengl32 -lgdi32 -limm32 -lole32 -loleaut32 -luuid \ -lwinmm -lglew32 -lglu32 -lyaml-cpp -llua54 define MKDIR_P if not exist "$(1)" mkdir "$(1)" >nul 2>&1 endef else # -------------------- Linux (or other Unix-likes) -------------------- EXE_EXT := GLFW_INCLUDE := /usr/include GLEW_INCLUDE := /usr/include LIB_PATHS := LIBS := -lglfw -lGL -lGLEW -lGLU -lyaml-cpp -llua define MKDIR_P mkdir -p "$(1)" endef endif # --------------------------------------------------------------------------- # Directories # --------------------------------------------------------------------------- SRC_DIR := src VENDOR_DIRS := vendor/imgui-docking vendor/stb vendor/ImGuizmo # BUILD_DIR is determined by $(BUILD_TYPE) above: either `build` or `release` # --------------------------------------------------------------------------- # Include Directories # --------------------------------------------------------------------------- INCLUDE_DIRS := \ $(SRC_DIR) \ $(VENDOR_DIRS) \ $(GLFW_INCLUDE) \ $(GLEW_INCLUDE) \ vendor/stb/include \ vendor/lua \ vendor/ImGuizmo \ vendor/gcml CXXFLAGS += $(foreach inc,$(INCLUDE_DIRS),-I$(inc)) # --------------------------------------------------------------------------- # Source Files # --------------------------------------------------------------------------- SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp) \ $(wildcard $(SRC_DIR)/**/*.cpp) VENDOR_SRC := $(foreach dir, $(VENDOR_DIRS), $(wildcard $(dir)/*.cpp)) STB_SRC := $(wildcard vendor/stb/src/*.cpp) # If stb has .cpp files ALL_SRC := $(SRC_FILES) $(VENDOR_SRC) $(STB_SRC) # --------------------------------------------------------------------------- # Object Files # --------------------------------------------------------------------------- OBJ_FILES := $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(ALL_SRC)) # --------------------------------------------------------------------------- # Target (goes into the same directory as object files) # --------------------------------------------------------------------------- TARGET := $(BUILD_DIR)/TesseractEngine$(EXE_EXT) # --------------------------------------------------------------------------- # Phony Targets # --------------------------------------------------------------------------- .PHONY: all clean debug release # Default target uses whatever BUILD_TYPE is (default = debug) all: $(TARGET) ## "debug" target => override BUILD_TYPE debug: @$(MAKE) BUILD_TYPE=debug all ## "release" target => override BUILD_TYPE release: @$(MAKE) BUILD_TYPE=release all # --------------------------------------------------------------------------- # Link all object files to create the executable # --------------------------------------------------------------------------- $(TARGET): $(OBJ_FILES) @echo Linking $@... $(CXX) $(CXXFLAGS) -o $@ $^ $(LIB_PATHS) $(LIBS) # --------------------------------------------------------------------------- # Pattern rule to compile .cpp files to .o files # --------------------------------------------------------------------------- $(BUILD_DIR)/%.o: %.cpp @$(call MKDIR_P,$(dir $@)) @echo Compiling $<... $(CXX) $(CXXFLAGS) -c $< -o $@ # --------------------------------------------------------------------------- # Clean build artifacts # --------------------------------------------------------------------------- clean: @echo Cleaning up... rm -rf build rm -rf release