From 1d7a36e5f09af4cb94330f1bc3638b73148c8664 Mon Sep 17 00:00:00 2001 From: YannMagnin Date: Sat, 16 Dec 2023 18:25:13 +0100 Subject: [PATCH] sh-elf-vhex - v2.0.0-dev9 : rework uninstall operation + various fixes *add* > [scripts] | [_uninstall] support `--purge` option to remove the cloned folder | [_utils] export `utils_warn_callcmd` which throw warning if cmd fail | [bootstrap] support `--overwrite` option to force-reinstall *update* > [scripts] | [bootstrap] rename default sysroot with underscore as prefix *fix* > [scripts] | [_uninstall] use the new _utils.sh helpers | [_uninstall] proper remove symlink in install prefix | [_uninstall] proper remove the sysroot | [_uninstall] check `sh-elf-vhex-as` instead of `sh-elf-vhex-gcc` | [_utils] fix local variable declaration | [_utils] fix pushd/popd handling | [binutils/config] fix missing `gcc` as dependency for all target | [binutils/config] fix missing `gcc-g++` for Fedora | [binutils/config] fix bad package search for Fedora | [bootstrap] proper support curl operation | [gcc/config] allow dependencies install fail with warning --- README.md | 80 ++++++++++++++++------------------- scripts/_uninstall.sh | 70 ++++++++++++++++++------------ scripts/_utils.sh | 40 ++++++++++++++++-- scripts/binutils/configure.sh | 14 +++--- scripts/bootstrap.sh | 66 ++++++++++++++++------------- scripts/gcc/configure.sh | 10 ++++- 6 files changed, 170 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index cd916a8..7e14d40 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,20 @@ # sh-elf-vhex - modified GCC for the Vhex kernel projet - ## Context This project was born following the discovery of a limitation with GCC on the -SuperH architecture [see on this subject from 2 years ago](https://gcc.gnu.org/legacy-ml/gcc-help/current/000075.html): +SuperH architecture +[see on this subject from 2 years ago]( +https://gcc.gnu.org/legacy-ml/gcc-help/current/000075.html +): The generation of dynamic libraries is blocked by GCC (the `--shared` flag is ignored), because the `sh3eb-elf` target (the one used for cross-compiling on Casio calculators), does not support this functionality. -I am currently building a kernel of a Casio's calculator for a graduation -project and I need this functionality. I had discovered, thanks to Lephenixnoir, +I am currently building a kernel for Casio's calculator for a graduation +project and I need this functionality. I had discovered, thanks to +[Lephenixnoir](https://silent-tower.net/research/), that we could generate 'shared' libraries by using directly `ld` with a custom linker script, but this workaround was of short duration. Indeed, we are dependent on a library called `libgcc`, which provide some useful critical @@ -27,47 +30,10 @@ This repository gathers only the files that we had to modify for `binutils` and` GCC`, as well as scripts to automate the installation of this particular GCC. - -## Build - -The build is relatively simple and can be done in two different ways: you can -use the `compile.sh` script which is at the root of the repository: - -```bash -./compile /your/installation/path -``` - -Or you can use the `giteapc` tool, created by Lephenixnoir: - -```bash -giteapc install sh-elf-vhex -``` - -It takes about twenty minutes for the build. - - ## Technical notes -The GCC build takes much longer than the `sh3eb-elf` target because we have two -stages for the GCC build. In order, we have: - -* download + configuration of binutils sources -* download + configuration of GCC sources -* compilation of binutils -* compilation of GCC (stage-1) without enabling the shared library functionality -* compilation of OpenLibM (a dependency of our standard C library) -* compilation of fxlibc, our custom C standard library -* compilation of GCC (stage-2) with activation of the shared library fonctionality -* installation of our C library -* compilation of the shared libgcc - As for the details of the `sh-elf-vhex` target that we created: -* machine-specific features: - * (`t-slibgcc`) compilation of the shared libgcc - * (`t-libgcc-pic`) the compilation of the libgcc in PIC - * (`t-fdpbit`) compilation of the library for emulated floating point numbers -* global configuration: * only C is supported * only big endian encoding is supported * we use the stdint header from `newlib`. Otherwise, the generation of `stdint.h` is incomplete @@ -76,8 +42,36 @@ As for the details of the `sh-elf-vhex` target that we created: * by default, we link our own C library to each generation of an object file * we do not provide a specialized default linker script (for the moment) +## Installing + +The build is relatively simple and can be done in two different ways: + +```bash +curl -s "https://github.com/YannMagnin/sh-elf-vhex/+/HEAD/scripts/bootstrap.sh?format=TEXT" | base64 --decode | bash +``` + +Or by cloning the project and using the `bootstrap.sh` script, see +`./scripts/bootstrap.sh --help` for more information about possible operation +you can do with it (like uninstalling the compiler) + +```bash +cd /tmp/ +git clone 'https://github.com/YannMagnin/sh-elf-vhex.git' --depth=1 +cd /tmp/sh-elf-vhex || exit 1 +./script/bootstrap.sh +``` + +It takes about twenty minutes for the build. + +## Supported version list + +Note that GCC `12.x` will never be supported since many critical bugs has been +found for the superh backend +(https://gcc.gnu.org/bugzilla/show\_bug.cgi?id=106609) + +- GCC `11.2.0` and binutils `2.31` ## Special thanks -A big thanks to Lephenixnoir who helped me a lot for the modification of the -sources and made this project possible! +A big thanks to [Lephenixnoir](https://silent-tower.net/research/) who helped +me a lot for the modification of the sources and made this project possible! diff --git a/scripts/_uninstall.sh b/scripts/_uninstall.sh index e27f420..7c07616 100755 --- a/scripts/_uninstall.sh +++ b/scripts/_uninstall.sh @@ -7,12 +7,16 @@ function help() { cat << EOF -Script for the uninstallation of the Vhex kernel's binutils. +Script for the uninstallation of sh-elf-vhex Usage $0 [options...] Configurations: -h, --help Display this help + --prefix-install Installation (bin) prefix + --prefix-sysroot Sysroot (lib, header, ...) prefix + --prefix-clone Clone prefix + --purge Remove the clonned folder EOF exit 0 } @@ -21,47 +25,59 @@ EOF # Parse arguments #--- +prefix_install='' +prefix_sysroot='' +prefix_clone='' +purge='false' for arg do case "$arg" in - --help | -h) help;; + --help | -h) help;; + --purge) purge='true';; + --prefix-install=*) prefix_install=${arg#*=};; + --prefix-sysroot=*) prefix_sysroot=${arg#*=};; + --prefix-clone=*) prefix_clone=${arg#*=};; *) echo "error: unreconized argument '$arg', giving up." >&2 exit 1 esac done +#--- +# Preliminary check +#--- + +if [[ -z "$prefix_install" || -z "$prefix_sysroot" || -z "$prefix_clone" ]] +then + echo 'Missing prefix information, abord' >&2 + exit 1 +fi + +if [[ ! -f "$prefix_sysroot/bin/sh-elf-vhex-as" ]] +then + echo 'error: Are you sure to have built sh-elf-vhex ? it seems that' >&2 + echo ' Missing '\''sh-elf-vhex-as'\'' tool...' >&2 + exit 1 +fi #--- # Unistall step #--- -source ../scripts/_utils.sh - -TAG='' -PREFIX=$(utils_get_env 'VHEX_PREFIX_INSTALL' 'install') -SYSROOT=$(utils_get_env 'VHEX_PREFIX_SYSROOT' 'sysroot') - -# Check that all tools has been generated - -if [[ ! -f "$SYSROOT/bin/sh-elf-vhex-gcc" ]] -then - echo 'error: Are you sure to have built sh-elf-vhex ? it seems that' >&2 - echo ' Missing '\''gcc'\'' tool...' >&2 - exit 1 -fi - -#--- -# Remove symlinks -#--- +_src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$_src" || exit 1 +source ./_utils.sh echo "$TAG Removing symlinks to binaries..." -for x in "$SYSROOT"/bin/*; do - unlink "$PREFIX/$x" +for x in "$prefix_sysroot"/bin/*; do + utils_callcmd unlink "$x" + utils_callcmd unlink "$prefix_install/$(basename "$x")" done -#--- -# Remove sysroot -#--- +echo "$TAG Removing sysroot..." +rm -rf "$prefix_sysroot" -echo "$TAG Removing installed files..." -rmdir "$SYSROOT" +if [[ "$purge" == 'true' ]] +then + echo "$TAG removing cloned folder..." + rm -rf "$prefix_clone" +fi diff --git a/scripts/_utils.sh b/scripts/_utils.sh index 9da7e49..c933cb6 100644 --- a/scripts/_utils.sh +++ b/scripts/_utils.sh @@ -18,6 +18,8 @@ export TAG='' function utils_find_last_version() { + local _version + _version=$(find "$1/" -maxdepth 1 -type d,l) _version=$(echo "$_version" | sort -r ) _version=$(echo "$_version" | head -n 1) @@ -45,8 +47,32 @@ function utils_callcmd() fi } +function utils_warn_callcmd() +{ + if [[ -v 'VERBOSE' && "$VERBOSE" == '1' ]] + then + echo "$@" + if ! "$@"; then + echo "$TAG warning: command failed, skipped" + return 1 + fi + return 0 + else + out='shelfvhex_crash.txt' + if ! "$@" >"$out" 2>&1; then + echo "$TAG warning: command failed, please check $(pwd)/$out" >&2 + echo "$@" >&2 + return 1 + fi + rm -f "$out" + return 0 + fi +} + function utils_makecmd() { + local cores + [[ $(uname) == "OpenBSD" ]] \ && cores=$(sysctl -n hw.ncpu) \ || cores=$(nproc) @@ -58,10 +84,17 @@ function utils_makecmd() function utils_archive_download() { + pushd '.' > /dev/null || exit 1 + local url + local output + local cached + local src + url=$1 output=$2 cached=$3 - archive="/tmp/sh-elf-vhex/$(basename "$url")" + src=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) + archive="$src/../_cache/$(basename "$url")" if [[ -d "$output/archive" ]] then @@ -89,13 +122,14 @@ function utils_archive_download() echo "$TAG Extracting $archive..." - mkdir -p "$output/archive" && pushd "$output/archive" > /dev/null || exit 1 + mkdir -p "$output/archive" && cd "$output/archive" || exit 1 unxz -c < "$archive" | tar --strip-components 1 -xf - - popd > /dev/null || exit 1 if [[ "$cached" != 'true' ]] then echo "$TAG Removing $archive..." rm -f "$archive" fi + + popd > /dev/null || exit 1 } diff --git a/scripts/binutils/configure.sh b/scripts/binutils/configure.sh index cb28073..54d8cc2 100755 --- a/scripts/binutils/configure.sh +++ b/scripts/binutils/configure.sh @@ -86,28 +86,28 @@ fi if command -v pkg >/dev/null 2>&1 then deps='cmake libmpfr libmpc libgmp libpng flex clang git texinfo' - deps="$deps libisl bison xz-utils" + deps="$deps libisl bison xz-utils gcc" pm='pkg' pm_has='dpkg -s' pm_install='ASSUME_ALWAYS_YES=yes pkg install' elif command -v apt >/dev/null 2>&1 then deps='cmake libmpfr-dev libmpc-dev libgmp-dev libpng-dev libppl-dev' - deps="$deps flex g++ git texinfo xz-utils" + deps="$deps flex g++ git texinfo xz-utils gcc" pm='apt' pm_has='dpkg -s' pm_install='sudo apt install -y' elif command -v dnf >/dev/null 2>&1 then deps='cmake mpfr-devel libmpc-devel gmp-devel libpng-devel ppl-devel' - deps="$deps flex gcc git texinfo xz" + deps="$deps flex gcc git texinfo xz gcc-c++" pm='dnf' - pm_has="echo '$(rpm -qa)' | grep -i" + pm_has='dnf list installed | grep -i' pm_install='sudo dnf install -y' - fix='-' + fix='^' elif command -v pacman >/dev/null 2>&1 then - deps='cmake mpfr libmpc gmp libpng ppl flex gcc git texinfo xz' + deps='cmake mpfr libmpc gmp libpng ppl flex gcc git texinfo xz gcc' pm='pacman' pm_has='pacman -Qi' pm_install='sudo pacman -S --noconfirm' @@ -118,7 +118,7 @@ fi missing='' if [[ -z "$trust_deps" ]]; then for d in $deps; do - if ! bash -c "$pm_has $d$fix" >/dev/null 2>&1; then + if ! bash -c "$pm_has $fix$d" >/dev/null 2>&1; then missing="$missing $d" fi done diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index ac985d1..80791c5 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -16,6 +16,7 @@ Options: --prefix-install Installation (bin) prefix --prefix-sysroot Sysroot (lib, header, ...) prefix --prefix-clone Clone prefix + --overwrite Remove the cloned version if exists and install --uninstall Uninstall operation Notes: @@ -34,7 +35,7 @@ action='install' verbose='false' overwrite='false' prefix_install=~/.local/bin -prefix_sysroot=~/.local/share/sh-elf-vhex/sysroot +prefix_sysroot=~/.local/share/sh-elf-vhex/_sysroot prefix_clone=~/.local/share/sh-elf-vhex for arg; do @@ -53,15 +54,42 @@ for arg; do done #--- -# Preliminary check +# Handle self-clone if needed #--- - +# export verbose now to handle the self-clone if needed +[[ "$verbose" == 'true' ]] && export VERBOSE=1 _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd "$_src" || exit 1 + +if [[ "$prefix_clone/scripts" != "$_src" ]] +then + if [[ -d "$prefix_clone" && "$overwrite" != 'true' ]] + then + echo -e \ + "It seems that the project is already existing :pouce:\n" \ + 'If you realy want to install this project use the "--overwrite"' \ + 'option.' + exit 1 + fi + [[ -d "$prefix_clone" ]] && rm -rf "$prefix_clone" + echo ' self-clone repository...' + utils_callcmd \ + git \ + clone \ + --depth=1 \ + https://github.com/YannMagnin/sh-elf-vhex.git \ + "$prefix_clone" +fi + +cd "$prefix_clone/scripts" || exit 1 source ./_utils.sh +#--- +# Preliminary checks +#--- + version_gcc=$(utils_find_last_version ../patches/gcc) version_binutils=$(utils_find_last_version ../patches/binutils) @@ -92,35 +120,11 @@ if [[ "$valid" != 'y' ]]; then exit 1 fi -[[ "$verbose" == 'true' ]] && export VERBOSE=1 #--- -# Perform install operation +# Performs install/uninstall operation #--- -if [[ "$prefix_clone/scripts" != "$_src" ]] -then - if [[ -d "$prefix_clone" && "$overwrite" != 'true' ]] - then - echo -e \ - "It seems that the project is already existing :pouce:\n" \ - 'If you realy want to install this project use the "--overwrite"' \ - 'option.' - exit 1 - fi - [[ -d "$prefix_clone" ]] && rm -rf "$prefix_clone" - utils_callcmd \ - git \ - clone \ - --depth=1 \ - https://github.com/YannMagnin/sh-elf-vhex.git \ - "$prefix_clone" -else - echo "WARNING: bootstrap script used in cloned folder, skipped updated" >&2 -fi - -cd "$prefix_clone/scripts" || exit 1 - if [[ "$action" == 'install' ]] then { @@ -143,7 +147,11 @@ then echo "Do not forget to export the binary path '$prefix_install'" else { - ./scripts/_uninstall.sh + ./_uninstall.sh \ + --prefix-sysroot="$prefix_sysroot" \ + --prefix-install="$prefix_install" \ + --prefix-clone="$prefix_clone" \ + --purge } || { echo 'Error during unstallation step, abort' >&2 exit 1 diff --git a/scripts/gcc/configure.sh b/scripts/gcc/configure.sh index 07b4b7b..140099d 100755 --- a/scripts/gcc/configure.sh +++ b/scripts/gcc/configure.sh @@ -111,4 +111,12 @@ mkdir ./build echo "$TAG install dependencies..." cd ./archive || exit 1 -utils_callcmd ./contrib/download_prerequisites +if ! utils_warn_callcmd ./contrib/download_prerequisites +then + echo "The installation of GCC's prerequisites have failed" + read -p 'Do you want to continue the installation ? [yN]: ' -r valid + if [[ "$valid" != 'y' ]]; then + echo 'Operation aborted o(x_x)o' + exit 1 + fi +fi