-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
83 lines (65 loc) · 1.54 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
71
72
73
74
75
76
77
78
79
80
81
82
83
SHELL=/bin/bash -o pipefail
ARCH ?= $(shell uname -m)
OBJDIR ?= build/$(ARCH)
SRC = src
SRCS = $(wildcard $(SRC)/*.c)
OBJS = $(patsubst $(SRC)/%.c,$(SRC)/%,$(SRCS))
ifdef CLANG_VER
CC = clang-$(CLANG_VER)
LLC = llc-$(CLANG_VER)
OPT = opt-$(CLANG_VER)
LLVM_DIS = llvm-dis-$(CLANG_VER)
LLVM = llvm-$(CLANG_VER)
LIBCLANG_DEV = libclang-$(CLANG_VER)-dev
else
CC = clang
LLC = llc
OPT = opt
LLVM_DIS = llvm-dis
LLVM = llvm
LIBCLANG_DEV = libclang-dev
endif
# If cross-compiling from an M1/M2 Mac then default to aarch64
ifeq ($(ARCH),arm64)
ARCH = aarch64
endif
ifeq ($(ARCH),aarch64)
KERNEL_ARCH_NAME = arm64
else ifeq ($(ARCH),x86_64)
KERNEL_ARCH_NAME = x86
else
$(error Unknown architecture $(ARCH))
endif
CFLAGS += \
-D__TARGET_ARCH_$(KERNEL_ARCH_NAME) \
-DBPF_NO_PRESERVE_ACCESS_INDEX \
-Wall \
-Werror \
-fno-stack-protector \
-Xclang -disable-llvm-passes \
-O2
TARGET = -target $(ARCH)
INCLUDES = -I $(SRC)
clean:
rm -rf $(OBJDIR)
realclean: clean
@:
$(OBJDIR):
mkdir -p $@
mkdir -p $@/wrapped
depends:
apt-get update
apt-get install -y $(LLVM) $(CC) $(LIBCLANG_DEV) binutils coreutils
no_wrapper:
$(MAKE) $(OBJS)
wrapper:
OBJDIR=build/$(ARCH)/wrapped CFLAGS="-DCONFIG_SYSCALL_WRAPPER" $(MAKE) $(OBJS)
$(OBJS): %: %.c
$(CC) $(TARGET) $(CFLAGS) -emit-llvm -c $< $(INCLUDES) -o - | \
$(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \
$(LLC) -march=bpf -filetype=obj -o $(OBJDIR)/$(notdir $@)
all: depends $(OBJDIR) wrapper no_wrapper
@:
dev: $(OBJDIR) wrapper no_wrapper
@:
.PHONY: all realclean clean ebpf ebpf_verifier depends