diff --git a/patchs/binutils/2.37/bfd/config.bfd b/patches/binutils/2.37/bfd/config.bfd similarity index 100% rename from patchs/binutils/2.37/bfd/config.bfd rename to patches/binutils/2.37/bfd/config.bfd diff --git a/patchs/binutils/2.37/config.sub b/patches/binutils/2.37/config.sub similarity index 100% rename from patchs/binutils/2.37/config.sub rename to patches/binutils/2.37/config.sub diff --git a/patchs/binutils/2.37/gas/configure.tgt b/patches/binutils/2.37/gas/configure.tgt similarity index 100% rename from patchs/binutils/2.37/gas/configure.tgt rename to patches/binutils/2.37/gas/configure.tgt diff --git a/patchs/binutils/2.37/ld/configure.tgt b/patches/binutils/2.37/ld/configure.tgt similarity index 100% rename from patchs/binutils/2.37/ld/configure.tgt rename to patches/binutils/2.37/ld/configure.tgt diff --git a/patchs/gcc/11.2.0/config.sub b/patches/gcc/11.2.0/config.sub similarity index 100% rename from patchs/gcc/11.2.0/config.sub rename to patches/gcc/11.2.0/config.sub diff --git a/patchs/gcc/11.2.0/fixincludes/mkfixinc.sh b/patches/gcc/11.2.0/fixincludes/mkfixinc.sh similarity index 100% rename from patchs/gcc/11.2.0/fixincludes/mkfixinc.sh rename to patches/gcc/11.2.0/fixincludes/mkfixinc.sh diff --git a/patchs/gcc/11.2.0/gcc/config.gcc b/patches/gcc/11.2.0/gcc/config.gcc similarity index 100% rename from patchs/gcc/11.2.0/gcc/config.gcc rename to patches/gcc/11.2.0/gcc/config.gcc diff --git a/patchs/gcc/11.2.0/gcc/config/sh/vhex.h b/patches/gcc/11.2.0/gcc/config/sh/vhex.h similarity index 100% rename from patchs/gcc/11.2.0/gcc/config/sh/vhex.h rename to patches/gcc/11.2.0/gcc/config/sh/vhex.h diff --git a/patchs/gcc/11.2.0/libgcc/config.host b/patches/gcc/11.2.0/libgcc/config.host similarity index 100% rename from patchs/gcc/11.2.0/libgcc/config.host rename to patches/gcc/11.2.0/libgcc/config.host diff --git a/patchs/gcc/11.3.0 b/patches/gcc/11.3.0 similarity index 100% rename from patchs/gcc/11.3.0 rename to patches/gcc/11.3.0 diff --git a/patchs/binutils/2.38 b/patchs/binutils/2.38 deleted file mode 120000 index 217e4eb..0000000 --- a/patchs/binutils/2.38 +++ /dev/null @@ -1 +0,0 @@ -2.37 \ No newline at end of file diff --git a/scripts/_install.sh b/scripts/_install.sh index 843534a..b8e2471 100755 --- a/scripts/_install.sh +++ b/scripts/_install.sh @@ -9,7 +9,7 @@ prefix= #--- function help() { - cat << OEF + cat << EOF Script for the installation step of binutils/GCC tools for the Vhex kernel. Usage $0 [options...] @@ -17,9 +17,7 @@ Usage $0 [options...] Configurations: -h, --help Display this help --cache Keep the build and the sources directory - --verbose Display extra information during the installation step - --prefix= Installation prefix -OEF +EOF exit 0 } @@ -27,33 +25,32 @@ OEF # Parse arguments #--- -[[ $# -eq 0 ]] && help - -for arg; do case "$arg" in - --help | -h) help;; - --verbose) verbose=true;; - --cache) cache=true;; - --prefix=*) prefix=${arg#*=};; - *) - echo "error: unreconized argument '$arg', giving up." >&2 - exit 1 -esac; done +for arg + do case "$arg" in + --help | -h) help;; + --cache) cache=true;; + *) + echo "error: unreconized argument '$arg', giving up." >&2 + exit 1 + esac +done #--- # Installation step #--- -source ../scripts/_utils.sh +_src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$_src" || exit 1 +source ./_utils.sh TAG='' -PREFIX="$prefix" -SYSROOT="$(get_sysroot)" +SYSROOT=$(utils_get_env 'VHEX_PREFIX_SYSROOT' 'sysroot') +INSTALL=$(utils_get_env 'VHEX_PREFIX_INSTALL' 'install') # Check that all tools has been generated -existing_gcc="$SYSROOT/bin/sh-elf-vhex-gcc" - -if [[ ! -f "$existing_gcc" ]]; then +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 " the 'as' tool is missing..." >&2 exit 1 @@ -61,7 +58,8 @@ fi # Cleanup build files -if [[ "$cache" == 'false' ]]; then +if [[ "$cache" == 'false' ]] +then echo "$TAG Cleaning up build files..." rm -rf ../../build fi @@ -72,7 +70,7 @@ fi echo "$TAG Symlinking binaries..." -mkdir -p "$PREFIX" -for x in *; do - ln -sf "$SYSROOT/bin/$x" "$PREFIX/$x" +mkdir -p "$INSTALL" +for x in "$SYSROOT/bin"/*; do + ln -s "$x" "$INSTALL/$x" done diff --git a/scripts/_utils.sh b/scripts/_utils.sh index 70542ff..3b4d2f0 100644 --- a/scripts/_utils.sh +++ b/scripts/_utils.sh @@ -1,11 +1,14 @@ # module used to provide common variable / functions # this file must not be manually invoked -# -# @note -# - workaround to trick the linter -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - verbose=$VHEX_VERBOSE -fi + +#--- +# Internals +#--- + +# workaround used to self-kill the current process if an error is detected +# in function +trap 'exit 1' TERM +export TOP_PID=$$ #--- # Exposed vars @@ -13,7 +16,7 @@ fi # select the appropriate quiet primitive quiet='utils_run_normaly' -[[ "$verbose" == "false" ]] && quiet='utils_run_quietly vxsdk-build.log' +[[ ! -v 'VHEX_VERBOSE' ]] && quiet='utils_run_quietly vxsdk-build.log' export quiet # Number of processor cores @@ -31,19 +34,21 @@ export make_cmd function utils_run_normaly() { echo "$@" - if ! "$@"; then + if ! "$@" + then echo "$TAG error: command failed, abord" - exit 1 + kill -s TERM $TOP_PID fi } function utils_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 + if ! "$@" >"$out" 2>&1 + then + echo "$TAG error: command failed, please check $(pwd)/$out o(x_x)o" >&2 + echo "$@" >&2 + kill -s TERM $TOP_PID fi rm -f "$out" } @@ -57,11 +62,11 @@ function utils_find_last_version() { } function utils_get_env() { - if [ -v "$1" ] + if [ ! -v "$1" ] then echo 'error: are you sure to use the bootstrap script ?' >&2 echo " Missing $2 information, abord" >&2 - exit 1 + kill -s TERM $TOP_PID fi echo "${!1/#\~/$HOME}" } diff --git a/scripts/binutils/build.sh b/scripts/binutils/build.sh index 8ce5fad..2cc4e99 100755 --- a/scripts/binutils/build.sh +++ b/scripts/binutils/build.sh @@ -34,7 +34,8 @@ done #--- _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source "$_src/../_utils.sh" +cd "$_src" || exit 1 +source ../_utils.sh TAG='' diff --git a/scripts/binutils/configure.sh b/scripts/binutils/configure.sh index 530c222..8663985 100755 --- a/scripts/binutils/configure.sh +++ b/scripts/binutils/configure.sh @@ -37,7 +37,8 @@ done #--- _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source "$_src/../_utils.sh" +cd "$_src" || exit 1 +source ../_utils.sh VERSION=$(utils_get_env 'VHEX_VERSION_BINUTILS' 'binutils') SYSROOT=$(utils_get_env 'VHEX_PREFIX_SYSROOT' 'sysroot') @@ -45,6 +46,9 @@ URL="https://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.xz" ARCHIVE="/tmp/sh-elf-vhex/$(basename "$URL")" TAG='' +echo "$TAG Target binutils version -> $VERSION" +echo "$TAG Sysroot found -> $SYSROOT" + #--- # Avoid rebuilds of the same version #--- @@ -101,7 +105,7 @@ else trust_deps=1 fi -missing="" +missing='' if [[ -z "$trust_deps" ]]; then for d in $deps; do if ! bash -c "$pm_has $d$fix" >/dev/null 2>&1; then @@ -117,9 +121,9 @@ then "$TAG Do you want to run '$pm_install $missing' to install " \ 'them [nY]? ' read -r do_install - if [[ "$do_install" == "n" ]] + if [[ "$do_install" != 'n' ]] then - $pm_install "$missing" + bash -c "$pm_install $missing" else echo "$TAG Skipping dependencies, hoping it will build anyway." fi @@ -157,8 +161,8 @@ fi echo "$TAG Extracting $ARCHIVE..." -mkdir -p ../../build/binutils/ -cd ../../build/binutils || exit 1 +mkdir -p ../../build/binutils +cd ../../build/binutils/ || exit 1 unxz -c < "$ARCHIVE" | tar -xf - @@ -171,7 +175,7 @@ touch "binutils-$VERSION/intl/plural.c" # Apply binutils patchs for Vhex echo "$TAG Apply Vhex patchs..." -cp -r "../../patchs/binutils/$VERSION/*" "./binutils-$VERSION/" +cp -r "$_src/../../patches/binutils/$VERSION"/* ./binutils-"$VERSION"/ # Create build folder diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 2c49ef5..f97e742 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -65,7 +65,6 @@ done # Preliminary check #--- - if [ -d "$VHEX_PREFIX_CLONE" ]; then echo "It seems that the project is already existing :pouce:" >&2 echo \ @@ -77,12 +76,13 @@ fi _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "$_src/_utils.sh" -VHEX_VERSION_GCC=$(utils_find_last_version "$_src/../patchs/gcc") -VHEX_VERSION_BINUTILS=$(utils_find_last_version "$_src/../patchs/binutils") +VHEX_VERSION_GCC=$(utils_find_last_version "$_src/../patches/gcc") +VHEX_VERSION_BINUTILS=$(utils_find_last_version "$_src/../patches/binutils") if [[ "$VHEX_VERBOSE" == 'true' ]] then echo "Debug fetched information:" + echo " - VHEX_VERBOSE = $VHEX_VERBOSE" echo " - VHEX_VERSION_BINUTILS = $VHEX_VERSION_BINUTILS" echo " - VHEX_VERSION_GCC = $VHEX_VERSION_GCC" echo " - VHEX_PREFIX_INSTALL = $VHEX_PREFIX_INSTALL" @@ -114,6 +114,7 @@ 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 @@ -123,17 +124,28 @@ export VHEX_PREFIX_INSTALL export VHEX_PREFIX_SYSROOT export VHEX_PREFIX_CLONE +success='true' if [[ "$action" == 'install' ]] then - ./scripts/binutils/configure.sh - ./scripts/binutils/build.sh - ./scripts/gcc/configure.sh - ./scripts/gcc/build.sh - ./scripts/_install.sh + ./scripts/binutils/configure.sh \ + && ./scripts/binutils/build.sh \ + && ./scripts/gcc/configure.sh \ + && ./scripts/gcc/build.sh \ + && ./scripts/_install.sh \ + || success='false' + if [[ "$success" == 'true' ]] + then + echo 'Error during bootstraping operation' >&2 + exit 1 + fi + echo 'Successfully installed sh-elf-vhex !' + echo "Do not forget to export the binary path '$VHEX_PREFIX_INSTALL'" else - ./scripts/_uninstall.sh + ./scripts/_uninstall.sh || success='false' + if [[ "$success" != 'true' ]] + then + echo 'Error during unstallation step, abord' >&2 + exit 1 + fi + echo 'Successfully uninstalled sh-elf-vhex' 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/gcc/build.sh b/scripts/gcc/build.sh index fe656dd..f900e95 100755 --- a/scripts/gcc/build.sh +++ b/scripts/gcc/build.sh @@ -38,14 +38,15 @@ done # building our own standard C library, which require openlibm and the # static version of the libgcc. # -# To avoid this circular dependency, we shall build the GCC tools with the -# static version of the libgcc. This will enable us to compile the +# To avoid this circular dependency, we shall build the GCC tools with +# the static version of the libgcc. This will enable us to compile the # openlibm, then our custom C standard library. After that, we will # rebuild GCC with, this time, the shared version of the libgcc. #--- _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source "$_src/../_utils.sh" +cd "$_src" || exit 1 +source ../_utils.sh TAG='' SYSROOT=$(utils_get_env 'VHEX_PREFIX_SYSROOT' 'sysroot') @@ -73,7 +74,7 @@ cd ../../build/gcc/build || exit 1 echo "$TAG Configuring GCC (stage 1)..." -# Configure GCC stage-1 (force disable shared version of the libgcc) +# Configure GCC stage-1 (minimal build as possible for library) $quiet ../gcc/configure \ --prefix="$SYSROOT" \ diff --git a/scripts/gcc/configure.sh b/scripts/gcc/configure.sh index a132480..92eac62 100755 --- a/scripts/gcc/configure.sh +++ b/scripts/gcc/configure.sh @@ -37,7 +37,8 @@ done #--- _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source "$_src/../_utils.sh" +cd "$_src" || exit 1 +source ../_utils.sh VERSION=$(utils_get_env 'VHEX_VERSION_GCC' 'binutils') SYSROOT=$(utils_get_env 'VHEX_PREFIX_SYSROOT' 'sysroot') @@ -45,6 +46,9 @@ URL="https://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.xz" ARCHIVE="/tmp/sh-elf-vhex/$(basename "$URL")" TAG='' +echo "$TAG Target gcc version -> $VERSION" +echo "$TAG Sysroot found -> $SYSROOT" + #--- # Avoid rebuilds of the same version #--- @@ -106,7 +110,7 @@ unxz -c < "$ARCHIVE" | tar -xf - #--- echo "$TAG Apply Vhex patchs..." -cp -r "../../patchs/gcc/$VERSION/*" "./gcc-$VERSION/" +cp -r "../../patches/gcc/$VERSION"/* "./gcc-$VERSION"/ # Rename the extracted directory to avoid path deduction during building # step (so the build script will use explicitly ...build/gcc/... path)