-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.sh
executable file
·100 lines (93 loc) · 2.29 KB
/
compile.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash -x
# Use to print each step: #!/bin/bash -x
#
# Example script -- boilerplate to automate compilation (and, possibly, execution) the lab project.
#
set -o errexit
set -o nounset
set -o pipefail
debug_build=true
optimize_build=false
remove_dirs=false
install_prefix=".."
while [[ $# -gt 0 ]]; do
case $1 in
-I | --install_prefix)
if [ "$2" -eq "$2" ] 2>/dev/null; then
install_prefix=$2
shift 2
else
echo "Option --install_prefix requires an numerical argument." >&2
exit 1
fi
;;
-D | --debug-build)
debug_build=true
shift
;;
-d | --no-debug-build)
debug_build=false
shift
;;
-O | --optimize-build)
optimize_build=true
shift
;;
-o | --no-optimize-build)
optimize_build=false
shift
;;
-R | --remove-build-dirs)
remove_dirs=true
shift
;;
-h | --help)
echo "Usage: ./compile.sh [options]
Options:
-h --help Show help message.
-O --optimize-build Compile with optimization before executing.
-o --no-optimize-build Compile without optimization before executing.
-D --debug-build Compile with debug options.
-d --no-debug-build Compile without debug options.
-I --install_prefix Installation path.
-R --remove-build-dirs Remove build dirs after the install."
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an numerical argument." >&2
exit 1
;;
*)
break
;;
esac
done
if [[ "$debug_build" == true ]]; then
mkdir -p ./cmake-build-debug
(
pushd ./cmake-build-debug > /dev/null || exit 1
echo Compiling...
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="${install_prefix}" .. || exit 1
cmake --build . || exit 1
cmake --install . || exit 1
popd
)
fi
if [[ "$optimize_build" == true ]]; then
mkdir -p ./cmake-build-release
(
pushd ./cmake-build-release >/dev/null || exit 1
echo Compiling...
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${install_prefix}" .. || exit 1
cmake --build . || exit 1
cmake --install . || exit 1
popd
)
fi
if [[ "$remove_dirs" == true ]]; then
rm -rf ./cmake-build-debug ./cmake-build-release
fi