mirror of
https://git.planet-casio.com/Lephenixnoir/sh-elf-gcc.git
synced 2024-12-28 04:23:39 +01:00
87 lines
2.3 KiB
Bash
Executable file
87 lines
2.3 KiB
Bash
Executable file
#! /usr/bin/env bash
|
|
|
|
source util.sh
|
|
|
|
VERSION=$1
|
|
PREFIX="$2"
|
|
URL="https://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.xz"
|
|
ARCHIVE=$(basename "$URL")
|
|
|
|
# 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"
|
|
if [[ -e build ]]; then
|
|
rm -rf build
|
|
fi
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
# Aggressive parameter to avoid rebuilds
|
|
|
|
if [[ ! -z "$ACCEPT_ANY" ]]; then
|
|
if command -v sh-elf-gcc >/dev/null 2>&1; then
|
|
echo "$TAG sh-elf-gcc in PATH and ACCEPT_ANY is set, skipping build"
|
|
if [[ -e build ]]; then
|
|
rm -rf build
|
|
fi
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
# Download archive
|
|
|
|
if [[ -f "$ARCHIVE" ]]; then
|
|
echo "$TAG Found $ARCHIVE, skipping download"
|
|
else
|
|
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
|
|
else
|
|
echo "$TAG error: no curl or wget; install one or download archive yourself" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Extract archive (openBSD-compliant version)
|
|
|
|
echo "$TAG Extracting $ARCHIVE..."
|
|
unxz -c < $ARCHIVE | tar -xf -
|
|
|
|
# Create build folder
|
|
|
|
[[ -d "build" ]] && rm -rf build
|
|
mkdir build
|
|
|
|
# Configure. GCC does not support make uninstall so we install in this
|
|
# directory and later symlink executables to $PREFIX/bin.
|
|
|
|
PREFIX="$(pwd)"
|
|
|
|
# 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
|
|
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
|
|
|
|
cd build
|
|
|
|
# OpenBSD apparently installs these in /usr/local
|
|
if [[ $(uname) == "OpenBSD" ]]; then
|
|
extra_args="--with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local"
|
|
else
|
|
extra_args=
|
|
fi
|
|
|
|
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 $extra_args
|