-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMakefile
50 lines (42 loc) · 1.27 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
.PHONY: help
help:
@echo "lint run lint"
@echo "release-all compile for all platforms "
@echo "build build"
PROJECT=zkcli
VERSION=$(shell cat main.go |grep 'version = "[0-9]\+.[0-9]\+.[0-9]\+"' | awk -F '"' '{print $$2}')
GIT_COMMIT=$(shell git rev-parse --short HEAD)
BUILT_TIME=$(shell date -u '+%FT%T%z')
GOVERSION=$(shell go version)
GOOS=$(word 1,$(subst /, ,$(lastword $(GOVERSION))))
GOARCH=$(word 2,$(subst /, ,$(lastword $(GOVERSION))))
LDFLAGS="-X main.gitCommit=${GIT_COMMIT} -X main.built=${BUILT_TIME}"
ARCNAME=$(PROJECT)-$(VERSION)-$(GOOS)-$(GOARCH)
RELDIR=$(ARCNAME)
DISTDIR=dist
export GO111MODULE=on
.PHONY: release
release:
rm -rf $(DISTDIR)/$(RELDIR)
mkdir -p $(DISTDIR)/$(RELDIR)
go clean
GOOS=$(GOOS) GOARCH=$(GOARCH) make build
cp $(PROJECT)$(SUFFIX_EXE) $(DISTDIR)/$(RELDIR)/
tar czf $(DISTDIR)/$(ARCNAME).tar.gz -C $(DISTDIR) $(RELDIR)
go clean
.PHONY: release-all
release-all:
@$(MAKE) release GOOS=linux GOARCH=amd64
@$(MAKE) release GOOS=linux GOARCH=386
@$(MAKE) release GOOS=linux GOARCH=arm64
@$(MAKE) release GOOS=darwin GOARCH=amd64
@$(MAKE) release GOOS=darwin GOARCH=arm64
.PHONY: build
build:
CGO_ENABLED=0 go build -ldflags ${LDFLAGS}
.PHONY: lint
lint:
gofmt -s -w .
golint .
golint core
go vet