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:
Bananymous 2023-10-23 13:27:23 +03:00
parent 5bfeb9f3ca
commit df69612bb1
14 changed files with 320 additions and 201 deletions

View File

@ -1,35 +1,13 @@
cmake_minimum_required(VERSION 3.26)
if(DEFINED ENV{BANAN_ARCH})
set(BANAN_ARCH $ENV{BANAN_ARCH})
else()
set(BANAN_ARCH x86_64)
endif()
set(TOOLCHAIN_PREFIX ${CMAKE_SOURCE_DIR}/toolchain/local)
if(EXISTS ${TOOLCHAIN_PREFIX}/bin/${BANAN_ARCH}-banan_os-g++)
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)
endif()
if(DEFINED QEMU_ACCEL)
set(QEMU_ACCEL -accel ${QEMU_ACCEL})
endif()
if(DEFINED UEFI_BOOT)
set(UEFI_BOOT 1)
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "banan-os")
message(FATAL_ERROR "CMAKE_SYSTEM_NAME is not banan-os")
endif ()
add_compile_options(-mno-sse -mno-sse2)
add_compile_definitions(__enable_sse=0)
project(banan-os CXX)
project(banan-os CXX C ASM)
set(BANAN_BASE_SYSROOT ${CMAKE_SOURCE_DIR}/base-sysroot.tar.gz)
set(BANAN_SYSROOT ${CMAKE_BINARY_DIR}/sysroot)
@ -37,15 +15,6 @@ set(BANAN_INCLUDE ${BANAN_SYSROOT}/usr/include)
set(BANAN_LIB ${BANAN_SYSROOT}/usr/lib)
set(BANAN_BIN ${BANAN_SYSROOT}/usr/bin)
set(BANAN_BOOT ${BANAN_SYSROOT}/boot)
set(DISK_IMAGE_PATH ${CMAKE_BINARY_DIR}/banan-os.img)
set(BANAN_SCRIPT_ENV
BANAN_ARCH="${BANAN_ARCH}"
DISK_IMAGE_PATH="${DISK_IMAGE_PATH}"
SYSROOT="${BANAN_SYSROOT}"
TOOLCHAIN_PREFIX="${TOOLCHAIN_PREFIX}"
UEFI_BOOT="${UEFI_BOOT}"
)
add_subdirectory(kernel)
add_subdirectory(BAN)
@ -66,63 +35,10 @@ add_custom_target(headers
DEPENDS libelf-headers
)
add_custom_target(toolchain
COMMAND ${CMAKE_COMMAND} -E env ${BANAN_SCRIPT_ENV} ${CMAKE_SOURCE_DIR}/toolchain/build.sh
DEPENDS headers
USES_TERMINAL
)
add_custom_target(libstdc++
COMMAND ${CMAKE_COMMAND} -E env LIBSTDCPP="1" ${CMAKE_SOURCE_DIR}/toolchain/build.sh
DEPENDS libc-install
USES_TERMINAL
)
add_custom_target(image
COMMAND ${CMAKE_COMMAND} -E env ${BANAN_SCRIPT_ENV} ${CMAKE_SOURCE_DIR}/image.sh
add_custom_target(install-sysroot
DEPENDS kernel-install
DEPENDS ban-install
DEPENDS libc-install
DEPENDS userspace-install
DEPENDS libelf-install
USES_TERMINAL
)
add_custom_target(image-full
COMMAND ${CMAKE_COMMAND} -E env ${BANAN_SCRIPT_ENV} ${CMAKE_SOURCE_DIR}/image-full.sh
DEPENDS kernel-install
DEPENDS ban-install
DEPENDS libc-install
DEPENDS userspace-install
DEPENDS libelf-install
USES_TERMINAL
)
add_custom_target(check-fs
COMMAND ${CMAKE_COMMAND} -E env ${BANAN_SCRIPT_ENV} ${CMAKE_SOURCE_DIR}/check-fs.sh
USES_TERMINAL
)
add_custom_target(qemu
COMMAND ${CMAKE_COMMAND} -E env ${BANAN_SCRIPT_ENV} ${CMAKE_SOURCE_DIR}/qemu.sh -serial stdio ${QEMU_ACCEL}
DEPENDS image
USES_TERMINAL
)
add_custom_target(qemu-nographic
COMMAND ${CMAKE_COMMAND} -E env ${BANAN_SCRIPT_ENV} ${CMAKE_SOURCE_DIR}/qemu.sh -nographic ${QEMU_ACCEL}
DEPENDS image
USES_TERMINAL
)
add_custom_target(qemu-debug
COMMAND ${CMAKE_COMMAND} -E env ${BANAN_SCRIPT_ENV} ${CMAKE_SOURCE_DIR}/qemu.sh -serial stdio -d int -no-reboot
DEPENDS image
USES_TERMINAL
)
add_custom_target(bochs
COMMAND ${CMAKE_COMMAND} -E env ${BANAN_SCRIPT_ENV} ${CMAKE_SOURCE_DIR}/bochs.sh
DEPENDS image
USES_TERMINAL
)

View File

@ -1 +0,0 @@
set(CMAKE_GENERATOR "Ninja" CACHE INTERNAL "" FORCE)

View File

@ -1,10 +0,0 @@
#!/bin/bash
set -e
LOOP_DEV=$(sudo losetup -f --show $DISK_IMAGE_PATH)
sudo partprobe $LOOP_DEV
sudo fsck.ext2 -fn ${LOOP_DEV}p2 || true
sudo losetup -d $LOOP_DEV

View File

@ -1,30 +0,0 @@
#!/bin/bash
if [ ! -f $DISK_IMAGE_PATH ]; then
$(dirname "$0")/image-full.sh
exit 0
fi
fdisk -l $DISK_IMAGE_PATH | grep -q 'EFI System'; IMAGE_IS_UEFI=$?
[[ $UEFI_BOOT == 1 ]]; CREATE_IS_UEFI=$?
if [ $IMAGE_IS_UEFI -ne $CREATE_IS_UEFI ]; then
echo Converting disk image to/from UEFI
$(dirname "$0")/image-full.sh
exit 0
fi
MOUNT_DIR=/mnt
LOOP_DEV=$(sudo losetup -f --show $DISK_IMAGE_PATH)
sudo partprobe $LOOP_DEV
ROOT_PARTITON=${LOOP_DEV}p2
sudo mount $ROOT_PARTITON $MOUNT_DIR
sudo rsync -a ${SYSROOT}/* ${MOUNT_DIR}/
sudo umount $MOUNT_DIR
sudo losetup -d $LOOP_DEV

19
qemu.sh
View File

@ -1,19 +0,0 @@
#!/bin/bash
set -e
if [ -z ${OVMF_PATH+x} ]; then
OVMF_PATH="/usr/share/ovmf/x64/OVMF.fd"
fi
if [ "$UEFI_BOOT" == "1" ]; then
BIOS_ARGS="-bios $OVMF_PATH -net none"
fi
qemu-system-$BANAN_ARCH \
-m 128 \
-smp 2 \
$BIOS_ARGS \
-drive format=raw,id=disk,file=${DISK_IMAGE_PATH},if=none \
-device ahci,id=ahci \
-device ide-hd,drive=disk,bus=ahci.0 \
$@ \

View File

@ -14,7 +14,7 @@ COM1_DEVICE=$(cat $COM1_DEVICE_FILE)
rm $COM1_DEVICE_FILE
cat > $BOCHS_CONFIG_FILE << EOF
ata0-master: type=disk, path=$DISK_IMAGE_PATH, status=inserted
ata0-master: type=disk, path=$BANAN_DISK_IMAGE_PATH, status=inserted
boot: disk
clock: sync=realtime, time0=local
display_library: x, options="gui_debug"

107
script/build.sh Executable file
View File

@ -0,0 +1,107 @@
#!/bin/bash
set -e
if [[ -z $BANAN_ARCH ]]; then
export BANAN_ARCH=x86_64
fi
export BANAN_SCRIPT_DIR=$(dirname $(realpath $0))
source $BANAN_SCRIPT_DIR/config.sh
make_build_dir () {
if ! [[ -d $BANAN_BUILD_DIR ]]; then
mkdir -p $BANAN_BUILD_DIR
cd $BANAN_BUILD_DIR
cmake --toolchain=$BANAN_TOOLCHAIN_DIR/Toolchain.txt -G Ninja $BANAN_ROOT_DIR $BANAN_CMAKE_ARGS
fi
}
build_target () {
make_build_dir
if [[ -z $1 ]]; then
echo "No target provided"
exit 1
fi
cd $BANAN_BUILD_DIR
ninja $1
}
build_toolchain () {
$BANAN_TOOLCHAIN_DIR/build.sh
build_target libc-install
$BANAN_TOOLCHAIN_DIR/build.sh libstdc++
}
create_image () {
build_target install-sysroot
if [[ "$1" == "full" ]]; then
$BANAN_SCRIPT_DIR/image-full.sh
else
$BANAN_SCRIPT_DIR/image.sh
fi
}
run_qemu () {
create_image
$BANAN_SCRIPT_DIR/qemu.sh $@
}
run_bochs () {
create_image
$BANAN_SCRIPT_DIR/bochs.sh $@
}
if [[ "$1" == "toolchain" ]]; then
if [[ -f $BANAN_TOOLCHAIN_PREFIX/bin/$BANAN_TOOLCHAIN_TRIPLE_PREFIX-gcc ]]; then
echo "You already seem to have build 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
build_toolchain
exit 0
fi
if [[ "$1" == "image" ]]; then
create_image
exit 0
fi
if [[ "$1" == "image-full" ]]; then
create_image full
exit 0
fi
if [[ "$(uname)" == "Linux" ]]; then
QEMU_ACCEL="-accel kvm"
fi
if [[ "$1" == "qemu" ]]; then
run_qemu -serial stdio $QEMU_ACCEL
exit 0
fi
if [[ "$1" == "qemu-nographic" ]]; then
run_qemu -nographic $QEMU_ACCEL
exit 0
fi
if [[ "$1" == "qemu-debug" ]]; then
run_qemu -serial stdio -d int -no-reboot
exit 0
fi
if [[ "$1" == "bochs" ]]; then
run_bochs
exit 0
fi
if [[ "$1" == "check-fs" ]]; then
$BANAN_SCRIPT_DIR/check-fs.sh
exit 0
fi
build_target $1

14
script/check-fs.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
set -e
if [[ -z $BANAN_DISK_IMAGE_PATH ]]; then
echo "You must set BANAN_DISK_IMAGE_PATH environment variable" >&2
exit 1
fi
LOOP_DEV=$(sudo losetup -f --show $BANAN_DISK_IMAGE_PATH)
sudo partprobe $LOOP_DEV
sudo fsck.ext2 -fn ${LOOP_DEV}p2 || true
sudo losetup -d $LOOP_DEV

27
script/config.sh Normal file
View File

@ -0,0 +1,27 @@
if [[ -z $BANAN_ROOT_DIR ]]; then
if [[ -z $BANAN_SCRIPT_DIR ]]; then
export BANAN_ROOT_DIR=$BANAN_SCRIPT_DIR/..
else
echo "You must set the BANAN_ROOT_DIR environment variable" >&2
exit 1
fi
fi
if [[ -z $BANAN_ARCH ]]; then
echo "You must set the BANAN_ARCH environment variable" >&2
exit 1
fi
export BANAN_TOOLCHAIN_DIR=$BANAN_ROOT_DIR/toolchain
export BANAN_TOOLCHAIN_PREFIX=$BANAN_TOOLCHAIN_DIR/local
export BANAN_TOOLCHAIN_TRIPLE_PREFIX=$BANAN_ARCH-banan_os
export BANAN_BUILD_DIR=$BANAN_ROOT_DIR/build
export BANAN_SYSROOT=$BANAN_BUILD_DIR/sysroot
export BANAN_DISK_IMAGE_PATH=$BANAN_BUILD_DIR/banan-os.img
if [[ -z $BANAN_UEFI_BOOT ]]; then
export BANAN_UEFI_BOOT=0
fi

View File

@ -1,14 +1,34 @@
#!/bin/bash
set -e
if [[ -z $BANAN_DISK_IMAGE_PATH ]]; then
echo "You must set the BANAN_DISK_IMAGE_PATH environment variable" >&2
exit 1
fi
if [[ -z $BANAN_SYSROOT ]]; then
echo "You must set the BANAN_SYSROOT 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_ARCH ]]; then
echo "You must set the BANAN_ARCH environment variable" >&2
exit 1
fi
DISK_SIZE=$[50 * 1024 * 1024]
MOUNT_DIR=/mnt
truncate -s 0 "$DISK_IMAGE_PATH"
truncate -s $DISK_SIZE "$DISK_IMAGE_PATH"
truncate -s 0 "$BANAN_DISK_IMAGE_PATH"
truncate -s $DISK_SIZE "$BANAN_DISK_IMAGE_PATH"
if [ "$UEFI_BOOT" == "1" ]; then
sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk "$DISK_IMAGE_PATH" > /dev/null
if [ "$BANAN_UEFI_BOOT" == "1" ]; then
sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk "$BANAN_DISK_IMAGE_PATH" > /dev/null
g # gpt
n # new partition
1 # partition number 1
@ -27,7 +47,7 @@ if [ "$UEFI_BOOT" == "1" ]; then
w # write changes
EOF
else
sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk "$DISK_IMAGE_PATH" > /dev/null
sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk "$BANAN_DISK_IMAGE_PATH" > /dev/null
g # gpt
n # new partition
1 # partition number 1
@ -47,30 +67,30 @@ else
EOF
fi
LOOP_DEV=$(sudo losetup -f --show "$DISK_IMAGE_PATH")
LOOP_DEV=$(sudo losetup -f --show "$BANAN_DISK_IMAGE_PATH")
sudo partprobe $LOOP_DEV
PARTITION1=${LOOP_DEV}p1
PARTITION2=${LOOP_DEV}p2
sudo mkfs.ext2 -d $SYSROOT -b 1024 -q $PARTITION2
sudo mkfs.ext2 -d $BANAN_SYSROOT -b 1024 -q $PARTITION2
if [[ "$UEFI_BOOT" == "1" ]]; then
if [[ "$BANAN_UEFI_BOOT" == "1" ]]; then
sudo mkfs.fat $PARTITION1 > /dev/null
sudo mount $PARTITION1 "$MOUNT_DIR"
sudo mkdir -p "$MOUNT_DIR/EFI/BOOT"
sudo "$TOOLCHAIN_PREFIX/bin/grub-mkstandalone" -O "$BANAN_ARCH-efi" -o "$MOUNT_DIR/EFI/BOOT/BOOTX64.EFI" "boot/grub/grub.cfg=$TOOLCHAIN_PREFIX/grub-memdisk.cfg"
sudo "$BANAN_TOOLCHAIN_PREFIX/bin/grub-mkstandalone" -O "$BANAN_ARCH-efi" -o "$MOUNT_DIR/EFI/BOOT/BOOTX64.EFI" "boot/grub/grub.cfg=$BANAN_TOOLCHAIN_PREFIX/grub-memdisk.cfg"
sudo umount "$MOUNT_DIR"
sudo mount $PARTITION2 "$MOUNT_DIR"
sudo mkdir -p "$MOUNT_DIR/boot/grub"
sudo cp "$TOOLCHAIN_PREFIX/grub-uefi.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
sudo cp "$BANAN_TOOLCHAIN_PREFIX/grub-uefi.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
sudo umount "$MOUNT_DIR"
else
sudo mount $PARTITION2 "$MOUNT_DIR"
sudo grub-install --no-floppy --target=i386-pc --modules="normal ext2 multiboot" --boot-directory="$MOUNT_DIR/boot" $LOOP_DEV
sudo mkdir -p "$MOUNT_DIR/boot/grub"
sudo cp "$TOOLCHAIN_PREFIX/grub-legacy-boot.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
sudo cp "$BANAN_TOOLCHAIN_PREFIX/grub-legacy-boot.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
sudo umount "$MOUNT_DIR"
fi

45
script/image.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
if [[ -z $BANAN_ROOT_DIR ]]; then
echo "You must set the BANAN_ROOT_DIR environment variable" >&2
exit 1
fi
if [[ -z $BANAN_DISK_IMAGE_PATH ]]; then
echo "You must set the BANAN_DISK_IMAGE_PATH environment variable" >&2
exit 1
fi
if [[ -z $BANAN_SYSROOT ]]; then
echo "You must set the BANAN_SYSROOT environment variable" >&2
exit 1
fi
if [[ ! -f $BANAN_DISK_IMAGE_PATH ]]; then
$BANAN_SCRIPT_DIR/image-full.sh
exit 0
fi
fdisk -l $BANAN_DISK_IMAGE_PATH | grep -q 'EFI System'; IMAGE_IS_UEFI=$?
[[ $BANAN_UEFI_BOOT == 1 ]]; CREATE_IS_UEFI=$?
if [[ $IMAGE_IS_UEFI -ne $CREATE_IS_UEFI ]]; then
echo Converting disk image to/from UEFI
$BANAN_SCRIPT_DIR/image-full.sh
exit 0
fi
MOUNT_DIR=/mnt
LOOP_DEV=$(sudo losetup -f --show $BANAN_DISK_IMAGE_PATH)
sudo partprobe $LOOP_DEV
ROOT_PARTITON=${LOOP_DEV}p2
sudo mount $ROOT_PARTITON $MOUNT_DIR
sudo rsync -a ${BANAN_SYSROOT}/* ${MOUNT_DIR}/
sudo umount $MOUNT_DIR
sudo losetup -d $LOOP_DEV

24
script/qemu.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
set -e
if [[ -z $BANAN_DISK_IMAGE_PATH ]]; then
echo "You must set the BANAN_DISK_IMAGE_PATH environment variable" >&2
exit 1
fi
if [[ -z $OVMF_PATH ]]; then
OVMF_PATH="/usr/share/ovmf/x64/OVMF.fd"
fi
if [[ "$BANAN_UEFI_BOOT" == "1" ]]; then
BIOS_ARGS="-bios $OVMF_PATH -net none"
fi
qemu-system-$BANAN_ARCH \
-m 128 \
-smp 2 \
$BIOS_ARGS \
-drive format=raw,id=disk,file=${BANAN_DISK_IMAGE_PATH},if=none \
-device ahci,id=ahci \
-device ide-hd,drive=disk,bus=ahci.0 \
$@ \

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