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