-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
104 lines (86 loc) · 2.32 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
DIST := dist
IMPORT := github.com/aiicy/aiicy-cli
GO ?= go
SED_INPLACE := sed -i
EXTRA_GOFLAGS ?=
EXTRA_GOENVS ?=
# TAGS ?=
LDFLAGS ?=
ifeq ($(OS), Windows_NT)
EXECUTABLE_CLI := aiicy-cli.exe
EXTRA_GOENVS = CGO_ENABLED=0 GOOS=windows GOARCH=amd64
else
EXECUTABLE_CLI := aiicy-cli
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
EXTRA_GOENVS = CGO_ENABLED=0 GOOS=darwin GOARCH=amd64
else
EXTRA_GOENVS = CGO_ENABLED=0 GOOS=linux GOARCH=amd64
endif
endif
GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*")
GOBINS := ${GOPATH}/bin
GOFMT ?= gofmt -s
GOFLAGS := -mod=vendor -v
PACKAGES ?= $(shell GO111MODULE=on $(GO) list -mod=vendor ./... | grep -v /vendor/)
SOURCES ?= $(shell find . -name "*.go" -type f)
.PHONY: all
all: build
.PHONY: clean
clean:
$(GO) clean -i ./...
rm -f $(EXECUTABLE_CLI)
.PHONY: fmt
fmt:
$(GOFMT) -w $(GOFILES)
.PHONY: fmt-check
fmt-check:
# get all go files and run go fmt on them
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
.PHONY: errcheck
errcheck:
@hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/kisielk/errcheck; \
fi
errcheck $(PACKAGES)
.PHONY: revive
revive:
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mgechev/revive; \
fi
revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -error -i unknwon,destory $(GOFILES)
.PHONY: misspell
misspell:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -w -i unknwon $(GOFILES)
.PHONY: test
test:
$(GO) test -tags='sqlite sqlite_unlock_notify' $(PACKAGES)
.PHONY: vendor
vendor:
GO111MODULE=on $(GO) mod tidy && GO111MODULE=on $(GO) mod vendor
.PHONY: test-vendor
test-vendor: vendor
@diff=$$(git diff vendor/); \
if [ -n "$$diff" ]; then \
echo "Please run 'make vendor' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
.PHONY: build
build: $(EXECUTABLE_CLI)
$(EXECUTABLE_CLI): $(SOURCES)
GO111MODULE=on $(EXTRA_GOENVS) $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -o $@;