]> git.sesse.net Git - stockfish/blob - src/Makefile
Syzygy tablebases
[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-2014 Marco Costalba, Joona Kiiski, Tord Romstad
4 #
5 # Stockfish is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Stockfish is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
19 ### ==========================================================================
20 ### Section 1. General Configuration
21 ### ==========================================================================
22
23 ### Establish the operating system name
24 UNAME = $(shell uname)
25
26 ### Executable name
27 EXE = stockfish
28
29 ### Installation dir definitions
30 PREFIX = /usr/local
31 # Haiku has a non-standard filesystem layout
32 ifeq ($(UNAME),Haiku)
33         PREFIX=/boot/system/non-packaged
34 endif
35 BINDIR = $(PREFIX)/bin
36
37 ### Built-in benchmark for pgo-builds
38 PGOBENCH = ./$(EXE) bench 16 1 1 default time
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 \
43         search.o thread.o timeman.o tt.o uci.o ucioption.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 # os = (name)         ---                  --- Target operating system
56 # bits = 64/32        --- -DIS_64BIT       --- 64-/32-bit operating system
57 # prefetch = yes/no   --- -DUSE_PREFETCH   --- Use prefetch x86 asm-instruction
58 # bsfq = yes/no       --- -DUSE_BSFQ       --- Use bsfq x86_64 asm-instruction (only
59 #                                              with GCC and ICC 64-bit)
60 # popcnt = yes/no     --- -DUSE_POPCNT     --- Use popcnt x86_64 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 os = any
72 bits = 32
73 prefetch = no
74 bsfq = no
75 popcnt = no
76 sse = no
77 pext = no
78 syzygy = yes
79
80 ifeq ($(syzygy),yes)
81         OBJS += syzygy/tbprobe.o
82         CXXFLAGS += -DSYZYGY
83 endif
84
85 ### 2.2 Architecture specific
86
87 ifeq ($(ARCH),general-32)
88         arch = any
89 endif
90
91 ifeq ($(ARCH),x86-32-old)
92         arch = i386
93 endif
94
95 ifeq ($(ARCH),x86-32)
96         arch = i386
97         prefetch = yes
98         sse = yes
99 endif
100
101 ifeq ($(ARCH),general-64)
102         arch = any
103         bits = 64
104 endif
105
106 ifeq ($(ARCH),x86-64)
107         arch = x86_64
108         bits = 64
109         prefetch = yes
110         bsfq = yes
111         sse = yes
112 endif
113
114 ifeq ($(ARCH),x86-64-modern)
115         arch = x86_64
116         bits = 64
117         prefetch = yes
118         bsfq = yes
119         popcnt = yes
120         sse = yes
121 endif
122
123 ifeq ($(ARCH),x86-64-bmi2)
124         arch = x86_64
125         bits = 64
126         prefetch = yes
127         bsfq = yes
128         popcnt = yes
129         sse = yes
130         pext = yes
131 endif
132
133 ifeq ($(ARCH),armv7)
134         arch = armv7
135         prefetch = yes
136         bsfq = yes
137 endif
138
139 ifeq ($(ARCH),ppc-32)
140         arch = ppc
141 endif
142
143 ifeq ($(ARCH),ppc-64)
144         arch = ppc64
145         bits = 64
146 endif
147
148
149 ### ==========================================================================
150 ### Section 3. Low-level configuration
151 ### ==========================================================================
152
153 ### 3.1 Selecting compiler (default = gcc)
154
155 CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
156 LDFLAGS += $(EXTRALDFLAGS)
157
158 ifeq ($(COMP),)
159         COMP=gcc
160 endif
161
162 ifeq ($(COMP),gcc)
163         comp=gcc
164         CXX=g++
165         CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
166 endif
167
168 ifeq ($(COMP),mingw)
169         comp=mingw
170         CXX=g++
171         CXXFLAGS += -Wextra -Wshadow
172         LDFLAGS += -static-libstdc++ -static-libgcc
173 endif
174
175 ifeq ($(COMP),icc)
176         comp=icc
177         CXX=icpc
178         CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
179 endif
180
181 ifeq ($(COMP),clang)
182         comp=clang
183         CXX=clang++
184         CXXFLAGS += -pedantic -Wno-long-long -Wextra -Wshadow
185 endif
186
187 ifeq ($(comp),icc)
188         profile_prepare = icc-profile-prepare
189         profile_make = icc-profile-make
190         profile_use = icc-profile-use
191         profile_clean = icc-profile-clean
192 else
193         profile_prepare = gcc-profile-prepare
194         profile_make = gcc-profile-make
195         profile_use = gcc-profile-use
196         profile_clean = gcc-profile-clean
197 endif
198
199 ifeq ($(UNAME),Darwin)
200         CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.6
201         LDFLAGS += -arch $(arch) -mmacosx-version-min=10.6
202 endif
203
204 ### On mingw use Windows threads, otherwise POSIX
205 ifneq ($(comp),mingw)
206         # On Android Bionic's C library comes with its own pthread implementation bundled in
207         ifneq ($(arch),armv7)
208                 # Haiku has pthreads in its libroot, so only link it in on other platforms
209                 ifneq ($(UNAME),Haiku)
210                         LDFLAGS += -lpthread
211                 endif
212         endif
213 endif
214
215 ### 3.4 Debugging
216 ifeq ($(debug),no)
217         CXXFLAGS += -DNDEBUG
218 else
219         CXXFLAGS += -g
220 endif
221
222 ### 3.5 Optimization
223 ifeq ($(optimize),yes)
224
225         ifeq ($(comp),gcc)
226                 CXXFLAGS += -O3
227
228                 ifeq ($(UNAME),Darwin)
229                         ifeq ($(arch),i386)
230                                 CXXFLAGS += -mdynamic-no-pic
231                         endif
232                         ifeq ($(arch),x86_64)
233                                 CXXFLAGS += -mdynamic-no-pic
234                         endif
235                 endif
236
237                 ifeq ($(arch),armv7)
238                         CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
239                 endif
240         endif
241
242         ifeq ($(comp),mingw)
243                 CXXFLAGS += -O3
244         endif
245
246         ifeq ($(comp),icc)
247                 ifeq ($(UNAME),Darwin)
248                         CXXFLAGS += -fast -mdynamic-no-pic
249                 else
250                         CXXFLAGS += -fast
251                 endif
252         endif
253
254         ifeq ($(comp),clang)
255                 CXXFLAGS += -O3
256
257                 ifeq ($(UNAME),Darwin)
258                         ifeq ($(pext),no)
259                                 CXXFLAGS += -flto
260                                 LDFLAGS += $(CXXFLAGS)
261                         endif
262                         ifeq ($(arch),i386)
263                                 CXXFLAGS += -mdynamic-no-pic
264                         endif
265                         ifeq ($(arch),x86_64)
266                                 CXXFLAGS += -mdynamic-no-pic
267                         endif
268                 endif
269         endif
270 endif
271
272 ### 3.6. Bits
273 ifeq ($(bits),64)
274         CXXFLAGS += -DIS_64BIT
275 endif
276
277 ### 3.7 prefetch
278 ifeq ($(prefetch),yes)
279         ifeq ($(sse),yes)
280                 CXXFLAGS += -msse
281                 DEPENDFLAGS += -msse
282         endif
283 else
284         CXXFLAGS += -DNO_PREFETCH
285 endif
286
287 ### 3.8 bsfq
288 ifeq ($(bsfq),yes)
289         CXXFLAGS += -DUSE_BSFQ
290 endif
291
292 ### 3.9 popcnt
293 ifeq ($(popcnt),yes)
294         ifeq ($(comp),icc)
295                 CXXFLAGS += -msse3 -DUSE_POPCNT
296         else
297                 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
298         endif
299 endif
300
301 ### 3.10 pext
302 ifeq ($(pext),yes)
303         CXXFLAGS += -DUSE_PEXT
304         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
305                 CXXFLAGS += -mbmi -mbmi2
306         endif
307 endif
308
309 ### 3.11 Link Time Optimization, it works since gcc 4.5 but not on mingw.
310 ### This is a mix of compile and link time options because the lto link phase
311 ### needs access to the optimization flags.
312 ifeq ($(comp),gcc)
313         ifeq ($(optimize),yes)
314         ifeq ($(debug),no)
315                 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
316                 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
317                 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
318                         CXXFLAGS += -flto
319                         LDFLAGS += $(CXXFLAGS)
320                 endif
321         endif
322         endif
323 endif
324
325 ### ==========================================================================
326 ### Section 4. Public targets
327 ### ==========================================================================
328
329 help:
330         @echo ""
331         @echo "To compile stockfish, type: "
332         @echo ""
333         @echo "make target ARCH=arch [COMP=comp]"
334         @echo ""
335         @echo "Supported targets:"
336         @echo ""
337         @echo "build                   > Standard build"
338         @echo "profile-build           > PGO build"
339         @echo "strip                   > Strip executable"
340         @echo "install                 > Install executable"
341         @echo "clean                   > Clean up"
342         @echo ""
343         @echo "Supported archs:"
344         @echo ""
345         @echo "x86-64                  > x86 64-bit"
346         @echo "x86-64-modern           > x86 64-bit with popcnt support"
347         @echo "x86-64-bmi2             > x86 64-bit with pext support"
348         @echo "x86-32                  > x86 32-bit with SSE support"
349         @echo "x86-32-old              > x86 32-bit fall back for old hardware"
350         @echo "ppc-64                  > PPC 64-bit"
351         @echo "ppc-32                  > PPC 32-bit"
352         @echo "armv7                   > ARMv7 32-bit"
353         @echo "general-64              > unspecified 64-bit"
354         @echo "general-32              > unspecified 32-bit"
355         @echo ""
356         @echo "Supported compilers:"
357         @echo ""
358         @echo "gcc                     > Gnu compiler (default)"
359         @echo "mingw                   > Gnu compiler with MinGW under Windows"
360         @echo "clang                   > LLVM Clang compiler"
361         @echo "icc                     > Intel compiler"
362         @echo ""
363         @echo "Non-standard targets:"
364         @echo ""
365         @echo "make hpux               >  Compile for HP-UX. Compiler = aCC"
366         @echo ""
367         @echo "Examples. If you don't know what to do, you likely want to run: "
368         @echo ""
369         @echo "make build ARCH=x86-64    (This is for 64-bit systems)"
370         @echo "make build ARCH=x86-32    (This is for 32-bit systems)"
371         @echo ""
372
373 .PHONY: build profile-build
374 build:
375         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
376         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
377
378 profile-build:
379         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
380         @echo ""
381         @echo "Step 0/4. Preparing for profile build."
382         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
383         @echo ""
384         @echo "Step 1/4. Building executable for benchmark ..."
385         @touch *.cpp *.h
386         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
387         @echo ""
388         @echo "Step 2/4. Running benchmark for pgo-build ..."
389         @$(PGOBENCH) > /dev/null
390         @echo ""
391         @echo "Step 3/4. Building final executable ..."
392         @touch *.cpp
393         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
394         @echo ""
395         @echo "Step 4/4. Deleting profile data ..."
396         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
397
398 strip:
399         strip $(EXE)
400
401 install:
402         -mkdir -p -m 755 $(BINDIR)
403         -cp $(EXE) $(BINDIR)
404         -strip $(BINDIR)/$(EXE)
405
406 clean:
407         $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda ./syzygy/*.o
408
409 default:
410         help
411
412 ### ==========================================================================
413 ### Section 5. Private targets
414 ### ==========================================================================
415
416 all: $(EXE) .depend
417
418 config-sanity:
419         @echo ""
420         @echo "Config:"
421         @echo "debug: '$(debug)'"
422         @echo "optimize: '$(optimize)'"
423         @echo "arch: '$(arch)'"
424         @echo "os: '$(os)'"
425         @echo "bits: '$(bits)'"
426         @echo "prefetch: '$(prefetch)'"
427         @echo "bsfq: '$(bsfq)'"
428         @echo "popcnt: '$(popcnt)'"
429         @echo "sse: '$(sse)'"
430         @echo "pext: '$(pext)'"
431         @echo ""
432         @echo "Flags:"
433         @echo "CXX: $(CXX)"
434         @echo "CXXFLAGS: $(CXXFLAGS)"
435         @echo "LDFLAGS: $(LDFLAGS)"
436         @echo ""
437         @echo "Testing config sanity. If this fails, try 'make help' ..."
438         @echo ""
439         @test "$(debug)" = "yes" || test "$(debug)" = "no"
440         @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
441         @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
442          test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
443         @test "$(os)" = "any"
444         @test "$(bits)" = "32" || test "$(bits)" = "64"
445         @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
446         @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
447         @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
448         @test "$(sse)" = "yes" || test "$(sse)" = "no"
449         @test "$(pext)" = "yes" || test "$(pext)" = "no"
450         @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
451
452 $(EXE): $(OBJS)
453         $(CXX) -o $@ $(OBJS) $(LDFLAGS)
454
455 gcc-profile-prepare:
456         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
457
458 gcc-profile-make:
459         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
460         EXTRACXXFLAGS='-fprofile-generate' \
461         EXTRALDFLAGS='-lgcov' \
462         all
463
464 gcc-profile-use:
465         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
466         EXTRACXXFLAGS='-fprofile-use' \
467         EXTRALDFLAGS='-lgcov' \
468         all
469
470 gcc-profile-clean:
471         @rm -rf *.gcda *.gcno bench.txt
472
473 icc-profile-prepare:
474         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
475         @mkdir profdir
476
477 icc-profile-make:
478         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
479         EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
480         all
481
482 icc-profile-use:
483         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
484         EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
485         all
486
487 icc-profile-clean:
488         @rm -rf profdir bench.txt
489
490 .depend:
491         -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
492
493 -include .depend
494
495
496 ### ==========================================================================
497 ### Section 6. Non-standard targets
498 ### ==========================================================================
499
500 hpux:
501         $(MAKE) \
502         CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \
503         CXXFLAGS="" \
504         LDFLAGS="" \
505         all
506