-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
96 lines (82 loc) · 2.71 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
GO := go
GO_BUILD = CGO_ENABLED=1 $(GO) build -v -trimpath
GO_GENERATE = $(GO) generate
GO_TAGS ?=
TARGET_GOARCH ?= amd64
GOARCH ?= amd64
TARGET=vista
INSTALL = $(QUIET)install
BINDIR ?= /usr/local/bin
VERSION=$(shell git describe --tags --always)
LIBPCAP_ARCH ?= x86_64-unknown-linux-gnu
# For compiling libpcap and CGO
CC ?= gcc
TEST_TIMEOUT ?= 5s
.DEFAULT_GOAL := vista
## Build the GO binary only
.PHONY: gobuild
gobuild:
CC=$(CC) GOARCH=$(TARGET_GOARCH) $(GO_BUILD) $(if $(GO_TAGS),-tags $(GO_TAGS)) \
-ldflags "-w -s \
-X 'github.com/Asphaltt/vista/internal/vista.Version=${VERSION}'"
.PHONY: gogen
gogen:
TARGET_GOARCH=$(TARGET_GOARCH) $(GO_GENERATE) ./internal/build
## Build the GO binary with libpcap and BPF
vista: libpcap/libpcap.a gogen gobuild
## Build libpcap for static linking
libpcap/libpcap.a:
cd libpcap && \
CC=$(LIBPCAP_CC) ./configure --disable-rdma --disable-shared --disable-usb --disable-netmap --disable-bluetooth --disable-dbus --without-libnl --host=$(LIBPCAP_ARCH) && \
make
## Build the GO binary within a Docker container
release:
docker run \
--rm \
--workdir /vista \
--volume `pwd`:/vista docker.io/library/golang:1.21.5 \
sh -c "apt update && apt install -y make git clang-15 llvm curl gcc flex bison gcc-aarch64* libc6-dev-arm64-cross && \
ln -s /usr/bin/clang-15 /usr/bin/clang && \
git config --global --add safe.directory /vista && \
make local-release"
## Build a new release
local-release: clean
ARCHS='amd64 arm64' ./local-release.sh
## Install the GO Binary to the location specified by 'BINDIR'
install: $(TARGET)
$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 0755 $(TARGET) $(DESTDIR)$(BINDIR)
## Clean up build artifacts
clean:
rm -f $(TARGET)
rm -f kprobevista_bpf*
rm -f kprobemultivista_bpf*
rm -f kprobevistawithoutoutputskb_bpf*
rm -f kprobemultivistawithoutoutputskb_bpf*
cd libpcap/ && make clean || true
## Run GO tests
test:
$(GO) test -timeout=$(TEST_TIMEOUT) -race -cover $$($(GO) list ./...)
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
TARGET_MAX_CHAR_NUM=20
## Show this help
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z0-9_-]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.PHONY: $(TARGET) build release local-release install clean test