-
Notifications
You must be signed in to change notification settings - Fork 88
/
Makefile
198 lines (170 loc) · 8.33 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
MACKEREL_AGENT_NAME ?= "mackerel-agent"
MACKEREL_API_BASE ?= "https://api.mackerelio.com"
VERSION := 0.82.0
CURRENT_REVISION := $(shell git rev-parse --short HEAD)
ARGS := "-conf=mackerel-agent.conf"
BUILD_OS_TARGETS := "linux darwin freebsd windows netbsd"
export GO111MODULE=on
BUILD_LDFLAGS := "\
-X main.version=$(VERSION) \
-X main.gitcommit=$(CURRENT_REVISION) \
-X github.com/mackerelio/mackerel-agent/config.agentName=$(MACKEREL_AGENT_NAME) \
-X github.com/mackerelio/mackerel-agent/config.apibase=$(MACKEREL_API_BASE)"
.PHONY: all
all: clean test build
.PHONY: test
test:
go test -v -short $(TESTFLAGS) ./...
.PHONY: build
build: deps
CGO_ENABLED=0 go build -ldflags=$(BUILD_LDFLAGS) \
-o build/$(MACKEREL_AGENT_NAME)
.PHONY: run
run: build
./build/$(MACKEREL_AGENT_NAME) $(ARGS)
.PHONY: deps
deps:
go install \
github.com/Songmu/gocredits/cmd/gocredits \
github.com/Songmu/goxz/cmd/goxz \
.PHONY: credits
credits: deps
go mod tidy # not `go get` to get all the dependencies regardress of OS, architecture and build tags
gocredits -skip-missing -w .
.PHONY: lint
lint:
golangci-lint run
.PHONY: convention
convention:
go generate ./... && git diff --exit-code || \
(echo 'please `go generate ./...` and commit them' && false)
.PHONY: crossbuild
crossbuild: deps credits
cp mackerel-agent.sample.conf mackerel-agent.conf
goxz -build-ldflags=$(BUILD_LDFLAGS) \
-os=linux,freebsd,netbsd -arch=386 -d ./snapshot \
-include=mackerel-agent.conf \
-n $(MACKEREL_AGENT_NAME) -o $(MACKEREL_AGENT_NAME)
goxz -build-ldflags=$(BUILD_LDFLAGS) \
-os=linux,darwin,freebsd,netbsd -arch=amd64 -d ./snapshot \
-include=mackerel-agent.conf \
-n $(MACKEREL_AGENT_NAME) -o $(MACKEREL_AGENT_NAME)
goxz -build-ldflags=$(BUILD_LDFLAGS) \
-os=linux,freebsd,netbsd -arch=arm -d ./snapshot \
-include=mackerel-agent.conf \
-n $(MACKEREL_AGENT_NAME) -o $(MACKEREL_AGENT_NAME)
goxz -build-ldflags=$(BUILD_LDFLAGS) \
-os=linux,darwin -arch=arm64 -d ./snapshot \
-include=mackerel-agent.conf \
-n $(MACKEREL_AGENT_NAME) -o $(MACKEREL_AGENT_NAME)
goxz -build-ldflags=$(BUILD_LDFLAGS) \
-os=linux -arch=mips -d ./snapshot \
-include=mackerel-agent.conf \
-n $(MACKEREL_AGENT_NAME) -o $(MACKEREL_AGENT_NAME)
.PHONY: cover
cover: deps
go test -race -short -covermode=atomic -coverprofile=.profile.cov ./...
# Depending to deps looks like not needed.
# However `make build` in recipe depends deps,
# and it would install some tools as GOARCH=386 if tools are not installed.
# We should be installed tools of native architecture.
.PHONY: crossbuild-package
crossbuild-package: deps
mkdir -p ./build-linux-386 ./build-linux-amd64 ./build-linux-arm64 ./build-linux-mips ./build-linux-armhf
GOOS=linux GOARCH=386 make build
mv build/$(MACKEREL_AGENT_NAME) build-linux-386/
GOOS=linux GOARCH=amd64 make build
mv build/$(MACKEREL_AGENT_NAME) build-linux-amd64/
GOOS=linux GOARCH=arm64 make build
mv build/$(MACKEREL_AGENT_NAME) build-linux-arm64/
GOOS=linux GOARCH=mips make build
mv build/$(MACKEREL_AGENT_NAME) build-linux-mips/
GOOS=linux GOARCH=arm GOARM=6 make build # specify ARMv6 for supporting Raspberry Pi 1 / Zero
mv build/$(MACKEREL_AGENT_NAME) build-linux-armhf/
.PHONY: crossbuild-package-kcps
crossbuild-package-kcps:
make crossbuild-package MACKEREL_AGENT_NAME=mackerel-agent-kcps MACKEREL_API_BASE=http://198.18.0.16
.PHONY: crossbuild-package-stage
crossbuild-package-stage:
make crossbuild-package MACKEREL_AGENT_NAME=mackerel-agent-stage MACKEREL_API_BASE=http://0.0.0.0
.PHONY: rpm
rpm: rpm-v2
.PHONY: rpm-v2
rpm-v2: rpm-v2-x86 rpm-v2-arm
.PHONY: rpm-v2-x86
rpm-v2-x86: crossbuild-package
MACKEREL_AGENT_NAME=$(MACKEREL_AGENT_NAME) _tools/packaging/prepare-rpm-build.sh
docker run --rm -v "$(PWD)":/workspace -v "$(PWD)/rpmbuild":/rpmbuild mackerel/docker-mackerel-rpm-builder:u8 \
--define "_sourcedir /workspace/packaging/rpm-build/src" --define "_builddir /workspace/build-linux-amd64" \
--define "_version ${VERSION}" --define "buildarch x86_64" --target x86_64 --define "dist .el7.centos" \
-bb packaging/rpm-build/$(MACKEREL_AGENT_NAME).spec
MACKEREL_AGENT_NAME=$(MACKEREL_AGENT_NAME) _tools/packaging/prepare-rpm-build.sh
docker run --rm -v "$(PWD)":/workspace -v "$(PWD)/rpmbuild":/rpmbuild mackerel/docker-mackerel-rpm-builder:u8 \
--define "_sourcedir /workspace/packaging/rpm-build/src" --define "_builddir /workspace/build-linux-amd64" \
--define "_version ${VERSION}" --define "buildarch x86_64" --target x86_64 --define "dist .amzn2" \
-bb packaging/rpm-build/$(MACKEREL_AGENT_NAME).spec
.PHONY: rpm-v2-arm
rpm-v2-arm: crossbuild-package
MACKEREL_AGENT_NAME=$(MACKEREL_AGENT_NAME) _tools/packaging/prepare-rpm-build.sh
docker run --rm -v "$(PWD)":/workspace -v "$(PWD)/rpmbuild":/rpmbuild mackerel/docker-mackerel-rpm-builder:u8 \
--define "_sourcedir /workspace/packaging/rpm-build/src" --define "_builddir /workspace/build-linux-arm64" \
--define "_version ${VERSION}" --define "buildarch aarch64" --target aarch64 --define "dist .el7.centos" \
-bb packaging/rpm-build/$(MACKEREL_AGENT_NAME).spec
MACKEREL_AGENT_NAME=$(MACKEREL_AGENT_NAME) _tools/packaging/prepare-rpm-build.sh
docker run --rm -v "$(PWD)":/workspace -v "$(PWD)/rpmbuild":/rpmbuild mackerel/docker-mackerel-rpm-builder:u8 \
--define "_sourcedir /workspace/packaging/rpm-build/src" --define "_builddir /workspace/build-linux-arm64" \
--define "_version ${VERSION}" --define "buildarch aarch64" --target aarch64 --define "dist .amzn2" \
-bb packaging/rpm-build/$(MACKEREL_AGENT_NAME).spec
.PHONY: deb
deb: crossbuild-package
BUILD_DIRECTORY=build-linux-amd64 MACKEREL_AGENT_NAME=$(MACKEREL_AGENT_NAME) _tools/packaging/prepare-deb-build.sh
cd packaging/deb-build && debuild --no-tgz-check -rfakeroot -uc -us
BUILD_DIRECTORY=build-linux-arm64 MACKEREL_AGENT_NAME=$(MACKEREL_AGENT_NAME) _tools/packaging/prepare-deb-build.sh
cd packaging/deb-build && debuild --no-tgz-check -rfakeroot -uc -us -aarm64
BUILD_DIRECTORY=build-linux-mips MACKEREL_AGENT_NAME=$(MACKEREL_AGENT_NAME) _tools/packaging/prepare-deb-build.sh
cd packaging/deb-build && debuild --no-tgz-check -rfakeroot -uc -us -amips
BUILD_DIRECTORY=build-linux-armhf MACKEREL_AGENT_NAME=$(MACKEREL_AGENT_NAME) _tools/packaging/prepare-deb-build.sh
cd packaging/deb-build && debuild --no-tgz-check -rfakeroot -uc -us -aarmhf
.PHONY: rpm-kcps
rpm-kcps: rpm-kcps-v2
.PHONY: rpm-kcps-v2
rpm-kcps-v2: crossbuild-package-kcps
MACKEREL_AGENT_NAME=mackerel-agent-kcps _tools/packaging/prepare-rpm-build.sh
docker run --rm -v "$(PWD)":/workspace -v "$(PWD)/rpmbuild":/rpmbuild mackerel/docker-mackerel-rpm-builder:u8 \
--define "_sourcedir /workspace/packaging/rpm-build/src" --define "_builddir /workspace/build-linux-amd64" \
--define "_version ${VERSION}" --define "buildarch x86_64" --target x86_64 --define "dist .el7.centos" \
-bb packaging/rpm-build/mackerel-agent-kcps.spec
.PHONY: deb-kcps
deb-kcps: crossbuild-package-kcps
MACKEREL_AGENT_NAME=mackerel-agent-kcps BUILD_DIRECTORY=build-linux-amd64 _tools/packaging/prepare-deb-build.sh
cd packaging/deb-build && debuild --no-tgz-check -rfakeroot -uc -us
.PHONY: rpm-stage
rpm-stage: rpm-stage-v2
.PHONY: rpm-stage-v2
rpm-stage-v2: crossbuild-package-stage
MACKEREL_AGENT_NAME=mackerel-agent-stage _tools/packaging/prepare-rpm-build.sh
docker run --rm -v "$(PWD)":/workspace -v "$(PWD)/rpmbuild":/rpmbuild mackerel/docker-mackerel-rpm-builder:u8 \
--define "_sourcedir /workspace/packaging/rpm-build/src" --define "_builddir /workspace/build-linux-amd64" \
--define "_version ${VERSION}" --define "buildarch x86_64" --target x86_64 --define "dist .el7.centos" \
-bb packaging/rpm-build/mackerel-agent-stage.spec
.PHONY: deb-stage
deb-stage: crossbuild-package-stage
MACKEREL_AGENT_NAME=mackerel-agent-stage BUILD_DIRECTORY=build-linux-amd64 _tools/packaging/prepare-deb-build.sh
cd packaging/deb-build && debuild --no-tgz-check -rfakeroot -uc -us
tgz_dir = "build/tgz/$(MACKEREL_AGENT_NAME)"
.PHONY: tgz
tgz: credits
GOOS=linux GOARCH=386 make build
rm -rf $(tgz_dir)
mkdir -p $(tgz_dir)
cp mackerel-agent.sample.conf $(tgz_dir)/$(MACKEREL_AGENT_NAME).conf
cp build/$(MACKEREL_AGENT_NAME) LICENSE CREDITS $(tgz_dir)/
tar cvfz build/$(MACKEREL_AGENT_NAME)-latest.tar.gz -C build/tgz $(MACKEREL_AGENT_NAME)
.PHONY: clean
clean:
rm -f build/$(MACKEREL_AGENT_NAME) build-linux-{386,amd64,arm64,mips,armhf}/$(MACKEREL_AGENT_NAME) CREDITS
go clean
.PHONY: update
update:
go get -u ./...
go mod tidy