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"
|
2023-10-30 11:02:57 +02:00
|
|
|
BINUTILS_GIT="https://sourceware.org/git/binutils-gdb.git"
|
|
|
|
BINUTILS_BRANCH="binutils-2_39"
|
|
|
|
|
2023-04-06 00:02:13 +03:00
|
|
|
GCC_VERSION="gcc-12.2.0"
|
2023-10-30 11:02:57 +02:00
|
|
|
GCC_GIT="https://gcc.gnu.org/git/gcc.git"
|
|
|
|
GCC_BRANCH="releases/$GCC_VERSION"
|
|
|
|
|
2023-10-16 01:37:12 +03:00
|
|
|
GRUB_VERSION="grub-2.06"
|
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
|
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
if [[ -z $BANAN_TOOLCHAIN_TRIPLE_PREFIX ]]; then
|
|
|
|
echo "You must set the BANAN_TOOLCHAIN_TRIPLE_PREFIX 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
|
|
|
|
|
2024-03-21 15:21:04 +02:00
|
|
|
if [ $BANAN_ARCH = "x86_64" ]; then
|
|
|
|
XCFLAGS="-g -O2 -mcmodel=large -mno-red-zone"
|
|
|
|
else
|
|
|
|
XCFLAGS="-g -O2"
|
|
|
|
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
|
2023-10-30 11:02:57 +02:00
|
|
|
git clone --single-branch --branch $BINUTILS_BRANCH $BINUTILS_GIT $BINUTILS_VERSION
|
|
|
|
cd $BINUTILS_VERSION
|
2023-12-28 20:16:36 +02:00
|
|
|
git apply $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 \
|
2023-10-23 13:27:23 +03:00
|
|
|
--target="$BANAN_TOOLCHAIN_TRIPLE_PREFIX" \
|
|
|
|
--prefix="$BANAN_TOOLCHAIN_PREFIX" \
|
|
|
|
--with-sysroot="$BANAN_SYSROOT" \
|
2023-10-30 11:02:57 +02:00
|
|
|
--disable-initfini-array \
|
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
|
2023-10-30 11:02:57 +02:00
|
|
|
git clone --single-branch --branch $GCC_BRANCH $GCC_GIT $GCC_VERSION
|
|
|
|
cd $GCC_VERSION
|
2023-12-28 20:16:36 +02:00
|
|
|
git apply $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 \
|
2023-10-23 13:27:23 +03:00
|
|
|
--target="$BANAN_TOOLCHAIN_TRIPLE_PREFIX" \
|
|
|
|
--prefix="$BANAN_TOOLCHAIN_PREFIX" \
|
|
|
|
--with-sysroot="$BANAN_SYSROOT" \
|
2023-10-30 11:02:57 +02:00
|
|
|
--disable-initfini-array \
|
2023-06-05 17:55:47 +03:00
|
|
|
--disable-nls \
|
2023-04-06 00:02:13 +03:00
|
|
|
--enable-languages=c,c++
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2023-10-16 01:37:12 +03:00
|
|
|
if [ ! -f ${GRUB_VERSION}.tar.xz ]; then
|
|
|
|
wget https://ftp.gnu.org/gnu/grub/${GRUB_VERSION}.tar.xz
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $GRUB_VERSION ]; then
|
|
|
|
tar xvf ${GRUB_VERSION}.tar.xz
|
|
|
|
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
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
build_libstdcpp () {
|
2024-03-21 15:21:04 +02:00
|
|
|
if ! [[ -d $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build-$BANAN_ARCH ]]; then
|
2023-10-24 16:48:46 +03:00
|
|
|
echo "You have to build gcc first"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-03-21 15:21:04 +02:00
|
|
|
cd $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build-$BANAN_ARCH
|
|
|
|
make $MAKE_JOBS all-target-libstdc++-v3 CFLAGS_FOR_TARGET="$XCFLAGS"
|
2023-10-23 13:27:23 +03:00
|
|
|
make install-target-libstdc++-v3
|
|
|
|
}
|
2023-10-16 01:37:12 +03:00
|
|
|
|
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
|
|
|
echo "Creating dummy sysroot"
|
|
|
|
mkdir -p $BANAN_SYSROOT/usr
|
|
|
|
cp -r $BANAN_ROOT_DIR/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
|
2023-10-23 13:27:23 +03:00
|
|
|
build_binutils
|
|
|
|
build_gcc
|
2024-03-21 15:21:04 +02:00
|
|
|
|
|
|
|
# Grub is only needed for UEFI (x86_64)
|
|
|
|
if [ $BANAN_ARCH = "x86_64" ]; then
|
|
|
|
build_grub
|
|
|
|
fi
|
2023-11-07 14:01:42 +02:00
|
|
|
|
2023-11-20 00:53:43 +02:00
|
|
|
# delete sysroot and install libc
|
|
|
|
rm -r $BANAN_SYSROOT
|
|
|
|
$BANAN_SCRIPT_DIR/build.sh libc-install
|
|
|
|
|
|
|
|
build_libstdcpp
|