-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
146 lines (127 loc) · 5.05 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
145
146
# Makefile for building and linting Go project
DOCKER := $(shell which docker)
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
GO_VERSION=1.23
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif
ifeq ($(WITH_CLEVELDB),yes)
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
empty = $(whitespace) $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(empty),$(comma),$(build_tags))
# Basic project settings
BINARY_NAME=junctiond
BUILD_DIR=./build
SOURCE_DIR=./cmd/junctiond
CHECKSUM_FILE=$(BUILD_DIR)/checksums.txt
# Go commands
GO_BUILD=go build
GO_INSTALL=go install
GO_CLEAN=go clean
GO_TEST=go test
# Versioning
VERSION ?= $(shell git describe --tags `git rev-list --tags --max-count=1`)
COMMIT := $(shell git log -1 --format='%H')
TMVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
# Build tags
build_tags = netgo
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
# Linker flags
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=junction \
-X github.com/cosmos/cosmos-sdk/version.AppName=$(BINARY_NAME) \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags)" \
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TMVERSION)
# Linter settings
GOLINT=golangci-lint
LINT_OPTIONS=--enable-all
ifeq ($(VERSION),1.0.0)
LINT_OPTIONS+=--disable=errcheck
endif
# Default target
default: build
# Build the project for the current architecture
build: go.sum
@echo "Building $(BINARY_NAME) binary..."
$(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME) $(SOURCE_DIR)
@shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME) >> $(CHECKSUM_FILE)
# Install the binary
install:
@echo "Installing $(BINARY_NAME) binary..."
$(GO_INSTALL) -tags "$(build_tags)" -ldflags '$(ldflags)' $(SOURCE_DIR)
# Run tests
test:
@echo "Running tests..."
$(GO_TEST) ./...
# Clean build artifacts
clean:
@echo "Cleaning up old versions..."
$(GO_CLEAN)
rm -f $(BUILD_DIR)/$(BINARY_NAME) $(CHECKSUM_FILE)
# Lint the project
lint:
@echo "Running linter..."
$(GOLINT) run $(LINT_OPTIONS)
# Print system information
print-system:
@echo "System architecture: $(shell uname -s)/$(shell uname -m)"
# Build the project for different architectures and generate checksums
build-all: go.sum
@echo "Building $(BINARY_NAME) for different architectures..."
rm -f $(CHECKSUM_FILE)
GOOS=linux GOARCH=amd64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(SOURCE_DIR)
@shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 >> $(CHECKSUM_FILE)
GOOS=linux GOARCH=arm64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 $(SOURCE_DIR)
@shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 >> $(CHECKSUM_FILE)
GOOS=darwin GOARCH=amd64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(SOURCE_DIR)
@shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 >> $(CHECKSUM_FILE)
GOOS=darwin GOARCH=arm64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(SOURCE_DIR)
@shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 >> $(CHECKSUM_FILE)
GOOS=windows GOARCH=amd64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(SOURCE_DIR)
@shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe >> $(CHECKSUM_FILE)
build-static-linux-amd64: go.sum $(BUILD_DIR)/
mkdir -p $(BUILD_DIR)
$(DOCKER) buildx create --name junctionbuilder || true
$(DOCKER) buildx use junctionbuilder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILD_TAGS=$(build_tags_comma_sep),muslc \
--platform linux/amd64 \
-t junction-amd64 \
--load \
-f Dockerfile.builder .
$(DOCKER) rm -f junctionbinary || true
$(DOCKER) create -ti --name junctionbinary junction-amd64
$(DOCKER) cp junctionbinary:/bin/junctiond $(BUILD_DIR)/junctiond-linux-amd64
$(DOCKER) rm -f junctionbinary
.PHONY: default build install test clean lint print-system build-all build-static-linux-amd64