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