summaryrefslogtreecommitdiff
path: root/tools/notsd-fixup--makefiles
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-10-25 02:03:25 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-10-26 21:24:19 -0400
commit96a2b322fe384fa624cadd468e7d44396e49c2af (patch)
tree6765961600773cc64bf9f8b19000b6bf4a11283f /tools/notsd-fixup--makefiles
parente4f65c8bb8468e4391c0b38b51e86001cd7e0ed8 (diff)
tools/notsd-fixup: Split the makefile pass into a separate executable.
This avoids using bash read(1) to loop over the files, as we've already gotten decent speedups from avoiding bash read(1). This means we've got at least two more fork/exec's because of xargs, but it's probably worth it. But that's kind of premature-optimization; the time improvement here is probably just random noise. But, I think this makes the code more maintainable/manageable too, so I'm committing it.
Diffstat (limited to 'tools/notsd-fixup--makefiles')
-rwxr-xr-xtools/notsd-fixup--makefiles30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/notsd-fixup--makefiles b/tools/notsd-fixup--makefiles
new file mode 100755
index 0000000000..bb18c3be7b
--- /dev/null
+++ b/tools/notsd-fixup--makefiles
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+doit() {
+ local filename=$1
+ {
+ <"$filename" sed -r \
+ -e "s|(/\.\.)*/config.mk|/$(realpath -ms --relative-to="$(dirname -- "$filename")" config.mk)|" \
+ -e '/^nested\.subdirs/d' \
+ -e '/^include \$\(topsrcdir\)\/build-aux\/Makefile\.tail\.mk$/d'
+ echo
+ find "$(dirname "$filename")" -mindepth 2 -maxdepth 2 -name Makefile -print0 |
+ xargs -r0 dirname -z -- |
+ xargs -r0 basename -a -z |
+ xargs -r0 printf 'nested.subdirs += %s\n' | sort
+ echo
+ echo 'include $(topsrcdir)/build-aux/Makefile.tail.mk'
+ } | cat -s | build-aux/write-ifchanged "$filename"
+}
+
+main() {
+ set -e
+ set -o pipefail
+ local filename
+ for filename in "$@"; do
+ >&2 printf ' => fixup %q\n' "$filename"
+ doit "$filename"
+ done
+}
+
+main "$@"