]> git.sesse.net Git - stockfish/blob - src/Makefile
Split at root!
[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 = 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 = no/yes      --- -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 = no/yes  --- -DBIGENDIAN --- big/little-endian byte order
51 # prefetch = no/yes   --- -DUSE_PREFETCH  --- Use prefetch x86 asm-instruction
52 # bsfq = no/yes       --- -DUSE_BSFQ  --- Use bsfq x86_64 asm-instruction
53 #                                     --- (Works only with GCC and ICC 64-bit)
54 # popcnt = no/yes     --- -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 = -lpthread $(EXTRALDFLAGS)
247
248 ifeq ($(os),osx)
249         LDFLAGS += -arch $(arch)
250 endif
251
252 ### 3.4 Debugging
253 ifeq ($(debug),no)
254         CXXFLAGS += -DNDEBUG
255 endif
256
257 ### 3.5 Optimization
258 ifeq ($(optimize),yes)
259
260         ifeq ($(comp),gcc)
261                 CXXFLAGS += -O3
262
263                 ifeq ($(os),osx)
264                         ifeq ($(arch),i386)
265                                 CXXFLAGS += -mdynamic-no-pic
266                         endif
267                         ifeq ($(arch),x86_64)
268                                 CXXFLAGS += -mdynamic-no-pic
269                         endif
270                 endif
271         endif
272
273         ifeq ($(comp),mingw)
274                 CXXFLAGS += -O3
275         endif
276
277         ifeq ($(comp),icc)
278                 ifeq ($(os),osx)
279                         CXXFLAGS += -fast -mdynamic-no-pic
280                 else
281                         CXXFLAGS += -O3
282                 endif
283         endif
284 endif
285
286 ### 3.6. Bits
287 ifeq ($(bits),64)
288         CXXFLAGS += -DIS_64BIT
289 endif
290
291 ### 3.7 Endianess
292 ifeq ($(bigendian),yes)
293         CXXFLAGS += -DBIGENDIAN
294 endif
295
296 ### 3.8 prefetch
297 ifeq ($(prefetch),yes)
298         CXXFLAGS += -msse
299         DEPENDFLAGS += -msse
300 else
301         CXXFLAGS += -DNO_PREFETCH
302 endif
303
304 ### 3.9 bsfq
305 ifeq ($(bsfq),yes)
306         CXXFLAGS += -DUSE_BSFQ
307 endif
308
309 ### 3.10 popcnt
310 ifeq ($(popcnt),yes)
311         CXXFLAGS += -DUSE_POPCNT
312 endif
313
314 ### ==========================================================================
315 ### Section 4. Public targets
316 ### ==========================================================================
317
318 help:
319         @echo ""
320         @echo "To compile stockfish, type: "
321         @echo ""
322         @echo "make target ARCH=arch [COMP=comp]"
323         @echo ""
324         @echo "Supported targets:"
325         @echo ""
326         @echo "build                > Build unoptimized version"
327         @echo "profile-build        > Build PGO-optimized version"
328         @echo "popcnt-profile-build > Build PGO-optimized version with optional popcnt-support"
329         @echo "strip                > Strip executable"
330         @echo "install              > Install executable"
331         @echo "clean                > Clean up"
332         @echo "testrun              > Make sample run"
333         @echo ""
334         @echo "Supported archs:"
335         @echo ""
336         @echo "x86-64               > x86 64-bit"
337         @echo "x86-64-modern        > x86 64-bit with runtime support for popcnt-instruction"
338         @echo "x86-32               > x86 32-bit excluding very old hardware without SSE-support"
339         @echo "x86-32-old           > x86 32-bit including also very old hardware"
340         @echo "osx-ppc-64           > PPC-Mac OS X 64 bit"
341         @echo "osx-ppc-32           > PPC-Mac OS X 32 bit"
342         @echo "osx-x86-64           > x86-Mac OS X 64 bit"
343         @echo "osx-x86-32           > x86-Mac OS X 32 bit"
344         @echo "general-64           > unspecified 64-bit"
345         @echo "general-32           > unspecified 32-bit"
346         @echo "bigendian-64         > unspecified 64-bit with bigendian byte order"
347         @echo "bigendian-32         > unspecified 32-bit with bigendian byte order"
348         @echo ""
349         @echo "Supported comps:"
350         @echo ""
351         @echo "gcc                  > Gnu compiler (default)"
352         @echo "icc                  > Intel compiler"
353         @echo "mingw                > Gnu compiler with MinGW under Windows"
354         @echo ""
355         @echo "Non-standard targets:"
356         @echo ""
357         @echo "make hpux           >  Compile for HP-UX. Compiler = aCC"
358         @echo ""
359         @echo "Examples. If you don't know what to do, you likely want to run: "
360         @echo ""
361         @echo "make profile-build ARCH=x86-64    (This is for 64-bit systems)"
362         @echo "make profile-build ARCH=x86-32    (This is for 32-bit systems)"
363         @echo ""
364
365 build:
366         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
367         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
368
369 profile-build:
370         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
371         @echo ""
372         @echo "Step 0/4. Preparing for profile build."
373         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
374         @echo ""
375         @echo "Step 1/4. Building executable for benchmark ..."
376         @touch *.cpp *.h
377         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
378         @echo ""
379         @echo "Step 2/4. Running benchmark for pgo-build ..."
380         @$(PGOBENCH) > /dev/null
381         @echo ""
382         @echo "Step 3/4. Building final executable ..."
383         @touch *.cpp
384         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
385         @echo ""
386         @echo "Step 4/4. Deleting profile data ..."
387         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
388
389 popcnt-profile-build:
390         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
391         @echo ""
392         @echo "Step 0/6. Preparing for profile build."
393         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
394         @echo ""
395         @echo "Step 1/6. Building executable for benchmark (popcnt disabled)..."
396         @touch *.cpp *.h
397         $(MAKE) ARCH=x86-64 COMP=$(COMP) $(profile_make)
398         @echo ""
399         @echo "Step 2/6. Running benchmark for pgo-build (popcnt disabled)..."
400         @$(PGOBENCH) > /dev/null
401         @echo ""
402         @echo "Step 3/6. Building executable for benchmark (popcnt enabled)..."
403         @touch *.cpp *.h
404         $(MAKE) ARCH=x86-64-modern COMP=$(COMP) $(profile_make)
405         @echo ""
406         @echo "Step 4/6. Running benchmark for pgo-build (popcnt enabled)..."
407         @$(PGOBENCH) > /dev/null
408         @echo ""
409         @echo "Step 5/6. Building final executable ..."
410         @touch *.cpp *.h
411         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
412         @echo ""
413         @echo "Step 6/6. Deleting profile data ..."
414         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
415         @echo ""
416
417 strip:
418         strip $(EXE)
419
420 install:
421         -mkdir -p -m 755 $(BINDIR)
422         -cp $(EXE) $(BINDIR)
423         -strip $(BINDIR)/$(EXE)
424
425 clean:
426         $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
427
428 testrun:
429         @$(PGOBENCH)
430
431 default:
432         help
433
434 ### ==========================================================================
435 ### Section 5. Private targets
436 ### ==========================================================================
437
438 all: $(EXE) .depend
439
440 config-sanity:
441         @echo ""
442         @echo "Config:"
443         @echo "debug: '$(debug)'"
444         @echo "optimize: '$(optimize)'"
445         @echo "arch: '$(arch)'"
446         @echo "os: '$(os)'"
447         @echo "bits: '$(bits)'"
448         @echo "bigendian: '$(bigendian)'"
449         @echo "prefetch: '$(prefetch)'"
450         @echo "bsfq: '$(bsfq)'"
451         @echo "popcnt: '$(popcnt)'"
452         @echo ""
453         @echo "Flags:"
454         @echo "CXX: $(CXX)"
455         @echo "CXXFLAGS: $(CXXFLAGS)"
456         @echo "LDFLAGS: $(LDFLAGS)"
457         @echo ""
458         @echo "Testing config sanity. If this fails, try 'make help' ..."
459         @echo ""
460         @test "$(debug)" = "yes" || test "$(debug)" = "no"
461         @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
462         @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
463          test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
464         @test "$(os)" = "any" || test "$(os)" = "osx"
465         @test "$(bits)" = "32" || test "$(bits)" = "64"
466         @test "$(bigendian)" = "yes" || test "$(bigendian)" = "no"
467         @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
468         @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
469         @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
470         @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw"
471
472 $(EXE): $(OBJS)
473         $(CXX) -o $@ $(OBJS) $(LDFLAGS)
474
475 gcc-profile-prepare:
476         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
477
478 gcc-profile-make:
479         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
480         EXTRACXXFLAGS='-fprofile-generate' \
481         EXTRALDFLAGS='-lgcov' \
482         all
483
484 gcc-profile-use:
485         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
486         EXTRACXXFLAGS='-fprofile-use' \
487         all
488
489 gcc-profile-clean:
490         @rm -rf *.gcda *.gcno bench.txt
491
492 icc-profile-prepare:
493         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
494         @mkdir profdir
495
496 icc-profile-make:
497         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
498         EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
499         all
500
501 icc-profile-use:
502         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
503         EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
504         all
505
506 icc-profile-clean:
507         @rm -rf profdir bench.txt
508
509 .depend:
510         -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
511
512 -include .depend
513
514
515 ### ==========================================================================
516 ### Section 6. Non-standard targets
517 ### ==========================================================================
518
519 hpux:
520         $(MAKE) \
521         CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG -DNO_PREFETCH' \
522         CXXFLAGS="" \
523         LDFLAGS="" \
524         all
525