#!/bin/bash
echo "Bfgminer Win32 builder:"
echo ""
export folder=$(pwd)
function libraries {
cd ~
pkg-config --libs libevent_pthreads PKG_CONFIG_PATH=/home/wareck/event
rm -r -f temp
mkdir temp
cd temp
wget http://wareck.free.fr/cross_compilation/uthash-2.3.0.tar.gz
wget http://wareck.free.fr/cross_compilation/event.tar.gz
tar xfz uthash-2.3.0.tar.gz
tar xfz event.tar.gz
cd uthash-2.3.0
sudo cp src/* /opt/mxe/usr/i686-w64-mingw32.static/include/
cd ~
}

function compilation {
git clone https://github.com/wareck/bfgminer.git
cd bfgminer
git submodule init
git submodule update
./autogen.sh
CFLAGS="-O2 -msse2" ./configure --host=i686-w64-mingw32.static libevent_CFLAGS="-I/home/wareck/event/include/" libevent_LIBS="-I/home/wareck/event/lib" --enable-scrypt --without-libevent --prefix=/home/wareck/zob
make
}

function pack {
cd ~/bfgminer
rm -r -f /tmp/bfgminer
mkdir /tmp/bfgminer
cp bfgminer.exe /tmp/bfgminer/
cp $folder/packages/bfgminer/* /tmp/bfgminer/
cd /tmp/
version="5.5.0"
7z a -tzip bfgminer-win32-$version.zip bfgminer
lftp -u wareck,zorn692611 ftpperso.free.fr <<EOF
put bfgminer-win32-$version.zip -o /crypto/bfgminer-win32-$version.zip
EOF
if ! [ -d /home/$USER/Bureau/win32_build/ ]; then mkdir /home/$USER/Bureau/win32_build ;fi
cp bfgminer-win32-$version.zip /home/$USER/Bureau/win32_build/
cd /tmp
rm -r -f /tmp/bfgminer
}
libraries
compilation
pack
