-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
156 lines (132 loc) · 4.98 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#
# Borrowed from: https://github.com/gopasspw/gopass/blob/master/Makefile
#
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
PKGS := $(shell go list ./...)
GOFILES_NOVENDOR := $(shell find . -name vendor -prune -o -type f -name '*.go' -not -name '*.pb.go' -print)
GOFILES_BUILD := $(shell find . -type f -name '*.go' -not -name '*_test.go')
APP_VERSION ?= $(shell git describe --tags --always --dirty)
APP_OUTPUT ?= autorandr-launcher
APP_REVISION := $(shell git describe --tags --always --dirty)
DATE := $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" '+%FT%T%z' 2>/dev/null || date -u '+%FT%T%z')
BUILDFLAGS_NOPIE := -trimpath -ldflags="-s -w -X main.version=$(APP_VERSION) -X main.commit=$(APP_REVISION) -X main.date=$(DATE)" -gcflags="-trimpath=$(GOPATH)" -asmflags="-trimpath=$(GOPATH)"
BUILDFLAGS ?= $(BUILDFLAGS_NOPIE) -buildmode=pie
TESTFLAGS ?=
PWD := $(shell pwd)
PREFIX ?= $(GOPATH)
BINDIR ?= $(PREFIX)/bin
GO := GO111MODULE=on go
GOOS ?= $(shell go version | cut -d' ' -f4 | cut -d'/' -f1)
GOARCH ?= $(shell go version | cut -d' ' -f4 | cut -d'/' -f2)
TAGS ?=
export GO111MODULE=on
OK := $(shell tput setaf 6; echo ' [OK]'; tput sgr0;)
all: sysinfo build
build: $(APP_OUTPUT)
sysinfo:
@echo ">> SYSTEM INFORMATION"
@echo -n " PLATFORM : $(shell uname -a)"
@printf '%s\n' '$(OK)'
@echo -n " PWD: : $(shell pwd)"
@printf '%s\n' '$(OK)'
@echo -n " GO : $(shell go version)"
@printf '%s\n' '$(OK)'
@echo -n " BUILDFLAGS : $(BUILDFLAGS)"
@printf '%s\n' '$(OK)'
@echo -n " GIT : $(shell git version)"
@printf '%s\n' '$(OK)'
@echo -n " GPG : $(shell which gpg) $(shell gpg --version | head -1)"
@printf '%s\n' '$(OK)'
@echo -n " GPGAgent : $(shell which gpg-agent) $(shell gpg-agent --version | head -1)"
@printf '%s\n' '$(OK)'
clean:
@echo -n ">> CLEAN"
@$(GO) clean -i ./...
@rm -f ./coverage-all.html
@rm -f ./coverage-all.out
@rm -f ./coverage.out
@find . -type f -name "coverage.out" -delete
@rm -f $(APP_OUTPUT)
@rm -f tests/tests
@rm -f *.test
@rm -rf dist/*
@printf '%s\n' '$(OK)'
$(APP_OUTPUT): $(GOFILES_BUILD)
@echo -n ">> BUILD, version = $(APP_VERSION)/$(APP_REVISION), output = $@"
@$(GO) build -o $@ $(BUILDFLAGS)
@printf '%s\n' '$(OK)'
fulltest: $(APP_OUTPUT)
@echo ">> TEST, \"full-mode\": race detector off"
@echo "mode: atomic" > coverage-all.out
@$(foreach pkg, $(PKGS),\
echo -n " ";\
go test -run '(Test|Example)' $(BUILDFLAGS) $(TESTFLAGS) -coverprofile=coverage.out -covermode=atomic $(pkg) || exit 1;\
tail -n +2 coverage.out >> coverage-all.out;)
@$(GO) tool cover -html=coverage-all.out -o coverage-all.html
test: $(APP_OUTPUT)
@echo ">> TEST, \"fast-mode\": race detector off"
@$(foreach pkg, $(PKGS),\
echo -n " ";\
$(GO) test -test.short -run '(Test|Example)' $(BUILDFLAGS) $(TESTFLAGS) $(pkg) || exit 1;)
test-win: $(APP_OUTPUT)
@echo ">> TEST, \"fast-mode-win\": race detector off"
@$(foreach pkg, $(PKGS),\
$(GO) test -test.short -run '(Test|Example)' $(pkg) || exit 1;)
codequality:
@echo ">> CODE QUALITY"
@echo -n " REVIVE "
@which revive > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mgechev/revive; \
fi
@revive -formatter friendly -exclude vendor/... ./...
@printf '%s\n' '$(OK)'
@echo -n " FMT "
@$(foreach gofile, $(GOFILES_NOVENDOR),\
out=$$(gofmt -s -l -d -e $(gofile) | tee /dev/stderr); if [ -n "$$out" ]; then exit 1; fi;)
@printf '%s\n' '$(OK)'
@echo -n " VET "
@$(GO) vet ./...
@printf '%s\n' '$(OK)'
@echo -n " CYCLO "
@which gocyclo > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/fzipp/gocyclo/cmd/gocyclo; \
fi
@$(foreach gofile, $(GOFILES_NOVENDOR),\
gocyclo -over 22 $(gofile) || exit 1;)
@printf '%s\n' '$(OK)'
@echo -n " INEFF "
@which ineffassign > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/gordonklaus/ineffassign; \
fi
@ineffassign ./... || exit 1
@printf '%s\n' '$(OK)'
@echo -n " SPELL "
@which misspell > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
@$(foreach gofile, $(GOFILES_NOVENDOR),\
misspell --error $(gofile) || exit 1;)
@printf '%s\n' '$(OK)'
@echo -n " STATICCHECK "
@which staticcheck > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u honnef.co/go/tools/cmd/staticcheck; \
fi
@staticcheck $(PKGS) || exit 1
@printf '%s\n' '$(OK)'
@echo -n " UNPARAM "
@which unparam > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u mvdan.cc/unparam; \
fi
@unparam -exported=false .
@printf '%s\n' '$(OK)'
gen:
@go generate ./...
fmt:
@gofmt -s -l -w $(GOFILES_NOVENDOR)
@goimports -l -w $(GOFILES_NOVENDOR)
@go mod tidy
deps:
@go build -v ./...
upgrade: gen fmt
@go get -u ./...
.PHONY: clean build install sysinfo test codequality