config.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/bin/bash
  2. #
  3. # Version 1.0.1 Build 10
  4. #
  5. # config.sh - multi-language support configuration script
  6. # Definition of absolute paths etc.
  7. # This file is 'included' in all scripts.
  8. #
  9. #############################################################################
  10. # Change log:
  11. # 31 May 2018, XPila, Initial
  12. # 17 Dec. 2021, 3d-gussner, Change default Arduino path to by PF-build.sh
  13. # created one
  14. # Prepare to use one config file for all languages
  15. # 11 Jan. 2022, 3d-gussner, Added version and Change log colored output
  16. # Use `git rev-list --count HEAD config.sh`
  17. # to get Build Nr
  18. # Check if variables are set by other scripts
  19. # and use these. More flexible for different build
  20. # scripts
  21. # Check correctly if files or dirs exist
  22. # 10 Feb. 2022, 3d-gussner, Add SRCDIR for compatibility with build server
  23. #############################################################################
  24. #
  25. if [ -z "$SRCDIR" ]; then
  26. export SRCDIR=".."
  27. fi
  28. LNGDIR="$( cd "$(dirname "$0")" ; pwd -P )"
  29. export LNGDIR=$LNGDIR
  30. # Arduino main folder:
  31. if [ -z "$ARDUINO" ]; then
  32. export ARDUINO=../../PF-build-env-1.0.6/1.8.5-1.0.4-linux-64 #C:/arduino-1.8.5
  33. fi
  34. #
  35. # Arduino builder:
  36. if [ -z "$BUILDER" ]; then
  37. export BUILDER=$ARDUINO/arduino-builder
  38. fi
  39. #
  40. # AVR gcc tools:
  41. if [ -z "$OBJCOPY" ]; then
  42. export OBJCOPY=$ARDUINO/hardware/tools/avr/bin/avr-objcopy
  43. fi
  44. if [ -z "$OBJDUMP" ]; then
  45. export OBJDUMP=$ARDUINO/hardware/tools/avr/bin/avr-objdump
  46. fi
  47. #
  48. # Output folder:
  49. if [ -z "$OUTDIR" ]; then
  50. export OUTDIR="../../Prusa-Firmware-build"
  51. fi
  52. #
  53. # Objects folder:
  54. if [ -z "$OBJDIR" ]; then
  55. export OBJDIR="$OUTDIR/sketch"
  56. fi
  57. #
  58. # Generated elf file:
  59. if [ -z "$INOELF" ]; then
  60. export INOELF="$OUTDIR/Firmware.ino.elf"
  61. fi
  62. #
  63. # Generated hex file:
  64. if [ -z "$INOHEX" ]; then
  65. export INOHEX="$OUTDIR/Firmware.ino.hex"
  66. fi
  67. #
  68. # Set default languages
  69. if [ -z "$LANGUAGES" ]; then
  70. export LANGUAGES="cz de es fr it pl"
  71. fi
  72. #
  73. # Check for community languages
  74. MAX_COMMINITY_LANG=10 # Total 16 - 6 default
  75. COMMUNITY_LANGUAGES=""
  76. #Search Firmware/config.h for active community group
  77. COMMUNITY_LANG_GROUP=$(grep --max-count=1 "^#define COMMUNITY_LANG_GROUP" $SRCDIR/Firmware/config.h| cut -d ' ' -f3)
  78. # Search Firmware/config.h for active community languanges
  79. if [ "$COMMUNITY_LANG_GROUP" = "1" ]; then
  80. COMMUNITY_LANGUAGES=$(grep --max-count=$MAX_COMMINITY_LANG "^#define COMMUNITY_LANG_GROUP1_" $SRCDIR/Firmware/config.h| cut -d '_' -f4 |cut -d ' ' -f1 |tr '[:upper:]' '[:lower:]'| tr '\n' ' ')
  81. elif [ "$COMMUNITY_LANG_GROUP" = "2" ]; then
  82. COMMUNITY_LANGUAGES=$(grep --max-count=$MAX_COMMINITY_LANG "^#define COMMUNITY_LANG_GROUP2_" $SRCDIR/Firmware/config.h| cut -d '_' -f4 |cut -d ' ' -f1 |tr '[:upper:]' '[:lower:]'| tr '\n' ' ')
  83. elif [ "$COMMUNITY_LANG_GROUP" = "3" ]; then
  84. COMMUNITY_LANGUAGES=$(grep --max-count=$MAX_COMMINITY_LANG "^#define COMMUNITY_LANG_GROUP3_" $SRCDIR/Firmware/config.h| cut -d '_' -f4 |cut -d ' ' -f1 |tr '[:upper:]' '[:lower:]'| tr '\n' ' ')
  85. fi
  86. if [ -z "$COMMUNITY_LANGUAGES" ]; then
  87. export COMMUNITY_LANGUAGES="$COMMUNITY_LANGUAGES"
  88. fi
  89. echo "$(tput setaf 2)config.sh started$(tput sgr0)" >&2
  90. _err=0
  91. echo -n " Arduino main folder: " >&2
  92. if [ -d $ARDUINO ]; then echo "$(tput setaf 2)OK$(tput sgr0)" >&2; else echo "$(tput setaf 1)NG!$(tput sgr0)" >&2; _err=1; fi
  93. echo -n " Arduino builder: " >&2
  94. if [ -e $BUILDER ]; then echo "$(tput setaf 2)OK$(tput sgr0)" >&2; else echo "$(tput setaf 1)NG!$(tput sgr0)" >&2; _err=2; fi
  95. echo " AVR gcc tools:" >&2
  96. echo -n " objcopy " >&2
  97. if [ -e $OBJCOPY ]; then echo "$(tput setaf 2)OK$(tput sgr0)" >&2; else echo "$(tput setaf 1)NG!$(tput sgr0)" >&2; _err=3; fi
  98. echo -n " objdump " >&2
  99. if [ -e $OBJDUMP ]; then echo "$(tput setaf 2)OK$(tput sgr0)" >&2; else echo "$(tput setaf 1)NG!$(tput sgr0)" >&2; _err=4; fi
  100. echo -n " Output folder: " >&2
  101. if [ -d $OUTDIR ]; then echo "$(tput setaf 2)OK$(tput sgr0)" >&2; else echo "$(tput setaf 1)NG!$(tput sgr0)" >&2; _err=5; fi
  102. echo -n " Objects folder: " >&2
  103. if [ -d $OBJDIR ]; then echo "$(tput setaf 2)OK$(tput sgr0)" >&2; else echo "$(tput setaf 1)NG!$(tput sgr0)" >&2; _err=6; fi
  104. echo -n " Generated elf file: " >&2
  105. if [ -e $INOELF ]; then echo "$(tput setaf 2)OK$(tput sgr0)" >&2; else echo "$(tput setaf 1)NG!$(tput sgr0)" >&2; _err=7; fi
  106. echo -n " Generated hex file: " >&2
  107. if [ -e $INOHEX ]; then echo "$(tput setaf 2)OK$(tput sgr0)" >&2; else echo "$(tput setaf 1)NG!$(tput sgr0)" >&2; _err=8; fi
  108. echo -n " Languages: " >&2
  109. echo "$(tput setaf 2)$LANGUAGES$(tput sgr0)" >&2
  110. echo -n " Community languages: " >&2
  111. echo "$(tput setaf 2)$COMMUNITY_LANGUAGES$(tput sgr0)" >&2
  112. if [ $_err -eq 0 ]; then
  113. echo "$(tput setaf 2)config.sh finished with success$(tput sgr0)" >&2
  114. export CONFIG_OK=1
  115. else
  116. echo "$(tput setaf 1)config.sh finished with errors!$(tput sgr0)" >&2
  117. export CONFIG_OK=0
  118. fi