#!/bin/bash

# which python to use in generating .tar.gz, .exe
host="`hostname`"
if [ $host = "coh" ];then
    PYTHON_FOR_BIN=python
else
    PYTHON_FOR_BIN=python
fi	    

# temporary folders
MISC=source/misc
EXAMPLES=source/examples

# clear up temporary folders
rm -rf $MISC
mkdir -p $MISC
rm -rf $EXAMPLES
mkdir -p $EXAMPLES

# need this folder so that you don't get warning
mkdir source/_static

# construct source tarball and put it in misc folder
rm -rf ../dist
rm ../MANIFEST
(cd .. ; $PYTHON_FOR_BIN setup.py sdist --format=gztar)
(cd .. ; $PYTHON_FOR_BIN setup.py sdist --format=zip)
cp ../dist/*.tar.gz $MISC
cp ../dist/*.zip $MISC
rm -rf ../dist

# copy more stuff to misc folder
cp ../gpl-3.0.txt $MISC
cp ../doc/talk/pythtb-talk.pdf $MISC
cp ../doc/formalism/pythtb-formalism.pdf $MISC
cp local/release/ver_*/*.tar.gz $MISC
cp local/w90_example/wannier90_example.tar.gz $MISC

# copy all example files
cp ../examples/*.py $EXAMPLES
# also files needed for w90 examples
cp local/w90_example/wannier90_example.tar.gz $EXAMPLES
(cd $EXAMPLES ; tar xvf wannier90_example.tar.gz ; rm wannier90_example.tar.gz )
# create tar file of all examples
(cd source ; tar --exclude='examples/pythtb.py' -zcvf pythtb-examples.tar.gz examples )
mv source/pythtb-examples.tar.gz $MISC
# also will need source file to run examples
cp ../pythtb.py $EXAMPLES

# make simple figure for main page
ln -s ../examples/pythtb.py source/simple_fig/pythtb.py
ln -s ../../matplotlibrc source/simple_fig/matplotlibrc
(cd source/simple_fig ; python3 simple_fig.py)

# now create website using sphinx
make html

# for some reason example files do not get copied, so we need to do it by hand
cp $EXAMPLES/*.py build/html/examples
