uni/CPP23-game/makefile

52 lines
1.0 KiB
Makefile

# Makefile for a C++ project with optimizations
# Define the target executable
TARGET = space-war
# Compiler
CXX = g++
# Compiler flags
CXXFLAGS = -std=c++20 -Wall
# Optimization flags
OPT_FLAGS = -O3 -march=native
# Source file
SRCS = $(shell find . -name "*.cpp")
# Define the build directory
BUILD_DIR = build
# Define the object files by placing them in the build directory
OBJS = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(SRCS))
PROFILE = game
# Source file
ifeq ($(PROFILE),tests)
CXXFLAGS += -DTESTS
endif
# Default target to build the executable
all: $(BUILD_DIR) $(BUILD_DIR)/$(TARGET)
# Rule to build the target executable
$(BUILD_DIR)/$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $(OBJS)
# Rule to compile source files into object files
$(BUILD_DIR)/%.o: %.cpp | $(BUILD_DIR)
@mkdir -p $(dir $@) # Ensure the directory exists
$(CXX) $(CXXFLAGS) -c $< -o $@
# Rule to create the build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Rule to clean the build files
clean:
rm -rf $(BUILD_DIR)
# Phony targets
.PHONY: all clean