TDDE18CppCourse/lab4/build_and_run.sh
2021-08-22 13:21:37 +02:00

62 lines
1 KiB
Bash
Executable file

#!/bin/bash
# TDDE18 - Lab 4
red='\e[0;31m'
green='\e[0;32m'
orange='\e[0;33m'
neutral='\e[0;m'
printout() {
echo -e "[${green}INFO${neutral}] $@"
}
printhelp() {
echo -e "[${orange}HELP${neutral}] $@"
}
printerr() {
echo -e "[${red}ERROR${neutral}] $@"
}
valgrd() {
echo ""
valgrind --tool=memcheck --leak-check=yes ./out.o $1 $2 $3 $4 $5
echo ""
}
printhelp "Compilation, execution and debugging script for TDDE18 C ++ labs."
printhelp "Pass the \"-v\" argument to run Valgrind."
printout "Starting building..."
/usr/bin/time --quiet --output=data.tmp -f "Time elasped: %E (%P cpu)" g++ -Wall -Wextra -Wpedantic -std=c++17 *.cc -o out.o
if test $? -eq 0
then
printout "Build finished."
printout `cat data.tmp`
rm data.tmp
if [ "$1" = "-v" ]
then
printout "Running with valgrind..."
valgrd $2 $3 $4 $5 $6
else
printout "Running..."
echo ""
./out.o $1 $2 $3 $4 $5
echo ""
fi
printout "Done. Cleaning..."
rm out.o
printout "Done."
else
printerr "Build failed."
printout `cat data.tmp`
rm data.tmp
exit 1
fi
echo ""
exit 0