Tesseract-Engine/Makefile

148 lines
4.8 KiB
Makefile
Raw Permalink Normal View History

2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
2025-01-04 02:45:31 +00:00
# Compiler and Base Flags
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
CXX := g++
2025-01-06 00:41:30 +00:00
# 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
# Well 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
# ---------------------------------------------------------------------------
2025-01-04 02:45:31 +00:00
# Detect Platform
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
2025-01-04 02:45:31 +00:00
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
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
# Directories
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
SRC_DIR := src
2025-01-05 04:04:21 +00:00
VENDOR_DIRS := vendor/imgui-docking vendor/stb vendor/ImGuizmo
2025-01-06 00:41:30 +00:00
# BUILD_DIR is determined by $(BUILD_TYPE) above: either `build` or `release`
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
# Include Directories
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
2025-01-04 02:45:31 +00:00
INCLUDE_DIRS := \
$(SRC_DIR) \
$(VENDOR_DIRS) \
$(GLFW_INCLUDE) \
$(GLEW_INCLUDE) \
vendor/stb/include \
vendor/lua \
2025-01-05 04:04:21 +00:00
vendor/ImGuizmo \
2025-01-04 02:45:31 +00:00
vendor/gcml
2025-01-04 02:45:31 +00:00
CXXFLAGS += $(foreach inc,$(INCLUDE_DIRS),-I$(inc))
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
# Source Files
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
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)
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
# Object Files
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
OBJ_FILES := $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(ALL_SRC))
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
# Target (goes into the same directory as object files)
# ---------------------------------------------------------------------------
TARGET := $(BUILD_DIR)/TesseractEngine$(EXE_EXT)
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
# Phony Targets
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
.PHONY: all clean debug release
2025-01-06 00:41:30 +00:00
# Default target uses whatever BUILD_TYPE is (default = debug)
2025-01-04 02:45:31 +00:00
all: $(TARGET)
2025-01-06 00:41:30 +00:00
## "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
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
$(TARGET): $(OBJ_FILES)
@echo Linking $@...
2025-01-04 02:45:31 +00:00
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIB_PATHS) $(LIBS)
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
# Pattern rule to compile .cpp files to .o files
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
$(BUILD_DIR)/%.o: %.cpp
2025-01-04 02:45:31 +00:00
@$(call MKDIR_P,$(dir $@))
@echo Compiling $<...
$(CXX) $(CXXFLAGS) -c $< -o $@
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
# Clean build artifacts
2025-01-06 00:41:30 +00:00
# ---------------------------------------------------------------------------
clean:
@echo Cleaning up...
2025-01-06 00:41:30 +00:00
rm -rf build
rm -rf release