본문 바로가기

카테고리 없음

GCC 크로스 컴파일러 만들기 (x86_64-elf, i686-elf target)

1. Prerequisites

   * flex, bison, texinfo.

   * pre-installed build essential packages.

     - gcc, g++, make, gawk, gperf, find, ...

 

2. Source tarballs

   * Binutils 2.35 - https://ftp.gnu.org/gnu/binutils/binutils-2.35.tar.xz

   * GMP 6.2.0 - https://ftp.gnu.org/gnu/gmp/gmp-6.2.0.tar.xz

   * MPFR 4.1.0 - https://ftp.gnu.org/gnu/mpfr/mpfr-4.1.0.tar.xz

   * MPC 1.2.0 - https://ftp.gnu.org/gnu/mpc/mpc-1.2.0.tar.gz

   * GCC 10.2.0 - https://ftp.gnu.org/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.gz

 

3. Automation script.

#!/bin/bash

sudo mkdir -pv /opt/cross
sudo chown `whoami`:`whoami` -R /opt/cross

wget https://ftp.gnu.org/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.gz
wget https://ftp.gnu.org/gnu/binutils/binutils-2.35.tar.xz

export PREV_CWD=`pwd`

tar xf binutils-2.35.tar.xz
cd binutils-2.35
mkdir -pv build

cd build
export PATH="/opt/cross/bin:$PATH"

../configure --target=$(uname -m)-elf --prefix=/opt/cross --disable-nls --disable-werror --with-sysroot

make -j 16 && make install

cd $PREV_CWD
tar xf gcc-10.2.0.tar.gz

cd gcc-10.2.0
wget https://ftp.gnu.org/gnu/gmp/gmp-6.2.0.tar.xz
wget https://ftp.gnu.org/gnu/mpfr/mpfr-4.1.0.tar.xz
wget https://ftp.gnu.org/gnu/mpc/mpc-1.2.0.tar.gz

tar xf gmp-6.2.0.tar.xz
tar xf mpfr-4.1.0.tar.xz
tar xf mpc-1.2.0.tar.gz

mv gmp-6.2.0 gmp
mv mpfr-4.1.0 mpfr
mv mpc-1.2.0 mpc

mkdir -pv build
cd build

../configure --target=$(uname -m)-elf --prefix=/opt/cross --disable-nls --enable-languages=c,c++ --without-headers

make all-gcc -j 16 && make install-gcc && \
make all-target-libgcc -j 16 && make install-target-libgcc

 

4. Beginners mistakes

  * NOTE that, export PATH="/opt/cross/bin:$PATH" should be done before configuring GCC package if compile them under target machine itself.

 

5. Easy way

  use crossng utility to build for ARM, MIPS, etc...