1export GOBIN ?= $(shell pwd)/bin
2
3GOLINT = $(GOBIN)/golint
4BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
5
6# Directories containing independent Go modules.
7#
8# We track coverage only for the main module.
9MODULE_DIRS = . ./benchmarks
10
11# Many Go tools take file globs or directories as arguments instead of packages.
12GO_FILES := $(shell \
13	find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
14	-o -name '*.go' -print | cut -b3-)
15
16.PHONY: all
17all: lint test
18
19.PHONY: lint
20lint: $(GOLINT)
21	@rm -rf lint.log
22	@echo "Checking formatting..."
23	@gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log
24	@echo "Checking vet..."
25	@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go vet ./... 2>&1) &&) true | tee -a lint.log
26	@echo "Checking lint..."
27	@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(GOLINT) ./... 2>&1) &&) true | tee -a lint.log
28	@echo "Checking for unresolved FIXMEs..."
29	@git grep -i fixme | grep -v -e Makefile | tee -a lint.log
30	@echo "Checking for license headers..."
31	@./checklicense.sh | tee -a lint.log
32	@[ ! -s lint.log ]
33
34$(GOLINT):
35	go install golang.org/x/lint/golint
36
37.PHONY: test
38test:
39	@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go test -race ./...) &&) true
40
41.PHONY: cover
42cover:
43	go test -race -coverprofile=cover.out -coverpkg=./... ./...
44	go tool cover -html=cover.out -o cover.html
45
46.PHONY: bench
47BENCH ?= .
48bench:
49	@$(foreach dir,$(MODULE_DIRS), ( \
50		cd $(dir) && \
51		go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) \
52	) &&) true
53
54.PHONY: updatereadme
55updatereadme:
56	rm -f README.md
57	cat .readme.tmpl | go run internal/readme/readme.go > README.md
58