forked from mackerelio/mackerel-agent-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
105 lines (83 loc) · 3.11 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
VERSION = 0.51.0
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)
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 $@`
build: deps
for i in mackerel-plugin-*; do \
$(MAKE) $(BINDIR)/$$i; \
done
build/mackerel-plugin: deps
mkdir -p build
go build -ldflags="-s -w -X main.gitcommit=$(CURRENT_REVISION)" \
-o build/mackerel-plugin
test: testgo lint testconvention
testgo: testdeps
go test $(VERBOSE_FLAG) ./...
testconvention:
prove -r t/
go generate ./... && git diff --exit-code || \
(echo 'please `go generate ./...` and commit them' && false)
deps:
go get -d -v ./...
testdeps:
go get -d -v -t ./...
go get github.com/golang/lint/golint
go get golang.org/x/tools/cmd/cover
go get github.com/pierrre/gotestcover
go get github.com/mattn/goveralls
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
lint: testdeps
go vet ./...
golint -set_exit_status ./...
cover: testdeps
gotestcover -v -covermode=count -coverprofile=.profile.cov -parallelpackages=4 ./...
rpm: rpm-v1 rpm-v2
rpm-v1:
$(MAKE) build GOOS=linux GOARCH=386
rpmbuild --define "_sourcedir `pwd`" --define "_bindir build/linux/386" \
--define "_version ${VERSION}" --define "buildarch noarch" \
-bb packaging/rpm/mackerel-agent-plugins.spec
$(MAKE) build GOOS=linux GOARCH=amd64
rpmbuild --define "_sourcedir `pwd`" --define "_bindir build/linux/amd64" \
--define "_version ${VERSION}" --define "buildarch x86_64" \
-bb packaging/rpm/mackerel-agent-plugins.spec
rpm-v2:
$(MAKE) build/mackerel-plugin GOOS=linux GOARCH=amd64
rpmbuild --define "_sourcedir `pwd`" --define "_version ${VERSION}" \
--define "buildarch x86_64" --define "dist .el7.centos" \
-bb packaging/rpm/mackerel-agent-plugins-v2.spec
rpmbuild --define "_sourcedir `pwd`" --define "_version ${VERSION}" \
--define "buildarch x86_64" --define "dist .amzn2" \
-bb packaging/rpm/mackerel-agent-plugins-v2.spec
deb: deb-v1 deb-v2
deb-v1:
$(MAKE) build GOOS=linux GOARCH=386
for i in `cat packaging/deb/debian/source/include-binaries`; do \
cp build/linux/386/`basename $$i` packaging/deb/debian/; \
done
cd packaging/deb && debuild --no-tgz-check -rfakeroot -uc -us
deb-v2:
$(MAKE) build/mackerel-plugin GOOS=linux GOARCH=amd64
cp build/mackerel-plugin packaging/deb-v2/debian/
cd packaging/deb-v2 && debuild --no-tgz-check -rfakeroot -uc -us
release: check-release-deps
(cd tool && cpanm -qn --installdeps .)
perl tool/create-release-pullrequest
clean:
@if [ -d build ]; then rm -rfv build; fi
.PHONY: all build test testgo deps testdeps rpm rpm-v1 rpm-v2 deb deb-v1 deb-v2 clean release lint cover testconvention