# ---- config ---- TARGET := bin/main BUILD ?= debug CXX := g++ CC := gcc CXXFLAGS := -std=c++20 -Wall -Wextra -Wshadow -Wconversion -Wno-unused-parameter CFLAGS := -std=c17 -Wall -Wextra -Wno-unused-parameter CPPFLAGS := -Iexternal/glad/include -Iexternal/glm -Isrc PKG_CFLAGS := $(shell pkg-config --cflags glfw3 cglm) PKG_LIBS := $(shell pkg-config --libs glfw3 cglm) # auto-deps: generate .d files next to .o DEPFLAGS := -MMD -MP ifeq ($(BUILD),debug) CXXFLAGS += -O0 -g CFLAGS += -O0 -g else CXXFLAGS += -O2 -DNDEBUG CFLAGS += -O2 -DNDEBUG endif LDFLAGS := $(PKG_LIBS) -ldl # ---- sources ---- SRCS_CPP := $(shell find src -name '*.cpp') SRCS_C := external/glad/src/glad.c OBJS := $(SRCS_CPP:%.cpp=obj/%.o) $(SRCS_C:%.c=obj/%.o) DEPS := $(OBJS:.o=.d) # ---- rules ---- .PHONY: all run clean tidy rebuild all: $(TARGET) $(TARGET): $(OBJS) @mkdir -p $(dir $@) $(CXX) $^ -o $@ $(LDFLAGS) # C++ obj/%.o: %.cpp @mkdir -p $(dir $@) $(CXX) $(CPPFLAGS) $(PKG_CFLAGS) $(CXXFLAGS) $(DEPFLAGS) -c $< -o $@ # C (glad) obj/%.o: %.c @mkdir -p $(dir $@) $(CC) $(CPPFLAGS) $(PKG_CFLAGS) $(CFLAGS) $(DEPFLAGS) -c $< -o $@ # include auto-generated header dependencies (safe if missing on first run) -include $(DEPS) run: $(TARGET) prime-run ./$(TARGET) clean: rm -rf obj tidy: rm -rf obj $(TARGET) rebuild: clean all