#!/bin/bash

set -x

COMPILE() {

    CONFIG="$1"
    OSVER="$2"
    PLUGINVER="$3"

    WHERE=/tmp/pocompile/

    mkdir -p $WHERE
    BDIR=`mktemp -d -p $WHERE TMP-$OSVER-$PLUGINVER-XXXXXXX`

    mkdir -p $BDIR

    HOME=$BDIR

    arduino-cli --additional-urls 'https://profezzorn.github.io/arduino-proffieboard/package_proffieboard_experimental_index.json' core install proffieboard_experimental:stm32l4@$PLUGINVER

    cd $HOME
    wget https://fredrik.hubbe.net/lightsaber/ProffieOS-v$OSVER.zip

    unzip ProffieOS-v$OSVER.zip
    cp "$CONFIG" ProffieOS/config/testconfig.h

    mv ProffieOS/ProffieOS.ino ProffieOS/ProffieOS.ino~

    (
	echo '#define CONFIG_FILE "config/testconfig.h"'
	cat ProffieOS/ProffieOS.ino~
    ) > ProffieOS/ProffieOS.ino
    
    cd ProffieOS

    time arduino-cli compile -v --fqbn=proffieboard_experimental:stm32l4:ProffieboardV3-L452RE:usb=cdc,dosfs=sdmmc1,speed=80,opt=os
    time arduino-cli compile -v --fqbn=proffieboard_experimental:stm32l4:ProffieboardV3-L452RE:usb=cdc,dosfs=sdmmc1,speed=80,opt=os
}

COMPILE /home/hubbe/Downloads/Aniflex.h 8.10 3.6
COMPILE /home/hubbe/Downloads/Aniflex.h 8.10 4.6
COMPILE /home/hubbe/Downloads/Aniflex.h 8.10 4.7
COMPILE /home/hubbe/Downloads/Aniflex.h 7.15 3.6
COMPILE /home/hubbe/Downloads/Aniflex.h 7.15 4.6
COMPILE /home/hubbe/Downloads/Aniflex.h 7.15 4.7

