-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMakefile
66 lines (52 loc) · 1.93 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
TARGETS := memcpy_kprobe
TARGETS += memcpy_stat
# Generate file name-scheme based on TARGETS
KERN_SOURCES = ${TARGETS:=_kern.c}
USER_SOURCES = ${TARGETS:=_user.c}
KERN_OBJECTS = ${KERN_SOURCES:.c=.o}
USER_OBJECTS = ${USER_SOURCES:.c=.o}
# Notice: the kbuilddir can be redefined on make cmdline
KERNEL ?= /lib/modules/$(shell uname -r)/build/
CFLAGS := -O2 -Wall
CFLAGS += -I ./
EXTRA_CFLAGS=-Werror
LDFLAGS= -lelf
BPFLIB = bpf/bpf.o
BPFLIB += bpf_load.o
LLC ?= llc
CLANG ?= clang
CC = gcc
NOSTDINC_FLAGS := -nostdinc -isystem $(shell $(CC) -print-file-name=include)
ARCH=$(shell uname -m | sed 's/x86_64/x86/' | sed 's/i386/x86/')
LINUXINCLUDE += -I$(KERNEL)/arch/$(ARCH)/include/generated/uapi
LINUXINCLUDE += -I$(KERNEL)/arch/$(ARCH)/include/generated
LINUXINCLUDE += -I$(KERNEL)/arch/$(ARCH)/include
LINUXINCLUDE += -I$(KERNEL)/arch/$(ARCH)/include/uapi
LINUXINCLUDE += -I$(KERNEL)/include
LINUXINCLUDE += -I$(KERNEL)/include/uapi
LINUXINCLUDE += -include $(KERNEL)/include/linux/kconfig.h
LINUXINCLUDE += -I$(KERNEL)/include/generated/uapi
all: $(TARGETS) $(KERN_OBJECTS)
.PHONY: clean $(CLANG) $(LLC)
clean:
rm -f *.ll
rm -f $(BPFLIB)
rm -f $(TARGETS)
rm -f $(KERN_OBJECTS)
rm -f $(USER_OBJECTS)
# clang option -S generated output file with suffix .ll
# which is the non-binary LLVM assembly language format
# (normally LLVM bitcode format .bc is generated)
#
$(KERN_OBJECTS): %.o: %.c bpf_helpers.h
#it will generate .ll file which is actually a LLVM assembly code
$(CLANG) -S $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
-Wno-compare-distinct-pointer-types \
-Wno-gnu-variable-sized-type-not-at-end \
-Wno-tautological-compare \
-O2 -emit-llvm -c $<
#now translate LLVM assembly to native assembly
$(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll}
$(TARGETS): %: %_user.c $(BPFLIB) Makefile
$(CC) $(CFLAGS) $(BPFLIB) $(LDFLAGS) -o $@ $<