-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·189 lines (148 loc) · 3.03 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
#
# A template for creating command line scripts taking options, commands
# and arguments.
#
# Exit values:
# 0 on success
# 1 on failure
#
# Name of the script
SCRIPT=$( basename "$0" )
#
# Message to display for usage and help.
#
function usage
{
local txt=(
"Roothelper build script"
"Usage: $SCRIPT [options]"
""
"Options:"
" --help, -h Print help."
" --full, -f Deletes CMake files and runs a full build."
" --install, -i Tries to install in /usr/{bin, lib} after build. Needs sudo."
" --uninstall, -u Tries to remove installed files from /usr/{bin, lib}. Needs sudo."
)
printf "%s\n" "${txt[@]}"
}
#
# Message to display when bad usage.
#
function badUsage
{
local message="$1"
local txt=(
"For an overview of the command, execute:"
"$SCRIPT --help"
)
[[ $message ]] && printf "$message\n"
printf "%s\n" "${txt[@]}"
}
function detectcpus
{
echo "Detecting cpu number"
cpus=$(nproc --all)
if [ -z "$cpus" ]; then
echo "Could not detect cpu number, setting to 2"
cpus=2
fi
echo "cpu number is $cpus"
export cpus
}
function stdbuild
{
detectcpus
set -e
cd CMAKE
cmake --build build -- -j$cpus
cd ..
cp -f cert/* bin/
}
function fullbuild
{
detectcpus
set -e
cd CMAKE
mkdir -p ../bin
rm -rf build
cmake -H. -Bbuild
cmake --build build -- -j$cpus
cd ..
cp -f cert/* bin/
}
function install
{
echo "Installing into /usr/{bin, lib}"
cp bin/r /usr/bin/
cp bin/lib7z.so cert/dummykey.pem cert/dummycrt.pem /usr/lib/
}
function uninstall
{
echo "Uninstalling from /usr/{bin, lib}, if installed"
rm -f /usr/bin/r
rm -f /usr/lib/{lib7z.so,dummykey.pem,dummycrt.pem}
}
if [ $# -eq 0 ]; then
stdbuild
exit 0
fi
#
# Process options
#
while (( $# ))
do
case "$1" in
--help | -h)
usage
exit 0
;;
--uninstall | -u)
uninstall
exit 0
;;
--full | -f)
if [ $# -eq 1 ]; then
fullbuild
exit 0
fi
case "$2" in
--install | -i)
fullbuild
install
exit 0
;;
*)
badUsage "Option/command not recognized."
exit 1
;;
esac
exit 0
;;
--install | -i)
if [ $# -eq 1 ]; then
stdbuild
install
exit 0
fi
case "$2" in
--fullbuild | -f)
fullbuild
install
exit 0
;;
*)
badUsage "Option/command not recognized."
exit 1
;;
esac
exit 0
;;
*)
badUsage "Option/command not recognized."
exit 1
;;
esac
done
badUsage
exit 1