config.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. # AVR gcc tools:
  36. if [ -z "$OBJCOPY" ]; then
  37. export OBJCOPY=$ARDUINO/hardware/tools/avr/bin/avr-objcopy
  38. fi
  39. #
  40. # Output folder:
  41. if [ -z "$OUTDIR" ]; then
  42. export OUTDIR="../../Prusa-Firmware-build"
  43. fi
  44. #
  45. # Output elf file:
  46. if [ -z "$INOELF" ]; then
  47. export INOELF="$OUTDIR/Firmware.ino.elf"
  48. fi
  49. #
  50. # Output hex file:
  51. if [ -z "$INOHEX" ]; then
  52. export INOHEX="$OUTDIR/Firmware.ino.hex"
  53. fi
  54. #
  55. # Generated multi-language hex file prefix:
  56. if [ -z "$INTLHEX" ]; then
  57. export INTLHEX="$LNGDIR/Firmware-intl"
  58. fi
  59. #
  60. # Set default languages
  61. if [ -z "$LANGUAGES" ]; then
  62. export LANGUAGES="cs de es fr it pl"
  63. fi
  64. #
  65. # Check for community languages
  66. MAX_COMMINITY_LANG=10 # Total 16 - 6 default
  67. COMMUNITY_LANGUAGES=""
  68. #Search Firmware/config.h for active community group
  69. COMMUNITY_LANG_GROUP=$(grep --max-count=1 "^#define COMMUNITY_LANG_GROUP" $SRCDIR/Firmware/config.h| cut -d ' ' -f3)
  70. # Search Firmware/config.h for active community languanges
  71. if [ "$COMMUNITY_LANG_GROUP" = "1" ]; then
  72. 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' ' ')
  73. elif [ "$COMMUNITY_LANG_GROUP" = "2" ]; then
  74. 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' ' ')
  75. elif [ "$COMMUNITY_LANG_GROUP" = "3" ]; then
  76. 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' ' ')
  77. fi
  78. # End of customization
  79. ######################
  80. if [ -z "$COMMUNITY_LANGUAGES" ]; then
  81. export COMMUNITY_LANGUAGES="$COMMUNITY_LANGUAGES"
  82. fi
  83. if [ ! -t 2 -o "$TERM" = "dumb" ]; then
  84. NO_COLOR=1
  85. fi
  86. color()
  87. {
  88. color=$1
  89. shift
  90. if [ "$NO_COLOR" = 0 -o -z "$NO_COLOR" ]; then
  91. echo "$(tput setaf $color)$*$(tput sgr 0)"
  92. else
  93. echo "$*"
  94. fi
  95. }
  96. ok() { color 2 "OK"; }
  97. ng() { color 1 "NG!"; }
  98. color 2 "config.sh started" >&2
  99. _err=0
  100. echo -n " Arduino main folder: " >&2
  101. if [ -d $ARDUINO ]; then ok >&2; else ng >&2; _err=1; fi
  102. echo " AVR gcc tools:" >&2
  103. echo -n " objcopy " >&2
  104. if [ -e $OBJCOPY ]; then ok >&2; else ng >&2; _err=3; fi
  105. echo -n " Output folder: " >&2
  106. if [ -d $OUTDIR ]; then ok >&2; else ng >&2; _err=5; fi
  107. echo -n " Output elf file: " >&2
  108. if [ -e $INOELF ]; then ok >&2; else ng >&2; _err=7; fi
  109. echo -n " Output hex file: " >&2
  110. if [ -e $INOHEX ]; then ok >&2; else ng >&2; _err=8; fi
  111. echo -n " Intl hex file prefix: " >&2
  112. if [ -n $INTLHEX ]; then ok >&2; else ng >&2; _err=8; fi
  113. echo -n " Languages: " >&2
  114. color 2 "$LANGUAGES" >&2
  115. echo -n " Community languages: " >&2
  116. color 2 "$COMMUNITY_LANGUAGES" >&2
  117. if [ $_err -eq 0 ]; then
  118. color 2 "config.sh finished with success" >&2
  119. export CONFIG_OK=1
  120. else
  121. color 1 "config.sh finished with errors!" >&2
  122. export CONFIG_OK=0
  123. fi