2008-11-02 07:35:32 -07:00
|
|
|
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
2010-05-19 11:37:56 -06:00
|
|
|
# Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
2016-01-02 02:43:25 -07:00
|
|
|
# Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
2018-11-19 03:18:21 -07:00
|
|
|
# Copyright (C) 2015-2019 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
2010-05-19 11:37:56 -06:00
|
|
|
#
|
2008-11-02 07:35:32 -07:00
|
|
|
# Stockfish is free software: you can redistribute it and/or modify
|
2008-08-31 23:59:13 -06:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2008-11-02 07:35:32 -07:00
|
|
|
# Stockfish is distributed in the hope that it will be useful,
|
2008-08-31 23:59:13 -06:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
### ==========================================================================
|
|
|
|
### Section 1. General Configuration
|
|
|
|
### ==========================================================================
|
|
|
|
|
|
|
|
### Executable name
|
2018-04-26 16:07:56 -06:00
|
|
|
ifeq ($(COMP),mingw)
|
|
|
|
EXE = stockfish.exe
|
|
|
|
else
|
2008-11-02 07:35:32 -07:00
|
|
|
EXE = stockfish
|
2018-04-26 16:07:56 -06:00
|
|
|
endif
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2010-02-11 22:49:16 -07:00
|
|
|
### Installation dir definitions
|
|
|
|
PREFIX = /usr/local
|
|
|
|
BINDIR = $(PREFIX)/bin
|
|
|
|
|
2014-04-28 02:30:06 -06:00
|
|
|
### Built-in benchmark for pgo-builds
|
2016-09-17 05:37:11 -06:00
|
|
|
PGOBENCH = ./$(EXE) bench
|
2010-05-19 11:37:56 -06:00
|
|
|
|
2020-05-08 05:07:42 -06:00
|
|
|
### Source and object files
|
|
|
|
SRCS = benchmark.cpp bitbase.cpp bitboard.cpp endgame.cpp evaluate.cpp main.cpp \
|
|
|
|
material.cpp misc.cpp movegen.cpp movepick.cpp pawns.cpp position.cpp psqt.cpp \
|
|
|
|
search.cpp thread.cpp timeman.cpp tt.cpp uci.cpp ucioption.cpp tune.cpp syzygy/tbprobe.cpp
|
|
|
|
|
|
|
|
OBJS = $(notdir $(SRCS:.cpp=.o))
|
|
|
|
|
|
|
|
VPATH = syzygy
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2018-03-03 03:07:23 -07:00
|
|
|
### Establish the operating system name
|
|
|
|
KERNEL = $(shell uname -s)
|
|
|
|
ifeq ($(KERNEL),Linux)
|
|
|
|
OS = $(shell uname -o)
|
|
|
|
endif
|
|
|
|
|
2009-08-08 01:12:31 -06:00
|
|
|
### ==========================================================================
|
2010-05-19 11:37:56 -06:00
|
|
|
### Section 2. High-level Configuration
|
2009-08-08 01:12:31 -06:00
|
|
|
### ==========================================================================
|
2010-05-19 11:37:56 -06:00
|
|
|
#
|
2020-06-23 09:56:38 -06:00
|
|
|
# flag --- Comp switch --- Description
|
2010-05-19 11:37:56 -06:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
#
|
2011-10-08 01:17:37 -06:00
|
|
|
# debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
|
Fix four data races.
the nodes, tbHits, rootDepth and lastInfoTime variables are read by multiple threads, but not declared atomic, leading to data races as found by -fsanitize=thread. This patch fixes this issue. It is based on top of the CI-threading branch (PR #1129), and should fix the corresponding CI error messages.
The patch passed an STC check for no regression:
http://tests.stockfishchess.org/tests/view/5925d5590ebc59035df34b9f
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 169597 W: 29938 L: 30066 D: 109593
Whereas rootDepth and lastInfoTime are not performance critical, nodes and tbHits are. Indeed, an earlier version using relaxed atomic updates on the latter two variables failed STC testing (http://tests.stockfishchess.org/tests/view/592001700ebc59035df34924), which can be shown to be due to x86-32 (http://tests.stockfishchess.org/tests/view/592330ac0ebc59035df34a89). Indeed, the latter have no instruction to atomically update a 64bit variable. The proposed solution thus uses a variable in Position that is accessed only by one thread, which is copied every few thousand nodes to the shared variable in Thread.
No functional change.
Closes #1130
Closes #1129
2017-06-21 14:36:53 -06:00
|
|
|
# sanitize = undefined/thread/no (-fsanitize )
|
|
|
|
# --- ( undefined ) --- enable undefined behavior checks
|
|
|
|
# --- ( thread ) --- enable threading error checks
|
2010-05-19 11:37:56 -06:00
|
|
|
# optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
|
2011-10-08 01:17:37 -06:00
|
|
|
# arch = (name) --- (-arch) --- Target architecture
|
|
|
|
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
2016-03-28 02:08:06 -06:00
|
|
|
# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
|
|
|
|
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
|
2012-10-14 17:13:41 -06:00
|
|
|
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
|
2014-04-10 12:07:40 -06:00
|
|
|
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
|
2010-05-19 11:37:56 -06:00
|
|
|
#
|
|
|
|
# Note that Makefile is space sensitive, so when adding new architectures
|
|
|
|
# or modifying existing flags, you have to make sure there are no extra spaces
|
|
|
|
# at the end of the line for flag values.
|
|
|
|
|
2013-12-17 01:30:42 -07:00
|
|
|
### 2.1. General and architecture defaults
|
2010-05-19 11:37:56 -06:00
|
|
|
optimize = yes
|
2014-04-10 12:07:40 -06:00
|
|
|
debug = no
|
2016-10-26 13:24:26 -06:00
|
|
|
sanitize = no
|
2020-06-23 09:56:38 -06:00
|
|
|
bits = 64
|
2013-12-17 01:30:42 -07:00
|
|
|
prefetch = no
|
|
|
|
popcnt = no
|
|
|
|
sse = no
|
2014-04-10 12:07:40 -06:00
|
|
|
pext = no
|
2013-12-17 01:30:42 -07:00
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
### 2.2 Architecture specific
|
2014-01-21 15:18:39 -07:00
|
|
|
ifeq ($(ARCH),general-32)
|
|
|
|
arch = any
|
2020-06-23 09:56:38 -06:00
|
|
|
bits = 32
|
2014-01-21 15:18:39 -07:00
|
|
|
endif
|
|
|
|
|
2013-12-17 01:30:42 -07:00
|
|
|
ifeq ($(ARCH),x86-32-old)
|
|
|
|
arch = i386
|
2020-06-23 09:56:38 -06:00
|
|
|
bits = 32
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
2013-12-17 01:30:42 -07:00
|
|
|
ifeq ($(ARCH),x86-32)
|
|
|
|
arch = i386
|
2020-06-23 09:56:38 -06:00
|
|
|
bits = 32
|
2013-12-17 01:30:42 -07:00
|
|
|
prefetch = yes
|
|
|
|
sse = yes
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(ARCH),general-64)
|
2014-01-21 15:18:39 -07:00
|
|
|
arch = any
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(ARCH),x86-64)
|
|
|
|
arch = x86_64
|
|
|
|
prefetch = yes
|
2012-10-14 17:13:41 -06:00
|
|
|
sse = yes
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(ARCH),x86-64-modern)
|
|
|
|
arch = x86_64
|
|
|
|
prefetch = yes
|
|
|
|
popcnt = yes
|
2012-10-14 17:13:41 -06:00
|
|
|
sse = yes
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
2014-04-10 12:07:40 -06:00
|
|
|
ifeq ($(ARCH),x86-64-bmi2)
|
|
|
|
arch = x86_64
|
|
|
|
prefetch = yes
|
|
|
|
popcnt = yes
|
|
|
|
sse = yes
|
|
|
|
pext = yes
|
|
|
|
endif
|
|
|
|
|
2012-10-11 08:55:25 -06:00
|
|
|
ifeq ($(ARCH),armv7)
|
|
|
|
arch = armv7
|
2012-10-10 05:34:06 -06:00
|
|
|
prefetch = yes
|
2020-06-23 09:56:38 -06:00
|
|
|
bits = 32
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
2020-06-23 02:41:53 -06:00
|
|
|
ifeq ($(ARCH),armv8)
|
|
|
|
arch = armv8-a
|
|
|
|
bits = 64
|
|
|
|
prefetch = yes
|
|
|
|
endif
|
|
|
|
|
2014-04-12 17:26:45 -06:00
|
|
|
ifeq ($(ARCH),ppc-32)
|
2010-05-19 11:37:56 -06:00
|
|
|
arch = ppc
|
2020-06-23 09:56:38 -06:00
|
|
|
bits = 32
|
2013-12-17 01:30:42 -07:00
|
|
|
endif
|
|
|
|
|
2014-04-12 17:26:45 -06:00
|
|
|
ifeq ($(ARCH),ppc-64)
|
2013-12-17 01:30:42 -07:00
|
|
|
arch = ppc64
|
2019-07-10 17:12:54 -06:00
|
|
|
popcnt = yes
|
|
|
|
prefetch = yes
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
2009-11-05 11:29:26 -07:00
|
|
|
### ==========================================================================
|
2020-06-23 09:56:38 -06:00
|
|
|
### Section 3. Low-level Configuration
|
2009-11-05 11:29:26 -07:00
|
|
|
### ==========================================================================
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
### 3.1 Selecting compiler (default = gcc)
|
2017-11-28 08:50:31 -07:00
|
|
|
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS)
|
2015-03-14 15:12:13 -06:00
|
|
|
DEPENDFLAGS += -std=c++11
|
2013-12-17 02:14:15 -07:00
|
|
|
LDFLAGS += $(EXTRALDFLAGS)
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
ifeq ($(COMP),)
|
|
|
|
COMP=gcc
|
|
|
|
endif
|
|
|
|
|
2013-12-17 02:14:15 -07:00
|
|
|
ifeq ($(COMP),gcc)
|
|
|
|
comp=gcc
|
2010-11-01 05:17:54 -06:00
|
|
|
CXX=g++
|
2016-10-08 04:15:43 -06:00
|
|
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
|
|
|
|
2020-06-23 02:41:53 -06:00
|
|
|
ifeq ($(ARCH),$(filter $(ARCH),armv7 armv8))
|
2016-10-08 04:15:43 -06:00
|
|
|
ifeq ($(OS),Android)
|
|
|
|
CXXFLAGS += -m$(bits)
|
2017-03-14 22:00:03 -06:00
|
|
|
LDFLAGS += -m$(bits)
|
2016-10-08 04:15:43 -06:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
CXXFLAGS += -m$(bits)
|
2017-02-14 22:11:44 -07:00
|
|
|
LDFLAGS += -m$(bits)
|
2016-10-08 04:15:43 -06:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(KERNEL),Darwin)
|
2015-03-02 14:01:19 -07:00
|
|
|
LDFLAGS += -Wl,--no-as-needed
|
|
|
|
endif
|
2010-11-01 05:17:54 -06:00
|
|
|
endif
|
|
|
|
|
2013-12-17 02:14:15 -07:00
|
|
|
ifeq ($(COMP),mingw)
|
|
|
|
comp=mingw
|
2015-12-03 06:59:27 -07:00
|
|
|
|
2016-10-08 04:15:43 -06:00
|
|
|
ifeq ($(KERNEL),Linux)
|
2015-12-23 01:37:59 -07:00
|
|
|
ifeq ($(bits),64)
|
|
|
|
ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
|
|
|
|
CXX=x86_64-w64-mingw32-c++
|
|
|
|
else
|
|
|
|
CXX=x86_64-w64-mingw32-c++-posix
|
|
|
|
endif
|
2015-12-03 06:59:27 -07:00
|
|
|
else
|
2015-12-23 01:37:59 -07:00
|
|
|
ifeq ($(shell which i686-w64-mingw32-c++-posix),)
|
|
|
|
CXX=i686-w64-mingw32-c++
|
|
|
|
else
|
|
|
|
CXX=i686-w64-mingw32-c++-posix
|
|
|
|
endif
|
2015-12-03 06:59:27 -07:00
|
|
|
endif
|
|
|
|
else
|
2015-12-23 01:37:59 -07:00
|
|
|
CXX=g++
|
2015-12-03 06:59:27 -07:00
|
|
|
endif
|
|
|
|
|
2013-12-17 02:14:15 -07:00
|
|
|
CXXFLAGS += -Wextra -Wshadow
|
2015-03-14 01:49:50 -06:00
|
|
|
LDFLAGS += -static
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(COMP),icc)
|
|
|
|
comp=icc
|
|
|
|
CXX=icpc
|
2013-12-17 02:14:15 -07:00
|
|
|
CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
2012-04-29 03:14:50 -06:00
|
|
|
ifeq ($(COMP),clang)
|
|
|
|
comp=clang
|
|
|
|
CXX=clang++
|
2016-10-08 04:15:43 -06:00
|
|
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
2018-03-03 03:07:23 -07:00
|
|
|
|
|
|
|
ifneq ($(KERNEL),Darwin)
|
|
|
|
ifneq ($(KERNEL),OpenBSD)
|
|
|
|
LDFLAGS += -latomic
|
|
|
|
endif
|
|
|
|
endif
|
2016-10-08 04:15:43 -06:00
|
|
|
|
2020-06-23 02:41:53 -06:00
|
|
|
ifeq ($(ARCH),$(filter $(ARCH),armv7 armv8))
|
2016-10-08 04:15:43 -06:00
|
|
|
ifeq ($(OS),Android)
|
|
|
|
CXXFLAGS += -m$(bits)
|
|
|
|
LDFLAGS += -m$(bits)
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
CXXFLAGS += -m$(bits)
|
|
|
|
LDFLAGS += -m$(bits)
|
|
|
|
endif
|
2013-12-17 01:30:42 -07:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(comp),icc)
|
|
|
|
profile_make = icc-profile-make
|
|
|
|
profile_use = icc-profile-use
|
2016-11-25 08:59:38 -07:00
|
|
|
else
|
|
|
|
ifeq ($(comp),clang)
|
|
|
|
profile_make = clang-profile-make
|
|
|
|
profile_use = clang-profile-use
|
2013-12-17 01:30:42 -07:00
|
|
|
else
|
2012-04-29 03:14:50 -06:00
|
|
|
profile_make = gcc-profile-make
|
|
|
|
profile_use = gcc-profile-use
|
|
|
|
endif
|
2016-11-25 08:59:38 -07:00
|
|
|
endif
|
2012-04-29 03:14:50 -06:00
|
|
|
|
2016-10-08 04:15:43 -06:00
|
|
|
ifeq ($(KERNEL),Darwin)
|
2015-03-02 14:01:19 -07:00
|
|
|
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
|
|
|
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
2013-02-20 21:27:26 -07:00
|
|
|
endif
|
|
|
|
|
2015-10-06 03:59:06 -06:00
|
|
|
### Travis CI script uses COMPILER to overwrite CXX
|
|
|
|
ifdef COMPILER
|
2016-01-17 08:24:18 -07:00
|
|
|
COMPCXX=$(COMPILER)
|
|
|
|
endif
|
|
|
|
|
|
|
|
### Allow overwriting CXX from command line
|
|
|
|
ifdef COMPCXX
|
|
|
|
CXX=$(COMPCXX)
|
2015-10-06 03:59:06 -06:00
|
|
|
endif
|
|
|
|
|
2012-01-27 11:41:12 -07:00
|
|
|
### On mingw use Windows threads, otherwise POSIX
|
|
|
|
ifneq ($(comp),mingw)
|
2013-09-01 14:37:26 -06:00
|
|
|
# On Android Bionic's C library comes with its own pthread implementation bundled in
|
2016-10-08 04:15:43 -06:00
|
|
|
ifneq ($(OS),Android)
|
2013-09-01 14:37:26 -06:00
|
|
|
# Haiku has pthreads in its libroot, so only link it in on other platforms
|
2016-10-08 04:15:43 -06:00
|
|
|
ifneq ($(KERNEL),Haiku)
|
2013-09-01 14:37:26 -06:00
|
|
|
LDFLAGS += -lpthread
|
|
|
|
endif
|
2012-07-29 18:13:27 -06:00
|
|
|
endif
|
2012-01-27 11:41:12 -07:00
|
|
|
endif
|
2010-05-19 11:37:56 -06:00
|
|
|
|
2016-10-26 13:24:26 -06:00
|
|
|
### 3.2.1 Debugging
|
2010-05-19 11:37:56 -06:00
|
|
|
ifeq ($(debug),no)
|
|
|
|
CXXFLAGS += -DNDEBUG
|
2013-07-03 00:21:21 -06:00
|
|
|
else
|
2013-07-15 13:39:06 -06:00
|
|
|
CXXFLAGS += -g
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
2016-10-26 13:24:26 -06:00
|
|
|
### 3.2.2 Debugging with undefined behavior sanitizers
|
Fix four data races.
the nodes, tbHits, rootDepth and lastInfoTime variables are read by multiple threads, but not declared atomic, leading to data races as found by -fsanitize=thread. This patch fixes this issue. It is based on top of the CI-threading branch (PR #1129), and should fix the corresponding CI error messages.
The patch passed an STC check for no regression:
http://tests.stockfishchess.org/tests/view/5925d5590ebc59035df34b9f
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 169597 W: 29938 L: 30066 D: 109593
Whereas rootDepth and lastInfoTime are not performance critical, nodes and tbHits are. Indeed, an earlier version using relaxed atomic updates on the latter two variables failed STC testing (http://tests.stockfishchess.org/tests/view/592001700ebc59035df34924), which can be shown to be due to x86-32 (http://tests.stockfishchess.org/tests/view/592330ac0ebc59035df34a89). Indeed, the latter have no instruction to atomically update a 64bit variable. The proposed solution thus uses a variable in Position that is accessed only by one thread, which is copied every few thousand nodes to the shared variable in Thread.
No functional change.
Closes #1130
Closes #1129
2017-06-21 14:36:53 -06:00
|
|
|
ifneq ($(sanitize),no)
|
|
|
|
CXXFLAGS += -g3 -fsanitize=$(sanitize) -fuse-ld=gold
|
|
|
|
LDFLAGS += -fsanitize=$(sanitize) -fuse-ld=gold
|
2016-10-26 13:24:26 -06:00
|
|
|
endif
|
|
|
|
|
2016-04-23 17:55:56 -06:00
|
|
|
### 3.3 Optimization
|
2010-05-19 11:37:56 -06:00
|
|
|
ifeq ($(optimize),yes)
|
|
|
|
|
2016-04-23 17:55:56 -06:00
|
|
|
CXXFLAGS += -O3
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
ifeq ($(comp),gcc)
|
2016-10-08 04:15:43 -06:00
|
|
|
ifeq ($(OS), Android)
|
2013-09-01 10:16:55 -06:00
|
|
|
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
|
2012-10-10 05:34:06 -06:00
|
|
|
endif
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
2019-10-18 18:20:38 -06:00
|
|
|
|
2018-02-09 18:39:57 -07:00
|
|
|
ifeq ($(comp),$(filter $(comp),gcc clang icc))
|
2016-10-08 04:15:43 -06:00
|
|
|
ifeq ($(KERNEL),Darwin)
|
2016-04-23 17:55:56 -06:00
|
|
|
CXXFLAGS += -mdynamic-no-pic
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2016-04-23 17:55:56 -06:00
|
|
|
### 3.4 Bits
|
2010-05-19 11:37:56 -06:00
|
|
|
ifeq ($(bits),64)
|
|
|
|
CXXFLAGS += -DIS_64BIT
|
|
|
|
endif
|
|
|
|
|
2016-04-23 17:55:56 -06:00
|
|
|
### 3.5 prefetch
|
2010-05-19 11:37:56 -06:00
|
|
|
ifeq ($(prefetch),yes)
|
2012-10-14 17:13:41 -06:00
|
|
|
ifeq ($(sse),yes)
|
2012-10-10 05:34:06 -06:00
|
|
|
CXXFLAGS += -msse
|
|
|
|
DEPENDFLAGS += -msse
|
|
|
|
endif
|
2010-05-20 23:05:36 -06:00
|
|
|
else
|
|
|
|
CXXFLAGS += -DNO_PREFETCH
|
2010-05-19 11:37:56 -06:00
|
|
|
endif
|
|
|
|
|
2016-04-23 17:55:56 -06:00
|
|
|
### 3.6 popcnt
|
2010-05-19 11:37:56 -06:00
|
|
|
ifeq ($(popcnt),yes)
|
2019-07-10 17:12:54 -06:00
|
|
|
ifeq ($(arch),ppc64)
|
|
|
|
CXXFLAGS += -DUSE_POPCNT
|
|
|
|
else ifeq ($(comp),icc)
|
2014-10-05 02:53:31 -06:00
|
|
|
CXXFLAGS += -msse3 -DUSE_POPCNT
|
|
|
|
else
|
|
|
|
CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
|
|
|
|
endif
|
2011-11-12 02:10:01 -07:00
|
|
|
endif
|
|
|
|
|
2016-04-23 17:55:56 -06:00
|
|
|
### 3.7 pext
|
2014-04-10 12:07:40 -06:00
|
|
|
ifeq ($(pext),yes)
|
|
|
|
CXXFLAGS += -DUSE_PEXT
|
|
|
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
2019-09-12 13:25:58 -06:00
|
|
|
CXXFLAGS += -msse4 -mbmi2
|
2014-04-10 12:07:40 -06:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2020-06-21 07:21:46 -06:00
|
|
|
### 3.8 Link Time Optimization
|
2011-11-12 02:10:01 -07:00
|
|
|
### This is a mix of compile and link time options because the lto link phase
|
|
|
|
### needs access to the optimization flags.
|
2018-02-05 16:43:29 -07:00
|
|
|
ifeq ($(optimize),yes)
|
|
|
|
ifeq ($(debug), no)
|
2020-06-23 09:56:38 -06:00
|
|
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
2015-12-03 06:59:27 -07:00
|
|
|
CXXFLAGS += -flto
|
|
|
|
LDFLAGS += $(CXXFLAGS)
|
|
|
|
endif
|
2018-02-05 16:43:29 -07:00
|
|
|
endif
|
2015-12-03 06:59:27 -07:00
|
|
|
endif
|
|
|
|
|
2016-04-23 17:55:56 -06:00
|
|
|
### 3.9 Android 5 can only run position independent executables. Note that this
|
2015-01-10 08:14:37 -07:00
|
|
|
### breaks Android 4.0 and earlier.
|
2016-10-08 04:15:43 -06:00
|
|
|
ifeq ($(OS), Android)
|
2015-01-10 08:14:37 -07:00
|
|
|
CXXFLAGS += -fPIE
|
|
|
|
LDFLAGS += -fPIE -pie
|
|
|
|
endif
|
|
|
|
|
2009-08-07 20:30:27 -06:00
|
|
|
### ==========================================================================
|
2020-06-23 09:56:38 -06:00
|
|
|
### Section 4. Public Targets
|
2009-08-07 20:30:27 -06:00
|
|
|
### ==========================================================================
|
|
|
|
|
|
|
|
help:
|
|
|
|
@echo ""
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo "To compile stockfish, type: "
|
2009-08-07 20:30:27 -06:00
|
|
|
@echo ""
|
2016-01-17 08:24:18 -07:00
|
|
|
@echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
|
2009-08-07 20:30:27 -06:00
|
|
|
@echo ""
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo "Supported targets:"
|
2010-05-14 10:12:10 -06:00
|
|
|
@echo ""
|
2013-07-14 04:23:28 -06:00
|
|
|
@echo "build > Standard build"
|
|
|
|
@echo "profile-build > PGO build"
|
|
|
|
@echo "strip > Strip executable"
|
|
|
|
@echo "install > Install executable"
|
|
|
|
@echo "clean > Clean up"
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo ""
|
|
|
|
@echo "Supported archs:"
|
|
|
|
@echo ""
|
2019-09-12 13:25:58 -06:00
|
|
|
@echo "x86-64-bmi2 > x86 64-bit with pext support (also enables SSE4)"
|
|
|
|
@echo "x86-64-modern > x86 64-bit with popcnt support (also enables SSE3)"
|
|
|
|
@echo "x86-64 > x86 64-bit generic"
|
2019-09-13 23:33:48 -06:00
|
|
|
@echo "x86-32 > x86 32-bit (also enables SSE)"
|
2013-07-14 04:23:28 -06:00
|
|
|
@echo "x86-32-old > x86 32-bit fall back for old hardware"
|
2014-04-12 17:26:45 -06:00
|
|
|
@echo "ppc-64 > PPC 64-bit"
|
|
|
|
@echo "ppc-32 > PPC 32-bit"
|
|
|
|
@echo "armv7 > ARMv7 32-bit"
|
2020-06-23 02:41:53 -06:00
|
|
|
@echo "armv8 > ARMv8 64-bit"
|
2013-07-14 04:23:28 -06:00
|
|
|
@echo "general-64 > unspecified 64-bit"
|
|
|
|
@echo "general-32 > unspecified 32-bit"
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo ""
|
2013-07-14 04:23:28 -06:00
|
|
|
@echo "Supported compilers:"
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo ""
|
2013-07-14 04:23:28 -06:00
|
|
|
@echo "gcc > Gnu compiler (default)"
|
|
|
|
@echo "mingw > Gnu compiler with MinGW under Windows"
|
|
|
|
@echo "clang > LLVM Clang compiler"
|
|
|
|
@echo "icc > Intel compiler"
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo ""
|
2016-01-17 08:24:18 -07:00
|
|
|
@echo "Simple examples. If you don't know what to do, you likely want to run: "
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo ""
|
2013-07-14 04:23:28 -06:00
|
|
|
@echo "make build ARCH=x86-64 (This is for 64-bit systems)"
|
|
|
|
@echo "make build ARCH=x86-32 (This is for 32-bit systems)"
|
2010-05-14 10:12:10 -06:00
|
|
|
@echo ""
|
2016-01-17 08:24:18 -07:00
|
|
|
@echo "Advanced examples, for experienced users: "
|
|
|
|
@echo ""
|
|
|
|
@echo "make build ARCH=x86-64 COMP=clang"
|
2019-09-13 23:33:48 -06:00
|
|
|
@echo "make profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-4.8"
|
2016-01-17 08:24:18 -07:00
|
|
|
@echo ""
|
|
|
|
|
2009-08-07 20:30:27 -06:00
|
|
|
|
2020-03-01 01:31:17 -07:00
|
|
|
.PHONY: help build profile-build strip install clean objclean profileclean \
|
2016-11-25 08:59:38 -07:00
|
|
|
config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make \
|
|
|
|
clang-profile-use clang-profile-make
|
2016-11-20 01:56:02 -07:00
|
|
|
|
|
|
|
build: config-sanity
|
2010-05-19 11:37:56 -06:00
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
2009-08-07 20:30:27 -06:00
|
|
|
|
2016-11-20 01:56:02 -07:00
|
|
|
profile-build: config-sanity objclean profileclean
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo ""
|
2016-11-20 01:56:02 -07:00
|
|
|
@echo "Step 1/4. Building instrumented executable ..."
|
2010-05-19 11:37:56 -06:00
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
2009-08-07 20:30:27 -06:00
|
|
|
@echo ""
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
2015-11-10 03:30:38 -07:00
|
|
|
$(PGOBENCH) > /dev/null
|
2009-08-07 20:30:27 -06:00
|
|
|
@echo ""
|
2016-11-20 01:56:02 -07:00
|
|
|
@echo "Step 3/4. Building optimized executable ..."
|
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
|
2010-05-19 11:37:56 -06:00
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
|
|
|
@echo ""
|
|
|
|
@echo "Step 4/4. Deleting profile data ..."
|
2016-11-20 01:56:02 -07:00
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
|
2009-11-06 00:59:42 -07:00
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
strip:
|
|
|
|
strip $(EXE)
|
2009-11-06 00:59:42 -07:00
|
|
|
|
2010-05-20 09:24:45 -06:00
|
|
|
install:
|
2010-05-19 11:37:56 -06:00
|
|
|
-mkdir -p -m 755 $(BINDIR)
|
|
|
|
-cp $(EXE) $(BINDIR)
|
|
|
|
-strip $(BINDIR)/$(EXE)
|
2009-08-07 20:30:27 -06:00
|
|
|
|
2016-11-20 01:56:02 -07:00
|
|
|
#clean all
|
|
|
|
clean: objclean profileclean
|
2017-06-04 03:03:23 -06:00
|
|
|
@rm -f .depend *~ core
|
2016-11-20 01:56:02 -07:00
|
|
|
|
|
|
|
# clean binaries and objects
|
|
|
|
objclean:
|
2018-04-26 16:07:56 -06:00
|
|
|
@rm -f $(EXE) *.o ./syzygy/*.o
|
2016-11-20 01:56:02 -07:00
|
|
|
|
|
|
|
# clean auxiliary profiling files
|
|
|
|
profileclean:
|
|
|
|
@rm -rf profdir
|
2020-05-08 05:07:42 -06:00
|
|
|
@rm -f bench.txt *.gcda *.gcno
|
2016-11-25 08:59:38 -07:00
|
|
|
@rm -f stockfish.profdata *.profraw
|
2009-08-07 20:30:27 -06:00
|
|
|
|
2011-05-17 01:09:26 -06:00
|
|
|
default:
|
|
|
|
help
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
### ==========================================================================
|
2020-06-23 09:56:38 -06:00
|
|
|
### Section 5. Private Targets
|
2010-05-19 11:37:56 -06:00
|
|
|
### ==========================================================================
|
2010-05-14 10:12:10 -06:00
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
all: $(EXE) .depend
|
2009-08-21 02:50:34 -06:00
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
config-sanity:
|
|
|
|
@echo ""
|
|
|
|
@echo "Config:"
|
|
|
|
@echo "debug: '$(debug)'"
|
2016-10-31 14:10:31 -06:00
|
|
|
@echo "sanitize: '$(sanitize)'"
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo "optimize: '$(optimize)'"
|
|
|
|
@echo "arch: '$(arch)'"
|
|
|
|
@echo "bits: '$(bits)'"
|
2016-10-08 04:15:43 -06:00
|
|
|
@echo "kernel: '$(KERNEL)'"
|
|
|
|
@echo "os: '$(OS)'"
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo "prefetch: '$(prefetch)'"
|
|
|
|
@echo "popcnt: '$(popcnt)'"
|
2012-10-14 17:13:41 -06:00
|
|
|
@echo "sse: '$(sse)'"
|
2014-04-10 12:07:40 -06:00
|
|
|
@echo "pext: '$(pext)'"
|
2010-05-19 11:37:56 -06:00
|
|
|
@echo ""
|
|
|
|
@echo "Flags:"
|
|
|
|
@echo "CXX: $(CXX)"
|
|
|
|
@echo "CXXFLAGS: $(CXXFLAGS)"
|
|
|
|
@echo "LDFLAGS: $(LDFLAGS)"
|
|
|
|
@echo ""
|
|
|
|
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
|
|
|
@echo ""
|
|
|
|
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
2019-04-27 12:47:06 -06:00
|
|
|
@test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "address" || test "$(sanitize)" = "no"
|
2010-05-19 11:37:56 -06:00
|
|
|
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
|
|
|
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
2020-06-23 02:41:53 -06:00
|
|
|
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || \
|
|
|
|
test "$(arch)" = "armv7" || test "$(arch)" = "armv8-a"
|
2010-05-19 11:37:56 -06:00
|
|
|
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
|
|
|
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
|
|
|
|
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
|
2012-10-14 17:13:41 -06:00
|
|
|
@test "$(sse)" = "yes" || test "$(sse)" = "no"
|
2014-04-10 12:07:40 -06:00
|
|
|
@test "$(pext)" = "yes" || test "$(pext)" = "no"
|
2012-04-29 03:14:50 -06:00
|
|
|
@test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
|
2009-08-21 02:50:34 -06:00
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
$(EXE): $(OBJS)
|
|
|
|
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
|
|
|
|
2016-11-25 08:59:38 -07:00
|
|
|
clang-profile-make:
|
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
|
|
|
EXTRACXXFLAGS='-fprofile-instr-generate ' \
|
|
|
|
EXTRALDFLAGS=' -fprofile-instr-generate' \
|
|
|
|
all
|
|
|
|
|
|
|
|
clang-profile-use:
|
|
|
|
llvm-profdata merge -output=stockfish.profdata *.profraw
|
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
|
|
|
EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
|
|
|
|
EXTRALDFLAGS='-fprofile-use ' \
|
|
|
|
all
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
gcc-profile-make:
|
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
2016-11-27 06:43:52 -07:00
|
|
|
EXTRACXXFLAGS='-fprofile-generate' \
|
2010-05-19 11:37:56 -06:00
|
|
|
EXTRALDFLAGS='-lgcov' \
|
2009-08-21 02:50:34 -06:00
|
|
|
all
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
gcc-profile-use:
|
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
2017-07-13 17:36:27 -06:00
|
|
|
EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \
|
2011-11-08 21:03:46 -07:00
|
|
|
EXTRALDFLAGS='-lgcov' \
|
2009-08-21 02:50:34 -06:00
|
|
|
all
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
icc-profile-make:
|
2016-11-20 01:56:02 -07:00
|
|
|
@mkdir -p profdir
|
2010-05-19 11:37:56 -06:00
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
|
|
|
EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
|
2009-08-21 02:50:34 -06:00
|
|
|
all
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
icc-profile-use:
|
|
|
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
|
|
|
EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
|
2009-08-21 02:50:34 -06:00
|
|
|
all
|
|
|
|
|
2010-05-19 11:37:56 -06:00
|
|
|
.depend:
|
2020-05-08 05:07:42 -06:00
|
|
|
-@$(CXX) $(DEPENDFLAGS) -MM $(SRCS) > $@ 2> /dev/null
|
2010-05-19 11:37:56 -06:00
|
|
|
|
|
|
|
-include .depend
|