#!/bin/sh

# Quick and dangerous script for building OSX binaries.

# A few quirks to note, which should be re-checked every release:
# - We require the latest development version of PyInstaller.
 
# To run, first install netlib and mitmproxy, then run 
#
#	./release/osx-binaries
#
# From the top-level mitmproxy directory. 

usage ()
{
  echo 'Usage : ./release/osx-binaries /path/to/pyinstaller.py'
  echo 'Run from the top-level mitmproxy directory'
  exit
}

if [ "$1" = "" ]
then
    usage
fi


TMPDIR=./tmp
PYINST_CMD=$1" -F --clean"

rm -f dist/*
rm -rf $TMPDIR

$PYINST_CMD ./release/mitmdump.spec
./dist/mitmdump --version || exit 1

$PYINST_CMD ./release/mitmproxy.spec
./dist/mitmproxy --version || exit 1

$PYINST_CMD ./release/mitmweb.spec
./dist/mitmweb --version || exit 1

DST=osx-mitmproxy-`./dist/mitmdump --shortversion 2>&1`
mkdir -p $TMPDIR/$DST
cp ./dist/mitmproxy $TMPDIR/$DST
cp ./dist/mitmdump $TMPDIR/$DST
cshape ./doc-src $TMPDIR/$DST/doc

cd $TMPDIR
tar -czvf $DST.tar.gz $DST
