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 and signature
38 PGOBENCH = ./$(EXE) bench 32 1 1 default time
39 SIGNBENCH = ./$(EXE) bench
42 OBJS = benchmark.o bitbase.o bitboard.o book.o endgame.o evaluate.o main.o \
43 material.o misc.o movegen.o movepick.o notation.o pawns.o position.o \
44 search.o thread.o timeman.o tt.o uci.o ucioption.o
46 ### ==========================================================================
47 ### Section 2. High-level Configuration
48 ### ==========================================================================
50 # flag --- Comp switch --- Description
51 # ----------------------------------------------------------------------------
53 # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
54 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
55 # arch = (name) --- (-arch) --- Target architecture
56 # os = (name) --- --- Target operating system
57 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
58 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
59 # bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
60 # with GCC and ICC 64-bit)
61 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
62 # sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
63 # pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
65 # Note that Makefile is space sensitive, so when adding new architectures
66 # or modifying existing flags, you have to make sure there are no extra spaces
67 # at the end of the line for flag values.
69 ### 2.1. General and architecture defaults
80 ### 2.2 Architecture specific
82 ifeq ($(ARCH),general-32)
86 ifeq ($(ARCH),x86-32-old)
96 ifeq ($(ARCH),general-64)
101 ifeq ($(ARCH),x86-64)
109 ifeq ($(ARCH),x86-64-modern)
118 ifeq ($(ARCH),x86-64-bmi2)
134 ifeq ($(ARCH),osx-ppc-32)
139 ifeq ($(ARCH),osx-ppc-64)
145 ifeq ($(ARCH),linux-ppc-64)
150 ifeq ($(ARCH),osx-x86-64)
159 ifeq ($(ARCH),osx-x86-64-modern)
169 ifeq ($(ARCH),osx-x86-32)
179 ### ==========================================================================
180 ### Section 3. Low-level configuration
181 ### ==========================================================================
183 ### 3.1 Selecting compiler (default = gcc)
185 CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
186 LDFLAGS += $(EXTRALDFLAGS)
195 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
201 CXXFLAGS += -Wextra -Wshadow
202 LDFLAGS += -static-libstdc++ -static-libgcc
208 CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
214 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
218 profile_prepare = icc-profile-prepare
219 profile_make = icc-profile-make
220 profile_use = icc-profile-use
221 profile_clean = icc-profile-clean
223 profile_prepare = gcc-profile-prepare
224 profile_make = gcc-profile-make
225 profile_use = gcc-profile-use
226 profile_clean = gcc-profile-clean
230 CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.6
231 LDFLAGS += -arch $(arch) -mmacosx-version-min=10.6
234 ### On mingw use Windows threads, otherwise POSIX
235 ifneq ($(comp),mingw)
236 # On Android Bionic's C library comes with its own pthread implementation bundled in
237 ifneq ($(arch),armv7)
238 # Haiku has pthreads in its libroot, so only link it in on other platforms
239 ifneq ($(UNAME),Haiku)
253 ifeq ($(optimize),yes)
260 CXXFLAGS += -mdynamic-no-pic
262 ifeq ($(arch),x86_64)
263 CXXFLAGS += -mdynamic-no-pic
268 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
278 CXXFLAGS += -fast -mdynamic-no-pic
290 CXXFLAGS += -mdynamic-no-pic
292 ifeq ($(arch),x86_64)
293 CXXFLAGS += -mdynamic-no-pic
301 CXXFLAGS += -DIS_64BIT
305 ifeq ($(prefetch),yes)
311 CXXFLAGS += -DNO_PREFETCH
316 CXXFLAGS += -DUSE_BSFQ
321 CXXFLAGS += -msse3 -DUSE_POPCNT
326 CXXFLAGS += -DUSE_PEXT
327 ifeq ($(comp),$(filter $(comp),gcc clang mingw))
332 ### 3.11 Link Time Optimization, it works since gcc 4.5 but not on mingw.
333 ### This is a mix of compile and link time options because the lto link phase
334 ### needs access to the optimization flags.
336 ifeq ($(optimize),yes)
338 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
339 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
340 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
342 LDFLAGS += $(CXXFLAGS)
348 ### ==========================================================================
349 ### Section 4. Public targets
350 ### ==========================================================================
354 @echo "To compile stockfish, type: "
356 @echo "make target ARCH=arch [COMP=comp]"
358 @echo "Supported targets:"
360 @echo "build > Standard build"
361 @echo "profile-build > PGO build"
362 @echo "strip > Strip executable"
363 @echo "install > Install executable"
364 @echo "clean > Clean up"
366 @echo "Supported archs:"
368 @echo "x86-64 > x86 64-bit"
369 @echo "x86-64-modern > x86 64-bit with popcnt support"
370 @echo "x86-64-bmi2 > x86 64-bit with pext support"
371 @echo "x86-32 > x86 32-bit with SSE support"
372 @echo "x86-32-old > x86 32-bit fall back for old hardware"
373 @echo "linux-ppc-64 > PPC-Linux 64 bit"
374 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
375 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
376 @echo "osx-x86-64-modern > x86-Mac OS X 64 bit with popcnt support"
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"
383 @echo "Supported compilers:"
385 @echo "gcc > Gnu compiler (default)"
386 @echo "mingw > Gnu compiler with MinGW under Windows"
387 @echo "clang > LLVM Clang compiler"
388 @echo "icc > Intel compiler"
390 @echo "Non-standard targets:"
392 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
394 @echo "Examples. If you don't know what to do, you likely want to run: "
396 @echo "make build ARCH=x86-64 (This is for 64-bit systems)"
397 @echo "make build ARCH=x86-32 (This is for 32-bit systems)"
400 .PHONY: build profile-build
402 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
403 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
406 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
408 @echo "Step 0/4. Preparing for profile build."
409 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
411 @echo "Step 1/4. Building executable for benchmark ..."
413 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
415 @echo "Step 2/4. Running benchmark for pgo-build ..."
416 @$(PGOBENCH) > /dev/null
418 @echo "Step 3/4. Building final executable ..."
420 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
422 @echo "Step 4/4. Deleting profile data ..."
423 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
429 -mkdir -p -m 755 $(BINDIR)
431 -strip $(BINDIR)/$(EXE)
434 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
439 ### ==========================================================================
440 ### Section 5. Private targets
441 ### ==========================================================================
448 @echo "debug: '$(debug)'"
449 @echo "optimize: '$(optimize)'"
450 @echo "arch: '$(arch)'"
452 @echo "bits: '$(bits)'"
453 @echo "prefetch: '$(prefetch)'"
454 @echo "bsfq: '$(bsfq)'"
455 @echo "popcnt: '$(popcnt)'"
456 @echo "sse: '$(sse)'"
457 @echo "pext: '$(pext)'"
461 @echo "CXXFLAGS: $(CXXFLAGS)"
462 @echo "LDFLAGS: $(LDFLAGS)"
464 @echo "Testing config sanity. If this fails, try 'make help' ..."
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 "$(sse)" = "yes" || test "$(sse)" = "no"
476 @test "$(pext)" = "yes" || test "$(pext)" = "no"
477 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
480 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
483 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
486 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
487 EXTRACXXFLAGS='-fprofile-generate' \
488 EXTRALDFLAGS='-lgcov' \
492 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
493 EXTRACXXFLAGS='-fprofile-use' \
494 EXTRALDFLAGS='-lgcov' \
498 @rm -rf *.gcda *.gcno bench.txt
501 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
505 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
506 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
510 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
511 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
515 @rm -rf profdir bench.txt
518 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
523 ### ==========================================================================
524 ### Section 6. Non-standard targets
525 ### ==========================================================================
529 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \