Last active
October 6, 2019 08:28
-
-
Save aprell/ed1df6f758252c79b361fbc048e7fb9e to your computer and use it in GitHub Desktop.
Convenience script for compiling and running C/C++ programs
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
| #!/usr/bin/env bash | |
| # ShellChecked with no issues detected | |
| set -eu | |
| set -o pipefail | |
| compile() { | |
| local args | |
| args=$(head -1 "$src" | sed 's/^\/*//') | |
| # Ignore any Makefiles that might be present | |
| eval "make -f /dev/null $args $exe" | |
| } | |
| run() { | |
| ./"$exe" "$@" | |
| } | |
| src="$1" | |
| exe="${src%.*}" | |
| shift | |
| compile && run "$@" |
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
| // CC=clang CFLAGS="-Wall -Wextra" | |
| #include <stdio.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| for (int i = 0; i < argc; i++) { | |
| printf("argv[%d] = %s\n", i, argv[i]); | |
| } | |
| return 0; | |
| } |
aprell
commented
Aug 25, 2019
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment