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