BuildSystem: Rewrite whole build system structure

Now you have to use script/build.sh for building and running banan-os
This commit is contained in:
2023-10-23 13:27:23 +03:00
parent f3d9da9549
commit ce87e0a605
14 changed files with 320 additions and 201 deletions

18
toolchain/Toolchain.txt Normal file
View File

@@ -0,0 +1,18 @@
if (NOT DEFINED ENV{BANAN_ARCH})
message(FATAL_ERROR "environment variable BANAN_ARCH not defined")
endif ()
set(BANAN_ARCH $ENV{BANAN_ARCH})
set(TOOLCHAIN_PREFIX ${CMAKE_SOURCE_DIR}/toolchain/local)
set(CMAKE_SYSTEM_NAME banan-os)
set(CMAKE_SYSTEM_PROCESSOR AMD64)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}/bin/${BANAN_ARCH}-banan_os-g++)
set(CMAKE_CXX_COMPILER_WORKS True)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}/bin/${BANAN_ARCH}-banan_os-gcc)
set(CMAKE_C_COMPILER_WORKS True)

View File

@@ -5,22 +5,23 @@ BINUTILS_VERSION="binutils-2.39"
GCC_VERSION="gcc-12.2.0"
GRUB_VERSION="grub-2.06"
cd $(dirname "$0")
if [[ -n $LIBSTDCPP ]]; then
cd build/${GCC_VERSION}/
make -j $(nproc) all-target-libstdc++-v3
make install-target-libstdc++-v3
exit 0
fi
if [[ -z $SYSROOT ]]; then
echo "You must set the SYSROOT environment variable" >&2
if [[ -z $BANAN_SYSROOT ]]; then
echo "You must set the BANAN_SYSROOT environment variable" >&2
exit 1
fi
if [[ -z $TOOLCHAIN_PREFIX ]]; then
echo "You must set the TOOLCHAIN_PREFIX environment variable" >&2
if [[ -z $BANAN_TOOLCHAIN_DIR ]]; then
echo "You must set the BANAN_TOOLCHAIN_DIR environment variable" >&2
exit 1
fi
if [[ -z $BANAN_TOOLCHAIN_PREFIX ]]; then
echo "You must set the BANAN_TOOLCHAIN_PREFIX environment variable" >&2
exit 1
fi
if [[ -z $BANAN_TOOLCHAIN_TRIPLE_PREFIX ]]; then
echo "You must set the BANAN_TOOLCHAIN_TRIPLE_PREFIX environment variable" >&2
exit 1
fi
@@ -29,12 +30,11 @@ if [[ -z $BANAN_ARCH ]]; then
exit 1
fi
TARGET="${BANAN_ARCH}-banan_os"
if [ ! -f ${TOOLCHAIN_PREFIX}/bin/${TARGET}-ld ]; then
build_binutils () {
echo "Building ${BINUTILS_VERSION}"
cd $BANAN_TOOLCHAIN_DIR
if [ ! -f ${BINUTILS_VERSION}.tar.xz ]; then
wget https://ftp.gnu.org/gnu/binutils/${BINUTILS_VERSION}.tar.xz
fi
@@ -45,26 +45,24 @@ if [ ! -f ${TOOLCHAIN_PREFIX}/bin/${TARGET}-ld ]; then
fi
mkdir -p build/${BINUTILS_VERSION}/
pushd build/${BINUTILS_VERSION}/
cd build/${BINUTILS_VERSION}/
../../${BINUTILS_VERSION}/configure \
--target="$TARGET" \
--prefix="$TOOLCHAIN_PREFIX" \
--with-sysroot="$SYSROOT" \
--target="$BANAN_TOOLCHAIN_TRIPLE_PREFIX" \
--prefix="$BANAN_TOOLCHAIN_PREFIX" \
--with-sysroot="$BANAN_SYSROOT" \
--disable-nls \
--disable-werror
make -j $(nproc)
make install
}
popd
fi
if [ ! -f ${TOOLCHAIN_PREFIX}/bin/${TARGET}-g++ ]; then
build_gcc () {
echo "Building ${GCC_VERSION}"
cd $BANAN_TOOLCHAIN_DIR
if [ ! -f ${GCC_VERSION}.tar.xz ]; then
wget https://ftp.gnu.org/gnu/gcc/${GCC_VERSION}/${GCC_VERSION}.tar.xz
fi
@@ -75,27 +73,25 @@ if [ ! -f ${TOOLCHAIN_PREFIX}/bin/${TARGET}-g++ ]; then
fi
mkdir -p build/${GCC_VERSION}/
pushd build/${GCC_VERSION}/
cd build/${GCC_VERSION}/
../../${GCC_VERSION}/configure \
--target="$TARGET" \
--prefix="$TOOLCHAIN_PREFIX" \
--with-sysroot="$SYSROOT" \
--target="$BANAN_TOOLCHAIN_TRIPLE_PREFIX" \
--prefix="$BANAN_TOOLCHAIN_PREFIX" \
--with-sysroot="$BANAN_SYSROOT" \
--disable-nls \
--enable-languages=c,c++
make -j $(nproc) all-gcc
make -j $(nproc) all-target-libgcc CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone'
make install-gcc install-target-libgcc
}
popd
fi
if [ ! -f ${TOOLCHAIN_PREFIX}/bin/grub-mkstandalone ]; then
build_grub () {
echo "Building ${GRUB_VERSION}"
cd $BANAN_TOOLCHAIN_DIR
if [ ! -f ${GRUB_VERSION}.tar.xz ]; then
wget https://ftp.gnu.org/gnu/grub/${GRUB_VERSION}.tar.xz
fi
@@ -105,17 +101,29 @@ if [ ! -f ${TOOLCHAIN_PREFIX}/bin/grub-mkstandalone ]; then
fi
mkdir -p build/${GRUB_VERSION}/
pushd build/${GRUB_VERSION}/
cd build/${GRUB_VERSION}/
../../${GRUB_VERSION}/configure \
--target="$BANAN_ARCH" \
--prefix="$TOOLCHAIN_PREFIX" \
--prefix="$BANAN_TOOLCHAIN_PREFIX" \
--with-platform="efi" \
--disable-werror
make -j $(nproc)
make install
}
popd
build_libstdcpp () {
cd build/${GCC_VERSION}/
make -j $(nproc) all-target-libstdc++-v3
make install-target-libstdc++-v3
}
if [[ "$1" == "libstdc++" ]]; then
build_libstdcpp
exit 0
fi
build_binutils
build_gcc
build_grub