PF-build.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. #!/bin/bash
  2. # This bash script is used to compile automatically the Prusa firmware with a dedicated build environment and settings
  3. #
  4. # Supported OS: Windows 10, Linux64 bit
  5. #
  6. # Linux:
  7. #
  8. # Windows:
  9. # To execute this script you gonna need few things on your Windows machine
  10. #
  11. # Linux Subsystem Ubuntu
  12. # 1. Follow these instructions
  13. # 2. Open Ubuntu bash and get latest updates with 'apt-get upgate'
  14. # 3. Install zip with 'apt-get install zip'
  15. # 4. Add at top of ~/.bashrc following lines by using 'sudo nano ~/.bashrc'
  16. #
  17. # export OS="Linux"
  18. # export JAVA_TOOL_OPTIONS="-Djava.net.preferIPv4Stack=true"
  19. # export GPG_TTY=$(tty)
  20. #
  21. # and confirm them. Restart Ubuntu bash
  22. #
  23. # Or GIT-BASH
  24. # 1. Download and install the correct (64bit or 32bit) Git version https://git-scm.com/download/win
  25. # 2. Also follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058
  26. # 3. Download and install 7z-zip from its official website.
  27. # By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case.
  28. # 4. Run git Bash under Administrator privilege and navigate to the directory /c/Program Files/Git/mingw64/bin,
  29. # you can run the command ln -s /c/Program Files/7-Zip/7z.exe zip.exe
  30. #
  31. # Useful things to edit and compare your custom Firmware
  32. # 1. Download and install current and correct (64bit or 32bit) Notepad++ version https://notepad-plus-plus.org/download
  33. # 2. Another great tool to compare your custom mod and stock firmware is WinMerge http://winmerge.org/downloads/?lang=en
  34. #
  35. # Example for MK3: open git bash and change to your Firmware directory
  36. # <username>@<machinename> MINGW64 /<drive>/path
  37. # bash build.sh 1_75mm_MK3-EINSy10a-E3Dv6full
  38. #
  39. # Example for MK25: open git bash and change to your directory
  40. # gussner@WIN01 MINGW64 /d/Data/Prusa-Firmware/MK3
  41. # bash build.sh 1_75mm_MK25-RAMBo13a-E3Dv6full
  42. #
  43. # The compiled hex files can be found in the folder above like from the example
  44. # gussner@WIN01 MINGW64 /d/Data/Prusa-Firmware
  45. # FW351-Build1778-1_75mm_MK25-RAMBo13a-E3Dv6full.hex
  46. #
  47. # Version: 1.0.1-Build_8
  48. # Change log:
  49. # 12 Jan 2019, 3d-gussner, Fixed "compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections" in 'platform.txt'
  50. # 16 Jan 2019, 3d-gussner, Build_2, Added development check to modify 'Configuration.h' to prevent unwanted LCD messages that Firmware is unknown
  51. # 17 Jan 2019, 3d-gussner, Build_3, Check for OS Windows or Linux and use the right build enviroment
  52. # 10 Feb 2019, ropaha, Pull Request, Select variant from list while using build.sh
  53. # 10 Feb 2019, ropaha, change FW_DEV_VERSION automatically depending on FW_VERSION RC/BETA/ALPHA
  54. # 10 Feb 2019, 3d-gussner, 1st tests with english only
  55. # 10 Feb 2019, ropaha, added compiling of all variants and english only
  56. # 10 Feb 2019, 3d-gussner, Set OUTPUT_FOLDER for hex files
  57. # 11 Feb 2019, 3d-gussner/ropaha, Minor changes and fixes
  58. # 11 Feb 2019, 3d-gussner, Ready for RC
  59. # 12 Feb 2019, 3d-gussner, Check if wget and zip are installed. Thanks to Bernd to point it out
  60. # 12 Feb 2019, 3d-gussner, Changed OS check to OSTYPE as it is not supported on Ubuntu
  61. # Also added different BUILD_ENV folders depending on OS used so Windows
  62. # Users can use git-bash AND Windows Linux Subsystems at the same time
  63. # Cleanup compiler flags is only depends on OS version.
  64. # 12 Feb 2019, 3d-gussner, Added additional OSTYPE check
  65. # 15 feb 2019, 3d-gussner, Added zip files for miniRAMbo multi language hex files
  66. # 15 Feb 2019, 3d-gussner, Added more checks if
  67. # Compiled Hex-files
  68. # Configuration_prusa.h
  69. # language build files
  70. # multi language firmware files exist and clean them up
  71. # 15 Feb 2019, 3d-gussner, Fixed selction GOLD/UNKNOWN DEV_STATUS for ALL variants builds, so you have to choose only once
  72. # 15 Feb 2019, 3d-gussner, Added some colored output
  73. # 15 Feb 2019, 3d-gussner, troubleshooting and minor fixes
  74. # 16 Feb 2019, 3d-gussner, Script can be run using arguments
  75. # $1 = variant, example "1_75mm_MK3-EINSy10a-E3Dv6full.h" at this moment it is not possible to use ALL
  76. # $2 = multi language OR english only [ALL/EN_ONLY]
  77. # $3 = development status [GOLD/RC/BETA/ALPHA/DEVEL/DEBUG]
  78. # If one argument is wrong a list of valid one will be shown
  79. # 13 Mar 2019, 3d-gussner, MKbel updated the linux build enviromentto version 1.0.2 with an Fix maximum firmware flash size.
  80. # So did I
  81. ###Check if OSTYPE is supported
  82. if [ $OSTYPE == "msys" ]; then
  83. if [ $(uname -m) == "x86_64" ]; then
  84. echo "$(tput setaf 2)Windows 64-bit found$(tput sgr0)"
  85. fi
  86. elif [ $OSTYPE == "linux-gnu" ]; then
  87. if [ $(uname -m) == "x86_64" ]; then
  88. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  89. fi
  90. else
  91. echo "$(tput setaf 1)This script doesn't support your Operating system!"
  92. echo "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash"
  93. echo "Read the notes of build.sh$(tput sgr0)"
  94. exit
  95. fi
  96. sleep 2
  97. ###Prepare bash enviroment and check if wget and zip are available
  98. if ! type wget > /dev/null; then
  99. echo "$(tput setaf 1)Missing 'wget' which is important to run this script"
  100. echo "Please follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058 to install wget$(tput sgr0)"
  101. exit
  102. fi
  103. if ! type zip > /dev/null; then
  104. if [ $OSTYPE == "msys" ]; then
  105. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  106. echo "Download and install 7z-zip from its official website https://www.7-zip.org/"
  107. echo "By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case."
  108. echo "Run git Bash under Administrator privilege and"
  109. echo "navigate to the directory /c/Program Files/Git/mingw64/bin,"
  110. echo "you can run the command $(tput setaf 2)ln -s /c/Program Files/7-Zip/7z.exe zip.exe$(tput sgr0)"
  111. exit
  112. elif [ $OSTYPE == "linux-gnu" ]; then
  113. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  114. echo "install it with the command $(tput setaf 2)'sudo apt-get install zip'$(tput sgr0)"
  115. exit
  116. fi
  117. fi
  118. ###End prepare bash enviroment
  119. BUILD_ENV="1.0.2"
  120. SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  121. # List few useful data
  122. echo
  123. echo "Script path:" $SCRIPT_PATH
  124. echo "OS :" $OS
  125. echo "OS type :" $OSTYPE
  126. echo ""
  127. #### Start prepare building
  128. #Check if build exists and creates it if not
  129. if [ ! -d "../build-env" ]; then
  130. mkdir ../build-env || exit 2
  131. fi
  132. cd ../build-env || exit 3
  133. # Check if PF-build-env-<version> exists and downloads + creates it if not
  134. # The build enviroment is based on the Arduino IDE 1.8.5 portal version with some changes
  135. if [ ! -d "../PF-build-env-$BUILD_ENV" ]; then
  136. echo "$(tput setaf 6)PF-build-env-$BUILD_ENV is missing ... creating it now for you$(tput sgr 0)"
  137. mkdir ../PF-build-env-$BUILD_ENV
  138. sleep 5
  139. fi
  140. if [ $OSTYPE == "msys" ]; then
  141. if [ ! -f "PF-build-env-Win-$BUILD_ENV.zip" ]; then
  142. echo "$(tput setaf 6)Downloading Windows build environment...$(tput setaf 2)"
  143. sleep 2
  144. wget https://github.com/3d-gussner/PF-build-env/releases/download/Win-$BUILD_ENV/PF-build-env-Win-$BUILD_ENV.zip || exit 4
  145. #cp -f ../../PF-build-env/PF-build-env-Win-$BUILD_ENV.zip PF-build-env-Win-$BUILD_ENV.zip || exit4
  146. echo "$(tput sgr 0)"
  147. fi
  148. if [ ! -d "../PF-build-env-$BUILD_ENV/$OSTYPE" ]; then
  149. echo "$(tput setaf 6)Unzipping Windows build environment...$(tput setaf 2)"
  150. sleep 2
  151. unzip PF-build-env-Win-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 4
  152. echo "$(tput sgr0)"
  153. fi
  154. fi
  155. if [ $OSTYPE == "linux-gnu" ]; then
  156. if [ ! -f "PF-build-env-Linux64-$BUILD_ENV.zip" ]; then
  157. echo "$(tput setaf 6)Downloading Linux 64 build environment...$(tput setaf 2)"
  158. sleep 2
  159. wget https://github.com/mkbel/PF-build-env/releases/download/$BUILD_ENV/PF-build-env-Linux64-$BUILD_ENV.zip || exit 3
  160. echo "$(tput sgr0)"
  161. fi
  162. if [ ! -d "../PF-build-env-$BUILD_ENV/$OSTYPE" ]; then
  163. echo "$(tput setaf 6)Unzipping Linux build enviroment...$(tput setaf 2)"
  164. sleep 2
  165. unzip PF-build-env-Linux64-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 4
  166. echo "$(tput sgr0)"
  167. fi
  168. fi
  169. cd $SCRIPT_PATH
  170. # First argument defines which variant of the Prusa Firmware will be compiled
  171. if [ -z "$1" ] ; then
  172. # Select which variant of the Prusa Firmware will be compiled, like
  173. PS3="Select a variant: "
  174. while IFS= read -r -d $'\0' f; do
  175. options[i++]="$f"
  176. done < <(find Firmware/variants/ -maxdepth 1 -type f -name "*.h" -print0 )
  177. select opt in "${options[@]}" "All" "Quit"; do
  178. case $opt in
  179. *.h)
  180. VARIANT=$(basename "$opt" ".h")
  181. VARIANTS[i++]="$opt"
  182. break
  183. ;;
  184. "All")
  185. VARIANT="All"
  186. VARIANTS=${options[*]}
  187. break
  188. ;;
  189. "Quit")
  190. echo "You chose to stop"
  191. exit 1
  192. ;;
  193. *)
  194. echo "$(tput setaf 1)This is not a valid variant$(tput sgr0)"
  195. ;;
  196. esac
  197. done
  198. else
  199. if [ -f "$SCRIPT_PATH/Firmware/variants/$1" ] ; then
  200. VARIANTS=$1
  201. else
  202. echo "$(tput setaf 1)$1 could not be found in Firmware/variants please choose a valid one$(tput setaf 2)"
  203. ls -1 $SCRIPT_PATH/Firmware/variants/*.h | xargs -n1 basename
  204. echo "$(tput sgr0)"
  205. exit
  206. fi
  207. fi
  208. #Second argument defines if it is an english only version. Known values EN_ONLY / ALL
  209. #Check default language mode
  210. MULTI_LANGUAGE_CHECK=$(grep --max-count=1 "^#define LANG_MODE *" $SCRIPT_PATH/Firmware/config.h|sed -e's/ */ /g'|cut -d ' ' -f3)
  211. if [ -z "$2" ] ; then
  212. PS3="Select a language: "
  213. echo
  214. echo "Which lang-build do you want?"
  215. select yn in "Multi languages" "English only"; do
  216. case $yn in
  217. "Multi languages")
  218. LANGUAGES="ALL"
  219. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE 1/g" $SCRIPT_PATH/Firmware/config.h
  220. break
  221. ;;
  222. "English only")
  223. LANGUAGES="EN_ONLY"
  224. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE 0/g" $SCRIPT_PATH/Firmware/config.h
  225. break
  226. ;;
  227. *)
  228. echo "$(tput setaf 1)This is not a valid language$(tput sgr0)"
  229. ;;
  230. esac
  231. done
  232. else
  233. if [[ "$2" == "ALL" || "$2" == "EN_ONLY" ]] ; then
  234. LANGUAGES=$2
  235. else
  236. echo "$(tput setaf 1)Language argument is wrong!$(tput sgr0)"
  237. echo "Only $(tput setaf 2)'ALL'$(tput sgr0) or $(tput setaf 2)'EN_ONLY'$(tput sgr0) are allowed as 2nd argument!"
  238. exit
  239. fi
  240. fi
  241. #Check if DEV_STATUS is selected via argument 3
  242. if [ ! -z "$3" ] ; then
  243. if [[ "$3" == "GOLD" || "$3" == "RC" || "$3" == "BETA" || "$3" == "ALPHA" || "$3" == "DEVEL" || "$3" == "DEBUG" ]] ; then
  244. DEV_STATUS_SELECTED=$3
  245. else
  246. echo "$(tput setaf 1)Development argument is wrong!$(tput sgr0)"
  247. echo "Only $(tput setaf 2)'GOLD', 'RC', 'BETA', 'ALPHA', 'DEVEL' or 'DEBUG'$(tput sgr0) are allowed as 3rd argument!$(tput sgr0)"
  248. exit
  249. fi
  250. fi
  251. #Set BUILD_ENV_PATH
  252. cd ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 5
  253. BUILD_ENV_PATH="$( pwd -P )"
  254. cd ../..
  255. #Checkif BUILD_PATH exists and if not creates it
  256. if [ ! -d "Prusa-Firmware-build" ]; then
  257. mkdir Prusa-Firmware-build || exit 6
  258. fi
  259. #Set the BUILD_PATH for Arduino IDE
  260. cd Prusa-Firmware-build || exit 7
  261. BUILD_PATH="$( pwd -P )"
  262. for v in ${VARIANTS[*]}
  263. do
  264. VARIANT=$(basename "$v" ".h")
  265. # Find firmware version in Configuration.h file and use it to generate the hex filename
  266. FW=$(grep --max-count=1 "\bFW_VERSION\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d '"' -f2|sed 's/\.//g')
  267. # Find build version in Configuration.h file and use it to generate the hex filename
  268. BUILD=$(grep --max-count=1 "\bFW_COMMIT_NR\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d ' ' -f3)
  269. # Check if the motherboard is an EINSY and if so only one hex file will generated
  270. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  271. # Check development status
  272. DEV_CHECK=$(grep --max-count=1 "\bFW_VERSION\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d '"' -f2|sed 's/\.//g'|cut -d '-' -f2)
  273. if [ -z "$DEV_STATUS_SELECTED" ] ; then
  274. if [[ "$DEV_CHECK" == "RC1" || "$DEV_CHECK" == "RC2" ]] ; then
  275. DEV_STATUS="RC"
  276. elif [[ "$DEV_CHECK" == "ALPHA" ]]; then
  277. DEV_STATUS="ALPHA"
  278. elif [[ "$DEV_CHECK" == "BETA" ]]; then
  279. DEV_STATUS="BETA"
  280. elif [[ "$DEV_CHECK" == "DEVEL" ]]; then
  281. DEV_STATUS="DEVEL"
  282. elif [[ "$DEV_CHECK" == "DEBUG" ]]; then
  283. DEV_STATUS="DEBUG"
  284. else
  285. DEV_STATUS="UNKNOWN"
  286. echo
  287. echo "$(tput setaf 5)DEV_STATUS is UNKNOWN. Do you wish to set DEV_STATUS to GOLD?$(tput sgr0)"
  288. PS3="Select YES only if source code is tested and trusted: "
  289. select yn in "Yes" "No"; do
  290. case $yn in
  291. Yes)
  292. DEV_STATUS="GOLD"
  293. DEV_STATUS_SELECTED="GOLD"
  294. break
  295. ;;
  296. No)
  297. DEV_STATUS="UNKNOWN"
  298. DEV_STATUS_SELECTED="UNKNOWN"
  299. break
  300. ;;
  301. *)
  302. echo "$(tput setaf 1)This is not a valid DEV_STATUS$(tput sgr0)"
  303. ;;
  304. esac
  305. done
  306. fi
  307. else
  308. DEV_STATUS=$DEV_STATUS_SELECTED
  309. fi
  310. #Prepare hex files folders
  311. if [ ! -d "$SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD" ]; then
  312. mkdir -p $SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD || exit 10
  313. fi
  314. OUTPUT_FOLDER="Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD"
  315. #Check if exactly the same hexfile already exists
  316. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex" && "$LANGUAGES" == "ALL" ]]; then
  317. echo ""
  318. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex | xargs -n1 basename
  319. echo "$(tput setaf 6)This hex file to be compiled already exists! To cancel this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  320. read -t 10 -p "Press Enter to continue..."
  321. elif [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex" && "$LANGUAGES" == "EN_ONLY" ]]; then
  322. echo ""
  323. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex | xargs -n1 basename
  324. echo "$(tput setaf 6)This hex file to be compiled already exists! To cancel this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  325. read -t 10 -p "Press Enter to continue..."
  326. fi
  327. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip" && "$LANGUAGES" == "ALL" ]]; then
  328. echo ""
  329. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip | xargs -n1 basename
  330. echo "$(tput setaf 6)This zip file to be compiled already exists! To cancel this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  331. read -t 10 -p "Press Enter to continue..."
  332. fi
  333. #List some useful data
  334. echo "$(tput setaf 2)$(tput setab 7) "
  335. echo "Variant :" $VARIANT
  336. echo "Firmware :" $FW
  337. echo "Build # :" $BUILD
  338. echo "Dev Check :" $DEV_CHECK
  339. echo "DEV Status :" $DEV_STATUS
  340. echo "Motherboard:" $MOTHERBOARD
  341. echo "Languages :" $LANGUAGES
  342. echo "Hex-file Folder:" $OUTPUT_FOLDER
  343. echo "$(tput sgr0)"
  344. #Prepare Firmware to be compiled by copying variant as Configuration_prusa.h
  345. if [ ! -f "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then
  346. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11
  347. else
  348. echo "$(tput setaf 6)Configuration_prusa.h already exist it will be overwritten in 10 seconds by the chosen variant.$(tput sgr 0)"
  349. read -t 10 -p "Press Enter to continue..."
  350. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11
  351. fi
  352. #Prepare Configuration.h to use the correct FW_DEV_VERSION to prevent LCD messages when connecting with OctoPrint
  353. sed -i -- "s/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/g" $SCRIPT_PATH/Firmware/Configuration.h
  354. # set FW_REPOSITORY
  355. sed -i -- 's/#define FW_REPOSITORY "Unknown"/#define FW_REPOSITORY "Prusa3d"/g' $SCRIPT_PATH/Firmware/Configuration.h
  356. #Prepare english only or multilanguage version to be build
  357. if [ $LANGUAGES == "ALL" ]; then
  358. echo " "
  359. echo "Multi-language firmware will be built"
  360. echo " "
  361. else
  362. echo " "
  363. echo "English only language firmware will be built"
  364. echo " "
  365. fi
  366. #Check if compiler flags are set to Prusa specific needs for the rambo board.
  367. if [ $OSTYPE == "msys" ]; then
  368. RAMBO_PLATFORM_FILE="rambo/hardware/avr/1.0.1/platform.txt"
  369. COMP_FLAGS="compiler.c.elf.flags={compiler.warning_flags} -Os -g -flto -fuse-linker-plugin -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections"
  370. CHECK_FLAGS=$(grep --max-count=1 "$COMP_FLAGS" $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE)
  371. if [ -z "$CHECK_FLAGS" ]; then
  372. echo "Compiler flags not found, adding flags"
  373. if [ ! -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck ]; then
  374. echo "making a backup"
  375. ls -1 $BUILD_ENV_PATH/portable/packages/rambo/hardware/avr/1.0.1/
  376. cp -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck
  377. fi
  378. echo $COMP_FLAGS >> $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE
  379. else
  380. echo "Compiler flags are set in rambo platform.txt" $CHECK_FLAGS
  381. fi
  382. fi
  383. #### End of Prepare building
  384. #### Start building
  385. export ARDUINO=$BUILD_ENV_PATH
  386. #echo $BUILD_ENV_PATH
  387. export BUILDER=$ARDUINO/arduino-builder
  388. echo
  389. #read -t 5 -p "Press Enter..."
  390. echo
  391. if [ $OSTYPE == "msys" ]; then
  392. echo "Start to build Prusa Firmware under Windows..."
  393. echo "Using variant $VARIANT$(tput setaf 3)"
  394. sleep 2
  395. #$BUILDER -dump-prefs -logger=machine -hardware $ARDUINO/hardware -hardware $ARDUINO/portable/packages -tools $ARDUINO/tools-builder -tools $ARDUINO/hardware/tools/avr -tools $ARDUINO/portable/packages -built-in-libraries $ARDUINO/libraries -libraries $ARDUINO/portable/sketchbook/libraries -fqbn=rambo:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=none -quiet $SCRIPT_PATH/Firmware/Firmware.ino || exit 12
  396. #$BUILDER -compile -logger=machine -hardware $ARDUINO/hardware -hardware $ARDUINO/portable/packages -tools $ARDUINO/tools-builder -tools $ARDUINO/hardware/tools/avr -tools $ARDUINO/portable/packages -built-in-libraries $ARDUINO/libraries -libraries $ARDUINO/portable/sketchbook/libraries -fqbn=rambo:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=none -quiet $SCRIPT_PATH/Firmware/Firmware.ino || exit 13
  397. $BUILDER -compile -hardware $ARDUINO/hardware -hardware $ARDUINO/portable/packages -tools $ARDUINO/tools-builder -tools $ARDUINO/hardware/tools/avr -tools $ARDUINO/portable/packages -built-in-libraries $ARDUINO/libraries -libraries $ARDUINO/portable/sketchbook/libraries -fqbn=rambo:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=all $SCRIPT_PATH/Firmware/Firmware.ino || exit 14
  398. echo "$(tput sgr 0)"
  399. fi
  400. if [ $OSTYPE == "linux-gnu" ] ; then
  401. echo "Start to build Prusa Firmware under Linux 64..."
  402. echo "Using variant $VARIANT$(tput setaf 3)"
  403. sleep 2
  404. $BUILD_ENV_PATH/arduino $SCRIPT_PATH/Firmware/Firmware.ino --verify --board rambo:avr:rambo --pref build.path=$BUILD_PATH --pref compiler.warning_level=all || exit 14
  405. echo "$(tput sgr 0)"
  406. fi
  407. if [ $LANGUAGES == "ALL" ]; then
  408. echo "$(tput setaf 2)"
  409. echo "Building multi language firmware" $MULTI_LANGUAGE_CHECK
  410. echo "$(tput sgr 0)"
  411. sleep 2
  412. cd $SCRIPT_PATH/lang
  413. echo "$(tput setaf 3)"
  414. ./config.sh || exit 15
  415. echo "$(tput sgr 0)"
  416. # Check if previous languages and firmware build exist and if so clean them up
  417. if [ -f "lang_en.tmp" ]; then
  418. echo ""
  419. echo "$(tput setaf 6)Previous lang build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  420. read -t 10 -p "Press Enter to continue..."
  421. echo "$(tput setaf 3)"
  422. ./lang-clean.sh
  423. echo "$(tput sgr 0)"
  424. fi
  425. if [ -f "progmem.out" ]; then
  426. echo ""
  427. echo "$(tput setaf 6)Previous firmware build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  428. read -t 10 -p "Press Enter to continue..."
  429. echo "$(tput setaf 3)"
  430. ./fw-clean.sh
  431. echo "$(tput sgr 0)"
  432. fi
  433. # build languages
  434. echo "$(tput setaf 3)"
  435. ./lang-build.sh || exit 16
  436. # Combine compiled firmware with languages
  437. ./fw-build.sh || exit 17
  438. echo "$(tput sgr 0)"
  439. # Check if the motherboard is an EINSY and if so only one hex file will generated
  440. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  441. # If the motherboard is an EINSY just copy one hexfile
  442. if [ "$MOTHERBOARD" = "BOARD_EINSY_1_0a" ]; then
  443. echo "$(tput setaf 2)Copying multi language firmware for MK3/Einsy board to Hex-files folder$(tput sgr 0)"
  444. cp -f firmware.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex
  445. else
  446. echo "$(tput setaf 2)Zip multi language firmware for MK2.5/miniRAMbo board to Hex-files folder$(tput sgr 0)"
  447. cp -f firmware_cz.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-cz.hex
  448. cp -f firmware_de.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-de.hex
  449. cp -f firmware_es.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-es.hex
  450. cp -f firmware_fr.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-fr.hex
  451. cp -f firmware_it.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-it.hex
  452. cp -f firmware_pl.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-pl.hex
  453. if [ $OSTYPE == "msys" ]; then
  454. zip a $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  455. rm $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  456. elif [ $OSTYPE == "linux-gnu" ]; then
  457. zip -m -j ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  458. fi
  459. fi
  460. # Cleanup after build
  461. echo "$(tput setaf 3)"
  462. ./fw-clean.sh || exit 18
  463. ./lang-clean.sh || exit 19
  464. echo "$(tput sgr 0)"
  465. else
  466. echo "$(tput setaf 2)Copying English only firmware to Hex-files folder$(tput sgr 0)"
  467. cp -f $BUILD_PATH/Firmware.ino.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex || exit 20
  468. fi
  469. # Cleanup Firmware
  470. rm $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 17
  471. sed -i -- "s/^#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/g" $SCRIPT_PATH/Firmware/Configuration.h
  472. sed -i -- 's/^#define FW_REPOSITORY "Prusa3d"/#define FW_REPOSITORY "Unknown"/g' $SCRIPT_PATH/Firmware/Configuration.h
  473. echo $MULTI_LANGUAGE_CHECK
  474. #sed -i -- "s/^#define LANG_MODE * /#define LANG_MODE $MULTI_LANGUAGE_CHECK/g" $SCRIPT_PATH/Firmware/config.h
  475. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  476. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  477. sleep 5
  478. done
  479. # Cleanup compiler flags are set to Prusa specific needs for the rambo board.
  480. #if [ $OSTYPE == "msys" ]; then
  481. # echo " "
  482. # echo "Restore Windows platform.txt"
  483. # echo " "
  484. # cp -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE
  485. #fi
  486. # Switch to hex path and list build files
  487. cd $SCRIPT_PATH
  488. cd ..
  489. echo "$(tput setaf 2) "
  490. echo " "
  491. echo "Build done, please use Slic3rPE > 1.41.0 to upload the firmware"
  492. echo "more information how to flash firmware https://www.prusa3d.com/drivers/ $(tput sgr 0)"
  493. #### End building