configure 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/bin/sh
  2. QEMU_EXECUTABLES="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. check_gdb_arch() {
  39. local item="$1"
  40. if $item --init-eval-command 'set arch' \
  41. --init-eval-command 'q' 2>&1 \
  42. | grep 'x86-64' >/dev/null 2>&1; then
  43. return 0
  44. else
  45. return 1
  46. fi
  47. }
  48. if [ "$GDB" = "" ]; then
  49. event "finding gdb"
  50. for item in $GDB_EXECUTABLES; do
  51. if check_gdb_arch "$item"; then
  52. GDB="$item"
  53. break
  54. fi
  55. done
  56. if [ "$GDB" = "" ]; then
  57. echo "failed"
  58. exit 1
  59. fi
  60. else
  61. event 'checking given gdb'
  62. if ! check_gdb_arch "$GDB"; then
  63. echo "failed"
  64. exit 1
  65. fi
  66. fi
  67. echo "$GDB"
  68. event "checking os type"
  69. OS=`uname`
  70. case "$OS" in
  71. "Linux")
  72. echo "Linux"
  73. ;;
  74. "Darwin")
  75. echo "macOS"
  76. ;;
  77. *)
  78. echo "unknown"
  79. exit 1
  80. ;;
  81. esac
  82. event "setting hardware acceleration type"
  83. case "$OS" in
  84. "Linux")
  85. echo "kvm"
  86. QEMU_ACCEL='-enable-kvm'
  87. ;;
  88. "Darwin")
  89. echo "tcg"
  90. QEMU_ACCEL='-accel tcg'
  91. ;;
  92. esac
  93. event "checking util-linux fdisk"
  94. if [ "$FDISK_BIN" = "" -a "$CROSS_COMPILE" = "" ]; then
  95. if ! which fdisk > /dev/null 2>&1; then
  96. echo "no"
  97. exit 1
  98. fi
  99. FDISK_BIN=`which fdisk`
  100. fi
  101. if ! $FDISK_BIN -v 2>&1 | grep util-linux > /dev/null 2>&1 ; then
  102. echo "no, fdisk is not from util-linux"
  103. exit 1
  104. else
  105. echo "$FDISK_BIN"
  106. fi
  107. event "checking cross compiling"
  108. if [ "$CROSS_COMPILE" != "" ]; then
  109. echo "yes"
  110. CROSS_COMPILE_FLAG='--toolchain cross-compile.cmake'
  111. generate_cross_compile_script "$OS" "$CROSS_COMPILE" "$FDISK_BIN"
  112. else
  113. echo "no"
  114. CROSS_COMPILE_FLAG=
  115. fi
  116. event "checking mkfs tool"
  117. if ! which mkfs.fat > /dev/null 2>&1; then
  118. echo "no"
  119. exit 1
  120. else
  121. echo `which mkfs.fat`
  122. fi
  123. event "checking mtools"
  124. if ! which mcopy > /dev/null 2>&1; then
  125. echo "no"
  126. exit 1
  127. else
  128. echo `which mcopy`
  129. fi
  130. cp Makefile.src Makefile
  131. sed -i '' -e "s/##PLACEHOLDER_1##/$QEMU/" Makefile > /dev/null 2>&1
  132. sed -i '' -e "s/##PLACEHOLDER_2##/$GDB/" Makefile > /dev/null 2>&1
  133. sed -i '' -e "s/##PLACEHOLDER_3##/$QEMU_ACCEL/" Makefile > /dev/null 2>&1
  134. sed -i '' -e "s/##PLACEHOLDER_4##/$CROSS_COMPILE_FLAG/" Makefile > /dev/null 2>&1
  135. exit 0