-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompile-cpp.sh
54 lines (41 loc) · 1.14 KB
/
compile-cpp.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
#!/bin/bash
PYTHON_EXECUTABLE=py # Windows Python Launcher by default
if [ "$#" -eq "1" ]; then
PYTHON_EXECUTABLE=$1 # custom python executable
fi
# dependencies
RAPIDJSON="../external/rapidjson/include"
CC=g++
CFLAGS="-std=c++17 -Wall -Werror -Wextra -pedantic -I$RAPIDJSON"
VERBOSE=1
log() {
if (( $VERBOSE == 1 )); then
echo " --info: $1"
fi
}
compiled=0
# create directory if not exist
[[ -d cpp ]] || mkdir cpp
for input in $(ls ./res); do
if [[ -f "res/$input" ]] && [[ "$input" == *.json ]]; then
src="${input%%.json}.cpp"
obj="${input%%.json}.o"
log "generate $src"
$PYTHON_EXECUTABLE gen.py -i "res/$input" -o "cpp/$src"
log "compile $src..."
cd cpp && $CC $CFLAGS -c "$src"
code=$?
cd ..
if [[ $code -eq "0" ]] && [[ -f "cpp/$obj" ]]; then
log "$obj is compiled"
compiled=$((compiled + 1))
else
log "$obj is not compiled"
exit 1
fi
fi
done
# cleanup
[[ -d cpp ]] && rm -r cpp
log "---------------------------------"
log "Summary: compiled $compiled files"