-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
65 lines (55 loc) · 2.32 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
60
61
62
63
64
65
CXX = g++
CXX_MERGE = cpp-merge
CXXFLAGS = --std=c++17
SOURCES_DIR = src
BUILD_DIR = build
MERGE_DIR = $(BUILD_DIR)/merged
SOURCES = $(wildcard $(SOURCES_DIR)/*.cpp)
MAIN = $(SOURCES_DIR)/main.cpp
PLAYERS = $(wildcard $(SOURCES_DIR)/player_*.cpp)
STATE_SOURCE = $(SOURCES_DIR)/state/state.cpp
POLICY_DIR = $(SOURCES_DIR)/policy
TARGET_PLAYER = $(PLAYERS:$(SOURCES_DIR)/player_%.cpp=%)
TARGET_MAIN = main
TARGET_MERGE_PLAYER = $(TARGET_PLAYER:%=merge_%)
TARGET_MERGE_MAIN = merge_main
TARGET_OTHER = selfplay benchmark
OTHER = action state gamelog.txt
.PHONY: all clean
all: |$(BUILD_DIR) $(TARGET_MAIN) $(TARGET_PLAYER)
player: |$(BUILD_DIR) $(TARGET_PLAYER)
merge: |$(MERGE_DIR) $(TARGET_MERGE_PLAYER) $(TARGET_MERGE_MAIN)
# make build dir if it doesn't exist
$(BUILD_DIR):
mkdir "$(BUILD_DIR)"
$(MERGE_DIR):
mkdir "$(MERGE_DIR)"
# build target
ifeq ($(OS), Windows_NT)
$(TARGET_PLAYER): % : $(SOURCES_DIR)/player_%.cpp
$(CXX) -Wall -Wextra -O2 $(CXXFLAGS) -o $(BUILD_DIR)/[email protected] $(STATE_SOURCE) $(POLICY_DIR)/[email protected] $<
$(TARGET_MAIN): % : $(SOURCES_DIR)/%.cpp
$(CXX) -Wall -Wextra -O2 $(CXXFLAGS) -o $(BUILD_DIR)/[email protected] $<
$(TARGET_OTHER): %: $(SOURCES_DIR)/%.cpp
$(CXX) -Wall -Wextra -O2 $(CXXFLAGS) -o $(BUILD_DIR)/[email protected] $(STATE_SOURCE) $(POLICY_DIR)/*.cpp $<
else
$(TARGET_PLAYER): % : $(SOURCES_DIR)/player_%.cpp
$(CXX) -Wall -Wextra -O2 $(CXXFLAGS) -o $(BUILD_DIR)/player_$@ $(STATE_SOURCE) $(POLICY_DIR)/[email protected] $<
$(TARGET_MAIN): % : $(SOURCES_DIR)/%.cpp
$(CXX) -Wall -Wextra -O2 $(CXXFLAGS) -o $(BUILD_DIR)/$@ $<
$(TARGET_OTHER): %: $(SOURCES_DIR)/%.cpp
$(CXX) -Wall -Wextra -O2 $(CXXFLAGS) -o $(BUILD_DIR)/$@ $(STATE_SOURCE) $(POLICY_DIR)/*.cpp $<
endif
# build merge file
$(TARGET_MERGE_PLAYER): merge_% : $(SOURCES_DIR)/player_%.cpp
$(CXX_MERGE) $< -o $(MERGE_DIR)/player_$*_merged.cpp
$(TARGET_MERGE_MAIN): merge_% : $(SOURCES_DIR)/%.cpp
$(CXX_MERGE) $< -o $(MERGE_DIR)/$*_merged.cpp
clean:
ifeq ($(OS), Windows_NT)
del /f $(BUILD_DIR)\main.exe $(OTHER:%=$(BUILD_DIR)\\%) $(TARGET_PLAYER:%=$(BUILD_DIR)\player_%.exe)
del /f $(BUILD_DIR)\merged\main_merged.cpp $(TARGET_PLAYER:%=$(BUILD_DIR)\merged\player_%_merged.cpp)
else
rm -f $(BUILD_DIR)/main $(OTHER:%=$(BUILD_DIR)/%) $(TARGET_PLAYER:%=$(BUILD_DIR)/player_%)
rm -f $(BUILD_DIR)/merged/main_merged.cpp $(TARGET_PLAYER:%=$(BUILD_DIR)/merged/player_%_merged.cpp)
endif