forked from facebookincubator/katran
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_bpf_modules_opensource.sh
executable file
·98 lines (85 loc) · 3.37 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
86
87
88
89
90
91
92
93
94
95
96
97
#!/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)
#!/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]
-s SRC_DIR (optional): Path to source dir for katran
-b BUILD_DIR (optional): Path to build dir for katran
-h|? Show this help message
EOF
}
while getopts ":hb:s:m" arg; do
case $arg in
b)
BUILD_DIR="${OPTARG}"
;;
s)
SRC_DIR="${OPTARG}"
;;
h | *) # Display help.
usage
exit 0
;;
esac
done
# 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)
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="${BUILD_DIR}"/..
fi
CLANG_PATH="${BUILD_DIR}/deps/clang/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04"
rm -rf "${BUILD_DIR}/deps/bpfprog"
mkdir -p "${BUILD_DIR}/deps/bpfprog/include"
cp "${SRC_DIR}/katran/lib/Makefile-bpf" "${BUILD_DIR}/deps/bpfprog/Makefile"
cp -r "${SRC_DIR}/katran/lib/bpf" "${BUILD_DIR}/deps/bpfprog/"
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="$*" \
LLC="${CLANG_PATH}/bin/llc" CLANG="${CLANG_PATH}/bin/clang"
echo "BPF BUILD COMPLITED"