-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (118 loc) · 3.96 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
include .bingo/Variables.mk
SHELL := bash
NAME := gopad-cli
IMPORT := github.com/gopad/$(NAME)
BIN := bin
DIST := dist
ifeq ($(OS), Windows_NT)
EXECUTABLE := $(NAME).exe
UNAME := Windows
else
EXECUTABLE := $(NAME)
UNAME := $(shell uname -s)
endif
GOBUILD ?= CGO_ENABLED=0 go build
PACKAGES ?= $(shell go list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f -not -iname mock.go -not -path ./.devenv/\* -not -path ./.direnv/\*)
TAGS ?= netgo
ifndef OUTPUT
ifeq ($(GITHUB_REF_TYPE), tag)
OUTPUT ?= $(subst v,,$(GITHUB_REF_NAME))
else
OUTPUT ?= testing
endif
endif
ifndef VERSION
ifeq ($(GITHUB_REF_TYPE), tag)
VERSION ?= $(subst v,,$(GITHUB_REF_NAME))
else
VERSION ?= $(shell git rev-parse --short HEAD)
endif
endif
ifndef DATE
DATE := $(shell date -u '+%Y%m%d')
endif
ifndef SHA
SHA := $(shell git rev-parse --short HEAD)
endif
LDFLAGS += -s -w -extldflags "-static" -X "$(IMPORT)/pkg/version.String=$(VERSION)" -X "$(IMPORT)/pkg/version.Revision=$(SHA)" -X "$(IMPORT)/pkg/version.Date=$(DATE)"
GCFLAGS += all=-N -l
.PHONY: all
all: build
.PHONY: sync
sync:
go mod download
.PHONY: clean
clean:
go clean -i ./...
rm -rf $(BIN) $(DIST)
.PHONY: fmt
fmt:
gofmt -s -w $(SOURCES)
.PHONY: vet
vet:
go vet $(PACKAGES)
.PHONY: golangci
golangci: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run ./...
.PHONY: staticcheck
staticcheck: $(STATICCHECK)
$(STATICCHECK) -tags '$(TAGS)' $(PACKAGES)
.PHONY: lint
lint: $(REVIVE)
for PKG in $(PACKAGES); do $(REVIVE) -config revive.toml -set_exit_status $$PKG || exit 1; done;
.PHONY: generate
generate:
go generate $(PACKAGES)
.PHONY: test
test: test
go test -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)
$(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(BIN)/$(EXECUTABLE)-debug: $(SOURCES)
$(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -gcflags '$(GCFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release
release: $(DIST) release-linux release-darwin release-windows release-checksum
$(DIST):
mkdir -p $(DIST)
.PHONY: release-linux
release-linux: $(DIST) \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-386 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-amd64 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-5 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-6 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-7 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm64
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-5:
GOOS=linux GOARCH=arm GOARM=5 $(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-6:
GOOS=linux GOARCH=arm GOARM=6 $(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-7:
GOOS=linux GOARCH=arm GOARM=7 $(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-%:
GOOS=linux GOARCH=$* $(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release-darwin
release-darwin: $(DIST) \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-darwin-amd64 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-darwin-arm64
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-darwin-%:
GOOS=darwin GOARCH=$* $(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release-windows
release-windows: $(DIST) \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-windows-4.0-amd64.exe \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-windows-4.0-arm64.exe \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-windows-4.0-%.exe:
GOOS=windows GOARCH=$* $(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release-reduce
release-reduce:
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),upx $(notdir $(file));)
.PHONY: release-checksum
release-checksum:
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
.PHONY: release-finish
release-finish: release-reduce release-checksum