diff options
author | tv <tv@nomic.retiolum> | 2013-11-06 04:01:41 +0100 |
---|---|---|
committer | tv <tv@nomic.retiolum> | 2013-11-06 04:01:41 +0100 |
commit | 0db968b3ca9d7efbf49730226f00a3912f4bca17 (patch) | |
tree | 37cc9486863380a11d234113ad8c3288707ff9e4 /ship | |
parent | 7631078cfc08b85954aca3dcf0e8521a3fa2d9f9 (diff) |
ship build: add defvar
Diffstat (limited to 'ship')
-rwxr-xr-x | ship/build | 50 |
1 files changed, 21 insertions, 29 deletions
@@ -12,16 +12,6 @@ build() { esac } -# usage: debug_script VARNAME [DESCRIPTION] -debug_script() { - if test "${debug-false}" = true; then - printf '[35m====== %s%s[m\n%s\n' \ - "$1" \ - "${2+" ($2)"}" \ - "$(eval echo \"\$$1\" | nl -b a)" >&2 - fi -} - ## usage: #@include \([0-9A-Za-z]\+\) -> build_include \1 \2 build_include() { cat<<EOF $1a\\ @@ -43,24 +33,18 @@ EOF ## usage: build_compile SRCFILE DSTFILE build_compile() { - srcfile="$(cat "$1")" - debug_script srcfile 'SRCFILE' - - 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' + defvar srcfile "$(cat "$1")" 'SRCFILE' + defvar build_directives "$(make_build_directives "$0")" '$0' + defvar build_x_directive_loader "$(make_build_x_directive_loader "$0")" '$0' eval "$build_x_directive_loader" - input_parser="$(make_input_parser "$0")" - sentinel="$(make_needs_compilation_sentinel $build_directives)" + defvar input_parser "$(make_input_parser "$0")" + defvar sentinel "$(make_needs_compilation_sentinel $build_directives)" while needs_compilation "$srcfile" "$sentinel"; do - script="$(make_sedscript_maker_shellscript "$srcfile" "$input_parser")" - srcfile="$(echo "$srcfile" | sed -n "$script")" - debug_script srcfile 'sed sedscript srcfile' + defvar script "$(make_sedscript_maker_shellscript "$srcfile" "$input_parser")" + defvar srcfile "$(echo "$srcfile" | sed -n "$script")" 'sed script srcfile' done echo "$srcfile" > "$2" @@ -77,12 +61,9 @@ needs_compilation() { # Print a shellscript that creates a sedscript that resolves all the build # directives in SRCFILE. make_sedscript_maker_shellscript() { - sedscript_generator="$(echo "$1" | nl -b a -s ' ' | sed "$2")" - debug_script sedscript_generator 'sed input_parser srcfile' - - sedscript="$(eval "$sedscript_generator")" - debug_script sedscript 'eval sedscript_generator' - + defvar sedscript_generator "$(echo "$1" | nl -b a -s ' ' | sed "$2")" \ + 'sed input_parser srcfile' + defvar sedscript "$(eval "$sedscript_generator")" 'eval sedscript_generator' echo "$sedscript" } @@ -151,5 +132,16 @@ make_needs_compilation_sentinel() { )\\)$" } +## usage: defvar NAME VALUE [DESCRIPTION] +defvar() { + eval "$1=\"\$2\"" + if test "${debug-false}" = true; then + printf '[35m====== %s%s[m\n%s\n' \ + "$1" \ + "${3+" ($3)"}" \ + "$(eval echo \"\$$1\" | nl -b a)" >&2 + fi +} + ## main build "$@" |