sh-elf-vhex - v2.0.0-dev6 : rework scripts

*update*
> [scripts]
  | [install] rework CLI and subscripts handling
  | [binutils] rework CLI and operations
  | [gcc] rework CLI and operations

*fix*
> [patches]
  | [gcc] drop 11.3.0 support
> [scripts]
  | [binutils] do not wait user confirm for package installation
This commit is contained in:
YannMagnin 2023-12-04 18:33:11 +01:00
parent 21e04b4df1
commit 155a34acc1
No known key found for this signature in database
GPG Key ID: D82629D933EADC59
8 changed files with 239 additions and 254 deletions

View File

@ -1 +0,0 @@
11.2.0

View File

@ -1,9 +1,5 @@
#! /usr/bin/env bash
verbose=false
cache=false
prefix=
#---
# Help screen
#---
@ -25,12 +21,20 @@ EOF
# Parse arguments
#---
for arg
do case "$arg" in
--help | -h) help;;
--cache) cache=true;;
cache=false
verbose=false
prefix_install=
prefix_sysroot=
for arg; do
case "$arg" in
--help | -h) help;;
--verbose | -v) verbose=true;;
--cache) cache=true;;
--prefix-sysroot=*) prefix_sysroot=${arg#*=};;
--prefix-install=*) prefix_install=${arg#*=};;
*)
echo "error: unreconized argument '$arg', giving up." >&2
echo "error: unrecognized argument '$arg', giving up." >&2
exit 1
esac
done
@ -43,34 +47,28 @@ _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$_src" || exit 1
source ./_utils.sh
TAG='<sh-elf-vhex>'
SYSROOT=$(utils_get_env 'VHEX_PREFIX_SYSROOT' 'sysroot')
INSTALL=$(utils_get_env 'VHEX_PREFIX_INSTALL' 'install')
# Check that all tools has been generated
if [[ ! -f "$SYSROOT/bin/sh-elf-vhex-gcc" ]]
if [[ ! -f "$prefix_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
fi
# Cleanup build files
if [[ "$cache" == 'false' ]]
then
echo "$TAG Cleaning up build files..."
rm -rf ../../build
fi
[[ "$verbose" == 'true' ]] && export VERBOSE=1
#---
# Symbolic link executables to $PREFIX
#---
echo "$TAG Symlinking binaries..."
mkdir -p "$INSTALL"
for x in "$SYSROOT/bin"/*; do
ln -s "$x" "$INSTALL/$x"
mkdir -p "$prefix_install"
for x in "$prefix_sysroot/bin"/*; do
utils_callcmd ln -sf "$x" "$prefix_install/$(basename "$x")"
done

View File

@ -1,4 +1,4 @@
# module used to provide common variable / functions
# module used to provide common variables / functions
# this file must not be manually invoked
#---
@ -11,49 +11,13 @@ trap 'exit 1' TERM
export TOP_PID=$$
#---
# Exposed vars
# Public
#---
# select the appropriate quiet primitive
quiet='utils_run_normaly'
[[ ! -v 'VHEX_VERBOSE' ]] && quiet='utils_run_quietly vxsdk-build.log'
export quiet
export TAG='<sh-elf-vhex>'
# 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 utils_run_normaly() {
echo "$@"
if ! "$@"
then
echo "$TAG error: command failed, abord"
kill -s TERM $TOP_PID
fi
}
function utils_run_quietly() {
out="$1"
shift 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"
}
function utils_find_last_version() {
function utils_find_last_version()
{
_version=$(find "$1/" -maxdepth 1 -type d,l)
_version=$(echo "$_version" | sort -r )
_version=$(echo "$_version" | head -n 1)
@ -61,12 +25,33 @@ function utils_find_last_version() {
echo "$_version"
}
function utils_get_env() {
if [ ! -v "$1" ]
then
echo 'error: are you sure to use the bootstrap script ?' >&2
echo " Missing $2 information, abord" >&2
kill -s TERM $TOP_PID
function utils_callcmd()
{
if [[ -v 'VERBOSE' && "$VERBOSE" == '1' ]]
then
echo "$@"
if ! "$@"; then
echo "$TAG error: command failed, abort"
kill -s TERM $TOP_PID
fi
else
out='shelfvhex_crash.txt'
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"
fi
echo "${!1/#\~/$HOME}"
}
function utils_makecmd()
{
[[ $(uname) == "OpenBSD" ]] \
&& cores=$(sysctl -n hw.ncpu) \
|| cores=$(nproc)
[[ $(command -v gmake >/dev/null 2>&1) ]] \
&& make_cmd='gmake' \
|| make_cmd='make'
utils_callcmd "$make_cmd" "-j$cores" "$@"
}

View File

@ -37,8 +37,6 @@ _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$_src" || exit 1
source ../_utils.sh
TAG='<sh-elf-vhex-binutils>'
# Avoid rebuilds and error
if [[ -f ../../build/binutils/.fini ]]
@ -62,13 +60,12 @@ cd ../../build/binutils/build || exit 1
echo "$TAG Compiling binutils (usually 5-10 minutes)..."
$quiet $make_cmd -j"$cores"
utils_makecmd
echo "$TAG Installing binutils to sysroot..."
$quiet $make_cmd install-strip
utils_makecmd install-strip
# Indicate that the build is finished
touch ../.fini
exit 0

View File

@ -12,7 +12,10 @@ Usage $0 [options...]
Configurations:
-h, --help Display this help
--cache Keep the archive of binutils
-v, --verbose Display extra information during operation
--cache Keep the archive of binutils
--prefix-sysroot Sysroot (lib, header, ...) prefix
--version Binutils version
EOF
exit 0
}
@ -22,10 +25,15 @@ EOF
#---
cache=false
prefix_sysroot=
version=
for arg;
do case "$arg" in
--help | -h) help;;
--cache) cache=true;;
--help | -h) help;;
--verbose | -v) verbose=true;;
--prefix-sysroot=*) prefix_sysroot=${arg#*=};;
--version=*) version=${arg#*=};;
--cache) cache=true;;
*)
echo "error: unrecognized argument '$arg', giving up" >&2
exit 1
@ -40,27 +48,32 @@ _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$_src" || exit 1
source ../_utils.sh
VERSION=$(utils_get_env 'VHEX_VERSION_BINUTILS' 'binutils')
SYSROOT=$(utils_get_env 'VHEX_PREFIX_SYSROOT' 'sysroot')
URL="https://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.xz"
ARCHIVE="/tmp/sh-elf-vhex/$(basename "$URL")"
TAG='<sh-elf-vhex-binutils>'
if [[ ! -d "../../patches/binutils/$version" ]]
then
echo "Binutils version '$version' not supported, abort" >&2
exit 1
fi
echo "$TAG Target binutils version -> $VERSION"
echo "$TAG Sysroot found -> $SYSROOT"
[[ "$verbose" == 'true' ]] && export VERBOSE=1
url="https://ftp.gnu.org/gnu/binutils/binutils-$version.tar.xz"
archive="/tmp/sh-elf-vhex/$(basename "$url")"
echo "$TAG Target binutils version -> $version"
echo "$TAG Sysroot found -> $prefix_sysroot"
#---
# Avoid rebuilds of the same version
#---
as_bin="$SYSROOT/bin/sh-elf-vhex-as"
as_bin="$prefix_sysroot/bin/sh-elf-vhex-as"
if [[ -f "$as_bin" ]]
if test -f "$as_bin"
then
as_version=$($as_bin --version | head -n 1 | grep -Eo '[0-9.]+$')
if [[ "$as_version" == "$VERSION" ]]
if [[ "$as_version" == "$version" ]]
then
echo "$TAG Version $VERSION already installed, skipping rebuild" >&2
echo "$TAG Version '$version' already installed, skipping rebuild" >&2
mkdir -p ../../build/binutils/
touch ../../build/binutils/.fini
exit 0
@ -79,28 +92,28 @@ then
deps="$deps libisl bison xz-utils"
pm='pkg'
pm_has='dpkg -s'
pm_install='pkg install'
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"
pm='apt'
pm_has='dpkg -s'
pm_install='sudo apt install'
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"
pm='dnf'
pm_has="echo '$(rpm -qa)' | grep -i "
pm_install='sudo dnf install'
pm_has="echo '$(rpm -qa)' | grep -i"
pm_install='sudo dnf install -y'
fix='-'
elif command -v pacman >/dev/null 2>&1
then
deps='cmake mpfr libmpc gmp libpng ppl flex gcc git texinfo xz'
pm='pacman'
pm_has="pacman -Qi"
pm_install="sudo pacman -S"
pm_has='pacman -Qi'
pm_install='sudo pacman -S --noconfirm'
else
trust_deps=1
fi
@ -133,20 +146,18 @@ fi
# Download archive
#---
[[ "$cache" == 'false' && -f "$ARCHIVE" ]] && rm -f "$ARCHIVE"
mkdir -p "$(dirname "$ARCHIVE")"
if [[ -f "$ARCHIVE" ]]
mkdir -p "$(dirname "$archive")"
if [[ -f "$archive" ]]
then
echo "$TAG Found $ARCHIVE, skipping download"
echo "$TAG Found $archive, skipping download"
else
echo "$TAG Downloading $URL..."
echo "$TAG Downloading $url..."
if command -v curl >/dev/null 2>&1
then
curl "$URL" -o "$ARCHIVE"
curl "$url" -o "$archive"
elif command -v wget >/dev/null 2>&1
then
wget -q --show-progress "$URL" -O "$ARCHIVE"
wget -q --show-progress "$url" -O "$archive"
else
echo \
"$TAG error: no curl or wget; install one or download "
@ -159,23 +170,23 @@ fi
# Extract archive (OpenBDS-compliant version)
#---
echo "$TAG Extracting $ARCHIVE..."
echo "$TAG Extracting $archive..."
mkdir -p ../../build/binutils
cd ../../build/binutils/ || exit 1
unxz -c < "$ARCHIVE" | tar -xf -
unxz -c < "$archive" | tar -xf -
# Touch intl/plural.c to avoid regenerating it from intl/plural.y with
# recent versions of bison, which is subject to the following known bug.
# * https://sourceware.org/bugzilla/show_bug.cgi?id=22941
# * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92008
touch "binutils-$VERSION/intl/plural.c"
touch "binutils-$version/intl/plural.c"
# Apply binutils patchs for Vhex
echo "$TAG Apply Vhex patchs..."
cp -r "$_src/../../patches/binutils/$VERSION"/* ./binutils-"$VERSION"/
cp -r "$_src/../../patches/binutils/$version"/* ./binutils-"$version"/
# Create build folder
@ -188,8 +199,9 @@ mkdir build && cd build || exit 1
echo "$TAG Configuring binutils..."
$quiet "../binutils-$VERSION/configure" \
--prefix="$SYSROOT" \
utils_callcmd \
"../binutils-$version/configure" \
--prefix="$prefix_sysroot" \
--target='sh-elf-vhex' \
--program-prefix='sh-elf-vhex-' \
--with-multilib-list='m3,m4-nofpu' \
@ -203,8 +215,6 @@ $quiet "../binutils-$VERSION/configure" \
if [[ "$cache" == 'false' ]]
then
echo "$TAG Removing $ARCHIVE..."
rm -f "$ARCHIVE"
echo "$TAG Removing $archive..."
rm -f "$archive"
fi
exit 0

View File

@ -5,7 +5,7 @@
#---
function help() {
cat << OEF
cat << EOF
Bootstrap script used to install or uninstall the sh-elf-vhex compiler.
Usage $0 [options...]
@ -13,28 +13,16 @@ 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-install Installation (bin) prefix
--prefix-sysroot Sysroot (lib, header, ...) prefix
--prefix-clone Clone prefix
--uninstall Uninstall operation
Notes:
This script will use env variables:
VHEX_VERBOSE - verbose status
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_VERBOSE - false
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
This project will automatically install the vxLibc. You can use the
VERBOSE env var to enable the verbose mode without explicit the '--verbose'
option.
EOF
exit 0
}
@ -43,20 +31,23 @@ OEF
#---
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
verbose='false'
overwrite='false'
prefix_install=~/.local/bin
prefix_sysroot=~/.local/share/sh-elf-vhex/sysroot
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#*=};;
--verbose | -v) verbose=true;;
--prefix-install=*) prefix_install=${arg#*=};;
--prefix-sysroot=*) prefix_sysroot=${arg#*=};;
--prefix-clone=*) prefix_clone=${arg#*=};;
--uninstall) action='uninstall';;
--overwrite) overwrite='true';;
*)
echo "error: unreconized argument '$arg', giving up." >&2
echo "error: unrecognized argument '$arg', giving up." >&2
exit 1
esac
done
@ -65,38 +56,40 @@ done
# Preliminary check
#---
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'"
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
_src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "$_src/_utils.sh"
cd "$_src" || exit 1
source ./_utils.sh
VHEX_VERSION_GCC=$(utils_find_last_version "$_src/../patches/gcc")
VHEX_VERSION_BINUTILS=$(utils_find_last_version "$_src/../patches/binutils")
version_gcc=$(utils_find_last_version ../patches/gcc)
version_binutils=$(utils_find_last_version ../patches/binutils)
if [[ "$VHEX_VERBOSE" == 'true' ]]
if [[ "$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"
echo " - VHEX_PREFIX_SYSROOT = $VHEX_PREFIX_SYSROOT"
echo " - VHEX_PREFIX_CLONE = $VHEX_PREFIX_CLONE"
echo " - VHEX_VERBOSE = $verbose"
echo " - VHEX_VERSION_BINUTILS = $version_binutils"
echo " - VHEX_VERSION_GCC = $version_gcc"
echo " - VHEX_PREFIX_INSTALL = $prefix_install"
echo " - VHEX_PREFIX_SYSROOT = $prefix_sysroot"
echo " - VHEX_PREFIX_CLONE = $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"
echo " - GCC version: $version_gcc"
echo " - Binutils version: $version_binutils"
echo " - Clone directory: $prefix_clone"
echo " - Compliler install at: $prefix_install"
read -p 'Process ? [yN]: ' -r valid
else
read -p 'Uninstall the sh-elf-vhex compiler ? [yN]: ' -r valid
@ -106,46 +99,48 @@ if [[ "$valid" != 'y' ]]; then
exit 1
fi
[[ -d "$prefix_clone" ]] && rm -rf "$prefix_clone"
[[ "$verbose" == 'true' ]] && export VERBOSE=1
#---
# Perform install operation
#---
git clone \
utils_callcmd \
git \
clone \
--depth=1 \
https://github.com/YannMagnin/sh-elf-vhex.git \
"$VHEX_PREFIX_CLONE"
"$prefix_clone"
cd "$VHEX_PREFIX_CLONE" || exit 1
cd "$prefix_clone/scripts" || 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
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 \
|| success='false'
if [[ "$success" == 'true' ]]
then
echo 'Error during bootstraping operation' >&2
{
./binutils/configure.sh \
--prefix-sysroot="$prefix_sysroot" \
--version="$version_binutils" \
&& ./binutils/build.sh \
&& ./gcc/configure.sh \
--prefix-sysroot="$prefix_sysroot" \
--version="$version_gcc" \
&& ./gcc/build.sh \
&& ./_install.sh \
--prefix-sysroot="$prefix_sysroot" \
--prefix-install="$prefix_install"
} || {
echo 'Error during bootstraping operations' >&2
exit 1
fi
}
echo 'Successfully installed sh-elf-vhex !'
echo "Do not forget to export the binary path '$VHEX_PREFIX_INSTALL'"
echo "Do not forget to export the binary path '$prefix_install'"
else
./scripts/_uninstall.sh || success='false'
if [[ "$success" != 'true' ]]
then
echo 'Error during unstallation step, abord' >&2
{
./scripts/_uninstall.sh
} || {
echo 'Error during unstallation step, abort' >&2
exit 1
fi
}
echo 'Successfully uninstalled sh-elf-vhex'
fi

View File

@ -12,7 +12,6 @@ Usage $0 [options...]
Configurations:
-h, --help Display this help
--verbose Display extra information during the building step
EOF
exit 0
}
@ -31,27 +30,21 @@ for arg;
done
#---
# Building step
# @note:
# 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 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.
# Preliminary checks
#---
_src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$_src" || exit 1
source ../_utils.sh
TAG='<sh-elf-vhex-gcc>'
SYSROOT=$(utils_get_env 'VHEX_PREFIX_SYSROOT' 'sysroot')
if ! test -d ../../build/gcc || ! test -f ../../build/gcc/sysroot_info.txt
then
echo 'error: Are you sure to have built GCC ? it seems that' >&2
echo ' the build directory is missing...' >&2
exit 1
fi
prefix_sysroot=$(cat ../../build/gcc/sysroot_info.txt)
# Avoid rebuilds and error
if [[ -f ../../build/gcc/.fini ]]
then
@ -59,12 +52,6 @@ then
exit 0
fi
if [[ ! -d ../../build/gcc ]]
then
echo 'error: Are you sure to have built GCC ? it seems that' >&2
echo ' the build directory is missing...' >&2
exit 1
fi
cd ../../build/gcc/build || exit 1
@ -76,8 +63,9 @@ echo "$TAG Configuring GCC (stage 1)..."
# Configure GCC stage-1 (minimal build as possible for library)
$quiet ../gcc/configure \
--prefix="$SYSROOT" \
utils_callcmd \
../gcc/configure \
--prefix="$prefix_sysroot" \
--target='sh-elf-vhex' \
--program-prefix="sh-elf-vhex-" \
--with-multilib-list='m3,m4-nofpu' \
@ -93,11 +81,11 @@ $quiet ../gcc/configure \
echo "$TAG Compiling GCC (usually 10-20 minutes)..."
$quiet $make_cmd -j"$cores" all-gcc
utils_makecmd all-gcc
echo "$TAG Install GCC..."
$quiet $make_cmd -j"$cores" install-strip-gcc
utils_makecmd install-strip-gcc
#---
# Patch the C standar library
@ -105,17 +93,17 @@ $quiet $make_cmd -j"$cores" install-strip-gcc
# export binaries used to build OpenLibM and fxLibc
export PATH="$PATH:$SYSROOT/bin"
export PATH="$PATH:$prefix_sysroot/bin"
echo "$TAG Building Vhex's custom C standard library..."
$quiet \
utils_callcmd \
git clone https://github.com/YannMagnin/vxLibc.git --depth 1 ../../_vxlibc
../../_vxlibc/scripts/install.sh \
--prefix-sysroot="$SYSROOT/sh-elf-vhex/" \
--yes \
|| exit 1
../../_vxlibc/scripts/install.sh \
--prefix-sysroot="$prefix_sysroot/sh-elf-vhex/" \
--yes \
|| exit 1
#---
# Finish to build GCC
@ -123,39 +111,38 @@ $quiet \
echo "$TAG Compiling libgcc..."
$quiet $make_cmd -j"$cores" all-target-libgcc
utils_makecmd all-target-libgcc
echo "$TAG Install libgcc..."
$quiet $make_cmd -j"$cores" install-strip-target-libgcc
utils_makecmd install-strip-target-libgcc
echo "$TAG Compiling libssp..."
$quiet $make_cmd -j"$cores" all-target-libssp
utils_makecmd all-target-libssp
echo "$TAG Install libssp..."
$quiet $make_cmd -j"$cores" install-strip-target-libssp
utils_makecmd install-strip-target-libssp
echo "$TAG Compiling LTO plugin..."
$quiet $make_cmd -j"$cores" all-lto-plugin
utils_makecmd all-lto-plugin
echo "$TAG Install LTO plugin..."
$quiet $make_cmd -j"$cores" install-strip-lto-plugin
utils_makecmd install-strip-lto-plugin
echo "$TAG Compiling libsanitizer..."
$quiet $make_cmd -j"$cores" all-target-libsanitizer
utils_makecmd all-target-libsanitizer
echo "$TAG Install libsanitizer..."
$quiet $make_cmd -j"$cores" install-strip-target-libsanitizer
utils_makecmd install-strip-target-libsanitizer
#---
# Indicate that the build is finished
#---
touch ../.fini
exit 0

View File

@ -22,12 +22,18 @@ EOF
#---
cache=false
prefix_sysroot=
version=
verbose=
for arg
do case "$arg" in
--help | -h) help;;
--cache) cache=true;;
--help | -h) help;;
--verbose | -v) verbose=true;;
--cache) cache=true;;
--prefix-sysroot=*) prefix_sysroot=${arg#*=};;
--version=*) version=${arg#*=};;
*)
echo "error: unreconized argument '$arg', giving up." >&2
echo "error: unrecognized argument '$arg', giving up." >&2
exit 1
esac
done
@ -40,27 +46,32 @@ _src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$_src" || exit 1
source ../_utils.sh
VERSION=$(utils_get_env 'VHEX_VERSION_GCC' 'binutils')
SYSROOT=$(utils_get_env 'VHEX_PREFIX_SYSROOT' 'sysroot')
URL="https://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.xz"
ARCHIVE="/tmp/sh-elf-vhex/$(basename "$URL")"
TAG='<sh-elf-vhex-gcc>'
if [[ ! -d "../../patches/gcc/$version" ]]
then
echo "Binutils version '$version' not supported, abort" >&2
exit 1
fi
echo "$TAG Target gcc version -> $VERSION"
echo "$TAG Sysroot found -> $SYSROOT"
[[ "$verbose" == 'true' ]] && export VERBOSE=1
url="https://ftp.gnu.org/gnu/gcc/gcc-$version/gcc-$version.tar.xz"
archive="/tmp/sh-elf-vhex/$(basename "$url")"
echo "$TAG Target gcc version -> $version"
echo "$TAG Sysroot found -> $prefix_sysroot"
#---
# Avoid rebuilds of the same version
#---
gcc_bin="$SYSROOT/bin/sh-elf-vhex-gcc"
gcc_bin="$prefix_sysroot/bin/sh-elf-vhex-gcc"
if [[ -f "$gcc_bin" ]]
then
gcc_version=$($gcc_bin --version | head -n 1 | grep -Eo '[0-9.]+$')
if [[ "$gcc_version" == "$VERSION" ]]
if [[ "$gcc_version" == "$version" ]]
then
echo "$TAG Version $VERSION already installed, skipping rebuild"
echo "$TAG Version $version already installed, skipping rebuild"
mkdir -p ../../build/gcc/
touch ../../build/gcc/.fini
exit 0
@ -73,20 +84,18 @@ fi
# Download archive
#---
[[ "$cache" == 'false' && -f "$ARCHIVE" ]] && rm -f "$ARCHIVE"
mkdir -p "$(dirname "$ARCHIVE")"
if [[ -f "$ARCHIVE" ]]
mkdir -p "$(dirname "$archive")"
if [[ -f "$archive" ]]
then
echo "$TAG Found $ARCHIVE, skipping download"
echo "$TAG Found $archive, skipping download"
else
echo "$TAG Downloading $URL..."
echo "$TAG Downloading $url..."
if command -v curl >/dev/null 2>&1
then
curl "$URL" -o "$ARCHIVE"
curl "$url" -o "$archive"
elif command -v wget >/dev/null 2>&1
then
wget -q --show-progress "$URL" -O "$ARCHIVE"
wget -q --show-progress "$url" -O "$archive"
else
echo \
"$TAG error: no curl or wget; install one or download archive " \
@ -99,24 +108,29 @@ fi
# Extract archive (openBSD-compliant version)
#---
echo "$TAG Extracting $ARCHIVE..."
echo "$TAG Extracting $archive..."
mkdir -p ../../build/gcc && cd ../../build/gcc/ || exit 1
unxz -c < "$ARCHIVE" | tar -xf -
unxz -c < "$archive" | tar -xf -
#---
# Apply GCC patchs for Vhex
#---
echo "$TAG Apply Vhex patchs..."
cp -r "../../patches/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)
[[ -d ./gcc ]] && rm -rf ./gcc
mv "./gcc-$VERSION/" ./gcc
mv "./gcc-$version/" ./gcc
# also store the sysroot prefix to avoid different CLI between binutils and
# gcc
echo "$prefix_sysroot" > ./sysroot_info.txt
#---
# Install dependencies
@ -125,7 +139,7 @@ mv "./gcc-$VERSION/" ./gcc
echo "$TAG install dependencies..."
cd gcc || exit 1
$quiet ./contrib/download_prerequisites
utils_callcmd ./contrib/download_prerequisites
cd .. || exit 1
mkdir -p build
@ -136,6 +150,6 @@ mkdir -p build
if [[ "$cache" == 'false' ]]
then
echo "$TAG Removing $ARCHIVE..."
rm -f "$ARCHIVE"
echo "$TAG Removing $archive..."
rm -f "$archive"
fi