-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayground-cpp-compile.sh
More file actions
executable file
·38 lines (36 loc) · 1.04 KB
/
playground-cpp-compile.sh
File metadata and controls
executable file
·38 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
# Compile a given single C++ file and immediately run it.
# Remove the executable afterwards.
#
# Usage:
#
# playground-cpp-compile.sh [-k|--keep] FILE [PARAMS]...
#
# Examples:
#
# playground-cpp-compile.sh main.cpp # compile the program, run it and delete it afterwards
# playground-cpp-compile.sh main.cpp -myarg # compile the program with -myarg, run it and delete it afterwards
# playground-cpp-compile.sh --keep main.cpp # compile the program, run it and don't delete it afterwards
#
# author: andreasl
keep_artifacts=false
while [ "$#" -gt 0 ]; do
case "$1" in
-k | --keep)
keep_artifacts=true
;;
*)
file="$1"
shift
params=("$@")
break
;;
esac
shift
done
# if g++ "${params[@]}" -pthread "$file" -o "${file}.o"; then
if clang++ "${params[@]}" -pthread "$file" -o "${file}.o"; then
# if clang++ --std=c++11 "${params[@]}" -pthread "$file" -o "${file}.o"; then
"./${file}.o";
[ "$keep_artifacts" = 'true' ] || rm "${file}.o";
fi