-
Notifications
You must be signed in to change notification settings - Fork 4
/
makefile
59 lines (39 loc) · 1.55 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
59
CC := gcc
LD := gcc
SRC_DIR := src
BUILD_DIR := build
#MODULES := shared client server
SRC_DIRS := $(addprefix SRC_DIR/,$(MODULES))
BUILD_DIRS := $(addprefix BUILD_DIR,$(MODULES))
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
SRC_FILES := $(call rwildcard,$(SRC_DIR)/,*.cpp)
SHARED_SRC := $(call rwildcard,$(SRC_DIR)/shared/,*.cpp)
CLIENT_SRC := $(call rwildcard,$(SRC_DIR)/client/,*.cpp)
SERVER_SRC := $(call rwildcard,$(SRC_DIR)/server/,*.cpp)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRC_FILES))
SHARED_OBJ := $(patsubst $(SRC_DIR)/shared/%.cpp,$(BUILD_DIR)/shared/%.o,$(SRC_FILES))
CLIENT_OBJ := $(patsubst $(SRC_DIR)/client/%.cpp,$(BUILD_DIR)/client/%.o,$(SRC_FILES))
SERVER_OBJ := $(patsubst $(SRC_DIR)/server/%.cpp,$(BUILD_DIR)/server/%.o,$(SRC_FILES))
OBJ := $(patsubst src/%.cpp,build/%.o,$(SRC))
INCLUDES := $(addprefix -I ,$(SRC_DIR))
define make-goal
build/%: src/%.cpp
$(CC) $(INCLUDES) -c $$< -o $$@
endef
.PHONY: build/shared build/client build/server checkdirs
all: checkdirs crush.exe server.exe
build/shared: $(SHARED_OBJ)
build/client: build/shared $(CLIENT_OBJ)
build/server: build/shared $(SERVER_OBJ)
crush.exe: $(SHARED_OBJ) $(CLIENT_OBJ)
$(LD) $^ -o $@
server.exe: $(SHARED_OBJ) $(SERVER_OBJ)
$(LD) $^ -o $@
$(OBJ_FILES):
$(CC) $(INCLUDES) -c $(patsubst $(BUILD_DIR)/%.o,$(SRC_DIR)/%.cpp,$@) -o $@
checkdirs: $(BUILD_DIRS)
$(BUILD_DIRS):
@mkdir -p $@
clean:
@rm -rf $(BUILD_DIR)
$(foreach ofile,$(OBJ_FILES),$(eval $(call make-goal,$(ofile))))