-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
53 lines (41 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
.ONESHELL:
SHELL = /bin/sh
BCC_SRC = ../../bcc
LIBBPF_SRC = $(BCC_SRC)/src/cc/libbpf
LIBBPF_TOOLS_SRC = $(BCC_SRC)/libbpf-tools
BPFTOOL_SRC = $(LIBBPF_TOOLS_SRC)/bpftool
LIBBPF_TOOLS_OUTPUT = $(abspath $(LIBBPF_TOOLS_SRC)/.output)
LIBBPF_OBJ = $(abspath $(LIBBPF_TOOLS_OUTPUT)/libbpf.a)
CLANG = clang
GIT = git
TOOL_NAME = $(shell basename $(abspath ./))
TOOL_BPF_OBJ = $(abspath $(LIBBPF_TOOLS_OUTPUT)/$(TOOL_NAME).bpf.o)
CGO_CFLAGS_STATIC = "-I$(abspath $(LIBBPF_TOOLS_OUTPUT))"
CGO_LDFLAGS_STATIC = "-lelf -lz -lzstd $(LIBBPF_OBJ)"
CGO_EXTLDFLAGS_STATIC = '-w -extldflags "-static"'
.PHONY: $(TOOL_NAME)
$(TOOL_NAME): $(TOOL_NAME).bpf.o install_uapi_headers
CC=$(CLANG) CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \
CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \
go build -tags netgo -ldflags $(CGO_EXTLDFLAGS_STATIC)
.PHONY: $(TOOL_NAME).bpf.o
$(TOOL_NAME).bpf.o: $(LIBBPF_SRC) $(BPFTOOL_SRC) $(TOOL_BPF_OBJ)
cp $(TOOL_BPF_OBJ) ./
.PHONY: $(LIBBPF_SRC)
$(LIBBPF_SRC):
cd $(BCC_SRC)
$(GIT) submodule update --init --recursive
.PHONY: $(BPFTOOL_SRC)
$(BPFTOOL_SRC):
cd $(BCC_SRC)
$(GIT) submodule update --init --recursive
.PHONY: $(TOOL_BPF_OBJ)
$(TOOL_BPF_OBJ):
cd $(LIBBPF_TOOLS_SRC)
@if ! test -d /usr/include/asm; then
sudo ln -s /usr/include/asm-generic /usr/include/asm
fi
$(MAKE)
.PHONY: install_uapi_headers
install_uapi_headers:
$(MAKE) -C $(LIBBPF_SRC)/src UAPIDIR=$(LIBBPF_TOOLS_OUTPUT) install_uapi_headers