-
Notifications
You must be signed in to change notification settings - Fork 253
/
build-and-run
executable file
·102 lines (85 loc) · 2.34 KB
/
build-and-run
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
#
# © 2018-2019 Konstantin Gredeskoul, All Rights Reserved.
# MIT License
#
# WARNING: This BASH script is completely optional. You don't need it to build this project.
#
# If you choose to run this script to build the project, run:
#
# $ ./build-and-run
#
# It will clean, build and run the tests.
#
[[ -z $(which git) ]] && {
echo "You need git installed. Please run 'xcode-select --install' first."
exit 1
}
export BashMatic="${HOME}/.bashmatic"
[[ -s ${BashMatic}/init.sh ]] || {
rm -rf "${BashMatic}" 2>/dev/null
git clone https://github.com/kigster/bashmatic "${BashMatic}" 2>&1 1>/dev/null
}
source "${BashMatic}/init.sh"
export ProjectRoot=$(pwd)
export BuildDir="${ProjectRoot}/build/run"
export BashLibRoot="${ProjectRoot}/bin/lib-bash"
export LibBashRepo="https://github.com/kigster/lib-bash"
divider.header() {
h1.purple "Fractional Division With Remainder: A CMake Project Template with Tests"
local OIFC=${IFC}
IFS="|" read -r -a gcc_info <<< "$(gcc --version 2>&1 | tr '\n' '|')"
export IFC=${OIFC}
h1 "${bldylw}GCC" "${gcc_info[1]}" "${gcc_info[2]}" "${gcc_info[3]}" "${gcc_info[4]}"
h1 "${bldylw}GIT: ${bldblu}$(git --version)"
h1 "${bldylw}CMAKE: ${bldblu}$(cmake --version | tr '\n' ' ')"
}
divider.setup() {
hl.subtle "Creating Build Folder..."
run "mkdir -p build/run"
run "git submodule init && git submodule update"
[[ -f .idea/workspace.xml ]] || cp .idea/workspace.xml.example .idea/workspace.xml
}
divider.clean() {
hl.subtle "Cleaning output folders..."
run 'rm -rf bin/d* include/d* lib/*'
}
divider.build() {
run "cd build/run"
run "cmake ../.. "
run.set-next show-output-on
run "make -j 12"
run "make install | egrep -v 'gmock|gtest'"
run "cd ${ProjectRoot}"
}
divider.tests() {
if [[ -f bin/divider_tests ]]; then
run.set-next show-output-on
run "echo && bin/divider_tests"
else
printf "${bldred}Can't find installed executable ${bldylw}bin/divider_tests.${clr}\n"
exit 2
fi
}
divider.examples() {
[[ ! -f bin/divider ]] && {
error "You don't have the cmpiled binary yet".
exit 3
}
run.set-all show-output-on
hr
run "bin/divider 11 7"
hr
run "bin/divider 1298798375 94759897"
hr
run "bin/divider 78 17"
hr
}
main() {
divider.header
divider.setup
divider.build
divider.tests
divider.examples
}
(( $_s_ )) || main