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.

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