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 # Haiku has a non-standard filesystem layout
35 BINDIR = $(PREFIX)/bin
37 ### Built-in benchmark for pgo-builds
38 PGOBENCH = ./$(EXE) bench 32 1 1 default time
41 OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
42 material.o misc.o movegen.o movepick.o notation.o pawns.o \
43 position.o search.o thread.o timeman.o tt.o uci.o ucioption.o
45 ### ==========================================================================
46 ### Section 2. High-level Configuration
47 ### ==========================================================================
49 # flag --- Comp switch --- Description
50 # ----------------------------------------------------------------------------
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 # sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
62 # pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
64 # Note that Makefile is space sensitive, so when adding new architectures
65 # or modifying existing flags, you have to make sure there are no extra spaces
66 # at the end of the line for flag values.
68 ### 2.1. General and architecture defaults
79 ### 2.2 Architecture specific
81 ifeq ($(ARCH),general-32)
85 ifeq ($(ARCH),x86-32-old)
95 ifeq ($(ARCH),general-64)
100 ifeq ($(ARCH),x86-64)
108 ifeq ($(ARCH),x86-64-modern)
117 ifeq ($(ARCH),x86-64-bmi2)
133 ifeq ($(ARCH),ppc-32)
137 ifeq ($(ARCH),ppc-64)
143 ### ==========================================================================
144 ### Section 3. Low-level configuration
145 ### ==========================================================================
147 ### 3.1 Selecting compiler (default = gcc)
149 CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
150 LDFLAGS += $(EXTRALDFLAGS)
159 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
165 CXXFLAGS += -Wextra -Wshadow
166 LDFLAGS += -static-libstdc++ -static-libgcc
172 CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
178 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
182 profile_prepare = icc-profile-prepare
183 profile_make = icc-profile-make
184 profile_use = icc-profile-use
185 profile_clean = icc-profile-clean
187 profile_prepare = gcc-profile-prepare
188 profile_make = gcc-profile-make
189 profile_use = gcc-profile-use
190 profile_clean = gcc-profile-clean
193 ifeq ($(UNAME),Darwin)
194 CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.6
195 LDFLAGS += -arch $(arch) -mmacosx-version-min=10.6
198 ### On mingw use Windows threads, otherwise POSIX
199 ifneq ($(comp),mingw)
200 # On Android Bionic's C library comes with its own pthread implementation bundled in
201 ifneq ($(arch),armv7)
202 # Haiku has pthreads in its libroot, so only link it in on other platforms
203 ifneq ($(UNAME),Haiku)
217 ifeq ($(optimize),yes)
222 ifeq ($(UNAME),Darwin)
224 CXXFLAGS += -mdynamic-no-pic
226 ifeq ($(arch),x86_64)
227 CXXFLAGS += -mdynamic-no-pic
232 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
241 ifeq ($(UNAME),Darwin)
242 CXXFLAGS += -fast -mdynamic-no-pic
251 ifeq ($(UNAME),Darwin)
254 LDFLAGS += $(CXXFLAGS)
257 CXXFLAGS += -mdynamic-no-pic
259 ifeq ($(arch),x86_64)
260 CXXFLAGS += -mdynamic-no-pic
268 CXXFLAGS += -DIS_64BIT
272 ifeq ($(prefetch),yes)
278 CXXFLAGS += -DNO_PREFETCH
283 CXXFLAGS += -DUSE_BSFQ
288 CXXFLAGS += -msse3 -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 "Non-standard targets:"
355 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
357 @echo "Examples. If you don't know what to do, you likely want to run: "
359 @echo "make build ARCH=x86-64 (This is for 64-bit systems)"
360 @echo "make build ARCH=x86-32 (This is for 32-bit systems)"
363 .PHONY: build profile-build
365 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
366 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
369 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
371 @echo "Step 0/4. Preparing for profile build."
372 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
374 @echo "Step 1/4. Building executable for benchmark ..."
376 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
378 @echo "Step 2/4. Running benchmark for pgo-build ..."
379 @$(PGOBENCH) > /dev/null
381 @echo "Step 3/4. Building final executable ..."
383 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
385 @echo "Step 4/4. Deleting profile data ..."
386 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
392 -mkdir -p -m 755 $(BINDIR)
394 -strip $(BINDIR)/$(EXE)
397 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
402 ### ==========================================================================
403 ### Section 5. Private targets
404 ### ==========================================================================
411 @echo "debug: '$(debug)'"
412 @echo "optimize: '$(optimize)'"
413 @echo "arch: '$(arch)'"
415 @echo "bits: '$(bits)'"
416 @echo "prefetch: '$(prefetch)'"
417 @echo "bsfq: '$(bsfq)'"
418 @echo "popcnt: '$(popcnt)'"
419 @echo "sse: '$(sse)'"
420 @echo "pext: '$(pext)'"
424 @echo "CXXFLAGS: $(CXXFLAGS)"
425 @echo "LDFLAGS: $(LDFLAGS)"
427 @echo "Testing config sanity. If this fails, try 'make help' ..."
429 @test "$(debug)" = "yes" || test "$(debug)" = "no"
430 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
431 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
432 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
433 @test "$(os)" = "any"
434 @test "$(bits)" = "32" || test "$(bits)" = "64"
435 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
436 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
437 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
438 @test "$(sse)" = "yes" || test "$(sse)" = "no"
439 @test "$(pext)" = "yes" || test "$(pext)" = "no"
440 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
443 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
446 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
449 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
450 EXTRACXXFLAGS='-fprofile-generate' \
451 EXTRALDFLAGS='-lgcov' \
455 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
456 EXTRACXXFLAGS='-fprofile-use' \
457 EXTRALDFLAGS='-lgcov' \
461 @rm -rf *.gcda *.gcno bench.txt
464 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
468 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
469 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
473 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
474 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
478 @rm -rf profdir bench.txt
481 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
486 ### ==========================================================================
487 ### Section 6. Non-standard targets
488 ### ==========================================================================
492 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \