MK404-build.sh 3.9 KB

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