From 23e34b8e7bad8820d86def1a3eb187c7fa3f04bf Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sat, 2 Jan 2021 00:13:11 +0100 Subject: [PATCH] split off binutils into a separate repository --- .gitignore | 1 + build.sh | 65 ++------------------------ configure.sh | 128 +++++++++++---------------------------------------- giteapc.make | 12 ++--- install.sh | 64 ++++++-------------------- uninstall.sh | 15 ++++-- util.sh | 11 +++++ 7 files changed, 75 insertions(+), 221 deletions(-) create mode 100644 util.sh diff --git a/.gitignore b/.gitignore index 7af2068..6315628 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ !build.sh !install.sh !uninstall.sh +!util.sh !.gitignore diff --git a/build.sh b/build.sh index 47b4dc5..1f3855d 100755 --- a/build.sh +++ b/build.sh @@ -1,65 +1,8 @@ #! /usr/bin/env bash -binutils_version=$1 -gcc_version=$2 -tag="" -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/* diff --git a/configure.sh b/configure.sh index 4136556..5053742 100755 --- a/configure.sh +++ b/configure.sh @@ -1,117 +1,43 @@ #! /usr/bin/env bash -binutils_version=$1 -gcc_version=$2 -tag="" +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 diff --git a/giteapc.make b/giteapc.make index e07f39b..b78c23a 100644 --- a/giteapc.make +++ b/giteapc.make @@ -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 diff --git a/install.sh b/install.sh index eab04ef..30b5c97 100755 --- a/install.sh +++ b/install.sh @@ -1,55 +1,21 @@ #! /usr/bin/env bash -path=$1/bin -tag="" +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 < " 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/ diff --git a/uninstall.sh b/uninstall.sh index 90c6353..e186054 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -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 " 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/ diff --git a/util.sh b/util.sh new file mode 100644 index 0000000..af37679 --- /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 +}