forked from niclashedam/ebpf-kill-example
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
43 lines (30 loc) · 1.13 KB
/
Makefile
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
CLANG = clang
LINUX_VERSION = v5.4
EXECABLE = src/ebpf-kill-example
BPFCODE = src/bpf_program
BPFTOOLS = kernel-src/samples/bpf
BPFLOADER = $(BPFTOOLS)/bpf_load.c
CCINCLUDE += -Ikernel-src/tools/testing/selftests/bpf
CCINCLUDE += -Ikernel-src/tools/lib/bpf
LOADINCLUDE += -Ikernel-src/samples/bpf
LOADINCLUDE += -Ikernel-src/tools/lib
LOADINCLUDE += -Ikernel-src/tools/perf
LOADINCLUDE += -Ikernel-src/tools/include
LIBRARY_PATH = -Llib64
BPFSO = -lbpf
.PHONY: clean bpfload build deps
deps:
sudo apt update
sudo apt install -y build-essential git make gcc clang libelf-dev gcc-multilib
kernel-src:
git clone --depth 1 --single-branch --branch ${LINUX_VERSION} https://github.com/torvalds/linux.git kernel-src
cd kernel-src/tools/lib/bpf && make && make install prefix=../../../../
clean:
rm -f src/*.o src/*.so $(EXECABLE)
build: kernel-src ${BPFCODE.c} ${BPFLOADER}
$(CLANG) -O2 -target bpf -c $(BPFCODE:=.c) $(CCINCLUDE) -o ${BPFCODE:=.o}
bpfload: build
$(CLANG) -O2 -o $(EXECABLE) -lelf $(LOADINCLUDE) $(LIBRARY_PATH) $(BPFSO) \
$(BPFLOADER) -DHAVE_ATTR_TEST=0 src/loader.c
$(EXECABLE): bpfload
.DEFAULT_GOAL := $(EXECABLE)