summarylogtreecommitdiffstats
path: root/makefile.patch
blob: 35ac1c37cb178225e4eacad6ec0a50a082c18d9c (plain)
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
diff -Naur pachi-pachi-12.10-jowa.orig/Makefile pachi-pachi-12.10-jowa.new/Makefile
--- pachi-pachi-12.10-jowa.orig/Makefile	2018-08-14 19:45:14.946828806 +0200
+++ pachi-pachi-12.10-jowa.new/Makefile	2018-08-14 19:46:53.610162808 +0200
@@ -28,7 +28,7 @@
 # You'll need to install Boost and Caffe libraries.
 # If Caffe is in a custom directory you can set it here.
 
-DCNN=1
+DCNN=0
 # CAFFE_PREFIX=/usr/local/caffe
 
 # Fixed board size. Set this to enable more aggressive optimizations
@@ -319,7 +319,7 @@
 	@CC="$(CC)" CFLAGS="$(CFLAGS)" ./spudfrog
 
 # Build info
-build.h: .git/HEAD .git/index Makefile
+build.h: Makefile
 	+@make spudfrog
 	@echo "[make] build.h"
 	@CC="$(CC)" CFLAGS="$(CFLAGS)" ./genbuild > $@
diff -Naur pachi-pachi-12.10-jowa.orig/Makefile.orig pachi-pachi-12.10-jowa.new/Makefile.orig
--- pachi-pachi-12.10-jowa.orig/Makefile.orig	1970-01-01 01:00:00.000000000 +0100
+++ pachi-pachi-12.10-jowa.new/Makefile.orig	2018-08-14 19:45:19.576828838 +0200
@@ -0,0 +1,399 @@
+#### CONFIGURATION
+
+# Uncomment one of the 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 quick, make generic ...)
+
+# 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 MSYS2 section for further configuration.
+
+# MSYS2=1
+
+# Do you compile on MacOS/X instead of Linux?
+# Please note that performance may not be optimal.
+
+# MAC=1
+
+# 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
+
+# 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
+
+# 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
+
+# Enable joseki engine ? Useful if running without dcnn support.
+# Otherwise will be slightly faster without.
+
+# JOSEKI=1
+# MOGGY_JOSEKI=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
+
+# Compile Pachi with external plugin support ?
+# If unsure leave disabled, you most likely don't need it.
+
+# PLUGINS=1
+
+# 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
+
+
+# Target directories when running 'make install' / 'make install-data'.
+# Pachi will look for extra data files (such as dcnn, pattern, joseki or
+# fuseki database) in system directory below in addition to current directory
+# (or DATA_DIR environment variable if present).
+PREFIX  ?= /usr/local
+BINDIR  ?= $(PREFIX)/bin
+DATADIR ?= $(PREFIX)/share/pachi
+
+# 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
+CUSTOM_CFLAGS   := -Wall -ggdb3 $(OPT) -std=gnu99 -pthread -Wsign-compare -D_GNU_SOURCE
+CUSTOM_CXXFLAGS := -Wall -ggdb3 $(OPT)
+
+
+###################################################################################################################
+### CONFIGURATION END
+
+MAKEFLAGS += --no-print-directory
+
+TUNE := -march=native
+ifeq ($(GENERIC), 1)
+	TUNE := -mtune=generic
+endif
+
+ifndef NO_FRENAME_REGISTERS
+	CUSTOM_CFLAGS += -frename-registers
+endif
+
+ifdef DATADIR
+	CUSTOM_CFLAGS += -DDATA_DIR=\"$(DATADIR)\"
+endif
+
+ifdef BOARD_SIZE
+	CUSTOM_CFLAGS += -DBOARD_SIZE=$(BOARD_SIZE)
+endif
+
+EXTRA_OBJS :=
+EXTRA_SUBDIRS :=
+
+##############################################################################
+ifdef MSYS2
+        # Try static build ?
+        # MSYS2_STATIC=1
+
+        # For dcnn build, caffe msys2 package is probably in the repos now.
+        # Otherwise get one from https://github.com/lemonsqueeze/mingw-caffe
+        # ('mini' / 'nohdf5' releases allow for smaller static builds)
+
+	WIN_HAVE_NO_REGEX_SUPPORT=1
+
+	SYS_CFLAGS  := $(TUNE)
+	SYS_LDFLAGS := -pthread -L$(CAFFE_PREFIX)/bin -L$(MINGW_PREFIX)/bin
+	SYS_LIBS    := -lws2_32
+	CUSTOM_CXXFLAGS += -I$(MINGW_PREFIX)/include/OpenBLAS
+
+        # Enable mingw-w64 C99 printf() / scanf() layer ?
+        SYS_CFLAGS += -D__USE_MINGW_ANSI_STDIO
+
+	ifdef WIN_HAVE_NO_REGEX_SUPPORT
+		SYS_CFLAGS += -DHAVE_NO_REGEX_SUPPORT
+	else
+		SYS_LIBS += -lregex -ltre -lintl -liconv	# Oh, dear...
+	endif
+
+	DCNN_LIBS := -lcaffe -lboost_system-mt -lglog -lstdc++ $(SYS_LIBS)
+
+	ifdef MSYS2_STATIC		# Static build, good luck
+                # Which type of caffe package do you have ?
+                # Regular caffe package is fine but pulls in hdf5 (+deps) which we don't need
+                # and requires --whole-archive for static linking. This makes binaries unnecessarily
+                # bloated. Choose normal, nohdf5, or mini (mini is best)
+		CAFFE=normal
+
+		ifeq ($(CAFFE), normal)
+			HDF5_LIBS = -lhdf5_hl -lhdf5 -lszip -lz
+		endif
+
+		ifeq ($(CAFFE), mini)
+                        # Force linking of caffe layer factory, will pull in layers we need.
+			EXTRA_OBJS := layer_factory.o
+			CAFFE_STATIC_LIB = -lcaffe
+		else
+			CAFFE_STATIC_LIB = -Wl,--whole-archive -l:libcaffe.a -Wl,--no-whole-archive
+		endif
+
+		DCNN_LIBS := -Wl,-Bstatic $(CAFFE_STATIC_LIB)  \
+			     -lboost_system-mt -lboost_thread-mt -lopenblas $(HDF5_LIBS) -lgflags_static \
+			     -lglog -lprotobuf -lstdc++ -lwinpthread $(SYS_LIBS)   -Wl,-Bdynamic -lshlwapi
+
+                # glog / gflags headers really shouldn't __declspec(dllexport) symbols for us,
+                # static linking will fail with undefined __imp__xxx symbols.
+                # Normally this works around it.
+		SYS_CXXFLAGS += -DGOOGLE_GLOG_DLL_DECL="" -DGFLAGS_DLL_DECL=""
+	endif
+else
+##############################################################################
+ifdef MAC
+	SYS_CFLAGS  := -DNO_THREAD_LOCAL
+	SYS_LDFLAGS := -pthread -rdynamic
+	SYS_LIBS    := -lm -ldl
+	DCNN_LIBS   := -lcaffe -lboost_system -lglog -lstdc++ $(SYS_LIBS)
+else
+##############################################################################
+# Linux
+	SYS_CFLAGS  := $(TUNE)
+	SYS_LDFLAGS := -pthread -rdynamic
+	SYS_LIBS    := -lm -lrt -ldl
+	DCNN_LIBS   := -lcaffe -lboost_system -lglog -lstdc++ $(SYS_LIBS)
+endif
+endif
+
+ifdef CAFFE_PREFIX
+	SYS_LDFLAGS += -L$(CAFFE_PREFIX)/lib -Wl,-rpath=$(CAFFE_PREFIX)/lib
+	CXXFLAGS    += -I$(CAFFE_PREFIX)/include
+endif
+
+ifeq ($(DCNN), 1)
+	CUSTOM_CFLAGS   += -DDCNN
+	CUSTOM_CXXFLAGS += -DDCNN
+	EXTRA_OBJS      += caffe.o dcnn.o
+	SYS_LIBS := $(DCNN_LIBS)
+endif
+
+ifeq ($(FIFO), 1)
+	CUSTOM_CFLAGS += -DPACHI_FIFO
+	EXTRA_OBJS    += fifo.o
+endif
+
+ifeq ($(JOSEKI), 1)
+	CUSTOM_CFLAGS += -DJOSEKI
+endif
+
+ifeq ($(MOGGY_JOSEKI), 1)
+	CUSTOM_CFLAGS += -DMOGGY_JOSEKI
+endif
+
+ifeq ($(DOUBLE_FLOATING), 1)
+	CUSTOM_CFLAGS += -DDOUBLE_FLOATING
+endif
+
+ifeq ($(DISTRIBUTED), 1)
+	CUSTOM_CFLAGS += -DDISTRIBUTED
+	EXTRA_SUBDIRS += distributed
+endif
+
+ifeq ($(PLUGINS), 1)
+	CUSTOM_CFLAGS += -DPACHI_PLUGINS
+endif
+
+
+ifeq ($(PROFILING), gprof)
+	CUSTOM_LDFLAGS += -pg
+	CUSTOM_CFLAGS  += -pg -fno-inline
+else
+        # Whee, an extra register!
+	CUSTOM_CFLAGS += -fomit-frame-pointer
+ifeq ($(PROFILING), perftools)
+	SYS_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 gtp.o move.o ownermap.o pattern3.o pattern.o patternsp.o patternprob.o playout.o \
+       probdist.o random.o stone.o timeinfo.o network.o fbook.o chat.o util.o gogui.o pachi.o
+
+# Low-level dependencies last
+SUBDIRS   = $(EXTRA_SUBDIRS) uct uct/policy t-unit t-predict engines playout tactics
+DATAFILES = patterns.prob patterns.spat book.dat golast19.prototxt golast.trained joseki19.pdict
+
+###############################################################################################################
+# Main rule + 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
+
+
+###############################################################################################################
+
+LOCALLIBS=$(SUBDIRS:%=%/lib.a)
+$(LOCALLIBS): all-recursive
+	@
+
+pachi: $(OBJS) $(LOCALLIBS)
+	$(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: .git/HEAD .git/index Makefile
+	+@make spudfrog
+	@echo "[make] build.h"
+	@CC="$(CC)" CFLAGS="$(CFLAGS)" ./genbuild > $@
+
+# Run unit tests
+test: FORCE
+	t-unit/run_tests
+
+	@echo -n "Testing uct genmove...   "
+	@ ./pachi -d0 -t =1000 < gtp/genmove.gtp  2>pachi.log >/dev/null
+	@echo "OK"
+
+	@echo -n "Testing quiet mode...    "
+	@if  grep -q '.' < pachi.log ; then \
+		echo "FAILED:";  cat pachi.log;  exit 1;  else  echo "OK"; \
+	fi
+
+
+# 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/
+
+        ifndef MSYS2
+		cd distribute  &&  strip pachi
+        else
+		cd distribute  &&  strip pachi.exe
+		@echo "packing exe ..."
+		@cd distribute  &&  upx -o p.exe pachi.exe  &&  mv p.exe pachi.exe
+                ifndef MSYS2_STATIC
+			@echo "copying dlls ..."
+			@cd distribute; \
+			    mingw=`echo $$MINGW_PREFIX | tr '/' '.' `; \
+			    dlls_list="../$${mingw}_dlls"; \
+			    cp `cat $$dlls_list` .
+                endif
+        endif
+
+# install-recursive?
+install: distribute
+	$(INSTALL) -d $(BINDIR)
+	$(INSTALL) distribute/pachi $(BINDIR)/
+
+install-data:
+	$(INSTALL) -d $(DATADIR)
+	@for file in $(DATAFILES); do                               \
+		if [ -f $$file ]; then                              \
+                        echo $(INSTALL) $$file $(DATADIR)/;         \
+			$(INSTALL) $$file $(DATADIR)/;              \
+		else                                                \
+			echo "WARNING: $$file datafile is missing"; \
+                fi                                                  \
+	done;
+
+# 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:
+
+# MSYS2 mini static link hack. XXX doesn't honor $(CAFFE_PREFIX)
+layer_factory.o: $(MINGW_PREFIX)/lib/libcaffe.a
+	@echo "[AR]   $@"
+	@ar x $< $@
+
+-include Makefile.lib