MK404-build.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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:?h flag
  20. do
  21. case "${flag}" in
  22. c) check_flag=${OPTARG};;
  23. u) update_flag=${OPTARG};;
  24. f) force_flag=${OPTARG};;
  25. ?) help_flag=1;;
  26. h) help_flag=1;;
  27. esac
  28. done
  29. echo "$check_flag"
  30. echo "$update_flag"
  31. #### Start check if OSTYPE is supported
  32. OS_FOUND=$( command -v uname)
  33. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  34. linux*)
  35. TARGET_OS="linux"
  36. ;;
  37. *)
  38. TARGET_OS='unknown'
  39. ;;
  40. esac
  41. # Linux
  42. if [ $TARGET_OS == "linux" ]; then
  43. if [ $(uname -m) == "x86_64" ]; then
  44. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  45. Processor="64"
  46. #elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  47. # echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)"
  48. # Processor="32"
  49. else
  50. echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)"
  51. echo "Please refer to the notes of build.sh$(tput sgr0)"
  52. exit 1
  53. fi
  54. else
  55. echo "$(tput setaf 1)This script doesn't support your Operating system!"
  56. echo "Please use Linux 64-bit"
  57. echo "Read the notes of build.sh$(tput sgr0)"
  58. exit 1
  59. fi
  60. sleep 2
  61. #### End check if OSTYPE is supported
  62. #### Check MK404 dependencies
  63. packages=(
  64. "libelf-dev"
  65. "gcc-7"
  66. "gcc-avr"
  67. "libglew-dev"
  68. "freeglut3-dev"
  69. "libsdl-sound1.2-dev"
  70. "libpng-dev"
  71. "cmake"
  72. "zip"
  73. "wget"
  74. "git"
  75. "build-essential"
  76. "lcov"
  77. "mtools"
  78. )
  79. for check_package in ${packages[@]}; do
  80. if dpkg-query -W -f'${db:Status-Abbrev}\n' $check_package 2>/dev/null \
  81. | grep -q '^.i $'; then
  82. echo "$(tput setaf 2)$check_package: Installed$(tput sgr0)"
  83. else
  84. 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)"
  85. not_installed=1;
  86. fi
  87. done
  88. if [ "$not_installed" = "1" ]; then
  89. exit 4
  90. fi
  91. #### End Check MK404 dependencies
  92. #### Set build environment
  93. MK404_SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  94. MK404_URL="https://github.com/vintagepc/MK404.git"
  95. MK404_owner="vintagepc"
  96. MK404_project="MK404"
  97. MK404_PATH="$MK404_SCRIPT_PATH/../MK404/master"
  98. MK404_BUILD_PATH="$MK404_PATH/build"
  99. # List few useful data
  100. echo
  101. echo "Script path :" $MK404_SCRIPT_PATH
  102. echo "OS :" $OS
  103. echo "OS type :" $TARGET_OS
  104. echo ""
  105. echo "MK404 path :" $MK404_PATH
  106. # Clone MK404 if needed
  107. if [ ! -d $MK404_PATH ]; then
  108. #release_url=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/$MK404_owner/$MK404_project/releases/latest)
  109. #release_tag=$(basename $release_url)
  110. #git clone -b $release_tag -- https://github.com/$MK404_owner/$MK404_project.git $MK404_PATH
  111. git clone $MK404_URL $MK404_PATH
  112. fi
  113. # Init and update submodules
  114. cd $MK404_PATH
  115. git submodule init
  116. git submodule update
  117. # Prepare MK404
  118. mkdir -p $MK404_BUILD_PATH
  119. if [[ ! -f "$MK404_BUILD_PATH/Makefile" || "$force_flag" == "1" ]]; then
  120. cmake -B$MK404_BUILD_PATH -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"
  121. fi
  122. # Make MK404
  123. cd $MK404_BUILD_PATH
  124. if [[ ! -f "$MK404_BUILD_PATH/MK404" || "$force_flag" == "1" ]]; then
  125. make
  126. fi
  127. # Make SDcards
  128. if [[ ! -f "$MK404_BUILD_PATH/Prusa_MK3S_SDcard.bin" || "$force_flag" == "1" ]]; then
  129. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3S_SDcard.bin
  130. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3_SDcard.bin
  131. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK25_13_SDcard.bin
  132. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK25S_13_SDcard.bin
  133. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3SMMU2_SDcard.bin
  134. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3MMU2_SDcard.bin
  135. fi
  136. # Check for updates ... WIP
  137. if [ "$check_flag" == "1" ]; then
  138. current_version=$( command ./MK404 --version | grep "MK404" | cut -f 4 -d " ")
  139. echo "Current version: $current_version"
  140. fi