-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
307 lines (266 loc) · 6.74 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
# Fire is a freeware UCI chess playing engine authored by Norman Schmidt.
#
# Fire utilizes many state-of-the-art chess programming ideas and techniques
# which have been documented in detail at https://www.chessprogramming.org/
# and demonstrated via the very strong open-source chess engine Stockfish...
# https://github.com/official-stockfish/Stockfish.
#
# Fire is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or any later version.
#
# You should have received a copy of the GNU General Public License with
# this program: copying.txt. If not, see <http://www.gnu.org/licenses/>.
UNAME = $(shell uname)
EXE = fire.exe
PGOBENCH = ./$(EXE) bench
OBJS =
OBJS += util/bench.o bitboard.o chrono.o egtb/egtb.o endgame.o \
evaluate.o hash.o bitbase/kpk.o main.o material.o movegen.o \
movepick.o pawn.o util/perft.o position.o pst.o search.o sfactor.o \
egtb/tbprobe.o thread.o tune/tune.o uci.o util/util.o zobrist.o \
optimize = yes
debug = no
bits = 32
prefetch = no
popcnt = no
sse = no
pext = no
ifeq ($(ARCH),x86-64-popc)
arch = x86_64
bits = 64
prefetch = yes
popcnt = yes
sse = yes
endif
ifeq ($(ARCH),x86-64-bmi2)
arch = x86_64
bits = 64
prefetch = yes
popcnt = yes
sse = yes
pext = yes
endif
CXXFLAGS += -Wcast-qual -fno-exceptions $(EXTRACXXFLAGS)
DEPENDFLAGS += -std=c++17
LDFLAGS += $(EXTRALDFLAGS)
CC = gcc
ifeq ($(COMP),)
COMP=gcc
endif
ifeq ($(COMP),gcc)
comp=gcc
CXX=g++
CXXFLAGS += -pedantic -Wextra -Wshadow -m$(bits)
endif
ifeq ($(COMP),mingw)
comp=mingw
ifeq ($(UNAME),Linux)
ifeq ($(bits),64)
ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
CXX=x86_64-w64-mingw32-c++
else
CXX=x86_64-w64-mingw32-c++-posix
endif
else
ifeq ($(shell which i686-w64-mingw32-c++-posix),)
CXX=i686-w64-mingw32-c++
else
CXX=i686-w64-mingw32-c++-posix
endif
endif
else
CXX=g++
endif
CXXFLAGS += -Wextra -Wshadow
LDFLAGS += -static
endif
profile_prepare = gcc-profile-prepare
profile_make = gcc-profile-make
profile_use = gcc-profile-use
profile_clean = gcc-profile-clean
ifdef COMPILER
COMPCXX=$(COMPILER)
endif
ifdef COMPCXX
CXX=$(COMPCXX)
endif
ifneq ($(comp),mingw)
ifneq ($(arch),armv7)
ifneq ($(UNAME),Haiku)
LDFLAGS += -lpthread
endif
endif
endif
ifeq ($(debug),no)
CXXFLAGS += -DNDEBUG
else
CXXFLAGS += -g
endif
ifeq ($(optimize),yes)
CXXFLAGS += -O3
endif
ifeq ($(bits),64)
CXXFLAGS += -DIS_64_BIT
endif
ifeq ($(prefetch),yes)
ifeq ($(sse),yes)
CXXFLAGS += -msse
DEPENDFLAGS += -msse
endif
else
CXXFLAGS += -DNO_PREFETCH
endif
ifeq ($(popcnt),yes)
ifeq ($(bits),64)
CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
else
CXXFLAGS += -mpopcnt -DUSE_POPCNT
endif
endif
ifeq ($(pext),yes)
CXXFLAGS += -DUSE_PEXT
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
CXXFLAGS += -mbmi -mbmi2
endif
endif
ifeq ($(comp),gcc)
ifeq ($(optimize),yes)
ifeq ($(debug),no)
CXXFLAGS += -flto
LDFLAGS += $(CXXFLAGS)
endif
endif
endif
ifeq ($(comp),mingw)
ifeq ($(UNAME),Linux)
ifeq ($(optimize),yes)
ifeq ($(debug),no)
CXXFLAGS += -flto
LDFLAGS += $(CXXFLAGS)
endif
endif
endif
endif
CFLAGS := $(CXXFLAGS)
CXXFLAGS += -fno-rtti -std=c++17
help:
@echo ""
@echo "To compile Fire, type: "
@echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
@echo ""
@echo "Supported targets:"
@echo "build > Standard build"
@echo "profile-build > PGO build"
@echo "strip > Strip executable"
@echo "clean > Clean up"
@echo ""
@echo "Supported architectures:"
@echo "x86-64-popc > x86 64-bit with popcnt support"
@echo "x86-64-bmi2 > x86 64-bit with pext support"
@echo ""
@echo "Supported compilers:"
@echo "gcc > Gnu compiler (default)"
@echo "mingw > Gnu compiler with MinGW under Windows"
@echo ""
@echo "make build ARCH=x86-64-popc
@echo "make build ARCH=x86-64-bmi2
@echo ""
@echo "make profile-build ARCH=x86-64-popc"
@echo "make profile-build ARCH=x86-64-bmi2"
@echo ""
.PHONY: build profile-build
build:
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
profile-build:
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
@echo ""
@echo "preparing for profile build..."
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
@echo ""
@echo "building executable for benchmark..."
$(MAKE) -B ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
@echo ""
@echo "running benchmark for pgo-build..."
$(PGOBENCH)
@echo ""
@echo "building final executable..."
$(MAKE) -B ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
@echo ""
@echo "deleting profile data..."
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
$(MAKE) strip
strip:
strip $(EXE)
install:
-mkdir -p -m 755 $(BINDIR)
-cp $(EXE) $(BINDIR)
-strip $(BINDIR)/$(EXE)
clean:
$(RM) *.o .depend *.gcda *.map *.txt
default:
help
all: $(EXE) .depend
config-sanity:
@echo ""
@echo "Config:"
@echo "debug: '$(debug)'"
@echo "optimize: '$(optimize)'"
@echo "arch: '$(arch)'"
@echo "bits: '$(bits)'"
@echo "prefetch: '$(prefetch)'"
@echo "popcnt: '$(popcnt)'"
@echo "sse: '$(sse)'"
@echo "pext: '$(pext)'"
@echo ""
@echo "Compiler:"
@echo "CXX: $(CXX)"
@echo "CXXFLAGS: $(CXXFLAGS)"
@echo "LDFLAGS: $(LDFLAGS)"
@echo "CC: $(CC)"
@echo "CFLAGS: $(CFLAGS)"
@echo ""
@echo "Testing config sanity. If this fails, try 'make help' ..."
@echo ""
@test "$(debug)" = "yes" || test "$(debug)" = "no"
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
@test "$(arch)" = "any" || test "$(arch)" = "x86_64"
@test "$(bits)" = "32" || test "$(bits)" = "64"
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
@test "$(sse)" = "yes" || test "$(sse)" = "no"
@test "$(pext)" = "yes" || test "$(pext)" = "no"
@test "$(comp)" = "gcc" || test "$(comp)" = "mingw"
$(EXE): $(OBJS) $(COBJS)
$(CXX) -o $@ $(OBJS) $(COBJS) $(LDFLAGS)
$(COBJS): %.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
gcc-profile-prepare:
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
gcc-profile-make:
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
EXTRACXXFLAGS='-fprofile-generate' \
EXTRALDFLAGS='-lgcov' \
all
gcc-profile-use:
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer -fprofile-correction' \
EXTRALDFLAGS='-lgcov -Wl,-Map,h.map' \
all
gcc-profile-clean:
@rm -rf *.gcda
@rm -rf *.o
@rm -rf bitbase/*.gcda
@rm -rf bitbase/*.o
@rm -rf egtb/*.gcda
@rm -rf egtb/*.o
@rm -rf macro/*.gcda
@rm -rf macro/*.o
@rm -rf tune/*.gcda
@rm -rf tune/*.o
@rm -rf util/*.gcda
@rm -rf util/*.o
.depend:
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) $(COBJS:.o=.c) > $@ 2> /dev/null
-include .depend