-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo.mk
More file actions
112 lines (93 loc) · 3.69 KB
/
go.mk
File metadata and controls
112 lines (93 loc) · 3.69 KB
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
SHELL := /bin/bash -euo pipefail
define GO_HELP
REQUIREMENTS:
- go : `go` command must be available.
TARGETS:
- go-help : show help message.
- go : run go command with given args.
- go-vet : run `go vet`.
- go-fmt : run `go fmt`.
VARIABLES [default value]:
- GO_CMD : go command. [go]
- GOFMT_CMD : go format command. [gofmt]
- GO_VET_TARGET : go vet target. [./...]
- GO_VET_OPTION : go vet command line option. []
- GO_FMT_TARGET : go fmt target. [./]
- GO_FMT_OPTION : go fmt command line option. [-l -e -s]
REFERENCES:
- https://pkg.go.dev/cmd/vet
- https://pkg.go.dev/cmd/gofmt
- https://go.dev/blog/gofmt
IDE INTEGRATIONS:
- VSCode : https://marketplace.visualstudio.com/items?itemName=golang.go
- JetBrains : https://plugins.jetbrains.com/plugin/9568-go
- Others? : https://go.dev/doc/editors
- Others? : https://go.dev/wiki/IDEsAndTextEditorPlugins
PROJECT STRUCTURE:
/ |-- Go project
├─ _scripts/ |-- Git submodule
│ └─ makefiles/ |
│ └─ go.mk |
├─ Makefile |-- include _scripts/makefiles/go.mk
├─ go.mod |
└─ go.sum |
endef
.PHONY: go-help
go-help:
$(info $(GO_HELP))
@echo ""
#├─────────────────────────────────────────────────────────────────────────────┤
GO_CMD ?= go
GOFMT_CMD ?= gofmt
# go vet envs.
GO_VET_TARGET ?= ./...
GO_VET_OPTION ?=
# go fmt envs.
GO_FMT_TARGET ?= ./
GO_FMT_OPTION ?= -l -e -s
#├─────────────────────────────────────────────────────────────────────────────┤
.PHONY: go-usage
go-usage:
# Usage : make go ARGS=""
# Exec : $$(GO_CMD) $$(ARGS)
# Desc : Run go with given arguments.
# Examples:
# - make go ARGS="version"
# - make go ARGS="help"
.PHONY: go
go:
$(GO_CMD) $(ARGS)
#├─────────────────────────────────────────────────────────────────────────────┤
.PHONY: go-vet-usage
go-vet-usage:
# Usage : make go-vet ARGS=""
# Exec : $$(GO_CMD) vet $$(ARGS) $$(GO_VET_OPTION) $$(GO_VET_TARGET)
# Desc : Run go vet for the specified targets.
# Run `go tool vet help` or `go help vet` to show help.
# Examples:
# - make go-vet
# - make go-vet ARGS=""
.PHONY: go-vet
go-vet:
$(GO_CMD) vet $(ARGS) $(GO_VET_OPTION) $(GO_VET_TARGET)
#├─────────────────────────────────────────────────────────────────────────────┤
.PHONY: go-fmt-usage
go-fmt-usage:
# Usage : make go-fmt ARGS=""
# Exec : $$(GOFMT_CMD) $$(ARGS) $$(GO_FMT_OPTION) $$(GO_FMT_TARGET)
# Desc : Run go fmt for the specified targets.
# Run `gofmt --help` to show help.
# Examples:
# - make go-fmt
# - make go-fmt ARGS=""
# - make go-fmt ARGS="-w"
.PHONY: go-fmt
go-fmt:
$(GOFMT_CMD) $(ARGS) $(GO_FMT_OPTION) $(GO_FMT_TARGET) > gofmt.tmp
@cat gofmt.tmp
@if [ ! -s gofmt.tmp ]; then \
rm -f gofmt.tmp; exit 0; \
else \
rm -f gofmt.tmp; exit 1; \
fi
#├─────────────────────────────────────────────────────────────────────────────┤