-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (115 loc) · 3.69 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
NAME := pagient-cli
IMPORT := github.com/pagient/$(NAME)
DIST := dist
ifeq ($(OS), Windows_NT)
EXECUTABLE := $(NAME).exe
HAS_RETOOL := $(shell where retool ;)
else
EXECUTABLE := $(NAME)
HAS_RETOOL := $(shell command -v retool ;)
endif
PACKAGES ?= $(shell go list ./... | grep -v /vendor/ | grep -v /_tools/)
SOURCES ?= $(shell find . -name "*.go" -type f -not -path "./vendor/*" -not -path "./_tools/*")
TAGS ?=
ifndef VERSION
ifneq ($(DRONE_TAG),)
VERSION ?= $(subst v,,$(DRONE_TAG))
else
ifneq ($(DRONE_BRANCH),)
VERSION ?= 0.0.0-$(subst /,,$(DRONE_BRANCH))
else
VERSION ?= 0.0.0-master
endif
endif
endif
ifndef SHA
SHA := $(shell git rev-parse --short HEAD)
endif
ifndef DATE
DATE := $(shell date -u '+%Y%m%d')
endif
LDFLAGS += -s -w -X "$(IMPORT)/pkg/version.VersionString=$(VERSION)" -X "$(IMPORT)/pkg/version.VersionDev=$(SHA)" -X "$(IMPORT)/pkg/version.VersionDate=$(DATE)"
.PHONY: all
all: build
.PHONY: update
update:
retool do dep ensure -update
.PHONY: sync
sync:
retool do dep ensure
.PHONY: clean
clean:
go clean -i ./...
rm -rf bin/ $(DIST)/binaries $(DIST)/release
.PHONY: fmt
fmt:
gofmt -s -w $(SOURCES)
.PHONY: vet
vet:
go vet $(PACKAGES)
.PHONY: megacheck
megacheck:
retool do megacheck -tags '$(TAGS)' $(PACKAGES)
.PHONY: lint
lint:
for PKG in $(PACKAGES); do retool do golint -set_exit_status $$PKG || exit 1; done;
.PHONY: generate
generate:
retool do go generate $(PACKAGES)
.PHONY: test
test:
retool do goverage -v -coverprofile coverage.out $(PACKAGES)
.PHONY: install
install: $(SOURCES)
go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME)
.PHONY: build
build: bin/$(EXECUTABLE)
bin/$(EXECUTABLE): $(SOURCES)
go build -i -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release
release: release-dirs release-windows release-linux release-darwin release-copy release-check
.PHONY: release-dirs
release-dirs:
mkdir -p $(DIST)/binaries $(DIST)/release
.PHONY: release-windows
release-windows:
ifeq ($(CI),drone)
xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out $(EXECUTABLE)-$(VERSION) ./cmd/$(NAME)
mv /build/* $(DIST)/binaries
else
retool do xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out $(EXECUTABLE)-$(VERSION) ./cmd/$(NAME)
endif
.PHONY: release-linux
release-linux:
ifeq ($(CI),drone)
xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out $(EXECUTABLE)-$(VERSION) ./cmd/$(NAME)
mv /build/* $(DIST)/binaries
else
retool do xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out $(EXECUTABLE)-$(VERSION) ./cmd/$(NAME)
endif
.PHONY: release-darwin
release-darwin:
ifeq ($(CI),drone)
xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out $(EXECUTABLE)-$(VERSION) ./cmd/$(NAME)
mv /build/* $(DIST)/binaries
else
retool do xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out $(EXECUTABLE)-$(VERSION) ./cmd/$(NAME)
endif
.PHONY: release-copy
release-copy:
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
.PHONY: release-check
release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
.PHONY: publish
publish: release
.PHONY: docs
docs:
hugo -s docs/
.PHONY: retool
retool:
ifndef HAS_RETOOL
go get -u github.com/twitchtv/retool
endif
retool sync
retool build