mirror of
https://git.planet-casio.com/Lephenixnoir/sh-elf-gcc.git
synced 2024-12-28 04:23:39 +01:00
split off binutils into a separate repository
This commit is contained in:
parent
5983cce9fa
commit
23e34b8e7b
7 changed files with 75 additions and 221 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,4 +5,5 @@
|
||||||
!build.sh
|
!build.sh
|
||||||
!install.sh
|
!install.sh
|
||||||
!uninstall.sh
|
!uninstall.sh
|
||||||
|
!util.sh
|
||||||
!.gitignore
|
!.gitignore
|
||||||
|
|
65
build.sh
65
build.sh
|
@ -1,65 +1,8 @@
|
||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
binutils_version=$1
|
source util.sh
|
||||||
gcc_version=$2
|
cd build
|
||||||
tag="<sh-elf-gcc>"
|
|
||||||
root=$(pwd)
|
|
||||||
|
|
||||||
run_with_guard() {
|
echo "$TAG Compiling gcc (usually 10-20 minutes)..."
|
||||||
out="$1"
|
run_quietly giteapc-build.log \
|
||||||
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 \
|
|
||||||
make -j$(nproc) all-gcc all-target-libgcc
|
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/*
|
|
||||||
|
|
128
configure.sh
128
configure.sh
|
@ -1,117 +1,43 @@
|
||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
binutils_version=$1
|
source util.sh
|
||||||
gcc_version=$2
|
|
||||||
tag="<sh-elf-gcc>"
|
|
||||||
|
|
||||||
has() {
|
VERSION=$1
|
||||||
which $1 >/dev/null 2>&1
|
URL="https://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.xz"
|
||||||
}
|
ARCHIVE=$(basename "$URL")
|
||||||
pacman_has() {
|
|
||||||
pacman -Qi $1 >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
apt_has() {
|
|
||||||
apt show $1 >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
download() {
|
# Download archive
|
||||||
url=$1
|
|
||||||
out=$2
|
|
||||||
|
|
||||||
if [ -f "$out" ]; then
|
if [[ -f "$ARCHIVE" ]]; then
|
||||||
echo "$tag Found $out in current directory, skipping download"
|
echo "$TAG Found $ARCHIVE, 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"
|
|
||||||
else
|
else
|
||||||
trust_deps=1
|
echo "$TAG Downloading $URL..."
|
||||||
fi
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
curl $URL -o $ARCHIVE
|
||||||
missing=""
|
elif command -v wget >/dev/null 2>&1; then
|
||||||
if [[ -z "$trust_deps" ]]; then
|
wget -q --show-progress $URL -O $ARCHIVE
|
||||||
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
|
|
||||||
else
|
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
|
||||||
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
|
# Extract archive
|
||||||
|
|
||||||
echo "$tag Extracting $binutils_archive..."
|
echo "$TAG Extracting $ARCHIVE..."
|
||||||
tar -x $decompress -f $binutils_archive
|
tar -xJf $ARCHIVE
|
||||||
|
|
||||||
echo "$tag Extracting $gcc_archive..."
|
# Create build folder
|
||||||
tar -x $decompress -f $gcc_archive
|
|
||||||
|
|
||||||
# Create empty build folders
|
[[ -d "build" ]] && rm -rf build
|
||||||
|
mkdir build
|
||||||
|
|
||||||
[[ -d "build-binutils" ]] && rm -rf build-binutils
|
# Configure. GCC does not support make uninstall so we install in this
|
||||||
mkdir build-binutils
|
# directory and later symlink executables to $PREFIX/bin.
|
||||||
|
|
||||||
[[ -d "build-gcc" ]] && rm -rf build-gcc
|
PREFIX="$(pwd)"
|
||||||
mkdir build-gcc
|
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
|
||||||
|
|
12
giteapc.make
12
giteapc.make
|
@ -1,18 +1,18 @@
|
||||||
# giteapc: version=1
|
# giteapc: version=1
|
||||||
|
# giteapc: depends=Lephenixnoir/sh-elf-binutils
|
||||||
|
|
||||||
binutils_version=2.35.1
|
VERSION=10.2.0
|
||||||
gcc_version=10.2.0
|
|
||||||
|
|
||||||
configure:
|
configure:
|
||||||
@ ./configure.sh $(binutils_version) $(gcc_version)
|
@ ./configure.sh $(VERSION)
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@ ./build.sh $(binutils_version) $(gcc_version)
|
@ ./build.sh
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@ ./install.sh $(CURDIR)
|
@ ./install.sh "$(GITEAPC_PREFIX)"
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@ ./uninstall.sh $(CURDIR)
|
@ ./uninstall.sh "$(GITEAPC_PREFIX)"
|
||||||
|
|
||||||
.PHONY: configure build install uninstall
|
.PHONY: configure build install uninstall
|
||||||
|
|
64
install.sh
64
install.sh
|
@ -1,55 +1,21 @@
|
||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
path=$1/bin
|
source util.sh
|
||||||
tag="<sh-elf-gcc>"
|
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)
|
# Symbolic link executables to $PREFIX/bin
|
||||||
rc=$?
|
echo "$TAG Symlinking binaries..."
|
||||||
|
for x in bin/*; do
|
||||||
if [[ $rc == 0 && "$existing" != "$path/sh-elf-gcc" ]]; then
|
ln -s "$(pwd)/$x" "$PREFIX/$x"
|
||||||
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
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Suggest to add the path to binaries to the PATH at startup
|
# Cleanup build files
|
||||||
|
echo "$TAG Cleaning up build files..."
|
||||||
cat <<EOF
|
rm -rf gcc-*/ gcc-*.tar.*
|
||||||
===============================================================================
|
rm -rf build/
|
||||||
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
|
|
||||||
|
|
||||||
|
|
15
uninstall.sh
15
uninstall.sh
|
@ -1,7 +1,14 @@
|
||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
rm -rf bin/ include/ lib/ libexec/ sh3eb-elf/ share/
|
source util.sh
|
||||||
rm -rf binutils-*/ binutils-*.tar.* gcc-*/ gcc-*.tar.*
|
PREFIX="$1"
|
||||||
rm -rf build-binutils/ build-gcc/
|
|
||||||
|
|
||||||
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
11
util.sh
Normal 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
|
||||||
|
}
|
Loading…
Reference in a new issue