You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.6 KiB

  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 37-ish distros:
  15. # sudo dnf install -y ant java-1.8.0-openjdk.x86_64
  16. sinfo() { echo "$@" >&2 ; }
  17. shead() { sinfo "" ; sinfo "---------------------------------" ; sinfo "-- $@" ; sinfo "---------------------------------" ; }
  18. this_script="$(realpath "${BASH_SOURCE[0]}")"
  19. script_dir="$(realpath "$(dirname "$this_script")")"
  20. qmk_firmware_dir="$(realpath "$script_dir/../")"
  21. export PATH="$PATH:$script_dir/fmpp/bin"
  22. build_fmpp() {
  23. [ -f "$script_dir/fmpp.tar.gz" ] \
  24. || wget -O"$script_dir/fmpp.tar.gz" https://github.com/freemarker/fmpp/archive/v0.9.16.tar.gz
  25. [ -d "$script_dir/fmpp" ] \
  26. || { mkdir "$script_dir/fmpp" && tar xf "$script_dir/fmpp.tar.gz" -C "$script_dir/fmpp" --strip-components=1 ; }
  27. pushd "$script_dir/fmpp" >/dev/null 2>&1
  28. sed -e "s#bootclasspath.path=.*#bootclasspath.path=$(find /usr/lib/jvm -name 'rt.jar' | sort | tail -n1)#g" \
  29. -e "s#ant.jar.path=.*#ant.jar.path=$(find /usr/share/java -name 'ant-1*.jar' -or -name 'ant.jar' | sort | tail -n1)#g" \
  30. build.properties.sample > build.properties
  31. sed -e 's#source="1.5"#source="1.8"#g' \
  32. -e 's#target="1.5"#target="1.8"#g' \
  33. build.xml > build.xml.new
  34. mv build.xml.new build.xml
  35. ant clean
  36. ant
  37. chmod +x "$script_dir/fmpp/bin/fmpp"
  38. popd >/dev/null 2>&1
  39. }
  40. find_chibi_files() {
  41. local search_path="$1"
  42. shift
  43. local conditions=( "$@" )
  44. for file in $(find -L "$search_path" -not -path '*/lib/chibios*' -and -not -path '*/util/*' -and \( "${conditions[@]}" \) | sort) ; do
  45. if [ -z "$(grep 'include_next' "$file")" ] ; then
  46. echo $file
  47. fi
  48. done
  49. }
  50. upgrade_conf_files_generic() {
  51. local search_filename="$1"
  52. local update_script="$2"
  53. shead "Updating $search_filename files ($update_script)..."
  54. pushd "$qmk_firmware_dir/lib/chibios/tools/updater" >/dev/null 2>&1
  55. for file in $(find_chibi_files "$qmk_firmware_dir" -name "$search_filename") ; do
  56. cp -f "$file" "$file.orig"
  57. clang-format --style='{IndentPPDirectives: None}' -i "$file"
  58. cp -f "$file" "$file.formatted"
  59. bash "$update_script" "$file"
  60. if ! diff "$file" "$file.formatted" >/dev/null 2>&1 ; then
  61. dos2unix "$file" >/dev/null 2>&1
  62. else
  63. cp -f "$file.orig" "$file"
  64. fi
  65. rm -f "$file.orig" "$file.formatted"
  66. done
  67. popd >/dev/null 2>&1
  68. }
  69. upgrade_chconf_files() {
  70. upgrade_conf_files_generic chconf.h update_chconf_rt.sh
  71. }
  72. upgrade_halconf_files() {
  73. upgrade_conf_files_generic halconf.h update_halconf.sh
  74. OIFS=$IFS
  75. IFS=$'\n'
  76. for file in $(find_chibi_files "$qmk_firmware_dir" -name halconf.h) ; do
  77. echo $file
  78. sed -i 's@#include "mcuconf.h"@#include <mcuconf.h>@g' "$file"
  79. done
  80. IFS=$OIFS
  81. }
  82. upgrade_mcuconf_files() {
  83. pushd "$qmk_firmware_dir/lib/chibios/tools/updater" >/dev/null 2>&1
  84. for f in $(find . -name 'update_mcuconf*') ; do
  85. upgrade_conf_files_generic mcuconf.h $f
  86. done
  87. popd >/dev/null 2>&1
  88. }
  89. hash -r
  90. [[ -n "$(which fmpp 2>/dev/null)" ]] || build_fmpp
  91. upgrade_mcuconf_files
  92. upgrade_chconf_files
  93. upgrade_halconf_files