#!/bin/bash
[% c("var/set_default_env") -%]
distdir="/var/tmp/dist/[% project %]"
[% c("var/set_PTDIR_DOCSDIR") -%]
mkdir -p $PTDIR $DOCSDIR
[% IF c("var/windows") -%]
  [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
[% ELSE -%]
[% END -%]
mkdir -p $distdir
tar -C $distdir -xf $rootdir/[% c('input_files_by_name/pycrypto') %]
tar -C $distdir -xf $rootdir/[% c('input_files_by_name/twisted') %]
tar -C $distdir -xf $rootdir/[% c('input_files_by_name/argparse') %]
tar -C $distdir -xf $rootdir/[% c('input_files_by_name/parsley') %]
tar -C $distdir -xf $rootdir/[% c('input_files_by_name/pyptlib') %]
tar -C $distdir -xf $rootdir/[% c('input_files_by_name/pyyaml') %]
tar -C $distdir -xf $rootdir/[% c('input_files_by_name/txsocksx') %]
tar -C $distdir -xf $rootdir/[% c('input_files_by_name/zope.interface') %]
mkdir -p /var/tmp/build
tar -C /var/tmp/build -xf $rootdir/[% project %]-[% c('version') %].tar.gz
cd /var/tmp/build/[% project %]-[% c('version') %]
[% IF c("var/windows") -%]
  pydir="$distdir/python"
  export PYTHONPATH="$(wine winepath -w $pydir)\\Lib\\site-packages"
  $PYTHON setup_py2exe.py py2exe
  $PYTHON setup.py install --prefix=$(wine winepath -w $pydir)
  py2exe_zip_timestomp py2exe_bundle/dist/obfsproxy.zip
  cp -an py2exe_bundle/dist/{*.pyd,*.exe,*.zip} $PTDIR/
  # http://bugs.winehq.org/show_bug.cgi?id=3591
  cp -a /var/tmp/dist/winpython/python27.dll $PTDIR
[% ELSE -%]
  export PYTHON=python2
  $PYTHON setup.py build --build-lib build
  cp -a build/obfsproxy $PTDIR/
  cp -a bin/obfsproxy $PTDIR/obfsproxy.bin
[% END -%]
cp -a {LICENSE,README} $DOCSDIR
cd $distdir
[% c('tar', {
        tar_src => [ '.' ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
    }) %]
