2021-11-14 12:14:41 +01:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-14 12:14:41 +01:00
|
|
|
# Help screen
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2023-12-01 18:30:01 +01:00
|
|
|
|
|
|
|
function help() {
|
|
|
|
cat << EOF
|
2023-12-17 17:14:44 +01:00
|
|
|
Script for the configuration step of Vhex's binutils.
|
2021-11-14 12:14:41 +01:00
|
|
|
|
|
|
|
Usage $0 [options...]
|
|
|
|
|
|
|
|
Configurations:
|
|
|
|
-h, --help Display this help
|
2021-11-16 17:43:29 +01:00
|
|
|
--cache Keep the archive of GCC
|
2023-12-01 18:30:01 +01:00
|
|
|
EOF
|
2021-11-14 12:14:41 +01:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-16 17:43:29 +01:00
|
|
|
# Parse arguments
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-12-04 20:42:28 +01:00
|
|
|
cached='true'
|
2023-12-04 18:33:11 +01:00
|
|
|
prefix_sysroot=
|
|
|
|
version=
|
|
|
|
verbose=
|
2023-12-01 18:30:01 +01:00
|
|
|
for arg
|
|
|
|
do case "$arg" in
|
2023-12-04 18:33:11 +01:00
|
|
|
--help | -h) help;;
|
2023-12-04 20:42:28 +01:00
|
|
|
--verbose | -v) verbose='true';;
|
|
|
|
--no-cache) cached='true';;
|
2023-12-04 18:33:11 +01:00
|
|
|
--prefix-sysroot=*) prefix_sysroot=${arg#*=};;
|
|
|
|
--version=*) version=${arg#*=};;
|
2023-12-01 18:30:01 +01:00
|
|
|
*)
|
2023-12-04 18:33:11 +01:00
|
|
|
echo "error: unrecognized argument '$arg', giving up." >&2
|
2023-12-01 18:30:01 +01:00
|
|
|
exit 1
|
|
|
|
esac
|
2022-07-30 22:27:22 +02:00
|
|
|
done
|
2021-11-16 17:43:29 +01:00
|
|
|
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-14 12:14:41 +01:00
|
|
|
# Configuration part
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-12-02 16:27:21 +01:00
|
|
|
_src=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
2023-12-02 19:04:31 +01:00
|
|
|
cd "$_src" || exit 1
|
|
|
|
source ../_utils.sh
|
2023-12-01 18:30:01 +01:00
|
|
|
|
2023-12-04 18:33:11 +01:00
|
|
|
if [[ ! -d "../../patches/gcc/$version" ]]
|
|
|
|
then
|
|
|
|
echo "Binutils version '$version' not supported, abort" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
[[ "$verbose" == 'true' ]] && export VERBOSE=1
|
|
|
|
|
|
|
|
echo "$TAG Target gcc version -> $version"
|
|
|
|
echo "$TAG Sysroot found -> $prefix_sysroot"
|
2023-12-02 19:04:31 +01:00
|
|
|
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2023-12-17 11:06:14 +01:00
|
|
|
# Avoid rebuilding of the same version
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-12-04 18:33:11 +01:00
|
|
|
gcc_bin="$prefix_sysroot/bin/sh-elf-vhex-gcc"
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-12-01 18:30:01 +01:00
|
|
|
if [[ -f "$gcc_bin" ]]
|
|
|
|
then
|
|
|
|
gcc_version=$($gcc_bin --version | head -n 1 | grep -Eo '[0-9.]+$')
|
2023-12-04 18:33:11 +01:00
|
|
|
if [[ "$gcc_version" == "$version" ]]
|
2023-12-01 18:30:01 +01:00
|
|
|
then
|
2023-12-17 11:06:14 +01:00
|
|
|
echo "$TAG Version $version already installed, skipping rebuilding"
|
2023-12-04 20:42:28 +01:00
|
|
|
mkdir -p ../../_build/gcc/
|
|
|
|
touch ../../_build/gcc/.fini
|
2021-11-14 12:14:41 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
2023-12-04 20:42:28 +01:00
|
|
|
[[ -d ../../_build/gcc/build ]] && rm -rf ../../_build/gcc/build
|
|
|
|
[[ -f ../../_build/gcc/.fini ]] && rm -f ../../_build/gcc/.fini
|
2021-11-14 12:14:41 +01:00
|
|
|
fi
|
|
|
|
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-14 12:14:41 +01:00
|
|
|
# Download archive
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-12-04 20:42:28 +01:00
|
|
|
utils_archive_download \
|
|
|
|
"https://ftp.gnu.org/gnu/gcc/gcc-$version/gcc-$version.tar.xz" \
|
|
|
|
../../_build/gcc \
|
|
|
|
"$cached"
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2023-12-04 20:42:28 +01:00
|
|
|
# Patch sources
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-12-04 20:42:28 +01:00
|
|
|
cd ../../_build/gcc || exit 1
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-12-17 11:06:14 +01:00
|
|
|
echo "$TAG Apply Vhex patches..."
|
2023-12-04 20:42:28 +01:00
|
|
|
cp -r "../../patches/gcc/$version"/* ./archive/
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-12-04 20:42:28 +01:00
|
|
|
# Store the sysroot prefix to avoid different CLI between binutils and gcc
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-12-04 20:42:28 +01:00
|
|
|
echo "$prefix_sysroot" > ./sysroot_info.txt
|
2023-12-04 18:33:11 +01:00
|
|
|
|
2023-12-04 20:42:28 +01:00
|
|
|
# Create build folder
|
2023-12-04 18:33:11 +01:00
|
|
|
|
2023-12-04 20:42:28 +01:00
|
|
|
[[ -d "./build" ]] && rm -rf build
|
|
|
|
mkdir ./build
|
2021-11-14 12:14:41 +01:00
|
|
|
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-17 21:12:42 +01:00
|
|
|
# Install dependencies
|
2023-01-08 16:59:05 +01:00
|
|
|
#---
|
2021-11-17 21:12:42 +01:00
|
|
|
|
2023-01-15 11:47:50 +01:00
|
|
|
echo "$TAG install dependencies..."
|
|
|
|
|
2023-12-04 20:42:28 +01:00
|
|
|
cd ./archive || exit 1
|
2023-12-16 18:25:13 +01:00
|
|
|
if ! utils_warn_callcmd ./contrib/download_prerequisites
|
|
|
|
then
|
2023-12-18 17:56:20 +01:00
|
|
|
echo -en \
|
|
|
|
'The installation of GCC'\''s prerequisites has failed\n' \
|
|
|
|
'Do you want to continue the installation ? [yN]: '
|
|
|
|
read -r valid < /dev/tty
|
2023-12-16 18:25:13 +01:00
|
|
|
if [[ "$valid" != 'y' ]]; then
|
|
|
|
echo 'Operation aborted o(x_x)o'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|