[LINUX] Start of self-made OS 1. Environment construction

Yes, let's make an OS!

So, I would like to make an OS. This time, let's get to the point of getting a GCC cross-compiler.

What to prepare

1. Dependency installation

First, install the dependencies.

What you need is:

You can use curl as you like, such as wget.

$ sudo apt update
$ sudo apt -y install curl build-essential m4 libgmp3-dev libmpc-dev libmpfr-dev qemu qemu-kvm

2. Build gmp, mpfr, mpc, binutils

First, make gmp. It is set to --prefix = / usr / local / cc, but you can use it as you like. However, I think it is better to make the value specified by this --prefix common to gmp, mpfr, mpc, and binutils.

First from gmp.

gmp


$ curl --output gmp-6.2.0.tar.bz2 https://ftp.gnu.org/gnu/gmp/gmp-6.2.0.tar.bz2
$ tar -xvf gmp-6.2.0.tar.bz2
$ cd gmp-6.2.0
$ ./configure --prefix=/usr/local/cc
$ make check && sudo make install
$ cd ..

Next, make in the order of mpfr, mpc, binutils.

mpfr


$ curl --output mpfr-4.1.0.tar.bz2 https://ftp.gnu.org/gnu/mpfr/mpfr-4.1.0.tar.bz2
$ tar -xvf mpfr-4.1.0.tar.bz2
$ cd mpfr-4.1.0
$ ./configure --prefix=/usr/local/cc
$ make check && sudo make install
$ cd ..

mpc


$ curl --output mpc-1.2.0.tar.gz https://ftp.gnu.org/gnu/mpc/mpc-1.2.0.tar.gz
$ tar -xvf mpc-1.2.0.tar.gz
$ cd mpc-1.2.0
$ ./configure --prefix=/usr/local/cc
$ make check && sudo make install
$ cd ..

binutils


$ curl --output binutils-2.35.tar.xz https://ftp.gnu.org/gnu/binutils/binutils-2.35.tar.xz
$ tar -xvf binutils-2.35.tar.xz
$ cd binutils-2.35
$ ./configure --target=x86_64-elf --prefix=/usr/local/cc --disable-nls
$ make
$ make install
$ cd ..

3. Build gcc

Well, finally GCC make. Here are some caveats. The first is that you should go into the gcc source code directory and do not ** ./configure **. If you do that, you can do it with make all-target-libgcc. The second is the configure argument --with-xxx. For this, specify the directory specified by --prefix of gmp, mpfr, mpc in the previous step. The third is the --with-as argument. This, unlike others, requires you to specify the ** execution binary path ** directly.

gcc make


$ curl --output gcc-10.2.0.tar.xz https://ftp.gnu.org/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.xz
$ tar -xvf gcc-10.2.0.tar.xz
$ mkdir gcc-make-tmp
$ cd gcc-make-tmp
$ ../gcc-10.2.0/configure\
    --target=x86_64-elf\
    --prefix=/usr/local/cc\
    --disable-nls\
    --enable-languages=c\
    --without-headers\
    --with-gmp=/usr/local/cc\
    --with-mpfr=/usr/local/cc\
    --with-mpc=/usr/local/cc\
    --with-as=/usr/local/cc/bin/x86_64-elf-as #Specify the binary path of the as command
    #You may get sick without this(stdio.h: no such file or directory.)
    #Add if you can
    # --with-headers=/usr/include\
    # --with-headers=/usr/include/x86_64-linux-gnu
$ #It takes a long time, so let's take a tea break while executing this command.
$ make all-gcc && make install-gcc
$ make all-target-libgcc && make install-target-libgcc

4. Test

$ export PATH=/usr/local/cc/bin:$PATH
$ x86_64-elf-gcc -v
Using built-in specs.
COLLECT_GCC=x86_64-elf-gcc
COLLECT_LTO_WRAPPER=/mnt/d/usr/local/cc/libexec/gcc/x86_64-elf/10.2.0/lto-wrapper
Target: x86_64-elf
Configured with: (abridgement)
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)

If such an output is made, it is successful. Thank you for your hard work.

5. Impressions

I had a hard time because there was little information. Especially the last gcc make was tough.

** Build binutils from source. ** **

Recommended Posts

Start of self-made OS 1. Environment construction
[Memo] Construction of cygwin environment
Environment construction of python2 & 3 (OSX)
[Django] Memorandum of environment construction procedure
Environment construction memo of pyenv + conda
Environment construction of python3.8 on mac
Environment construction of "Tello_Video" on Ubuntu
Mac OS X Mavericks 10.9.5 Development environment construction
GeoDjango + SQLite environment construction on OS X
Mac OS X Yosemite 10.10 Development environment construction
Mac OS X development environment construction memo
Construction of development environment for Choreonoid class
DeepIE3D environment construction
Emacs-based environment construction
Linux environment construction
Python environment construction
Environment construction (python)
django environment construction
CodeIgniter environment construction
python environment construction
Python --Environment construction
Python environment construction
Golang environment construction
python environment construction
Word2vec environment construction
Installation of Python3 and Flask [Environment construction summary]
Poetry-virtualenv environment construction with python of centos-sclo-rh ~ Notes
Mac OS X Mountain Lion 10.8.5 Development environment construction
Environment construction: GCP + Docker
Django project environment construction
Unification of Python environment
python windows environment construction
Go language environment construction
ConoHa environment construction memo
homebrew python environment construction
PyData related environment construction
Anaconda-4.2.0-python3 environment construction (Mac)
Python development environment construction
YOLO v4 environment construction ①
pyenv + fish environment construction
python2.7 development environment construction
BigGorilla environment construction memo
Memorandum of understanding for environment construction of AutoML library PyCaret
grip environment construction onCentOS6.5
Anaconda environment construction memo
Golang environment construction [goenv]
Mac environment construction Python
Pyxel environment construction (Mac)
Python environment construction @ Win7
Construction of Python local development environment Part 2 (pyenv-virtualenv, pip usage)
Automatic scraping of reCAPTCHA site every day (1/7: python environment construction)
Memo of python + numpy/scipy/pandas/matplotlib/jupyterlab environment construction on M1 macOS (as of 2020/12/24)
Memo of Linux environment construction using VirtualBox + Vagrant on Windows 10
Construction of Cortex-M development environment for TOPPERS using Raspberry Pi
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Python + Anaconda + Pycharm environment construction
About Linux environment construction (CentOS)
Python --Quick start of logging
PyTorch C ++ (LibTorch) environment construction
Anaconda environment construction on CentOS7
Django development environment construction memo