-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
125 lines (92 loc) · 2.47 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
#### Vars ####
platform = $(shell uname -s)
arch = $(shell uname -m)
prefix = $(shell pwd)/build
app_name = ops
go_deps = $(shell find . -name '*.go')
tag = $(shell git describe --tags $(shell git rev-list --tags --max-count=1))
flags = -ldflags '-s -w'
#### Test Objects ####
test_output_dir = coverage
coverage_profile = $(test_output_dir)/coverage.profile
coverage_out = $(test_output_dir)/coverage.out
#### Build Objects ####
component = $(app_name)_$(tag)
component_path = $(prefix)/$(component)
linux_objects = $(component_path)_linux_$(arch)
darwin_objects = $(component_path)_darwin_$(arch)
#### Gather Objects ####
ifeq ($(platform),Linux)
objects := $(linux_objects)
endif
ifeq ($(platform),Darwin)
objects := $(darwin_objects)
endif
#### Zip File Objects ####
$(foreach o,$(objects), $(eval zips += $(o).zip))
#### Rules Section ####
# builds main executable
.PHONY: all
all: $(app_name)
# builds main executable
$(prefix)/$(app_name): $(go_deps)
go build $(flags) -o $(@)
# build main executable
.PHONY: $(app_name)
$(app_name): $(prefix)/$(app_name)
# build develpment version of main executable
$(prefix)/$(app_name)-dev: $(go_deps)
go build -race $(flags) -o $(@)
# build develpment version of main executable
.PHONY: dev
dev: $(prefix)/$(app_name)-dev
# installs main executable in user's default bin for golang
.PHONY: install
install:
go install $(flags)
# compiles binaries with statically linked libpcap for linux and darwin
$(objects): $(go_deps)
go build $(flags) -o $(@)
# creates zips of pre-built binaries
$(zips): $(objects)
zip -j $(@) $(@:.zip=)
# generates a relase of all pre-built binaries
.PHONY: release
release: $(zips)
.PHONY: lint
lint:
golangci-lint run
.PHONY: test
test:
rm -rf $(test_output_dir)
mkdir -p $(test_output_dir)
go test \
-v \
-race \
-coverprofile $(coverage_profile) \
-covermode=atomic \
./...
.PHONY: print-coverage
print-coverage:
go tool cover -func $(coverage_profile)
.PHONY: coverage
coverage:
go tool cover -func $(coverage_profile) -o=$(coverage_out)
.PHONY: test-report
test-report:
go tool cover -html=$(coverage_profile)
.PHONY: deps
deps:
go install go.uber.org/mock/mockgen@latest
curl \
-sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b $(shell go env GOPATH)/bin v1.55.2
# generate mocks
.PHONY: mock
mock:
go generate ./...
# remove buid directory and installed executable
.PHONY: clean
clean:
rm -f $(GOPATH)/bin/$(app_name)
rm -rf $(prefix)