From d4b8b52af7fc4b6e5c4426cba53641476071908a Mon Sep 17 00:00:00 2001 From: Yann MAGNIN Date: Tue, 16 Nov 2021 17:43:29 +0100 Subject: [PATCH] fix comments --- scripts/compile.sh => compile.sh | 2 +- configure.sh | 8 --- scripts/binutils/build.sh | 23 +++++--- scripts/binutils/configure.sh | 42 +++++++------- scripts/binutils/install.sh | 23 ++++---- scripts/binutils/uninstall.sh | 19 +++++-- scripts/gcc/build.sh | 97 +++++++++++++++++--------------- scripts/gcc/configure.sh | 29 +++++----- scripts/gcc/install.sh | 22 ++++---- scripts/gcc/uninstall.sh | 16 ++++-- scripts/utils.sh | 7 ++- 11 files changed, 150 insertions(+), 138 deletions(-) rename scripts/compile.sh => compile.sh (92%) delete mode 100644 configure.sh diff --git a/scripts/compile.sh b/compile.sh similarity index 92% rename from scripts/compile.sh rename to compile.sh index c22f808..7d57b86 100755 --- a/scripts/compile.sh +++ b/compile.sh @@ -1,7 +1,7 @@ #! /usr/bin/env bash echo "Compil and install binutils" -cd binutils +cd scripts/binutils ./configure.sh --version=2.37 && ./build.sh && ./install.sh --prefix=/tmp echo "Compil and install GCC" diff --git a/configure.sh b/configure.sh deleted file mode 100644 index b712451..0000000 --- a/configure.sh +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env bash - -# - -TARGET=$1 -PREFIX="$2" -URL="https://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.xz" -ARCHIVE=$(basename "$URL") diff --git a/scripts/binutils/build.sh b/scripts/binutils/build.sh index 63b2ffe..a67b88a 100755 --- a/scripts/binutils/build.sh +++ b/scripts/binutils/build.sh @@ -5,11 +5,9 @@ verbose=false # # Help screen # -help() -{ +help() { cat << OEF -Building helper script for the configuration step of the binutils build for the -Vhex kernel project. +Script for the building step of binutils for the Vhex kernel. Usage $0 [options...] @@ -23,7 +21,7 @@ OEF # -# Parse argument +# Parse arguments # for arg; do case "$arg" in @@ -42,17 +40,23 @@ esac; done TAG='' +# Check that the configuration step has been effectuated -# Avoid rebuilds of the same version -[[ ! -d ../../build/binutils/build ]] && exit 0 +if [[ ! -d ../../build/binutils/build ]]; then + echo "error: Are you sure to have configured binutils ? it seems that" >&2 + echo " the build directory is missing..." >&2 + exit 1 +fi cd ../../build/binutils/build -# import some utility +# Import some helpers + source ../../../scripts/utils.sh -# build part +# Build part + echo "$TAG Compiling binutils (usually 5-10 minutes)..." $quiet $make_cmd -j"$cores" @@ -60,3 +64,4 @@ $quiet $make_cmd -j"$cores" echo "$TAG Installing to local folder..." $quiet $make_cmd install-strip +exit 0 diff --git a/scripts/binutils/configure.sh b/scripts/binutils/configure.sh index 2e281f7..3597d7b 100755 --- a/scripts/binutils/configure.sh +++ b/scripts/binutils/configure.sh @@ -1,20 +1,15 @@ #! /usr/bin/env bash - verbose=false cache=false version='?' -prefix= - # # Help screen # -help() -{ +help() { cat << OEF -Configuration file for the configuration step of the binutils build for the -Vhex kernel project. +Script for the configuration step of Vhex kernel's binutils. Usage $0 [options...] @@ -22,9 +17,9 @@ Configurations: -h, --help Display this help --cache Keep the archive of binutils --verbose Display extra information during the configuration step - --version= Select the binutils version. If the '?' argument is - passed then all binutils version with Vhex patch - availables will be printed + --version= Select the binutils version. If '?' argument is passed, + then all binutils version with Vhex patchs available + will be displayed OEF exit 0 } @@ -32,7 +27,7 @@ OEF # -# Parse argument +# Parse arguments # [[ $# -eq 0 ]] && help @@ -41,19 +36,20 @@ for arg; do case "$arg" in --help | -h) help;; --verbose) verbose=true;; --cache) cache=true;; - --prefix=*) prefix=${arg#*=};; --version=*) version=${arg#*=};; *) - echo "error: unreconized argument '$arg', giving up." >&2 + echo "error: unrecognized argument '$arg', giving up" >&2 exit 1 esac; done + # # Check parsing validity # # check version + list_version=$(basename $(ls -d ../../patchs/binutils/*)) if [[ "$version" == '?' ]]; then echo "$list_version" @@ -69,9 +65,6 @@ fi # # Configuration part -# @note -# This part is forked from the sh-elf-binutils repository created by -# Lephenixnoir. # TAG='' @@ -95,6 +88,7 @@ if [[ -f "$existing_as" ]]; then fi # Check dependencies for binutils and GCC + if command -v pkg >/dev/null 2>&1; then deps="libmpfr libmpc libgmp libpng flex clang git texinfo libisl bison xz-utils" pm=pkg @@ -186,10 +180,11 @@ cp -r ../../patchs/binutils/$VERSION/* ./binutils-$VERSION/ [[ -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. +# Configure binutils does not support the uninstall target (wow) so we just +# install in this directory and later symlink executables to the "real" prefix. PREFIX="$(pwd)" + cd build echo "$TAG Configuring binutils..." @@ -197,8 +192,8 @@ echo "$TAG Configuring binutils..." if command -v termux-setup-storage >/dev/null 2>&1; then # Since the __ANDROID_API__ flag is hardcoded as 24 in clang, and # doesn't prototype some functions when this flag is too low, fixes it's - # version by checking system's properties so as to prevent from missing prototypes - # of existing functions such as fgets_unlocked (only if API >= 28) + # version by checking system's properties so as to prevent from missing + # prototypes of existing functions such as fgets_unlocked (only if API >= 28) # See the following issues : # * https://github.com/termux/termux-packages/issues/6176 # * https://github.com/termux/termux-packages/issues/2469 @@ -208,14 +203,17 @@ if command -v termux-setup-storage >/dev/null 2>&1; then fi -# check quiet mode +# Import some helpers + source ../../../scripts/utils.sh # Real configuration step + $quiet ../binutils-$VERSION/configure --prefix="$PREFIX" --target=sh-elf-vhex \ --with-multilib-list=m3,m4-nofpu --disable-nls --enable-lto -# cache management +# Cache management + if [[ "$cache" == 'false' ]]; then echo "$TAG Removing $ARCHIVE..." rm -f $ARCHIVE diff --git a/scripts/binutils/install.sh b/scripts/binutils/install.sh index 49d1fd1..4c978ff 100755 --- a/scripts/binutils/install.sh +++ b/scripts/binutils/install.sh @@ -4,21 +4,18 @@ verbose=false cache=false prefix= - # # Help screen # -help() -{ +help() { cat << OEF -Installation helper script for the configuration step of the binutils build for -the Vhex kernel project. +Script for the installation step of binutils for the Vhex kernel. Usage $0 [options...] Configurations: -h, --help Display this help - --cache Keep the build and sources directory + --cache Keep the build and the sources directory --verbose Display extra information during the installation step --prefix= Installation prefix OEF @@ -28,7 +25,7 @@ OEF # -# Parse argument +# Parse arguments # [[ $# -eq 0 ]] && help @@ -44,19 +41,21 @@ for arg; do case "$arg" in esac; done + # # Installation step -# @note -# This part is forked from the sh-elf-binutils repository created by -# Lephenixnoir. # TAG='' PREFIX="$prefix" -# Avoid rebuilds of the same version +# Check that the configuration step has been effectuated -[[ ! -d ../../build/binutils/build ]] && exit 0 +if [[ ! -d ../../build/binutils/build ]]; then + echo "error: Are you sure to have configured binutils ? it seems that" >&2 + echo " the build directory is missing..." >&2 + exit 1 +fi cd ../../build/binutils # Symbolic link executables to $PREFIX/bin diff --git a/scripts/binutils/uninstall.sh b/scripts/binutils/uninstall.sh index 8fb33c5..1bbe6d4 100755 --- a/scripts/binutils/uninstall.sh +++ b/scripts/binutils/uninstall.sh @@ -10,14 +10,13 @@ prefix= help() { cat << OEF -Installation helper script for the configuration step of the binutils build for -the Vhex kernel project. +Script for the uninstallation of the Vhex kernel's binutils. Usage $0 [options...] Configurations: -h, --help Display this help - --verbose Display extra information during the installation step + --verbose Display extra information during the uninstallation --prefix= Installation prefix OEF exit 0 @@ -26,9 +25,11 @@ OEF # -# Parse argument +# Parse arguments # +[[ $# -eq 0 ]] && help + for arg; do case "$arg" in --help | -h) help;; --verbose) verbose=true;; @@ -46,17 +47,23 @@ esac; done TAG='' PREFIX="$prefix" -# Avoid rebuilds of the same version +# Check that the configuration step has been effectuated -[[ ! -d ../../build/binutils ]] && exit 0 +if [[ ! -d ../../build/binutils/build ]]; then + echo "error: Are you sure to have configured binutils ? it seems that" >&2 + echo " the build directory is missing..." >&2 + exit 1 +fi cd ../../build/binutils # 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 ../binutils diff --git a/scripts/gcc/build.sh b/scripts/gcc/build.sh index cbb7925..cc41378 100755 --- a/scripts/gcc/build.sh +++ b/scripts/gcc/build.sh @@ -5,11 +5,9 @@ verbose=false # # Help screen # -help() -{ +help() { cat << OEF -Building helper script for the configuration step of the binutils build for the -Vhex kernel project. +Script for the building step of GCC for the Vhex kernel. Usage $0 [options...] @@ -23,7 +21,7 @@ OEF # -# Parse argument +# Parse arguments # for arg; do case "$arg" in @@ -39,56 +37,54 @@ esac; done # # Building step # @note: -# We need to build GCC a least two time. This because we whant to enable -# shared version of the libgcc. But, to compile the librarie, we need to build -# our own standard C librarie, which required openlibm and the libgcc. +# We need to build GCC at least two time. This because we want to enable +# shared version of the libgcc. But, to compile this library, we require +# building our own standard C library, which require openlibm and the static +# version of the libgcc. # -# To avoid this, we will configure and build the GCC tools and the static -# libgcc. This will enable us to compile the openlibm, then our libc. After -# that we will anable to build the shared 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 openlibm, +# then our custom C standard library. After that, we will rebuild GCC with, +# this time, the shared version of the libgcc. # - - -## Get external information before starting the building step - -# verbose tag TAG='' -# import utility +# Import some helpers + source ../utils.sh # OpenBSD apparently installs these in /usr/local + extra_args= if [[ $(uname) == "OpenBSD" ]]; then - extra_args="--with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local" + extra_args='--with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local' fi - - -## create the building directory +# Create the build directory mkdir -p ../../build/gcc/build cd ../../build/gcc/build -## first configuration + +# +# Build GCC stage-1 +# echo "$TAG Configuring GCC (stage 1)..." -# Configure. GCC does not support make uninstall so we install in this -# directory and later symlink executables to $PREFIX/bin. +# GCC does not support 'make uninstall' so we install in this directory and +# later symlink executables to the "real" prefix. PREFIX="$(pwd)/.." +# Configure GCC stage-1 (force disable shared version of the libgcc) + $quiet ../gcc/configure --prefix=$PREFIX --target=sh-elf-vhex \ --with-multilib-list=m3,m4-nofpu --enable-languages=c --without-headers \ --disable-nls --enable-lto --disable-shared $extra_args - - -## first build - echo "$TAG Compiling GCC (stage 1) (usually 10-20 minutes)..." $quiet $make_cmd -j"$cores" all-gcc @@ -111,7 +107,7 @@ $quiet $make_cmd -j"$cores" install-strip-target-libgcc # Patch the C standar library # -# export binary +# Export binaries used to build OpenLibM and fxLibc cd .. @@ -120,23 +116,26 @@ export PATH="$PATH:$(pwd)/sh-elf-vhex/bin" cd .. -## Install OpenLibM +echo "$TAG Building Vhex's custom C standard library..." -echo "$TAG Install OpenLibM..." +# Install OpenLibM rm -rf OpenLibm $quiet git clone https://gitea.planet-casio.com/Lephenixnoir/OpenLibm.git --depth=1 cd OpenLibm -# get installation path +# Get installation path + LIP=$(sh-elf-vhex-gcc --print-search-dirs | grep install | sed 's/install: //') -# build +# Build + $quiet $make_cmd USEGCC=1 ARCH=sh3eb TOOLPREFIX=sh-elf-vhex- \ CC=sh-elf-vhex-gcc AR=sh-elf-vhex-ar \ libdir="$LIP" includedir="$LIP/include" -# install +# Install (needed by fxlibc) + $quiet $make_cmd USEGCC=1 ARCH=sh3eb TOOLPREFIX=sh-elf-vhex- \ CC=sh-elf-vhex-gcc AR=sh-elf-vhex-ar \ libdir="$LIP" includedir="$LIP/include" \ @@ -144,8 +143,7 @@ $quiet $make_cmd USEGCC=1 ARCH=sh3eb TOOLPREFIX=sh-elf-vhex- \ cd .. - -echo "$TAG Patch the standard library..." +# Build Vhex custom C standard library rm -rf fxlibc $quiet git clone https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc.git @@ -164,22 +162,24 @@ cd ../.. # -# Build the GCC state-2 +# Build GCC stage-2 # echo "$TAG Configuring GCC (stage 2)..." cd gcc -## remove stage 1 compilation part +# Remove stage-1 compilation part rm -rf $(ls | grep -v gcc | grep -v sh-elf-vhex) -## build +# Recreate the build directory mkdir -p build cd build +# Configure GCC for the stage-2 (force enable shared version of libgcc) + $quiet ../gcc/configure --prefix=$PREFIX --target=sh-elf-vhex \ --with-multilib-list=m3,m4-nofpu --enable-languages=c --without-headers \ --disable-nls --enable-lto $extra_args @@ -192,25 +192,33 @@ echo "$TAG Install GCC (stage 2)..." $quiet $make_cmd -j"$cores" install-strip-gcc -## libc patch +# +# Patch the generation of the shared version of the libgcc which require a C +# standard library. +# echo "$TAG Install C standar library..." +# Re-install openlibm + cd ../../OpenLibm + $quiet $make_cmd USEGCC=1 ARCH=sh3eb TOOLPREFIX=sh-elf-vhex- \ CC=sh-elf-vhex-gcc AR=sh-elf-vhex-ar \ libdir="$LIP" includedir="$LIP/include" \ install-static install-headers +# Install the C standard library + cd ../fxlibc/build-vhex $quiet $make_cmd install - +# Generate the shared version of libgcc cd ../../gcc/build -# it seems that the generation of the shared libgcc search the -# libc in a non-conventional path +# It seems that the generation of the shared libgcc search the +# libc in a non-conventional (?) path rm -rf $(pwd)/../sh-elf-vhex/lib ln -sf $LIP/lib $(pwd)/../sh-elf-vhex/lib @@ -222,7 +230,4 @@ $quiet $make_cmd -j"$cores" all-target-libgcc echo "$TAG Install libgcc (stage 2)..." $quiet $make_cmd -j"$cores" install-strip-target-libgcc - - - exit 0 diff --git a/scripts/gcc/configure.sh b/scripts/gcc/configure.sh index 13793b0..2f791f0 100755 --- a/scripts/gcc/configure.sh +++ b/scripts/gcc/configure.sh @@ -4,25 +4,22 @@ verbose=false cache=false version='?' - # # Help screen # -help() -{ +help() { cat << OEF -Configuration file for the configuration step of the GCC build for the Vhex -kernel project. +Script for the configuration step of Vhex kernel's binutils. Usage $0 [options...] Configurations: -h, --help Display this help - --no-cache Do not keep the archive of binutils + --cache Keep the archive of GCC --verbose Display extra information during the configuration step - --version= Select the GCC version. If the '?' argument is - passed then all binutils version with Vhex patch - availables will be printed + --version= Select the GCC version. If '?' argument is passed, + then all GCC version with Vhex patchs available + will be displayed OEF exit 0 } @@ -30,7 +27,7 @@ OEF # -# Parse argument +# Parse arguments # [[ $# -eq 0 ]] && help @@ -51,6 +48,7 @@ esac; done # # check version + list_version=$(basename $(ls -d ../../patchs/gcc/*)) if [[ "$version" == '?' ]]; then echo "$list_version" @@ -62,11 +60,10 @@ if [[ ! $list_version =~ (^|[[:space:]])$version($|[[:space:]]) ]]; then exit 1 fi + + # # Configuration part -# @note -# This part is forked from the sh-elf-binutils repository created by -# Lephenixnoir. # TAG='' @@ -119,14 +116,14 @@ unxz -c < $ARCHIVE | tar -xf - echo "$TAG Apply Vhex patchs..." cp -r ../../patchs/gcc/$VERSION/* ./gcc-$VERSION/ -# Rename the directory to avoid path deduction during configuration part in -# build.sh +# Rename the extracted directory to avoid path deduction during building strep [[ -d ./gcc ]] && rm -rf ./gcc mv ./gcc-$VERSION/ ./gcc # Symlink as, ld, ar and ranlib, which gcc will not find by itself (we renamed # them from sh3eb-elf-* to sh-elf-* with --program-prefix). + mkdir -p sh-elf-vhex/bin ln -sf $(pwd)/../binutils/bin/sh-elf-vhex-as sh-elf-vhex/bin/as ln -sf $(pwd)/../binutils/bin/sh-elf-vhex-ld sh-elf-vhex/bin/ld @@ -136,6 +133,8 @@ ln -sf $(pwd)/../binutils/bin/sh-elf-vhex-ranlib sh-elf-vhex/bin/ranlib # patch OpenLibM building error (which search for sh-elf-vhex-ar) ln -sf $(pwd)/../binutils/bin/sh-elf-vhex-ar sh-elf-vhex/bin/sh-elf-vhex-ar +# Cache management + if [[ "$cache" == 'false' ]]; then echo "$TAG Removing $ARCHIVE..." rm -f $ARCHIVE diff --git a/scripts/gcc/install.sh b/scripts/gcc/install.sh index 22bf2b4..22f6dd4 100755 --- a/scripts/gcc/install.sh +++ b/scripts/gcc/install.sh @@ -4,15 +4,12 @@ verbose=false cache=false prefix= - # # Help screen # -help() -{ +help() { cat << OEF -Installation helper script for the configuration step of the binutils build for -the Vhex kernel project. +Script for the installation step of GCC for the Vhex kernel. Usage $0 [options...] @@ -28,7 +25,7 @@ OEF # -# Parse argument +# Parse arguments # [[ $# -eq 0 ]] && help @@ -44,22 +41,23 @@ for arg; do case "$arg" in esac; done + # # Installation step -# @note -# This part is forked from the sh-elf-binutils repository created by -# Lephenixnoir. # TAG='' PREFIX="$prefix" -# Avoid rebuilds of the same version +# Check that the configuration step has been effectuated -[[ ! -d ../../build/gcc ]] && exit 0 +if [[ ! -d ../../build/gcc/build ]]; then + echo "error: Are you sure to have configured GCC ? it seems that" >&2 + echo " the build directory is missing..." >&2 + exit 1 +fi cd ../../build/gcc - # Symbolic link executables to $PREFIX/bin echo "$TAG Symlinking binaries..." diff --git a/scripts/gcc/uninstall.sh b/scripts/gcc/uninstall.sh index f196630..1e6f6cd 100755 --- a/scripts/gcc/uninstall.sh +++ b/scripts/gcc/uninstall.sh @@ -10,8 +10,7 @@ prefix= help() { cat << OEF -Installation helper script for the configuration step of the binutils build for -the Vhex kernel project. +Script for the uninstallation of the Vhex kernel's GCC. Usage $0 [options...] @@ -26,7 +25,7 @@ OEF # -# Parse argument +# Parse arguments # [[ $# -eq 0 ]] && help @@ -48,18 +47,25 @@ esac; done TAG='' PREFIX="$prefix" -# Avoid rebuilds of the same version +# Check that the configuration step has been effectuated -[[ ! -d ../../build/gcc ]] && exit 0 +if [[ ! -d ../../build/gcc/build ]]; then + echo "error: Are you sure to have configured GCC ? it seems that" >&2 + echo " the build directory is missing..." >&2 + exit 1 +fi cd ../../build/gcc # 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 ../gcc exit 0 diff --git a/scripts/utils.sh b/scripts/utils.sh index 23a4971..fc08b51 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -1,3 +1,4 @@ +# module used to provide common variable / functions # select the appropriate quiet primitive quiet='run_normaly' @@ -6,10 +7,12 @@ quiet='run_normaly' # Number of processor cores [[ $(uname) == "OpenBSD" ]] && cores=$(sysctl -n hw.ncpu) || cores=$(nproc) -# selecte make utility +# Selecte make utility [[ $(command -v gmake >/dev/null 2>&1) ]] && make_cmd=gmake || make_cmd=make -## functions privided +# +# Functions privided +# run_normaly() { bash -c "$@"