-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
65 lines (52 loc) · 1.39 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
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
TARGET := xdpdump
LLC ?= llc
CLANG ?= clang
CC ?= gcc
LIBBPF_DIR = ../libbpf/src/
XDP_C = ${TARGET:=_kern.c}
XDP_OBJ = ${XDP_C:.c=.o}
USER_C = ${TARGET:=_user.c}
USER_OBJ = ${USER_C:.c=.o}
OBJECT_LIBBPF = $(LIBBPF_DIR)/libbpf.a
CFLAGS ?= -I$(LIBBPF_DIR)/root/usr/include/
CFLAGS += -I../headers/
LDFLAGS ?= -L$(LIBBPF_DIR)
LIBS = -lbpf -lelf
all: llvm-check $(TARGET) $(XDP_OBJ)
.PHONY: clean $(CLANG) $(LLC)
clean:
cd $(LIBBPF_DIR) && $(MAKE) clean;
rm -f $(TARGET)
rm -f $(XDP_OBJ)
rm -f $(USER_OBJ)
rm -f *.ll
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; \
mkdir -p root; DESTDIR=root $(MAKE) install_headers; \
fi
$(TARGET): %: %_user.c $(OBJECT_LIBBPF) Makefile
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
$(XDP_OBJ): %.o: %.c
$(CLANG) -S \
-D __BPF_TRACING__ \
$(CFLAGS) \
-Wall \
-Wno-unused-value \
-Wno-pointer-sign \
-Wno-compare-distinct-pointer-types \
-Werror \
-O2 -emit-llvm -c -g $<
$(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll}