#!/bin/bash

rvern="$(./vcs-revno)"
mingwb="$(ls /usr/ | grep mingw32 | grep -v amd64 | head --lines 1)"
qtwind="$(pwd)/qt4-win"
qtx11d="$(pwd)/qt4-x11"

if [ ! -d release ]
then
mkdir release
fi

if [ ! -f "sevnz.dll" ] || [ ! -f "sevnz.exe" ]
then
svloc=$(wget "http://7-zip.org/" -O - | grep --ignore-case "a href=\"http://downloads.sourceforge.net/sevenzip/" | grep -v ".msi" | grep -v "x64" | tail -n 1 | tr "<" "\n" | tr ">" "\n" | tr "\"" "\n" | grep "http://downloads.sourceforge.net/sevenzip/")
wget "$svloc" -O sevenzip.exe
svxloc=$(echo "$svloc" | sed 's/.exe/_extra.7z/')
wget "$svxloc" -O sevenzip-extra.7z
7z e -y sevenzip.exe 7z.exe 7z.dll
mv 7z.exe sevnz.exe
mv 7z.dll sevnz.dll
7z e -y sevenzip-extra.7z 7zS.sfx
fi

$qtx11d/bin/lrelease unetbootin.pro
./qmake-windows
make
$mingwb-strip --strip-all release/unetbootin.exe
mv release/unetbootin.exe release/unetbootin-windows-$rvern.exe
./upx --lzma release/unetbootin-windows-$rvern.exe

