From 04a0d8bc1a8337df3cc2eded36c0986f0d0a4f6f Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 6 Nov 2013 03:12:44 +0100 Subject: build ship: generate directives and input_parser --- ship/build | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 15 deletions(-) (limited to 'ship') 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< build_info \1 build_info() { cat< \([^ ]\+\) \(.*\)$/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 "$@" -- cgit v1.2.3