#!/usr/bin/env bash

set -e

mkdir -p /home/build-host
cd /home/build-host
cmake ../source -DCMAKE_TOOLCHAIN_FILE=/home/toolchain-host.cmake -DCMAKE_INSTALL_PREFIX=/home/tools
cmake --build . -t install -j

mkdir -p /home/build-target
cd /home/build-target
rm -rf ./*
# Use emsdk wrapper for cmake - it sets some env variables to select the
# right toolchain.
emcmake cmake \
  -DBOOST_SOURCE_ROOT=$(realpath ../source)/psemek/3rdparty/boost \
  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  -DPSEMEK_PACKAGE_MODE=ON \
  -DPSEMEK_PACKAGE_HOST=OFF \
  -DPSEMEK_PACKAGE_TARGET=ON \
  -DPSEMEK_STACKTRACE=OFF \
  -DBOOST_SOURCE_ROOT=/home/boost \
  -DPSEMEK_PACKAGE_TOOLS_PATH=/home/tools \
  -DPSEMEK_PACKAGE_COPY_FILES= \
  -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH \
  ../source
cmake --build . -j
