2020-12-30 23:03:15 +01:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
source util.sh
|
2020-12-30 23:03:15 +01:00
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
VERSION=$1
|
2021-01-08 10:00:34 +01:00
|
|
|
PREFIX="$2"
|
2021-01-02 00:13:11 +01:00
|
|
|
URL="https://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.xz"
|
|
|
|
ARCHIVE=$(basename "$URL")
|
2020-12-30 23:03:15 +01:00
|
|
|
|
2021-01-08 10:00:34 +01:00
|
|
|
# Avoid rebuilds of the same version
|
|
|
|
|
|
|
|
existing_gcc="$PREFIX/bin/sh-elf-gcc"
|
|
|
|
|
|
|
|
if [[ -f "$existing_gcc" ]]; then
|
|
|
|
existing_version=$(sh-elf-gcc --version | head -n 1 | grep -Eo '[0-9.]+$')
|
|
|
|
if [[ $existing_version == $VERSION ]]; then
|
|
|
|
echo "$TAG Version $VERSION already installed, skipping rebuild"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
# Download archive
|
2020-12-30 23:03:15 +01:00
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
if [[ -f "$ARCHIVE" ]]; then
|
|
|
|
echo "$TAG Found $ARCHIVE, skipping download"
|
2020-12-30 23:03:15 +01:00
|
|
|
else
|
2021-01-02 00:13:11 +01:00
|
|
|
echo "$TAG Downloading $URL..."
|
|
|
|
if command -v curl >/dev/null 2>&1; then
|
|
|
|
curl $URL -o $ARCHIVE
|
|
|
|
elif command -v wget >/dev/null 2>&1; then
|
|
|
|
wget -q --show-progress $URL -O $ARCHIVE
|
2020-12-30 23:03:15 +01:00
|
|
|
else
|
2021-01-02 00:13:11 +01:00
|
|
|
echo "$TAG error: no curl or wget; install one or download archive yourself" >&2
|
|
|
|
exit 1
|
2020-12-30 23:03:15 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Extract archive
|
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
echo "$TAG Extracting $ARCHIVE..."
|
|
|
|
tar -xJf $ARCHIVE
|
|
|
|
|
|
|
|
# Create build folder
|
2020-12-30 23:03:15 +01:00
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
[[ -d "build" ]] && rm -rf build
|
|
|
|
mkdir build
|
2020-12-30 23:03:15 +01:00
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
# Configure. GCC does not support make uninstall so we install in this
|
|
|
|
# directory and later symlink executables to $PREFIX/bin.
|
2020-12-30 23:03:15 +01:00
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
PREFIX="$(pwd)"
|
2021-01-02 22:48:31 +01:00
|
|
|
|
|
|
|
# Symlink as, ld, ar and ranlib, which gcc will not find by itself (we renamed
|
|
|
|
# them from sh3eb-elf-* to sh-elf-* with --program-prefix).
|
|
|
|
mkdir -p sh3eb-elf/bin
|
2021-01-04 14:11:25 +01:00
|
|
|
ln -sf $(command -v sh-elf-as) sh3eb-elf/bin/as
|
|
|
|
ln -sf $(command -v sh-elf-ld) sh3eb-elf/bin/ld
|
|
|
|
ln -sf $(command -v sh-elf-ar) sh3eb-elf/bin/ar
|
|
|
|
ln -sf $(command -v sh-elf-ranlib) sh3eb-elf/bin/ranlib
|
2021-01-02 22:48:31 +01:00
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
cd build
|
2020-12-30 23:03:15 +01:00
|
|
|
|
2021-01-02 00:13:11 +01:00
|
|
|
echo "$TAG Configuring gcc..."
|
|
|
|
run_quietly giteapc-configure.log \
|
|
|
|
../gcc-$VERSION/configure --prefix="$PREFIX" --target=sh3eb-elf --with-multilib-list=m3,m4-nofpu --enable-languages=c,c++ --without-headers --with-newlib --program-prefix=sh-elf- --enable-libssp --enable-lto
|