-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
101 lines (88 loc) · 2.81 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
.PHONY: all check auto_install generate build install install_bin install_ui clean
RM := rm -f
RMDIR := rm -rf
MKDIRP := mkdir -p
CPDIR := cp -r
PROTO_DIR := proto
FRONTEND_DIR := frontend
GRAFANA_DIR := grafana_app
INSTALL_DIR := ./install/
METADATA_DIR := $(if $(DESTDIR),$(DESTDIR),$(HOME))/hermes/
SRC_CONFIG_DIR := ./config/
DST_CONFIG_DIR := $(METADATA_DIR)/config/
INSTALL_BIN := install -m 755
DST_BIN_DIR := /usr/sbin/
CFLAGS := -O2 -g -Wall -Werror $(CFLAGS)
ARCH := $(shell dpkg --print-architecture)
all: clean build
check:
go vet ./...
auto_install:
ifeq ($(shell dpkg -s curl 2> /dev/null; echo $$?), 1)
apt install -y curl
endif
ifeq ($(shell dpkg -s llvm 2> /dev/null; echo $$?), 1)
apt install -y llvm
endif
ifeq ($(shell dpkg -s clang 2> /dev/null; echo $$?), 1)
apt install -y clang
endif
ifeq ($(shell dpkg -s libbpf-dev 2> /dev/null; echo $$?), 1)
apt install -y libbpf-dev
endif
ifeq ($(shell dpkg -s protobuf-compiler 2> /dev/null; echo $$?), 1)
apt install -y protobuf-compiler
endif
ifeq ($(shell dpkg -s pkg-config 2> /dev/null; echo $$?), 1)
apt install -y pkg-config
endif
ifeq ($(shell dpkg -s sudo 2> /dev/null; echo $$?), 1)
apt install -y sudo
endif
ifeq ($(shell dpkg -s gnupg 2> /dev/null; echo $$?), 1)
apt install -y gnupg
endif
ifeq ($(shell dpkg -s nodejs 2> /dev/null; echo $$?), 1)
apt install -y ca-certificates
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt update
apt install -y nodejs
endif
snap install go --classic
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
build: auto_install ui backend grafana
generate: export BPF_CLANG := clang
generate: export BPF_CFLAGS := $(CFLAGS)
generate: export BPF_ARCH := $(ARCH)
generate: export BPF_VMLINUX_HEADER := ../header/$(ARCH)
generate: auto_install
go generate ./backend/ebpf/...
backend: generate
make -C $(PROTO_DIR) build
go build -ldflags "-X main.metadataDir=$(METADATA_DIR)" -o $(INSTALL_DIR) ./...
ui: auto_install
make -C $(FRONTEND_DIR) build
grafana: auto_install
make -C $(GRAFANA_DIR) build
install: install_bin install_ui
install_bin:
$(MKDIRP) $(DESTDIR)$(DST_BIN_DIR)
$(INSTALL_BIN) $(INSTALL_DIR)* $(DESTDIR)$(DST_BIN_DIR)
$(MKDIRP) $(DST_CONFIG_DIR)
$(CPDIR) $(SRC_CONFIG_DIR)* $(DST_CONFIG_DIR)
install_ui:
make -C $(FRONTEND_DIR) install
clean:
ifneq ($(shell which go),)
go clean
endif
$(RMDIR) $(INSTALL_DIR)
$(RM) ./backend/ebpf/*/bpf_bpfeb*.go
$(RM) ./backend/ebpf/*/bpf_bpfeb*.o
$(RM) ./backend/ebpf/*/bpf_bpfel*.go
$(RM) ./backend/ebpf/*/bpf_bpfel*.o
make -C $(PROTO_DIR) clean
make -C $(FRONTEND_DIR) clean
make -C $(GRAFANA_DIR) clean