MK404-build.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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_3
  14. # Change log:
  15. # 11 Feb 2021, 3d-gussner, Inital
  16. # 11 Feb 2021, 3d-gussner, Optional flags to check for updates
  17. # 12 Feb 2021, 3d-gussner, Update cmake
  18. # 13 Feb 2021, 3d-gussner, Auto build SD cards
  19. while getopts c:u:f:m:g:?h flag
  20. do
  21. case "${flag}" in
  22. c) check_flag=${OPTARG};;
  23. u) update_flag=${OPTARG};;
  24. f) force_flag=${OPTARG};;
  25. m) mk404_flag=${OPTARG};;
  26. g) graphics_flag=${OPTARG};;
  27. ?) help_flag=1;;
  28. h) help_flag=1;;
  29. esac
  30. done
  31. echo "$check_flag"
  32. echo "$update_flag"
  33. echo "$force_flag"
  34. echo "$mk404_flag"
  35. echo "$graphics_flag"
  36. #### Start check if OSTYPE is supported
  37. OS_FOUND=$( command -v uname)
  38. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  39. linux*)
  40. TARGET_OS="linux"
  41. ;;
  42. *)
  43. TARGET_OS='unknown'
  44. ;;
  45. esac
  46. # Linux
  47. if [ $TARGET_OS == "linux" ]; then
  48. if [ $(uname -m) == "x86_64" ]; then
  49. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  50. Processor="64"
  51. #elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  52. # echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)"
  53. # Processor="32"
  54. else
  55. echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)"
  56. echo "Please refer to the notes of build.sh$(tput sgr0)"
  57. exit 1
  58. fi
  59. else
  60. echo "$(tput setaf 1)This script doesn't support your Operating system!"
  61. echo "Please use Linux 64-bit"
  62. echo "Read the notes of build.sh$(tput sgr0)"
  63. exit 1
  64. fi
  65. sleep 2
  66. #### End check if OSTYPE is supported
  67. #### Check MK404 dependencies
  68. packages=(
  69. "libelf-dev"
  70. "gcc-7"
  71. "gcc-avr"
  72. "libglew-dev"
  73. "freeglut3-dev"
  74. "libsdl-sound1.2-dev"
  75. "libpng-dev"
  76. "cmake"
  77. "zip"
  78. "wget"
  79. "git"
  80. "build-essential"
  81. "lcov"
  82. "mtools"
  83. )
  84. for check_package in ${packages[@]}; do
  85. if dpkg-query -W -f'${db:Status-Abbrev}\n' $check_package 2>/dev/null \
  86. | grep -q '^.i $'; then
  87. echo "$(tput setaf 2)$check_package: Installed$(tput sgr0)"
  88. else
  89. 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)"
  90. not_installed=1;
  91. fi
  92. done
  93. if [ "$not_installed" = "1" ]; then
  94. exit 4
  95. fi
  96. #### End Check MK404 dependencies
  97. #### Set build environment
  98. MK404_SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  99. MK404_URL="https://github.com/vintagepc/MK404.git"
  100. MK404_owner="vintagepc"
  101. MK404_project="MK404"
  102. MK404_PATH="$MK404_SCRIPT_PATH/../MK404/master"
  103. MK404_BUILD_PATH="$MK404_PATH/build"
  104. # List few useful data
  105. echo
  106. echo "Script path :" $MK404_SCRIPT_PATH
  107. echo "OS :" $OS
  108. echo "OS type :" $TARGET_OS
  109. echo ""
  110. echo "MK404 path :" $MK404_PATH
  111. # Clone MK404 if needed
  112. if [ ! -d $MK404_PATH ]; then
  113. #release_url=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/$MK404_owner/$MK404_project/releases/latest)
  114. #release_tag=$(basename $release_url)
  115. #git clone -b $release_tag -- https://github.com/$MK404_owner/$MK404_project.git $MK404_PATH
  116. git clone $MK404_URL $MK404_PATH
  117. fi
  118. #
  119. cd $MK404_PATH
  120. # Check for updates ... WIP
  121. # Check MK404
  122. if [ "$force_flag" == "1" ]; then
  123. check_flag=1
  124. update_flag=1
  125. fi
  126. if [ "$update_flag" == "1" ]; then
  127. check_flag=1
  128. fi
  129. if [ "$check_flag" == "1" ]; then
  130. if [ -d $MK404_BUILD_PATH ]; then
  131. cd $MK404_BUILD_PATH
  132. MK404_current_version=$( command ./MK404 --version | grep "MK404" | cut -f 4 -d " ")
  133. cd $MK404_PATH
  134. else
  135. echo "Cannot check current version as it has not been build."
  136. fi
  137. # Get local Commit_Hash
  138. MK404_local_GIT_COMMIT_HASH=$(git log --pretty=format:"%H" -1)
  139. # Get local Commit_Number
  140. MK404_local_GIT_COMMIT_NUMBER=$(git rev-list HEAD --count)
  141. # Get remote Commit_Hash
  142. MK404_remote_GIT_COMMIT_HASH=$(git ls-remote --heads $(git config --get remote.origin.url) | grep "refs/heads/master" | cut -f 1)
  143. # Get remote Commit_Number
  144. MK404_remote_GIT_COMMIT_NUMBER=$(git rev-list origin/master --count)
  145. # Output
  146. echo "Current version : $MK404_current_version"
  147. echo ""
  148. echo "Current local hash : $MK404_local_GIT_COMMIT_HASH"
  149. echo "Current local commit nr : $MK404_local_GIT_COMMIT_NUMBER"
  150. if [ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_remote_GIT_COMMIT_HASH" ]; then
  151. echo "$(tput setaf 1)"
  152. else
  153. echo "$(tput sgr 0)"
  154. fi
  155. echo "Current remote hash : $MK404_remote_GIT_COMMIT_HASH"
  156. echo "Current remote commit nr: $MK404_remote_GIT_COMMIT_NUMBER"
  157. echo "$(tput sgr 0)"
  158. # Check for updates
  159. if [[ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_remote_GIT_COMMIT_HASH" && -z "$update_flag" ]]; then
  160. echo "$(tput setaf 2)Update is availible.$(tput sgr 0)"
  161. read -t 10 -n 1 -p "$(tput setaf 3)Update now Y/n$(tput sgr 0)" update_answer
  162. if [ "$update_answer" == "Y" ]; then
  163. update_flag=1
  164. fi
  165. echo ""
  166. fi
  167. fi
  168. # Check for updates
  169. if [ "$update_flag" == "1" ]; then
  170. if [ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_remote_GIT_COMMIT_HASH" ]; then
  171. echo ""
  172. git fetch --all
  173. read -t 10 -p "$(tput setaf 2)Updating MK404 !$(tput sgr 0)"
  174. echo ""
  175. git reset --hard origin/master
  176. read -t 10 -p "$(tput setaf 2)Compiling MK404 !$(tput sgr 0)"
  177. echo ""
  178. force_flag=1
  179. fi
  180. fi
  181. # Prepare MK404
  182. mkdir -p $MK404_BUILD_PATH
  183. if [[ ! -f "$MK404_BUILD_PATH/Makefile" || "$force_flag" == "1" ]]; then
  184. # Init and update submodules
  185. git submodule init
  186. git submodule update
  187. cmake -B$MK404_BUILD_PATH -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"
  188. fi
  189. # Make MK404
  190. cd $MK404_BUILD_PATH
  191. if [[ ! -f "$MK404_BUILD_PATH/MK404" || "$force_flag" == "1" ]]; then
  192. make
  193. fi
  194. # Make SDcards
  195. if [[ ! -f "$MK404_BUILD_PATH/Prusa_MK3S_SDcard.bin" || "$force_flag" == "1" ]]; then
  196. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3S_SDcard.bin
  197. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3_SDcard.bin
  198. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK25_13_SDcard.bin
  199. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK25S_13_SDcard.bin
  200. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3SMMU2_SDcard.bin
  201. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3MMU2_SDcard.bin
  202. fi