-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
70 lines (55 loc) · 1.55 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
XDP_TARGETS := reflector
USER_TARGETS :=
LLC ?= llc
CLANG ?= clang
CC ?= gcc
XDP_C = ${XDP_TARGETS:=.c}
XDP_OBJ = ${XDP_C:.c=.o}
USER_C := ${USER_TARGETS:=.c}
USER_OBJ := ${USER_C:.c=.o}
LIBBPF_DIR ?= ./libbpf/src/
OBJECT_LIBBPF = $(LIBBPF_DIR)/libbpf.a
EXTRA_DEPS +=
CFLAGS ?= -I$(LIBBPF_DIR)/build/usr/include/ -g
LDFLAGS ?= -L$(LIBBPF_DIR)
BPF_CFLAGS ?= -I$(LIBBPF_DIR)/build/usr/include/
LIBS = -l:libbpf.a -lelf $(USER_LIBS)
all: llvm-check $(USER_TARGETS) $(XDP_OBJ)
.PHONY: clean $(CLANG) $(LLC)
clean:
rm -rf $(LIBBPF_DIR)/build
$(MAKE) -C $(LIBBPF_DIR) clean
rm -f $(USER_TARGETS) $(XDP_OBJ) $(USER_OBJ)
rm -f *.ll
rm -f *~
llvm-check: $(CLANG) $(LLC)
@for TOOL in $^ ; do \
if [ ! $$(command -v $${TOOL} 2>/dev/null) ]; then \
echo "*** ERROR: Cannot find tool $${TOOL}" ;\
exit 1; \
else true; fi; \
done
$(OBJECT_LIBBPF):
@if [ ! -d $(LIBBPF_DIR) ]; then \
echo "Error: Need libbpf submodule"; \
echo "May need to run git submodule update --init"; \
exit 1; \
else \
cd $(LIBBPF_DIR) && $(MAKE) all OBJDIR=.; \
mkdir -p build; $(MAKE) install_headers DESTDIR=build OBJDIR=.; \
fi
$(USER_TARGETS): %: %.c $(OBJECT_LIBBPF) Makefile
$(CC) -Wall $(CFLAGS) $(LDFLAGS) -o $@ \
$< $(LIBS)
$(XDP_OBJ): %.o: %.c Makefile $(OBJECT_LIBBPF)
$(CLANG) -S \
-target bpf \
-D __BPF_TRACING__ \
$(BPF_CFLAGS) \
-Wall \
-Wno-unused-value \
-Wno-pointer-sign \
-Wno-compare-distinct-pointer-types \
-Werror \
-O2 -emit-llvm -c -g -o ${@:.o=.ll} $<
$(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll}