-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
48 lines (38 loc) · 1.1 KB
/
Makefile
File metadata and controls
48 lines (38 loc) · 1.1 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
# Detect Windows environment
ifeq ($(OS),Windows_NT)
WINDOWS := 1
else
WINDOWS := 0
endif
# Compiler and flags
CXX := g++
CXXFLAGS := -std=c++20 -O3 -m64 -Isrc -s
LDFLAGS := -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lwebsockets -lssl -lcrypto -lz -lpthread
# Add -lmingw32 first for Windows
ifeq ($(WINDOWS), 1)
CXXFLAGS += -Id:/src/cpp/include -Ld:/src/cpp/lib -s
LDFLAGS := -lmingw32 -lws2_32 $(LDFLAGS)
endif
# Build directories
BUILD_DIR := build
SRC := main.cpp $(wildcard src/game/*.cpp) $(wildcard src/examples/*.cpp)
OBJ := $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(SRC))
# Create directories for object files
OBJ_DIRS := $(sort $(dir $(OBJ)))
# Default target
all: $(BUILD_DIR) $(OBJ_DIRS) main
# Linking step
main: $(OBJ)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ) $(LDFLAGS)
# Compilation step (separate object files in build/)
$(BUILD_DIR)/%.o: %.cpp | $(BUILD_DIR) $(OBJ_DIRS)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Ensure build/ directory exists
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Ensure all required object directories exist
$(OBJ_DIRS):
mkdir -p $@
# Clean command
clean:
rm -rf main $(BUILD_DIR)