configure 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/sh
  2. QEMU_EXECUTABLES="qemu-system-i386 qemu-system-x86_64"
  3. GDB_EXECUTABLES="gdb x86_64-elf-gdb"
  4. event() {
  5. printf "$1... "
  6. }
  7. # $1: OS NAME
  8. # $2: CROSS COMPILE FLAG
  9. # $3: FDISK_BIN
  10. generate_cross_compile_script() {
  11. cat > cross-compile.cmake <<EOF
  12. set(CMAKE_SYSTEM_NAME $1)
  13. set(TOOLCHAIN_PATH_AND_PREFIX "$2")
  14. set(CMAKE_C_COMPILER \${TOOLCHAIN_PATH_AND_PREFIX}gcc)
  15. set(CMAKE_CXX_COMPILER \${TOOLCHAIN_PATH_AND_PREFIX}c++)
  16. set(CMAKE_AR \${TOOLCHAIN_PATH_AND_PREFIX}ar)
  17. set(CMAKE_LINKER \${TOOLCHAIN_PATH_AND_PREFIX}ld)
  18. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  19. SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  20. # for libraries and headers in the target directories
  21. SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  22. SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  23. SET(FDISK_BIN $3)
  24. EOF
  25. }
  26. event "finding qemu"
  27. for item in $QEMU_EXECUTABLES; do
  28. if $item --version > /dev/null 2>&1; then
  29. QEMU="$item"
  30. break
  31. fi
  32. done
  33. if [ "$QEMU" = "" ]; then
  34. echo "failed"
  35. exit 1
  36. fi
  37. echo "$QEMU"
  38. event "finding gdb"
  39. for item in $GDB_EXECUTABLES; do
  40. if $item --version > /dev/null 2>&1; then
  41. GDB="$item"
  42. break
  43. fi
  44. done
  45. if [ "$GDB" = "" ]; then
  46. echo "failed"
  47. exit 1
  48. fi
  49. echo "$GDB"
  50. event "checking os type"
  51. OS=`uname`
  52. case "$OS" in
  53. "Linux")
  54. echo "Linux"
  55. ;;
  56. "Darwin")
  57. echo "macOS"
  58. ;;
  59. *)
  60. echo "unknown"
  61. exit 1
  62. ;;
  63. esac
  64. event "setting hardware acceleration type"
  65. case "$OS" in
  66. "Linux")
  67. echo "kvm"
  68. QEMU_ACCEL='-enable-kvm'
  69. ;;
  70. "Darwin")
  71. if [ "$QEMU" = "qemu-system-x86_64" ]; then
  72. echo "hvf"
  73. QEMU_ACCEL='-accel hvf'
  74. else
  75. echo "tcg"
  76. QEMU_ACCEL='-accel tcg'
  77. fi
  78. ;;
  79. esac
  80. event "checking util-linux fdisk"
  81. if [ "$FDISK_BIN" = "" -a "$CROSS_COMPILE" = "" ]; then
  82. if ! which fdisk > /dev/null 2>&1; then
  83. echo "no"
  84. exit 1
  85. fi
  86. FDISK_BIN=`which fdisk`
  87. fi
  88. if ! $FDISK_BIN -v 2>&1 | grep util-linux > /dev/null 2>&1 ; then
  89. echo "no, fdisk is not from util-linux"
  90. exit 1
  91. else
  92. echo "$FDISK_BIN"
  93. fi
  94. event "checking cross compiling"
  95. if [ "$CROSS_COMPILE" != "" ]; then
  96. echo "yes"
  97. CROSS_COMPILE_FLAG='--toolchain cross-compile.cmake'
  98. generate_cross_compile_script "$OS" "$CROSS_COMPILE" "$FDISK_BIN"
  99. else
  100. echo "no"
  101. CROSS_COMPILE_FLAG=
  102. fi
  103. event "checking mkfs tool"
  104. if ! which mkfs.fat > /dev/null 2>&1; then
  105. echo "no"
  106. exit 1
  107. else
  108. echo `which mkfs.fat`
  109. fi
  110. event "checking mtools"
  111. if ! which mcopy > /dev/null 2>&1; then
  112. echo "no"
  113. exit 1
  114. else
  115. echo `which mcopy`
  116. fi
  117. cp Makefile.src Makefile
  118. sed -i '' -e "s/##PLACEHOLDER_1##/$QEMU/" Makefile > /dev/null 2>&1
  119. sed -i '' -e "s/##PLACEHOLDER_2##/$GDB/" Makefile > /dev/null 2>&1
  120. sed -i '' -e "s/##PLACEHOLDER_3##/$QEMU_ACCEL/" Makefile > /dev/null 2>&1
  121. sed -i '' -e "s/##PLACEHOLDER_4##/$CROSS_COMPILE_FLAG/" Makefile > /dev/null 2>&1
  122. exit 0