]> git.sesse.net Git - stockfish/blob - src/Makefile
Fix fallouts from previous patch
[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 # osx-section
129 ifeq ($(ARCH),osx-ppc-64)
130         arch = ppc64
131         os = osx
132         bits = 64
133         prefetch = no
134         bsfq = no
135         popcnt = no
136 endif
137
138 ifeq ($(ARCH),osx-ppc-32)
139         arch = ppc
140         os = osx
141         bits = 32
142         prefetch = no
143         bsfq = no
144         popcnt = no
145 endif
146
147 ifeq ($(ARCH),osx-x86-64)
148         arch = x86_64
149         os = osx
150         bits = 64
151         prefetch = yes
152         bsfq = yes
153         popcnt = no
154 endif
155
156 ifeq ($(ARCH),osx-x86-32)
157         arch = i386
158         os = osx
159         bits = 32
160         prefetch = yes
161         bsfq = no
162         popcnt = no
163 endif
164
165
166 ### ==========================================================================
167 ### Section 3. Low-level configuration
168 ### ==========================================================================
169
170 ### 3.1 Selecting compiler (default = gcc)
171 ifeq ($(COMP),)
172         COMP=gcc
173 endif
174
175 ifeq ($(COMP),mingw)
176         comp=mingw
177         CXX=g++
178         prefetch = yes
179         profile_prepare = gcc-profile-prepare
180         profile_make = gcc-profile-make
181         profile_use = gcc-profile-use
182         profile_clean = gcc-profile-clean
183 endif
184
185 ifeq ($(COMP),gcc)
186         comp=gcc
187         CXX=g++
188         prefetch = yes
189         profile_prepare = gcc-profile-prepare
190         profile_make = gcc-profile-make
191         profile_use = gcc-profile-use
192         profile_clean = gcc-profile-clean
193 endif
194
195 ifeq ($(COMP),icc)
196         comp=icc
197         CXX=icpc
198         profile_prepare = icc-profile-prepare
199         profile_make = icc-profile-make
200         profile_use = icc-profile-use
201         profile_clean = icc-profile-clean
202 endif
203
204 ifeq ($(COMP),clang)
205         comp=clang
206         CXX=clang++
207         prefetch = yes
208         profile_prepare = gcc-profile-prepare
209         profile_make = gcc-profile-make
210         profile_use = gcc-profile-use
211         profile_clean = gcc-profile-clean
212 endif
213
214 ### 3.2 General compiler settings
215 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
216
217 ifeq ($(comp),gcc)
218         CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
219 endif
220
221 ifeq ($(comp),mingw)
222         CXXFLAGS += -Wextra -Wshadow
223 endif
224
225 ifeq ($(comp),icc)
226         CXXFLAGS += -wd383,981,1418,1419,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
227 endif
228
229 ifeq ($(comp),clang)
230         CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
231 endif
232
233 ifeq ($(os),osx)
234         CXXFLAGS += -arch $(arch)
235 endif
236
237 ### 3.3 General linker settings
238 LDFLAGS = $(EXTRALDFLAGS)
239
240 ### On mingw use Windows threads, otherwise POSIX
241 ifneq ($(comp),mingw)
242         # Haiku has pthreads in its libroot, so only link it in on other platforms
243         ifneq ($(UNAME),Haiku)
244                 LDFLAGS += -lpthread
245         endif
246 endif
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
285         ifeq ($(comp),clang)
286                 ### -O4 requires a linker that supports LLVM's LTO
287                 CXXFLAGS += -O3
288
289                 ifeq ($(os),osx)
290                         ifeq ($(arch),i386)
291                                 CXXFLAGS += -mdynamic-no-pic
292                         endif
293                         ifeq ($(arch),x86_64)
294                                 CXXFLAGS += -mdynamic-no-pic
295                         endif
296                 endif
297         endif
298 endif
299
300 ### 3.6. Bits
301 ifeq ($(bits),64)
302         CXXFLAGS += -DIS_64BIT
303 endif
304
305 ### 3.7 prefetch
306 ifeq ($(prefetch),yes)
307         CXXFLAGS += -msse
308         DEPENDFLAGS += -msse
309 else
310         CXXFLAGS += -DNO_PREFETCH
311 endif
312
313 ### 3.8 bsfq
314 ifeq ($(bsfq),yes)
315         CXXFLAGS += -DUSE_BSFQ
316 endif
317
318 ### 3.9 popcnt
319 ifeq ($(popcnt),yes)
320         CXXFLAGS += -msse3 -DUSE_POPCNT
321 endif
322
323 ### 3.10 Link Time Optimization, it works since gcc 4.5 but not on mingw.
324 ### This is a mix of compile and link time options because the lto link phase
325 ### needs access to the optimization flags.
326 ifeq ($(comp),gcc)
327         ifeq ($(optimize),yes)
328                 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
329                 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
330                 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
331                         CXXFLAGS += -flto
332                         LDFLAGS += $(CXXFLAGS)
333                 endif
334         endif
335 endif
336
337 ### ==========================================================================
338 ### Section 4. Public targets
339 ### ==========================================================================
340
341 help:
342         @echo ""
343         @echo "To compile stockfish, type: "
344         @echo ""
345         @echo "make target ARCH=arch [COMP=comp]"
346         @echo ""
347         @echo "Supported targets:"
348         @echo ""
349         @echo "build                > Build unoptimized version"
350         @echo "profile-build        > Build PGO-optimized version"
351         @echo "strip                > Strip executable"
352         @echo "install              > Install executable"
353         @echo "clean                > Clean up"
354         @echo "testrun              > Make sample run"
355         @echo ""
356         @echo "Supported archs:"
357         @echo ""
358         @echo "x86-64               > x86 64-bit"
359         @echo "x86-64-modern        > x86 64-bit with runtime support for popcnt instruction"
360         @echo "x86-32               > x86 32-bit excluding old hardware without SSE-support"
361         @echo "x86-32-old           > x86 32-bit including also very old hardware"
362         @echo "osx-ppc-64           > PPC-Mac OS X 64 bit"
363         @echo "osx-ppc-32           > PPC-Mac OS X 32 bit"
364         @echo "osx-x86-64           > x86-Mac OS X 64 bit"
365         @echo "osx-x86-32           > x86-Mac OS X 32 bit"
366         @echo "general-64           > unspecified 64-bit"
367         @echo "general-32           > unspecified 32-bit"
368         @echo ""
369         @echo "Supported comps:"
370         @echo ""
371         @echo "gcc                  > Gnu compiler (default)"
372         @echo "icc                  > Intel compiler"
373         @echo "mingw                > Gnu compiler with MinGW under Windows"
374         @echo "clang                > LLVM Clang compiler"
375         @echo ""
376         @echo "Non-standard targets:"
377         @echo ""
378         @echo "make hpux           >  Compile for HP-UX. Compiler = aCC"
379         @echo ""
380         @echo "Examples. If you don't know what to do, you likely want to run: "
381         @echo ""
382         @echo "make profile-build ARCH=x86-64    (This is for 64-bit systems)"
383         @echo "make profile-build ARCH=x86-32    (This is for 32-bit systems)"
384         @echo ""
385
386 build:
387         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
388         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
389
390 profile-build:
391         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
392         @echo ""
393         @echo "Step 0/4. Preparing for profile build."
394         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
395         @echo ""
396         @echo "Step 1/4. Building executable for benchmark ..."
397         @touch *.cpp *.h
398         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
399         @echo ""
400         @echo "Step 2/4. Running benchmark for pgo-build ..."
401         @$(PGOBENCH) > /dev/null
402         @echo ""
403         @echo "Step 3/4. Building final executable ..."
404         @touch *.cpp
405         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
406         @echo ""
407         @echo "Step 4/4. Deleting profile data ..."
408         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
409
410 strip:
411         strip $(EXE)
412
413 install:
414         -mkdir -p -m 755 $(BINDIR)
415         -cp $(EXE) $(BINDIR)
416         -strip $(BINDIR)/$(EXE)
417
418 clean:
419         $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
420
421 testrun:
422         @$(PGOBENCH)
423
424 default:
425         help
426
427 ### ==========================================================================
428 ### Section 5. Private targets
429 ### ==========================================================================
430
431 all: $(EXE) .depend
432
433 config-sanity:
434         @echo ""
435         @echo "Config:"
436         @echo "debug: '$(debug)'"
437         @echo "optimize: '$(optimize)'"
438         @echo "arch: '$(arch)'"
439         @echo "os: '$(os)'"
440         @echo "bits: '$(bits)'"
441         @echo "prefetch: '$(prefetch)'"
442         @echo "bsfq: '$(bsfq)'"
443         @echo "popcnt: '$(popcnt)'"
444         @echo ""
445         @echo "Flags:"
446         @echo "CXX: $(CXX)"
447         @echo "CXXFLAGS: $(CXXFLAGS)"
448         @echo "LDFLAGS: $(LDFLAGS)"
449         @echo ""
450         @echo "Testing config sanity. If this fails, try 'make help' ..."
451         @echo ""
452         @test "$(debug)" = "yes" || test "$(debug)" = "no"
453         @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
454         @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
455          test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
456         @test "$(os)" = "any" || test "$(os)" = "osx"
457         @test "$(bits)" = "32" || test "$(bits)" = "64"
458         @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
459         @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
460         @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
461         @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
462
463 $(EXE): $(OBJS)
464         $(CXX) -o $@ $(OBJS) $(LDFLAGS)
465
466 gcc-profile-prepare:
467         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
468
469 gcc-profile-make:
470         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
471         EXTRACXXFLAGS='-fprofile-generate' \
472         EXTRALDFLAGS='-lgcov' \
473         all
474
475 gcc-profile-use:
476         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
477         EXTRACXXFLAGS='-fprofile-use' \
478         EXTRALDFLAGS='-lgcov' \
479         all
480
481 gcc-profile-clean:
482         @rm -rf *.gcda *.gcno bench.txt
483
484 icc-profile-prepare:
485         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
486         @mkdir profdir
487
488 icc-profile-make:
489         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
490         EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
491         all
492
493 icc-profile-use:
494         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
495         EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
496         all
497
498 icc-profile-clean:
499         @rm -rf profdir bench.txt
500
501 .depend:
502         -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
503
504 -include .depend
505
506
507 ### ==========================================================================
508 ### Section 6. Non-standard targets
509 ### ==========================================================================
510
511 hpux:
512         $(MAKE) \
513         CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \
514         CXXFLAGS="" \
515         LDFLAGS="" \
516         all
517