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