MK404-build.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/bash
  2. # This bash script is used to compile automatically the MK404 simulator
  3. #
  4. # Supported OS: Linux64 bit
  5. #
  6. # Linux:
  7. # Linux Ubuntu
  8. # 1. Follow these instructions
  9. # 2. Open Ubuntu bash and get latest updates with 'sudo apt-get update'
  10. # 3. Install latest updates with 'sudo apt-get upgrade'
  11. # 4.
  12. #
  13. # Version: 0.1-Build_1
  14. # Change log:
  15. # 11 Feb 2021, 3d-gussner, Inital
  16. # 11 Feb 2021, 3d-gussner, Optional flags to check for updates
  17. while getopts c:u:?h flag
  18. do
  19. case "${flag}" in
  20. c) check_flag=${OPTARG};;
  21. u) update_flag=${OPTARG};;
  22. ?) help_flag=1;;
  23. h) help_flag=1;;
  24. esac
  25. done
  26. echo "$check_flag"
  27. echo "$update_flag"
  28. #### Start check if OSTYPE is supported
  29. OS_FOUND=$( command -v uname)
  30. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  31. linux*)
  32. TARGET_OS="linux"
  33. ;;
  34. *)
  35. TARGET_OS='unknown'
  36. ;;
  37. esac
  38. # Linux
  39. if [ $TARGET_OS == "linux" ]; then
  40. if [ $(uname -m) == "x86_64" ]; then
  41. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  42. Processor="64"
  43. #elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  44. # echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)"
  45. # Processor="32"
  46. else
  47. echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)"
  48. echo "Please refer to the notes of build.sh$(tput sgr0)"
  49. exit 1
  50. fi
  51. else
  52. echo "$(tput setaf 1)This script doesn't support your Operating system!"
  53. echo "Please use Linux 64-bit"
  54. echo "Read the notes of build.sh$(tput sgr0)"
  55. exit 1
  56. fi
  57. sleep 2
  58. #### End check if OSTYPE is supported
  59. #### Check MK404 dependencies
  60. packages=(
  61. "libelf-dev"
  62. "gcc-7"
  63. "gcc-avr"
  64. "libglew-dev"
  65. "freeglut3-dev"
  66. "libsdl-sound1.2-dev"
  67. "libpng-dev"
  68. "cmake"
  69. "zip"
  70. "wget"
  71. "git"
  72. "build-essential"
  73. "lcov"
  74. "mtools"
  75. )
  76. for check_package in ${packages[@]}; do
  77. if dpkg-query -W -f'${db:Status-Abbrev}\n' $check_package 2>/dev/null \
  78. | grep -q '^.i $'; then
  79. echo "$(tput setaf 2)$check_package: Installed$(tput sgr0)"
  80. else
  81. echo "$(tput setaf 1)$check_package: Not installed use $(tput setaf 3)'sudo apt install $check_package'$(tput setaf 1) to install missing package$(tput sgr0)"
  82. not_installed=1;
  83. fi
  84. done
  85. if [ "$not_installed" = "1" ]; then
  86. exit 4
  87. fi
  88. #### End Check MK404 dependencies
  89. #### Set build environment
  90. SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  91. MK404_URL="https://github.com/vintagepc/MK404.git"
  92. MK404_PATH="$SCRIPT_PATH/../MK404"
  93. MK404_BUILD_PATH="$MK404_PATH/build"
  94. # List few useful data
  95. echo
  96. echo "Script path :" $SCRIPT_PATH
  97. echo "OS :" $OS
  98. echo "OS type :" $TARGET_OS
  99. echo ""
  100. echo "MK404 path :" $MK404_PATH
  101. if [ ! -d $MK404_PATH ]; then
  102. git clone $MK404_URL $MK404_PATH
  103. fi
  104. cd $MK404_PATH
  105. git submodule init
  106. git submodule update
  107. mkdir -p $MK404_BUILD_PATH
  108. if [ ! -f "$MK404_BUILD_PATH/Makefile" ]; then
  109. cmake -B $MK404_BUILD_PATH
  110. fi
  111. cd $MK404_BUILD_PATH
  112. if [ ! -f "$MK404_BUILD_PATH/MK404" ]; then
  113. make
  114. fi
  115. if [ "$check_flag" == "1" ]; then
  116. current_version=$( command ./MK404 --version | grep "MK404" | cut -f 4 -d " ")
  117. echo "Current version: $current_version"
  118. fi