View on GitHub

PR-OS

A x86 Operating System based on existing kernel analysis

Cross Compiler GCC

For this project we are going to build our own GCC Cross Compiler

Tools required for the build OS dev

replace dnf with apt for debian/ ubuntu and pacman -S for arch

  1. GCC - core compiler
    sudo dnf install gcc
    
  2. G++ - required for new gcc versions
    sudo dnf install g++
    
  3. MAKE - automate the build system
    sudo dnf install make
    
  4. BISON - parser
    sudo dnf install bison
    
  5. FLEX - lexical analyzer generator
    sudo dnf install flex
    
  6. GMP (math library) - handles large arithmetic
    sudo dnf install gmp-devel
    
  7. MPFR(floating point math) - precise floating-point calculations
    sudo dnf install mpfr-devel
    
  8. MPC(complex math) - complex number arithmetic
    sudo dnf install libmpc-devel
    
  9. TEXINFO - generate GCC documentation
    sudo dnf install texinfo
    
  10. ISL (OPTIONAL) - advanced loop optimizations and code analysis
    sudo dnf install isl-devel
    

Steps

  1. install the above tools
  2. install the gcc and binutils source code from binutils and GCC
  3. commands
# defining the path and the target

#defining the path where everything will be installed
export PREFIX="$HOME/opt/cross"

# the target architecture i686 is for 32 bit mode and the file output -elf is for flat binary output file
export TARGET=i686-elf

# adding the compiler to the path
export PATH="$PREFIX/bin:$PATH"

# make sure that the folder names are the below mentioned
# src is the source folder where the extracted source code is saved
cd $HOME/src

# compiling binutils replace x.y.z with the downloaded version
mkdir build-binutils
cd build-binutils

# target is defining the architecture to target
# prefix install location
# with sysroot enables a virtual root file system
# disable nls disables native language support
# disable werror suppresses warnigs being treated as errors
../binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make
make install

cd $HOME/src

# compiling gcc replace x.y.z with the downloaded version
mkdir build-gcc
cd build-gcc

# target is defining the architecture to target
# prefix install location
# with sysroot enables a virtual root file system
# disable nls disables native language support
# enable languages is defining the support for the supported languages
# without headers is dont expect any existing standard libraries
# disable werror suppresses warnings being treated as errors
# disable hosted libstdcxx disables hosted c++ standard library features
../gcc-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers --disable-hosted-libstdcxx
make all-gcc
make all-target-libgcc
make all-target-libstdc++-v3
make install-gcc
make install-target-libgcc
make install-target-libstdc++-v3

## to verify the cross compiler build
$HOME/opt/cross/bin/i686-elf-gcc --version

## to make the cross compile shareable 
tar -czf i686-elf-gcc.tar.gz -C $HOME/opt cross