-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (42 loc) · 1.45 KB
/
Makefile
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
# Compiler
CC = g++
# Flags
CFLAGS = -lws2_32 -lgdi32 -luser32 -lwinmm -lshlwapi -s -ffunction-sections -fdata-sections -Wno-write-strings -fno-exceptions -fmerge-all-constants -static-libstdc++ -static-libgcc -fpermissive -fexceptions
# Directories
SRC_DIR = src
BUILD_DIR = build
OBJ_DIR = obj
# Source files
CLIENT_SRC = $(wildcard $(SRC_DIR)/client/*.cpp)
SERVER_SRC = $(wildcard $(SRC_DIR)/server/*.cpp)
COMMON_SRC = $(wildcard $(SRC_DIR)/*.cpp)
# Object files
CLIENT_OBJ = $(patsubst $(SRC_DIR)/client/%.cpp,$(OBJ_DIR)/client/%.o,$(CLIENT_SRC))
SERVER_OBJ = $(patsubst $(SRC_DIR)/server/%.cpp,$(OBJ_DIR)/server/%.o,$(SERVER_SRC))
COMMON_OBJ = $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(COMMON_SRC))
# Targets
TARGETS = client server
# Default target
all: $(TARGETS)
client: $(CLIENT_OBJ) $(COMMON_OBJ)
$(CC) -O2 $^ -o $(BUILD_DIR)/$@.exe $(CFLAGS)
server: $(SERVER_OBJ) $(COMMON_OBJ)
$(CC) -O2 $^ -o $(BUILD_DIR)/$@.exe $(CFLAGS)
# Rule to compile source files into object files
$(OBJ_DIR)/client/%.o: $(SRC_DIR)/client/%.cpp | $(OBJ_DIR)/client
$(CC) -c $< -o $@ $(CFLAGS)
$(OBJ_DIR)/server/%.o: $(SRC_DIR)/server/%.cpp | $(OBJ_DIR)/server
$(CC) -c $< -o $@ $(CFLAGS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
$(CC) -c $< -o $@ $(CFLAGS)
# Create directories if they don't exist
$(OBJ_DIR)/client:
mkdir -p $@
$(OBJ_DIR)/server:
mkdir -p $@
$(OBJ_DIR):
mkdir -p $@
# Clean
clean:
rm -rf $(BUILD_DIR)/* $(OBJ_DIR)/*
.PHONY: all client server clean