#!/bin/bash

PREV_VER=$1
NEXT_VER=$2

# update version in doxygen configs
python update_doxyfile_version.py $PREV_VER $NEXT_VER

# build documentation
make --directory="../Doxygen/"
#make --directory="../Doxygen/dark_theme/build/latex"
#make --directory="../doxygen/light_theme/build/latex"

# create release folder
cd ../Releases
mkdir niietcm4_pd_$2

#copy sources
cp -avr ../Libs niietcm4_pd_$2
cp -avr ../Templates niietcm4_pd_$2
cp -avr ../Examples niietcm4_pd_$2
# delete temp, build and etc information
find niietcm4_pd_$2 -name "build*" -exec rm -R "{}" \;
find niietcm4_pd_$2 -type f -name "*.qbs.user" -delete

# copy docs
#mkdir -p niietcm4_pd_$2/Docs/pdf
#cp ../Doxygen/dark_theme/build/latex/refman.pdf niietcm4_pd_$2/Docs/pdf/NIIETCM4_PD-$2.pdf

mkdir -p niietcm4_pd_$2/Docs/dark_theme
cp -avr ../Doxygen/dark_theme/build/html niietcm4_pd_$2/Docs/dark_theme
cp -avr ../Doxygen/dark_theme/build/qch niietcm4_pd_$2/Docs/dark_theme

mkdir -p niietcm4_pd_$2/Docs/light_theme
cp -avr ../Doxygen/light_theme/build/html niietcm4_pd_$2/Docs/light_theme
cp -avr ../Doxygen/light_theme/build/qch niietcm4_pd_$2/Docs/light_theme

cp ../README.md niietcm4_pd_$2/
cp ../RELEASE.md niietcm4_pd_$2/

# zip folder and remove it
zip -r niietcm4_pd_$2.zip niietcm4_pd_$2
rm -rf niietcm4_pd_$2
