diff options
author | tv <tv@nomic.retiolum> | 2013-11-05 23:29:34 +0100 |
---|---|---|
committer | tv <tv@nomic.retiolum> | 2013-11-05 23:29:34 +0100 |
commit | 85c99011060b4b37a760fa24d0a0e23e83413bef (patch) | |
tree | 0e143ab522ebade768a95f4f81134aba56a3bc78 /ship/build | |
parent | 816471fe35bb2e9886ed3c3fdff8f23f700c912b (diff) |
ship build: modularize directive decls
Diffstat (limited to 'ship/build')
-rwxr-xr-x | ship/build | 75 |
1 files changed, 36 insertions, 39 deletions
@@ -16,61 +16,58 @@ build() { 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:" + +## usage: build_include LINENO LIBNAME +build_include() { cat<<EOF +$1a\\ +# begin $2 +$1r$(build_resolve $2) +$1a\\ +# end $2 +EOF +} + +## usage: build_info LINENO +build_info() { cat<<EOF +$1a\\ +# this file was generated by //ship/build\\ +# date: $(date -u --rfc-3339=s)\\ +# version: $(git rev-parse HEAD) +EOF +} + ## usage: build_compile SRCFILE DSTFILE build_compile() { - cp "$1" "$2" + srcfile="$(cat "$1")" - while needs_compilation "$2"; do - script="$(make_sedscript_maker_shellscript "$2" | sh)" - sed -n "$script" "$2" >"$2.tmp" - mv "$2.tmp" "$2" + while needs_compilation "$srcfile"; do + script="$(make_sedscript_maker_shellscript "$srcfile")" + srcfile="$(echo "$srcfile" | sed -n "$script")" done + echo "$srcfile" > "$2" chmod +x "$2" } -## usage: needs_compilation SRCFILE +## usage: needs_compilation SHELLSCRIPT # Returns true if SRCFILE contains compilation directives. needs_compilation() { - grep -q "^\\($build_include_directive\\|$build_info_directive\\)$" "$1" + echo "$1" | + grep -q "^\\($build_include_directive\\|$build_info_directive\\)$" } ## usage: make_sedscript_maker_shellscript SRCFILE # Print a shellscript that creates a sedscript that resolves all the build # directives in SRCFILE. make_sedscript_maker_shellscript() { - echo 'set -euf' - - echo "_build_info='$( - echo "# This file was generated by //ship/build\\" - echo "# Date: $(date -u --rfc-3339=s)\\" - echo "# Git-Commit: $(git show --pretty=oneline | awk '{print$1}')" - )'" - - deps="$(build_deps "$1")" - for lib in $deps; do - echo "_build_include_$(basename $lib)=$lib" - done - - nl -b a -s ' ' "$1" | - sed ' - s:^ *:: - - s:^\([0-9]\+\) '"$build_info_directive"'$:\1a\\\\\ -$_build_info\ - : - - s:^\([0-9]\+\) '"$build_include_directive"'$:\1a\\\\\ -# BEGIN \2\ - \1r\$_build_include_\2\ - \1a\\\\\ -# END \2: - - s:^\([0-9]\+\) .*:\1p: - - 1s:^:echo ": - $s:$:": - ' + sedscript_generator="$(echo "$1" | nl -b a -s ' ' | sed "$input_parser")" + sedscript="$(eval "$sedscript_generator")" + echo "$sedscript" } ## usage: build_deps SRCFILE |