-
Notifications
You must be signed in to change notification settings - Fork 9
Build a cross compiler for FOOS
This page will show you how to build a cross-compiler for FOOS. A cross compiler
is a tool that helps compile program into other binary formats (e.g.
build arm
code on x86
machine and vice versa). This tutorial is going to
build you a cross compiler that builds i386-elf
code on your machine. To do
this, you need to have gcc
and binutils
installed.
To help you understand what these code mean, I declare a few variables in the first place:
export TARGET=i386-elf
export PREFIX=/usr/local
TARGET
is the binary format the cross compiler will build, PREFIX
is where
the compiler will be installed
Binutils is a tool that helps create and manipulate binary files (binary
utilities). A program's compilation done by gcc
expects binutils
to link
executables.
To build binutils, we download and unpack its tarball from here, for example:
$ wget https://ftpmirror.gnu.org/gnu/binutils/binutils-2.30.tar.gz
$ tar xvf binutils-2.30.tar.gz
For future use, I create a new directory called build-binutils
to keep the
source from being dirty
$ mkdir build-binutils && cd build-binutils
$ ../binutils-2.30/configure --prefix=$PREFIX --target=$TARGET \
> --disable-nls --disable-werror --with-sysroot
$ make
# make install
disable-nls: Disable native language support so the compiler only outputs English, and it really reduces the time to build
disable-werror: werror
basically turns warnings into errors, sometimes
you OS's compilation contains some "friendly" warnings.
Now you have successfully built binutils
, so let's look at gcc. Somehow,
any versions later or before 5.2.0
won't be built successfully, so I
choose gcc-5.2.0.tar.gz
to download.
tar xvf gcc-5.2.0.tar.gz
$ mkdir build-gcc && cd build-gcc
$ ../gcc-5.2.0/configure --prefix=$PREFIX --target=$TARGET \
> --enable-languages=c --disable-nls --disable-multilib --without-headers
$ make all-gcc
$ make all-target-libgcc
# make install-gcc
# make install-target-libgcc
If everything works fine, you should be building FOOS successfully like this:
$ git clone git@github.com:TravorLZH/foos.git
$ cd foos
$ make
This page is part of the FOOS distribution. It can be freely copied and distributed but without WARRANTY