-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
57 lines (44 loc) · 1.3 KB
/
Makefile
File metadata and controls
57 lines (44 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Compiler settings
CXX = g++
CXXFLAGS = -Wall -std=c++23
RELEASE_FLAGS = -O3 -march=native -flto -ffast-math -DNDEBUG
DEBUG_FLAGS = -g -O0 -DDEBUG
# Directories
SRC_DIR = src
BUILD_DIR = build
RELEASE_DIR = $(BUILD_DIR)/release
DEBUG_DIR = $(BUILD_DIR)/debug
# Source files
SRCS = $(SRC_DIR)/main.cpp
RELEASE_OBJS = $(SRCS:$(SRC_DIR)/%.cpp=$(RELEASE_DIR)/%.o)
DEBUG_OBJS = $(SRCS:$(SRC_DIR)/%.cpp=$(DEBUG_DIR)/%.o)
TARGET = raytracer
# Default target
all: release
# Release target
release: CXXFLAGS += $(RELEASE_FLAGS)
release: $(RELEASE_DIR)/$(TARGET)
# Debug target
debug: CXXFLAGS += $(DEBUG_FLAGS)
debug: $(DEBUG_DIR)/$(TARGET)
# Create build directories
$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)
$(DEBUG_DIR):
mkdir -p $(DEBUG_DIR)
# Compile source files to object files (release)
$(RELEASE_DIR)/%.o: $(SRC_DIR)/%.cpp | $(RELEASE_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Compile source files to object files (debug)
$(DEBUG_DIR)/%.o: $(SRC_DIR)/%.cpp | $(DEBUG_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Link object files to create executable (release)
$(RELEASE_DIR)/$(TARGET): $(RELEASE_OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^
# Link object files to create executable (debug)
$(DEBUG_DIR)/$(TARGET): $(DEBUG_OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^
# Clean build files
clean:
rm -rf $(BUILD_DIR)
.PHONY: all clean release debug