Kjetil's Information Center: A Blog About My Projects

Renesas GCC Toolchains Update

I recently installed Slackware 15.0 on a computer and I noticed that my older script no longer works well. Here is an updated script that compiles GCC version 12 and it's associated tools. The steps are also simplified, mainly because "--enable-maintainer-mode" has been removed when configuring "binutils".

I have tested with the two Renesas target architectures that I use; RX and RL78 so one of these can be selected as the argument for the script. By default the toolchains are installed at /opt/ but this can be changed with the PREFIX variable in the script. Also note that "make" as been set up to run 32 parallel jobs which greatly improves the compilation time if you have enough cores, so adjust this as needed.

Here is the updated script:

#!/bin/bash
set -e

if [ -z "$1" ]; then
  echo "Choose a target:"
  echo "1) rx-elf"
  echo "2) rl78-elf"
  exit 0
elif [ "$1" -eq 1 ]; then
  TARGET="rx-elf"
elif [ "$1" -eq 2 ]; then
  TARGET="rl78-elf"
else
  echo "Unknown target!"
  exit 1
fi

PREFIX="/opt/gcc-${TARGET}/"
BUILD_DIR="build-${TARGET}/"

export PATH="${PREFIX}bin:$PATH"

# 1) Prepare build directories:
if [ -d "${BUILD_DIR}" ]; then
  echo "Old build directory detected, please remove it."
  exit 1
else
  mkdir -p "${BUILD_DIR}/binutils"
  mkdir -p "${BUILD_DIR}/gcc"
  mkdir -p "${BUILD_DIR}/gdb"
  mkdir -p "${BUILD_DIR}/newlib"
fi

# 2) Get sources:
if [ ! -d source ]; then
  mkdir source
  cd source
  wget "https://gnuftp.uib.no/gcc/gcc-12.1.0/gcc-12.1.0.tar.xz"
  wget "https://gnuftp.uib.no/gdb/gdb-12.1.tar.xz"
  wget "https://gnuftp.uib.no/binutils/binutils-2.38.tar.xz"
  wget "ftp://sourceware.org/pub/newlib/newlib-4.1.0.tar.gz"
  tar -xvJf gcc-12.1.0.tar.xz
  tar -xvJf gdb-12.1.tar.xz
  tar -xvJf binutils-2.38.tar.xz
  tar -xvzf newlib-4.1.0.tar.gz
  cd ..
fi

# 3) Build binutils:
cd "${BUILD_DIR}"
cd binutils
../../source/binutils-2.38/configure --target=$TARGET --prefix=$PREFIX --disable-nls --disable-werror
make -j32
sudo make install
cd ..

# 4) Build gcc (step 1):
cd gcc
../../source/gcc-12.1.0/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++ --disable-shared --with-newlib --enable-lto --disable-libstdcxx-pch --disable-nls --disable-werror
make -j32 all-gcc
sudo make install-gcc
cd ..

# 5) Build newlib:
cd newlib
../../source/newlib-4.1.0/configure --target=$TARGET --prefix=$PREFIX --disable-nls
make -j32
sudo make install
cd ..

# 6) Build gdb:
cd gdb
../../source/gdb-12.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls
make -j32
sudo make install
cd ..

# 7) Build gcc (step 2):
cd gcc
make -j32
sudo make install
          


Topic: Configuration, by Kjetil @ 15/07-2022, Article Link