From af8fa4014f816781832df87a69a1e081997ef3d8 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 20 May 2024 16:19:29 +0300 Subject: [PATCH] BuildSystem: Always download cmake instead of using host's If cmake was installed from snap, build system would cause an error because some libfakeroot GLIBC requirement. --- script/build.sh | 26 ++++---- script/check-requirements.sh | 61 ------------------- script/config.sh | 2 +- script/install-bootloader.sh | 6 +- toolchain/build.sh | 112 +++++++++++++++++++++++++++++------ 5 files changed, 108 insertions(+), 99 deletions(-) delete mode 100644 script/check-requirements.sh diff --git a/script/build.sh b/script/build.sh index 773b7eb5..3e8eae2f 100755 --- a/script/build.sh +++ b/script/build.sh @@ -6,11 +6,6 @@ source $BANAN_SCRIPT_DIR/config.sh FAKEROOT_FILE="$BANAN_BUILD_DIR/fakeroot-context" -if [[ -z $CMAKE_COMMAND ]]; then - echo "No usable cmake binary found" >&2 - exit 1 -fi - run_fakeroot() { fakeroot -i $FAKEROOT_FILE -s $FAKEROOT_FILE -- /bin/bash -c '$@' bash $@ } @@ -19,11 +14,21 @@ make_build_dir () { mkdir -p $BANAN_BUILD_DIR cd $BANAN_BUILD_DIR if ! [[ -f "build.ninja" ]]; then - $CMAKE_COMMAND --toolchain=$BANAN_TOOLCHAIN_DIR/Toolchain.txt -G Ninja $BANAN_ROOT_DIR + $BANAN_CMAKE --toolchain=$BANAN_TOOLCHAIN_DIR/Toolchain.txt -G Ninja $BANAN_ROOT_DIR fi } build_target () { + if ! [[ -f $BANAN_CMAKE ]]; then + echo "cmake not found, please re-run toolchain compilation script" + exit 1 + fi + + if ! type ninja &> /dev/null ; then + echo "ninja not found" >&2 + exit 1 + fi + make_build_dir if [[ $# -eq 0 ]]; then echo "No target provided" @@ -34,15 +39,6 @@ build_target () { } build_toolchain () { - if [[ -f $BANAN_TOOLCHAIN_PREFIX/bin/$BANAN_TOOLCHAIN_TRIPLE_PREFIX-gcc ]]; then - echo "You already seem to have a toolchain." - read -e -p "Do you want to rebuild it [y/N]? " choice - if ! [[ "$choice" == [Yy]* ]]; then - echo "Aborting toolchain rebuild" - exit 0 - fi - fi - $BANAN_TOOLCHAIN_DIR/build.sh } diff --git a/script/check-requirements.sh b/script/check-requirements.sh deleted file mode 100644 index 09975691..00000000 --- a/script/check-requirements.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -CMAKE_VERSION_REQUIRED="3.26" - -version_atleast() { - [ "$1" = "$(echo -e "$1\n$2" | sort -rV | head -n1)" ] -} - -download_cmake() { - read -e -p "Do you want to download it [y/N]? " choice - if ! [[ "$choice" == [Yy]* ]]; then - echo "Build requirements not met" >&2 - return 1 - fi - - CMAKE_FULL_NAME="cmake-3.26.6-linux-x86_64" - - mkdir -p $BANAN_BUILD_DIR/toolchain - mkdir -p $BANAN_TOOLCHAIN_PREFIX/bin - mkdir -p $BANAN_TOOLCHAIN_PREFIX/share - cd $BANAN_BUILD_DIR/toolchain - - if ! [[ -f $CMAKE_FULL_NAME.tar.gz ]]; then - wget https://cmake.org/files/v3.26/$CMAKE_FULL_NAME.tar.gz - fi - - if ! [[ -d $CMAKE_FULL_NAME ]]; then - tar xf $CMAKE_FULL_NAME.tar.gz - fi - - cp -r $CMAKE_FULL_NAME/bin/* $BANAN_TOOLCHAIN_PREFIX/bin/ - cp -r $CMAKE_FULL_NAME/share/* $BANAN_TOOLCHAIN_PREFIX/share/ - - export CMAKE_COMMAND="$BANAN_TOOLCHAIN_PREFIX/bin/cmake" -} - -if ! type ninja &> /dev/null ; then - echo "ninja not found" >&2 - return 1 -fi - -if [ -z "$CMAKE_COMMAND" ]; then - if [ -f $BANAN_TOOLCHAIN_PREFIX/bin/cmake ]; then - export CMAKE_COMMAND="$BANAN_TOOLCHAIN_PREFIX/bin/cmake" - else - export CMAKE_COMMAND=cmake - fi -fi - -if ! type $CMAKE_COMMAND &> /dev/null ; then - echo "You don't seem to have cmake installed" - download_cmake - return 0 -fi - -CMAKE_VERSION=$($CMAKE_COMMAND --version | head -n1 | cut -d' ' -f3) -if ! version_atleast "$CMAKE_VERSION" "$CMAKE_VERSION_REQUIRED" ; then - echo "Your cmake version ($CMAKE_VERSION) is less than the required $CMAKE_VERSION_REQUIRED" - download_cmake - return 0 -fi diff --git a/script/config.sh b/script/config.sh index 3739af40..64dfceae 100644 --- a/script/config.sh +++ b/script/config.sh @@ -30,4 +30,4 @@ if [[ -z $BANAN_BOOTLOADER ]]; then export BANAN_BOOTLOADER="BANAN" fi -source $BANAN_SCRIPT_DIR/check-requirements.sh +export BANAN_CMAKE=$BANAN_TOOLCHAIN_PREFIX/bin/cmake diff --git a/script/install-bootloader.sh b/script/install-bootloader.sh index 6255f873..2d37fa00 100755 --- a/script/install-bootloader.sh +++ b/script/install-bootloader.sh @@ -25,8 +25,8 @@ if [ -z $BANAN_ROOT_DIR ]; then exit 1 fi -if [ -z $CMAKE_COMMAND ]; then - echo "You must set the CMAKE_COMMAND environment variable" >&2 +if [ -z $BANAN_CMAKE ]; then + echo "You must set the BANAN_CMAKE environment variable" >&2 exit 1 fi @@ -77,7 +77,7 @@ install_banan_legacy() { if [ ! -d $INSTALLER_BUILD_DIR ]; then mkdir -p $INSTALLER_BUILD_DIR cd $INSTALLER_BUILD_DIR - $CMAKE_COMMAND -G Ninja ../.. + $BANAN_CMAKE -G Ninja ../.. fi cd $INSTALLER_BUILD_DIR diff --git a/toolchain/build.sh b/toolchain/build.sh index 52126cf4..90711f8a 100755 --- a/toolchain/build.sh +++ b/toolchain/build.sh @@ -10,6 +10,12 @@ GCC_TAR="$GCC_VERSION.tar.gz" GCC_URL="https://ftp.gnu.org/gnu/gcc/$GCC_VERSION/$GCC_TAR" GRUB_VERSION="grub-2.06" +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" if [[ -z $BANAN_SYSROOT ]]; then echo "You must set the BANAN_SYSROOT environment variable" >&2 @@ -123,17 +129,28 @@ build_gcc () { make install-target-libgcc } +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 + make $MAKE_JOBS all-target-libstdc++-v3 CFLAGS_FOR_TARGET="$XCFLAGS" + make install-target-libstdc++-v3 +} + build_grub () { echo "Building ${GRUB_VERSION}" cd $BANAN_BUILD_DIR/toolchain - if [ ! -f ${GRUB_VERSION}.tar.xz ]; then - wget https://ftp.gnu.org/gnu/grub/${GRUB_VERSION}.tar.xz + if [ ! -f $GRUB_TAR ]; then + wget $GRUB_URL fi if [ ! -d $GRUB_VERSION ]; then - tar xvf ${GRUB_VERSION}.tar.xz + tar xvf $GRUB_TAR fi cd $GRUB_VERSION @@ -149,38 +166,95 @@ build_grub () { make install } -build_libstdcpp () { - if ! [[ -d $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build-$BANAN_ARCH ]]; then - echo "You have to build gcc first" - exit 1 +build_cmake() { + echo "Downloading ${CMAKE_VERSION}" + + cd $BANAN_BUILD_DIR/toolchain + + if [ ! -f $CMAKE_TAR ]; then + wget $CMAKE_URL fi - cd $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build-$BANAN_ARCH - make $MAKE_JOBS all-target-libstdc++-v3 CFLAGS_FOR_TARGET="$XCFLAGS" - make install-target-libstdc++-v3 + 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/ } +BUILD_BINUTILS=1 +if [[ -f $BANAN_TOOLCHAIN_PREFIX/bin/$BANAN_TOOLCHAIN_TRIPLE_PREFIX-ld ]]; then + 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 +if [[ -f $BANAN_TOOLCHAIN_PREFIX/bin/$BANAN_TOOLCHAIN_TRIPLE_PREFIX-gcc ]]; then + 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 + +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 + # delete everything but toolchain mkdir -p $BANAN_BUILD_DIR find $BANAN_BUILD_DIR -mindepth 1 -maxdepth 1 ! -name toolchain -exec rm -r {} + # NOTE: we have to manually create initial sysroot with libc headers # since cmake cannot be invoked yet -echo "Creating dummy sysroot" mkdir -p $BANAN_SYSROOT/usr cp -r $BANAN_ROOT_DIR/libc/include $BANAN_SYSROOT/usr/include mkdir -p $BANAN_BUILD_DIR/toolchain -build_binutils -build_gcc -# Grub is only needed for UEFI (x86_64) -if [ $BANAN_ARCH = "x86_64" ]; then +if (($BUILD_BINUTILS)); then + build_binutils +fi + +if (($BUILD_GCC)); then + build_gcc +fi + +if (($BUILD_GRUB)); then build_grub fi -# delete sysroot and install libc -rm -r $BANAN_SYSROOT -$BANAN_SCRIPT_DIR/build.sh libc-install +if (($BUILD_CMAKE)); then + build_cmake +fi -build_libstdcpp +if (($BUILD_GCC)); then + # delete sysroot and install libc + rm -r $BANAN_SYSROOT + $BANAN_SCRIPT_DIR/build.sh libc-install + + build_libstdcpp +fi