-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
45 lines (32 loc) · 1 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
# Determine root directory
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# Gather all .go files for use in dependencies below
GO_FILES=$(shell find $(ROOT_DIR) -name '*.go')
# Gather list of expected binaries
BINARIES=$(shell cd $(ROOT_DIR)/cmd && ls -1 | grep -v ^common)
# Extract Go module name from go.mod
GOMODULE=$(shell grep ^module $(ROOT_DIR)/go.mod | awk '{ print $$2 }')
GO_LDFLAGS=-ldflags "-s -w"
.PHONY: build mod-tidy clean test
# Alias for building program binary
build: $(BINARIES)
mod-tidy:
# Needed to fetch new dependencies and add them to go.mod
go mod tidy
clean:
rm -f $(BINARIES)
format:
go fmt ./...
golines:
golines -w --ignore-generated --chain-split-dots --max-len=80 --reformat-tags .
test: mod-tidy
go test -v -race ./...
bench: mod-tidy
go test -v -bench=. ./...
# Build our program binaries
# Depends on GO_FILES to determine when rebuild is needed
$(BINARIES): mod-tidy $(GO_FILES)
CGO_ENABLED=0 go build \
$(GO_LDFLAGS) \
-o $(@) \
./cmd/$(@)