This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
forked from mackerelio/mackerel-agent-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
146 lines (119 loc) · 4.16 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
VERSION = 0.63.5
VERBOSE_FLAG = $(if $(VERBOSE),-verbose)
CURRENT_REVISION = $(shell git rev-parse --short HEAD)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
BINDIR = build/$(GOOS)/$(GOARCH)
export GO111MODULE=on
.PHONY: all
all: lint cover testconvention rpm deb
.SECONDEXPANSION:
$(BINDIR)/mackerel-plugin-%: mackerel-plugin-%/main.go $$(wildcard mackerel-plugin-%/lib/*.go)
@if [ ! -d $(BINDIR) ]; then mkdir -p $(BINDIR); fi
go build -ldflags="-s -w" -o $@ ./`basename $@`
.PHONY: build
build:
for i in mackerel-plugin-*; do \
$(MAKE) $(BINDIR)/$$i; \
done
build/mackerel-plugin: $(patsubst %,depends_on,$(GOOS)$(GOARCH))
mkdir -p build
go build -ldflags="-s -w -X main.gitcommit=$(CURRENT_REVISION)" \
-o build/mackerel-plugin
.PHONY: depends_on
depends_on:
@:
.PHONY: test
test: testgo lint testconvention
.PHONY: testgo
testgo: testdeps
go test $(VERBOSE_FLAG) ./...
.PHONY: testconvention
testconvention:
prove -r t/
go generate ./... && git diff --exit-code -- . ':(exclude)go.*' || \
(echo 'please `go generate ./...` and commit them' && false)
.PHONY: testdeps
testdeps:
cd && go get golang.org/x/lint/golint \
golang.org/x/tools/cmd/cover \
github.com/mattn/goveralls
.PHONY: check-release-deps
check-release-deps:
@have_error=0; \
for command in cpanm hub ghch gobump; do \
if ! command -v $$command > /dev/null; then \
have_error=1; \
echo "\`$$command\` command is required for releasing"; \
fi; \
done; \
test $$have_error = 0
.PHONY: lint
lint: testdeps
golint -set_exit_status ./...
.PHONY: cover
cover: testdeps
#go test -race -covermode=atomic -coverprofile=.profile.cov ./...
go test -covermode=atomic -coverprofile=.profile.cov ./...
.PHONY: rpm
rpm: rpm-v1 rpm-v2
.PHONY: rpm-v1
rpm-v1:
$(MAKE) build GOOS=linux GOARCH=arm
rpmbuild --define "_sourcedir `pwd`" --define "_bindir build/linux/arm" \
--define "_version ${VERSION}" --define "buildarch noarch" \
--target armv7l -bb packaging/rpm/mackerel-agent-plugins.spec
$(MAKE) build GOOS=linux GOARCH=arm64
rpmbuild --define "_sourcedir `pwd`" --define "_bindir build/linux/arm64" \
--define "_version ${VERSION}" --define "buildarch noarch" \
--target aarch64 -bb packaging/rpm/mackerel-agent-plugins.spec
.PHONY: rpm-v2
rpm-v2: rpm-v2-x86 rpm-v2-arm
.PHONY: rpm-v2-x86
rpm-v2-x86:
$(MAKE) build/mackerel-plugin GOOS=linux GOARCH=amd64
rpmbuild --define "_sourcedir `pwd`" --define "_version ${VERSION}" \
--define "buildarch x86_64" --define "dist .el7.centos" \
--target x86_64 -bb packaging/rpm/mackerel-agent-plugins-v2.spec
rpmbuild --define "_sourcedir `pwd`" --define "_version ${VERSION}" \
--define "buildarch x86_64" --define "dist .amzn2" \
--target x86_64 -bb packaging/rpm/mackerel-agent-plugins-v2.spec
.PHONY: rpm-v2-arm
rpm-v2-arm:
$(MAKE) build/mackerel-plugin GOOS=linux GOARCH=arm64
rpmbuild --define "_sourcedir `pwd`" --define "_version ${VERSION}" \
--define "buildarch noarch" --define "dist .el7.centos" \
--target aarch64 -bb packaging/rpm/mackerel-agent-plugins-v2.spec
rpmbuild --define "_sourcedir `pwd`" --define "_version ${VERSION}" \
--define "buildarch noarch" --define "dist .amzn2" \
--target aarch64 -bb packaging/rpm/mackerel-agent-plugins-v2.spec
.PHONY: deb
deb: deb-v1 deb-v2
.PHONY: deb-v1
deb-v1:
$(MAKE) build GOOS=linux GOARCH=arm
for i in `cat packaging/deb/debian/source/include-binaries`; do \
cp build/linux/arm/`basename $$i` packaging/deb/debian/; \
done
cd packaging/deb && debuild --no-tgz-check -rfakeroot -uc -us -aarmhf
.PHONY: deb-v2
deb-v2:
$(MAKE) build/mackerel-plugin GOOS=linux GOARCH=arm64
cp build/mackerel-plugin packaging/deb-v2/debian/
cd packaging/deb-v2 && debuild --no-tgz-check -rfakeroot -uc -us -aarm64
.PHONY: deb-v2-arm
deb-v2-arm:
$(MAKE) build/mackerel-plugin GOOS=linux GOARCH=arm64
cp build/mackerel-plugin packaging/deb-v2/debian/
cd packaging/deb-v2 && debuild --no-tgz-check -rfakeroot -uc -us -aarm64
.PHONY: release
release: check-release-deps
(cd tool && cpanm -qn --installdeps .)
perl tool/create-release-pullrequest
.PHONY: clean
clean:
@if [ -d build ]; then rm -rfv build; fi
.PHONY: update
update:
go get -u ./...
go mod tidy