#!/bin/bash

arch="$1"

if [[ $# -ge 2 ]]
then
    version=$2
else
    version=$(find_version)
fi
echo "Compiling $version..."

echo "core.info" > ${STORM_ROOT}/Compiler/COMPILER.version
echo "$version" >> ${STORM_ROOT}/Compiler/COMPILER.version

cd $STORM_ROOT

if [[ "$STORM_USE_COMPAT" == "1" ]]
then
    compat="compat"
else
    compat=""
fi

# Seems to be more or less standard in Git bash at least. If we fail, we will just run the build
# less efficiently, so it is not a big problem.
mm release $compat mps -ne || { echo "Compilation (mps) failed!"; exit 1; }
if [[ ! $arch == arm64 ]]
then
    mm release $compat smm -ne || { echo "Compilation (smm) failed!"; exit 1; }
fi

echo "Done! Running test suite..."
release/Test_mps --all || { echo "Tests failed (mps)!"; exit 1; }
#release/Test_smm --all || { echo "Tests failed (smm)!"; exit 1; }
echo "Success!"
