-
Notifications
You must be signed in to change notification settings - Fork 505
/
build_bpf_modules_opensource.sh
executable file
·85 lines (76 loc) · 2.9 KB
/
build_bpf_modules_opensource.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
#!/usr/bin/env bash
# Copyright (C) 2018-present, Facebook, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
set -xeo pipefail
# this script must be run inside katran's project root
# if you are adding new bpf prog:
# 1) put it into bpf/ dir
# 2) edit Makefile (add new prog into always += section)
# By default it is called from the build dir.
# Optionally BUILD_DIR and SRC_DIR args can be supplied
usage() {
cat 1>&2 <<EOF
Usage ${0##*/} [-h|?] [-s SRC_DIR] [-b BUILD_DIR] [-d DEFINES]
-s SRC_DIR (optional): Path to source dir for katran
-b BUILD_DIR (optional): Path to build dir for katran
-d DEFINES (optional): Specify custom defines for bpf program
-h|? Show this help message
EOF
}
while getopts ":hb:s:d:m" arg; do
case $arg in
b)
BUILD_DIR="${OPTARG}"
;;
s)
SRC_DIR="${OPTARG}"
;;
d)
DEFINES="${OPTARG}"
;;
h) # Display help.
usage
exit 0
;;
esac
done
shift $((OPTIND -1))
# Validate required parameters
if [ -z "${BUILD_DIR-}" ] ; then
echo -e "[ INFO ] BUILD_DIR is not set. So setting it as default to $(pwd)"
BUILD_DIR="$(pwd)/_build/"
fi
# Validate required parameters
if [ -z "${SRC_DIR-}" ] ; then
echo -e "[ INFO ] SRC_DIR is not set. So setting it as default to $(pwd) "
SRC_DIR="$(pwd)"
fi
# Use the clang version based on the one fetched in 'build_katran.sh'
CLANG_PATH="${BUILD_DIR}/deps/clang/clang+llvm-12.0.0-x86_64-linux-gnu-ubuntu-20.04"
if [ -f /etc/redhat-release ]; then
CLANG_PATH=/usr
fi
rm -rf "${BUILD_DIR}/deps/bpfprog"
mkdir -p "${BUILD_DIR}/deps/bpfprog/include"
mkdir -p "${BUILD_DIR}/deps/bpfprog/katran/lib/bpf"
cp "${SRC_DIR}/katran/lib/Makefile-bpf" "${BUILD_DIR}/deps/bpfprog/Makefile"
cp -r "${SRC_DIR}/katran/lib/bpf" "${BUILD_DIR}/deps/bpfprog/katran/lib/"
cp -r "${SRC_DIR}/katran/lib/linux_includes" "${BUILD_DIR}/deps/bpfprog/katran/lib/linux_includes"
cp -r "${SRC_DIR}/katran/decap/bpf" "${BUILD_DIR}/deps/bpfprog/"
cp "${SRC_DIR}"/katran/lib/linux_includes/* "${BUILD_DIR}/deps/bpfprog/include/"
cd "${BUILD_DIR}/deps/bpfprog" && LD_LIBRARY_PATH="${CLANG_PATH}/lib" make \
EXTRA_CFLAGS="${DEFINES}" \
LLC="${CLANG_PATH}/bin/llc" CLANG="${CLANG_PATH}/bin/clang"
echo "BPF BUILD COMPLETED"