-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
73 lines (59 loc) · 2.47 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
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
# kbuild trick to avoid linker error. Can be omitted if a module is built.
obj- := dummy.o
# List of programs to build
hostprogs-y := sandfs
sandfs-objs := \
src/main.o src/utils.o src/ebpf.o src/libbpf.o src/bpf_load.o
# Generate .c files based on kernel source
%.c:
cp $(objtree)/samples/bpf/bpf_load.c $(PWD)/src/.
if [ -f $(objtree)/samples/bpf/libbpf.c ]; then \
cp $(objtree)/samples/bpf/libbpf.c $(PWD)/src/.; \
else \
cp $(objtree)/tools/lib/bpf/bpf.c $(PWD)/src/libbpf.c; \
fi;
# Tell kbuild to always build the programs
always := $(hostprogs-y)
always += bpf/sandfs.o
EXTRA_CFLAGS += -I$(PWD)/include -I$(objtree)/samples/bpf
HOSTCFLAGS += -fPIC -I$(objtree)/usr/include -I$(PWD)/include
HOSTCFLAGS += -I$(objtree)/samples/bpf -I$(objtree)/tools/lib -I$(objtree)/tools/lib/bpf
HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
HOSTCFLAGS_libbpf.o += -I$(objtree)/usr/include -Wno-unused-variable
HOSTLOADLIBES_sandfs += -lelf -lcap -lpthread
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
LLC ?= llc
CLANG ?= clang
# Trick to allow make to be run from this directory
all:
$(MAKE) -C /lib/modules/`uname -r`/build $$PWD/
clean:
$(MAKE) -C /lib/modules/`uname -r`/build M=$$PWD clean
rm -f src/*.o xdp/*.o *.a *.so sandfs
rm -f include/bpf_helpers.h include/bpf_load.h include/libbpf.h
rm -f src/libbpf.c src/bpf_load.c
# Verify LLVM compiler tools are available and bpf target is supported by llc
.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
verify_cmds: $(CLANG) $(LLC)
@for TOOL in $^ ; do \
if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
exit 1; \
else true; fi; \
done
verify_target_bpf: verify_cmds
@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
echo " NOTICE: LLVM version >= 3.7.1 required" ;\
exit 2; \
else true; fi
$(src)/*.c: verify_target_bpf
# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
# But, there is no easy way to fix it, so just exclude it since it is
# useless for BPF samples.
$(obj)/%.o: $(src)/%.c
$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
-Wno-compare-distinct-pointer-types \
-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@