So, I would like to make an OS. This time, let's get to the point of getting a GCC cross-compiler.
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
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 ..
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
$ 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.
I had a hard time because there was little information. Especially the last gcc make was tough.
** Build binutils from source. ** **
Recommended Posts