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