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