Prerequesites

Here I show how to compile GCC, GDB and clang in debian, I compiled the source code from the latest in master. Before doing the steps below I cloned the git repos for all of them.

git clone git://gcc.gnu.org/git/gcc.git
git clone git://sourceware.org/git/binutils-gdb.git
git clone https://github.com/llvm/llvm-project.git

The OS is Debian Buster and Debian Stretch, there are less steps in Buster since it is newer than Stretch.

GDB

For debugging my programs, I use gdb, the gnu debugger. In general, gdb is available precompiled in the package repositories but sometimes I want to use the latest or enable more features.

Here is how to compile gdb with syntax highlighting in TUI mode in Debian Buster (it requires flex 2.6.4, so it doesn't work in debian stretch unless you install flex 2.6.4 manually)

sudo apt-get install texinfo bison flex libgmp-dev libsource-highlight-dev
./configure
make -j4
sudo make install

GCC

# in debian stretch
# zstd has to be install manually
git clone https://github.com/facebook/zstd
cd zstd
make
sudo make install
sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libisl-dev

# in debian buster
sudo apt-get install libzstd-dev libgmp-dev libmpfr-dev libmpc-dev libisl-dev

./configure --disable-multilib --enable-languages=c,lto
make -j4
sudo make install

Clang

cd llvm-project
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld" -G "Unix Makefiles" ../llvm
make -j4
sudo make install

gcc can use lld for linking with the option -fuse-ld=lld. In my tests, lld is 5% faster than gold.