Compiling Stockfish with gcc on Termux

Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Offline (Active 5 Hours, 15 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Compiling Stockfish with gcc on Termux

Post by Archimedes »

Here is a short description, how you can compile Stockfish for arm64-v8a based CPUs with gcc on Termux.

At first, forget the installation of gcc via the repository https://github.com/its-pointless/its-pointless.github.io. It works for Demolito, which is a C based chess engine, but not for Stockfish (and probably other C++ based chess engines).

If you have already installed gcc via the above repository, remove it with:

Code: Select all

apt-get remove gcc-11
apt-get autoremove
Use CCTools for that purpose. A detailed description, how you install the cctool packages under Termux can be found here:
https://cctools.info/index.php/Termux_repository_with_cctools_packages_(gcc_with_fortran_support_etc)

Follow the explanations step by step.

After that, download the Stockfish sources.

Code: Select all

git clone https://github.com/official-stockfish/Stockfish
cd Stockfish/src
Make changes to the makefile, as the following code pieces are shown:

Before:

Code: Select all

ifeq ($(COMP),gcc)
	comp=gcc
	CXX=g++
	CXXFLAGS += -pedantic -Wextra -Wshadow

	ifeq ($(arch),$(filter $(arch),armv7 armv8))
		ifeq ($(OS),Android)
			CXXFLAGS += -m$(bits)
			LDFLAGS += -m$(bits)
After:

Code: Select all

ifeq ($(COMP),gcc)
	comp=gcc
	CXX=g++
	CXXFLAGS += -pedantic -Wextra -Wshadow

	ifeq ($(arch),$(filter $(arch),armv7 armv8))
		ifeq ($(OS),Android)
			CXXFLAGS += 
			LDFLAGS += 
Before:

Code: Select all

### Sometimes gcc is really clang
ifeq ($(COMP),gcc)
After:

Code: Select all

### Sometimes gcc is really clang
ifeq ($(COMP),)
Before:

Code: Select all

### 3.3 Optimization
ifeq ($(optimize),yes)

	CXXFLAGS += -O3

	ifeq ($(comp),gcc)
		ifeq ($(OS), Android)
			CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
After:

Code: Select all

### 3.3 Optimization
ifeq ($(optimize),yes)

	CXXFLAGS += -O3

	ifeq ($(comp),gcc)
		ifeq ($(OS), Android)
			CXXFLAGS += -march=native
Now you can compile Stockfish with gcc and PGO optimization with the following command:

Code: Select all

make -j profile-build ARCH=armv8 COMP=gcc

Return to “Programming, Technical Discussions, Chess related questions etc.”