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