summaryrefslogtreecommitdiffstats
path: root/ship/build
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-11-13 00:48:05 +0100
committermakefu <github@syntax-fehler.de>2013-11-13 00:48:05 +0100
commit41f20813f3de8df1cc8074e5d18692388bd6f482 (patch)
tree1e5e276ce06046f2aba47647cf303251482435f3 /ship/build
parentf09880150c6a309ce15931a8e2d52ebf054a115a (diff)
parent0be9d62c78c27ea73691cb0a58779c319d5f9355 (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'ship/build')
-rwxr-xr-xship/build67
1 files changed, 63 insertions, 4 deletions
diff --git a/ship/build b/ship/build
index 7755253d..bd26482d 100755
--- a/ship/build
+++ b/ship/build
@@ -20,14 +20,24 @@ build() {
esac
}
-## usage: #@include \([0-9A-Za-z]\+\) -> build_include \1 \2
-build_include() { cat<<EOF
+###
+### macros
+###
+
+## usage: #@include \([0-9A-Za-z_]\+\) -> build_include \1 \2
+build_include() {
+ if buildcache_has "#@include:$2"; then
+ printf '%da\\\n##include %s: already done\n' $1 $2
+ else
+ buildcache_add "#@include:$2"
+ cat<<EOF
$1a\\
# begin $2
$1r$(build_resolve $2)
$1a\\
# end $2
EOF
+ fi
}
## usage: #@info -> build_info \1
@@ -39,6 +49,10 @@ $1a\\
EOF
}
+###
+### main subroutines
+###
+
## usage: build_compile SRCFILE DSTFILE
build_compile() {
@@ -57,12 +71,16 @@ t;s:^ *\\([0-9]\\+\\) .*:echo \\1p:
SRCFILE="$1" setf src '$(cat "$%s")' SRCFILE
+ buildcache_initialize "$2"
+
while echo "$src" | grep -q "$unexpanded_macros_pattern"; do
setf sedgen '$(echo "$%s" | nl -b a -s \ | sed "$%s")' src input_parser
setf sedscript '$(eval "$%s")' sedgen
setf src '$(echo "$%s" | sed -n "$%s")' src sedscript
done
+ buildcache_finalize
+
echo "$src" > "$2"
chmod +x "$2"
}
@@ -85,6 +103,10 @@ build_deps() {
done | sort | uniq
}
+###
+### misc utilities
+###
+
## usage: build_resolve LIBNAME
build_resolve() {
echo "$BUILD_PATH" | tr : \\n |
@@ -115,11 +137,48 @@ setf() {
eval "$1=$value_script"
- if test "${debug-false}" = true; then
+ if is_debug_mode; then
eval 'echo "$1=\"$value_script\""'
eval 'echo "'"\$$1"'"' | nl -b a
fi >&2
}
-## main
+## usage: is_debug_mode
+is_debug_mode() {
+ test "${debug-false}" = true
+}
+
+###
+### buildcache utilities
+###
+
+## usage: buildcache_initialize DESTFILE
+buildcache_initialize() {
+ buildcache="$1.buildcache"
+ cat /dev/null > "$buildcache"
+}
+
+## usage: buildcache_finalize
+buildcache_finalize() {
+ if is_debug_mode; then
+ rm "$buildcache"
+ fi
+}
+
+## usage: buildcache_has BRE
+# Check if buildcache contains a line matching BRE.
+buildcache_has() {
+ grep -q "^$1\$" "$buildcache"
+}
+
+## usage: buildcache_add LINE
+# Add LINE to buildcache.
+buildcache_add() {
+ echo "$1" >> "$buildcache"
+}
+
+###
+### main invocation
+###
+
build "$@"