build.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. #!/bin/bash
  2. # This bash script is used to compile automatically the Prusa firmware with a dedecated build enviroment and settings
  3. #
  4. # Supported OS: Windows 10, Linux64 bit
  5. #
  6. # Linux:
  7. #
  8. # Windows:
  9. # To excecute this sciprt 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. # Usefull 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 chage 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 chage 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 uknown
  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. ###Check if OSTYPE is supported
  75. if [ $OSTYPE == "msys" ]; then
  76. if [ $(uname -m) == "x86_64" ]; then
  77. echo "$(tput setaf 2)Windows 64-bit found$(tput sgr0)"
  78. fi
  79. elif [ $OSTYPE == "linux-gnu" ]; then
  80. if [ $(uname -m) == "x86_64" ]; then
  81. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  82. fi
  83. else
  84. echo "$(tput setaf 1)This script doesn't support your Operating system!"
  85. echo "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash"
  86. echo "Read the notes of build.sh$(tput sgr0)"
  87. exit
  88. fi
  89. sleep 2
  90. ###Prepare bash enviroment and check if wget and zip are availible
  91. if ! type wget > /dev/null; then
  92. echo "$(tput setaf 1)Missing 'wget' which is important to run this script"
  93. echo "Please follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058 to install wget$(tput sgr0)"
  94. exit
  95. fi
  96. if ! type zip > /dev/null; then
  97. if [ $OSTYPE == "msys" ]; then
  98. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  99. echo "Download and install 7z-zip from its official website https://www.7-zip.org/"
  100. echo "By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case."
  101. echo "Run git Bash under Administrator privilege and"
  102. echo "navigate to the directory /c/Program Files/Git/mingw64/bin,"
  103. echo "you can run the command $(tput setaf 2)ln -s /c/Program Files/7-Zip/7z.exe zip.exe$(tput sgr0)"
  104. exit
  105. elif [ $OSTYPE == "linux-gnu" ]; then
  106. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  107. echo "install it with the command $(tput setaf 2)'sudo apt-get install zip'$(tput sgr0)"
  108. exit
  109. fi
  110. fi
  111. ###End prepare bash enviroment
  112. BUILD_ENV="1.0.1"
  113. SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  114. # List few useful data
  115. echo
  116. echo "Script path:" $SCRIPT_PATH
  117. echo "OS :" $OS
  118. echo "OS type :" $OSTYPE
  119. echo ""
  120. #### Start prepare building
  121. #Check if build exists and creates it if not
  122. if [ ! -d "../build-env" ]; then
  123. mkdir ../build-env || exit 2
  124. fi
  125. cd ../build-env || exit 3
  126. # Check if PF-build-env-<version> exists and downloads + creates it if not
  127. # The build enviroment is based on the Arduino IDE 1.8.5 portal vesion with some changes
  128. if [ ! -d "../PF-build-env-$BUILD_ENV" ]; then
  129. echo "$(tput setaf 6)PF-build-env-$BUILD_ENV is missing ... creating it now for you$(tput sgr 0)"
  130. mkdir ../PF-build-env-$BUILD_ENV
  131. sleep 5
  132. fi
  133. if [ $OSTYPE == "msys" ]; then
  134. if [ ! -f "PF-build-env-Win-$BUILD_ENV.zip" ]; then
  135. echo "$(tput setaf 6)Downloding Windows build enviroment...$(tput setaf 2)"
  136. sleep 2
  137. wget https://github.com/3d-gussner/PF-build-env/releases/download/Win-$BUILD_ENV/PF-build-env-Win-$BUILD_ENV.zip || exit 4
  138. #cp -f ../../PF-build-env/PF-build-env-Win-$BUILD_ENV.zip PF-build-env-Win-$BUILD_ENV.zip || exit4
  139. echo "$(tput sgr 0)"
  140. fi
  141. if [ ! -d "../PF-build-env-$BUILD_ENV/$OSTYPE" ]; then
  142. echo "$(tput setaf 6)Unzipping Windows build enviroment...$(tput setaf 2)"
  143. sleep 2
  144. unzip PF-build-env-Win-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 4
  145. echo "$(tput sgr0)"
  146. fi
  147. fi
  148. if [ $OSTYPE == "linux-gnu" ]; then
  149. if [ ! -f "PF-build-env-Linux64-$BUILD_ENV.zip" ]; then
  150. echo "$(tput setaf 6)Downloading Linux 64 build enviroment...$(tput setaf 2)"
  151. sleep 2
  152. wget https://github.com/mkbel/PF-build-env/releases/download/$BUILD_ENV/PF-build-env-Linux64-$BUILD_ENV.zip || exit 3
  153. echo "$(tput sgr0)"
  154. fi
  155. if [ ! -d "../PF-build-env-$BUILD_ENV/$OSTYPE" ]; then
  156. echo "$(tput setaf 6)Unzipping Linux build enviroment...$(tput setaf 2)"
  157. sleep 2
  158. unzip PF-build-env-Linux64-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 4
  159. echo "$(tput sgr0)"
  160. fi
  161. fi
  162. cd $SCRIPT_PATH
  163. # First argument defines which varaint of the Prusa Firmware will be compiled
  164. if [ -z "$1" ] ; then
  165. # Select which varaint of the Prusa Firmware will be compiled, like
  166. PS3="Select a variant: "
  167. while IFS= read -r -d $'\0' f; do
  168. options[i++]="$f"
  169. done < <(find Firmware/variants/ -maxdepth 1 -type f -name "*.h" -print0 )
  170. select opt in "${options[@]}" "All" "Quit"; do
  171. case $opt in
  172. *.h)
  173. VARIANT=$(basename "$opt" ".h")
  174. VARIANTS[i++]="$opt"
  175. break
  176. ;;
  177. "All")
  178. VARIANT="All"
  179. VARIANTS=${options[*]}
  180. break
  181. ;;
  182. "Quit")
  183. echo "You chose to stop"
  184. exit 1
  185. ;;
  186. *)
  187. echo "$(tput setaf 1)This is not a valid variant$(tput sgr0)"
  188. ;;
  189. esac
  190. done
  191. else
  192. VARIANT=$1
  193. fi
  194. #Second argument defines if it is an english only version. Known values EN_ONLY / ALL
  195. #Check default language mode
  196. MULTI_LANGUAGE_CHECK=$(grep --max-count=1 "^#define LANG_MODE *" $SCRIPT_PATH/Firmware/config.h|sed -e's/ */ /g'|cut -d ' ' -f3)
  197. if [ -z "$2" ] ; then
  198. PS3="Select a language: "
  199. echo
  200. echo "Which lang-build do you want?"
  201. select yn in "Multi languages" "English only"; do
  202. case $yn in
  203. "Multi languages")
  204. LANGUAGES="ALL"
  205. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE 1/g" $SCRIPT_PATH/Firmware/config.h
  206. break
  207. ;;
  208. "English only")
  209. LANGUAGES="EN_ONLY"
  210. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE 0/g" $SCRIPT_PATH/Firmware/config.h
  211. break
  212. ;;
  213. *)
  214. echo "$(tput setaf 1)This is not a valid language$(tput sgr0)"
  215. ;;
  216. esac
  217. done
  218. else
  219. LANGUAGES=$2
  220. fi
  221. #Set BUILD_ENV_PATH
  222. cd ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 5
  223. BUILD_ENV_PATH="$( pwd -P )"
  224. cd ../..
  225. #Checkif BUILD_PATH exisits and if not creates it
  226. if [ ! -d "Prusa-Firmware-build" ]; then
  227. mkdir Prusa-Firmware-build || exit 6
  228. fi
  229. #Set the BUILD_PATH for Arduino IDE
  230. cd Prusa-Firmware-build || exit 7
  231. BUILD_PATH="$( pwd -P )"
  232. for v in ${VARIANTS[*]}
  233. do
  234. VARIANT=$(basename "$v" ".h")
  235. # Find firmware version in Configuration.h file and use it to generate the hex filename
  236. FW=$(grep --max-count=1 "\bFW_VERSION\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d '"' -f2|sed 's/\.//g')
  237. # Find build version in Configuration.h file and use it to generate the hex filename
  238. BUILD=$(grep --max-count=1 "\bFW_COMMIT_NR\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d ' ' -f3)
  239. # Check if the motherboard is an EINSY and if so the only one hex file will generated
  240. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  241. # Check development status
  242. 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)
  243. if [ -z "$DEV_STATUS_SELECTED" ] ; then
  244. if [[ "$DEV_CHECK" == "RC1" || "$DEV_CHECK" == "RC2" ]] ; then
  245. DEV_STATUS="RC"
  246. elif [[ "$DEV_CHECK" == "ALPHA" ]]; then
  247. DEV_STATUS="ALPHA"
  248. elif [[ "$DEV_CHECK" == "BETA" ]]; then
  249. DEV_STATUS="BETA"
  250. elif [[ "$DEV_CHECK" == "DEVEL" ]]; then
  251. DEV_STATUS="DEVEL"
  252. elif [[ "$DEV_CHECK" == "DEBUG" ]]; then
  253. DEV_STATUS="DEBUG"
  254. else
  255. DEV_STATUS="UNKNOWN"
  256. echo
  257. echo "$(tput setaf 5)DEV_STATUS is UNKNOWN. Do you wish to set DEV_STATUS to GOLD?$(tput sgr0)"
  258. PS3="Select YES only if source code is tested and trusted: "
  259. select yn in "Yes" "No"; do
  260. case $yn in
  261. Yes)
  262. DEV_STATUS="GOLD"
  263. DEV_STATUS_SELECTED="GOLD"
  264. break
  265. ;;
  266. No)
  267. DEV_STATUS="UNKNOWN"
  268. DEV_STATUS_SELECTED="UNKNOWN"
  269. break
  270. ;;
  271. *)
  272. echo "$(tput setaf 1)This is not a valid DEV_STATUS$(tput sgr0)"
  273. ;;
  274. esac
  275. done
  276. fi
  277. else
  278. DEV_STATUS=$DEV_STATUS_SELECTED
  279. fi
  280. #Prepare hex files folders
  281. if [ ! -d "$SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD" ]; then
  282. mkdir -p $SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD || exit 10
  283. fi
  284. OUTPUT_FOLDER="Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD"
  285. #Check if exacly the same hexfile already exsits
  286. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex" && "$LANGUAGES" == "ALL" ]]; then
  287. echo ""
  288. ls $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex
  289. echo "$(tput setaf 6)This hex file to be comiled already exsits! To cancle this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  290. read -t 10 -p "Press any key to continue..."
  291. elif [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex" && "$LANGUAGES" == "EN_ONLY" ]]; then
  292. echo ""
  293. ls $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex
  294. echo "$(tput setaf 6)This hex file to be comiled already exsits! To cancle this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  295. read -t 10 -p "Press any key to continue..."
  296. fi
  297. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip" && "$LANGUAGES" == "ALL" ]]; then
  298. echo ""
  299. ls $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip
  300. echo "$(tput setaf 6)This zip file to be comiled already exsits! To cancle this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  301. read -t 10 -p "Press any key to continue..."
  302. fi
  303. #List some useful data
  304. echo "$(tput setaf 2)$(tput setab 7) "
  305. echo "Variant :" $VARIANT
  306. echo "Firmware :" $FW
  307. echo "Build # :" $BUILD
  308. echo "Dev Check :" $DEV_CHECK
  309. echo "DEV Status :" $DEV_STATUS
  310. echo "Motherboard:" $MOTHERBOARD
  311. echo "Languages :" $LANGUAGES
  312. echo "Hex-file Folder:" $OUTPUT_FOLDER
  313. echo "$(tput sgr0)"
  314. #Prepare Firmware to be compiled by copying variant as Configuration_prusa.h
  315. if [ ! -f "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then
  316. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11
  317. else
  318. echo "$(tput setaf 6)Configuration_prusa.h already exist it will be overwritten in 10 seconds by the chosen variant.$(tput sgr 0)"
  319. read -t 10 -p "Press any key to continue..."
  320. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11
  321. fi
  322. #Prepare Configuration.h to use the correct FW_DEV_VERSION to prevent LCD messages when connecting with OctoPrint
  323. sed -i -- "s/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/g" $SCRIPT_PATH/Firmware/Configuration.h
  324. # set FW_REPOSITORY
  325. sed -i -- 's/#define FW_REPOSITORY "Unknown"/#define FW_REPOSITORY "Prusa3d"/g' $SCRIPT_PATH/Firmware/Configuration.h
  326. #Prepare english only or multilanguage version to be build
  327. if [ $LANGUAGES == "ALL" ]; then
  328. echo " "
  329. echo "Multi-language firmware will be build"
  330. echo " "
  331. else
  332. echo " "
  333. echo "English only language firmware will be build"
  334. echo " "
  335. fi
  336. #Check if compiler flags are set to Prusa specific needs for the rambo board.
  337. if [ $OSTYPE == "msys" ]; then
  338. RAMBO_PLATFORM_FILE="rambo/hardware/avr/1.0.1/platform.txt"
  339. COMP_FLAGS="compiler.c.elf.flags={compiler.warning_flags} -Os -g -flto -fuse-linker-plugin -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections"
  340. CHECK_FLAGS=$(grep --max-count=1 "$COMP_FLAGS" $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE)
  341. if [ -z "$CHECK_FLAGS" ]; then
  342. echo "Compiler flags not found, adding flags"
  343. if [ ! -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck ]; then
  344. echo "making a backup"
  345. ls $BUILD_ENV_PATH/portable/packages/rambo/hardware/avr/1.0.1/
  346. cp -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck
  347. fi
  348. echo $COMP_FLAGS >> $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE
  349. else
  350. echo "Compiler flags are set in rambo platform.txt" $CHECK_FLAGS
  351. fi
  352. fi
  353. #### End of Prepare building
  354. #### Start building
  355. export ARDUINO=$BUILD_ENV_PATH
  356. #echo $BUILD_ENV_PATH
  357. export BUILDER=$ARDUINO/arduino-builder
  358. echo
  359. #read -t 5 -p "Press any key..."
  360. echo
  361. if [ $OSTYPE == "msys" ]; then
  362. echo "Start to build Prusa Firmware under Windows..."
  363. echo "Using variant $VARIANT$(tput setaf 3)"
  364. sleep 2
  365. #$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
  366. #$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
  367. $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=default $SCRIPT_PATH/Firmware/Firmware.ino || exit 14
  368. echo "$(tput sgr 0)"
  369. fi
  370. if [ $OSTYPE == "linux-gnu" ] ; then
  371. echo "Start to build Prusa Firmware under Linux 64..."
  372. echo "Using variant $VARIANT$(tput setaf 3)"
  373. sleep 2
  374. $BUILD_ENV_PATH/arduino $SCRIPT_PATH/Firmware/Firmware.ino --verify --board rambo:avr:rambo --pref build.path=$BUILD_PATH || exit 14
  375. echo "$(tput sgr 0)"
  376. fi
  377. if [ $LANGUAGES == "ALL" ]; then
  378. echo "$(tput setaf 2)"
  379. echo "Building mutli language firmware" $MULTI_LANGUAGE_CHECK
  380. echo "$(tput sgr 0)"
  381. sleep 2
  382. cd $SCRIPT_PATH/lang
  383. echo "$(tput setaf 3)"
  384. ./config.sh || exit 15
  385. echo "$(tput sgr 0)"
  386. # Check if privious languages and firmware build exist and if so clean them up
  387. if [ -f "lang_en.tmp" ]; then
  388. echo ""
  389. echo "$(tput setaf 6)Previous lang build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  390. read -t 10 -p "Press any key to continue..."
  391. echo "$(tput setaf 3)"
  392. ./lang-clean.sh
  393. echo "$(tput sgr 0)"
  394. fi
  395. if [ -f "progmem.out" ]; then
  396. echo ""
  397. echo "$(tput setaf 6)Previous firmware build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  398. read -t 10 -p "Press any key to continue..."
  399. echo "$(tput setaf 3)"
  400. ./fw-clean.sh
  401. echo "$(tput sgr 0)"
  402. fi
  403. # build languages
  404. echo "$(tput setaf 3)"
  405. ./lang-build.sh || exit 16
  406. # Combine compiled firmware with languages
  407. ./fw-build.sh || exit 17
  408. echo "$(tput sgr 0)"
  409. # Check if the motherboard is an EINSY and if so the only one hex file will generated
  410. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  411. # If the motherboard is an EINSY just copy one hexfile
  412. if [ "$MOTHERBOARD" = "BOARD_EINSY_1_0a" ]; then
  413. echo "$(tput setaf 2)Copying multi language firmware for MK3/Einsy board to Hex-files folder$(tput sgr 0)"
  414. cp -f firmware.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex
  415. else
  416. echo "$(tput setaf 2)Zip multi language firmware for MK2.5/miniRAMbo board to Hex-files folder$(tput sgr 0)"
  417. cp -f firmware_cz.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-cz.hex
  418. cp -f firmware_de.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-de.hex
  419. cp -f firmware_es.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-es.hex
  420. cp -f firmware_fr.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-fr.hex
  421. cp -f firmware_it.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-it.hex
  422. cp -f firmware_pl.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-pl.hex
  423. if [ $OSTYPE == "msys" ]; then
  424. zip a $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  425. rm $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  426. elif [ $OSTYPE == "linux-gnu" ]; then
  427. zip -m -j ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  428. fi
  429. fi
  430. # Cleanup after build
  431. echo "$(tput setaf 3)"
  432. ./fw-clean.sh || exit 18
  433. ./lang-clean.sh || exit 19
  434. echo "$(tput sgr 0)"
  435. else
  436. echo "$(tput setaf 2)Copying English only firmware to Hex-files folder$(tput sgr 0)"
  437. cp -f $BUILD_PATH/Firmware.ino.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex || exit 20
  438. fi
  439. # Cleanup Firmware
  440. rm $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 17
  441. sed -i -- "s/^#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/g" $SCRIPT_PATH/Firmware/Configuration.h
  442. sed -i -- 's/^#define FW_REPOSITORY "Prusa3d"/#define FW_REPOSITORY "Unknown"/g' $SCRIPT_PATH/Firmware/Configuration.h
  443. echo $MULTI_LANGUAGE_CHECK
  444. #sed -i -- "s/^#define LANG_MODE * /#define LANG_MODE $MULTI_LANGUAGE_CHECK/g" $SCRIPT_PATH/Firmware/config.h
  445. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  446. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  447. sleep 5
  448. done
  449. # Cleanup compiler flags are set to Prusa specific needs for the rambo board.
  450. #if [ $OSTYPE == "msys" ]; then
  451. # echo " "
  452. # echo "Restore Windows platform.txt"
  453. # echo " "
  454. # cp -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE
  455. #fi
  456. # Switch to hex path and list build files
  457. cd $SCRIPT_PATH
  458. cd ..
  459. echo "$(tput setaf 2) "
  460. echo " "
  461. echo "Build done, please use Slic3rPE > 1.41.0 to upload the firmware"
  462. echo "more information how to flash firmware https://www.prusa3d.com/drivers/ $(tput sgr 0)"
  463. #### End building