#!/bin/bash

# Poor mans git sub modules / subtrees, coz otherwise it gets complex.
#if [ ! -d git-sub-modules/opensim-moneymodule-gloebit ]; then
#    pushd git-sub-modules >/dev/null
#    git clone https://github.com/gloebit/opensim-moneymodule-gloebit.git
#    popd >/dev/null
#else
#    pushd git-sub-modules/opensim-moneymodule-gloebit >/dev/null
#    git pull
#    popd >/dev/null
#fi
#rm -rf addon-modules/Gloebit/GloebitMoneyModule
#cp -r git-sub-modules/opensim-moneymodule-gloebit/addon-modules/Gloebit/GloebitMoneyModule addon-modules/Gloebit/

./runprebuild.sh autoclean
# Clean the stuff autoclean forgets to clean.  I feel so dirty.
find -name obj -type d -print | xargs /bin/rm -fr
# Clean the stuff the tests created.
rm -fr bin/ScriptEngines
rm Test*.txt
./runprebuild.sh vs2015

# Prebuild converts Microsoft.CSharp.targets to Microsoft.CSHARP.Targets, which case sensitive file systems fail to find.
#find -name *.csproj | xargs sed -i "s@Microsoft.CSHARP.Targets@Microsoft.CSharp.targets@g"

# Debian no longer provides nant.
#./nant-color

if [ "4" == $(mono -V | head -n 1 | cut -d ' ' -f 5 | cut -d '.' -f 1) ]; then
    export XBUILD_COLORS=errors=brightred,warnings=yellow,events=blue
    xbuild /target:clean
    xbuild /p:TargetFrameworkVersion="v4.5"xbuild /p:TargetFrameworkVersion="v4.5"
else
    # Use this for Mono 5 and later.
    msbuild /p:Configuration=Release
#    msbuild /p:Configuration=Debug
fi

#cp -f addon-modules/Gloebit/GloebitMoneyModule/bin/Gloebit.dll bin

pushd src >/dev/null
./BuildIt.sh
popd >/dev/null