123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #!/bin/sh
- QEMU_EXECUTABLES="qemu-system-i386 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 <<EOF
- set(CMAKE_SYSTEM_NAME $1)
- set(TOOLCHAIN_PATH_AND_PREFIX "$2")
- set(CMAKE_C_COMPILER \${TOOLCHAIN_PATH_AND_PREFIX}gcc)
- set(CMAKE_CXX_COMPILER \${TOOLCHAIN_PATH_AND_PREFIX}c++)
- set(CMAKE_AR \${TOOLCHAIN_PATH_AND_PREFIX}ar)
- set(CMAKE_LINKER \${TOOLCHAIN_PATH_AND_PREFIX}ld)
- set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
- SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
- # for libraries and headers in the target directories
- SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
- SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
- SET(FDISK_BIN $3)
- EOF
- }
- event "finding qemu"
- for item in $QEMU_EXECUTABLES; do
- if $item --version > /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")
- if [ "$QEMU" = "qemu-system-x86_64" ]; then
- echo "hvf"
- QEMU_ACCEL='-accel hvf'
- else
- echo "tcg"
- QEMU_ACCEL='-accel tcg'
- fi
- ;;
- 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
|