Skip to content

Instantly share code, notes, and snippets.

@rumkin
Created July 30, 2011 15:07
Show Gist options
  • Save rumkin/1115616 to your computer and use it in GitHub Desktop.
Save rumkin/1115616 to your computer and use it in GitHub Desktop.
G++ compiling
#!/bin/bash
# Exception :)
function error {
echo "Error: "$1
exit
}
#read param
fname=$1;
if [ ${#fname} -eq 0 ];
then
echo -e "Message: Filename not set\nEnter filename:"
read fname
fi
#check for param #1
if [ ${#fname} -eq 0 ];
then
error "filename is empty"
fi
# check source for existance
if [ ! -r ./$fname.cpp ];
then
error "file is not found or unreadable"
fi
# delete old binary
# TODO(deside): rename old binary for bac up
if [ -f ./$fname ];
then
rm ./$fname
fi
params=$2
# detect gcc params
if [ ${#params} -eq 0 ];
then
params="-Wall -W -Werror"
fi
g++ $params $fname.cpp -o $fname
# Show binnary output
echo
echo "------------------------------------------------"
echo
./$fname
echo
echo "------------------------------------------------"
echo
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment