!/bin/bash
## compilecpp by highneko :3
## compile .cpp file and execute compiled binary file
## change g++ compile parameters to your liking
a="$1"
b="${1%.*}"
c=`ls -l --time-style=full-iso | grep "$b" | sed 1q`
## if file exists
if [ -f "$a" ]; then
## compile file
g++ "$a" -Wno-deprecated -lglut -lGLU -lGL -o "$b"
## else if unknown parameter
elif [ -n "$a" ]; then
echo "error: can't find file: $a" ## if file not found echo error message
else
echo "error: no input file found" ## if no filename was given echo error message
fi
d=`ls -l --time-style=full-iso | grep "$b" | sed 1q`
if [ "$c" = "$d" ]; then #file has not changed
echo "compile error"
else
echo "compile successful"
# make file executable for ugo
chmod 755 "$b"
# execute c++ binary file
./"$b"
fi