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