-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (51 loc) · 1.69 KB
/
Makefile
File metadata and controls
67 lines (51 loc) · 1.69 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
58
59
60
61
62
63
64
65
66
67
# Detect Windows environment
ifeq ($(OS),Windows_NT)
WINDOWS := 1
else
WINDOWS := 0
endif
PKGS := sdl3 sdl3-image sdl3-ttf
# Compiler and flags
CXX := g++
CXXFLAGS := -std=c++20 -O3 -m64 -Isrc -s `pkg-config --cflags $(PKGS)`
LDFLAGS := -Wl,--subsystem,console `pkg-config --libs $(PKGS)` -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
GAME_SRC := $(filter-out src/game/minimap.cpp src/game/terrain.cpp,$(wildcard src/game/*.cpp))
WAR2_SRC := war2_main.cpp $(GAME_SRC) $(wildcard src/war2/*.cpp)
KLAD1_GAME_SRC := $(filter-out src/klad1/tilemap.cpp,$(wildcard src/klad1/*.cpp))
KLAD1_LEVEL_SRC := $(wildcard src/klad1/levels/*.cpp)
KLAD1_SRC := klad1_main.cpp $(GAME_SRC) $(KLAD1_GAME_SRC) $(KLAD1_LEVEL_SRC)
WAR2_OBJ := $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(WAR2_SRC))
KLAD1_OBJ := $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(KLAD1_SRC))
# Create directories for object files
OBJ_DIRS := $(sort $(dir $(WAR2_OBJ) $(KLAD1_OBJ)))
# Default target
all: $(BUILD_DIR) $(OBJ_DIRS) war2 klad1
# Linking step
war2: $(WAR2_OBJ)
$(CXX) $(CXXFLAGS) -o $@ $(WAR2_OBJ) $(LDFLAGS)
klad1: $(KLAD1_OBJ)
$(CXX) $(CXXFLAGS) -o $@ $(KLAD1_OBJ) $(LDFLAGS)
run-war2: war2
./war2
run-klad1: klad1
./klad1
# 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 war2 klad1 $(BUILD_DIR)