forked from hgfischer/go-otp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
100 lines (76 loc) · 2.23 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
SOURCES := $(shell find . -type f -name '*.go')
GOTOOLDIR := $(shell go env GOTOOLDIR)
LINT := $(GOBIN)/golint
GODOCDOWN := $(GOBIN)/godocdown
VET := $(GOTOOLDIR)/vet
COVER := $(GOTOOLDIR)/cover
PKGS := $(shell go list ./...)
PKG := $(shell go list)
COVER_OUT := coverage.out
COVER_HTML := coverage.html
TMP_COVER := tmp_cover.out
.PHONY: default
default: test
.PHONY: check_gopath
check_gopath:
ifndef GOPATH
@echo "ERROR!! GOPATH must be declared. Check http://golang.org/doc/code.html#GOPATH"
@exit 1
endif
ifeq ($(shell go list ./... | grep -q '^_'; echo $$?), 0)
@echo "ERROR!! This directory should be at $(GOPATH)/src/$(REPO)"
@exit 1
endif
@exit 0
.PHONY: check_gobin
check_gobin:
ifndef GOBIN
@echo "ERROR!! GOBIN must be declared. Check http://golang.org/doc/code.html#GOBIN"
@exit 1
endif
@exit 0
.PHONY: clean
clean: check_gopath
@echo "Removing temp files..."
@rm -fv *.cover *.out *.html
@go clean -v
.PHONY: test
test: $(SYMLINK) check_gopath
@go get -t
@for pkg in $(PKGS); do go test -v -race $$pkg || exit 1; done
$(COVER): check_gopath check_gobin
@go get code.google.com/p/go.tools/cmd/cover || exit 0
.PHONY: cover
cover: check_gopath $(COVER)
@echo 'mode: set' > $(COVER_OUT)
@touch $(TMP_COVER)
@for pkg in $(PKGS); do \
go test -v -coverprofile=$(TMP_COVER) $$pkg || exit 1; \
grep -v 'mode: set' $(TMP_COVER) >> $(COVER_OUT); \
done
@go tool cover -html=$(COVER_OUT) -o $(COVER_HTML)
@(which gnome-open && gnome-open $(COVER_HTML)) || (which -s open && open $(COVER_HTML)) || (exit 0)
@echo Generated HTML report in $(COVER_HTML)...
$(LINT): check_gopath check_gobin
@go get github.com/golang/lint/golint
.PHONY: lint
lint: $(LINT)
@for src in $(SOURCES); do golint $$src || exit 1; done
.PHONY: check_vet
check_vet:
@if [ ! -x $(VET) ]; then \
echo Missing Go vet tool! Please install with the following command...; \
echo sudo go get code.google.com/p/go.tools/cmd/vet; \
exit 1; \
fi
.PHONY: vet
vet: check_gopath check_vet
@for src in $(SOURCES); do go tool vet $$src; done
$(GODOCDOWN): check_gopath check_gobin
@go get github.com/robertkrimen/godocdown/godocdown
.PHONY: doc
doc: $(GODOCDOWN)
@godocdown $(PKG) > GODOC.md
.PHONY: fmt
fmt:
@gofmt -s -w .