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-2014 Marco Costalba, Joona Kiiski, Tord Romstad
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.
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.
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/>.
19 ### ==========================================================================
20 ### Section 1. General Configuration
21 ### ==========================================================================
23 ### Establish the operating system name
24 UNAME = $(shell uname)
29 ### Installation dir definitions
31 BINDIR = $(PREFIX)/bin
33 ### Built-in benchmark for pgo-builds
34 PGOBENCH = ./$(EXE) bench 16 1 1 default time
37 OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
38 material.o misc.o movegen.o movepick.o pawns.o position.o \
39 search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o
41 ### ==========================================================================
42 ### Section 2. High-level Configuration
43 ### ==========================================================================
45 # flag --- Comp switch --- Description
46 # ----------------------------------------------------------------------------
48 # debug = yes/no --- -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 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
54 # bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
55 # with GCC and ICC 64-bit)
56 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
57 # sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
58 # pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
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.
64 ### 2.1. General and architecture defaults
75 ### 2.2 Architecture specific
77 ifeq ($(ARCH),general-32)
81 ifeq ($(ARCH),x86-32-old)
91 ifeq ($(ARCH),general-64)
104 ifeq ($(ARCH),x86-64-modern)
113 ifeq ($(ARCH),x86-64-bmi2)
129 ifeq ($(ARCH),ppc-32)
133 ifeq ($(ARCH),ppc-64)
139 ### ==========================================================================
140 ### Section 3. Low-level configuration
141 ### ==========================================================================
143 ### 3.1 Selecting compiler (default = gcc)
145 CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
146 LDFLAGS += $(EXTRALDFLAGS)
155 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
161 CXXFLAGS += -Wextra -Wshadow
162 LDFLAGS += -static-libstdc++ -static-libgcc
168 CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
174 CXXFLAGS += -pedantic -Wno-long-long -Wextra -Wshadow
178 profile_prepare = icc-profile-prepare
179 profile_make = icc-profile-make
180 profile_use = icc-profile-use
181 profile_clean = icc-profile-clean
183 profile_prepare = gcc-profile-prepare
184 profile_make = gcc-profile-make
185 profile_use = gcc-profile-use
186 profile_clean = gcc-profile-clean
189 ifeq ($(UNAME),Darwin)
190 CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.6
191 LDFLAGS += -arch $(arch) -mmacosx-version-min=10.6
194 ### On mingw use Windows threads, otherwise POSIX
195 ifneq ($(comp),mingw)
196 # On Android Bionic's C library comes with its own pthread implementation bundled in
197 ifneq ($(arch),armv7)
198 # Haiku has pthreads in its libroot, so only link it in on other platforms
199 ifneq ($(UNAME),Haiku)
213 ifeq ($(optimize),yes)
218 ifeq ($(UNAME),Darwin)
220 CXXFLAGS += -mdynamic-no-pic
222 ifeq ($(arch),x86_64)
223 CXXFLAGS += -mdynamic-no-pic
228 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
237 ifeq ($(UNAME),Darwin)
238 CXXFLAGS += -fast -mdynamic-no-pic
247 ifeq ($(UNAME),Darwin)
250 LDFLAGS += $(CXXFLAGS)
253 CXXFLAGS += -mdynamic-no-pic
255 ifeq ($(arch),x86_64)
256 CXXFLAGS += -mdynamic-no-pic
264 CXXFLAGS += -DIS_64BIT
268 ifeq ($(prefetch),yes)
274 CXXFLAGS += -DNO_PREFETCH
279 CXXFLAGS += -DUSE_BSFQ
285 CXXFLAGS += -msse3 -DUSE_POPCNT
287 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
293 CXXFLAGS += -DUSE_PEXT
294 ifeq ($(comp),$(filter $(comp),gcc clang mingw))
295 CXXFLAGS += -mbmi -mbmi2
299 ### 3.11 Link Time Optimization, it works since gcc 4.5 but not on mingw.
300 ### This is a mix of compile and link time options because the lto link phase
301 ### needs access to the optimization flags.
303 ifeq ($(optimize),yes)
305 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
306 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
307 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
309 LDFLAGS += $(CXXFLAGS)
315 ### ==========================================================================
316 ### Section 4. Public targets
317 ### ==========================================================================
321 @echo "To compile stockfish, type: "
323 @echo "make target ARCH=arch [COMP=comp]"
325 @echo "Supported targets:"
327 @echo "build > Standard build"
328 @echo "profile-build > PGO build"
329 @echo "strip > Strip executable"
330 @echo "install > Install executable"
331 @echo "clean > Clean up"
333 @echo "Supported archs:"
335 @echo "x86-64 > x86 64-bit"
336 @echo "x86-64-modern > x86 64-bit with popcnt support"
337 @echo "x86-64-bmi2 > x86 64-bit with pext support"
338 @echo "x86-32 > x86 32-bit with SSE support"
339 @echo "x86-32-old > x86 32-bit fall back for old hardware"
340 @echo "ppc-64 > PPC 64-bit"
341 @echo "ppc-32 > PPC 32-bit"
342 @echo "armv7 > ARMv7 32-bit"
343 @echo "general-64 > unspecified 64-bit"
344 @echo "general-32 > unspecified 32-bit"
346 @echo "Supported compilers:"
348 @echo "gcc > Gnu compiler (default)"
349 @echo "mingw > Gnu compiler with MinGW under Windows"
350 @echo "clang > LLVM Clang compiler"
351 @echo "icc > Intel compiler"
353 @echo "Examples. If you don't know what to do, you likely want to run: "
355 @echo "make build ARCH=x86-64 (This is for 64-bit systems)"
356 @echo "make build ARCH=x86-32 (This is for 32-bit systems)"
359 .PHONY: build profile-build
361 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
362 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
365 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
367 @echo "Step 0/4. Preparing for profile build."
368 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
370 @echo "Step 1/4. Building executable for benchmark ..."
372 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
374 @echo "Step 2/4. Running benchmark for pgo-build ..."
375 @$(PGOBENCH) > /dev/null
377 @echo "Step 3/4. Building final executable ..."
379 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
381 @echo "Step 4/4. Deleting profile data ..."
382 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
388 -mkdir -p -m 755 $(BINDIR)
390 -strip $(BINDIR)/$(EXE)
393 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda ./syzygy/*.o ./syzygy/*.gcda
398 ### ==========================================================================
399 ### Section 5. Private targets
400 ### ==========================================================================
407 @echo "debug: '$(debug)'"
408 @echo "optimize: '$(optimize)'"
409 @echo "arch: '$(arch)'"
411 @echo "bits: '$(bits)'"
412 @echo "prefetch: '$(prefetch)'"
413 @echo "bsfq: '$(bsfq)'"
414 @echo "popcnt: '$(popcnt)'"
415 @echo "sse: '$(sse)'"
416 @echo "pext: '$(pext)'"
420 @echo "CXXFLAGS: $(CXXFLAGS)"
421 @echo "LDFLAGS: $(LDFLAGS)"
423 @echo "Testing config sanity. If this fails, try 'make help' ..."
425 @test "$(debug)" = "yes" || test "$(debug)" = "no"
426 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
427 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
428 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
429 @test "$(os)" = "any"
430 @test "$(bits)" = "32" || test "$(bits)" = "64"
431 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
432 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
433 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
434 @test "$(sse)" = "yes" || test "$(sse)" = "no"
435 @test "$(pext)" = "yes" || test "$(pext)" = "no"
436 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
439 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
442 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
445 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
446 EXTRACXXFLAGS='-fprofile-generate' \
447 EXTRALDFLAGS='-lgcov' \
451 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
452 EXTRACXXFLAGS='-fprofile-use' \
453 EXTRALDFLAGS='-lgcov' \
457 @rm -rf *.gcda *.gcno syzygy/*.gcda syzygy/*.gcno bench.txt
460 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
464 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
465 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
469 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
470 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
474 @rm -rf profdir bench.txt
477 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null