aboutsummaryrefslogtreecommitdiff
path: root/util/chibios_conf_updater.sh
diff options
context:
space:
mode:
authorAkshay <[email protected]>2022-04-10 12:13:40 +0100
committerAkshay <[email protected]>2022-04-10 12:13:40 +0100
commitdc90387ce7d8ba7b607d9c48540bf6d8b560f14d (patch)
tree4ccb8fa5886b66fa9d480edef74236c27f035e16 /util/chibios_conf_updater.sh
Diffstat (limited to 'util/chibios_conf_updater.sh')
-rwxr-xr-xutil/chibios_conf_updater.sh105
1 files changed, 105 insertions, 0 deletions
diff --git a/util/chibios_conf_updater.sh b/util/chibios_conf_updater.sh
new file mode 100755
index 000000000..a5699ca3c
--- /dev/null
+++ b/util/chibios_conf_updater.sh
@@ -0,0 +1,105 @@
1#!/usr/bin/env bash
2
3set -eEuo pipefail
4umask 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
17sinfo() { echo "$@" >&2 ; }
18shead() { sinfo "" ; sinfo "---------------------------------" ; sinfo "-- $@" ; sinfo "---------------------------------" ; }
19havecmd() { command command type "${1}" >/dev/null 2>&1 || return 1 ; }
20
21this_script="$(realpath "${BASH_SOURCE[0]}")"
22script_dir="$(realpath "$(dirname "$this_script")")"
23qmk_firmware_dir="$(realpath "$script_dir/../")"
24
25export PATH="$PATH:$script_dir/fmpp/bin"
26
27build_fmpp() {
28 [ -f "$script_dir/fmpp.tar.gz" ] \
29 || wget -O"$script_dir/fmpp.tar.gz" https://github.com/freemarker/fmpp/archive/v0.9.16.tar.gz
30 [ -d "$script_dir/fmpp" ] \
31 || { mkdir "$script_dir/fmpp" && tar xf "$script_dir/fmpp.tar.gz" -C "$script_dir/fmpp" --strip-components=1 ; }
32 pushd "$script_dir/fmpp" >/dev/null 2>&1
33 sed -e "s#bootclasspath.path=.*#bootclasspath.path=$(find /usr/lib/jvm -name 'rt.jar' | sort | tail -n1)#g" \
34 -e "s#ant.jar.path=.*#ant.jar.path=$(find /usr/share/java -name 'ant-1*.jar' | sort | tail -n1)#g" \
35 build.properties.sample > build.properties
36 sed -e 's#source="1.5"#source="1.8"#g' \
37 -e 's#target="1.5"#target="1.8"#g' \
38 build.xml > build.xml.new
39 mv build.xml.new build.xml
40 ant clean
41 ant
42 chmod +x "$script_dir/fmpp/bin/fmpp"
43 popd >/dev/null 2>&1
44}
45
46find_chibi_files() {
47 local search_path="$1"
48 shift
49 local conditions=( "$@" )
50 for file in $(find -L "$search_path" -not -path '*/lib/chibios*' -and -not -path '*/util/*' -and \( "${conditions[@]}" \) | sort) ; do
51 if [ -z "$(grep 'include_next' "$file")" ] ; then
52 echo $file
53 fi
54 done
55}
56
57upgrade_conf_files_generic() {
58 local search_filename="$1"
59 local update_script="$2"
60 shead "Updating $search_filename files ($update_script)..."
61 pushd "$qmk_firmware_dir/lib/chibios/tools/updater" >/dev/null 2>&1
62 for file in $(find_chibi_files "$qmk_firmware_dir" -name "$search_filename") ; do
63 cp -f "$file" "$file.orig"
64 clang-format --style='{IndentPPDirectives: None}' -i "$file"
65 cp -f "$file" "$file.formatted"
66 bash "$update_script" "$file"
67 if ! diff "$file" "$file.formatted" >/dev/null 2>&1 ; then
68 dos2unix "$file" >/dev/null 2>&1
69 else
70 cp -f "$file.orig" "$file"
71 fi
72 rm -f "$file.orig" "$file.formatted"
73 done
74 popd >/dev/null 2>&1
75}
76
77upgrade_chconf_files() {
78 upgrade_conf_files_generic chconf.h update_chconf_rt.sh
79}
80
81upgrade_halconf_files() {
82 upgrade_conf_files_generic halconf.h update_halconf.sh
83
84 OIFS=$IFS
85 IFS=$'\n'
86 for file in $(find_chibi_files "$qmk_firmware_dir" -name halconf.h) ; do
87 echo $file
88 sed -i 's@#include "mcuconf.h"@#include <mcuconf.h>@g' "$file"
89 done
90 IFS=$OIFS
91}
92
93upgrade_mcuconf_files() {
94 pushd "$qmk_firmware_dir/lib/chibios/tools/updater" >/dev/null 2>&1
95 for f in $(find . -name 'update_mcuconf*') ; do
96 upgrade_conf_files_generic mcuconf.h $f
97 done
98 popd >/dev/null 2>&1
99}
100
101havecmd fmpp || build_fmpp
102
103upgrade_mcuconf_files
104upgrade_chconf_files
105upgrade_halconf_files