-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·119 lines (101 loc) · 2.93 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
#!/bin/bash
BUILD_DIR="build"
BPFSEC_SRC_DIR="bpf"
# dependencies array
DEPS=('yaml-cpp')
function prepare_preqs() {
local tools=linux-tools-generic
dpkg -l ${tools} > /dev/null
if [ $? -eq 1 ]; then
echo "installing ${tools}"
sudo apt install ${tools} linux-tools-$(uname -r)
fi
dpkg -l libbpf-dev > /dev/null
[ $? -eq 1 ] && sudo apt install libbpf-dev || true
# check for ninja
dpkg -l ninja-build > /dev/null
[ $? -eq 1 ] && sudo apt install ninja-build || true
# create vmlinux header file using bpftool
if [ ! -f ${BPFSEC_SRC_DIR}/vmlinux.h ]; then
bpftool btf dump file /sys/kernel/btf/vmlinux format c > ${BPFSEC_SRC_DIR}/vmlinux.h
fi
make -C libbpf/src BUILD_STATIC_ONLY=1 OBJDIR=$(pwd)/${BUILD_DIR}/libbpf
local libbpf_include_dir="libbpf/include/libbpf"
[ ! -d ${libbpf_include_dir} ] && mkdir ${libbpf_include_dir} || true
cp libbpf/src/*.h ${libbpf_include_dir}
# install each dependency
for dep in ${DEPS[@]}; do
vcpkg install ${dep}
done
}
function build() {
local build_type=Debug
local is_rebuild=false
if [ "$1" == "debug" ] || [ "$1" == "Debug" ]; then
if [ ! -d build-debug ]; then
mkdir build-debug
is_rebuild=true
fi
BUILD_DIR=${BUILD_DIR}-debug
else
if [ ! -d build-release ]; then
mkdir build-release
is_rebuild=true
fi
BUILD_DIR=${BUILD_DIR}-release
build_type=release
fi
if [ "${is_rebuild}" = true ]; then
prepare_preqs
fi
cd ${BUILD_DIR} && cmake -G Ninja -DCMAKE_BUILD_TYPE=${build_type} .. && ninja
}
function clean() {
if [ "$1" == "debug" ] || [ "$1" == "Debug" ]; then
[ -d build-debug ] && rm -rf build-debug || echo "Nothing to be cleaned ;-)";
else
[ -d build-release ] && rm -rf build-release || echo "Nothing to be cleaned ;-)";
fi
}
function menu() {
PS3='>> '
options=("build debug" "build release" "clean debug" "clean release" "exit")
select opt in "${options[@]}"
do
case $opt in
"build debug")
build debug
break
;;
"build release")
build release
break
;;
"clean debug")
clean debug
break
;;
"clean release")
clean release
break
;;
"exit")
break
;;
*) echo "invalid option $REPLY"
break
;;
esac
done
}
cat << END
____ __ _____
| _ \ / _/ ____|
| |_) |_ __ | || (___ ___ ___
| _ <| '_ \| _\___ \ / _ \/ __|
| |_) | |_) | | ____) | __/ (__
|____/| .__/|_||_____/ \___|\___|
| |
|_|
END
menu