]> git.sesse.net Git - stockfish/blob - src/Makefile
Singular extension at 8 plies also for PV nodes
[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-2013 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/common
34 endif
35 BINDIR = $(PREFIX)/bin
36
37 ### Built-in benchmark for pgo-builds and signature
38 PGOBENCH = ./$(EXE) bench 32 1 10 default depth
39 SIGNBENCH = ./$(EXE) bench
40
41 ### Object files
42 OBJS = benchmark.o bitbase.o bitboard.o book.o endgame.o evaluate.o main.o \
43         material.o misc.o movegen.o movepick.o notation.o pawns.o position.o \
44         search.o thread.o timeman.o tt.o uci.o ucioption.o
45
46 ### ==========================================================================
47 ### Section 2. High-level Configuration
48 ### ==========================================================================
49 #
50 # flag                --- Comp switch --- Description
51 # ----------------------------------------------------------------------------
52 #
53 # debug = yes/no      --- -DNDEBUG         --- Enable/Disable debug mode
54 # optimize = yes/no   --- (-O3/-fast etc.) --- Enable/Disable optimizations
55 # arch = (name)       --- (-arch)          --- Target architecture
56 # os = (name)         ---                  --- Target operating system
57 # bits = 64/32        --- -DIS_64BIT       --- 64-/32-bit operating system
58 # prefetch = yes/no   --- -DUSE_PREFETCH   --- Use prefetch x86 asm-instruction
59 # bsfq = yes/no       --- -DUSE_BSFQ       --- Use bsfq x86_64 asm-instruction (only
60 #                                              with GCC and ICC 64-bit)
61 # popcnt = yes/no     --- -DUSE_POPCNT     --- Use popcnt x86_64 asm-instruction
62 # sse = yes/no        --- -msse            --- Use Intel Streaming SIMD Extensions
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
69 debug = no
70 optimize = yes
71
72 ### 2.2 Architecture specific
73
74 # General-section
75 ifeq ($(ARCH),general-64)
76         arch = any
77         os = any
78         bits = 64
79         prefetch = no
80         bsfq = no
81         popcnt = no
82         sse = no
83 endif
84
85 ifeq ($(ARCH),general-32)
86         arch = any
87         os = any
88         bits = 32
89         prefetch = no
90         bsfq = no
91         popcnt = no
92         sse = no
93 endif
94
95 # x86-section
96 ifeq ($(ARCH),x86-64)
97         arch = x86_64
98         os = any
99         bits = 64
100         prefetch = yes
101         bsfq = yes
102         popcnt = no
103         sse = yes
104 endif
105
106 ifeq ($(ARCH),x86-64-modern)
107         arch = x86_64
108         os = any
109         bits = 64
110         prefetch = yes
111         bsfq = yes
112         popcnt = yes
113         sse = yes
114 endif
115
116 ifeq ($(ARCH),x86-32)
117         arch = i386
118         os = any
119         bits = 32
120         prefetch = yes
121         bsfq = no
122         popcnt = no
123         sse = yes
124 endif
125
126 ifeq ($(ARCH),x86-32-old)
127         arch = i386
128         os = any
129         bits = 32
130         prefetch = no
131         bsfq = no
132         popcnt = no
133         sse = no
134 endif
135
136 #arm section
137 ifeq ($(ARCH),armv7)
138         arch = armv7
139         os = any
140         bits = 32
141         prefetch = yes
142         bsfq = yes
143         popcnt = no
144         sse = no
145 endif
146
147 # osx-section
148 ifeq ($(ARCH),osx-ppc-64)
149         arch = ppc64
150         os = osx
151         bits = 64
152         prefetch = no
153         bsfq = no
154         popcnt = no
155         sse = no
156 endif
157
158 ifeq ($(ARCH),osx-ppc-32)
159         arch = ppc
160         os = osx
161         bits = 32
162         prefetch = no
163         bsfq = no
164         popcnt = no
165         sse = no
166 endif
167
168 ifeq ($(ARCH),osx-x86-64)
169         arch = x86_64
170         os = osx
171         bits = 64
172         prefetch = yes
173         bsfq = yes
174         popcnt = no
175         sse = yes
176 endif
177
178 ifeq ($(ARCH),osx-x86-32)
179         arch = i386
180         os = osx
181         bits = 32
182         prefetch = yes
183         bsfq = no
184         popcnt = no
185         sse = yes
186 endif
187
188
189 ### ==========================================================================
190 ### Section 3. Low-level configuration
191 ### ==========================================================================
192
193 ### 3.1 Selecting compiler (default = gcc)
194 ifeq ($(COMP),)
195         COMP=gcc
196 endif
197
198 ifeq ($(COMP),mingw)
199         comp=mingw
200         CXX=g++
201         profile_prepare = gcc-profile-prepare
202         profile_make = gcc-profile-make
203         profile_use = gcc-profile-use
204         profile_clean = gcc-profile-clean
205 endif
206
207 ifeq ($(COMP),gcc)
208         comp=gcc
209         CXX=g++
210         profile_prepare = gcc-profile-prepare
211         profile_make = gcc-profile-make
212         profile_use = gcc-profile-use
213         profile_clean = gcc-profile-clean
214 endif
215
216 ifeq ($(COMP),icc)
217         comp=icc
218         CXX=icpc
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 endif
224
225 ifeq ($(COMP),clang)
226         comp=clang
227         CXX=clang++
228         profile_prepare = gcc-profile-prepare
229         profile_make = gcc-profile-make
230         profile_use = gcc-profile-use
231         profile_clean = gcc-profile-clean
232 endif
233
234 ### 3.2 General compiler settings
235 CXXFLAGS = -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
236
237 ifeq ($(comp),gcc)
238         CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
239 endif
240
241 ifeq ($(comp),mingw)
242         CXXFLAGS += -Wextra -Wshadow
243 endif
244
245 ifeq ($(comp),icc)
246         CXXFLAGS += -wd383,981,1418,1419,1476,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
247 endif
248
249 ifeq ($(comp),clang)
250         CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
251 endif
252
253 ifeq ($(os),osx)
254         CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.0
255 endif
256
257 ### 3.3 General linker settings
258 LDFLAGS = $(EXTRALDFLAGS)
259
260 ifeq ($(comp),mingw)
261         LDFLAGS += -static-libstdc++ -static-libgcc
262 endif
263
264 ### On mingw use Windows threads, otherwise POSIX
265 ifneq ($(comp),mingw)
266         # On Android Bionic's C library comes with its own pthread implementation bundled in
267         ifneq ($(arch),armv7)
268                 # Haiku has pthreads in its libroot, so only link it in on other platforms
269                 ifneq ($(UNAME),Haiku)
270                         LDFLAGS += -lpthread
271                 endif
272         endif
273 endif
274
275 ifeq ($(os),osx)
276         LDFLAGS += -arch $(arch) -mmacosx-version-min=10.0
277 endif
278
279 ### 3.4 Debugging
280 ifeq ($(debug),no)
281         CXXFLAGS += -DNDEBUG
282 else
283         CXXFLAGS += -g
284 endif
285
286 ### 3.5 Optimization
287 ifeq ($(optimize),yes)
288
289         ifeq ($(comp),gcc)
290                 CXXFLAGS += -O3
291
292                 ifeq ($(os),osx)
293                         ifeq ($(arch),i386)
294                                 CXXFLAGS += -mdynamic-no-pic
295                         endif
296                         ifeq ($(arch),x86_64)
297                                 CXXFLAGS += -mdynamic-no-pic
298                         endif
299                 endif
300
301                 ifeq ($(arch),armv7)
302                         CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
303                 endif
304         endif
305
306         ifeq ($(comp),mingw)
307                 CXXFLAGS += -O3
308         endif
309
310         ifeq ($(comp),icc)
311                 ifeq ($(os),osx)
312                         CXXFLAGS += -fast -mdynamic-no-pic
313                 else
314                         CXXFLAGS += -O3
315                 endif
316         endif
317
318         ifeq ($(comp),clang)
319                 ### -O4 requires a linker that supports LLVM's LTO
320                 CXXFLAGS += -O3
321
322                 ifeq ($(os),osx)
323                         ifeq ($(arch),i386)
324                                 CXXFLAGS += -mdynamic-no-pic
325                         endif
326                         ifeq ($(arch),x86_64)
327                                 CXXFLAGS += -mdynamic-no-pic
328                         endif
329                 endif
330         endif
331 endif
332
333 ### 3.6. Bits
334 ifeq ($(bits),64)
335         CXXFLAGS += -DIS_64BIT
336 endif
337
338 ### 3.7 prefetch
339 ifeq ($(prefetch),yes)
340         ifeq ($(sse),yes)
341                 CXXFLAGS += -msse
342                 DEPENDFLAGS += -msse
343         endif
344 else
345         CXXFLAGS += -DNO_PREFETCH
346 endif
347
348 ### 3.8 bsfq
349 ifeq ($(bsfq),yes)
350         CXXFLAGS += -DUSE_BSFQ
351 endif
352
353 ### 3.9 popcnt
354 ifeq ($(popcnt),yes)
355         CXXFLAGS += -msse3 -DUSE_POPCNT
356 endif
357
358 ### 3.10 Link Time Optimization, it works since gcc 4.5 but not on mingw.
359 ### This is a mix of compile and link time options because the lto link phase
360 ### needs access to the optimization flags.
361 ifeq ($(comp),gcc)
362         ifeq ($(optimize),yes)
363         ifeq ($(debug),no)
364                 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
365                 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
366                 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
367                         CXXFLAGS += -flto
368                         LDFLAGS += $(CXXFLAGS)
369                 endif
370         endif
371         endif
372 endif
373
374 ### ==========================================================================
375 ### Section 4. Public targets
376 ### ==========================================================================
377
378 help:
379         @echo ""
380         @echo "To compile stockfish, type: "
381         @echo ""
382         @echo "make target ARCH=arch [COMP=comp]"
383         @echo ""
384         @echo "Supported targets:"
385         @echo ""
386         @echo "build                   > Standard build"
387         @echo "signature-build         > Standard build with embedded signature"
388         @echo "profile-build           > PGO build"
389         @echo "signature-profile-build > PGO build with embedded signature"
390         @echo "strip                   > Strip executable"
391         @echo "install                 > Install executable"
392         @echo "clean                   > Clean up"
393         @echo ""
394         @echo "Supported archs:"
395         @echo ""
396         @echo "x86-64                  > x86 64-bit"
397         @echo "x86-64-modern           > x86 64-bit with popcnt support"
398         @echo "x86-32                  > x86 32-bit with SSE support"
399         @echo "x86-32-old              > x86 32-bit fall back for old hardware"
400         @echo "osx-ppc-64              > PPC-Mac OS X 64 bit"
401         @echo "osx-ppc-32              > PPC-Mac OS X 32 bit"
402         @echo "osx-x86-64              > x86-Mac OS X 64 bit"
403         @echo "osx-x86-32              > x86-Mac OS X 32 bit"
404         @echo "armv7                   > ARMv7 32 bit"
405         @echo "general-64              > unspecified 64-bit"
406         @echo "general-32              > unspecified 32-bit"
407         @echo ""
408         @echo "Supported compilers:"
409         @echo ""
410         @echo "gcc                     > Gnu compiler (default)"
411         @echo "mingw                   > Gnu compiler with MinGW under Windows"
412         @echo "clang                   > LLVM Clang compiler"
413         @echo "icc                     > Intel compiler"
414         @echo ""
415         @echo "Non-standard targets:"
416         @echo ""
417         @echo "make hpux               >  Compile for HP-UX. Compiler = aCC"
418         @echo ""
419         @echo "Examples. If you don't know what to do, you likely want to run: "
420         @echo ""
421         @echo "make build ARCH=x86-64    (This is for 64-bit systems)"
422         @echo "make build ARCH=x86-32    (This is for 32-bit systems)"
423         @echo ""
424
425 .PHONY: build profile-build embed-signature
426 build:
427         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
428         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
429
430 profile-build:
431         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
432         @echo ""
433         @echo "Step 0/4. Preparing for profile build."
434         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
435         @echo ""
436         @echo "Step 1/4. Building executable for benchmark ..."
437         @touch *.cpp *.h
438         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
439         @echo ""
440         @echo "Step 2/4. Running benchmark for pgo-build ..."
441         @$(PGOBENCH) > /dev/null
442         @echo ""
443         @echo "Step 3/4. Building final executable ..."
444         @touch *.cpp
445         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
446         @echo ""
447         @echo "Step 4/4. Deleting profile data ..."
448         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
449
450 embed-signature:
451         @echo "Running benchmark for getting the signature ..."
452         @$(SIGNBENCH) 2>&1 | sed -n 's/Nodes searched  : \(.*\)/\/string Version\/s\/"\\(.*\\)"\/"sig-\1"\//p' > sign.txt
453         @sed -f sign.txt misc.cpp > misc2.cpp
454         @mv misc2.cpp misc.cpp
455         @rm sign.txt
456
457 signature-build: build embed-signature
458         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
459
460 signature-profile-build: build embed-signature profile-build
461
462 strip:
463         strip $(EXE)
464
465 install:
466         -mkdir -p -m 755 $(BINDIR)
467         -cp $(EXE) $(BINDIR)
468         -strip $(BINDIR)/$(EXE)
469
470 clean:
471         $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
472
473 default:
474         help
475
476 ### ==========================================================================
477 ### Section 5. Private targets
478 ### ==========================================================================
479
480 all: $(EXE) .depend
481
482 config-sanity:
483         @echo ""
484         @echo "Config:"
485         @echo "debug: '$(debug)'"
486         @echo "optimize: '$(optimize)'"
487         @echo "arch: '$(arch)'"
488         @echo "os: '$(os)'"
489         @echo "bits: '$(bits)'"
490         @echo "prefetch: '$(prefetch)'"
491         @echo "bsfq: '$(bsfq)'"
492         @echo "popcnt: '$(popcnt)'"
493         @echo "sse: '$(sse)'"
494         @echo ""
495         @echo "Flags:"
496         @echo "CXX: $(CXX)"
497         @echo "CXXFLAGS: $(CXXFLAGS)"
498         @echo "LDFLAGS: $(LDFLAGS)"
499         @echo ""
500         @echo "Testing config sanity. If this fails, try 'make help' ..."
501         @echo ""
502         @test "$(debug)" = "yes" || test "$(debug)" = "no"
503         @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
504         @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
505          test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
506         @test "$(os)" = "any" || test "$(os)" = "osx"
507         @test "$(bits)" = "32" || test "$(bits)" = "64"
508         @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
509         @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
510         @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
511         @test "$(sse)" = "yes" || test "$(sse)" = "no"
512         @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
513
514 $(EXE): $(OBJS)
515         $(CXX) -o $@ $(OBJS) $(LDFLAGS)
516
517 gcc-profile-prepare:
518         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
519
520 gcc-profile-make:
521         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
522         EXTRACXXFLAGS='-fprofile-generate' \
523         EXTRALDFLAGS='-lgcov' \
524         all
525
526 gcc-profile-use:
527         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
528         EXTRACXXFLAGS='-fprofile-use' \
529         EXTRALDFLAGS='-lgcov' \
530         all
531
532 gcc-profile-clean:
533         @rm -rf *.gcda *.gcno bench.txt
534
535 icc-profile-prepare:
536         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
537         @mkdir profdir
538
539 icc-profile-make:
540         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
541         EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
542         all
543
544 icc-profile-use:
545         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
546         EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
547         all
548
549 icc-profile-clean:
550         @rm -rf profdir bench.txt
551
552 .depend:
553         -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
554
555 -include .depend
556
557
558 ### ==========================================================================
559 ### Section 6. Non-standard targets
560 ### ==========================================================================
561
562 hpux:
563         $(MAKE) \
564         CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \
565         CXXFLAGS="" \
566         LDFLAGS="" \
567         all
568