Last active
April 5, 2016 18:27
-
-
Save OneOfOne/c7e5a1af08b03da8857e0314fa526fc6 to your computer and use it in GitHub Desktop.
run c++ files and then clean up (go run for c++ with clang pretty much)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| fname="$(mktemp cpp-run.XXXXX)" | |
| cppArgs="" | |
| runArgs="" | |
| doRun=0 | |
| doGDB=0 | |
| keep=0 | |
| for arg in "$@"; do | |
| if [ "$arg" == "--" ]; then | |
| doRun=1 | |
| elif [ "$doRun" == 1 ]; then | |
| runArgs="$argArgs $arg" | |
| elif [ "$arg" == "--gdb" ]; then | |
| doGDB=1 | |
| cppArgs="$cppArgs -ggdb -g3" | |
| elif [ "$arg" == "--keep" ]; then | |
| keep=1 | |
| else | |
| cppArgs="$cppArgs $arg" | |
| fi | |
| done | |
| [ "$keep" == "0" ] && trap "rm -f $fname &>/dev/null" EXIT | |
| clang++ -o $fname -Wall -Wextra -std=c++1z -stdlib=libc++ -lc++abi -pthread -pedantic $cppArgs || exit 1 | |
| if [ "$doGDB" == "1" ]; then | |
| gdb -ex run -- $fname $runArgs | |
| else | |
| $fname $runArgs | |
| fi | |
| [ "$keep" != "0" ] && echo "executable: $fname" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment