split off binutils into a separate repository

This commit is contained in:
Lephenixnoir 2021-01-02 00:13:11 +01:00
parent 5983cce9fa
commit 23e34b8e7b
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
7 changed files with 75 additions and 221 deletions

1
.gitignore vendored
View File

@ -5,4 +5,5 @@
!build.sh
!install.sh
!uninstall.sh
!util.sh
!.gitignore

View File

@ -1,65 +1,8 @@
#! /usr/bin/env bash
binutils_version=$1
gcc_version=$2
tag="<sh-elf-gcc>"
root=$(pwd)
source util.sh
cd build
run_with_guard() {
out="$1"
shift 1
"$@" >$out 2>&1
if [[ "$?" != 0 ]]; then
echo "$tag error: build failed, please check $(pwd)/$out o(x_x)o"
exit 1
fi
}
# Configure binutils
echo "$tag Configuring binutils..."
cd build-binutils
run_with_guard giteapc-configure.log \
../binutils-$binutils_version/configure --prefix="$root" --target=sh3eb-elf --with-multilib-list=m3,m4-nofpu --program-prefix=sh-elf- --enable-libssp --enable-lto
# Build binutils
echo "$tag Compiling binutils (can take a couple of minutes)..."
run_with_guard giteapc-build.log \
make -j$(nproc)
run_with_guard giteapc-install.log \
make install
cd ..
# Configure GCC
echo "$tag Configuring gcc..."
cd build-gcc
run_with_guard giteapc-configure.log \
../gcc-$gcc_version/configure --prefix="$root" --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
# Build GCC
echo "$tag Compiling gcc (often takes 10-20 minutes)..."
run_with_guard giteapc-build.log \
echo "$TAG Compiling gcc (usually 10-20 minutes)..."
run_quietly giteapc-build.log \
make -j$(nproc) all-gcc all-target-libgcc
run_with_guard giteapc-install.log \
make install-gcc install-target-libgcc
cd ..
# Cleaning up everything
echo "$tag Cleaning up..."
rm -rf binutils-$binutils_version/ build-binutils/
rm -rf gcc-$gcc_version/ build-gcc
strip bin/*

View File

@ -1,117 +1,43 @@
#! /usr/bin/env bash
binutils_version=$1
gcc_version=$2
tag="<sh-elf-gcc>"
source util.sh
has() {
which $1 >/dev/null 2>&1
}
pacman_has() {
pacman -Qi $1 >/dev/null 2>&1
}
apt_has() {
apt show $1 >/dev/null 2>&1
}
VERSION=$1
URL="https://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.xz"
ARCHIVE=$(basename "$URL")
download() {
url=$1
out=$2
# Download archive
if [ -f "$out" ]; then
echo "$tag Found $out in current directory, skipping download"
return
fi
echo "$tag Downloading $url..."
if has curl; then
curl $url -o $out
elif has wget; then
wget -q --show-progress $url -O $out
else
echo "$tag error: no curl or wget; install one or download archives yourself" >&2
return 1
fi
}
# Check dependencies
if has pacman; then
deps="mpfr mpc gmp libpng ppl flex gcc git texinfo"
pm=pacman
pm_has=pacman_has
install_cmd="sudo pacman -S"
elif has apt; then
deps="libmpfr-dev libmpc-dev libgmp-dev libpng-dev libppl-dev flex g++ git texinfo"
pm=apt
pm_has=apt_has
install_cmd="sudo apt install"
if [[ -f "$ARCHIVE" ]]; then
echo "$TAG Found $ARCHIVE, skipping download"
else
trust_deps=1
fi
missing=""
if [[ -z "$trust_deps" ]]; then
for d in $deps; do
if ! $pm_has $d; then
missing="$missing $d"
fi
done
fi
# Offer to install dependencies
if [[ ! -z "$missing" ]]; then
echo "$tag Based on $pm, some dependencies are missing: $missing"
echo -n "$tag Do you want to run '$missing_cmd' to install them (Y/n)? "
read do_install
if [[ "$do_install" == "y" || "$do_install" == "Y" || "$do_install" == "" ]]; then
$missing_cmd
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 Skipping dependencies, hoping it will build anyway."
echo "$TAG error: no curl or wget; install one or download archive yourself" >&2
exit 1
fi
fi
# Determine which compression to use (either gzip or xzip)
if has xz; then
format="tar.xz"
decompress="-J"
elif has gzip; then
format="tar.gz"
decompress="-z"
else
echo "error: gcc archives need gzip or xzip to decompress!" >&2
exit 1
fi
# Deduce source URL and file names
binutils_url="https://ftp.gnu.org/gnu/binutils/binutils-$binutils_version.$format"
binutils_archive=$(basename $binutils_url)
gcc_url="https://ftp.gnu.org/gnu/gcc/gcc-$gcc_version/gcc-$gcc_version.$format"
gcc_archive="$(basename $gcc_url)"
# Download archives
download $binutils_url $binutils_archive
download $gcc_url $gcc_archive
# Extract archive
echo "$tag Extracting $binutils_archive..."
tar -x $decompress -f $binutils_archive
echo "$TAG Extracting $ARCHIVE..."
tar -xJf $ARCHIVE
echo "$tag Extracting $gcc_archive..."
tar -x $decompress -f $gcc_archive
# Create build folder
# Create empty build folders
[[ -d "build" ]] && rm -rf build
mkdir build
[[ -d "build-binutils" ]] && rm -rf build-binutils
mkdir build-binutils
# Configure. GCC does not support make uninstall so we install in this
# directory and later symlink executables to $PREFIX/bin.
[[ -d "build-gcc" ]] && rm -rf build-gcc
mkdir build-gcc
PREFIX="$(pwd)"
cd build
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

View File

@ -1,18 +1,18 @@
# giteapc: version=1
# giteapc: depends=Lephenixnoir/sh-elf-binutils
binutils_version=2.35.1
gcc_version=10.2.0
VERSION=10.2.0
configure:
@ ./configure.sh $(binutils_version) $(gcc_version)
@ ./configure.sh $(VERSION)
build:
@ ./build.sh $(binutils_version) $(gcc_version)
@ ./build.sh
install:
@ ./install.sh $(CURDIR)
@ ./install.sh "$(GITEAPC_PREFIX)"
uninstall:
@ ./uninstall.sh $(CURDIR)
@ ./uninstall.sh "$(GITEAPC_PREFIX)"
.PHONY: configure build install uninstall

View File

@ -1,55 +1,21 @@
#! /usr/bin/env bash
path=$1/bin
tag="<sh-elf-gcc>"
source util.sh
PREFIX="$1"
# Check whether there is already such a binutils in the PATH
cd build
echo "$TAG Installing to local folder..."
run_quietly giteapc-install.log \
make install-strip-gcc install-strip-target-libgcc
cd ..
existing=$(which sh-elf-gcc)
rc=$?
if [[ $rc == 0 && "$existing" != "$path/sh-elf-gcc" ]]; then
echo "$tag WARNING: there seems to be another sh-elf-gcc in the PATH, be careful!" >&2
fi
if [[ $rc == 0 && "$existing" == "$path/sh-elf-gcc" ]]; then
echo "$tag This build is already in the PATH, there is nothing to do." >&2
exit 0
fi
# Try to find a suitable default
default="$HOME/.profile"
candidates="$HOME/.zprofile $HOME/.profile $HOME/.bash_profile $HOME/.zshrc $HOME/.bashrc"
for c in $candidates; do
if [[ -f $c ]]; then
default=$c
break
fi
# Symbolic link executables to $PREFIX/bin
echo "$TAG Symlinking binaries..."
for x in bin/*; do
ln -s "$(pwd)/$x" "$PREFIX/$x"
done
# Suggest to add the path to binaries to the PATH at startup
cat <<EOF
===============================================================================
sh-elf-gcc has been compiled but is not in the PATH, so it can't be used yet.
I can add this line to your profile to update the PATH when you log in:
export PATH="\$PATH:$path"
* Press Enter to add this line to $default
* Or type "-" to skip this step
* Or type in another file name
EOF
read -p "> " startup_file
[[ -z "$startup_file" ]] && startup_file=$default
if [[ "$startup_file" == "-" ]]; then
echo "$tag Skipped setting the PATH."
else
echo "export PATH=\"\$PATH:$path\"" >> $startup_file
echo "$tag Set the PATH in $startup_file, this will take effect next login."
fi
# Cleanup build files
echo "$TAG Cleaning up build files..."
rm -rf gcc-*/ gcc-*.tar.*
rm -rf build/

View File

@ -1,7 +1,14 @@
#! /usr/bin/env bash
rm -rf bin/ include/ lib/ libexec/ sh3eb-elf/ share/
rm -rf binutils-*/ binutils-*.tar.* gcc-*/ gcc-*.tar.*
rm -rf build-binutils/ build-gcc/
source util.sh
PREFIX="$1"
echo "<sh-elf-gcc> You can now remove $1/bin from your PATH."
# Remove symlinks
echo "$TAG Removing symlinks to binaries..."
for x in bin/*; do
rm "$PREFIX/$x"
done
# Remove local files
echo "$TAG Removing installed files..."
rm -rf bin/ include/ lib/ libexec/ share/

11
util.sh Normal file
View File

@ -0,0 +1,11 @@
TAG="<sh-elf-gcc>"
run_quietly() {
out="$1"
shift 1
"$@" >$out 2>&1
if [[ "$?" != 0 ]]; then
echo "$tag error: build failed, please check $(pwd)/$out o(x_x)o"
exit 1
fi
}