Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # compile
- clear
- if [ -z "$1" ]
- then
- echo "$0 Usage:"
- echo " $0 sourceCode.cpp [inputFile.in]"
- echo ""
- echo "Example:"
- echo " $0 test.cpp"
- echo " $0 test.cpp test.1.in"
- echo ""
- echo "This script compiles the C++ source code if the"
- echo "source is newer than the binary. Then pipe in the"
- echo "input if exists. Finally compare it with the output"
- echo "if exists."
- else
- filename=$(basename "$1")
- extension="${filename##*.}"
- filename="${filename%.*}"
- if [ -z "$2" ]
- then
- casename=$filename
- else
- casename=$(basename "$2.in")
- casename="${casename%.*}"
- fi
- if [ ! -f "$filename" ] || [ "$1" -nt "$filename" ]
- then
- g++ -lm -Wall -Wconversion -g -O2 -std=c++11 -o $filename $1
- fi
- # run with input
- if [ $? -eq 0 ]
- then
- if [ -f "$casename.in" ]
- then
- if [ -f "$casename.out" ]
- then
- ./$filename < $casename.in | diff -y - $casename.out
- else
- ./$filename < $casename.in
- fi
- else
- ./$filename
- fi
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement