# Directories INCLUDE_DIR = include SRC_DIR = src BUILD_DIR = build # ImGui directory (only set if ImGui is used) IMGUI_DIR = imgui # Compiler CXX = g++ # Libs LIBS = -lGL `pkg-config --libs sdl3` # Compiler and linker settings CXXFLAGS = `pkg-config --cflags sdl3` -std=c++17 -I $(INCLUDE_DIR) # If ImGui directory is set, include its source files ifdef IMGUI_DIR CXXFLAGS += -I $(IMGUI_DIR) -I $(IMGUI_DIR)/backends endif # Source and object files SRC = $(wildcard $(SRC_DIR)/*.cpp) # If ImGui is used, add its source files to the source list ifdef IMGUI_DIR SRC += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp SRC += $(IMGUI_DIR)/backends/imgui_impl_sdl3.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp endif # Target executable UNAME := $(shell uname -s) BUILD_DIR := $(BUILD_DIR)/$(UNAME) OBJ_DIR := $(BUILD_DIR)/objs BIN = $(BUILD_DIR)/main # Object files corresponding to the source files (now in obj directory) OBJS = $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(basename $(notdir $(SRC))))) # development target with debugging dev: CXXFLAGS += -g -Wall -Wformat dev: all # Release target release: CXXFLAGS += -O3 release: all # Create directories for build output dirs: @mkdir -p $(BUILD_DIR) @mkdir -p $(OBJ_DIR) # Pattern rule for source files in src directory $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< # Pattern rule for ImGui source files ifdef IMGUI_DIR $(OBJ_DIR)/%.o: $(IMGUI_DIR)/%.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< $(OBJ_DIR)/%.o: $(IMGUI_DIR)/backends/%.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< endif all: dirs $(BIN) @echo Build complete $(BIN): $(OBJS) $(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS) clean: rm -rf $(BUILD_DIR)