new build system for fxSDK sysroot

* Configure and install so stuff ends up in the fxSDK sysroot
* Don't clean by default, make it a configuration called :clean
* :any now only skips build if the compiler is in the sysroot
* Redo README with proper tutorial

Details:
* Proper .gitignore
This commit is contained in:
Lephenixnoir 2022-08-19 15:03:06 +02:00
parent 5486485faf
commit 92ec440af8
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
9 changed files with 149 additions and 93 deletions

15
.gitignore vendored
View file

@ -1,11 +1,4 @@
# Everything but the scripts /binutils-*/
* /binutils-*.tar.*
!giteapc.make /build*/
!giteapc-config-any.make /giteapc-config.make
!configure.sh
!build.sh
!install.sh
!uninstall.sh
!util.sh
!.gitignore
!README.md

View file

@ -1,19 +1,67 @@
# Automatic `sh-elf-binutils` installer # SuperH toolchain: `sh-elf-binutils`
This script can be used to automatically compile and install an SH3/SH4 binutils suite. The normal use is with GiteaPC: This repository provides a guide and automated scripts to install an SH3/SH4-compatible [binutils](https://www.gnu.org/software/binutils/) suite. binutils is a collection of tools to assemble, edit and link binary programs, mainly object files. It is the main dependency for GCC, which compiles C down to assembler and relies on binutils to assemble and link this assembler output.
``` The following three methods all install binutils with different degrees of automation.
## Method 1: Using GiteaPC
The most common way to install binutils (for the fxSDK) is by using [GiteaPC](https://gitea.planet-casio.com/Lephenixnoir/GiteaPC):
```bash
% giteapc install Lephenixnoir/sh-elf-binutils % giteapc install Lephenixnoir/sh-elf-binutils
``` ```
You can also install binutils manually by running the GiteaPC Makefile with a manually-specified install prefix: This will take care of all the steps and install binutils in the fxSDK's SuperH system root.
``` A `:any` configuration is provided in case you already have another version of binutils installed in the fxSDK sysroot and want to keep using it (ie. skip a version upgrade). This will mark this repository as installed, so other repositories depending on it can build, without actually compiling binutils. Having binutils installed outside the fxSDK sysroot is not sufficient for some libraries.
% make -f giteapc.make configure build install PREFIX=$HOME/.local
```
An `any` configuration is provided in case you already have binutils installed somewhere and want to keep using it. This will turn this repository into a no-op while still satisfying requirements for other repositories. You can do this as long as you have `sh-elf-as` in your PATH: ```bash
```
% giteapc install Lephenixnoir/sh-elf-binutils:any % giteapc install Lephenixnoir/sh-elf-binutils:any
``` ```
A `:clean` configuration is also provided if you want to clean up the source and build files automatically after installing. This frees up some disk space.
```bash
% giteapc install Lephenixnoir/sh-elf-binutils:clean
```
## Method 2: Manually running the scripts
You can also install binutils by directly running this repository's scripts. In terms of dependencies, you will need:
* [fxSDK](https://gitea.planet-casio.com/Lephenixnoir/fxsdk) ≥ 2.9 (provides the sysroot)
* Most of the [requirements for GCC](https://gcc.gnu.org/install/prerequisites.html) are checked by `configure.sh`
You can run `fxsdk path sysroot` to show the SuperH sysroot where binutils will be installed. You should also specify a PATH-reachable `PREFIX` where the binaries of the toolchain will be symlinked. (The `PREFIX` is *only* for symlinks to executables, the toolchain will always be installed in the fxSDK's sysroot.) Once you're ready, run the main scripts with `make`:
```bash
% make -f giteapc.make configure build install PREFIX="$HOME/.local"
```
## Method 3: Fully manually
Get your version of choice from [`ftp.gnu.org`](https://ftp.gnu.org/gnu/binutils/) and extract the archive. Touch `binutils-$VERSION/intl/plural.c` to avoid autotools rebuilding it with bison, which no longer works ([[1]](https://sourceware.org/bugzilla/show_bug.cgi?id=22941),[[2]](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92008)).
If you want to use the fxSDK, you must install the SDK's SuperH sysroot and set the `PREFIX` to `$(fxsdk path sysroot)`. Otherwise, anything that properly isolates the cross-compiler from the host is fine.
Create and move into a build folder, then configure:
```bash
% ../binutils-$VERSION/configure \
--prefix="$PREFIX" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--program-prefix="sh-elf-" \
--enable-libssp \
--enable-lto
```
Finally, build and install:
```bash
% make -j$(nproc)
% make install-strip
```
You should add the SuperH sysroot's `bin` to your PATH, or symlink them somewhere else in the PATH. You can then remove the build folder, source folder, and source archive if you need to free up disk space.

View file

@ -1,7 +1,7 @@
#! /usr/bin/env bash #! /usr/bin/env bash
# Avoid rebuilds of the same version # Avoid rebuilds of the same version
[[ ! -d build ]] && exit 0 [[ -e "build/giteapc-skip-rebuild.txt" ]] && exit 0
source util.sh source util.sh
cd build cd build
@ -15,11 +15,5 @@ fi
echo "$TAG Compiling binutils (usually 5-10 minutes)..." echo "$TAG Compiling binutils (usually 5-10 minutes)..."
if command -v gmake >/dev/null 2>&1; then
make_command=gmake
else
make_command=make
fi
run_quietly giteapc-build.log \ run_quietly giteapc-build.log \
$make_command -j"$cores" $MAKE_COMMAND -j"$cores"

View file

@ -7,34 +7,35 @@ PREFIX="$2"
URL="https://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.xz" URL="https://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.xz"
ARCHIVE=$(basename "$URL") ARCHIVE=$(basename "$URL")
# Avoid rebuilds of the same version # Final location of ld in the sysroot
SYSROOT_LD="$SYSROOT/bin/sh-elf-ld"
# Version string of any existing sh-elf-ld in the sysroot
SYSROOT_LD_VERSION=
existing_as="$PREFIX/bin/sh-elf-as" #---
# Determine what versions are already here and decide whether to skip
#---
if [[ -f "$existing_as" ]]; then if [[ -f "$SYSROOT_LD" ]]; then
existing_version=$($existing_as --version | head -n 1 | grep -Eo '[0-9.]+$') SYSROOT_LD_VERSION=$("$SYSROOT_LD" --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 fi
# Aggressive parameter to avoid rebuilds if [[ "$SYSROOT_LD_VERSION" = "$VERSION" ]]; then
echo "$TAG binutils $VERSION already installed, skipping rebuild"
if [[ ! -z "$ACCEPT_ANY" ]]; then [[ -d build ]] && touch "build/giteapc-skip-rebuild.txt"
if command -v sh-elf-as >/dev/null 2>&1; then exit 0
echo "$TAG Found sh-elf-as in PATH and ACCEPT_ANY is set, skipping build"
if [[ -e build ]]; then
rm -rf build
fi
exit 0
fi
fi fi
# Check dependencies for binutils and GCC if [[ ! -z "$ACCEPT_ANY" && ! -z "$SYSROOT_LD_VERSION" ]]; then
echo "$TAG binutils $SYSROOT_LD_VERSION is available; skipping as per ACCEPT_ANY"
[[ -d build ]] && touch "build/giteapc-skip-rebuild.txt"
exit 0
fi
#---
# Check dependencies for building binutils and GCC, and offer to install them
#---
if command -v pkg >/dev/null 2>&1; then if command -v pkg >/dev/null 2>&1; then
deps="libmpfr libmpc libgmp libpng flex clang git texinfo libisl bison xz-utils" deps="libmpfr libmpc libgmp libpng flex clang git texinfo libisl bison xz-utils"
pm=pkg pm=pkg
@ -63,57 +64,53 @@ if [[ -z "$trust_deps" ]]; then
done done
fi fi
# Offer to install dependencies
if [[ ! -z "$missing" ]]; then if [[ ! -z "$missing" ]]; then
echo "$TAG Based on $pm, some dependencies are missing: $missing" echo "$TAG Based on $pm, some dependencies are missing: $missing"
echo -n "$TAG Do you want to run '$pm_install $missing' to install them (Y/n)? " echo -n "$TAG Do you want to run '$pm_install $missing' to install them (Y/n)? "
read do_install read do_install
if [[ "$do_install" == "y" || "$do_install" == "Y" || "$do_install" == "" ]]; then if [[ "$do_install" = "y" || "$do_install" = "Y" || "$do_install" = "" ]]; then
$pm_install $missing $pm_install $missing
else else
echo "$TAG Skipping dependencies, hoping it will build anyway." echo "$TAG Skipping dependencies, hoping it will build anyway."
fi fi
fi fi
# Download archive #---
# Get sources
#---
if [[ -f "$ARCHIVE" ]]; then if [[ -f "$ARCHIVE" ]]; then
echo "$TAG Found $ARCHIVE, skipping download" echo "$TAG Found $ARCHIVE, skipping download"
else else
echo "$TAG Downloading $URL..." echo "$TAG Downloading $URL..."
if command -v curl >/dev/null 2>&1; then if command -v curl >/dev/null 2>&1; then
curl $URL -o $ARCHIVE curl "$URL" -o "$ARCHIVE"
elif command -v wget >/dev/null 2>&1; then elif command -v wget >/dev/null 2>&1; then
wget -q --show-progress $URL -O $ARCHIVE wget -q --show-progress "$URL" -O "$ARCHIVE"
else else
echo "$TAG error: no curl or wget; install one or download archive yourself" >&2 echo "$TAG error: no curl or wget; install one or download archive yourself" >&2
exit 1 exit 1
fi fi
fi fi
# Extract archive (OpenBDS-compliant version) # Extract archive (OpenBSD-compliant version)
echo "$TAG Extracting $ARCHIVE..." echo "$TAG Extracting $ARCHIVE..."
unxz -c < $ARCHIVE | tar -xf - unxz -c < "$ARCHIVE" | tar -xf -
# Touch intl/plural.c to avoid regenerating it from intl/plural.y with recent # Touch intl/plural.c to avoid regenerating it from intl/plural.y with recent
# versions of bison, which is subject to the following known bug. # versions of bison, which is subject to the following known bug.
# * https://sourceware.org/bugzilla/show_bug.cgi?id=22941 # * https://sourceware.org/bugzilla/show_bug.cgi?id=22941
# * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92008 # * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92008
touch binutils-$VERSION/intl/plural.c touch "binutils-$VERSION/intl/plural.c"
# Create build folder #---
# Configure
#---
# We install in the sysroot and then symlink to the PREFIX folder in the path
[[ -d "build" ]] && rm -rf build [[ -d "build" ]] && rm -rf build
mkdir build mkdir build && cd build
# Configure. binutils does not support the uninstall target (wow) so we just
# install in this directory and later symlink executables to $PREFIX/bin.
PREFIX="$(pwd)"
cd build
echo "$TAG Configuring binutils..." echo "$TAG Configuring binutils..."
@ -130,5 +127,11 @@ if command -v termux-setup-storage >/dev/null 2>&1; then
CXXFLAGS="-D__ANDROID_API__=$(getprop ro.build.version.sdk) -g -O2" CXXFLAGS="-D__ANDROID_API__=$(getprop ro.build.version.sdk) -g -O2"
fi fi
run_quietly giteapc-configure.log \ run_quietly giteapc-configure.log \
../binutils-$VERSION/configure --prefix="$PREFIX" --target=sh3eb-elf --with-multilib-list=m3,m4-nofpu --program-prefix=sh-elf- --enable-libssp --enable-lto ../binutils-$VERSION/configure \
--prefix="$SYSROOT" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--program-prefix="sh-elf-" \
--enable-libssp \
--enable-lto

View file

@ -0,0 +1,4 @@
# Clean the build products after install
CONFIG_CLEAN=1
export CONFIG_CLEAN

View file

@ -1,4 +1,5 @@
# giteapc: version=1 # giteapc: version=1
# giteapc: depends=Lephenixnoir/fxsdk
PREFIX ?= $(GITEAPC_PREFIX) PREFIX ?= $(GITEAPC_PREFIX)
VERSION = 2.39 VERSION = 2.39

View file

@ -1,30 +1,26 @@
#! /usr/bin/env bash #! /usr/bin/env bash
# Avoid rebuilds of the same version # Avoid rebuilds of the same version
[[ ! -d build ]] && exit 0 [[ -e "build/giteapc-skip-rebuild.txt" ]] && exit 0
source util.sh source util.sh
PREFIX="$1" PREFIX="$1"
if command -v gmake >/dev/null 2>&1; then
make_command=gmake
else
make_command=make
fi
cd build cd build
echo "$TAG Installing to local folder..." echo "$TAG Installing binutils to the SuperH sysroot..."
run_quietly giteapc-install.log \ run_quietly giteapc-install.log \
$make_command install-strip $MAKE_COMMAND install-strip
cd .. cd ..
# Symbolic link executables to $PREFIX/bin # Symbolic link executables to $PREFIX/bin
echo "$TAG Symlinking binaries..." echo "$TAG Symlinking sysroot binaries to $PREFIX/bin..."
for x in bin/*; do mkdir -p "$PREFIX/bin"
ln -sf "$(pwd)/$x" "$PREFIX/$x" for f in "$SYSROOT/bin"/*; do
ln -sf "$f" "$PREFIX/${f#$SYSROOT/}"
done done
# Cleanup build files # Cleanup build files
echo "$TAG Cleaning up build files..." if [[ ! -z "$CONFIG_CLEAN" ]]; then
rm -rf binutils-*/ binutils-*.tar.* echo "$TAG Cleaning up build files..."
rm -rf build/ rm -rf binutils-*/ binutils-*.tar.* build/
fi

View file

@ -3,12 +3,13 @@
source util.sh source util.sh
PREFIX="$1" PREFIX="$1"
# Remove symlinks echo "$TAG Removing symlinks to $PREFIX/bin..."
echo "$TAG Removing symlinks to binaries..." TOOLS="addr2line ar as c++filt elfedit gprof ld ld.bfd nm objcopy objdump \
for x in bin/*; do ranlib readelf size strings strip"
rm "$PREFIX/$x"
for t in $TOOLS; do
[[ -L "$PREFIX/bin/sh-elf-$t" ]] && rm "$PREFIX/bin/sh-elf-$t"
done done
# Remove local files echo "$TAG Other files are managed by the fxSDK's SuperH sysroot"
echo "$TAG Removing installed files..." echo "$TAG Uninstall Lephenixnoir/fxsdk to clean up the sysroot"
rm -rf bin/ sh3eb-elf/ share/

16
util.sh
View file

@ -1,5 +1,21 @@
TAG="<sh-elf-binutils>" TAG="<sh-elf-binutils>"
if command -v gmake >/dev/null 2>&1; then
MAKE_COMMAND=gmake
else
MAKE_COMMAND=make
fi
if ! command -v fxsdk >/dev/null 2>&1; then
echo "$TAG error: fxSDK is not installed"
exit 1
elif ! fxsdk path sysroot >/dev/null 2>&1; then
echo "$TAG error: need fxSDK ≥ 2.9 with 'path' command"
exit 1
fi
SYSROOT="$(fxsdk path sysroot)"
run_quietly() { run_quietly() {
out="$1" out="$1"
shift 1 shift 1