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
|
2024-05-20 16:19:29 +03:00
|
|
|
$BANAN_CMAKE --toolchain=$BANAN_TOOLCHAIN_DIR/Toolchain.txt -G Ninja $BANAN_ROOT_DIR
|
2023-10-23 13:27:23 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
build_target () {
|
2024-05-20 16:19:29 +03:00
|
|
|
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
|
|
|
|
|
2023-10-23 13:27:23 +03:00
|
|
|
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 () {
|
|
|
|
$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
|
2024-04-03 19:14:35 +03:00
|
|
|
$BANAN_ROOT_DIR/ports/build.sh
|
|
|
|
build_target package-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
|
2024-05-24 11:09:04 +03:00
|
|
|
if [[ -r /dev/kvm ]] && [[ -w /dev/kvm ]]; then
|
|
|
|
QEMU_ACCEL="-accel kvm"
|
|
|
|
else
|
|
|
|
echo "You don't have read/write permissions for /dev/kvm" >&2
|
|
|
|
fi
|
2023-10-23 13:27:23 +03:00
|
|
|
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
|