#!/bin/sh
set -e

if [ "$1" = '' ]
then
	echo 'The first argument needs to be the tree file'
	exit 1
fi

tree_file="$(realpath "$1")"
start_dir="$PWD"
script_dir="$(dirname $(readlink -f $0))"

cd "$script_dir/src"

language='
	-std=c++17
	-fno-rtti
	-fno-exceptions
	-fno-non-call-exceptions
	-fno-common'
# force each global variable to be only defined once

warnings='-Wall -Wextra -Wpedantic' #-fanalyzer

cp -f "$tree_file" user_tree.hpp
g++ -o "$start_dir/${1%.*}.tft" $language $warnings -march=native -DNDEBUG -pipe -g create_tree.cpp tree.cpp person.cpp utils.cpp -lncursesw
rm user_tree.hpp
cd "$start_dir"
exec "./${1%.*}.tft"
