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"
|
|
|
|
GCC_VERSION="gcc-12.2.0"
|
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-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-10-24 16:48:46 +03:00
|
|
|
enter_clean_build () {
|
|
|
|
rm -rf build
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
}
|
|
|
|
|
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 [ ! -f ${BINUTILS_VERSION}.tar.xz ]; then
|
|
|
|
wget https://ftp.gnu.org/gnu/binutils/${BINUTILS_VERSION}.tar.xz
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $BINUTILS_VERSION ]; then
|
|
|
|
tar xvf ${BINUTILS_VERSION}.tar.xz
|
2023-10-24 16:48:46 +03:00
|
|
|
patch -s -p0 < $BANAN_TOOLCHAIN_DIR/${BINUTILS_VERSION}.patch
|
2023-04-06 00:02:13 +03:00
|
|
|
fi
|
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
cd $BINUTILS_VERSION
|
|
|
|
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-06-05 17:55:47 +03:00
|
|
|
--disable-nls \
|
2023-04-06 00:02:13 +03:00
|
|
|
--disable-werror
|
|
|
|
|
|
|
|
make -j $(nproc)
|
|
|
|
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 [ ! -f ${GCC_VERSION}.tar.xz ]; then
|
|
|
|
wget https://ftp.gnu.org/gnu/gcc/${GCC_VERSION}/${GCC_VERSION}.tar.xz
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $GCC_VERSION ]; then
|
|
|
|
tar xvf ${GCC_VERSION}.tar.xz
|
2023-10-24 16:48:46 +03:00
|
|
|
patch -s -p0 < $BANAN_TOOLCHAIN_DIR/${GCC_VERSION}.patch
|
2023-04-06 00:02:13 +03:00
|
|
|
fi
|
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
cd ${GCC_VERSION}
|
|
|
|
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-06-05 17:55:47 +03:00
|
|
|
--disable-nls \
|
2023-04-06 00:02:13 +03:00
|
|
|
--enable-languages=c,c++
|
|
|
|
|
2023-05-30 07:59:41 +03:00
|
|
|
make -j $(nproc) all-gcc
|
|
|
|
make -j $(nproc) all-target-libgcc CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone'
|
2023-04-06 00:02:13 +03:00
|
|
|
make install-gcc 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
|
|
|
|
|
|
|
|
make -j $(nproc)
|
|
|
|
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 () {
|
2023-10-24 16:48:46 +03:00
|
|
|
if ! [[ -d $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build ]]; then
|
|
|
|
echo "You have to build gcc first"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build
|
2023-10-23 13:27:23 +03:00
|
|
|
make -j $(nproc) all-target-libstdc++-v3
|
|
|
|
make install-target-libstdc++-v3
|
|
|
|
}
|
2023-10-16 01:37:12 +03:00
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
if [[ $# -ge 1 ]]; then
|
|
|
|
if [[ "$1" == "libstdc++" ]]; then
|
|
|
|
build_libstdcpp
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "unrecognized arguments $@"
|
|
|
|
exit 1
|
2023-04-06 00:02:13 +03:00
|
|
|
fi
|
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
|
|
|
|
echo "Syncing sysroot headers"
|
|
|
|
mkdir -p $BANAN_SYSROOT
|
|
|
|
sudo mkdir -p $BANAN_SYSROOT/usr/include
|
|
|
|
sudo rsync -a $BANAN_ROOT_DIR/libc/include/ $BANAN_SYSROOT/usr/include/
|
|
|
|
|
|
|
|
mkdir -p $BANAN_BUILD_DIR/toolchain
|
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
build_binutils
|
|
|
|
build_gcc
|
|
|
|
build_grub
|