-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
66 lines (52 loc) · 1.29 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
PKG := $(shell head -1 go.mod | sed -e 's/module //')
PKG_LIST := $(shell go list ${PKG}/...)
GO_FILES := $(shell find . -name '*.go')
OUT := $(shell basename ${PKG} | sed -e 's/\.git//')
DIST := $(OUT).zip
VERSION := $(shell git describe --tag --long --dirty 2>/dev/null)
ifeq ($(VERSION),)
VERSION = development
endif
INSTALLBIN := $(GOPATH)/bin
ifeq ($(GOPATH),)
INSTALLBIN = ~/go/bin
endif
all: build
.PHONY: build
build: vet lint {{ .ProjectName }}
ifeq ($(TRAVIS_OS_NAME),windows)
OUT := $(OUT).exe
.PHONY: {{ .ProjectName }}
endif
{{ .ProjectName }}:
go build -v -o $(OUT) -ldflags="-X '{{ .GitURLNoProto }}/cmd.version=$(VERSION)'" $(PKG)
ifeq ($(DIST_NAME),)
DIST_NAME = $(OUT)
endif
.PHONY: dist
dist: {{ .ProjectName }}
zip $(DIST_NAME).zip $(OUT)
.PHONY: install
install: {{ .ProjectName }}
install -D $(OUT) $(INSTALLBIN)
c.out:
go test -coverprofile=c.out -v $(PKG)/...
@echo Total coverage: `go tool cover -func c.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}'`%
cover.html: c.out
go tool cover -html=c.out -o cover.html
.PHONY: clean
clean:
rm -f $(OUT) $(OUT).exe $(OUT).exe.zip $(DIST) c.out
.PHONY: lint
lint:
@for file in $(GO_FILES); do \
golint $$file ; \
done
.PHONY: test
test: c.out
.PHONY: tidy
tidy:
@go mod tidy
.PHONY: vet
vet:
@go vet $(PKG_LIST)