...
1# I'm sure there is better way. But I would need to find it first
2MK_FILE_PATH = $(lastword $(MAKEFILE_LIST))
3PRJ_DIR = $(abspath $(dir $(MK_FILE_PATH)))
4GOPATH_BUILD = $(PRJ_DIR)/build
5COVER_DIR = $(GOPATH_BUILD)/coverage
6TOOLS_DIR ?= $(GOPATH)/bin
7ETC_DIR = $(PRJ_DIR)/.etc
8OPTS ?=
9NOASM ?=
10GO ?= go
11GOLANGCILINT ?= golangci-lint
12# -run="^_" as we want to avoid running tests by 'bench' and there never be a test starting with _
13BENCH_OPTS ?= -bench=. -run="^_" -benchmem
14V ?= 1
15GOARCH ?=
16BUILD_ARCH = $(shell $(GO) env GOARCH)
17
18ifeq ($(NOASM),1)
19 OPTS+=--tags noasm
20endif
21
22ifeq ($(V),1)
23 OPTS += -v # Be verbose
24endif
25
26all: build
27
28lint:
29 $(GOLANGCILINT) run --config $(ETC_DIR)/golangci.yml ./...
30
31lint-fix:
32 $(GOLANGCILINT) run --config $(ETC_DIR)/golangci.yml --fix ./...
33
34build:
35 $(GO) build ./...
36
37test: clean
38 $(GO) vet ./...
39 $(GO) test $(OPTS) ./...
40
41bench: clean
42 $(GO) test $(BENCH_OPTS) $(OPTS) ./...
43
44cover: clean
45 mkdir -p $(COVER_DIR)
46 $(GO) test -race -coverprofile=$(COVER_DIR)/coverage.txt -covermode=atomic $(OPTS) ./...
47 $(GO) tool cover -html $(COVER_DIR)/coverage.txt -o $(COVER_DIR)/coverage.html
48
49generate: clean
50 $(GO) generate -v ./...
51
52bootstrap:
53 curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(TOOLS_DIR) v1.18.0
54
55clean:
56 rm -rf $(GOPATH_BUILD)
57
58.INTERMEDIATE: circl.go circl_static.exe circl_plugin.so
59circl_static: circl_static.exe
60circl_static.exe: circl.go
61 go clean -cache -modcache
62 go build -buildmode=default -o $@ $^
63
64circl_plugin: circl_plugin.so
65circl_plugin.so: circl.go
66 go clean -cache -modcache
67 go build -buildmode=plugin -o $@ $^
68
69circl.go:
70 go run .etc/all_imports.go -out $@
View as plain text