#!/bin/bash

mseroot=./mseide-msegui
funits=`readlink -n -f -s ./units/`
exeout=`readlink -n -f -s ./`

     pushd $mseroot
     fpc -Xs- -Ow -FWo.opt -OWAll -CfSSE64 -Cg -k-pie -k-znow -FU$funits  -Fu./lib/common/* -Fu./lib/common/kernel/linux -CX -XX -O2 -Mobjfpc ./tools/form2pas.pas -FE$exeout
     if [ "$?" != "0" ]
     then
          echo 'Compiling error - update FAILED :('
          popd
          exit
     fi
     fpc -Xs- -Ow -FWo.opt -OWAll -CfSSE64 -Cg -k-pie -k-znow -FU$funits  -Fu./lib/common/* -Fu./lib/common/kernel/linux -CX -XX -O2 -Mobjfpc ./tools/data2pas.pas -FE$exeout
     if [ "$?" != "0" ]
     then
          echo 'Compiling error - update FAILED :('
          popd
          exit
     fi
     popd

find ./ \( -name "*.mfm" \) -exec ./form2pas '{}' \;

     pushd $mseroot
     fpc -Xs- -Ow -FWo.opt -OWAll -CfSSE64 -Cg -k-pie -k-znow -FU$funits  -Fu./lib/common/* -Fu./lib/common/kernel/linux -CX -XX -O2 -Mobjfpc ./tools/bmp2pas.pas -FE$exeout
     if [ "$?" != "0" ]
     then
          echo 'Compiling error - update FAILED :('
          popd
          exit
     fi
     popd

echo 'All OK :)'