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