#!/bin/sh
# Builds ./bank from the given web.cml + host.cml + ffi.c, in the cwd.
# Needs cake (CAKE, default: cake on PATH) and the release's basis_ffi.c
# (BASIS, default: next to cake). Usage: ./build.sh web.cml
# cake touches its whole heap: on rtx, web.cml takes 2.3 s and 1.06 GB peak
# RSS (CML_HEAP_SIZE=256: 2.3 s, 270 MB, the same assembly).
set -e
dir=$(dirname "$0")
cake=${CAKE:-$(command -v cake)}
basis=${BASIS:-$(dirname "$cake")/basis_ffi.c}
cat "$1" "$dir/host.cml" > bank.cml
"$cake" < bank.cml > bank.S
cc -O2 bank.S "$basis" "$dir/ffi.c" -lm -o bank
