-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (54 loc) · 1.63 KB
/
Copy pathMakefile
File metadata and controls
70 lines (54 loc) · 1.63 KB
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
# make V=1 // to see full commands
ifeq ($(V),1)
Q =
msg =
else
Q = @
msg = @printf ' %-8s %s%s\n' "$(1)" "$(2)" "$(if $(3), $(3))";
endif
CLANG := clang-13
CFLAGS ?= -g -O2 -Werror -Wall
LDLIBS := -lm
all: libebpf example test
BIN_DIR = bin
OUT_DIR := $(BIN_DIR)/objs
SRC_FILES = $(wildcard src/*.c)
OBJ_FILES = $(patsubst src/%.c, $(OUT_DIR)/%.o, $(SRC_FILES))
BPF_FILES = $(wildcard example/bpf/*.ebpf.c)
BPF_ELF = $(patsubst example/bpf/%.ebpf.c, $(BIN_DIR)/bpf/%.ebpf, $(BPF_FILES))
mk_out_dir:
$(Q)mkdir -p $(OUT_DIR)
$(Q)mkdir -p $(BIN_DIR)/bpf
# make libebpf
libebpf: bin/libebpf.a
bin/objs/%.o: src/%.c | mk_out_dir
$(Q)$(CC) $(CFLAGS) -I inc/ -c $< -o $@
bin/libebpf.a: $(OBJ_FILES)
$(call msg,AR,$@)
$(Q)$(AR) rcs $@ $(OUT_DIR)/*.o
# make test program
example: libebpf
$(call msg,build example,$@)
$(Q)$(CC) example/test_vm.c -static $(CFLAGS) $(LDLIBS) -I inc/ -L bin/ -l:libebpf.a -o bin/vm
$(Q)$(CC) example/test_code.c -static $(CFLAGS) $(LDLIBS) -I inc/ -L bin/ -l:libebpf.a -o bin/code
# 单元测试
# 测试libebpf基本功能
# %.ebpf: %.ebpf.c
# $(call msg,build bpf,$@)
# $(CLANG) -g -O2 -target bpf -c $^ -o bin/bpf/$@
$(BIN_DIR)/bpf/%.ebpf: example/bpf/%.ebpf.c
$(call msg,build bpf,$@)
$(CLANG) -g -O2 -target bpf -c $^ -o $@
smoke_test: example $(BPF_ELF)
$(call msg,smoke test,$@)
$(Q)python3 tools/write_mem.py
$(Q)mv mem $(BIN_DIR)/
# $(BIN_DIR)/vm -m $(BIN_DIR)/mem $(BIN_DIR)/bpf/test1.ebpf
$(Q)python3 tools/compile_code.py -s example/bpf/test1.ebpf.c -f example/test_code.h
$(BIN_DIR)/code
unitest:
$(call msg,unitest,$@)
nosetests3 -v test
test: smoke_test unitest
clean:
rm -rf $(BIN_DIR)