#!/bin/bash
cd build-release
curdir=`pwd`
builddir=`basename ${curdir}`
if [ ${builddir} != "build-release" ]; then
    echo "You must run this script from CodeLite root folder"
    exit -1
fi

# Clear old installers
os_name=`uname -s`
if [ ${os_name} == "Darwin" ]; then
    echo rm -f codelite.app.tar.gz
    rm -f codelite.app.tar.gz
else
    echo rm -fr *.deb
    rm -fr *.deb
fi

# Update our source tree
git pull --rebase 
if [ $? -ne 0 ]; then
    exit $?
fi

cd ../wxcrafter && git pull --rebase && cd ../build-release

# Build and upload
if [ ${os_name} == "Darwin" ]; then
    cmake -DCMAKE_BUILD_TYPE=Release .. -DWITH_PCH=1
    make -j4 && make install
    tar cvfz codelite.app.tar.gz codelite.app/*
    scp codelite.app.tar.gz root@codelite.org:/var/www/html/downloads/codelite/weekly/wip
else
    cmake -DCMAKE_BUILD_TYPE=Release -DMAKE_DEB=1 -DCOPY_WX_LIBS=1 ..
    make -j4 && make package
    deb_file=`ls -lt *.deb|awk '{print $9;}'|head -n 1`
    echo Uploading deb file ${deb_file}
    scp ${deb_file} root@codelite.org:/var/www/html/downloads/codelite/weekly/wip
fi

