2023-10-23 13:27:23 +03:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
export BANAN_SCRIPT_DIR=$(dirname $(realpath $0))
|
|
|
|
source $BANAN_SCRIPT_DIR/config.sh
|
|
|
|
|
2023-11-04 17:50:43 +02:00
|
|
|
FAKEROOT_FILE="$BANAN_BUILD_DIR/fakeroot-context"
|
|
|
|
|
|
|
|
run_fakeroot() {
|
|
|
|
fakeroot -i $FAKEROOT_FILE -s $FAKEROOT_FILE -- /bin/bash -c '$@' bash $@
|
|
|
|
}
|
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
make_build_dir () {
|
2023-10-24 16:48:46 +03:00
|
|
|
mkdir -p $BANAN_BUILD_DIR
|
|
|
|
cd $BANAN_BUILD_DIR
|
|
|
|
if ! [[ -f "build.ninja" ]]; then
|
|
|
|
cmake --toolchain=$BANAN_TOOLCHAIN_DIR/Toolchain.txt -G Ninja $BANAN_ROOT_DIR
|
2023-10-23 13:27:23 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
build_target () {
|
|
|
|
make_build_dir
|
2023-10-24 16:48:46 +03:00
|
|
|
if [[ $# -eq 0 ]]; then
|
2023-10-23 13:27:23 +03:00
|
|
|
echo "No target provided"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cd $BANAN_BUILD_DIR
|
2023-11-04 17:50:43 +02:00
|
|
|
run_fakeroot ninja $1
|
2023-10-23 13:27:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
build_toolchain () {
|
2023-10-24 16:48:46 +03:00
|
|
|
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
|
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
$BANAN_TOOLCHAIN_DIR/build.sh
|
|
|
|
build_target libc-install
|
|
|
|
$BANAN_TOOLCHAIN_DIR/build.sh libstdc++
|
|
|
|
}
|
|
|
|
|
|
|
|
create_image () {
|
|
|
|
build_target install-sysroot
|
2023-11-04 17:50:43 +02:00
|
|
|
$BANAN_SCRIPT_DIR/image.sh "$1"
|
2023-10-23 13:27:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
run_qemu () {
|
|
|
|
create_image
|
|
|
|
$BANAN_SCRIPT_DIR/qemu.sh $@
|
|
|
|
}
|
|
|
|
|
|
|
|
run_bochs () {
|
|
|
|
create_image
|
|
|
|
$BANAN_SCRIPT_DIR/bochs.sh $@
|
|
|
|
}
|
|
|
|
|
2023-11-04 17:50:43 +02:00
|
|
|
if [[ -c /dev/kvm ]]; then
|
2023-10-23 13:27:23 +03:00
|
|
|
QEMU_ACCEL="-accel kvm"
|
|
|
|
fi
|
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
if [[ $# -eq 0 ]]; then
|
|
|
|
echo "No argument given"
|
|
|
|
exit 1
|
2023-10-23 13:27:23 +03:00
|
|
|
fi
|
|
|
|
|
2023-10-24 16:48:46 +03:00
|
|
|
case $1 in
|
|
|
|
toolchain)
|
|
|
|
build_toolchain
|
|
|
|
;;
|
|
|
|
image)
|
|
|
|
create_image
|
|
|
|
;;
|
|
|
|
image-full)
|
|
|
|
create_image full
|
|
|
|
;;
|
|
|
|
qemu)
|
|
|
|
run_qemu -serial stdio $QEMU_ACCEL
|
|
|
|
;;
|
|
|
|
qemu-nographic)
|
|
|
|
run_qemu -nographic $QEMU_ACCEL
|
|
|
|
;;
|
|
|
|
qemu-debug)
|
|
|
|
run_qemu -serial stdio -d int -no-reboot
|
|
|
|
;;
|
|
|
|
bochs)
|
|
|
|
run_bochs
|
|
|
|
;;
|
|
|
|
check-fs)
|
|
|
|
$BANAN_SCRIPT_DIR/check-fs.sh
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
build_target $1
|
|
|
|
;;
|
|
|
|
esac
|
2023-10-23 13:27:23 +03:00
|
|
|
|