poppin/build.sh

109 lines
2.2 KiB
Bash
Raw Normal View History

2024-05-23 18:39:00 +00:00
BUILD_DIR="./target"
BIN="$BUILD_DIR/poppin.bin"
ISO="$BUILD_DIR/poppin.iso"
set -e
function cmd_exists() {
if ! command -v $1 &> /dev/null
then
echo "The command '$1' could not be found please install it"
exit 1
fi
}
function pre_build() {
cmd_exists cargo
cmd_exists xorriso
cmd_exists grub-file
cmd_exists ld
cmd_exists grub-mkrescue
cmd_exists qemu-system-x86_64
}
function build_kernel() {
echo "INFO: Building poppin-kernel"
pushd kernel > /dev/null
cargo build --release --target-dir ../${BUILD_DIR}
popd > /dev/null
}
function build_boot() {
echo "INFO: Building boot code"
nasm -felf64 -o $BUILD_DIR/long_mode.o boot/long_mode.s
nasm -felf64 -o $BUILD_DIR/boot.o boot/boot.s
nasm -felf64 -o $BUILD_DIR/multiboot.o boot/multiboot.s
}
function link(){
echo "INFO: Linking"
ld -melf_x86_64 -n \
-T linker.ld \
-o ${BIN} \
${BUILD_DIR}/multiboot.o \
${BUILD_DIR}/boot.o \
${BUILD_DIR}/long_mode.o \
2024-06-10 20:57:38 +00:00
${BUILD_DIR}/x86_64-unknown-none/release/libkernel.a
2024-05-23 18:39:00 +00:00
}
function check_mb() {
if grub-file --is-x86-multiboot2 $BIN; then
echo "INFO: Kernel conatins multiboot2"
else
echo "ERROR: Kernel doesnt contain multiboot2"
exit 1
fi
}
function make_iso() {
echo "INFO: Building ISO"
mkdir -p ${BUILD_DIR}/iso/boot/grub
cp ${BUILD_DIR}/poppin.bin ${BUILD_DIR}/iso/boot/poppin.bin
cp boot/grub.cfg ${BUILD_DIR}/iso/boot/grub/grub.cfg
grub-mkrescue -o ${ISO} ${BUILD_DIR}/iso > /dev/null 2>&1
}
function run_qemu() {
2024-06-10 20:57:38 +00:00
qemu-system-x86_64 \
-cdrom $ISO \
-serial stdio \
-device VGA
2024-05-23 18:39:00 +00:00
}
function print_help() {
echo "Usage: ./build.sh [command]"
echo "Commands:"
echo " run-qemu - Compiles and Runs the built iso with qemu"
echo " build - Compiles everything"
}
function build() {
pre_build
build_kernel
build_boot
link
check_mb
make_iso
}
case $1 in
run-qemu)
build
run_qemu
;;
build)
build
;;
*)
if [ $# -gt 0 ]; then
echo "ERROR: Unknown option '$1'"
fi
print_help
exit 1
;;
esac