-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·79 lines (70 loc) · 1.45 KB
/
build.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
73
74
75
76
77
78
79
#!/bin/bash
# This is the project build script.
# Pass --help to review how to use the script.
output_dir=cmake-build-debug
tests_dir=${output_dir}/tests/
should_configure="yes"
should_ask="no"
should_clean="no"
function help() {
echo "Usage: $0 [--output=] [--configure=yes|no]"
}
function build_procedure() {
[ "${should_configure}" == "no" ] || \
ccmake -S. -B${output_dir} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Debug -DTESTS_DIR_PREFIX="${pwd}/"
[ -f ${output_dir}/compile_commands.json ] && \
ln -sf ${output_dir}/compile_commands.json compile_commands.json
make -C${output_dir}
find ${tests_dir} -name 'test_*' -type f -executable -exec '{}' ';'
}
function build_docs() {
make -C docs/ clean
make -C docs/
}
function clean() {
question=$([ ${should_ask} == "yes" ] && echo "-i" || echo "")
rm -rf ${question} ${output_dir}
}
function parse_arguments() {
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
help
exit
;;
--output=*)
output_dir="${1#*=}"
tests_dir=${output_dir}/tests/
shift
;;
--tests=*)
shift
tests_dir="${1#*=}"
;;
--configure=*)
should_configure="${1#*=}"
shift
;;
--clean)
should_clean="yes"
shift
[[ "$1" == "--ask" ]] && should_ask="yes"
clean
;;
--docs)
shift
build_docs
[[ "$1" == "open" ]] && xdg-open docs/doc.pdf
;;
*)
echo "$0: Invalid input."
exit
;;
esac
done
}
function main() {
parse_arguments $@
build_procedure
}
main $@