-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathMakefile
390 lines (288 loc) · 9.24 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
############################ CONFIGURATION ############################
# Tweak options below to change the way Pachi is built.
# Alternatively, you can pass the option to make itself, like:
# make MAC=1 DOUBLE_FLOATING=1
# or use the short aliases (make fast, make generic ...)
################################ Build ################################
# Generic build ?
# If binary will be distributed you need this !
# Otherwise you may do without to enable more aggressive optimizations
# for this machine only.
# GENERIC=1
# Do you compile on Windows instead of Linux ?
# Please note that performance may not be optimal.
# To compile in msys2 with mingw-w64, uncomment the following line.
# See Makefile.msys2 for further configuration.
# MSYS2=1
# Do you compile on MacOS/X instead of Linux?
# Please note that performance may not be optimal.
# MAC=1
############################ Deep Learning ############################
# Compile Pachi with dcnn support ?
# You'll need to install Boost and Caffe libraries.
# If Caffe is in a custom directory you can set it here.
DCNN=1
# CAFFE_PREFIX=/usr/local/caffe
# Supported networks:
# Comment out those you don't need for speed.
DCNN_DETLEF=1
DCNN_DARKFOREST=1
############################ Special Builds ###########################
# Fixed board size. Set this to enable more aggressive optimizations
# if you only play on 19x19. Pachi won't be able to play on other
# board sizes.
# BOARD_SIZE=19
# Build josekifix module ?
# Provides fixes for joseki lines that dcnn plays poorly, and more varied
# fusekis when playing as black.
JOSEKIFIX=1
# Running multiple Pachi instances ? Enable this to coordinate them so that
# only one takes the cpu at a time. If your system uses systemd beware !
# Go and read note at top of fifo.c
# FIFO=1
# By default, Pachi uses low-precision numbers within the game tree to
# conserve memory. This can become an issue with playout counts >1M,
# e.g. with extremely long thinking times or massive parallelization;
# 24 bits of floating_t mantissa become insufficient then.
# DOUBLE_FLOATING=1
# Enable distributed engine for cluster play ?
# DISTRIBUTED=1
# NETWORK=1
# Compile Pachi with external plugin support ?
# If unsure leave disabled, you most likely don't need it.
# PLUGINS=1
# Build extra engines used for development ?
# EXTRA_ENGINES=1
# Compile extra tests ? Enable this to test board implementation.
# BOARD_TESTS=1
############################## Profiling ##############################
# Enable performance profiling using gprof. Note that this also disables
# inlining, which allows more fine-grained profile, but may also distort
# it somewhat.
# PROFILING=gprof
# Enable performance profiling using google-perftools. This is much
# more accurate, fine-grained and nicer than gprof and does not change
# the way the actual binary is compiled and runs.
# PROFILING=perftools
############################### Install ###############################
# Target directories when running 'make install'.
# Pachi will look for its data files (dcnn, pattern, joseki etc) in
# system directory below (in addition to current directory / DATA_DIR
# environment variable if present).
PREFIX=$(DESTDIR)/usr
BINDIR=$(PREFIX)/bin
DATADIR=$(PREFIX)/share/pachi-go
# Generic compiler options. You probably do not really want to twiddle
# any of this.
# (N.B. -ffast-math breaks us; -fomit-frame-pointer is added below
# unless PROFILING=gprof.)
OPT ?= -O3
COMMON_FLAGS := -Wall -ggdb3 $(OPT) -D_GNU_SOURCE
CFLAGS := -std=gnu99 -pthread -Wsign-compare -Wno-format-zero-length
CXXFLAGS := -std=c++11
#########################################################################
### CONFIGURATION END
# Main rules + aliases
# Aliases are nice, but don't ask too much: 'make quick 19' won't do what
# you expect for example (use 'make OPT=-O0 BOARD_SIZE=19' instead)
all: build.h
+@make all-recursive pachi
debug fast quick O0:
+@make OPT=-O0
opt slow O3:
+@make OPT=-O3
generic:
+@make GENERIC=1
native:
+@make GENERIC=0
nodcnn:
+@make DCNN=0
19:
+@make BOARD_SIZE=19
double:
+@make DOUBLE_FLOATING=1
#######################################################################
MAKEFLAGS += --no-print-directory
ARCH = $(shell uname -m)
TUNE := -march=native
ifeq ($(GENERIC), 1)
TUNE := -mtune=generic
endif
ifndef NO_FRENAME_REGISTERS
COMMON_FLAGS += -frename-registers
endif
ifdef DATADIR
COMMON_FLAGS += -DDATA_DIR=\"$(DATADIR)\"
endif
ifdef BOARD_SIZE
COMMON_FLAGS += -DBOARD_SIZE=$(BOARD_SIZE)
endif
EXTRA_OBJS :=
EXTRA_SUBDIRS :=
ifdef MSYS2
-include Makefile.msys2
else
ifdef MAC
-include Makefile.mac
else
-include Makefile.linux
endif
endif
ifdef CAFFE_PREFIX
LDFLAGS += -L$(CAFFE_PREFIX)/lib -Wl,-rpath=$(CAFFE_PREFIX)/lib
CXXFLAGS += -I$(CAFFE_PREFIX)/include
endif
ifeq ($(DCNN), 1)
COMMON_FLAGS += -DDCNN
EXTRA_SUBDIRS += dcnn
EXTRA_OBJS += $(EXTRA_DCNN_OBJS)
LIBS := $(DCNN_LIBS)
else
DCNN_DETLEF = 0
DCNN_DARKFOREST = 0
endif
ifeq ($(DCNN_DETLEF), 1)
COMMON_FLAGS += -DDCNN_DETLEF
endif
ifeq ($(DCNN_DARKFOREST), 1)
COMMON_FLAGS += -DDCNN_DARKFOREST
endif
ifeq ($(FIFO), 1)
COMMON_FLAGS += -DPACHI_FIFO
EXTRA_OBJS += fifo.o
endif
ifeq ($(NETWORK), 1)
COMMON_FLAGS += -DNETWORK
EXTRA_OBJS += network.o
endif
ifeq ($(DOUBLE_FLOATING), 1)
COMMON_FLAGS += -DDOUBLE_FLOATING
endif
ifeq ($(DISTRIBUTED), 1)
COMMON_FLAGS += -DDISTRIBUTED
EXTRA_SUBDIRS += distributed
endif
ifeq ($(PLUGINS), 1)
COMMON_FLAGS += -DPACHI_PLUGINS
endif
ifeq ($(EXTRA_ENGINES), 1)
COMMON_FLAGS += -DEXTRA_ENGINES
endif
ifeq ($(JOSEKIFIX), 1)
COMMON_FLAGS += -DJOSEKIFIX
EXTRA_SUBDIRS += josekifix
EXTRA_DATAFILES += josekifix.gtp
endif
ifeq ($(BOARD_TESTS), 1)
LIBS += -lcrypto
COMMON_FLAGS += -DBOARD_TESTS
endif
ifeq ($(PROFILING), gprof)
LDFLAGS += -pg
COMMON_FLAGS += -pg -fno-inline
else
# Whee, an extra register!
COMMON_FLAGS += -fomit-frame-pointer
ifeq ($(PROFILING), perftools)
LIBS += -lprofiler
endif
endif
ifndef LD
LD=ld
endif
ifndef AR
AR=ar
endif
ifndef INSTALL
INSTALL=/usr/bin/install
endif
export
unexport INCLUDES
INCLUDES=-I.
OBJS = $(EXTRA_OBJS) \
board.o board_undo.o engine.o gogui.o gtp.o move.o ownermap.o pachi.o pattern3.o \
playout.o random.o stone.o timeinfo.o fbook.o chat.o util.o
# Low-level dependencies last
SUBDIRS = $(EXTRA_SUBDIRS) pattern joseki uct uct/policy t-unit t-predict engines playout tactics
DATAFILES = $(EXTRA_DATAFILES) detlef54.prototxt detlef54.trained joseki19.gtp opening.dat patterns_mm.gamma patterns_mm.spat
############################################################################################################
LOCALLIBS=$(SUBDIRS:%=%/lib.a)
$(LOCALLIBS): all-recursive
@
pachi: $(OBJS) $(LOCALLIBS) $(EXTRA_DEPS)
$(call cmd,link)
# Use runtime gcc profiling for extra optimization. This used to be a large
# bonus but nowadays, it's rarely worth the trouble.
.PHONY: pachi-profiled
pachi-profiled:
@make clean all XLDFLAGS=-fprofile-generate XCFLAGS="-fprofile-generate -fomit-frame-pointer -frename-registers"
./pachi -t =5000 no_tbook < gtp/genmove_both.gtp
@make clean all clean-profiled XLDFLAGS=-fprofile-use XCFLAGS="-fprofile-use -fomit-frame-pointer -frename-registers"
# Pachi build attendant
.PHONY: spudfrog
spudfrog: FORCE
@CC="$(CC)" CFLAGS="$(CFLAGS)" ./spudfrog
# Build info
build.h: build.h.git Makefile
+@make spudfrog
@echo "[make] build.h"
@cp build.h.git $@
@CC="$(CC)" CFLAGS="$(CFLAGS)" ./genbuild >> $@
build.h.git: .git/HEAD .git/index
@./genbuild --git > $@
# Unit tests
test: FORCE
+@make -C t-unit test
test_gtp: FORCE
+@make -C t-unit test_gtp
test_board: FORCE
+@make -C t-unit test_board
test_moggy: FORCE
+@make -C t-unit test_moggy
test_spatial: FORCE
+@make -C t-unit test_spatial
# Regression tests
regtest: FORCE
+@make -C t-regress regtest
# Prepare for install
distribute: FORCE
ifneq ($(GENERIC), 1)
@echo "WARNING: Don't distribute binaries built with -march=native !"
endif
@rm -rf distribute 2>/dev/null; $(INSTALL) -d distribute
cp pachi distribute/
+@make strip # arch specific stuff
# install everything
install: install-bin install-data
install-bin: distribute
$(INSTALL) -d $(BINDIR)
$(INSTALL) distribute/pachi $(BINDIR)/
install-data: $(DATAFILES)
$(INSTALL) -d $(DATADIR)
@for file in $(DATAFILES); do \
if [ -f $$file ]; then \
echo $(INSTALL) $$file $(DATADIR)/; \
$(INSTALL) $$file $(DATADIR)/; \
else \
echo "FATAL: datafile '$$file' is missing"; \
exit 1; \
fi \
done;
# Get missing datafiles
datafiles: $(DATAFILES)
# Download dcnn files from github
detlef54.prototxt detlef54.trained:
@echo "Getting dcnn datafiles:" ; echo ""
wget -c -O detlef54.zip 'https://github.com/pasky/pachi/releases/download/pachi_networks/detlef54.zip'
unzip -q -o detlef54.zip detlef54.prototxt detlef54.trained
rm detlef54.zip
# Generic clean rule is in Makefile.lib
clean:: clean-recursive
-@rm pachi build.h* >/dev/null 2>&1
@echo ""
clean-profiled:: clean-profiled-recursive
TAGS: FORCE
@echo "Generating TAGS ..."
@etags `find . -name "*.[ch]" -o -name "*.cpp"`
FORCE:
-include Makefile.lib