MK404-build.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. #!/bin/bash
  2. # This bash script is used to compile automatically and run 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. #
  12. #
  13. # Version: 1.0.0-Build_13
  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. # 18 Jun 2021, 3d-gussner, Documentation and version number
  20. # 18 Jun 2021, 3d-gussner, Added some arguments and checks
  21. # 18 Jun 2021, 3d-gussner, Default extrusion graphics to line. Thanks @vintagepc point it out
  22. # 18 Jun 2021, 3d-gussner, Added -g 3 and 4 for more details extrusion lines
  23. # 18 Jun 2021, 3d-gussner, Check for updates is default. Fix update if internet connection is lost.
  24. # 21 Jun 2021, 3d-gussner, Change board_flash argument to 'y' and firmware_version to 'f'
  25. #### Start: Failures
  26. failures()
  27. {
  28. case "$1" in
  29. 0) echo "$(tput setaf 2)MK404-build.sh finished with success$(tput sgr0)" ;;
  30. 2) echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)" ; echo "Please refer to the notes of MK404-build.sh$(tput sgr0)" ; exit 2 ;;
  31. 3) echo "$(tput setaf 1)This script doesn't support your Operating system!"; echo "Please use Linux 64-bit"; echo "Read the notes of MK404-build.sh$(tput sgr0)" ; exit 2 ;;
  32. 4) echo "$(tput setaf 1)Some packages are missing please install these!$(tput sgr0)" ; exit 4 ;;
  33. 5) echo "$(tput setaf 1)Wrong printer chosen.$(tput sgr0) Following Printers are supported: MK25, MK25S, MK3 and MK3S" ; exit 5 ;;
  34. 6) echo "$(tput setaf 1)Unsupported board flash size chosen.$(tput sgr0) Only '256', '384', '512', '1024' and '32M' are allowed." ; exit 6 ;;
  35. 7) echo "$(tput setaf 1)Unsupported board mem size chosen.$(tput sgr0) Only '8', '16', '32' and '64' are allowed." ; exit 7 ;;
  36. 8) echo "$(tput setaf 1)No firmware version file selected!$(tput sgr0)" ; echo "Add argument -f with path and hex filename to start MK404" ; exit 8 ;;
  37. 9) echo "$(tput setaf 1)Tried to determine MK404 printer from hex file, but failed!$(tput sgr0)" ; "Add argument -p with 'MK25', 'MK25S', 'MK3' or 'MK3S' to start MK404" ; exit 9 ;;
  38. 10) echo "$(tput setaf 1)Missing printer$(tput sgr0)" ; exit 10 ;;
  39. esac
  40. }
  41. #### End: Failures
  42. #### Start: Check options
  43. ##check_options()
  44. ##{
  45. while getopts c:f:g:m:n:p:u:x:y:?h flag
  46. do
  47. case "${flag}" in
  48. c) check_flag=${OPTARG};;
  49. f) firmware_version_flag=${OPTARG};;
  50. g) mk404_graphics_flag=${OPTARG};;
  51. h) help_flag=1;;
  52. m) mk404_flag=${OPTARG};;
  53. n) new_build_flag=${OPTARG};;
  54. p) mk404_printer_flag=${OPTARG};;
  55. u) update_flag=${OPTARG};;
  56. x) board_mem_flag=${OPTARG};;
  57. y) board_flash_flag=${OPTARG};;
  58. ?) help_flag=1;;
  59. esac
  60. done
  61. #Debug echos
  62. #echo "c: $check_flag"
  63. #echo "f: $firmware_version_flag"
  64. #echo "g: $mk404_graphics_flag"
  65. #echo "m: $mk404_flag"
  66. #echo "n: $new_build_flag"
  67. #echo "p: $mk404_printer_flag"
  68. #echo "u: $update_flag"
  69. #echo "x: $board_mem_flag"
  70. #echo "y: $board_flash_flag"
  71. # '?' 'h' argument usage and help
  72. if [ "$help_flag" == "1" ] ; then
  73. echo "***************************************"
  74. echo "* MK404-build.sh Version: 1.0.0-Build_13 *"
  75. echo "***************************************"
  76. echo "Arguments:"
  77. echo "$(tput setaf 2)-c$(tput sgr0) Check for update"
  78. echo "$(tput setaf 2)-f$(tput sgr0) Prusa-Firmware version"
  79. echo "$(tput setaf 2)-g$(tput sgr0) Start MK404 graphics"
  80. echo "$(tput setaf 2)-h$(tput sgr0) Help"
  81. echo "$(tput setaf 2)-m$(tput sgr0) Start MK404 sim"
  82. echo "$(tput setaf 2)-n$(tput sgr0) Force new build"
  83. echo "$(tput setaf 2)-p$(tput sgr0) MK404 Printer"
  84. echo "$(tput setaf 2)-u$(tput sgr0) Update MK404"
  85. echo "$(tput setaf 2)-x$(tput sgr0) Board memory size"
  86. echo "$(tput setaf 2)-y$(tput sgr0) Board flash size"
  87. echo "$(tput setaf 2)-?$(tput sgr0) Help"
  88. echo
  89. echo "Brief USAGE:"
  90. echo " $(tput setaf 2)./MK404-build.sh$(tput sgr0) [-c] [-f] [-g] [-m] [-n] [-p] [-u] [-v] [-x] [-h] [-?]"
  91. echo
  92. echo " -c : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes"
  93. echo " -f : '$(tput setaf 2)path+file name$(tput sgr0)'"
  94. echo " -g : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' lite, '$(tput setaf 2)2$(tput sgr0)' fancy, '$(tput setaf 2)3$(tput sgr0)' lite with Quad_HR, '$(tput setaf 2)4$(tput sgr0)' fancy with Quad_HR"
  95. echo " -m : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes '$(tput setaf 2)2$(tput sgr0)' with MMU2"
  96. echo " -n : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes"
  97. echo " -p : '$(tput setaf 2)MK25$(tput sgr0)', '$(tput setaf 2)MK25S$(tput sgr0)', '$(tput setaf 2)MK3$(tput sgr0)' or '$(tput setaf 2)MK3S$(tput sgr0)'"
  98. echo " -u : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes '"
  99. echo " -x : '$(tput setaf 2)8$(tput sgr0)',$(tput setaf 2)16$(tput sgr0)',$(tput setaf 2)32$(tput sgr0)' or '$(tput setaf 2)64$(tput sgr0)' Kb."
  100. echo " -y : '$(tput setaf 2)256$(tput sgr0)','$(tput setaf 2)384$(tput sgr0)','$(tput setaf 2)512$(tput sgr0)','$(tput setaf 2)1024$(tput sgr0)''$(tput setaf 2)32M$(tput sgr0)'"
  101. echo
  102. echo "Example:"
  103. echo " $(tput setaf 2)./MK404-build.sh -f 1$(tput sgr0)"
  104. echo " Will force an update and rebuild the MK404 SIM"
  105. echo
  106. echo " $(tput setaf 2)./MK404-build.sh -m 1 -g 1 -f ../../../../Prusa-Firmware/PF-build-hex/FW3100-Build4481/BOARD_EINSY_1_0a/FW3100-Build4481-1_75mm_MK3S-EINSy10a-E3Dv6full.hex$(tput sgr0)"
  107. echo " Will start MK404 with Prusa_MK3S and Prusa-Firmware 3.10.0-Build4481"
  108. exit 1
  109. fi
  110. #Check MK404 agruments
  111. #Set Check for updates as default
  112. check_flag=1
  113. #Start: Check mk404_printer_flag
  114. if [ ! -z $mk404_printer_flag ]; then
  115. if [[ "$mk404_printer_flag" == "MK3" || "$mk404_printer_flag" == "MK3S" || "$mk404_printer_flag" == "MK25" || "$mk404_printer_flag" == "MK25S" ]]; then
  116. MK404_PRINTER_TEMP=$mk404_printer_flag
  117. else
  118. failures 5
  119. fi
  120. fi
  121. #End: Check mk404_printer_flag
  122. #Start: Check if Build is selected with argument '-f'
  123. if [ ! -z "$board_flash_flag" ] ; then
  124. if [ "$board_flash_flag" == "256" ] ; then
  125. BOARD_FLASH="0x3FFFF"
  126. echo "Board flash size : $board_flash_flag Kb, $BOARD_FLASH (hex)"
  127. elif [ "$board_flash_flag" == "384" ] ; then
  128. BOARD_FLASH="0x5FFFF"
  129. echo "Board flash size : $board_flash_flag Kb, $BOARD_FLASH (hex)"
  130. elif [ "$board_flash_flag" == "512" ] ; then
  131. BOARD_FLASH="0x7FFFF"
  132. echo "Board flash size : $board_flash_flag Kb, $BOARD_FLASH (hex)"
  133. elif [ "$board_flash_flag" == "1024" ] ; then
  134. BOARD_FLASH="0xFFFFF"
  135. echo "Board flash size : $board_flash_flag Kb, $BOARD_FLASH (hex)"
  136. elif [[ "$board_flash_flag" == "32M" || "$board_flash_flag" == "32768" ]] ; then
  137. BOARD_FLASH="0x1FFFFFF"
  138. echo "Board flash size : 32 Mb, $BOARD_FLASH (hex)"
  139. else
  140. failures 6
  141. fi
  142. fi
  143. #End: Check if Build is selected with argument '-f'
  144. #Start: Check if Build is selected with argument '-x'
  145. if [ ! -z "$board_mem_flag" ] ; then
  146. if [ "$board_mem_flag" == "8" ] ; then
  147. BOARD_MEM="0x21FF"
  148. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  149. elif [ "$board_mem_flag" == "16" ] ; then
  150. BOARD_MEM="0x3DFF"
  151. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  152. elif [ "$board_mem_flag" == "32" ] ; then
  153. BOARD_MEM="0x7DFF"
  154. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  155. elif [ "$board_mem_flag" == "64" ] ; then
  156. BOARD_MEM="0xFFFF"
  157. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  158. else
  159. failures 7
  160. fi
  161. fi
  162. #End: Check if Build is selected with argument '-x'
  163. #Start: Check if new build is selected
  164. if [ "$new_build_flag" == "1" ]; then
  165. check_flag=1
  166. update_flag=1
  167. fi
  168. if [ "$update_flag" == "1" ]; then
  169. check_flag=1
  170. fi
  171. #End: Check if new build is selected
  172. # Prepare run MK404
  173. #Check MK404_Printer
  174. if [ ! -z $firmware_version_flag ]; then
  175. MK404_PRINTER_TEMP=$(echo $firmware_version_flag | sed 's/\(.*\)\///' | grep 'MK3')
  176. if [ ! -z $MK404_PRINTER_TEMP ]; then
  177. MK404_PRINTER=MK3
  178. fi
  179. MK404_PRINTER_TEMP=$(echo $firmware_version_flag | sed 's/\(.*\)\///' | grep 'MK3S')
  180. if [ ! -z $MK404_PRINTER_TEMP ]; then
  181. MK404_PRINTER=MK3S
  182. fi
  183. MK404_PRINTER_TEMP=$(echo $firmware_version_flag | sed 's/\(.*\)\///' | grep 'MK25')
  184. if [ ! -z $MK404_PRINTER_TEMP ]; then
  185. MK404_PRINTER=MK25
  186. fi
  187. MK404_PRINTER_TEMP=$(echo $firmware_version_flag | sed 's/\(.*\)\///' | grep 'MK25S')
  188. if [ ! -z $MK404_PRINTER_TEMP ]; then
  189. MK404_PRINTER=MK25S
  190. fi
  191. else
  192. failures 8
  193. fi
  194. if [ -z "$MK404_PRINTER" ]; then
  195. failures 9
  196. fi
  197. if [ ! -z $mk404_printer_flag ]; then
  198. if [ "$mk404_printer_flag" != "$MK404_PRINTER" ]; then
  199. echo "$(tput setaf 3)You defined a different printer type than the firmware!"
  200. echo "This can cause unexpected issues.$(tput sgr 0)"
  201. echo
  202. PS3="Select $(tput setaf 2)printer$(tput sgr 0) you want to use."
  203. select which in "$(tput setaf 2)$MK404_PRINTER$(tput sgr 0)" "$mk404_printer_flag"; do
  204. case $which in
  205. $MK404_PRINTER)
  206. echo "Set $MK404_PRINTER as printer"
  207. break
  208. ;;
  209. $mk404_printer_flag)
  210. echo "Set $(tput setaf 3)$mk404_printer_flag$(tput sgr 0) as printer"
  211. echo "$(tput setaf 3)This firmware file isn't correct for this printer!!!$(tput sgr 0)"
  212. echo
  213. MK404_PRINTER=$mk404_printer_flag
  214. read -p "Press Enter to continue."
  215. break
  216. ;;
  217. *)
  218. break
  219. ;;
  220. esac
  221. done
  222. fi
  223. fi
  224. if [ -z $MK404_PRINTER ]; then
  225. failures 10
  226. fi
  227. if [[ "$MK404_PRINTER" == "MK25" || "$MK404_PRINTER" == "MK25S" ]]; then
  228. MK404_PRINTER="${MK404_PRINTER}_mR13"
  229. else
  230. if [ "$mk404_flag" == "2" ]; then # Check if MMU2 is selected only for MK3/S
  231. MK404_PRINTER="${MK404_PRINTER}MMU2"
  232. fi
  233. fi
  234. # Run MK404 with 'debugcore' and/or 'bootloader-file'
  235. if [[ ! -z $MK404_DEBUG && "$MK404_DEBUG" == "atmega404" || ! -z $BOARD_MEM && "$BOARD_MEM" == "0xFFFF" ]]; then
  236. MK404_options="--debugcore"
  237. fi
  238. if [[ ! -z $MK404_DEBUG && "$MK404_DEBUG" == "atmega404_no_bootloader" || ! -z $BOARD_FLASH && "$BOARD_FLASH" != "0x3FFFF" ]]; then
  239. MK404_options='--debugcore --bootloader-file ""'
  240. fi
  241. # Run MK404 with graphics
  242. if [ ! -z "$mk404_graphics_flag" ]; then
  243. if [ ! -z "$MK404_options" ]; then
  244. MK404_options="${MK404_options} -g "
  245. else
  246. MK404_options=" -g "
  247. fi
  248. if [[ "$mk404_graphics_flag" == "1" || "$mk404_graphics_flag" == "lite" || "$mk404_graphics_flag" == "3" ]]; then
  249. MK404_options="${MK404_options}lite"
  250. elif [[ "$mk404_graphics_flag" == "2" || "$mk404_graphics_flag" == "fancy" || "$mk404_graphics_flag" == "4" ]]; then
  251. MK404_options="${MK404_options}fancy"
  252. else
  253. echo "$(tput setaf 1)Unsupported MK404 graphics option $mk404_graphics_flag$(tput sgr 0)"
  254. fi
  255. if [[ "$mk404_graphics_flag" == "3" || "$mk404_graphics_flag" == "4" ]]; then
  256. MK404_options="${MK404_options} --colour-extrusion --extrusion Quad_HR"
  257. else
  258. MK404_options="${MK404_options} --extrusion Line"
  259. fi
  260. fi
  261. if [ ! -z $firmware_version_flag ]; then
  262. MK404_firmware_file=" -f $firmware_version_flag"
  263. fi
  264. #End: Check MK404 agruments
  265. ##}
  266. #### End: Check for options/flags
  267. #### Start: Check if OSTYPE is supported
  268. check_OS()
  269. {
  270. OS_FOUND=$( command -v uname)
  271. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  272. linux*)
  273. TARGET_OS="linux"
  274. ;;
  275. *)
  276. TARGET_OS='unknown'
  277. ;;
  278. esac
  279. # Linux
  280. if [ $TARGET_OS == "linux" ]; then
  281. if [ $(uname -m) == "x86_64" ]; then
  282. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  283. Processor="64"
  284. #elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  285. # echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)"
  286. # Processor="32"
  287. else
  288. failures 2
  289. fi
  290. else
  291. failures 3
  292. fi
  293. sleep 2
  294. }
  295. #### End: Check if OSTYPE is supported
  296. #### Start: Check MK404 dependencies
  297. check_packages()
  298. {
  299. packages=(
  300. "libelf-dev"
  301. "gcc-7"
  302. "gcc-avr"
  303. "libglew-dev"
  304. "freeglut3-dev"
  305. "libsdl-sound1.2-dev"
  306. "libpng-dev"
  307. "cmake"
  308. "zip"
  309. "wget"
  310. "git"
  311. "build-essential"
  312. "lcov"
  313. "mtools"
  314. )
  315. for check_package in ${packages[@]}; do
  316. if dpkg-query -W -f'${db:Status-Abbrev}\n' $check_package 2>/dev/null \
  317. | grep -q '^.i $'; then
  318. echo "$(tput setaf 2)$check_package: Installed$(tput sgr0)"
  319. else
  320. 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)"
  321. not_installed=1;
  322. fi
  323. done
  324. if [ "$not_installed" = "1" ]; then
  325. failures 4
  326. fi
  327. }
  328. #### End: Check MK404 dependencies
  329. #### Start: Set build environment
  330. set_build_env_variables()
  331. {
  332. MK404_SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  333. MK404_URL="https://github.com/vintagepc/MK404.git"
  334. MK404_owner="vintagepc"
  335. MK404_project="MK404"
  336. MK404_PATH="$MK404_SCRIPT_PATH/../MK404/master"
  337. MK404_BUILD_PATH="$MK404_PATH/build"
  338. }
  339. #### End: Set build environment
  340. #### Start: List few useful data
  341. output_useful_data()
  342. {
  343. echo
  344. echo "Script path :" $MK404_SCRIPT_PATH
  345. echo "OS :" $TARGET_OS
  346. echo ""
  347. echo "MK404 path :" $MK404_PATH
  348. }
  349. #### End: List few useful data
  350. #### Start: Clone MK404 if needed
  351. get_MK404()
  352. {
  353. if [ ! -d $MK404_PATH ]; then
  354. #release_url=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/$MK404_owner/$MK404_project/releases/latest)
  355. #release_tag=$(basename $release_url)
  356. #git clone -b $release_tag -- https://github.com/$MK404_owner/$MK404_project.git $MK404_PATH
  357. git clone $MK404_URL $MK404_PATH
  358. fi
  359. }
  360. #### End: Clone MK404 if needed
  361. #### Start: Check for updates
  362. check_for_updates()
  363. {
  364. if [ "$check_flag" == "1" ]; then
  365. if [ -d $MK404_BUILD_PATH ]; then
  366. cd $MK404_BUILD_PATH
  367. MK404_current_version=$( command ./MK404 --version | grep "MK404" | cut -f 4 -d " ")
  368. cd $MK404_PATH
  369. else
  370. echo "Cannot check current version as it has not been build."
  371. fi
  372. # Get local Commit_Hash
  373. MK404_local_GIT_COMMIT_HASH=$(git log --pretty=format:"%H" -1)
  374. # Get local Commit_Number
  375. MK404_local_GIT_COMMIT_NUMBER=$(git rev-list HEAD --count)
  376. # Get latest release
  377. MK404_release_url=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/$MK404_owner/$MK404_project/releases/latest)
  378. MK404_release_tag=$(basename $MK404_release_url)
  379. # Get remote Commit_Hash
  380. #MK404_remote_GIT_COMMIT_HASH=$(git ls-remote --heads $(git config --get remote.origin.url) | grep "refs/heads/master" | cut -f 1)
  381. MK404_remote_GIT_COMMIT_HASH=$(git ls-remote | grep "refs/tags/$MK404_release_tag" | cut -f 1)
  382. # Get remote Commit_Number
  383. MK404_remote_GIT_COMMIT_NUMBER=$(git rev-list $MK404_release_tag --count)
  384. # Output
  385. echo ""
  386. echo "Current version : $MK404_current_version"
  387. echo ""
  388. echo "Current local hash : $MK404_local_GIT_COMMIT_HASH"
  389. echo "Current local commit nr : $MK404_local_GIT_COMMIT_NUMBER"
  390. if [ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_remote_GIT_COMMIT_HASH" ]; then
  391. echo "$(tput setaf 1)"
  392. else
  393. echo "$(tput setaf 2)"
  394. fi
  395. echo "Latest release tag : $MK404_release_tag"
  396. echo "Latest release hash : $MK404_remote_GIT_COMMIT_HASH"
  397. echo "Latest remote commit nr : $MK404_remote_GIT_COMMIT_NUMBER"
  398. echo "$(tput sgr 0)"
  399. # Check for updates
  400. if [ ! -z $MK404_remote_GIT_COMMIT_HASH ]; then
  401. if [[ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_remote_GIT_COMMIT_HASH" && -z "$update_flag" ]]; then
  402. echo "$(tput setaf 2)Update is availible.$(tput sgr 0)"
  403. read -t 10 -n 1 -p "$(tput setaf 3)Update now Y/n$(tput sgr 0)" update_answer
  404. if [ "$update_answer" == "Y" ]; then
  405. update_flag=1
  406. fi
  407. echo ""
  408. fi
  409. fi
  410. fi
  411. }
  412. #### End: Check for updates
  413. #### Start: Fetch updates and force new build
  414. fetch_updates()
  415. {
  416. if [ "$update_flag" == "1" ]; then
  417. if [ ! -z $MK404_remote_GIT_COMMIT_HASH ]; then
  418. if [ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_remote_GIT_COMMIT_HASH" ]; then
  419. echo ""
  420. git fetch --all
  421. read -t 10 -p "$(tput setaf 2)Updating MK404 !$(tput sgr 0)"
  422. echo ""
  423. git reset --hard $MK404_release_tag
  424. read -t 10 -p "$(tput setaf 2)Compiling MK404 !$(tput sgr 0)"
  425. echo ""
  426. new_build_flag=1
  427. fi
  428. fi
  429. fi
  430. }
  431. #### End: Fetch updates and force new build
  432. #### Start: Prepare MK404 build
  433. prepare_MK404()
  434. {
  435. if [ ! -d $MK404_BUILD_PATH ]; then
  436. mkdir -p $MK404_BUILD_PATH
  437. fi
  438. }
  439. #### End: Prepare MK404 build
  440. #### Start: Build MK404
  441. build_MK404()
  442. {
  443. if [[ ! -f "$MK404_BUILD_PATH/Makefile" || "$new_build_flag" == "1" ]]; then
  444. # Init and update submodules
  445. if [ -d $MK404_BUILD_PATH ]; then
  446. rm -rf $MK404_BUILD_PATH
  447. mkdir -p $MK404_BUILD_PATH
  448. fi
  449. git submodule init
  450. git submodule update
  451. cmake -B$MK404_BUILD_PATH -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"
  452. fi
  453. # Make MK404
  454. cd $MK404_BUILD_PATH
  455. if [[ ! -f "$MK404_BUILD_PATH/MK404" || "$new_build_flag" == "1" ]]; then
  456. make
  457. fi
  458. # Make SDcards
  459. if [[ ! -f "$MK404_BUILD_PATH/Prusa_MK3S_SDcard.bin" || "$new_build_flag" == "1" ]]; then
  460. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3S_SDcard.bin
  461. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3_SDcard.bin
  462. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK25_13_SDcard.bin
  463. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK25S_13_SDcard.bin
  464. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3SMMU2_SDcard.bin
  465. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3MMU2_SDcard.bin
  466. fi
  467. }
  468. #### End: Build MK404
  469. #### Start: Run MK404 SIM
  470. run_MK404_SIM()
  471. {
  472. if [ ! -z $mk404_flag ]; then
  473. # Output some useful data
  474. echo "Printer : $MK404_PRINTER"
  475. echo "Options : $MK404_options"
  476. echo ""
  477. read -t 5 -p "Press $(tput setaf 2)Enter$(tput sgr 0) to start MK404"
  478. echo ""
  479. # Change to MK404 build folder
  480. cd $MK404_BUILD_PATH
  481. # Start MK404
  482. # default with serial output and terminal to manipulate it via terminal
  483. echo ""
  484. echo "./MK404 Prusa_$MK404_PRINTER -s --terminal $MK404_options $MK404_firmware_file"
  485. sleep 5
  486. ./MK404 Prusa_$MK404_PRINTER -s --terminal $MK404_options $MK404_firmware_file || exit 10
  487. fi
  488. }
  489. #### End: Run MK404 SIM
  490. #### Check OS and needed packages
  491. echo "Check OS"
  492. check_OS
  493. check_packages
  494. #### Check for options/flags
  495. echo "Check for options"
  496. #### Prepare build environment
  497. echo "Prepare build env"
  498. set_build_env_variables
  499. output_useful_data
  500. get_MK404
  501. #
  502. cd $MK404_PATH
  503. check_for_updates
  504. fetch_updates
  505. prepare_MK404
  506. build_MK404
  507. run_MK404_SIM
  508. #### End of MK404 Simulator