Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. # compile
  2. clear
  3. if [ -z "$1" ]
  4. then
  5. echo "$0 Usage:"
  6. echo " $0 sourceCode.cpp [inputFile.in]"
  7. echo ""
  8. echo "Example:"
  9. echo " $0 test.cpp"
  10. echo " $0 test.cpp test.1.in"
  11. echo ""
  12. echo "This script compiles the C++ source code if the"
  13. echo "source is newer than the binary. Then pipe in the"
  14. echo "input if exists. Finally compare it with the output"
  15. echo "if exists."
  16. else
  17. filename=$(basename "$1")
  18. extension="${filename##*.}"
  19. filename="${filename%.*}"
  20.  
  21. if [ -z "$2" ]
  22. then
  23. casename=$filename
  24. else
  25. casename=$(basename "$2.in")
  26. casename="${casename%.*}"
  27. fi
  28.  
  29. if [ ! -f "$filename" ] || [ "$1" -nt "$filename" ]
  30. then
  31. g++ -lm -Wall -Wconversion -g -O2 -std=c++11 -o $filename $1
  32. fi
  33.  
  34. # run with input
  35. if [ $? -eq 0 ]
  36. then
  37. if [ -f "$casename.in" ]
  38. then
  39. if [ -f "$casename.out" ]
  40. then
  41. ./$filename < $casename.in | diff -y - $casename.out
  42. else
  43. ./$filename < $casename.in
  44. fi
  45. else
  46. ./$filename
  47. fi
  48. fi
  49.  
  50. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement