#!/usr/bin/env bash
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
build_dir="${REDALERT_ENGINE_BUILD_DIR:-${repo_root}/.runtime/engine-web-build}"
emcmake_bin="${EMCMAKE_BIN:-emcmake}"
cmake_bin="${CMAKE_BIN:-cmake}"

"${emcmake_bin}" "${cmake_bin}" -S "${repo_root}/engine/vanilla" -B "${build_dir}" \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_REMASTERTD=OFF -DBUILD_REMASTERRA=OFF \
  -DBUILD_VANILLATD=OFF -DBUILD_VANILLARA=ON \
  -DBUILD_TESTS=OFF -DBUILD_TOOLS=OFF \
  -DNETWORKING=ON -DSDL2=ON -DOPENAL=ON \
  -DVANILLA_VENDORED_REVISION=ce83b59edd99cccac6cebaae054ca04962c744b7

"${cmake_bin}" --build "${build_dir}" --target VanillaRA --parallel 1

printf 'Engine artifacts: %s/vanillara.js and %s/vanillara.wasm\n' "${build_dir}" "${build_dir}"
