#!/bin/bash

set -o errexit
#set -o xtrace

PYVER=2.7
case $PYVER in
    25 | 2.5) VER=25;;
    26 | 2.6) VER=26;;
    27 | 2.7) VER=27;;
    30 | 3.0) VER=30;;
esac
PYTHON=$TOOLS/Python$VER/python.exe

if [ ! -x $PYTHON ]; then
    echo Something is wrong with the Python at $PYTHON
    exit 1
fi

MYBINDIR=$(dirname $(readlink -f $0))

# This is specific to my machine. If you need to build your own sip then adjust accordingly
export INCLUDE="c:\TOOLS\VisStudio9\VC\ATLMFC\INCLUDE;c:\TOOLS\VisStudio9\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v6.0A\include;"
export LIB="c:\TOOLS\VisStudio9\VC\ATLMFC\LIB;c:\TOOLS\VisStudio9\VC\LIB;C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib;"
export SDK_DIR="C:\Program Files\Microsoft SDKs\Windows\v7.1"
export PATH="/c/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Bin:$PATH"

echo "INCLUDE: $INCLUDE"
echo "LIB:     $LIB"


cd /c/projects/sip/sip
SIPVER=$($PYTHON -c "import sys,configure; sys.stdout.write(configure.sip_version_str);")

$PYTHON configure.py \
    --sip-module wx.siplib \
    $*

cd sipgen
nmake clean all
mv sip.exe $MYBINDIR/sip-$SIPVER-win32.exe
cd $MYBINDIR

echo ""
echo "The MD5:"
$PYTHON mymd5.py sip-$SIPVER-win32.exe
echo ""
echo "If ready to upload then do these commands now:"
echo "    bzip2 -9 $MYBINDIR/sip-$SIPVER-win32.exe"
echo "    scp $MYBINDIR/sip-$SIPVER-win32.exe.bz2 robind@riobu.com:/home/robind/domains/wxpython.org/htdocs/Phoenix/tools"


## Reset the *_RELEASE flags to use debug options so the sip executable
## will be built in debug mode too.  Using --debug doesn't do that.
## These are the defaults:
##
##        myCFLAGS="-O2 -MD"
##        myLFLAGS="/INCREMENTAL:NO"
#myCFLAGS="-Zi -MDd"
#myLFLAGS="/DEBUG"
#
#$PYTHON configure.py \
#    --debug \
#    CFLAGS_RELEASE="$myCFLAGS" \
#    CXXFLAGS_RELEASE="$myCFLAGS" \
#    LFLAGS_RELEASE="$myLFLAGS" \
#    $*

