forked from Estrella-Explore/gcc_strict-flags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·72 lines (59 loc) · 2.67 KB
/
make.sh
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# `${1%.cpp}` catches the whole file name(include path), delete the suffix `.cpp`
filename=${1%.cpp}
# Remove the old `${filename}.out` if it exists.
if test -f ${filename}.out;then
rm ${filename}.out
fi
# Remove the old `${filename}.ans` if it exists.
if test -f ${filename}.ans;then
rm ${filename}.ans
fi
# @brief: Compile `${filename}.cpp`
# --std=c++14 is the require of CCF - China Cheating-money Foundation
# c++14 for CSP-J/S, NOIp and NOI, etc.
# E.g.: Your file name is `foo.cpp`, then your executable file name is `foo.out`.
g++ -g -Wall -Wextra -pedantic --std=c++14 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -fdiagnostics-color=always $1 -o ${filename}.out
# @brief: read default test as `stdin`, redirect `stdout` to `${filename}.ans` .
# If found `${filename}.in`, \
# ask user if they want to use `${filename}.in` as testcase. \
# Output was been redirected to `${filename}.ans`
tryUsingDefaultTestcase() {
if test -r ${filename}.in; then # Test if `${filename}.in` exists and readable.
echo ""
echo "[Info]: Testcase ${filename}.in was detected."
echo "------> Using this testcase? [Y/n]"
read -r operation
if [[ "$operation" != [Nn]* ]]; then # If `$operation` is not "N" or "n", include empty input.
./${filename}.out <${filename}.in >${filename}.ans # Run program.
echo "[Info]: Reading ${filename}.in as testcase."
echo -e "[Info]: Your answer is below, which will be saved as ${filename}.ans.\n"
cat ${filename}.ans
echo -e "\n[Hint]: You can try \"diff ${filename}.ans <Standard Answer>\" to debug."
fi
fi
}
# @brief: Receive a string as parameter, output it in blue.
# `\033[34m` sets the color to blue, \
# `\033[0m` clear all the colors
blueOutput () {
echo -e "\033[34m${1}\033[0m"
}
# @brief: Receive a string as parameter, output it in red.
# `\033[31m` sets the color to red, \
# `\033[0m` clear all the colors
redOutput () {
echo -e "\033[31m${1}\033[0m"
}
# ---------- Functions definitions finished ----------
# if [[ $? == 0 ]]; then
# HINT: Sometimes `g++` will return 0 even if got trouble.
if test -x ${filename}.out; then # If `${filename}.out` exists and can be executed.
blueOutput "[Info]:\033[0m Successfully compiled $1"
blueOutput "[Info]:\033[0m Executable file is ${filename}.out"
tryUsingDefaultTestcase
else
# TODO: Output the above compile informations to `${filename}.log`
redOutput "[Error]: Got trouble in compiling..."
blueOutput "[Info]:\033[0m Exiting..."
fi