aboutsummaryrefslogtreecommitdiff
path: root/home/dot_local/share/bin/executable_mk
diff options
context:
space:
mode:
Diffstat (limited to 'home/dot_local/share/bin/executable_mk')
-rw-r--r--home/dot_local/share/bin/executable_mk87
1 files changed, 87 insertions, 0 deletions
diff --git a/home/dot_local/share/bin/executable_mk b/home/dot_local/share/bin/executable_mk
new file mode 100644
index 0000000..051235a
--- /dev/null
+++ b/home/dot_local/share/bin/executable_mk
@@ -0,0 +1,87 @@
+#!/bin/sh
+progname="$(basename "$0")"
+showmode() {
+ ! [ -n "$FROM_PROMPT" ] && return
+ ! [ -t 1 ] && return
+
+ mode=" ($1)"
+ col=$(( $(tput cols) - $(echo "$mode" | wc -L) + 1 ))
+ printf '\e[1A\e['$col'G\e[1;30m%s\e[0m\n' "$mode"
+}
+
+make_tags() {
+ build_dir="${1-build}"
+
+ if [ -e "$build_dir/domains.yaml" ] ; then
+ yaml2json "$build_dir/domains.yaml" | jq --raw-output '. as $r | $r.flash_order[] as $n | $r.domains[] | select(.name == $n) | .build_dir' | while IFS= read -r build_dir; do
+ echo "Processing: $build_dir"
+ done
+ fi
+
+}
+
+mode_west() {
+ showmode 'west'
+ if [ -z "$*" ] ; then
+ set -- build
+ [ -e sysbuild ] || [ -e sysbuild.conf ] && set -- "$@" --sysbuild
+ fi
+ west "$@"
+ ec=$?
+
+ mktags build &
+
+ exit $ec
+}
+path="."
+for x in $(seq 10) ; do
+ [ -e "$path/.west" ] && mode_west "$@"
+ [ "$path" -ef "$path/.." ] && break
+ path="$path/.."
+done
+
+mode_cmake() {
+ showmode 'cmake'
+ builddir="build"
+
+ [ "$*" = "clean" ] && exec rm -rf "$builddir"
+
+ export CMAKE_GENERATOR="Ninja"
+
+ # re-run configuration if fresh or CMakeLists was changed
+ if [ ! -e "$builddir/build.ninja" ] ||
+ [ "CMakeLists.txt" -nt "$builddir/build.ninja" ] ; then
+ cmake --log-level WARNING -B "$builddir" || exit $?
+ fi
+
+ # build
+ cmake --build "$builddir" -- "$@"
+ ec=$?
+
+ # generate vim tags (continue after mk exits)
+ mktags "$builddir" &
+
+ exit $ec
+}
+[ -e "CMakeLists.txt" ] && mode_cmake "$@"
+
+mode_make() {
+ showmode 'make'
+ exec make "$@"
+}
+[ -e "makefile" ] && mode_make "$@"
+[ -e "Makefile" ] && mode_make "$@"
+
+mode_latexmk() {
+ showmode 'latexmk'
+
+ [ "$*" = "clean" ] && exec latexmk -c
+
+ exec latexmk "$@"
+}
+[ -e "latexmkrc" ] && mode_latexmk "$@"
+[ -e ".latexmkrc" ] && mode_latexmk "$@"
+
+echo "$progname: unable to determine project build system!" >&2
+exit 1
+