How to compile chess engines and programs for Linux ?
Updated: Jan 20
This article was inspired by MartinPL1977. Thank you :)
Your Linux and favorite distribution. You have perfected it down to the smallest detail. It looks beautiful, it is functional, the programs do their job. The whole system for you works better than any Windows or macOS machine.
You are proud of it and would like to be able to use modern engines and useful chess software. But... not everything you are interested in is ready to work immediately. It has to be compiled.

Is it difficult ?
Does it require specialized knowledge ?
How to do that ?
I will try to answer the questions posed above.
This article is for those who understand how Linux works and know what commands typed at the Linux command line do.
First I have some good informations for you. Compiling engines and programs in most cases is not difficult and comes down to typing just a few commands in the command line.
Typically, properly and independently compiled chess engines run slightly faster on the same computer on Linux than the same engines on a Windows computer.
Why is this the case ?
The easiest way to understand this is to use the example of buying a suit. When you buy - even in the best store - a suit, you choose a particular size. The suit fits and it's fine.

On the other hand, when you go to a tailor, who will tailor the suit to your exact measurements, you will not only get a suit that fits, but one that is exactly tailored to your measurements. And this tailor-made suit will fit you perfectly.

Without going into technical details - it is similar with compilation of chess software, which due to its specialized nature - works best on the machine on which it was compiled. It is not a coincidence that at important competitions where chess engines have participated and are participating, they are run on Linux - in the environment where they were previously compiled.
How much difference in speed can there be between an engine compiled for a particular machine versus the same engine not optimized for that machine ?
The difference can range from a fraction of a percent to several percent.
Is it much or is it little ? It depends.
During usual chess engine activities, such as chess game analysis or training applications - it does not matter much.
But if the engine participates in competitions or it is important to get as much power as possible or you use it to analyze difficult positions in correspondence games or looking for an effective novelty in a chess opening - then the speed higher by "just" a fraction of a percent will be important, it may increase the chance of a draw or even victory in an important chess game.

You don't need specialized knowledge to compile a chess engine or program properly. You don't even need to know how to program. However, it is worth reading with concentration and understanding, because usually in the sources of the program there is a file describing the steps of compilation of the given engine or chess program.
Ok. So without further ado, what are we going to compile ?
First, we'll take a compilation of two free modern and powerful chess engines, Berserk and Stockfish. Then we will take a compilation of the best free chess database program Scid vs PC.
What do you need to compile ?
1. Linux Distribution.
It doesn't really matter what distribution it is. It will compile the same way on Arch, Debian, Fedora, Gentoo, Ubuntu or any other distribution. It doesn't really matter if the Linux distribution you are using uses an AMD, ARM or other processor.
2. Compiler.
We will compile software written in C / C++ so we need a compiler called GCC (GNU Compiler Collection).
3. Source code.
It takes source code in file/s form for the GCC compiler to be able to create a working engine / program.
4. Anything else ?
In some cases, depending on, for example, the installed version of the GCC compiler and the Linux distribution libraries, you may need to install components specified by the compiler.
5. Time. How long does it take to compile ?
On a modern computer, it usually takes tens of seconds to compile.
Even on older computers, e.g. 10-15 years old, compiling a chess engine will take from tens of seconds to several minutes. The compilation of a program like Scid vs. PC may take a little longer because of its larger size.
Will the compilation be described in detail ?
All compilations will be explained and presented in such a way that the Reader, by following all compilation steps - will be able to compile the software described below by himself.
Due to the nature of the compilation process and the required knowledge of the Reader, the compilation descriptions will not address detailed issues of how Linux works and the effects of executing command line commands.
Workshops for compilation.
I am using Debian GNU/Linux 10 (buster).
This distribution is supported until 2024 (LTS - Long Term Support); it is a very stable and high quality distribution with frequent updates.
Debian runs on my computer with ARM64 processors.

The compilation will be performed by GCC version 8.3.0.

If you do not have the GCC compiler installed, I would refer you to the help system of the Linux distribution you are using. There you will get information how to install GCC.
In Debian, the following steps are required to install GCC:
1. Update the packages list:
sudo apt update
2. Install the build-essential package by running:
sudo apt install build-essential
3. You can skip this step.
You would like also to install the manual pages that includes documentation about using GNU/Linux for (among others) compiling.
sudo apt-get install manpages-dev
4. To confirm that the GCC compiler is successfully installed type:
gcc --version
A compilation of the Berserk chess engine.
Berserk is licensed under the GPL v3.0.
We will be compiling the latest publicly available version of this engine.
The Berserk source code is available on GitHub at: https://github.com/jhonnold/berserk
To compile Berserk we will use the information on this engine's page.
1.
In the first step, we will select the directory where the source code will reside.
Type:
cd

Of course, you must press the Enter key after typing each command.
2.
In this, step we will download the source code.
Type the command:
git clone https://github.com/jhonnold/berserk

If the download does not start, it is likely that git is not installed on your system - then install git and repeat step #2.
How to install git
sudo apt install git
On my internet connection, the download took about 30 seconds.
3.
Type:
cd berserk/src

4.
Type the command:
make basic

Now the compilation will take place.
If any errors occur during compilation, the engine will not compile and the GCC compiler will show messages on the screen.
Unfortunately, the compilation failed.
Why? Look carefully at the messages the compiler gave you.

GCC suggests that the stdlib.h library should be added to the nn.c file.
Open the nn.c file in any text file editor - I used the system Text Editor.