
#!/bin/bash

cd buildbot
WORKDIR=$PWD

#### ASSET SECTION ####

#### END ASSET SECTION ####


#### WINX64 BUILDBOT SECTION ####

echo STARTING WIN_X64 BUILDBOT
echo =========================================================================================

# prepare build environment
BOT=$PWD/buildbot_x64
cd $BOT
git pull

# build cores
echo BUILDBOT TASK: building retroarch-mingw-w64-seh
./libretro-buildbot-recipe.sh recipes/win_x64/retroarch-mingw-w64-seh
echo BUILDBOT TASK: building cores-mingw-w64-seh
./libretro-buildbot-recipe.sh recipes/win_x64/cores-mingw-w64-seh
echo BUILDBOT TASK: building cores-mingw-w64-sjlj
./libretro-buildbot-recipe.sh recipes/win_x64/cores-mingw-w64-sjlj

# create packages and cleanup
echo BUILDBOT TASK: packaging cores
CORE_DIR=$PWD/packages/$(date +%F)_cores
RA_DIR=$PWD/packages/$(date +%F)_RetroArch
mkdir $CORE_DIR -p
mkdir $RA_DIR -p

cp -rf retroarch/windows/* $RA_DIR 

cd $CORE_DIR
mkdir ../latest

find ../../dist/win_x64 -name '*.dll' -mmin -1000 -exec cp '{}' . \;
cp ../../dist/info/*.info .

7z a -mx9 "${CORE_DIR}.7z" *.dll *.info

find . -type f -name '*.dll' -exec zip -j '{}'.zip '{}' \;
find . -type f -name '*.dll' -exec rm '{}' \;

find . -type f -name '*.info' -exec rm '{}' \;
find . -type f -name '*.dll' -exec rm '{}' \;

cp *.zip ../latest/

echo
rsync --progress ../latest/*.zip buildbot@buildbot.libretro.com:/home/buildbot/www/nightly/win-x86_64/latest/

cd ..

cd $RA_DIR
7z a -mx9 "${RA_DIR}.7z" *

rsync --progress ../*.7z buildbot@buildbot.libretro.com:/home/buildbot/www/nightly/win-x86_64/

cd ..

echo BUILDBOT TASK: cleaning up

rm -rf $CORE_DIR.7z
rm -rf $CORE_DIR
rm -rf packages/latest
rm -rf $RA_DIR.7z
rm -rf $RA_DIR

cd $WORKDIR
echo
#### END WINDOWS X64 BUILDBOT ####

