commit 11fc5fc3542a1a833defb80c71601e5051de573d Author: Lephenixnoir Date: Fri Jan 1 23:22:19 2021 +0100 initial building script diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6315628 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Everything but the scripts +* +!giteapc.make +!configure.sh +!build.sh +!install.sh +!uninstall.sh +!util.sh +!.gitignore diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..efe64e5 --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#! /usr/bin/env bash + +source util.sh +cd build + +echo "$TAG Compiling binutils (usually 5-10 minutes)..." +run_quietly giteapc-build.log \ +make -j$(nproc) diff --git a/configure.sh b/configure.sh new file mode 100755 index 0000000..436bcfa --- /dev/null +++ b/configure.sh @@ -0,0 +1,82 @@ +#! /usr/bin/env bash + +source util.sh + +VERSION=$1 +URL="https://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.xz" +ARCHIVE=$(basename "$URL") + +# Check dependencies for binutils and GCC + +if command -v apt >/dev/null 2>&1; then + deps="libmpfr-dev libmpc-dev libgmp-dev libpng-dev libppl-dev flex g++ git texinfo xz-utils" + pm=apt + pm_has="apt show" + pm_install="sudo apt install" +elif command -v pacman >/dev/null 2>&1; then + deps="mpfr mpc gmp libpng ppl flex gcc git texinfo xz" + pm=pacman + pm_has="pacman -Qi" + pm_install="sudo pacman -S" +else + trust_deps=1 +fi + +missing="" +if [[ -z "$trust_deps" ]]; then + for d in $deps; do + if ! $pm_has $d >/dev/null 2>&1; 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 '$pm_install' to install them (Y/n)? " + + read do_install + if [[ "$do_install" == "y" || "$do_install" == "Y" || "$do_install" == "" ]]; then + $pm_install + else + echo "$TAG Skipping dependencies, hoping it will build anyway." + 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 + +echo "$TAG Extracting $ARCHIVE..." +tar -xJf $ARCHIVE + +# Create build folder + +[[ -d "build" ]] && rm -rf build +mkdir 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..." +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 diff --git a/giteapc.make b/giteapc.make new file mode 100644 index 0000000..6292a0b --- /dev/null +++ b/giteapc.make @@ -0,0 +1,17 @@ +# giteapc: version=1 + +VERSION=2.35.1 + +configure: + @ ./configure.sh $(VERSION) + +build: + @ ./build.sh + +install: + @ ./install.sh "$(GITEAPC_PREFIX)" + +uninstall: + @ ./uninstall.sh "$(GITEAPC_PREFIX)" + +.PHONY: configure build install uninstall diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..449cf65 --- /dev/null +++ b/install.sh @@ -0,0 +1,21 @@ +#! /usr/bin/env bash + +source util.sh +PREFIX=$1 + +cd build +echo "$TAG Installing to local folder..." +run_quietly giteapc-install.log \ +make install-strip +cd .. + +# Symbolic link executables to $PREFIX/bin +echo "$TAG Symlinking binaries..." +for x in bin/*; do + ln -s $(pwd)/$x $PREFIX/$x +done + +# Cleanup build files +echo "$TAG Cleaning up build files..." +rm -rf binutils-*/ binutils-*.tar.* +rm -rf build/ diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..37feeaa --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,14 @@ +#! /usr/bin/env bash + +source util.sh +PREFIX=$1 + +# 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/ sh3eb-elf/ share/ diff --git a/util.sh b/util.sh new file mode 100644 index 0000000..8ecd195 --- /dev/null +++ b/util.sh @@ -0,0 +1,11 @@ +TAG="" + +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 +}