#!/bin/sh QEMU_EXECUTABLES="qemu-system-x86_64" GDB_EXECUTABLES="gdb x86_64-elf-gdb" event() { printf "$1... " } # $1: OS NAME # $2: CROSS COMPILE FLAG # $3: FDISK_BIN generate_cross_compile_script() { cat > cross-compile.cmake < /dev/null 2>&1; then QEMU="$item" break fi done if [ "$QEMU" = "" ]; then echo "failed" exit 1 fi echo "$QEMU" event "finding gdb" for item in $GDB_EXECUTABLES; do if $item --version > /dev/null 2>&1; then GDB="$item" break fi done if [ "$GDB" = "" ]; then echo "failed" exit 1 fi echo "$GDB" event "checking os type" OS=`uname` case "$OS" in "Linux") echo "Linux" ;; "Darwin") echo "macOS" ;; *) echo "unknown" exit 1 ;; esac event "setting hardware acceleration type" case "$OS" in "Linux") echo "kvm" QEMU_ACCEL='-enable-kvm' ;; "Darwin") echo "tcg" QEMU_ACCEL='-accel tcg' ;; esac event "checking util-linux fdisk" if [ "$FDISK_BIN" = "" -a "$CROSS_COMPILE" = "" ]; then if ! which fdisk > /dev/null 2>&1; then echo "no" exit 1 fi FDISK_BIN=`which fdisk` fi if ! $FDISK_BIN -v 2>&1 | grep util-linux > /dev/null 2>&1 ; then echo "no, fdisk is not from util-linux" exit 1 else echo "$FDISK_BIN" fi event "checking cross compiling" if [ "$CROSS_COMPILE" != "" ]; then echo "yes" CROSS_COMPILE_FLAG='--toolchain cross-compile.cmake' generate_cross_compile_script "$OS" "$CROSS_COMPILE" "$FDISK_BIN" else echo "no" CROSS_COMPILE_FLAG= fi event "checking mkfs tool" if ! which mkfs.fat > /dev/null 2>&1; then echo "no" exit 1 else echo `which mkfs.fat` fi event "checking mtools" if ! which mcopy > /dev/null 2>&1; then echo "no" exit 1 else echo `which mcopy` fi cp Makefile.src Makefile sed -i '' -e "s/##PLACEHOLDER_1##/$QEMU/" Makefile > /dev/null 2>&1 sed -i '' -e "s/##PLACEHOLDER_2##/$GDB/" Makefile > /dev/null 2>&1 sed -i '' -e "s/##PLACEHOLDER_3##/$QEMU_ACCEL/" Makefile > /dev/null 2>&1 sed -i '' -e "s/##PLACEHOLDER_4##/$CROSS_COMPILE_FLAG/" Makefile > /dev/null 2>&1 exit 0