1
- BIN =bin
2
- KRNDIR =/home/rahul/rnd/linux-5.3
3
- CL =clang
4
- CC =gcc
5
- CFLAGS: =-Isrc -O2 -Wall
6
- KCFLAGS: =$(CFLAGS ) -funroll-loops -I/usr/include/x86_64-linux-gnu -O2 -target bpf
7
- UCFLAGS: =$(CFLAGS ) -I $(KRNDIR ) /tools/lib -Wall
8
- ULDFLAGS: =$(KRNDIR ) /tools/lib/bpf/libbpf.a -lelf
1
+ ifeq (,$(KRNDIR ) )
2
+ KRNDIR = /home/rahul/rnd/linux-5.3
3
+ endif
4
+
5
+ BIN = bin
6
+ CL = clang
7
+ CC = gcc
8
+ Q = @
9
+
10
+ ifeq ($(V ) ,1)
11
+ Q =
12
+ endif
13
+
14
+ # This is shamelessly copied from kernel's samples/bpf/Makefile
15
+ KF = -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/7/include \
16
+ -I$(KRNDIR ) /arch/x86/include -I$(KRNDIR ) /arch/x86/include/generated \
17
+ -I$(KRNDIR ) /include -I$(KRNDIR ) /arch/x86/include/uapi \
18
+ -I$(KRNDIR ) /arch/x86/include/generated/uapi -I$(KRNDIR ) /include/uapi \
19
+ -I$(KRNDIR ) /include/generated/uapi \
20
+ -include $(KRNDIR ) /include/linux/kconfig.h \
21
+ -include asm_goto_workaround.h \
22
+ -I$(KRNDIR ) /samples/bpf -I$(KRNDIR ) /tools/testing/selftests/bpf/ -Isrc \
23
+ -D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
24
+ -D__TARGET_ARCH_x86 -Wno-compare-distinct-pointer-types \
25
+ -Wno-gnu-variable-sized-type-not-at-end \
26
+ -Wno-address-of-packed-member -Wno-tautological-compare \
27
+ -Wno-unknown-warning-option \
28
+ -O2 -emit-llvm
29
+
30
+ UF = -Isrc -O2 -I $(KRNDIR ) /tools/lib -Wall
31
+ UDF = $(KRNDIR ) /tools/lib/bpf/libbpf.a -lelf
32
+
9
33
SRCDIR =src
10
34
11
35
SRCS_KERN: =$(wildcard $(SRCDIR ) /* -kern.c)
@@ -18,18 +42,29 @@ UBINS:=$(patsubst %.c,$(BIN)/%.bin,$(SRCN))
18
42
19
43
vpath % .c $(SRCDIR )
20
44
45
+ RED =\033[0;31m
46
+ GREEN =\033[0;32m
47
+ CYAN =\033[0;36m
48
+ NC =\033[0m
49
+
21
50
.PHONY : all
22
- all : mkdir $(BOBJS ) $(UBINS )
51
+ all : chkdir $(BOBJS ) $(UBINS )
23
52
24
- .PHONY : mkdir
25
- mkdir :
53
+ .PHONY : chkdir
54
+ chkdir :
55
+ ifeq (,$(wildcard $(KRNDIR ) /Kconfig) )
56
+ @echo "Your kernel path[$(RED)$(KRNDIR)$(NC)] is incorrect. Use 'make KRNDIR=[KERNEL-SRC-PATH]'."
57
+ Quitting abnormally
58
+ endif
26
59
@mkdir -p $(BIN) 2>/dev/null
27
60
28
61
$(BIN ) /% .bin : % .c
29
- $(CC ) $(UCFLAGS ) $< -o $@ $(ULDFLAGS )
62
+ @echo " Compiling user-space app: $( CYAN) $@ $( NC) ..."
63
+ $(Q )$(CC ) $(UF ) $< -o $@ $(UDF )
30
64
31
65
$(BIN ) /% .bo : % .c
32
- $(CL ) $(KCFLAGS ) -c $< -o $@
66
+ @echo " Compiling eBPF bytecode: $( GREEN) $@ $( NC) ..."
67
+ $(Q )$(CL ) $(KF ) -c $< -o -| llc -march=bpf -mcpu=probe -filetype=obj -o $@
33
68
34
69
.PHONY : clean
35
70
clean :
0 commit comments