-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
144 lines (116 loc) · 5.13 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/make -f
# Project variables
NAME?=omni
BINARY?=$(NAME)d
COMMIT:=$(shell git log -1 --format='%H')
VERSION:=$(shell git describe --tags --match 'v*' --abbrev=8 | sed 's/-g/-/' | sed 's/-[0-9]*-/-/')
GOFLAGS:=""
GOTAGS:=ledger
SHELL := /bin/bash # Use bash syntax
# currently installed 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)
# minimum supported Go version
GO_MINIMUM_MAJOR_VERSION = $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f2 | cut -d'.' -f1)
GO_MINIMUM_MINOR_VERSION = $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f2 | cut -d'.' -f2)
RED=\033[0;31m
GREEN=\033[0;32m
LGREEN=\033[1;32m
NOCOLOR=\033[0m
GO_CURR_VERSION=$(shell echo -e "Current Go version: $(LGREEN)$(GO_MAJOR_VERSION).$(GREEN)$(GO_MINOR_VERSION)$(NOCOLOR)")
GO_VERSION_ERR_MSG=$(shell echo -e '$(RED)❌ ERROR$(NOCOLOR): Go version $(LGREEN)$(GO_MINIMUM_MAJOR_VERSION).$(GREEN)$(GO_MINIMUM_MINOR_VERSION)$(NOCOLOR)+ is required')
BUILDDIR ?= $(CURDIR)/build
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.7.0
DOCKERNET_HOME=./dockernet
DOCKERNET_COMPOSE_FILE=$(DOCKERNET_HOME)/docker-compose.yml
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(NAME) \
-X github.com/cosmos/cosmos-sdk/version.AppName=$(NAME) \
-X github.com/cosmos/cosmos-sdk/version.ServerName=$(BINARY) \
-X github.com/cosmos/cosmos-sdk/version.ClientName=$(BINARY) \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT)
BUILD_FLAGS := -ldflags '$(ldflags)' -tags '$(GOTAGS)'
BUILD_FOLDER = ./build
## install: Install omnid binary in $GOBIN
install: check-version go.sum
@echo Installing omnid binary...
@GOFLAGS=$(GOFLAGS) go install $(BUILD_FLAGS) ./cmd/$(BINARY)
@omnid version
go install -mod=readonly $(BUILD_FLAGS) ./cmd/observerd
## build: Build the binary
build: check-version go.sum
@echo Building omnid binary...
@-mkdir -p $(BUILD_FOLDER) 2> /dev/null
@GOFLAGS=$(GOFLAGS) go build $(BUILD_FLAGS) -o $(BUILD_FOLDER) ./cmd/$(BINARY)
go build -mod=mod $(BUILD_FLAGS) -o build/observerd ./cmd/observerd
## build-all: Build binaries for all platforms
build-all:
@echo Building omnid binaries for all platforms...
@-mkdir -p $(BUILD_FOLDER) 2> /dev/null
@GOFLAGS=$(GOFLAGS) GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BUILD_FOLDER)/$(BINARY)-linux-amd64 ./cmd/$(BINARY)
@GOFLAGS=$(GOFLAGS) GOOS=linux GOARCH=arm64 go build $(BUILD_FLAGS) -o $(BUILD_FOLDER)/$(BINARY)-linux-arm64 ./cmd/$(BINARY)
@GOFLAGS=$(GOFLAGS) GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BUILD_FOLDER)/$(BINARY)-darwin-amd64 ./cmd/$(BINARY)
go build -mod=mod $(BUILD_FLAGS) -o build/observerd ./cmd/observerd
## do-checksum: Generate checksums for all binaries
do-checksum:
@cd build && sha256sum $(BINARY)-linux-amd64 $(BINARY)-linux-arm64 $(BINARY)-darwin-amd64 > $(BINARY)_checksum
## build-with-checksum: Build binaries for all platforms and generate checksums
build-with-checksum: build-all do-checksum
.PHONY: install build build-all do-checksum build-with-checksum
## mocks: Generate mocks
mocks:
@echo Generating mocks
@go install github.com/vektra/mockery/v2
@go generate ./...
## test-unit: Run unit tests
test-unit:
@echo Running unit tests...
@GOFLAGS=$(GOFLAGS) go test -race -failfast -v ./...
## clean: Clean build files. Runs `go clean` internally.
clean:
@echo Cleaning build cache...
@rm -rf $(BUILD_FOLDER) 2> /dev/null
@go clean ./...
.PHONY: mocks test-unit clean
## go-mod-cache: Retrieve the go modules and store them in the local cache
go-mod-cache: go.sum
@echo "--> Retrieve the go modules and store them in the local cache."
@go mod download
## go.sum: Ensure dependencies have not been modified
go.sum: go.mod
@echo "--> Make sure that the dependencies haven't been altered."
@go mod verify
# Add check to make sure we are using the proper Go version before proceeding with anything
check-version:
@echo '$(GO_CURR_VERSION)'
@if [[ $(GO_MAJOR_VERSION) -eq $(GO_MINIMUM_MAJOR_VERSION) && $(GO_MINOR_VERSION) -ge $(GO_MINIMUM_MINOR_VERSION) ]]; then \
exit 0; \
elif [[ $(GO_MAJOR_VERSION) -lt $(GO_MINIMUM_MAJOR_VERSION) ]]; then \
echo '$(GO_VERSION_ERR_MSG)'; \
exit 1; \
elif [[ $(GO_MINOR_VERSION) -lt $(GO_MINIMUM_MINOR_VERSION) ]]; then \
echo '$(GO_VERSION_ERR_MSG)'; \
exit 1; \
fi
.PHONY: go-mod-cache go.sum check-version
help: Makefile
@echo
@echo " Choose a command run in "$(BINARY)", or just run 'make' for install"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
.PHONY: help
.DEFAULT_GOAL := install
build-docker:
@bash $(DOCKERNET_HOME)/build.sh -${build} ${BUILDDIR}
start-docker: build-docker
@bash $(DOCKERNET_HOME)/start_network.sh
clean-docker:
@docker-compose -f $(DOCKERNET_COMPOSE_FILE) stop
@docker-compose -f $(DOCKERNET_COMPOSE_FILE) down
rm -rf $(DOCKERNET_HOME)/state
docker image prune -a
stop-docker:
@bash $(DOCKERNET_HOME)/pkill.sh
docker-compose -f $(DOCKERNET_COMPOSE_FILE) down --remove-orphans