#! /bin/bash
# Build LifeViewer Javascript definition

# The command line argument is the repository directory
if [ -z "$1" ]; then
  echo "`basename $0`: Script must be passed the repository directory"
  exit 1
fi

repo=$1
base64=$2

# Generate the Javascript file
echo "// LifeViewer WASM definitions"
echo "// This file is autogenerated during the build process"
echo ""
echo "var wasmBase64 = \"`cat ${base64}`\";"
echo ""
echo "var WASM = {"
egrep "(^void|^uint32_t)" ${repo}/wasm/*.c | sed "s/.* /\t/" | sed "s/(/: null,/"
echo -e "\tmemory: null,\n\tallocator: null\n};"
