-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·433 lines (376 loc) · 12.3 KB
/
build
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!/bin/bash
CMAKE=/usr/bin/cmake
#export CXX=/usr/bin/clang++
clean() {
echo "*****************************************"
echo "** Removing old build **"
echo "*****************************************"
[[ -d bin ]] && rm -fr bin
[[ -d .build ]] && rm -fr .build
[[ -f compile_commands.json ]] && rm compile_commands.json
}
debug() {
echo "*****************************************"
echo "** Building debug binaries **"
echo "*****************************************"
local verbose="$1"
local static="$2"
local buildsys="$3"
# compile static
if [[ "$static" == 1 ]]; then
$CMAKE -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-Denable-static=ON \
-G"$buildsys" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=YES ../../..
[[ $? -eq 0 ]] || exit 1
[[ "$verbose" == 1 ]] && VERBOSE=1 cmake --build . || cmake --build .
# compile dynamic lib
else
$CMAKE -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-Denable-static=OFF \
-G"$buildsys" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=YES ../../..
[[ $? -eq 0 ]] || exit 1
[[ "$verbose" == 1 ]] && VERBOSE=1 cmake --build . || cmake --build .
fi
cp compile_commands.json ../../..
}
release() {
echo "*****************************************"
echo "** Building release binaries **"
echo "*****************************************"
local verbose="$1"
local static="$2"
local buildsys="$3"
# compile static lib
if [[ "$static" == 1 ]]; then
$CMAKE -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-Denable-static=ON \
-G"$buildsys" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=YES ../../..
[[ $? -eq 0 ]] || exit 1
[[ "$verbose" == 1 ]] && VERBOSE=1 cmake --build . || \
cmake --build .
# compile dynamic lib
else
$CMAKE -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-Denable-static=OFF \
-G"$buildsys" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=YES ../../..
[[ $? -eq 0 ]] || exit 1
[[ "$verbose" == 1 ]] && VERBOSE=1 cmake --build . || \
cmake --build .
fi
cp compile_commands.json ../../..
}
coverage() {
echo "*****************************************"
echo "** Running test cases **"
echo "*****************************************"
local static="$1"
local debug="$2"
local verbose="$3"
local buildsys="$4"
local gcovr="$5"
[[ -d googletest-build ]] || update="ON"
[[ -d googletest-src ]] || update="ON"
if [[ "$debug" == 0 ]]; then
$CMAKE -DCMAKE_BUILD_TYPE=Release \
-Denable-test=ON \
-Denable-static="$static" \
-G"$buildsys" \
-Dwith-gcovr="$gcovr" \
-Dupdate-gtest="$update" ../../..
fi
if [[ $debug == 1 ]]; then
$CMAKE -DCMAKE_BUILD_TYPE=Debug \
-Denable-test=ON \
-Denable-static="$static" \
-G"$buildsys" \
-Dwith-gcovr="$gcovr" \
-Dupdate-gtest="$update" ../../..
fi
[[ $? -eq 0 ]] || exit 1
[[ "$verbose" == 1 ]] && VERBOSE=1 cmake --build . -- coverage || \
cmake --build . -- coverage
}
usage() {
local error="$1"
local program="$2"
local option="$3"
[[ "$error" == 1 ]] && echo "option $option not recognized"
cat <<-EOF
Usage: $program [options]
--clear delete build artifacts
--binary build binaries
--test build (and run) test with coverage
--debug debug symbols on (off by default)
--static static library (dynamic by default)
--linux for Linux
--windows for Windows
--update update googletest
--gcovr generate test coverage (requires --test, linux only)
--verbose build verbose mode
--ninja build with ninja (unix make by default)
--apache=PATH build the apache example module (path to dev apache required)
--help print this help and exit
EOF
exit 1
}
just_make() {
echo "*****************************************"
echo "** Make **"
echo "*****************************************"
if [[ -d .build/release ]]; then
cd .build/release
cmake --build .
cp -a bin/* ../../bin/release
cd ../..
fi
if [[ -d .build/debug ]]; then
cd .build/debug
cmake --build .
cp -a bin/* ../../bin/debug
cd ../..
fi
}
build_binary() {
local static="$1"
local debug="$2"
local verbose="$3"
local buildsys="$4"
[[ "$debug" == 1 ]] && debug "$verbose" "$static" "$buildsys"\
|| release "$verbose" "$static" "$buildsys"
}
build_test() {
local static="$1"
local debug="$2"
local verbose="$3"
local buildsys="$4"
local gcovr="$5"
coverage "$static" "$debug" "$verbose" "$buildsys" "$gcovr"
}
build_apache() {
local path="$1"
local www="$path/www"
local example="$www/amps_example"
local libtool="$www/build/libtool"
local apxs="$www/bin/apxs"
if [[ ! -d "$www" || ! -d "$example" || ! -f "$libtool" ]]; then
echo "$www not found"
exit 1
fi
mkdir -p "$example"
cp apache/amps_wrapper.cpp apache/amps_wrapper.h apache/mod_cool_framework.c \
apache/template.tpl apache/template_xml.tpl "$example"
local amps="$PWD"
pushd "$example"
echo "Compiling amps"
$libtool --mode=compile g++ -std=c++17 -I"$amps/include" -I"$www/include" \
-fPIC amps_wrapper.cpp -lm -o wrapper.lo -c -g3
[[ $? != 0 ]] && exit 1
$apxs -I"$amps/include" -c -i mod_cool_framework.c wrapper.lo libamps-static.a
[[ $? != 0 ]] && exit 1
exit 0
echo "Configuring module"
echo "LoadFile /usr/lib64/libstdc++.so.6" >> "$path/www/conf/httpd.conf"
echo "LoadModule cool_framework_module modules/mod_cool_framework.so" >> "$path/www/conf/httpd.conf"
echo "<Location /cool_framework>" >> "$path/www/conf/httpd.conf"
echo "SetHandler cool_framework" >> "$path/www/conf/httpd.conf"
echo "</Location>" >> "$path/www/conf/httpd.conf"
echo "Done. Reload the server and access http://localhost/cool_framework"
popd
}
main() {
local test=0
local clear=0
local debug=0
local release=0
local windows=0
local linux=0
local verbose=0
local binary=0
local static=0
local gcovr="OFF"
local buildsys="Unix Makefiles"
local update="OFF"
local apache_path=""
if [[ -z "$1" ]]; then
just_make
exit 0
fi
while [[ "$1" == --* ]]; do
local opt="$1"
shift
case "$opt" in
--test)
test=1
;;
--binary)
binary=1
;;
--clear)
clear=1
;;
--release)
release=1
;;
--debug)
debug=1
;;
--static)
static=1
;;
--linux)
linux=1
;;
--windows)
windows=1
;;
--update)
update="ON"
;;
--ninja)
buildsys="Ninja"
;;
--apache=*)
apache_path="${opt##*=}"
;;
--verbose)
verbose=1
;;
--gcovr)
gcovr="ON";
;;
--help)
usage 0 "$0" ""
;;
*)
usage 1 "$0" "$opt"
;;
esac
done
if [[ "$gcovr" == "ON" && "$test" == 0 ]]
then
echo "gcovr option can be eanbled with --test only, disabling it"
gcovr="OFF";
fi
[[ "$clear" == 1 ]] && clean
if [[ "$buildsys" == "Ninja" ]]; then
if [[ $(which ninja > /dev/null 2>&1; echo $?) != 0 ]]; then
echo "Ninja build system not found, using Make instead"
buildsys="Unix Makefiles";
fi
fi
if [[ "$windows" == 1 ]]; then
#export CC=/usr/bin/i686-w64-mingw32-gcc
#export CXX=/usr/bin/i686-w64-mingw32-g++
#CMAKE=/usr/bin/mingw32-cmake
CMAKE=cmake
buildsys="Visual Studio 15 2017"
if [[ "$binary" == 1 ]]; then
mkdir -p bin/windows
mkdir -p .build/windows
cd .build/windows
# generate release version
if [[ "$debug" == 0 || "$release" == 1 ]]; then
mkdir -p ../../bin/windows/release
mkdir -p release
cd release
build_binary "$static" 0 "$verbose" "$buildsys"
cd ..
cp -a release/bin/* ../../bin/windows/release
# generate debug version
else
mkdir -p ../../bin/windows/debug
mkdir -p debug
cd debug
build_binary "$static" 1 "$verbose" "$buildsys"
cd ..
cp -a debug/bin/* ../../bin/windows/debug
fi
cd ../..
fi
if [[ "$test" == 1 ]]; then
mkdir -p .build/windows
cd .build/windows
# generate release version
if [[ "$debug" == 0 || "$release" == 1 ]]; then
mkdir -p ../../bin/windows/release
mkdir -p release
cd release
build_test "$static" 0 "$update" "$buildsys" "OFF"
cd ..
cp -a release/bin/* ../../bin/windows/release
# generate debug version
else
mkdir -p ../../bin/windows/debug
mkdir -p debug
cd debug
build_test "$static" 1 "$update" "$buildsys" "OFF"
cd ..
cp -a debug/bin/* ../../bin/windows/debug
fi
cd ../..
fi
fi
if [[ "$linux" == 1 ]]; then
#export CC=/usr/bin/gcc
#export CXX=/usr/bin/g++
#CMAKE=/usr/bin/cmake
CMAKE=cmake
if [[ "$binary" == 1 ]]; then
mkdir -p bin/linux
mkdir -p .build/linux
cd .build/linux
# generate release version
if [[ "$debug" == 0 || "$release" == 1 ]]; then
mkdir -p ../../bin/linux/release
mkdir -p release
cd release
build_binary "$static" 0 "$verbose" "$buildsys"
cd ..
cp -a release/bin/* ../../bin/linux/release
# generate debug version
else
mkdir -p ../../bin/linux/debug
mkdir -p debug
cd debug
build_binary "$static" 1 "$verbose" "$buildsys"
cd ..
cp -a debug/bin/* ../../bin/linux/debug
fi
cd ../..
fi
if [[ "$test" == 1 ]]; then
mkdir -p bin/linux
mkdir -p .build/linux
cd .build/linux
# generate release version
if [[ "$debug" == 0 || "$release" == 1 ]]; then
mkdir -p ../../bin/linux/release
mkdir -p release
cd release
build_test "$static" 0 "$update" "$buildsys" "$gcovr"
cd ..
cp -a release/bin/* ../../bin/linux/release
# generate debug version
else
mkdir -p ../../bin/linux/debug
mkdir -p debug
cd debug
build_test "$static" 1 "$update" "$buildsys" "$gcovr"
cd ..
cp -a debug/bin/* ../../bin/linux/debug
fi
cd ../..
fi
fi
[[ -d "$apache_path" ]] && build_apache "$apache_path"
exit 0
}
main $@