2023-06-02 18:40:24 +03:00
|
|
|
#!/bin/bash
|
2023-04-06 00:02:13 +03:00
|
|
|
set -e
|
|
|
|
|
|
|
|
BINUTILS_VERSION="binutils-2.39"
|
2024-04-22 19:53:49 +03:00
|
|
|
BINUTILS_TAR="$BINUTILS_VERSION.tar.gz"
|
|
|
|
BINUTILS_URL="https://ftp.gnu.org/gnu/binutils/$BINUTILS_TAR"
|
2023-10-30 11:02:57 +02:00
|
|
|
|
2023-04-06 00:02:13 +03:00
|
|
|
GCC_VERSION="gcc-12.2.0"
|
2024-04-22 19:53:49 +03:00
|
|
|
GCC_TAR="$GCC_VERSION.tar.gz"
|
|
|
|
GCC_URL="https://ftp.gnu.org/gnu/gcc/$GCC_VERSION/$GCC_TAR"
|
2023-10-30 11:02:57 +02:00
|
|
|
|
2023-10-16 01:37:12 +03:00
|
|
|
GRUB_VERSION="grub-2.06"
|
2024-05-20 16:19:29 +03:00
|
|
|
GRUB_TAR="$GRUB_VERSION.tar.xz"
|
|
|
|
GRUB_URL="https://ftp.gnu.org/gnu/grub/$GRUB_TAR"
|
|
|
|
|
|
|
|
CMAKE_VERSION="cmake-3.26.6-linux-x86_64"
|
|
|
|
CMAKE_TAR="$CMAKE_VERSION.tar.gz"
|
|
|
|
CMAKE_URL="https://cmake.org/files/v3.26/$CMAKE_TAR"
|
2023-04-06 00:02:13 +03:00
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
if [[ -z $BANAN_SYSROOT ]]; then
|
|
|
|
echo "You must set the BANAN_SYSROOT environment variable" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-04-06 00:02:13 +03:00
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
if [[ -z $BANAN_ROOT_DIR ]]; then
|
|
|
|
echo "You must set the BANAN_ROOT_DIR environment variable" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $BANAN_BUILD_DIR ]]; then
|
|
|
|
echo "You must set the BANAN_BUILD_DIR environment variable" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-11-20 00:53:43 +02:00
|
|
|
if [[ -z $BANAN_SCRIPT_DIR ]]; then
|
|
|
|
echo "You must set the BANAN_SCRIPT_DIR environment variable" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
if [[ -z $BANAN_TOOLCHAIN_DIR ]]; then
|
|
|
|
echo "You must set the BANAN_TOOLCHAIN_DIR environment variable" >&2
|
|
|
|
exit 1
|
2023-06-02 18:39:42 +03:00
|
|
|
fi
|
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
if [[ -z $BANAN_TOOLCHAIN_PREFIX ]]; then
|
|
|
|
echo "You must set the BANAN_TOOLCHAIN_PREFIX environment variable" >&2
|
2023-04-06 00:02:13 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-09 17:08:07 +03:00
|
|
|
if [[ -z $BANAN_TOOLCHAIN_TRIPLE ]]; then
|
|
|
|
echo "You must set the BANAN_TOOLCHAIN_TRIPLE environment variable" >&2
|
2023-04-06 00:02:13 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-10-20 04:59:08 +03:00
|
|
|
if [[ -z $BANAN_ARCH ]]; then
|
|
|
|
echo "You must set the BANAN_ARCH environment variable" >&2
|
2023-04-06 00:02:13 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-11-20 00:53:43 +02:00
|
|
|
if [[ -z ${MAKE_JOBS:x} ]]; then
|
|
|
|
MAKE_JOBS="-j$(nproc)"
|
|
|
|
fi
|
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
enter_clean_build () {
|
2024-03-21 15:21:04 +02:00
|
|
|
rm -rf build-$BANAN_ARCH
|
|
|
|
mkdir build-$BANAN_ARCH
|
|
|
|
cd build-$BANAN_ARCH
|
2023-10-24 16:48:46 +03:00
|
|
|
}
|
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
build_binutils () {
|
2023-04-06 00:02:13 +03:00
|
|
|
echo "Building ${BINUTILS_VERSION}"
|
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
cd $BANAN_BUILD_DIR/toolchain
|
2023-10-23 13:27:23 +03:00
|
|
|
|
2023-04-06 00:02:13 +03:00
|
|
|
if [ ! -d $BINUTILS_VERSION ]; then
|
2024-08-27 17:36:09 +03:00
|
|
|
if [ ! -f $BINUTILS_TAR ]; then
|
|
|
|
wget $BINUTILS_URL
|
|
|
|
fi
|
2024-04-22 19:53:49 +03:00
|
|
|
tar xf $BINUTILS_TAR
|
2024-08-27 17:36:09 +03:00
|
|
|
patch -ruN -p1 -d "$BINUTILS_VERSION" < "$BANAN_TOOLCHAIN_DIR/$BINUTILS_VERSION.patch"
|
2023-04-06 00:02:13 +03:00
|
|
|
fi
|
|
|
|
|
2023-10-30 11:02:57 +02:00
|
|
|
cd $BANAN_BUILD_DIR/toolchain/$BINUTILS_VERSION
|
2023-10-24 16:48:46 +03:00
|
|
|
enter_clean_build
|
2023-04-06 00:02:13 +03:00
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
../configure \
|
2024-08-09 17:08:07 +03:00
|
|
|
--target="$BANAN_TOOLCHAIN_TRIPLE" \
|
2023-10-23 13:27:23 +03:00
|
|
|
--prefix="$BANAN_TOOLCHAIN_PREFIX" \
|
|
|
|
--with-sysroot="$BANAN_SYSROOT" \
|
2024-08-26 14:04:58 +03:00
|
|
|
--enable-initfini-array \
|
2024-08-27 17:36:09 +03:00
|
|
|
--enable-shared \
|
|
|
|
--enable-lto \
|
2023-06-05 17:55:47 +03:00
|
|
|
--disable-nls \
|
2023-04-06 00:02:13 +03:00
|
|
|
--disable-werror
|
|
|
|
|
2023-11-20 00:53:43 +02:00
|
|
|
make $MAKE_JOBS
|
2023-04-06 00:02:13 +03:00
|
|
|
make install
|
2023-10-23 13:27:23 +03:00
|
|
|
}
|
2023-04-06 00:02:13 +03:00
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
build_gcc () {
|
2023-04-06 00:02:13 +03:00
|
|
|
echo "Building ${GCC_VERSION}"
|
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
cd $BANAN_BUILD_DIR/toolchain
|
2023-10-23 13:27:23 +03:00
|
|
|
|
2023-04-06 00:02:13 +03:00
|
|
|
if [ ! -d $GCC_VERSION ]; then
|
2024-08-27 17:36:09 +03:00
|
|
|
if [ ! -f $GCC_TAR ]; then
|
|
|
|
wget $GCC_URL
|
|
|
|
fi
|
2024-04-22 19:53:49 +03:00
|
|
|
tar xf $GCC_TAR
|
2024-08-27 17:36:09 +03:00
|
|
|
patch -ruN -p1 -d "$GCC_VERSION" < "$BANAN_TOOLCHAIN_DIR/$GCC_VERSION.patch"
|
2023-04-06 00:02:13 +03:00
|
|
|
fi
|
|
|
|
|
2023-10-30 11:02:57 +02:00
|
|
|
cd $BANAN_BUILD_DIR/toolchain/$GCC_VERSION
|
2023-10-24 16:48:46 +03:00
|
|
|
enter_clean_build
|
2023-04-06 00:02:13 +03:00
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
../configure \
|
2024-08-09 17:08:07 +03:00
|
|
|
--target="$BANAN_TOOLCHAIN_TRIPLE" \
|
2023-10-23 13:27:23 +03:00
|
|
|
--prefix="$BANAN_TOOLCHAIN_PREFIX" \
|
|
|
|
--with-sysroot="$BANAN_SYSROOT" \
|
2024-08-26 14:04:58 +03:00
|
|
|
--enable-initfini-array \
|
2024-08-27 17:36:09 +03:00
|
|
|
--enable-shared \
|
|
|
|
--enable-lto \
|
2023-06-05 17:55:47 +03:00
|
|
|
--disable-nls \
|
2023-04-06 00:02:13 +03:00
|
|
|
--enable-languages=c,c++
|
|
|
|
|
2024-09-05 12:54:22 +03:00
|
|
|
XCFLAGS=""
|
|
|
|
if [ $BANAN_ARCH = "x86_64" ]; then
|
|
|
|
XCFLAGS="-mcmodel=large -mno-red-zone"
|
|
|
|
fi
|
|
|
|
|
2023-11-20 00:53:43 +02:00
|
|
|
make $MAKE_JOBS all-gcc
|
2024-03-21 15:21:04 +02:00
|
|
|
make $MAKE_JOBS all-target-libgcc CFLAGS_FOR_TARGET="$XCFLAGS"
|
2023-11-20 00:53:43 +02:00
|
|
|
make install-gcc
|
|
|
|
make install-target-libgcc
|
2023-10-23 13:27:23 +03:00
|
|
|
}
|
2023-04-06 00:02:13 +03:00
|
|
|
|
2024-05-20 16:19:29 +03:00
|
|
|
build_libstdcpp () {
|
|
|
|
if ! [[ -d $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build-$BANAN_ARCH ]]; then
|
|
|
|
echo "You have to build gcc first"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build-$BANAN_ARCH
|
2024-09-05 12:54:22 +03:00
|
|
|
make $MAKE_JOBS all-target-libstdc++-v3
|
2024-05-20 16:19:29 +03:00
|
|
|
make install-target-libstdc++-v3
|
|
|
|
}
|
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
build_grub () {
|
2023-10-16 01:37:12 +03:00
|
|
|
echo "Building ${GRUB_VERSION}"
|
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
cd $BANAN_BUILD_DIR/toolchain
|
2023-10-23 13:27:23 +03:00
|
|
|
|
2024-05-20 16:19:29 +03:00
|
|
|
if [ ! -f $GRUB_TAR ]; then
|
|
|
|
wget $GRUB_URL
|
2023-10-16 01:37:12 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $GRUB_VERSION ]; then
|
2024-05-20 16:19:29 +03:00
|
|
|
tar xvf $GRUB_TAR
|
2023-10-16 01:37:12 +03:00
|
|
|
fi
|
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
cd $GRUB_VERSION
|
|
|
|
enter_clean_build
|
2023-10-16 01:37:12 +03:00
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
../configure \
|
2023-10-20 04:59:08 +03:00
|
|
|
--target="$BANAN_ARCH" \
|
2023-10-23 13:27:23 +03:00
|
|
|
--prefix="$BANAN_TOOLCHAIN_PREFIX" \
|
2023-10-16 01:37:12 +03:00
|
|
|
--with-platform="efi" \
|
|
|
|
--disable-werror
|
2024-01-24 14:43:46 +02:00
|
|
|
|
2023-11-20 00:53:43 +02:00
|
|
|
make $MAKE_JOBS
|
2023-10-16 01:37:12 +03:00
|
|
|
make install
|
2023-10-23 13:27:23 +03:00
|
|
|
}
|
2023-10-16 01:37:12 +03:00
|
|
|
|
2024-05-20 16:19:29 +03:00
|
|
|
build_cmake() {
|
|
|
|
echo "Downloading ${CMAKE_VERSION}"
|
|
|
|
|
|
|
|
cd $BANAN_BUILD_DIR/toolchain
|
|
|
|
|
|
|
|
if [ ! -f $CMAKE_TAR ]; then
|
|
|
|
wget $CMAKE_URL
|
2023-10-24 16:48:46 +03:00
|
|
|
fi
|
|
|
|
|
2024-05-20 16:19:29 +03:00
|
|
|
if [ ! -d $CMAKE_VERSION ]; then
|
|
|
|
tar xvf $CMAKE_TAR
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd $CMAKE_VERSION
|
|
|
|
|
|
|
|
mkdir -p $BANAN_TOOLCHAIN_PREFIX/bin
|
|
|
|
mkdir -p $BANAN_TOOLCHAIN_PREFIX/share
|
|
|
|
|
|
|
|
cp -r ./bin/* $BANAN_TOOLCHAIN_PREFIX/bin/
|
|
|
|
cp -r ./share/* $BANAN_TOOLCHAIN_PREFIX/share/
|
2023-10-23 13:27:23 +03:00
|
|
|
}
|
2023-10-16 01:37:12 +03:00
|
|
|
|
2024-05-20 16:19:29 +03:00
|
|
|
BUILD_BINUTILS=1
|
2024-08-09 17:08:07 +03:00
|
|
|
if [[ -f $BANAN_TOOLCHAIN_PREFIX/bin/$BANAN_TOOLCHAIN_TRIPLE-ld ]]; then
|
2024-05-20 16:19:29 +03:00
|
|
|
echo "You already seem to have a binutils installed."
|
|
|
|
read -e -p "Do you want to rebuild it [y/N]? " choice
|
|
|
|
if ! [[ "$choice" == [Yy]* ]]; then
|
|
|
|
BUILD_BINUTILS=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
BUILD_GCC=1
|
2024-08-09 17:08:07 +03:00
|
|
|
if [[ -f $BANAN_TOOLCHAIN_PREFIX/bin/$BANAN_TOOLCHAIN_TRIPLE-gcc ]]; then
|
2024-05-20 16:19:29 +03:00
|
|
|
echo "You already seem to have a gcc installed."
|
|
|
|
read -e -p "Do you want to rebuild it [y/N]? " choice
|
|
|
|
if ! [[ "$choice" == [Yy]* ]]; then
|
|
|
|
BUILD_GCC=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-05-29 19:12:15 +03:00
|
|
|
BUILD_LIBSTDCPP=$BUILD_GCC
|
|
|
|
if ! (($BUILD_LIBSTDCPP)); then
|
|
|
|
read -e -p "Do you want to rebuild libstdc++ [y/N]? " choice
|
|
|
|
if [[ "$choice" == [Yy]* ]]; then
|
|
|
|
BUILD_LIBSTDCPP=1
|
|
|
|
fi
|
|
|
|
fi
|
2024-05-25 19:17:13 +03:00
|
|
|
|
2024-05-20 16:19:29 +03:00
|
|
|
BUILD_GRUB=1
|
|
|
|
if [[ -f $BANAN_TOOLCHAIN_PREFIX/bin/grub-mkstandalone ]]; then
|
|
|
|
echo "You already seem to have a grub installed."
|
|
|
|
read -e -p "Do you want to rebuild it [y/N]? " choice
|
|
|
|
if ! [[ "$choice" == [Yy]* ]]; then
|
|
|
|
BUILD_GRUB=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
BUILD_CMAKE=1
|
|
|
|
if [[ -f $BANAN_TOOLCHAIN_PREFIX/bin/cmake ]]; then
|
|
|
|
echo "You already seem to have a cmake installed."
|
|
|
|
read -e -p "Do you want to rebuild it [y/N]? " choice
|
|
|
|
if ! [[ "$choice" == [Yy]* ]]; then
|
|
|
|
BUILD_CMAKE=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-11-20 00:53:43 +02:00
|
|
|
# delete everything but toolchain
|
2023-12-27 12:36:40 +02:00
|
|
|
mkdir -p $BANAN_BUILD_DIR
|
2023-11-20 00:53:43 +02:00
|
|
|
find $BANAN_BUILD_DIR -mindepth 1 -maxdepth 1 ! -name toolchain -exec rm -r {} +
|
2023-10-23 13:27:23 +03:00
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
# NOTE: we have to manually create initial sysroot with libc headers
|
|
|
|
# since cmake cannot be invoked yet
|
2023-11-07 14:01:42 +02:00
|
|
|
mkdir -p $BANAN_SYSROOT/usr
|
2024-06-20 14:32:05 +03:00
|
|
|
cp -r $BANAN_ROOT_DIR/userspace/libraries/LibC/include $BANAN_SYSROOT/usr/include
|
2023-10-24 16:48:46 +03:00
|
|
|
|
2023-11-07 14:01:42 +02:00
|
|
|
mkdir -p $BANAN_BUILD_DIR/toolchain
|
2024-03-21 15:21:04 +02:00
|
|
|
|
2024-05-20 16:19:29 +03:00
|
|
|
if (($BUILD_BINUTILS)); then
|
|
|
|
build_binutils
|
|
|
|
fi
|
|
|
|
|
|
|
|
if (($BUILD_GCC)); then
|
|
|
|
build_gcc
|
|
|
|
fi
|
|
|
|
|
|
|
|
if (($BUILD_GRUB)); then
|
2024-03-21 15:21:04 +02:00
|
|
|
build_grub
|
|
|
|
fi
|
2023-11-07 14:01:42 +02:00
|
|
|
|
2024-05-20 16:19:29 +03:00
|
|
|
if (($BUILD_CMAKE)); then
|
|
|
|
build_cmake
|
|
|
|
fi
|
2023-11-20 00:53:43 +02:00
|
|
|
|
2024-05-25 19:17:13 +03:00
|
|
|
if (($BUILD_LIBSTDCPP)); then
|
2024-05-20 16:19:29 +03:00
|
|
|
# delete sysroot and install libc
|
|
|
|
rm -r $BANAN_SYSROOT
|
2024-09-05 12:54:22 +03:00
|
|
|
$BANAN_SCRIPT_DIR/build.sh libc-static
|
|
|
|
$BANAN_SCRIPT_DIR/build.sh libc-shared
|
2024-06-20 14:32:05 +03:00
|
|
|
$BANAN_SCRIPT_DIR/build.sh install
|
2024-05-20 16:19:29 +03:00
|
|
|
|
|
|
|
build_libstdcpp
|
|
|
|
fi
|
2024-09-17 22:30:40 +03:00
|
|
|
|
|
|
|
find "$BANAN_TOOLCHAIN_PREFIX" -type f -executable -exec strip --strip-unneeded {} + 2>/dev/null
|