#!/bin/sh

# Init-Datei fuer Out-of-Tree-Build

o_path=$PWD
br_dir=$(realpath $(dirname "$0")/../../..)

defcfg=cv_octavo_btdevel_ext_tc_defconfig
defcfg_tc=cv_octavo_btdevel_defconfig

help()
{
    echo -h: help
    echo -o: old board, 34_39_500 instead 34_39_500A
    echo -t: build with toolchain
    exit
}

old=0
tc=0
while getopts hot flag
do
    case "${flag}" in
        h) help;;
        o) old=1;;
        t) tc=1;;
    esac
done

if [ "$tc" -eq "1" ]; then
	defcfg=$defcfg_tc
fi

if [ "$old" -eq "1" ]; then
    sed -e 's/34_39_500A/34_39_500/' $br_dir/configs/$defcfg > $br_dir/configs/old_$defcfg
    defcfg=old_$defcfg
fi

echo make -C $br_dir O=$o_path $defcfg
echo make -C $br_dir O=$o_path $defcfg > cv_current_config.sh
chmod +x cv_current_config.sh
echo "sudo dd if=images/sdcard.img of=/dev/sdb bs=1MB" > mkcard.sh
chmod +x mkcard.sh
make -C $br_dir O=$o_path $defcfg
