-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·104 lines (92 loc) · 1.73 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
#!/bin/sh
set -e
SOURCE_DIR="$(pwd)"
BUILD_DIR="${SOURCE_DIR}/build"
BUILD_BIN="trapit"
PACK_DIR="${SOURCE_DIR}/build/dist"
if ! [ -f "${SOURCE_DIR}/CMakeLists.txt" ]; then
printf >&2 'ERROR: %s is not the source directory which includes %s' \
"${SOURCE_DIR}" "CMakeLists.txt"
exit 2
fi
cmake_configure() {
cmake -S "${SOURCE_DIR}" -B "${BUILD_DIR}" "$@"
}
cmake_build() {
cmake --build "${BUILD_DIR}"
}
cmd_help() {
printf >&2 'Usage: %s [help|clean|build|run]\n' "$0"
}
cmd_clean() {
set -x
rm -rf "${BUILD_DIR}"
}
cmd_build() {
BUILD_TYPE="${1:-Release}"
set -x
if [ -z "$(command -v ninja)" ]; then
cmake_configure -DCMAKE_BUILD_TYPE="$BUILD_TYPE"
else
cmake_configure -DCMAKE_BUILD_TYPE="$BUILD_TYPE" -G Ninja
fi
cmake_build
}
cmd_pack() {
cmd_clean
cmd_build
(
cd "${BUILD_DIR}"
cpack -G TXZ --config CPackSourceConfig.cmake
cpack -G TXZ
if command -v dpkg > /dev/null; then
cpack -G DEB
else
printf >&2 '=> Skip to pack DEB because lack of "dpkg" (dpkg)\n'
fi
if command -v rpmbuild > /dev/null; then
cpack -G RPM
else
printf >&2 '=> Skip to pack RPM because lack of "rpm-tools" (rpmbuild)\n'
fi
rm -rf "${PACK_DIR}/_CPack_Packages"
)
}
cmd_run() {
cmd_build
exec "${BUILD_DIR}/${BUILD_BIN}" "$@"
}
cmd_dbg() {
cmd_build Debug
if command -v gdb > /dev/null; then
exec gdb --args "${BUILD_DIR}/${BUILD_BIN}" "$@"
else
exec lldb -- "${BUILD_DIR}/${BUILD_BIN}" "$@"
fi
}
case "$1" in
help)
cmd_help
;;
clean)
cmd_clean
;;
build)
cmd_build
;;
pack)
cmd_pack
;;
run)
shift
cmd_run "$@"
;;
dbg)
shift
cmd_dbg "$@"
;;
*)
cmd_help
exit 2
;;
esac