summaryrefslogtreecommitdiff
path: root/make-permanently.in
diff options
context:
space:
mode:
Diffstat (limited to 'make-permanently.in')
-rwxr-xr-xmake-permanently.in86
1 files changed, 86 insertions, 0 deletions
diff --git a/make-permanently.in b/make-permanently.in
new file mode 100755
index 0000000..659517a
--- /dev/null
+++ b/make-permanently.in
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+# part of even-more-utils, version #VERSION#
+
+# run make as soon as needed
+
+if [ "x$1" = 'x-r' ]; then
+ recursive=true
+ shift
+else
+ recursive=false
+fi
+
+make "$@"
+
+while true; do
+ if ${recursive}; then
+ inotifywait -e DELETE_SELF,CLOSE_WRITE -r * || break
+ else
+ make_content=$(
+ sed '
+ :a
+ \/\\$/ {
+ N
+ s/\\\n//
+ ta
+ }
+ /^\(\s\|$\)/d
+ ' 'Makefile' \
+ | while read -r line; do
+ if [ -z "${line##\$(foreach *,*,*)*}" ]; then
+ line="${line#\$(foreach }"
+ var="${line%%,*}"
+ line="${line#${var}*,}"
+ runs="${line%,*}"
+ line="${line#${runs},}"
+ body="${line%%)*}"
+ line="${line#${body})}"
+ while [ $(printf '%s\n' "${body}" | tr -d '\n' | tr ')' '\n' | wc -l) -lt $(printf '%s\n' "${body}" | tr -d '\n' | tr '(' '\n' | wc -l) ] \
+ && [ -z "${line##*)*}" ]; do
+ new_body="${line%%)*}"
+ body="${body})${new_body}"
+ line="${line#${new_body})}"
+ done
+ for s in ${runs}; do
+ printf '%s' "${body}" \
+ | sed '
+ s#\$('"${var}"')#'"${s}"'#g
+ '
+ done \
+ | sed '
+ s/^\s\+//
+ s/\s\+$//
+ '
+ fi
+ printf '%s\n' "${line}"
+ done
+ )
+ substs=$(
+ printf '%s\n' "${make_content}" \
+ | sed '
+ s/^\([^[:space:]=]\+\)=\(.*\)$/s@\1@ \2 @g;\n/
+ t
+ d
+ '
+ )
+ watch_files=$(
+ printf '%s\n' "${make_content}" \
+ | sed "${substs}" \
+ | sed -n '
+ s/^\S.*: //
+ T
+ y/ /\n/
+ p
+ ' \
+ | sed '
+ /^\s*$/d
+ y/%/*/
+ ' \
+ | xargs -r readlink -f \
+ | sort -u
+ )
+ inotifywait -e DELETE_SELF,CLOSE_WRITE $(find ${watch_files} -type f) || break
+ fi
+ make "$@"
+done