forked from ricoberger/script_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
99 lines (85 loc) · 3.78 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
WHAT := script_exporter
PROJECT ?= script_exporter
REPO ?= github.com/ricoberger/script_exporter
PWD ?= $(shell pwd)
VERSION ?= $(shell git describe --tags)
REVISION ?= $(shell git rev-parse HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILDUSER ?= $(shell id -un)
BUILDTIME ?= $(shell date '+%Y%m%d-%H:%M:%S')
.PHONY: build build-darwin-amd64 build-linux-amd64 build-linux-armv7 build-linux-arm64 build-windows-amd64 clean release release-major release-minor release-patch
build:
for target in $(WHAT); do \
go build -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \
-X ${REPO}/pkg/version.Revision=${REVISION} \
-X ${REPO}/pkg/version.Branch=${BRANCH} \
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \
-o ./bin/$$target ./cmd/$$target; \
done
build-darwin-amd64:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \
-X ${REPO}/pkg/version.Revision=${REVISION} \
-X ${REPO}/pkg/version.Branch=${BRANCH} \
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \
-o ./bin/$$target-darwin-amd64 ./cmd/$$target; \
done
build-linux-amd64:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \
-X ${REPO}/pkg/version.Revision=${REVISION} \
-X ${REPO}/pkg/version.Branch=${BRANCH} \
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \
-o ./bin/$$target-linux-amd64 ./cmd/$$target; \
done
build-linux-armv7:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=arm GOARM=7 GOOS=linux go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \
-X ${REPO}/pkg/version.Revision=${REVISION} \
-X ${REPO}/pkg/version.Branch=${BRANCH} \
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \
-o ./bin/$$target-linux-armv7 ./cmd/$$target; \
done
build-linux-arm64:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \
-X ${REPO}/pkg/version.Revision=${REVISION} \
-X ${REPO}/pkg/version.Branch=${BRANCH} \
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \
-o ./bin/$$target-linux-arm64 ./cmd/$$target; \
done
build-windows-amd64:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \
-X ${REPO}/pkg/version.Revision=${REVISION} \
-X ${REPO}/pkg/version.Branch=${BRANCH} \
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \
-o ./bin/$$target-windows-amd64.exe ./cmd/$$target; \
done
clean:
rm -rf ./bin
release: clean build-darwin-amd64 build-linux-amd64 build-linux-armv7 build-linux-arm64 build-windows-amd64
release-major:
$(eval MAJORVERSION=$(shell git describe --tags --abbrev=0 | sed s/v// | awk -F. '{print "v"$$1+1".0.0"}'))
git checkout master
git pull
git tag -a $(MAJORVERSION) -m 'release $(MAJORVERSION)'
git push origin --tags
release-minor:
$(eval MINORVERSION=$(shell git describe --tags --abbrev=0 | sed s/v// | awk -F. '{print "v"$$1"."$$2+1".0"}'))
git checkout master
git pull
git tag -a $(MINORVERSION) -m 'release $(MINORVERSION)'
git push origin --tags
release-patch:
$(eval PATCHVERSION=$(shell git describe --tags --abbrev=0 | sed s/v// | awk -F. '{print "v"$$1"."$$2"."$$3+1}'))
git checkout master
git pull
git tag -a $(PATCHVERSION) -m 'release $(PATCHVERSION)'
git push origin --tags