2.1 KiB
2.1 KiB
Building the tools needed to build the kernel
Install dependencies
Ubuntu/Debian
sudo apt install build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo libisl-dev gcc-multilib
Fedora
sudo dnf install gcc gcc-c++ make bison flex gmp-devel libmpc-devel mpfr-devel texinfo isl-devel
Others
For others please check OSDev Wiki Installing Dependencies section
Compile
This is compiling
GCCversion14.xandbinutilsversion2.43.x, make sure your OS gcc and binutils are the same major version!
Setting up the environment
First, create the prefix folder, from your project folder execute
mkdir $(pwd)/toolchain/
export PREFIX="$(pwd)/toolchain/"
export PATH="$PREFIX/bin:$PATH"
Set the target to be a i686
export TARGET=i686-elf
Building binutils
From your project folder execute:
mkdir -p tools/build/build-binutils
cd tools/build/build-binutils
../../binutils/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make -j$(($(nproc)-2))
make install
To check what each flag does consult OSDev Wiki
Build GCC
First, check if binutils is reachable from within $PATH
which i686-elf-ld | grep $PREFIX -q && echo "Found i686-elf-ld" || echo "NOT found i686-elf-ld"
If you see Found i686-elf-ld you are good to got, if not you have made some mistake on the steps above.
Now, compile GCC and libgcc. From your project folder execute:
mkdir -p tools/build/build-gcc
cd build-gcc
../../gcc/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc -j$(($(nproc)-2))
make all-target-libgcc -j$(($(nproc)-2))
make install-gcc
make install-target-libgcc
Finals
Once everything is compile you should have some binaries inside $PREFIX/bin, mainly i686-elf-gcc, i686-elf-ld, i686-elf-gdb, i686-elf-as and i686-elf-g++.
ls $PREFIX/bin