Table of Contents
This page explains how to build the cross compiler for building and running Thor.
Before building the compiler, you need to install the GMP, MPFR and MPC support libraries. For Debian-based systems, including Ubuntu, you should install the packages libgmp-dev, libmpfr-dev and libmpc-dev. For RPM-based systems, including Fedora and SUSE, you should install gmp-devel, mpfr-devel and libmpc-devel (or mpc-devel on SUSE) packages.
Prerequisites
sudo apt-get install libmpc-dev g++ nasm gcc-multilib
also make sure that gcc is pointing to the cross compiled version after this.
Download
Download binutils and GCC
mkdir $HOME/src/
cd $HOME/src/
wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.33.1.tar.gz
wget ftp://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz
tar xvzf binutils*
tar xvzf gcc*
Configuration
export CC=gcc
export CXX=g++
export LD=ld.bfd
export PREFIX="$HOME/opt/cross"
export TARGET=x86_64-elf
export PATH="$PREFIX/bin:$PATH"
Build binutils
cd $HOME/src
mkdir build-binutils
cd build-binutils
../binutils-*/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --disable-werror
make -j9
make install
Build GCC
cd $HOME/src
mkdir build-gcc
cd build-gcc
../gcc-*/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++
make -j9 all-gcc
make -j9 all-target-libgcc CFLAGS_FOR_TARGET="-mcmodel=large"
make install-gcc
make install-target-libgcc
Normally, you should now have a working x86_64-elf cross compiler.
On Gentoo
On Gentoo, it should be easier to create a cross-compilation chain and especially easier to have multiple cross compilation chains.
sudo emerge crossdev
sudo mkdir -p /usr/local/portage-crossdev/profiles/
echo local-crossdev /usr/local/portage-crossdev/profiles/repo_name
PORTDIR_OVERLAY="/usr/local/portage-crossdev" crossdev -S --target x86_64-elf
Unfortunately, I've never got this to work :(