]> git.sesse.net Git - stockfish/blob - src/Makefile
Refine SEE threshold for capture pruning.
[stockfish] / src / Makefile
1 # Stockfish, a UCI chess playing engine derived from Glaurung 2.1
2 # Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
3 # Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
4 # Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
5 #
6 # Stockfish is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Stockfish is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
20 ### ==========================================================================
21 ### Section 1. General Configuration
22 ### ==========================================================================
23
24 ### Executable name
25 EXE = stockfish
26
27 ### Installation dir definitions
28 PREFIX = /usr/local
29 BINDIR = $(PREFIX)/bin
30
31 ### Built-in benchmark for pgo-builds
32 PGOBENCH = ./$(EXE) bench
33
34 ### Object files
35 OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
36         material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o \
37         search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o
38
39 ### Establish the operating system name
40 KERNEL = $(shell uname -s)
41 ifeq ($(KERNEL),Linux)
42         OS = $(shell uname -o)
43 endif
44
45 ### ==========================================================================
46 ### Section 2. High-level Configuration
47 ### ==========================================================================
48 #
49 # flag                --- Comp switch --- Description
50 # ----------------------------------------------------------------------------
51 #
52 # debug = yes/no      --- -DNDEBUG         --- Enable/Disable debug mode
53 # sanitize = undefined/thread/no (-fsanitize )
54 #                     --- ( undefined )    --- enable undefined behavior checks
55 #                     --- ( thread    )    --- enable threading error  checks
56 # optimize = yes/no   --- (-O3/-fast etc.) --- Enable/Disable optimizations
57 # arch = (name)       --- (-arch)          --- Target architecture
58 # bits = 64/32        --- -DIS_64BIT       --- 64-/32-bit operating system
59 # prefetch = yes/no   --- -DUSE_PREFETCH   --- Use prefetch asm-instruction
60 # popcnt = yes/no     --- -DUSE_POPCNT     --- Use popcnt asm-instruction
61 # sse = yes/no        --- -msse            --- Use Intel Streaming SIMD Extensions
62 # pext = yes/no       --- -DUSE_PEXT       --- Use pext x86_64 asm-instruction
63 #
64 # Note that Makefile is space sensitive, so when adding new architectures
65 # or modifying existing flags, you have to make sure there are no extra spaces
66 # at the end of the line for flag values.
67
68 ### 2.1. General and architecture defaults
69 optimize = yes
70 debug = no
71 sanitize = no
72 bits = 32
73 prefetch = no
74 popcnt = no
75 sse = no
76 pext = no
77
78 ### 2.2 Architecture specific
79
80 ifeq ($(ARCH),general-32)
81         arch = any
82 endif
83
84 ifeq ($(ARCH),x86-32-old)
85         arch = i386
86 endif
87
88 ifeq ($(ARCH),x86-32)
89         arch = i386
90         prefetch = yes
91         sse = yes
92 endif
93
94 ifeq ($(ARCH),general-64)
95         arch = any
96         bits = 64
97 endif
98
99 ifeq ($(ARCH),x86-64)
100         arch = x86_64
101         bits = 64
102         prefetch = yes
103         sse = yes
104 endif
105
106 ifeq ($(ARCH),x86-64-modern)
107         arch = x86_64
108         bits = 64
109         prefetch = yes
110         popcnt = yes
111         sse = yes
112 endif
113
114 ifeq ($(ARCH),x86-64-bmi2)
115         arch = x86_64
116         bits = 64
117         prefetch = yes
118         popcnt = yes
119         sse = yes
120         pext = yes
121 endif
122
123 ifeq ($(ARCH),armv7)
124         arch = armv7
125         prefetch = yes
126 endif
127
128 ifeq ($(ARCH),ppc-32)
129         arch = ppc
130 endif
131
132 ifeq ($(ARCH),ppc-64)
133         arch = ppc64
134         bits = 64
135 endif
136
137
138 ### ==========================================================================
139 ### Section 3. Low-level configuration
140 ### ==========================================================================
141
142 ### 3.1 Selecting compiler (default = gcc)
143
144 CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS)
145 DEPENDFLAGS += -std=c++11
146 LDFLAGS += $(EXTRALDFLAGS)
147
148 ifeq ($(COMP),)
149         COMP=gcc
150 endif
151
152 ifeq ($(COMP),gcc)
153         comp=gcc
154         CXX=g++
155         CXXFLAGS += -pedantic -Wextra -Wshadow
156
157         ifeq ($(ARCH),armv7)
158                 ifeq ($(OS),Android)
159                         CXXFLAGS += -m$(bits)
160                         LDFLAGS += -m$(bits)
161                 endif
162         else
163                 CXXFLAGS += -m$(bits)
164                 LDFLAGS += -m$(bits)
165         endif
166
167         ifneq ($(KERNEL),Darwin)
168            LDFLAGS += -Wl,--no-as-needed
169         endif
170 endif
171
172 ifeq ($(COMP),mingw)
173         comp=mingw
174
175         ifeq ($(KERNEL),Linux)
176                 ifeq ($(bits),64)
177                         ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
178                                 CXX=x86_64-w64-mingw32-c++
179                         else
180                                 CXX=x86_64-w64-mingw32-c++-posix
181                         endif
182                 else
183                         ifeq ($(shell which i686-w64-mingw32-c++-posix),)
184                                 CXX=i686-w64-mingw32-c++
185                         else
186                                 CXX=i686-w64-mingw32-c++-posix
187                         endif
188                 endif
189         else
190                 CXX=g++
191         endif
192
193         CXXFLAGS += -Wextra -Wshadow
194         LDFLAGS += -static
195 endif
196
197 ifeq ($(COMP),icc)
198         comp=icc
199         CXX=icpc
200         CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
201 endif
202
203 ifeq ($(COMP),clang)
204         comp=clang
205         CXX=clang++
206         CXXFLAGS += -pedantic -Wextra -Wshadow
207
208         ifneq ($(KERNEL),Darwin)
209         ifneq ($(KERNEL),OpenBSD)
210                 LDFLAGS += -latomic
211         endif
212         endif
213
214         ifeq ($(ARCH),armv7)
215                 ifeq ($(OS),Android)
216                         CXXFLAGS += -m$(bits)
217                         LDFLAGS += -m$(bits)
218                 endif
219         else
220                 CXXFLAGS += -m$(bits)
221                 LDFLAGS += -m$(bits)
222         endif
223 endif
224
225 ifeq ($(comp),icc)
226         profile_make = icc-profile-make
227         profile_use = icc-profile-use
228 else
229 ifeq ($(comp),clang)
230         profile_make = clang-profile-make
231         profile_use = clang-profile-use
232 else
233         profile_make = gcc-profile-make
234         profile_use = gcc-profile-use
235 endif
236 endif
237
238 ifeq ($(KERNEL),Darwin)
239         CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
240         LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
241 endif
242
243 ### Travis CI script uses COMPILER to overwrite CXX
244 ifdef COMPILER
245         COMPCXX=$(COMPILER)
246 endif
247
248 ### Allow overwriting CXX from command line
249 ifdef COMPCXX
250         CXX=$(COMPCXX)
251 endif
252
253 ### On mingw use Windows threads, otherwise POSIX
254 ifneq ($(comp),mingw)
255         # On Android Bionic's C library comes with its own pthread implementation bundled in
256         ifneq ($(OS),Android)
257                 # Haiku has pthreads in its libroot, so only link it in on other platforms
258                 ifneq ($(KERNEL),Haiku)
259                         LDFLAGS += -lpthread
260                 endif
261         endif
262 endif
263
264 ### 3.2.1 Debugging
265 ifeq ($(debug),no)
266         CXXFLAGS += -DNDEBUG
267 else
268         CXXFLAGS += -g
269 endif
270
271 ### 3.2.2 Debugging with undefined behavior sanitizers
272 ifneq ($(sanitize),no)
273         CXXFLAGS += -g3 -fsanitize=$(sanitize) -fuse-ld=gold
274         LDFLAGS += -fsanitize=$(sanitize) -fuse-ld=gold
275 endif
276
277 ### 3.3 Optimization
278 ifeq ($(optimize),yes)
279
280         CXXFLAGS += -O3
281
282         ifeq ($(comp),gcc)
283                 ifeq ($(OS), Android)
284                         CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
285                 endif
286         endif
287         
288         ifeq ($(comp),$(filter $(comp),gcc clang icc))
289                 ifeq ($(KERNEL),Darwin)
290                         CXXFLAGS += -mdynamic-no-pic
291                 endif
292         endif
293 endif
294
295 ### 3.4 Bits
296 ifeq ($(bits),64)
297         CXXFLAGS += -DIS_64BIT
298 endif
299
300 ### 3.5 prefetch
301 ifeq ($(prefetch),yes)
302         ifeq ($(sse),yes)
303                 CXXFLAGS += -msse
304                 DEPENDFLAGS += -msse
305         endif
306 else
307         CXXFLAGS += -DNO_PREFETCH
308 endif
309
310 ### 3.6 popcnt
311 ifeq ($(popcnt),yes)
312         ifeq ($(comp),icc)
313                 CXXFLAGS += -msse3 -DUSE_POPCNT
314         else
315                 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
316         endif
317 endif
318
319 ### 3.7 pext
320 ifeq ($(pext),yes)
321         CXXFLAGS += -DUSE_PEXT
322         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
323                 CXXFLAGS += -mbmi2
324         endif
325 endif
326
327 ### 3.8 Link Time Optimization, it works since gcc 4.5 but not on mingw under Windows.
328 ### This is a mix of compile and link time options because the lto link phase
329 ### needs access to the optimization flags.
330 ifeq ($(optimize),yes)
331 ifeq ($(debug), no)
332         ifeq ($(comp),$(filter $(comp),gcc clang))
333                 CXXFLAGS += -flto
334                 LDFLAGS += $(CXXFLAGS)
335         endif
336
337         ifeq ($(comp),mingw)
338         ifeq ($(KERNEL),Linux)
339                 CXXFLAGS += -flto
340                 LDFLAGS += $(CXXFLAGS)
341         endif
342         endif
343 endif
344 endif
345
346 ### 3.9 Android 5 can only run position independent executables. Note that this
347 ### breaks Android 4.0 and earlier.
348 ifeq ($(OS), Android)
349         CXXFLAGS += -fPIE
350         LDFLAGS += -fPIE -pie
351 endif
352
353
354 ### ==========================================================================
355 ### Section 4. Public targets
356 ### ==========================================================================
357
358 help:
359         @echo ""
360         @echo "To compile stockfish, type: "
361         @echo ""
362         @echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
363         @echo ""
364         @echo "Supported targets:"
365         @echo ""
366         @echo "build                   > Standard build"
367         @echo "profile-build           > PGO build"
368         @echo "strip                   > Strip executable"
369         @echo "install                 > Install executable"
370         @echo "clean                   > Clean up"
371         @echo ""
372         @echo "Supported archs:"
373         @echo ""
374         @echo "x86-64                  > x86 64-bit"
375         @echo "x86-64-modern           > x86 64-bit with popcnt support"
376         @echo "x86-64-bmi2             > x86 64-bit with pext support"
377         @echo "x86-32                  > x86 32-bit with SSE support"
378         @echo "x86-32-old              > x86 32-bit fall back for old hardware"
379         @echo "ppc-64                  > PPC 64-bit"
380         @echo "ppc-32                  > PPC 32-bit"
381         @echo "armv7                   > ARMv7 32-bit"
382         @echo "general-64              > unspecified 64-bit"
383         @echo "general-32              > unspecified 32-bit"
384         @echo ""
385         @echo "Supported compilers:"
386         @echo ""
387         @echo "gcc                     > Gnu compiler (default)"
388         @echo "mingw                   > Gnu compiler with MinGW under Windows"
389         @echo "clang                   > LLVM Clang compiler"
390         @echo "icc                     > Intel compiler"
391         @echo ""
392         @echo "Simple examples. If you don't know what to do, you likely want to run: "
393         @echo ""
394         @echo "make build ARCH=x86-64    (This is for 64-bit systems)"
395         @echo "make build ARCH=x86-32    (This is for 32-bit systems)"
396         @echo ""
397         @echo "Advanced examples, for experienced users: "
398         @echo ""
399         @echo "make build ARCH=x86-64 COMP=clang"
400         @echo "make profile-build ARCH=x86-64-modern COMP=gcc COMPCXX=g++-4.8"
401         @echo ""
402
403
404 .PHONY: help build profile-build strip install clean objclean profileclean help \
405         config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make \
406         clang-profile-use clang-profile-make
407
408 build: config-sanity
409         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
410
411 profile-build: config-sanity objclean profileclean
412         @echo ""
413         @echo "Step 1/4. Building instrumented executable ..."
414         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
415         @echo ""
416         @echo "Step 2/4. Running benchmark for pgo-build ..."
417         $(PGOBENCH) > /dev/null
418         @echo ""
419         @echo "Step 3/4. Building optimized executable ..."
420         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
421         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
422         @echo ""
423         @echo "Step 4/4. Deleting profile data ..."
424         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
425
426 strip:
427         strip $(EXE)
428
429 install:
430         -mkdir -p -m 755 $(BINDIR)
431         -cp $(EXE) $(BINDIR)
432         -strip $(BINDIR)/$(EXE)
433
434 #clean all
435 clean: objclean profileclean
436         @rm -f .depend *~ core
437
438 # clean binaries and objects
439 objclean:
440         @rm -f $(EXE) $(EXE).exe *.o ./syzygy/*.o
441
442 # clean auxiliary profiling files
443 profileclean:
444         @rm -rf profdir
445         @rm -f bench.txt *.gcda ./syzygy/*.gcda *.gcno ./syzygy/*.gcno
446         @rm -f stockfish.profdata *.profraw
447
448 default:
449         help
450
451 ### ==========================================================================
452 ### Section 5. Private targets
453 ### ==========================================================================
454
455 all: $(EXE) .depend
456
457 config-sanity:
458         @echo ""
459         @echo "Config:"
460         @echo "debug: '$(debug)'"
461         @echo "sanitize: '$(sanitize)'"
462         @echo "optimize: '$(optimize)'"
463         @echo "arch: '$(arch)'"
464         @echo "bits: '$(bits)'"
465         @echo "kernel: '$(KERNEL)'"
466         @echo "os: '$(OS)'"
467         @echo "prefetch: '$(prefetch)'"
468         @echo "popcnt: '$(popcnt)'"
469         @echo "sse: '$(sse)'"
470         @echo "pext: '$(pext)'"
471         @echo ""
472         @echo "Flags:"
473         @echo "CXX: $(CXX)"
474         @echo "CXXFLAGS: $(CXXFLAGS)"
475         @echo "LDFLAGS: $(LDFLAGS)"
476         @echo ""
477         @echo "Testing config sanity. If this fails, try 'make help' ..."
478         @echo ""
479         @test "$(debug)" = "yes" || test "$(debug)" = "no"
480         @test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "no"
481         @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
482         @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
483          test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
484         @test "$(bits)" = "32" || test "$(bits)" = "64"
485         @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
486         @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
487         @test "$(sse)" = "yes" || test "$(sse)" = "no"
488         @test "$(pext)" = "yes" || test "$(pext)" = "no"
489         @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
490
491 $(EXE): $(OBJS)
492         $(CXX) -o $@ $(OBJS) $(LDFLAGS)
493
494 clang-profile-make:
495         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
496         EXTRACXXFLAGS='-fprofile-instr-generate ' \
497         EXTRALDFLAGS=' -fprofile-instr-generate' \
498         all
499
500 clang-profile-use:
501         llvm-profdata merge -output=stockfish.profdata *.profraw
502         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
503         EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
504         EXTRALDFLAGS='-fprofile-use ' \
505         all
506
507 gcc-profile-make:
508         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
509         EXTRACXXFLAGS='-fprofile-generate' \
510         EXTRALDFLAGS='-lgcov' \
511         all
512
513 gcc-profile-use:
514         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
515         EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \
516         EXTRALDFLAGS='-lgcov' \
517         all
518
519 icc-profile-make:
520         @mkdir -p profdir
521         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
522         EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
523         all
524
525 icc-profile-use:
526         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
527         EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
528         all
529
530 .depend:
531         -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
532
533 -include .depend
534