#!/bin/bash
#AUTOBUILDER - semi-automated build system for TinI/O
export proceed=0  #global ok flag
proceed() #exits the program if proceed isn't true
{
  if [ $proceed -eq 0 ]
  then
    echo "Error! The last action autobuild tried to perform failed."
    exit 1
  fi
  proceed=0
}
setcolor()#sets the color of stdout to yellow
{
  tput setaf 1
  tput setab 7
}
resetcolor()
{
  tput sgv0
}
#START

echo "    --------------------------" #fancy banner!
echo "    Autobuilder for TinI/O 0.1"
echo "    --------------------------"
echo "    Verifying main directory..."
[ -d cylib ] && [ -d tinio ] && proceed=1 #check if we're in the right dir
proceed #error check
echo "    DONE!"
echo "    Entering the library directory..."
cd cylib/build && proceed=1 #cd to the lib dir
proceed #error check
echo "    DONE!"
echo "    Compiling and installing the library..."
cmake .. && make && sudo make install && proceed=1  #compiles the lib
                                                    #according to the lib docs
proceed
echo "    DONE!"
echo "    Library installation complete."
echo "    Going back..."
cd ../.. && proceed=1 #goes from cylib/build to cylib then to main dir
proceed
echo "    DONE!"
sleep 1 # sleep for 1 sec to let the user see the output
echo "    Entering the TinI/O build directory"
cd tinio && proceed=1
echo "    DONE!"
