-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
128 lines (110 loc) · 2.98 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
BINARY_NAME=harpoon
BINARY_DIR=./bin
OUTPUT_DIR=./output
IMAGE_NAME?=alegrey91/harpoon
GO_VERSION := $(shell grep '^toolchain' go.mod | awk '{print $$2}' | sed 's/go//')
build-static-libbpfgo:
git submodule update --init --recursive && \
cd libbpfgo && \
make libbpfgo-static
vmlinux.h:
bpftool btf dump file /sys/kernel/btf/vmlinux format c > ebpf/vmlinux.h
build-bpf: create-output-dir
clang -g -O2 -c -target bpf -D__TARGET_ARCH_x86 -o ${OUTPUT_DIR}/ebpf.o ebpf/ebpf.c
cp ${OUTPUT_DIR}/ebpf.o ./internal/embeddable/output/
build-go: create-bin-dir
go mod download
export CURRENT_DIR=$(shell pwd); \
CC=gcc \
CGO_CFLAGS="-I $$CURRENT_DIR/libbpfgo/output" \
CGO_LDFLAGS="-lelf -lz $$CURRENT_DIR/libbpfgo/output/libbpf/libbpf.a" \
go build \
-tags core,ebpf \
-v \
-o ${BINARY_DIR}/${BINARY_NAME} \
.
build-go-cover: create-bin-dir
go mod download
export CURRENT_DIR=$(shell pwd); \
CC=gcc \
CGO_CFLAGS="-I $$CURRENT_DIR/libbpfgo/output" \
CGO_LDFLAGS="-lelf -lz $$CURRENT_DIR/libbpfgo/output/libbpf/libbpf.a" \
go build \
-tags core,ebpf \
-v \
-cover \
-o ${BINARY_DIR}/${BINARY_NAME} \
.
build: create-bin-dir vmlinux.h build-static-libbpfgo build-bpf
go mod download
export CURRENT_DIR=$(shell pwd); \
CC=gcc \
CGO_CFLAGS="-I $$CURRENT_DIR/libbpfgo/output" \
CGO_LDFLAGS="-lelf -lz $$CURRENT_DIR/libbpfgo/output/libbpf/libbpf.a" \
go build \
-tags core,ebpf \
-v \
-o ${BINARY_DIR}/${BINARY_NAME} \
.
build-gh: create-bin-dir vmlinux.h build-static-libbpfgo build-bpf
ifndef GITHUB_REF_NAME
$(error GITHUB_REF_NAME is undefined)
endif
go mod download
export CURRENT_DIR=$(shell pwd); \
CC=gcc \
CGO_CFLAGS="-I $$CURRENT_DIR/libbpfgo/output" \
CGO_LDFLAGS="-lelf -lz $$CURRENT_DIR/libbpfgo/output/libbpf/libbpf.a" \
go build \
-tags core,ebpf \
-v \
-ldflags="-s -w -X 'github.com/alegrey91/harpoon/cmd.Version=${GITHUB_REF_NAME}'" \
-o ${BINARY_DIR}/${BINARY_NAME} \
.
build-docker-gh:
ifdef GITHUB_REF_NAME
docker build \
--no-cache \
--build-arg GO_VERSION=$(GO_VERSION) \
-t $(IMAGE_NAME):latest \
-t $(IMAGE_NAME):$(GITHUB_REF_NAME) \
.
endif
build-docker:
docker build \
--no-cache \
--build-arg GO_VERSION=$(GO_VERSION) \
-t $(IMAGE_NAME):latest \
.
push-docker:
ifdef GITHUB_REF_NAME
docker push ${IMAGE_NAME}:${GITHUB_REF_NAME}
docker push ${IMAGE_NAME}:latest
endif
unit-tests:
mkdir -p /tmp/unit/
go test \
-cover \
-v \
$(shell go list ./... | grep -v "github.com/alegrey91/harpoon$$" | grep -v ebpf | grep -v cmd) \
-skip TestHarpoon \
-args -test.gocoverdir=/tmp/unit/
integration-tests:
mkdir -p /tmp/integration
go test \
-exec sudo \
-cover \
-v main_test.go \
-args -test.gocoverdir=/tmp/integration/
create-bin-dir:
mkdir -p ${BINARY_DIR}
create-output-dir:
mkdir -p ${OUTPUT_DIR}
install:
cp ${BINARY_DIR}/${BINARY_NAME} /usr/local/bin
clean:
rm -rf ${OUTPUT_DIR}
rm -rf ${BINARY_DIR}
rm -rf ./libbpfgo
go-version:
@grep '^toolchain' go.mod | awk '{print $$2}' | sed 's/go//'