-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
87 lines (73 loc) · 1.76 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
PKG_NAME := main
# Commands
GO := go
GOFMT := gofmt
GOLINT := golint
GOVET := go vet
GOTEST := go test
GOCOVER := go tool cover
# Flags
GOFLAGS := -v
GOFMTFLAGS := -s
GOLINTFLAGS := -set_exit_status
GOVETFLAGS := -all
GOTESTFLAGS := -v
GOCOVERFLAGS := -html
# Directories and Files
TEMP_DIR := ./tmp
COVERAGE_PROFILE := cover.out
BINARY := $(TEMP_DIR)/$(PKG_NAME)
EXAMPLE_DIR := ./examples
EXAMPLE_SCRIPT := $(EXAMPLE_DIR)/generate.sh
EXAMPLE_MAIN := $(EXAMPLE_DIR)/main.go
.PHONY: all
all: build test
.PHONY: fmt
fmt:
$(GOFMT) $(GOFMTFLAGS) -w .
.PHONY: lint
lint:
$(GOLINT) $(GOLINTFLAGS) ./...
.PHONY: vet
vet:
$(GOVET) $(GOVETFLAGS) ./...
.PHONY: clean
clean:
rm -f $(TEMP_DIR)/*
.PHONY: build
build: vet
$(GO) build $(GOFLAGS) -o $(BINARY)
.PHONY: test
test:
$(GOTEST) $(GOTESTFLAGS) ./...
.PHONY: cover
cover:
mkdir -p $(TEMP_DIR)
$(GOTEST) $(GOTESTFLAGS) -coverprofile=$(COVERAGE_PROFILE) -outputdir=$(TEMP_DIR) `go list ./... | grep -v ./internal | grep -v ./examples`
$(GOCOVER) $(GOCOVERFLAGS) $(TEMP_DIR)/$(COVERAGE_PROFILE)
.PHONY: generate-example
generate-example:
@if [ -x $(EXAMPLE_SCRIPT) ]; then \
$(EXAMPLE_SCRIPT); \
else \
echo "$(EXAMPLE_SCRIPT) does not exist or is not executable"; \
exit 1; \
fi
.PHONY: run-example
run-example:
$(GO) run $(EXAMPLE_MAIN)
.PHONY: help
help:
@echo "Usage: make <target>"
@echo "Targets:"
@echo " all - build and test"
@echo " fmt - format source code"
@echo " lint - lint source code"
@echo " vet - vet source code"
@echo " clean - clean up"
@echo " build - build binary"
@echo " test - run tests"
@echo " cover - run tests with coverage"
@echo " generate-example - generate example"
@echo " run-example - run example"
@echo " help - show this help message"