diff options
author | tv <tv@nomic.retiolum> | 2013-11-06 03:12:44 +0100 |
---|---|---|
committer | tv <tv@nomic.retiolum> | 2013-11-06 03:12:44 +0100 |
commit | 04a0d8bc1a8337df3cc2eded36c0986f0d0a4f6f (patch) | |
tree | b40b865f8233c5583e1bed6295fd89ec2d0af63b /ship | |
parent | 7d6b65a71a3a18bb50c699e57738723d2056f436 (diff) |
build ship: generate directives and input_parser
Diffstat (limited to 'ship')
-rwxr-xr-x | ship/build | 73 |
1 files changed, 58 insertions, 15 deletions
@@ -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 "$@" |