shake
minimal build system that generates Ninja build files
git clone https://9o.is/git/shake.git
commit 8ec4a16a7d69ebc6283a3f6109c35295939bb75b parent 7ef77cd50c48828cbd93ec41e25d9357f9d6491a Author: Jul <jul@9o.is> Date: Fri, 13 Mar 2026 12:32:58 +0800 remove prefix and build parsing from shell Diffstat:
| M | example/nested/bin/Shakefile | | | 4 | ++-- |
| M | example/nested/lib/Shakefile | | | 4 | ++-- |
| M | example/simple/Shakefile | | | 8 | ++++---- |
| M | shake | | | 67 | ++++++------------------------------------------------------------- |
| M | shakeout.awk | | | 16 | ++++++++++------ |
5 files changed, 24 insertions(+), 75 deletions(-)
diff --git a/example/nested/bin/Shakefile b/example/nested/bin/Shakefile @@ -2,7 +2,7 @@ var CFLAGS $CFLAGS -I $LIBDIR -cc main.o main.c '|' $LIBDIR/lib.h -link hello main.o $LIBDIR/lib.a +cc main.o: main.c '|' $LIBDIR/lib.h +link hello: main.o $LIBDIR/lib.a default hello diff --git a/example/nested/lib/Shakefile b/example/nested/lib/Shakefile @@ -1,4 +1,4 @@ #!/usr/bin/env sh -cc lib.o lib.c -ar lib.a lib.o +cc lib.o: lib.c +ar lib.a: lib.o diff --git a/example/simple/Shakefile b/example/simple/Shakefile @@ -14,11 +14,11 @@ rule link '$CC $in -o $out' rule cp 'cp -f $in $out' bind description 'CP $in' -cc main.o main.c -cc hello.o hello.c -link hello main.o hello.o +cc main.o: main.c +cc hello.o: hello.c +link hello: main.o hello.o -cp $DESTDIR$PREFIX/bin/hello hello +cp $DESTDIR$PREFIX/bin/hello: hello phony install $DESTDIR$PREFIX/bin/hello default hello diff --git a/shake b/shake @@ -59,7 +59,7 @@ while [ $# -gt 0 ]; do done fini_gen() { - gen "$GEN_OUTS" '|' $GEN_FILES + gen $GEN_OUTS: '|' $GEN_FILES phony ninja $NINJA_FILES wait } @@ -136,49 +136,13 @@ bind() { } build() { - _v1=$1 - prefix _v2 $outdir $2 - shift 2 - prefix _vs $dir $* - build_parse $_vs - printf 'shake+build %s: %s %s %s %s\n' "$_v2" "$_v1" "$_vs" "$_vd" "$_vo" -} - -build_parse() { - _vs= - _vd= - _vo= - _mode=vs - - for _v in $*; do - case $_v in - '|') _mode=vd;; - '||') _mode=vo;; - *) - case $_mode in - vs) _vs="$_vs $_v";; - vd) _vd="${_vd:-|} $_v";; - vo) _vo="${_vo:-||} $_v";; - esac - esac - done + printf 'shake+build %s\n' "$*" } rule() { - _rule=$1 - _cmd="$2" - - printf 'shake+rule %s\n' "$_rule" - bind command "$_cmd" - - _d= - for _v in $_cmd; do - case "$_v" in - *\$*dir/*) _d="${_d:-'|'} \$${_v#*$}";; - esac - done - - eval "$_rule() { _v=\"\$1\"; shift; build $_rule \"\$_v\" \$* $_d; }" + printf 'shake+rule %s\n' "$1" + bind command "${*:2}" + eval "$1() { build $1 \$*; }" } default() { @@ -186,26 +150,7 @@ default() { } phony() { - prefix _v $dir $1 - shift - printf 'shake+build %s: phony %s\n' "$_v" "$*" -} - -prefix() { - _var=$1 - _pre=$2 - _vs= - shift 2 - - for _v in $*; do - case $_v in - \$* | \|* | /* | .*) ;; - *) _v=$_pre/$_v;; - esac - _vs="$_vs $_v" - done - - eval "$_var='$_vs'" + printf 'shake+build phony %s: %s\n' "$1" "${*:2}" } error() { diff --git a/shakeout.awk b/shakeout.awk @@ -10,7 +10,6 @@ function reset(newstate) { function add_prefix(str) { if (str ~ /^(\$|\.\/|\.\.\/|\/)/) return str if (state == "VAR") return str - if (state == "BRUL") return str if (state == "BOUT") return "$outdir/" str if (state == "BIN") return "$dir/" str if (state == "BDEP") return "$dir/" str @@ -32,13 +31,18 @@ function process(cmd, str) { sep = substr(str, RSTART, RLENGTH) if (tok != "" && tok != cmd) { - printf " %s", add_prefix(tok) - if (state == "BRUL") state = "BIN" + if (state == "BRUL") { + brule = tok + state = "BOUT" + } else { + printf " %s", add_prefix(tok) + } } if (sep ~ /:/) { - state = "BRUL" - printf ":" + state = "BIN" + printf ": %s", brule + brule = "" } else if (sep ~ /\|\|/ && state != "BORD") { @@ -58,7 +62,7 @@ function process(cmd, str) { } /^shake\+build / { - reset("BOUT") + reset("BRUL") printf "build" process("shake+build", $0) next