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