-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (59 loc) · 2.5 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
#!/usr/bin/make -f
export GO111MODULE=on
BUILD_DIR ?= $(CURDIR)/build
MAIN_CMD := $(CURDIR)/valin
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
GORELEASER_CONFIG ?= ./.goreleaser.yml
GIT_HEAD_COMMIT_LONG := $(shell git log -1 --format='%H')
ifeq (,$(VERSION))
VERSION := $(shell git describe --exact-match 2>/dev/null)
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif
###############################################################################
### Build / Install ###
###############################################################################
all: build
build: go.sum go-version
@mkdir -p $(BUILD_DIR)
go build -mod=readonly -o $(BUILD_DIR) $(BUILD_FLAGS) $(MAIN_CMD)
install: go.sum go-version
go install -mod=readonly $(BUILD_FLAGS) $(MAIN_CMD)
.PHONY: build install
###############################################################################
### Go Version ###
###############################################################################
GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
MIN_GO_MAJOR_VERSION = 1
MIN_GO_MINOR_VERSION = 20
GO_VERSION_ERROR = Golang version $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION) is not supported, \
please update to at least $(MIN_GO_MAJOR_VERSION).$(MIN_GO_MINOR_VERSION)
go-version:
@echo "Verifying go version..."
@if [ $(GO_MAJOR_VERSION) -gt $(MIN_GO_MAJOR_VERSION) ]; then \
exit 0; \
elif [ $(GO_MAJOR_VERSION) -lt $(MIN_GO_MAJOR_VERSION) ]; then \
echo $(GO_VERSION_ERROR); \
exit 1; \
elif [ $(GO_MINOR_VERSION) -lt $(MIN_GO_MINOR_VERSION) ]; then \
echo $(GO_VERSION_ERROR); \
exit 1; \
fi
.PHONY: go-version
###############################################################################
### Go Modules ###
###############################################################################
go.sum: go.mod
@echo "Ensuring app dependencies have not been modified..."
go mod verify
go mod tidy
verify:
@echo "Verifying all go module dependencies..."
@find . -name 'go.mod' -type f -execdir go mod verify \;
tidy:
@echo "Cleaning up all go module dependencies..."
@find . -name 'go.mod' -type f -execdir go mod tidy \;
.PHONY: verify tidy