-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
76 lines (65 loc) · 2.03 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
PROJECT_SINCE:=$(shell git log --pretty=format:"%ad" --date=unix|tail -1)
AUTO_COUNT_SINCE:=$(shell echo $$(((`date -u +%s`-$(PROJECT_SINCE))/(24*60*60))))
AUTO_COUNT_LOG:=$(shell git log --since=midnight --oneline|wc -l|tr -d " ")
COMMIT:=4b825dc
REVIEWDOG:=| reviewdog -efm='%f:%l:%c: %m' -diff="git diff $(COMMIT) HEAD"
GOBIN:=go1.11rc2
VGOBIN:=GO111MODULE=on go1.11rc2
PKG:=$(shell $(GOBIN) list)
NAME:=$(notdir $(PKG))
GOLIST:=$(shell $(GOBIN) list ./...)
GODIR:=$(patsubst $(PKG)/%,%,$(wordlist 2,$(words $(GOLIST)),$(GOLIST)))
GO:=$(find . -type d -name vendor -prune -or -type f -name "*.go" -print)
LIBGO:=$(wildcard lib/*.go)
LIB:=$(LIBGO:.go=.so)
VENDOR:=vendor
.SUFFIXES: .go .so
.go.so: $(VENDOR)
$(GOBIN) build -buildmode=c-shared -o $@ $<
all: $(VENDOR) $(GO) $(LIB)
$(VGOBIN) build -ldflags=" \
-X main.serial=$(AUTO_COUNT_SINCE).$(AUTO_COUNT_LOG) \
-X main.hash=$(shell git describe --always --dirty=+) \
-X \"main.build=$(shell LANG=en date -u +'%b %d %T %Y')\" \
"
$(VENDOR): go.mod
$(VGOBIN) mod vendor
clean:
rm -f $(NAME) $(wildcard lib/*.h) $(wildcard lib/*.so)
rm -rf vendor
test: $(VENDOR)
$(GOBIN) test $(PKG)/...
.PHONY: bench
bench:
$(GOBIN) test -bench . -benchmem -count 5 -run none $(PKG)/... | tee bench/now.txt
[ -f bench/before.txt ] && ( type benchcmp > /dev/null 2>&1 ) && benchcmp bench/before.txt bench/now.txt || :
lint: $(VENDOR)
-echo $(GOLIST) | xargs -L1 golint
@echo
-deadcode $(GODIR) 2>&1
@echo
-find $(GODIR) -type f -exec misspell {} \; $(REVIEWDOG)
@echo
-staticcheck $(GOLIST) $(REVIEWDOG)
@echo
-errcheck $(GOLIST) $(REVIEWDOG)
@echo
-safesql $(GOLIST)
@echo
-goconst $(GOLIST) $(REVIEWDOG)
@echo
-$(GOBIN) vet $(GOLIST) $(REVIEWDOG)
@echo
-$(GOBIN) vet -shadow $(GOLIST) $(REVIEWDOG)
@echo
-aligncheck $(GOLIST) $(REVIEWDOG)
@echo
-gosimple $(GOLIST) $(REVIEWDOG)
@echo
-unconvert $(GOLIST) $(REVIEWDOG)
@echo
-interfacer $(GOLIST) $(REVIEWDOG)
review:
$(MAKE) lint COMMIT:=master
review-dupl:
-git diff $(COMMIT) HEAD --name-only --diff-filter=AM|grep -e "\.go$$" | xargs dupl