summaryrefslogtreecommitdiffstats
path: root/ship
diff options
context:
space:
mode:
Diffstat (limited to 'ship')
-rwxr-xr-xship/build73
1 files changed, 58 insertions, 15 deletions
diff --git a/ship/build b/ship/build
index 486f4bed..3c510f91 100755
--- a/ship/build
+++ b/ship/build
@@ -12,6 +12,25 @@ build() {
esac
}
+## usage: init
+init() {
+ directive_pattern='s:^ *\\([0-9]\\+\\) \1$:\2 \3:'
+
+ input_parser="$(make_input_parser "$0")"
+ debug_script input_parser '$0'
+
+ build_directives="$(make_build_directives "$0")"
+ debug_script build_directives '$0'
+
+ build_x_directive_loader="$(make_build_x_directive_loader "$0")"
+ debug_script build_x_directive_loader '$0'
+
+ eval "$build_x_directive_loader"
+
+ needs_compilation_sentinel="$(make_needs_compilation_sentinel $build_directives)"
+ debug_script needs_compilation_sentinel 'build_directives'
+}
+
# usage: debug_script VARNAME [DESCRIPTION]
debug_script() {
if test "${debug-false}" = true; then
@@ -22,18 +41,7 @@ debug_script() {
fi
}
-## build directives
-build_info_directive='#@info'
-build_include_directive='#@include \([0-9A-Za-z]\+\)'
-
-input_parser="\
-s:^ *\([0-9]\+\) "$build_info_directive"$:build_info \1:
-s:^ *\([0-9]\+\) "$build_include_directive"$:build_include \1 \2:
-t
-s:^ *\([0-9]\+\) .*:echo \1p:"
-debug_script input_parser
-
-## usage: build_include LINENO LIBNAME
+## usage: #@include \([0-9A-Za-z]\+\) -> build_include \1 \2
build_include() { cat<<EOF
$1a\\
# begin $2
@@ -43,7 +51,7 @@ $1a\\
EOF
}
-## usage: build_info LINENO
+## usage: #@info -> build_info \1
build_info() { cat<<EOF
$1a\\
# this file was generated by //ship/build\\
@@ -70,8 +78,7 @@ build_compile() {
## usage: needs_compilation SHELLSCRIPT
# Returns true if SRCFILE contains compilation directives.
needs_compilation() {
- echo "$1" |
- grep -q "^\\($build_include_directive\\|$build_info_directive\\)$"
+ echo "$1" | grep -q "$needs_compilation_sentinel"
}
## usage: make_sedscript_maker_shellscript SRCFILE
@@ -118,4 +125,40 @@ build_resolve() {
}
}
+## usage: make_input_parser FILENAME
+make_input_parser() {
+ echo "$(sed -n '
+ s/^## usage: \(.*\) -> \([^ ]\+\) \(.*\)$/s:^ *\\([0-9]\\+\\) \1$:\2 \3:/p
+ $a\
+t;s:^ *\\([0-9]\\+\\) .*:echo \\1p:
+ ' "$1")"
+}
+
+## usage: make_build_directives FILENAME
+make_build_directives() {
+ echo "$(sed -n '
+ s/^## usage: \(.*\) -> \([^ ]\+\) \(.*\)$/\2_directive/p
+ ' "$0")"
+}
+
+## usage: make_build_x_directive_loader FILENAME
+make_build_x_directive_loader() {
+ sed -n '
+ s/^## usage: \(.*\) -> \([^ ]\+\) \(.*\)$/\2_directive='"'"'\1'"'"'/p
+ ' "$1"
+}
+
+## usage: make_needs_compilation_sentinel BUILD_DIRECTIVES...
+make_needs_compilation_sentinel() {
+ echo "^\\($(
+ for directive; do
+ eval echo \"\$$directive\"
+ done |
+ tr \\n \| |
+ sed 's/|/\\|/'
+ )\\)$"
+}
+
+## main
+init
build "$@"