#!/bin/sh

OSNAME=`uname`
. `dirname $0`/make-jobs.inc.sh
. `dirname $0`/wasi-env.sh
. `dirname $0`/wasi-common.sh

TOOLS="radare2"
HTTP_SUFFIX=""
if [ "${WASI_HTTP:-0}" = 1 ]; then
	export CFLAGS="${CFLAGS} -DR2_WASM_HTTP=1"
	HTTP_SUFFIX="-http"
fi

# Setup WASI SDK
wasi_setup_sdk

# Configure and build
./configure --with-static-themes --without-gperf --with-compiler=wasi --disable-debugger --without-fork --with-ostype=wasi-api --with-checks-level=0 --disable-threads --without-dylink --with-libr --without-gpl || exit 1
wasi_setup_plugins || exit 1

make -s -j${MAKE_JOBS} libs || exit 1

# Build tools and package
R2V=`./configure -qV`
D="radare2-$R2V-wasi-api${HTTP_SUFFIX}"

wasi_build_tools "$TOOLS" "$D"
ERR=$?

zip -qr "$D".zip "$D"
exit $ERR
