chibios_conf_updater.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env bash
  2. set -eEuo pipefail
  3. umask 022
  4. #####################
  5. # You will need to get an older JDK -- JDK 8
  6. #
  7. # !!!!!!!! DO NOT INSTALL THIS IF YOU HAVE AN EXISTING JDK OR JRE INSTALLED !!!!!!!!
  8. #
  9. # For Debian 10-ish distro's:
  10. # wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
  11. # sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
  12. # sudo apt-get update && sudo apt-get install adoptopenjdk-8-hotspot
  13. #
  14. # For Fedora 36-ish distros:
  15. # # Prep yum repository from https://adoptium.net/installation/linux/
  16. # sudo dnf install -y ant temurin-8-jdk
  17. # export JAVA_HOME=/usr/lib/jvm/temurin-8-jdk
  18. sinfo() { echo "$@" >&2 ; }
  19. shead() { sinfo "" ; sinfo "---------------------------------" ; sinfo "-- $@" ; sinfo "---------------------------------" ; }
  20. this_script="$(realpath "${BASH_SOURCE[0]}")"
  21. script_dir="$(realpath "$(dirname "$this_script")")"
  22. qmk_firmware_dir="$(realpath "$script_dir/../")"
  23. export PATH="$PATH:$script_dir/fmpp/bin"
  24. build_fmpp() {
  25. [ -f "$script_dir/fmpp.tar.gz" ] \
  26. || wget -O"$script_dir/fmpp.tar.gz" https://github.com/freemarker/fmpp/archive/v0.9.16.tar.gz
  27. [ -d "$script_dir/fmpp" ] \
  28. || { mkdir "$script_dir/fmpp" && tar xf "$script_dir/fmpp.tar.gz" -C "$script_dir/fmpp" --strip-components=1 ; }
  29. pushd "$script_dir/fmpp" >/dev/null 2>&1
  30. sed -e "s#bootclasspath.path=.*#bootclasspath.path=$(find /usr/lib/jvm -name 'rt.jar' | sort | tail -n1)#g" \
  31. -e "s#ant.jar.path=.*#ant.jar.path=$(find /usr/share/java -name 'ant-1*.jar' -or -name 'ant.jar' | sort | tail -n1)#g" \
  32. build.properties.sample > build.properties
  33. sed -e 's#source="1.5"#source="1.8"#g' \
  34. -e 's#target="1.5"#target="1.8"#g' \
  35. build.xml > build.xml.new
  36. mv build.xml.new build.xml
  37. ant clean
  38. ant
  39. chmod +x "$script_dir/fmpp/bin/fmpp"
  40. popd >/dev/null 2>&1
  41. }
  42. find_chibi_files() {
  43. local search_path="$1"
  44. shift
  45. local conditions=( "$@" )
  46. for file in $(find -L "$search_path" -not -path '*/lib/chibios*' -and -not -path '*/util/*' -and \( "${conditions[@]}" \) | sort) ; do
  47. if [ -z "$(grep 'include_next' "$file")" ] ; then
  48. echo $file
  49. fi
  50. done
  51. }
  52. upgrade_conf_files_generic() {
  53. local search_filename="$1"
  54. local update_script="$2"
  55. shead "Updating $search_filename files ($update_script)..."
  56. pushd "$qmk_firmware_dir/lib/chibios/tools/updater" >/dev/null 2>&1
  57. for file in $(find_chibi_files "$qmk_firmware_dir" -name "$search_filename") ; do
  58. cp -f "$file" "$file.orig"
  59. clang-format --style='{IndentPPDirectives: None}' -i "$file"
  60. cp -f "$file" "$file.formatted"
  61. bash "$update_script" "$file"
  62. if ! diff "$file" "$file.formatted" >/dev/null 2>&1 ; then
  63. dos2unix "$file" >/dev/null 2>&1
  64. else
  65. cp -f "$file.orig" "$file"
  66. fi
  67. rm -f "$file.orig" "$file.formatted"
  68. done
  69. popd >/dev/null 2>&1
  70. }
  71. upgrade_chconf_files() {
  72. upgrade_conf_files_generic chconf.h update_chconf_rt.sh
  73. }
  74. upgrade_halconf_files() {
  75. upgrade_conf_files_generic halconf.h update_halconf.sh
  76. OIFS=$IFS
  77. IFS=$'\n'
  78. for file in $(find_chibi_files "$qmk_firmware_dir" -name halconf.h) ; do
  79. echo $file
  80. sed -i 's@#include "mcuconf.h"@#include <mcuconf.h>@g' "$file"
  81. done
  82. IFS=$OIFS
  83. }
  84. upgrade_mcuconf_files() {
  85. pushd "$qmk_firmware_dir/lib/chibios/tools/updater" >/dev/null 2>&1
  86. for f in $(find . -name 'update_mcuconf*') ; do
  87. upgrade_conf_files_generic mcuconf.h $f
  88. done
  89. popd >/dev/null 2>&1
  90. }
  91. hash -r
  92. [[ -n "$(which fmpp 2>/dev/null)" ]] || build_fmpp
  93. upgrade_mcuconf_files
  94. upgrade_chconf_files
  95. upgrade_halconf_files