#!/usr/bin/env bash
export CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL:-$(python3 -c "import os;print(os.cpu_count())")}

if [ "x$1" = "x" ]; then
    # No version arg
    echo Please provide a version argument,e.g : $0 2.0
    exit 1;
fi


export MCVERSION=${1}
export WORKDIR=$PWD

mkdir -p build-arm64 && rm -rf build-arm64/*
mkdir -p build-x86_64  && rm -rf build-x86_64/*

mkdir -p dist-arm64 && rm -rf dist-arm64/*
mkdir -p dist-x86_64  && rm -rf dist-x86_64/*


cd $WORKDIR/build-arm64
cmake $WORKDIR/support/MacOSX/McCode-conda.app -DBUILD_MCSTAS=ON -DMCVERSION=${MCVERSION} -DARCH_ENABLE=arm64 -DCMAKE_INSTALL_PREFIX=$WORKDIR/mcstas-macOS-arm64/McStas-${MCVERSION}.app
make install
cd $WORKDIR

cd $WORKDIR/build-x86_64
cmake $WORKDIR/support/MacOSX/McCode-conda.app -DBUILD_MCSTAS=ON -DMCVERSION=${MCVERSION} -DARCH_ENABLE=x86_64 -DCMAKE_INSTALL_PREFIX=$WORKDIR/mcstas-macOS-x86_64/McStas-${MCVERSION}.app
make install
cd $WORKDIR
cp INSTALL-McStas/macOS/README.md mcstas-macOS-arm64
cp INSTALL-McStas/macOS/README.md mcstas-macOS-x86_64
