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"
|
|
|
|
|
2023-12-28 19:13:27 +02:00
|
|
|
if [[ -z $CMAKE_COMMAND ]]; then
|
|
|
|
echo "No usable cmake binary found" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-11-04 17:50:43 +02:00
|
|
|
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
|
2023-12-27 12:55:32 +02:00
|
|
|
$CMAKE_COMMAND --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
|
|
|
|
}
|
|
|
|
|
|
|
|
create_image () {
|
2023-11-20 00:54:15 +02:00
|
|
|
build_target bootloader
|
2023-10-23 13:27:23 +03:00
|
|
|
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
|
|
|
|
;;
|
2023-11-12 01:09:31 +02:00
|
|
|
clean)
|
|
|
|
build_target clean
|
|
|
|
rm -f $FAKEROOT_FILE
|
|
|
|
rm -rf $BANAN_SYSROOT
|
2024-01-11 13:27:02 +02:00
|
|
|
rm -f $BANAN_DISK_IMAGE_PATH
|
2023-11-12 01:09:31 +02:00
|
|
|
;;
|
2023-10-24 16:48:46 +03:00
|
|
|
*)
|
|
|
|
build_target $1
|
|
|
|
;;
|
|
|
|
esac
|