From 3b071dbbdf08aaa869ef9af6799ce767958949cb Mon Sep 17 00:00:00 2001 From: YannMagnin Date: Fri, 1 Dec 2023 16:23:13 +0100 Subject: [PATCH] sh-elf-vhex - v1.4.0-dev1 : create bootstrap script + drop vxSDK support (WIP) *regression* > [project] | [arch] drop vxSDK support (WIP) *add* > [scripts] | [bootstrap] create the bootstrap script *update* > [scripts] | [install] move to internal name (`install.sh` -> `_install.sh`) | [uninstall] move to internal name (`uninstall.sh` -> `_uninstall.sh`) | [utils] move to internal name (`utils.sh` -> `_utils.sh`) | [utils] review code (WIP) --- Makefile | 60 ---------- cmake/toolchain.cmake | 19 ---- scripts/{install.sh => _install.sh} | 16 +-- scripts/{uninstall.sh => _uninstall.sh} | 0 scripts/_utils.sh | 66 +++++++++++ scripts/bootstrap.sh | 139 ++++++++++++++++++++++++ scripts/utils.sh | 47 -------- vxsdk.toml | 16 --- 8 files changed, 208 insertions(+), 155 deletions(-) delete mode 100644 Makefile delete mode 100644 cmake/toolchain.cmake rename scripts/{install.sh => _install.sh} (95%) rename scripts/{uninstall.sh => _uninstall.sh} (100%) create mode 100644 scripts/_utils.sh create mode 100755 scripts/bootstrap.sh delete mode 100644 scripts/utils.sh delete mode 100644 vxsdk.toml diff --git a/Makefile b/Makefile deleted file mode 100644 index c15e36c..0000000 --- a/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -#--- -# This makefile is particular because it can be involved many time during the -# building process. This is why we using many conditional rule exposition -# -# All possible scenarii are : -# * sh-elf-vhex -> fxlibc -> OpenLibM -> sh-elf-vhex -# * sh-elf-vhex -> fxlibc -> sh-elf-vhex -# * fxlibc -> sh-elf-vhex -> fxlibc -> sh-elf-vhex -# * OpenLibM -> sh-elf-vhex -> fxlibc -> OpenLibM -> sh-elf-vhex -#--- - -VERSION_BINUTILS := 2.38 -VERSION_GCC := 11.3.0 - - -# check that the vxSDK is used - -ifeq ($(VXSDK_PREFIX_INSTALL),) -$(error you need to use the vxSDK to compile this package) -endif - -# default rules - -all: build install - -#--- -# Performs the real operations -#--- - -ifeq ($(VXSDK_COMPILER_CIRCULAR_BUILD_WORKAROUND),) -build: - @ cd ./scripts/binutils && ./configure.sh --version="$(VERSION_BINUTILS)" - @ cd ./scripts/binutils && ./build.sh - @ cd ./scripts/gcc && ./configure.sh --version="$(VERSION_GCC)" - @ cd ./scripts/gcc && ./build.sh - -install: - @ cd ./scripts && ./install.sh --prefix="$(VXSDK_PREFIX_INSTALL)" - -uninstall: - @ cd ./scripts && ./uninstall.sh --prefix="$(VXSDK_PREFIX_INSTALL)" - -#--- -# If a circular build is detected, simulate that all operations have -# successfully been executed -#--- - -else -build: - @ true - -install: - @ true - -uninstall: - @ true - -endif - -.PHONY: all build install uninstall diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake deleted file mode 100644 index 0ae732a..0000000 --- a/cmake/toolchain.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# Vhex toolchain file for chadCasio graphing calculators - -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_VERSION 1) -set(CMAKE_SYSTEM_PROCESSOR sh) - -set(CMAKE_C_COMPILER sh-elf-vhex-gcc) -set(CMAKE_CXX_COMPILER sh-elf-vhex-g++) - -set(CMAKE_C_FLAGS_INIT "") -set(CMAKE_CXX_FLAGS_INIT "") - -add_compile_options(-nostdlib) -add_link_options(-nostdlib) - -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/scripts/install.sh b/scripts/_install.sh similarity index 95% rename from scripts/install.sh rename to scripts/_install.sh index 20a7f12..843534a 100755 --- a/scripts/install.sh +++ b/scripts/_install.sh @@ -7,7 +7,8 @@ prefix= #--- # Help screen #--- -help() { + +function help() { cat << OEF Script for the installation step of binutils/GCC tools for the Vhex kernel. @@ -22,9 +23,6 @@ OEF exit 0 } - - - #--- # Parse arguments #--- @@ -41,14 +39,11 @@ for arg; do case "$arg" in exit 1 esac; done - - - #--- # Installation step #--- -source ../scripts/utils.sh +source ../scripts/_utils.sh TAG='' PREFIX="$prefix" @@ -71,17 +66,12 @@ if [[ "$cache" == 'false' ]]; then rm -rf ../../build fi - - - #--- # Symbolic link executables to $PREFIX #--- echo "$TAG Symlinking binaries..." -cd "$SYSROOT/bin" - mkdir -p "$PREFIX" for x in *; do ln -sf "$SYSROOT/bin/$x" "$PREFIX/$x" diff --git a/scripts/uninstall.sh b/scripts/_uninstall.sh similarity index 100% rename from scripts/uninstall.sh rename to scripts/_uninstall.sh diff --git a/scripts/_utils.sh b/scripts/_utils.sh new file mode 100644 index 0000000..c1c8e74 --- /dev/null +++ b/scripts/_utils.sh @@ -0,0 +1,66 @@ +# module used to provide common variable / functions + +## workaround to trick the linter +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + verbose=false +fi + +#--- +# Exposed vars +#--- + +# select the appropriate quiet primitive +quiet='run_normaly' +[[ "$verbose" == "false" ]] && quiet='run_quietly vxsdk-build.log' +export quiet + +# Number of processor cores +[[ $(uname) == "OpenBSD" ]] && cores=$(sysctl -n hw.ncpu) || cores=$(nproc) +export cores + +# Select make utility +make_cmd='make' +[[ $(command -v gmake >/dev/null 2>&1) ]] && make_cmd='gmake' +export make_cmd + +#--- +# Functions provided +#--- + +function run_normaly() { + echo "$@" + if ! "$@"; then + echo "$TAG error: command failed, abord" + exit 1 + fi +} + +function run_quietly() { + out="$1" + shift 1 + if ! "$@" >"$out" 2>&1; then + >&2 echo "$TAG error: command failed, please check $(pwd)/$out o(x_x)o" + >&2 echo "$@" + exit 1 + fi + rm -f "$out" +} + +function utils_find_last_version() { + _version=$(find "$1/" -maxdepth 1 -type d,l) + _version=$(echo "$_version" | sort -r ) + _version=$(echo "$_version" | head -n 1) + _version=$(basename "$_version") + echo "$_version" +} + +function get_sysroot() { + if [ -z "${VHEX_PREFIX_SYSROOT}" ]; then + echo 'error: are you sure to use the bootstrap script ?' >&2 + echo ' Missing sysroot information, abord' >&2 + exit 1 + fi + SYSROOT="${VHEX_PREFIX_SYSROOT/#\~/$HOME}" + mkdir -p "$SYSROOT" + echo "SYSROOT" +} diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100755 index 0000000..958f871 --- /dev/null +++ b/scripts/bootstrap.sh @@ -0,0 +1,139 @@ +#!/usr/bin/env bash + +#--- +# Help screen +#--- + +function help() { + cat << OEF +Bootstrap script used to install or uninstall the sh-elf-vhex compiler. + +Usage $0 [options...] + +Options: + -h, --help Display this help + -v, --verbose Display extra information during operation + --prefix-install Installation prefix + --prefix-sysroot Sysroot prefix + --prefix-clone Clone prefix + --uninstall Uninstall operation + +Notes: + + This script will use env variables: + VHEX_VERSION_BINUTILS - target version of BINUTILS + VHEX_VERSION_GCC - target version of GCC + VHEX_PREFIX_INSTALL - installation prefix + VHEX_PREFIX_SYSROOT - sysroot prefix + + Default value for each configuration: + VHEX_VERSION_BINUTILS - lastest detected + VHEX_VERSION_GCC - lastest detected + VHEX_PREFIX_INSTALL - "~/.local/bin/" + VHEX_PREFIX_CLONE - "~/.local/share/sh-elf-vhex" + VHEX_PREFIX_SYSROOT - "~/.local/share/sh-elf-vhex/sysroot" +OEF + exit 0 +} + +#--- +# Parse arguments +#--- + +[[ $# -eq 0 ]] && help + +action='install' +VHEX_VERBOSE=false +VHEX_PREFIX_INSTALL=~/.local/bin +VHEX_PREFIX_SYSROOT=~/.local/share/sh-elf-vhex/sysroot +VHEX_PREFIX_CLONE=~/.local/share/sh-elf-vhex + +for arg; do + case "$arg" in + --help | -h) help;; + --verbose | -v) VHEX_VERBOSE=true;; + --prefix-install=*) VHEX_PREFIX_INSTALL=${arg#*=};; + --prefix-sysroot=*) VHEX_PREFIX_SYSROOT=${arg#*=};; + --uninstall) action='uninstall';; + *) + echo "error: unreconized argument '$arg', giving up." >&2 + exit 1 + esac +done + +#--- +# Preliminary check +#--- + +_src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +if [ -d "$VHEX_PREFIX_CLONE" ]; then + echo "It seems that the project is already existing :pouce:" >&2 + echo \ + 'If you realy want to install this project remove the folder' \ + "'$VHEX_PREFIX_CLONE'" + exit 1 +fi + +source ./_utils.sh + +VHEX_VERSION_GCC=$(utils_find_last_version "$_src/../patchs/gcc") +VHEX_VERSION_BINUTILS=$(utils_find_last_version "$_src/../patchs/binutils") + +if [[ "$VHEX_VERBOSE" == 'true' ]] +then + echo "Debug fetched information:" + echo " - VHEX_VERSION_BINUTILS = $VHEX_VERSION_BINUTILS" + echo " - VHEX_VERSION_GCC = $VHEX_VERSION_GCC" + echo " - VHEX_PREFIX_INSTALL = $VHEX_PREFIX_INSTALL" + echo " - VHEX_PREFIX_SYSROOT = $VHEX_PREFIX_SYSROOT" + echo " - VHEX_PREFIX_CLONE = $VHEX_PREFIX_CLONE" +fi + +if [[ "$action" == 'install' ]] +then + echo 'The script will install the sh-elf-vhex compiler with:' + echo " - GCC version: $VHEX_VERSION_GCC" + echo " - Binutils version: $VHEX_VERSION_BINUTILS" + echo " - Clone directory: $VHEX_PREFIX_CLONE" + echo " - Compliler install at: $VHEX_PREFIX_INSTALL" + read -p 'Process ? [yN]: ' -r valid +else + read -p 'Uninstall the sh-elf-vhex compiler ? [yN]: ' -r valid +fi +if [[ "$valid" != 'y' ]]; then + echo 'Operation aborted o(x_x)o' + exit 1 +fi + +#--- +# Perform install operation +#--- + +git clone \ + --depth=1 \ + https://github.com/YannMagnin/sh-elf-vhex.git \ + "$VHEX_PREFIX_CLONE" +cd "$VHEX_PREFIX_CLONE" || exit 1 + +export VHEX_VERSION_BINUTILS +export VHEX_VERSION_GCC +export VHEX_VERBOSE +export VHEX_PREFIX_INSTALL +export VHEX_PREFIX_SYSROOT +export VHEX_PREFIX_CLONE + +if [[ "$action" == 'install' ]] +then + ./scripts/binutils/configure.sh + #./scripts/binutils/build.sh + #./scripts/gcc/configure.sh + #./scripts/gcc/build.sh + #./scripts/_install.sh +else + ./scripts/_uninstall.sh +fi + +echo 'Successfully installed sh-elf-vhex !' +echo "Do not forget to export the binary path '$VHEX_PREFIX_INSTALL'" +exit 0 diff --git a/scripts/utils.sh b/scripts/utils.sh deleted file mode 100644 index e6c2d8f..0000000 --- a/scripts/utils.sh +++ /dev/null @@ -1,47 +0,0 @@ -# module used to provide common variable / functions - -# select the appropriate quiet primitive -quiet='run_normaly' -[[ "$verbose" == "false" ]] && quiet='run_quietly vxsdk-build.log' - -# Number of processor cores -[[ $(uname) == "OpenBSD" ]] && cores=$(sysctl -n hw.ncpu) || cores=$(nproc) - -# Selecte make utility -[[ $(command -v gmake >/dev/null 2>&1) ]] && make_cmd=gmake || make_cmd=make - -# -# Functions privided -# - -run_normaly() { - echo "$@" - "$@" - if [[ "$?" != 0 ]]; then - echo "$TAG error: command failed, abord" - exit 1 - fi -} - -run_quietly() { - out="$1" - shift 1 - "$@" >$out 2>&1 - if [[ "$?" != 0 ]]; then - >&2 echo "$TAG error: command failed, please check $(pwd)/$out o(x_x)o" - >&2 echo "$@" - exit 1 - fi - rm -f "$out" -} - -get_sysroot() { - if [ -z $VXSDK_PREFIX_SYSROOT ]; then - >2& echo "error: are you sure to use the vxSDK ?" - >2& echo " Missing sysroot information, abord" - exit 1 - fi - SYSROOT="${VXSDK_PREFIX_SYSROOT/#\~/$HOME}" - mkdir -p "$SYSROOT" - echo "$SYSROOT" -} diff --git a/vxsdk.toml b/vxsdk.toml deleted file mode 100644 index 1f02ed5..0000000 --- a/vxsdk.toml +++ /dev/null @@ -1,16 +0,0 @@ -[project] -name = 'sh-elf-vhex' -type = 'app' -target = [ - 'superh' -] - -[superh.build] -build = 'make build' -install = 'make install' -uninstall = 'make uninstall' - -[superh.env] -VXSDK_PUBLIC_HOOK_CMAKE_TOOLCHAIN = [ - '{VXSDK_CURRENT_SOURCE_DIR}/cmake/toolchain.cmake' -]