#!/bin/bash -e
cd "$(dirname "$0")"

echo "---------- clean build ----------"
rm -rf "build" "dist"
rm -f "*.spec"

# echo "---------- detect build deps ----------"
# pipreqs --force "./src"

echo "---------- run init script ----------"
./init.sh

source "./venv/Scripts/activate" || source "./venv/bin/activate"

# pip install --upgrade pint
# this might be needed to oveerride a python-obd dependency
# to an older pint version not compatible with python 3.10

echo "---------- install builders ----------"
pip install --upgrade pyinstaller
# also you should install
# pipreqs
# "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
# IPython pywin32 pycairo

echo "---------- build ----------"
python "build.py"

echo "---------- copy data ----------"
mkdir -p "./dist/data"
cp -fr "./data" "./dist"
mkdir -p "./dist/config"
cp -fr "./config" "./dist"
mkdir -p "./dist/src/prove"
cp "./src/prove/p.csv" "./dist/src/prove/"
cp "./src/prove/t.csv" "./dist/src/prove/"

echo "---------- done. ----------"
